Had a couple issues that were preventing a clean shutdown. Seems fine now?

This commit is contained in:
casey langen 2020-01-26 21:33:34 -08:00
parent 092147aad0
commit c8e2d55631
3 changed files with 8 additions and 6 deletions

View File

@ -169,6 +169,7 @@ PlaybackService::PlaybackService(
PlaybackService::~PlaybackService() {
playback::SavePlaybackContext(appPrefs, library, *this);
this->messageQueue.Remove(this);
savePreferences(*this, playbackPrefs);
this->Stop();
this->ResetRemotes();

View File

@ -76,7 +76,7 @@ namespace musik { namespace core { namespace audio {
musik::core::runtime::IMessageQueue& messageQueue,
musik::core::ILibraryPtr library);
~PlaybackService();
virtual ~PlaybackService();
/* IMessageTarget */
virtual void ProcessMessage(musik::core::runtime::IMessage &message) override;

View File

@ -85,6 +85,7 @@ static class PlaybackRemote : public IPlaybackRemote {
void CheckRunningStatus() {
if (!thread && context.environment && context.playback && context.prefs && context.metadataProxy) {
this->Start();
thread.reset(new std::thread(std::bind(&PlaybackRemote::ThreadProc, this)));
}
else if (thread && (!context.environment || !context.playback || !context.prefs || !context.metadataProxy)) {
@ -124,22 +125,22 @@ static class PlaybackRemote : public IPlaybackRemote {
private:
void ThreadProc() {
httpServer.Wait();
webSocketServer.Wait();
}
void Start() {
if (context.prefs->GetBool(prefs::http_server_enabled.c_str(), true)) {
httpServer.Start();
}
if (context.prefs->GetBool(prefs::websocket_server_enabled.c_str(), true)) {
webSocketServer.Start();
}
httpServer.Wait();
webSocketServer.Wait();
}
void Stop() {
httpServer.Stop();
webSocketServer.Stop();
if (this->thread) {
this->thread->join();
this->thread.reset();