From 7cdb14f7c769946e3e37b5b0b387316663bc896c Mon Sep 17 00:00:00 2001 From: Adrian Muzyka Date: Mon, 26 Feb 2024 13:05:05 +0100 Subject: [PATCH] Support Hibernate abort by calling wakeup --- Source/WPEFramework/PluginServer.cpp | 35 +++++++++++++++++++++++++--- Source/core/Portability.h | 1 + 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/Source/WPEFramework/PluginServer.cpp b/Source/WPEFramework/PluginServer.cpp index 9e5598a6fb..9b69907125 100644 --- a/Source/WPEFramework/PluginServer.cpp +++ b/Source/WPEFramework/PluginServer.cpp @@ -709,12 +709,22 @@ namespace PluginHost { result = Core::ERROR_BAD_REQUEST; } else { + State(IShell::HIBERNATED); #ifdef HIBERNATE_SUPPORT_ENABLED Core::process_t parentPID = local->ParentPID(); + local->Release(); + Unlock(); SYSLOG(Logging::Notification, ("Hibernation of plugin [%s] process [%u]", Callsign().c_str(), parentPID)); result = HibernateProcess(timeout, parentPID, _administrator.Configuration().HibernateLocator().c_str(), _T(""), &_hibernateStorage); - if(result == HIBERNATE_ERROR_NONE) + Lock(); + if (State() != IShell::HIBERNATED) { + SYSLOG(Logging::Startup, ("Hibernation aborted of plugin [%s] process [%u]", Callsign().c_str(), parentPID)); + result = Core::ERROR_ABORTED; + } + Unlock(); + + if (result == HIBERNATE_ERROR_NONE) { { result = HibernateChildren(parentPID, timeout); if(result != Core::ERROR_NONE) @@ -724,14 +734,21 @@ namespace PluginHost { WakeupProcess(timeout, parentPID, _administrator.Configuration().HibernateLocator().c_str(), _T(""), &_hibernateStorage); } } + + if (result == Core::ERROR_NONE) { + SYSLOG(Logging::Startup, ("Hibernated plugin [%s]:[%s]", ClassName().c_str(), Callsign().c_str())); + } + Lock(); #else + local->Release(); result = Core::ERROR_NONE; #endif if (result == Core::ERROR_NONE) { - State(IShell::state::HIBERNATED); SYSLOG(Logging::Notification, ("Hibernated plugin [%s]:[%s]", ClassName().c_str(), Callsign().c_str())); } - local->Release(); + else if (State() == IShell::state::HIBERNATED) { + State(IShell::ACTIVATED); + } } } Unlock(); @@ -798,10 +815,22 @@ namespace PluginHost { for (auto iter = childrenPIDs.begin(); iter != childrenPIDs.end(); ++iter) { SYSLOG(Logging::Notification, ("Hibernation of plugin [%s] child process [%u]", Callsign().c_str(), *iter)); + Lock(); + if (State() != IShell::HIBERNATED) { + SYSLOG(Logging::Startup, ("Hibernation aborted of plugin [%s] child process [%u]", Callsign().c_str(), *iter)); + result = Core::ERROR_ABORTED; + Unlock(); + break; + } + Unlock(); result = HibernateProcess(timeout, *iter, _administrator.Configuration().HibernateLocator().c_str(), _T(""), &_hibernateStorage); if (result == HIBERNATE_ERROR_NONE) { // Hibernate Children of this process result = HibernateChildren(*iter, timeout); + if (result == Core::ERROR_ABORTED) { + break; + } + if (result != HIBERNATE_ERROR_NONE) { // revert Hibernation of parent SYSLOG(Logging::Notification, ("Wakeup plugin [%s] process [%u] on Hibernate error [%d]", Callsign().c_str(), *iter, result)); diff --git a/Source/core/Portability.h b/Source/core/Portability.h index 3644b5445c..986b9841e0 100644 --- a/Source/core/Portability.h +++ b/Source/core/Portability.h @@ -896,6 +896,7 @@ namespace Core { ERROR_CODE(ERROR_INTERNAL_JSONRPC, 55) \ ERROR_CODE(ERROR_PARSING_ENVELOPPE, 56) \ ERROR_CODE(ERROR_COMPOSIT_OBJECT, 57) \ + ERROR_CODE(ERROR_ABORTED, 58) #define ERROR_CODE(CODE, VALUE) CODE = VALUE,