Skip to content

Commit

Permalink
Merge branch 'master' into R4
Browse files Browse the repository at this point in the history
  • Loading branch information
Divya authored and Divya committed Dec 14, 2022
2 parents 24c2567 + 835f340 commit a25c4a9
Show file tree
Hide file tree
Showing 14 changed files with 227 additions and 107 deletions.
98 changes: 68 additions & 30 deletions Source/WPEFramework/PluginServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,13 +316,22 @@ namespace PluginHost

IShell::state currentState(State());

if (currentState == IShell::ACTIVATION) {
if (currentState == IShell::state::ACTIVATION) {
Unlock();
result = Core::ERROR_INPROGRESS;
} else if ((currentState == IShell::UNAVAILABLE) || (currentState == IShell::DEACTIVATION) || (currentState == IShell::DESTROYED)) {
}
else if ((currentState == IShell::state::UNAVAILABLE) || (currentState == IShell::state::DEACTIVATION) || (currentState == IShell::state::DESTROYED)) {
Unlock();
result = Core::ERROR_ILLEGAL_STATE;
} else if ((currentState == IShell::DEACTIVATED) || (currentState == IShell::PRECONDITION)) {
}
else if (currentState == IShell::state::HIBERNATED) {
// Wake up the Hibernated process..
Wakeup();
State(ACTIVATED);
Unlock();
result = Core::ERROR_NONE;

} else if ((currentState == IShell::state::DEACTIVATED) || (currentState == IShell::state::PRECONDITION)) {

// Load the interfaces, If we did not load them yet...
if (_handler == nullptr) {
Expand Down Expand Up @@ -397,10 +406,6 @@ namespace PluginHost

} else {

State(ACTIVATION);

Unlock();

// Before we dive into the "new" initialize lets see if this has a pending OOP running, if so forcefully kill it now, no time to wait !
if (_lastId != 0) {
_administrator.Destroy(_lastId);
Expand All @@ -410,6 +415,10 @@ namespace PluginHost
TRACE(Activity, (_T("Activation plugin [%s]:[%s]"), className.c_str(), callSign.c_str()));

_administrator.Initialize(callSign, this);

State(ACTIVATION);

Unlock();

REPORT_DURATION_WARNING( { ErrorMessage(_handler->Initialize(this)); }, WarningReporting::TooLongPluginState, WarningReporting::TooLongPluginState::StateChange::ACTIVATION, callSign.c_str());

Expand Down Expand Up @@ -478,18 +487,12 @@ namespace PluginHost

IShell::state currentState(State());

if (currentState == IShell::ACTIVATION) {
if (currentState == IShell::state::ACTIVATION) {
result = Core::ERROR_INPROGRESS;
} else if ((currentState == IShell::DEACTIVATION) || (currentState == IShell::DESTROYED)) {
} else if ((currentState == IShell::state::DEACTIVATION) || (currentState == IShell::state::DESTROYED)) {
result = Core::ERROR_ILLEGAL_STATE;
} else if (currentState == IShell::DEACTIVATED) {

Unlock();

} else if ( (currentState == IShell::state::DEACTIVATED) || (currentState == IShell::state::HIBERNATED) ) {
result = Activate(why);

Lock();

currentState = State();
}

Expand Down Expand Up @@ -521,11 +524,11 @@ namespace PluginHost

IShell::state currentState(State());

if (currentState == IShell::DEACTIVATION) {
if (currentState == IShell::state::DEACTIVATION) {
result = Core::ERROR_INPROGRESS;
} else if ((currentState == IShell::ACTIVATION && why != IShell::INITIALIZATION_FAILED) || (currentState == IShell::DESTROYED)) {
} else if ( ((currentState == IShell::state::ACTIVATION) && (why != IShell::reason::INITIALIZATION_FAILED)) || (currentState == IShell::state::HIBERNATED) || (currentState == IShell::state::DESTROYED)) {
result = Core::ERROR_ILLEGAL_STATE;
} else if ( (currentState == IShell::ACTIVATION && why == IShell::INITIALIZATION_FAILED) || (currentState == IShell::UNAVAILABLE) || (currentState == IShell::ACTIVATED) || (currentState == IShell::PRECONDITION)) {
} else if ( ((currentState == IShell::state::ACTIVATION) && (why == IShell::reason::INITIALIZATION_FAILED)) || (currentState == IShell::state::UNAVAILABLE) || (currentState == IShell::state::ACTIVATED) || (currentState == IShell::state::PRECONDITION)) {
const Core::EnumerateType<PluginHost::IShell::reason> textReason(why);

const string className(PluginHost::Service::Configuration().ClassName.Value());
Expand All @@ -552,7 +555,7 @@ namespace PluginHost
DisableWebServer();
}

if( currentState == IShell::ACTIVATED ) {
if( currentState == IShell::state::ACTIVATED ) {
TRACE(Activity, (_T("Deactivation plugin [%s]:[%s]"), className.c_str(), callSign.c_str()));
}

Expand All @@ -570,7 +573,7 @@ namespace PluginHost

}

if( currentState != IShell::ACTIVATION ) {
if( currentState != IShell::state::ACTIVATION ) {

SYSLOG(Logging::Shutdown, (_T("Deactivated plugin [%s]:[%s]"), className.c_str(), callSign.c_str()));

Expand Down Expand Up @@ -609,11 +612,11 @@ namespace PluginHost

IShell::state currentState(State());

if (currentState == IShell::DEACTIVATION) {
if (currentState == IShell::state::DEACTIVATION) {
result = Core::ERROR_INPROGRESS;
} else if ((currentState == IShell::ACTIVATION) || (currentState == IShell::DESTROYED)) {
} else if ((currentState == IShell::state::ACTIVATION) || (currentState == IShell::state::DESTROYED) || (currentState == IShell::state::HIBERNATED)) {
result = Core::ERROR_ILLEGAL_STATE;
} else if ((currentState == IShell::ACTIVATED) || (currentState == IShell::PRECONDITION)) {
} else if ((currentState == IShell::state::ACTIVATED) || (currentState == IShell::state::PRECONDITION)) {
// See if we need can and should SUSPEND.
IStateControl* stateControl = _handler->QueryInterface<PluginHost::IStateControl>();
if (stateControl == nullptr) {
Expand Down Expand Up @@ -641,14 +644,15 @@ namespace PluginHost

IShell::state currentState(State());

if ((currentState == IShell::DEACTIVATION) ||
(currentState == IShell::ACTIVATION) ||
(currentState == IShell::DESTROYED) ||
(currentState == IShell::ACTIVATED) ||
(currentState == IShell::PRECONDITION)) {
if ((currentState == IShell::state::DEACTIVATION) ||
(currentState == IShell::state::ACTIVATION) ||
(currentState == IShell::state::DESTROYED) ||
(currentState == IShell::state::ACTIVATED) ||
(currentState == IShell::state::PRECONDITION) ||
(currentState == IShell::state::HIBERNATED) ) {
result = Core::ERROR_ILLEGAL_STATE;
}
else if (currentState == IShell::DEACTIVATED) {
else if (currentState == IShell::state::DEACTIVATED) {

const Core::EnumerateType<PluginHost::IShell::reason> textReason(why);

Expand Down Expand Up @@ -677,6 +681,40 @@ namespace PluginHost

}

uint32_t Server::Service::Hibernate(const PluginHost::IShell::reason why) {
uint32_t result = Core::ERROR_NONE;

Lock();

IShell::state currentState(State());

if (currentState != IShell::state::ACTIVATED) {
result = Core::ERROR_ILLEGAL_STATE;
}
else if (_connection != nullptr) {
result = Core::ERROR_BAD_REQUEST;
}
else {
// Oke we have an Connection so there is something to Hibernate..
RPC::IMonitorableProcess* local = _connection->QueryInterface< RPC::IMonitorableProcess>();

if (local == nullptr) {
result = Core::ERROR_BAD_REQUEST;
}
else {
local->Release();
}
}
Unlock();

return (result);

}

void Server::Service::Wakeup() {
}


/* virtual */ uint32_t Server::Service::Submit(const uint32_t id, const Core::ProxyType<Core::JSON::IElement>& response)
{
return (_administrator.Submit(id, response));
Expand Down
3 changes: 3 additions & 0 deletions Source/WPEFramework/PluginServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -1055,6 +1055,8 @@ namespace PluginHost {
uint32_t Activate(const reason) override;
uint32_t Deactivate(const reason) override;
uint32_t Unavailable(const reason) override;
uint32_t Hibernate(const reason) override;

reason Reason() const override
{
return (_reason);
Expand All @@ -1076,6 +1078,7 @@ namespace PluginHost {
}

private:
void Wakeup();
virtual std::vector<string> GetLibrarySearchPaths(const string& locator) const override
{
std::vector<string> all_paths;
Expand Down
11 changes: 11 additions & 0 deletions Source/com/Communicator.h
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ namespace RPC {

Process(const uint32_t sequenceNumber, const Config& config, const Object& instance)
: _options(config.HostApplication())
, _id(0)
{
ASSERT(instance.Locator().empty() == false);
ASSERT(instance.ClassName().empty() == false);
Expand Down Expand Up @@ -410,6 +411,7 @@ namespace RPC {
Core::Process fork(false);

uint32_t result = fork.Launch(_options, &id);
_id = id;

//restore the original value
if (_systemRootPath.empty() == false) {
Expand All @@ -425,6 +427,9 @@ namespace RPC {

return (result);
}
Core::process_t Id() const {
return(_id);
}

private:
const std::vector<string>& DynamicLoaderPaths() const;
Expand Down Expand Up @@ -456,6 +461,7 @@ namespace RPC {
Core::Process::Options _options;
int8_t _priority;
string _systemRootPath;
Core::process_t _id;
static Core::CriticalSection _ldLibLock;
};

Expand All @@ -465,6 +471,7 @@ namespace RPC {
~IMonitorableProcess() override = default;

virtual string Callsign() const = 0;
virtual Core::instance_id ParentPID() const = 0;
};

class EXTERNAL Communicator {
Expand Down Expand Up @@ -588,6 +595,10 @@ namespace RPC {
{
return (_process.Options());
}
Core::instance_id ParentPID() const override {
return (static_cast<const Core::instance_id>(_process.Id()));
}

void PostMortem() override;

private:
Expand Down
2 changes: 1 addition & 1 deletion Source/core/JSON.h
Original file line number Diff line number Diff line change
Expand Up @@ -1623,7 +1623,7 @@ namespace Core {
inline const string Value() const
{
if ((_flagsAndCounters & (SetBit | QuoteFoundBit | QuotedSerializeBit)) == (SetBit | QuoteFoundBit)) {
return ('\"' + Core::ToString(_value.c_str()) + '\"');
return (Core::ToQuotedString('\"', _value));
}
return (((_flagsAndCounters & (SetBit | NullBit)) == SetBit) ? Core::ToString(_value.c_str()) : Core::ToString(_default.c_str()));
}
Expand Down
Loading

0 comments on commit a25c4a9

Please sign in to comment.