Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow jsonrpc for plugin suspend/resume #1799

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions Source/Thunder/Controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ namespace Plugin {
result->Message = _T("There is no callsign: ") + callSign;
}
}
}
}
} else if (index.Current() == _T("Unavailable")) {
if (index.Next()) {
const string callSign(index.Current().Text());
Expand Down Expand Up @@ -918,7 +918,6 @@ namespace Plugin {
if (_pluginServer->Services().FromIdentifier(callsign, service) == Core::ERROR_NONE) {
ASSERT(service.IsValid());
result = service->Deactivate(PluginHost::IShell::REQUESTED);

// Normalise return code
if ((result != Core::ERROR_NONE) && (result != Core::ERROR_ILLEGAL_STATE) && (result != Core::ERROR_INPROGRESS)) {
result = Core::ERROR_CLOSING_FAILED;
Expand Down Expand Up @@ -966,7 +965,7 @@ namespace Plugin {
{
Core::hresult result = Core::ERROR_NONE;
ASSERT(_pluginServer != nullptr);

if (callsign != Callsign()) {
Core::ProxyType<PluginHost::IShell> service;

Expand All @@ -979,6 +978,7 @@ namespace Plugin {
}
else {
result = stateControl->Request(PluginHost::IStateControl::command::SUSPEND);
NotifySuspendResumeStateChange(callsign, Exchange::Controller::ILifeTime::state::SUSPENDED);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is too early, we can only do so if the state is indeed changed. You know that if you would subscribe to the IStateControl::INotification interface. What if the Suspend or Resume fails ?
Lets have a broader discussion on this if we want this as this has some severe impact..

stateControl->Release();
}
}
Expand All @@ -989,7 +989,6 @@ namespace Plugin {
else {
result = Core::ERROR_PRIVILIGED_REQUEST;
}

return result;
}

Expand All @@ -1010,6 +1009,7 @@ namespace Plugin {
}
else {
result = stateControl->Request(PluginHost::IStateControl::command::RESUME);
NotifySuspendResumeStateChange(callsign, Exchange::Controller::ILifeTime::state::RESUMED);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is too early, we can only do so if the state is indeed changed. You know that if you would subscribe to the IStateControl::INotification interface. What if the Suspend or Resume fails ?
Lets have a broader discussion on this if we want this as this has some severe impact..

stateControl->Release();
}
}
Expand Down Expand Up @@ -1347,24 +1347,36 @@ namespace Plugin {

return (Core::ERROR_NONE);
}

void Controller::NotifyStateChange(const string& callsign, const PluginHost::IShell::state& state, const PluginHost::IShell::reason& reason)
{
_adminLock.Lock();

LifeTimeNotifiers::const_iterator index = _lifeTimeObservers.begin();

while(index != _lifeTimeObservers.end()) {
(*index)->StateChange(callsign, state, reason);
index++;
}

_adminLock.Unlock();

// also notify the JSON RPC listeners (if any)
Exchange::Controller::JLifeTime::Event::StateChange(*this, callsign, state, reason);
}

void Controller::NotifySuspendResumeStateChange(const string& callsign, const Exchange::Controller::ILifeTime::state& state)
{
_adminLock.Lock();

LifeTimeNotifiers::const_iterator index = _lifeTimeObservers.begin();
while(index != _lifeTimeObservers.end()) {
(*index)->SuspendResumeStateChange(callsign, state);
index++;
}

_adminLock.Unlock();
// also notify the JSON RPC listeners (if any)
Exchange::Controller::JLifeTime::Event::SuspendResumeStateChange(*this, callsign, state);
}

Core::hresult Controller::BuildInfo(IMetadata::Data::BuildInfo& buildInfo) const
{
#if defined(__WINDOWS__)
Expand Down
3 changes: 1 addition & 2 deletions Source/Thunder/Controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,8 @@ namespace Plugin {
void Activated(const string& callsign, PluginHost::IShell* plugin) override
{
_parent.NotifyStateChange(callsign, PluginHost::IShell::ACTIVATED, plugin->Reason());

// Make sure the resumes
_parent.StartupResume(callsign, plugin);

}
void Deactivated(const string& callsign, PluginHost::IShell* plugin) override
{
Expand Down Expand Up @@ -381,6 +379,7 @@ namespace Plugin {
Core::ProxyType<Web::Response> DeleteMethod(Core::TextSegmentIterator& index, const Web::Request& request);
void StartupResume(const string& callsign, PluginHost::IShell* plugin);
void NotifyStateChange(const string& callsign, const PluginHost::IShell::state& state, const PluginHost::IShell::reason& reason);
void NotifySuspendResumeStateChange(const string& callsign, const Exchange::Controller::ILifeTime::state& state);

private:
Core::CriticalSection _adminLock;
Expand Down
1 change: 0 additions & 1 deletion Source/Thunder/PluginServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,6 @@ namespace PluginHost {

uint32_t Server::Service::Resume(const reason why) /* override */ {
uint32_t result = Core::ERROR_NONE;

Lock();

IShell::state currentState(State());
Expand Down
2 changes: 1 addition & 1 deletion Source/Thunder/PluginServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,6 @@ namespace PluginHost {
ASSERT(plugin != nullptr);
_parent._administrator.Unavailable(link + PluginHost::ICompositPlugin::Delimiter + callsign, plugin);
}

BEGIN_INTERFACE_MAP(Composit)
INTERFACE_ENTRY(PluginHost::ICompositPlugin::ICallback)
END_INTERFACE_MAP
Expand Down Expand Up @@ -2829,6 +2828,7 @@ namespace PluginHost {
}
void Activated(const string& callsign, PluginHost::IShell* entry)
{

_notificationLock.Lock();

Notifiers::iterator index(_notifiers.begin());
Expand Down
13 changes: 12 additions & 1 deletion Source/plugins/IController.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,26 @@ namespace Controller {
struct EXTERNAL ILifeTime : virtual public Core::IUnknown {
enum { ID = RPC::ID_CONTROLLER_LIFETIME };

enum state : uint8_t {
SUSPENDED,
RESUMED
};

// @event
struct EXTERNAL INotification : virtual public Core::IUnknown {
enum { ID = RPC::ID_CONTROLLER_LIFETIME_NOTIFICATION };

// @brief Notifies of a plugin state change
// @brief Notifies of a plugin state change controlled by Thunder
// @param callsign: Plugin callsign
// @param state: New state of the plugin
// @param reason: Reason for state change
virtual void StateChange(const string& callsign, const PluginHost::IShell::state& state, const PluginHost::IShell::reason& reason) = 0;

// @brief Notifies of a plugin state change controlled by the plugin
// @param callsign: Plugin callsign
// @param state: New state of the plugin
// @param reason: Reason for state change
virtual void SuspendResumeStateChange(const string& callsign, const state& state) = 0;
};

virtual Core::hresult Register(INotification* sink) = 0;
Expand Down
2 changes: 1 addition & 1 deletion Source/plugins/IShell.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ namespace PluginHost {
ACTIVATION,
PRECONDITION,
HIBERNATED,
DESTROYED
DESTROYED,
};

enum class startmode : uint8_t {
Expand Down
Loading