From 0edc4d16527af043d67cb725c59855359ae02321 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 3 Jul 2016 10:43:35 -0700 Subject: [PATCH] http: Check server status asynchronously. --- UI/RemoteISOScreen.cpp | 28 ++++++++++++++++++---------- UI/RemoteISOScreen.h | 3 +++ 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/UI/RemoteISOScreen.cpp b/UI/RemoteISOScreen.cpp index f347021b91..3453660a45 100644 --- a/UI/RemoteISOScreen.cpp +++ b/UI/RemoteISOScreen.cpp @@ -70,7 +70,23 @@ static void ExecuteServer() { UpdateStatus(ServerStatus::STOPPED); } -RemoteISOScreen::RemoteISOScreen() { +RemoteISOScreen::RemoteISOScreen() : serverRunning_(false) { +} + +void RemoteISOScreen::update(InputState &input) { + UIScreenWithBackground::update(input); + + bool nowRunning = RetrieveStatus() != ServerStatus::STOPPED; + if (serverRunning_ && !nowRunning) { + // Server stopped, delete the thread. + delete serverThread; + serverThread = nullptr; + } + if (serverRunning_ != nowRunning) { + RecreateViews(); + } + + serverRunning_ = nowRunning; } void RemoteISOScreen::CreateViews() { @@ -89,7 +105,7 @@ void RemoteISOScreen::CreateViews() { rightColumnItems->SetSpacing(0.0f); rightColumnItems->Add(new Choice(rp->T("Browse Games"))); - if (serverStatus != ServerStatus::STOPPED) { + if (RetrieveStatus() != ServerStatus::STOPPED) { rightColumnItems->Add(new Choice(rp->T("Stop Sharing")))->OnClick.Handle(this, &RemoteISOScreen::HandleStopServer); } else { rightColumnItems->Add(new Choice(rp->T("Share Games (Server)")))->OnClick.Handle(this, &RemoteISOScreen::HandleStartServer); @@ -117,9 +133,6 @@ UI::EventReturn RemoteISOScreen::HandleStartServer(UI::EventParams &e) { serverThread = new std::thread(&ExecuteServer); serverThread->detach(); - serverStatusCond.wait(serverStatusLock); - RecreateViews(); - return EVENT_DONE; } @@ -131,11 +144,6 @@ UI::EventReturn RemoteISOScreen::HandleStopServer(UI::EventParams &e) { } serverStatus = ServerStatus::STOPPING; - serverStatusCond.wait(serverStatusLock); - delete serverThread; - serverThread = nullptr; - - RecreateViews(); return EVENT_DONE; } diff --git a/UI/RemoteISOScreen.h b/UI/RemoteISOScreen.h index 04b92722c1..26340c0f3a 100644 --- a/UI/RemoteISOScreen.h +++ b/UI/RemoteISOScreen.h @@ -27,8 +27,11 @@ public: RemoteISOScreen(); protected: + void update(InputState &input) override; void CreateViews() override; UI::EventReturn HandleStartServer(UI::EventParams &e); UI::EventReturn HandleStopServer(UI::EventParams &e); + + bool serverRunning_; };