Skip to content

Commit

Permalink
[INTERFACE] Prepare for the upcoming IDispatcher Interface changes fo…
Browse files Browse the repository at this point in the history
…r R5! (#1664)
  • Loading branch information
pwielders authored Jun 24, 2024
1 parent 5466cf9 commit d36af08
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 50 deletions.
31 changes: 21 additions & 10 deletions Source/Thunder/PluginServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,17 +416,18 @@ namespace PluginHost {

SYSLOG(Logging::Startup, (_T("Activation of plugin [%s]:[%s], failed. Error [%s]"), className.c_str(), callSign.c_str(), ErrorMessage().c_str()));

_reason = reason::INITIALIZATION_FAILED;
_administrator.Deinitialized(callSign, this);

if( _administrator.Configuration().LegacyInitialize() == false ) {
Deactivate(reason::INITIALIZATION_FAILED);
} else {
_reason = reason::INITIALIZATION_FAILED;
_administrator.Deinitialized(callSign, this);
Lock();
ReleaseInterfaces();
State(DEACTIVATED);
Unlock();
REPORT_DURATION_WARNING({ _handler->Deinitialize(this); }, WarningReporting::TooLongPluginState, WarningReporting::TooLongPluginState::StateChange::DEACTIVATION, callSign.c_str());
}

Lock();
ReleaseInterfaces();
State(DEACTIVATED);
Unlock();

} else {
const Core::EnumerateType<PluginHost::IShell::reason> textReason(why);
const string webUI(PluginHost::Service::Configuration().WebUI.Value());
Expand All @@ -435,7 +436,12 @@ namespace PluginHost {
}

if (_jsonrpc != nullptr) {
_jsonrpc->Activate(this);
PluginHost::IShell::IConnectionServer::INotification* sink = nullptr;
_jsonrpc->Attach(sink, this);
if (sink != nullptr) {
Register(sink);
sink->Release();
}
}

if (_external.Connector().empty() == false) {
Expand Down Expand Up @@ -579,7 +585,12 @@ namespace PluginHost {
Lock();

if (_jsonrpc != nullptr) {
_jsonrpc->Deactivate();
PluginHost::IShell::IConnectionServer::INotification* sink = nullptr;
_jsonrpc->Detach(sink);
if (sink != nullptr) {
Unregister(sink);
sink->Release();
}
}

if (_external.Connector().empty() == false) {
Expand Down
8 changes: 3 additions & 5 deletions Source/Thunder/PluginServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -1439,10 +1439,8 @@ namespace PluginHost {
_textSocket = newIF->QueryInterface<ITextSocket>();
_rawSocket = newIF->QueryInterface<IChannel>();
_webSecurity = newIF->QueryInterface<ISecurity>();
IDispatcher* jsonrpc = newIF->QueryInterface<IDispatcher>();
if (jsonrpc != nullptr) {
_jsonrpc = jsonrpc->Local();
}
_jsonrpc = newIF->QueryInterface<IDispatcher>();

_composit.AquireInterfaces(newIF);
if (_webSecurity == nullptr) {
_webSecurity = _administrator.Configuration().Security();
Expand Down Expand Up @@ -1540,7 +1538,7 @@ namespace PluginHost {
ITextSocket* _textSocket;
IChannel* _rawSocket;
ISecurity* _webSecurity;
ILocalDispatcher* _jsonrpc;
IDispatcher* _jsonrpc;
reason _reason;
Condition _precondition;
Condition _termination;
Expand Down
2 changes: 1 addition & 1 deletion Source/plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ ProxyStubGenerator(NAMESPACE "Thunder::PluginHost" INPUT "${CMAKE_CURRENT_SOURCE
ProxyStubGenerator(NAMESPACE "Thunder::Exchange" INPUT "${CMAKE_CURRENT_SOURCE_DIR}/IController.h" OUTDIR "${CMAKE_CURRENT_BINARY_DIR}/generated" INCLUDE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/..")
ProxyStubGenerator(NAMESPACE "Thunder::PluginHost" INPUT "${CMAKE_CURRENT_SOURCE_DIR}/IStateControl.h" OUTDIR "${CMAKE_CURRENT_BINARY_DIR}/generated")
ProxyStubGenerator(NAMESPACE "Thunder::PluginHost" INPUT "${CMAKE_CURRENT_SOURCE_DIR}/ISubSystem.h" OUTDIR "${CMAKE_CURRENT_BINARY_DIR}/generated")
ProxyStubGenerator(NAMESPACE "Thunder::PluginHost" INPUT "${CMAKE_CURRENT_SOURCE_DIR}/IDispatcher.h" OUTDIR "${CMAKE_CURRENT_BINARY_DIR}/generated")
ProxyStubGenerator(NAMESPACE "Thunder::PluginHost" INPUT "${CMAKE_CURRENT_SOURCE_DIR}/IDispatcher.h" OUTDIR "${CMAKE_CURRENT_BINARY_DIR}/generated" INCLUDE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/..")

JsonGenerator(CODE NAMESPACE Thunder::Exchange::Controller INPUT ${CMAKE_CURRENT_SOURCE_DIR}/IController.h OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/json" INCLUDE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/.." NO_INCLUDES)

Expand Down
25 changes: 13 additions & 12 deletions Source/plugins/IDispatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@
* limitations under the License.
*/

#ifndef __IDISPATCHER_H__
#define __IDISPATCHER_H__
#pragma once

#include <com/ICOM.h>
#include "IShell.h"

// @stubgen:include <plugins/IShell.h>

namespace Thunder {

namespace PluginHost {

struct EXTERNAL ILocalDispatcher;

struct EXTERNAL IDispatcher : public virtual Core::IUnknown {
~IDispatcher() override = default;

Expand All @@ -46,14 +46,15 @@ namespace Thunder {
virtual Core::hresult Subscribe(ICallback* callback, const string& event, const string& designator) = 0;
virtual Core::hresult Unsubscribe(ICallback* callback, const string& event, const string& designator) = 0;

// If this is a local instance of this interface, we get access to the IShell
// of this service which in turn allows access to the channels and thus the
// possibility to return responses on the right JSONRPC channels.
/* @stubgen:stub */
virtual ILocalDispatcher* Local() = 0;
// Lifetime managment of the IDispatcher.
// Attach is to be called prior to receiving JSONRPC requests!
// Detach is to be called if the service is nolonger required!
virtual Core::hresult Attach(IShell::IConnectionServer::INotification*& sink /* @out */, IShell* service) = 0;
virtual Core::hresult Detach(IShell::IConnectionServer::INotification*& sink /* @out */) = 0;

// If a callback is unexpectedly dropepd (non-happy day scenarios) it is reported through this
// method that all subscribtions for a certain callback can be dropped..
virtual void Dropped(const ICallback* callback) = 0;
};
}

}

#endif
33 changes: 11 additions & 22 deletions Source/plugins/JSONRPC.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,7 @@ namespace Thunder {

namespace PluginHost {

struct EXTERNAL ILocalDispatcher : public IDispatcher {
virtual ~ILocalDispatcher() = default;

virtual void Activate(IShell* service) = 0;
virtual void Deactivate() = 0;
virtual void Dropped(const IDispatcher::ICallback* callback) = 0;
};

class EXTERNAL JSONRPC : public ILocalDispatcher {
class EXTERNAL JSONRPC : public IDispatcher {
public:
using SendIfMethod = std::function<bool(const string&)>;

Expand Down Expand Up @@ -710,13 +702,8 @@ namespace PluginHost {

return (result);
}
ILocalDispatcher* Local() override {
return (this);
}

// Inherited via ILocalDispatcher
// ---------------------------------------------------------------------------------
void Activate(IShell* service) override
Core::hresult Attach(IShell::IConnectionServer::INotification*& sink /* @out */, IShell* service) override
{
ASSERT(_service == nullptr);
ASSERT(service != nullptr);
Expand All @@ -727,24 +714,26 @@ namespace PluginHost {
_service->AddRef();
_callsign = _service->Callsign();

_service->Register(&_notification);
sink = &_notification;
sink->AddRef();

_adminLock.Unlock();

return (Core::ERROR_NONE);
}
void Deactivate() override
Core::hresult Detach(IShell::IConnectionServer::INotification*& sink /* @out */) override
{
_adminLock.Lock();

if (_service != nullptr) {
_service->Unregister(&_notification);
_service->Release();
_service = nullptr;
}
sink = &_notification;
sink->AddRef();

_callsign.clear();
_observers.clear();

_adminLock.Unlock();

return (Core::ERROR_NONE);
}

// Inherited via IDispatcher::ICallback
Expand Down

0 comments on commit d36af08

Please sign in to comment.