From e918bec496184a861670a8d2528f852719c5edf3 Mon Sep 17 00:00:00 2001 From: Karthick Somasundaresan Date: Thu, 22 Aug 2024 06:03:56 -0700 Subject: [PATCH] Sending notification about state change --- WebServer/WebServer.cpp | 30 +++++++++++++++++++++++++++ WebServer/WebServer.h | 3 --- WebServer/WebServerImplementation.cpp | 8 ------- 3 files changed, 30 insertions(+), 11 deletions(-) diff --git a/WebServer/WebServer.cpp b/WebServer/WebServer.cpp index b05f9154..8e5de4f2 100644 --- a/WebServer/WebServer.cpp +++ b/WebServer/WebServer.cpp @@ -73,6 +73,7 @@ namespace Plugin { message = _T("WebServer Couldnt get StateControl."); } else { + stateControl->Register(&_notification); uint32_t result = stateControl->Configure(_service); stateControl->Release(); if (result != Core::ERROR_NONE) { @@ -163,5 +164,34 @@ namespace Plugin { Core::IWorkerPool::Instance().Submit(PluginHost::IShell::Job::Create(_service, PluginHost::IShell::DEACTIVATED, PluginHost::IShell::FAILURE)); } } + void WebServer::StateChange(const PluginHost::IStateControl::state state) + { + switch (state) { + case PluginHost::IStateControl::RESUMED: + TRACE(Trace::Information, + (string(_T("StateChange: { \"suspend\":false }")))); + _service->Notify("{ \"suspended\":false }"); + break; + case PluginHost::IStateControl::SUSPENDED: + TRACE(Trace::Information, + (string(_T("StateChange: { \"suspend\":true }")))); + _service->Notify("{ \"suspended\":true }"); + break; + case PluginHost::IStateControl::EXITED: + Core::IWorkerPool::Instance().Submit( + PluginHost::IShell::Job::Create(_service, + PluginHost::IShell::DEACTIVATED, + PluginHost::IShell::REQUESTED)); + break; + case PluginHost::IStateControl::UNINITIALIZED: + break; + default: + ASSERT(false); + break; + } + } + + + } } diff --git a/WebServer/WebServer.h b/WebServer/WebServer.h index b19f1475..5ba9e9df 100644 --- a/WebServer/WebServer.h +++ b/WebServer/WebServer.h @@ -115,9 +115,6 @@ POP_WARNING() string Information() const override; void StateChange(PluginHost::IStateControl::state); - - - private: void Deactivated(RPC::IRemoteConnection* connection); diff --git a/WebServer/WebServerImplementation.cpp b/WebServer/WebServerImplementation.cpp index 775fd5d1..3b7496aa 100644 --- a/WebServer/WebServerImplementation.cpp +++ b/WebServer/WebServerImplementation.cpp @@ -743,7 +743,6 @@ POP_WARNING() } - //void RequestForStateChange(const PluginHost::IStateControl::command command) { void Dispatch() { bool stateChanged = false; uint32_t result = Core::ERROR_NONE; @@ -777,13 +776,6 @@ POP_WARNING() _requestedCommand = command; _job.Submit(); _adminLock.Unlock(); - /*if (_state == PluginHost::IStateControl::UNINITIALIZED || - (_state == PluginHost::IStateControl::RESUMED && command == PluginHost::IStateControl::SUSPEND) || - (_state == PluginHost::IStateControl::SUSPENDED && command == PluginHost::IStateControl::RESUME)){ - Core::ProxyType job = Core::ProxyType(Core::ProxyType::Create(*this, command)); - Core::WorkerPool::Instance().Submit(job); - } - */ return (Core::ERROR_NONE); }