Skip to content

Commit 087dcae

Browse files
authored
[PRUNING] Cleanup of the "all" event mechanism sending out RESTFULL notifications and JSONRPC events. (#1667)
1 parent d36af08 commit 087dcae

File tree

9 files changed

+55
-152
lines changed

9 files changed

+55
-152
lines changed

Source/Thunder/Controller.cpp

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -738,9 +738,7 @@ namespace Plugin {
738738

739739
void Controller::SubSystems()
740740
{
741-
#if THUNDER_RESTFULL_API || defined(__DEBUG__)
742741
PluginHost::Metadata response;
743-
#endif
744742
Core::JSON::ArrayType<JsonData::Subsystems::SubsystemInfo> responseJsonRpc;
745743
PluginHost::ISubSystem* subSystem = _service->SubSystems();
746744

@@ -763,10 +761,7 @@ namespace Plugin {
763761
status.Subsystem = current;
764762
status.Active = ((reportMask & bit) != 0);
765763
responseJsonRpc.Add(status);
766-
767-
#if THUNDER_RESTFULL_API || defined(__DEBUG__)
768764
response.SubSystems.Add(current, ((reportMask & bit) != 0));
769-
#endif
770765

771766
sendReport = true;
772767
}
@@ -781,15 +776,11 @@ namespace Plugin {
781776

782777
if (sendReport == true) {
783778

784-
#if THUNDER_RESTFULL_API || defined(__DEBUG__)
785779
string message;
786780
response.ToString(message);
787781
TRACE_L1("Sending out a SubSystem change notification. %s", message.c_str());
788-
#endif
789782

790-
#if THUNDER_RESTFULL_API
791-
_pluginServer->_controller->Notification(message);
792-
#endif
783+
_service->Notify(EMPTY_STRING, message);
793784

794785
Exchange::Controller::JSubsystems::Event::SubsystemChange(*this, responseJsonRpc);
795786
}
@@ -1110,10 +1101,7 @@ namespace Plugin {
11101101
service.Configuration = meta.Configuration;
11111102
service.Precondition = meta.Precondition;
11121103
service.Termination = meta.Termination;
1113-
1114-
#if THUNDER_RESTFULL_API
11151104
service.Observers = meta.Observers;
1116-
#endif
11171105

11181106
#if THUNDER_RUNTIME_STATISTICS
11191107
service.ProcessedRequests = meta.ProcessedRequests;

Source/Thunder/Controller.h

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -210,23 +210,6 @@ namespace Plugin {
210210
}
211211
}
212212

213-
void Notification(const string& callsign, const string& message)
214-
{
215-
ASSERT(callsign.empty() == false);
216-
ASSERT(message.empty() == false);
217-
218-
Exchange::Controller::JEvents::Event::ForwardMessage(*this, callsign, message);
219-
}
220-
221-
void Notification(const string& callsign, const string& event, const string& params)
222-
{
223-
ASSERT(callsign.empty() == false);
224-
ASSERT(event.empty() == false);
225-
226-
Exchange::Controller::IEvents::INotification::Event data{event, params};
227-
Exchange::Controller::JEvents::Event::ForwardEvent(*this, callsign, data);
228-
}
229-
230213
inline void SetServer(PluginHost::Server* pluginServer, const std::vector<PluginHost::ISubSystem::subsystem>& externalSubsystems)
231214
{
232215
ASSERT((_pluginServer == nullptr) && (pluginServer != nullptr));

Source/Thunder/PluginHost.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -774,10 +774,7 @@ POP_WARNING()
774774
printf("Locator: %s\n", index.Current().Locator.Value().c_str());
775775
printf("Classname: %s\n", index.Current().ClassName.Value().c_str());
776776
printf("StartMode: %s\n", index.Current().StartMode.Data());
777-
#if THUNDER_RESTFULL_API
778-
779777
printf("Observers: %d\n", index.Current().Observers.Value());
780-
#endif
781778

782779
#if THUNDER_RUNTIME_STATISTICS
783780
printf("Requests: %d\n", index.Current().ProcessedRequests.Value());

Source/Thunder/PluginServer.cpp

Lines changed: 34 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,14 @@ namespace PluginHost {
298298
AddRef();
299299
result = static_cast<PluginHost::IShell::IConnectionServer*>(this);
300300
}
301+
else if (id == PluginHost::IDispatcher::ID) {
302+
_pluginHandling.Lock();
303+
if (_jsonrpc != nullptr) {
304+
_jsonrpc->AddRef();
305+
result = _jsonrpc;
306+
}
307+
_pluginHandling.Unlock();
308+
}
301309
else {
302310
_pluginHandling.Lock();
303311

@@ -456,19 +464,15 @@ namespace PluginHost {
456464
State(ACTIVATED);
457465
_administrator.Activated(callSign, this);
458466

459-
#if THUNDER_RESTFULL_API
460-
_administrator.Notification(_T("{\"callsign\":\"") + callSign + _T("\",\"state\":\"deactivated\",\"reason\":\"") + textReason.Data() + _T("\"}"));
461-
#endif
462-
463-
_administrator.Notification(callSign, string(_T("{\"state\":\"activated\",\"reason\":\"")) + textReason.Data() + _T("\"}"));
464-
465467
IStateControl* stateControl = nullptr;
466468
if ((Resumed() == true) && ((stateControl = _handler->QueryInterface<PluginHost::IStateControl>()) != nullptr)) {
467469

468470
stateControl->Request(PluginHost::IStateControl::RESUME);
469471
stateControl->Release();
470472
}
471473

474+
Notify(EMPTY_STRING, string(_T("{\"state\":\"activated\",\"reason\":\"")) + textReason.Data() + _T("\"}"));
475+
472476
Unlock();
473477
}
474478
}
@@ -600,12 +604,7 @@ namespace PluginHost {
600604
if (currentState != IShell::state::ACTIVATION) {
601605
SYSLOG(Logging::Shutdown, (_T("Deactivated plugin [%s]:[%s]"), className.c_str(), callSign.c_str()));
602606

603-
#if THUNDER_RESTFULL_API
604-
_administrator.Notification(_T("{\"callsign\":\"") + callSign + _T("\",\"state\":\"deactivated\",\"reason\":\"") + textReason.Data() + _T("\"}"));
605-
#endif
606-
607-
_administrator.Notification(callSign, string(_T("{\"state\":\"deactivated\",\"reason\":\"")) + textReason.Data() + _T("\"}"));
608-
607+
Notify(EMPTY_STRING, string(_T("{\"state\":\"deactivated\",\"reason\":\"")) + textReason.Data() + _T("\"}"));
609608
}
610609
}
611610

@@ -691,11 +690,7 @@ namespace PluginHost {
691690
State(UNAVAILABLE);
692691
_administrator.Unavailable(callSign, this);
693692

694-
#if THUNDER_RESTFULL_API
695-
_administrator.Notification(_T("{\"callsign\":\"") + callSign + _T("\",\"state\":\"unavailable\",\"reason\":\"") + textReason.Data() + _T("\"}"));
696-
#endif
697-
698-
_administrator.Notification(callSign, string(_T("{\"state\":\"unavailable\",\"reason\":\"")) + textReason.Data() + _T("\"}"));
693+
Notify(EMPTY_STRING, string(_T("{\"state\":\"unavailable\",\"reason\":\"")) + textReason.Data() + _T("\"}"));
699694
}
700695

701696
Unlock();
@@ -899,19 +894,15 @@ namespace PluginHost {
899894
return (_administrator.SubSystemsInterface(this));
900895
}
901896

902-
void Server::Service::Notify(const string& message) /* override */
897+
void Server::Service::Notify(const string& jsonrpcEvent, const string& message) /* override */
903898
{
904-
#if THUNDER_RESTFULL_API
905-
// Notify the base class and the subscribers
906-
PluginHost::Service::Notification(message);
907-
#endif
908-
909-
_administrator.Notification(PluginHost::Service::Callsign(), message);
910-
}
899+
// JSONRPC has been send by now, lets send it to the "notification"
900+
// observers..
901+
if (jsonrpcEvent.empty() == true) {
902+
BaseClass::Notification(message);
903+
}
911904

912-
void Server::Service::Notify(const string& event, const string& parameters) /* override */
913-
{
914-
_administrator.Notification(PluginHost::Service::Callsign(), event, parameters);
905+
_administrator.Notification(PluginHost::Service::Callsign(), jsonrpcEvent, message);
915906
}
916907

917908
//
@@ -1193,46 +1184,27 @@ namespace PluginHost {
11931184
IFactories::Assign(nullptr);
11941185
}
11951186

1196-
void Server::Notification(const string& callsign, const string& data)
1187+
void Server::Notification(const string& callsign, const string& jsonrpc_event, const string& parameters)
11971188
{
1198-
Plugin::Controller* controller;
1199-
if ((_controller.IsValid() == true) && ((controller = (_controller->ClassType<Plugin::Controller>())) != nullptr)) {
1200-
1201-
controller->Notification(callsign, data);
1202-
1203-
#if THUNDER_RESTFULL_API
1204-
JsonData::Events::ForwardMessageParamsData message;
1205-
message.Callsign = callsign;
1206-
message.Data = data;
1207-
string messageString;
1208-
message.ToString(messageString);
1209-
_controller->Notification(messageString);
1210-
#endif
1211-
}
1212-
}
1189+
ASSERT((_controller.IsValid() == true) && (_controller->ClassType<Plugin::Controller>() != nullptr));
12131190

1214-
void Server::Notification(const string& callsign, const string& event, const string& parameters)
1215-
{
1216-
if (_controller.IsValid() == true) {
1217-
Plugin::Controller* controller = _controller->ClassType<Plugin::Controller>();
1191+
Plugin::Controller* controller = _controller->ClassType<Plugin::Controller>();
12181192

1219-
if (controller != nullptr) {
1220-
static const TCHAR allEvent[] = _T("all");
1193+
// Break a recursive loop, if it tries to arise ;-)
1194+
if ( (controller != nullptr) && (callsign != controller->Callsign()) ) {
12211195

1222-
if ((callsign != controller->Callsign()) || (event != allEvent)) {
1196+
ASSERT(callsign.empty() == false);
12231197

1224-
controller->Notification(callsign, event, parameters);
1198+
if (jsonrpc_event.empty() == false) {
1199+
JsonData::Events::ForwardEventParamsData message;
1200+
message.Data = Exchange::Controller::IEvents::INotification::Event({ jsonrpc_event, parameters });
1201+
message.Callsign = callsign;
1202+
Exchange::Controller::JEvents::Event::ForwardEvent(*controller, message);
1203+
}
1204+
else {
1205+
string messageString = string(_T("{\"callsign\":\"")) + callsign + _T("\", {\"data\":\"") + parameters + _T("\"}}");
12251206

1226-
#if THUNDER_RESTFULL_API
1227-
JsonData::Events::ForwardEventParamsData message;
1228-
message.Callsign = callsign;
1229-
message.Data.Event = event;
1230-
message.Data.Params = parameters;
1231-
string messageString;
1232-
message.ToString(messageString);
1233-
_controller->Notification(messageString);
1234-
#endif
1235-
}
1207+
_controller->Notify(EMPTY_STRING, messageString);
12361208
}
12371209
}
12381210
}

Source/Thunder/PluginServer.h

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@ namespace PluginHost {
320320
};
321321

322322
private:
323+
using BaseClass = PluginHost::Service;
323324
class Composit : public PluginHost::ICompositPlugin::ICallback {
324325
public:
325326
Composit() = delete;
@@ -811,27 +812,17 @@ namespace PluginHost {
811812
}
812813
inline bool Subscribe(Channel& channel)
813814
{
814-
#if THUNDER_RESTFULL_API
815815
bool result = PluginHost::Service::Subscribe(channel);
816816

817817
if ((result == true) && (_extended != nullptr)) {
818818
_extended->Attach(channel);
819819
}
820820

821821
return (result);
822-
#else
823-
if (_extended != nullptr) {
824-
_extended->Attach(channel);
825-
}
826-
827-
return (_extended != nullptr);
828-
#endif
829822
}
830823
inline void Unsubscribe(Channel& channel)
831824
{
832-
#if THUNDER_RESTFULL_API
833825
PluginHost::Service::Unsubscribe(channel);
834-
#endif
835826

836827
if (_extended != nullptr) {
837828
_extended->Detach(channel);
@@ -1156,8 +1147,7 @@ namespace PluginHost {
11561147

11571148
uint32_t Submit(const uint32_t id, const Core::ProxyType<Core::JSON::IElement>& response) override;
11581149
ISubSystem* SubSystems() override;
1159-
void Notify(const string& message) override;
1160-
void Notify(const string& event, const string& parameters) override;
1150+
void Notify(const string& event, const string& message) override;
11611151
void* QueryInterface(const uint32_t id) override;
11621152
void* QueryInterfaceByCallsign(const uint32_t id, const string& name) override;
11631153
template <typename REQUESTEDINTERFACE>
@@ -2981,20 +2971,10 @@ namespace PluginHost {
29812971

29822972
return (Iterator(std::move(workingList)));
29832973
}
2984-
inline void Notification(const string& callsign, const string& message)
2974+
inline void Notification(const string& callsign, const string& jsonrpc_event, const string& message)
29852975
{
2986-
_server.Notification(callsign, message);
2976+
_server.Notification(callsign, jsonrpc_event, message);
29872977
}
2988-
inline void Notification(const string& callsign, const string& event, const string& message)
2989-
{
2990-
_server.Notification(callsign, event, message);
2991-
}
2992-
#if THUNDER_RESTFULL_API
2993-
inline void Notification(const string& message)
2994-
{
2995-
_server.Controller()->Notification(message);
2996-
}
2997-
#endif
29982978
void GetMetadata(Core::JSON::ArrayType<Metadata::Service>& metaData) const
29992979
{
30002980
std::vector<Core::ProxyType<Service>> workingList;
@@ -4451,8 +4431,7 @@ namespace PluginHost {
44514431
return (_config);
44524432
}
44534433

4454-
void Notification(const string& callsign, const string& message);
4455-
void Notification(const string& callsign, const string& event, const string& message);
4434+
void Notification(const string& callsign, const string& jsonrpc_event, const string& message);
44564435
void Open();
44574436
void Close();
44584437

Source/plugins/IShell.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -252,10 +252,12 @@ namespace PluginHost {
252252
virtual ISubSystem* SubSystems() = 0;
253253

254254
// Notify all subscribers of this service with the given string.
255-
// It is expected to be JSON formatted strings as it is assumed that this is for reaching websockets clients living in
256-
// the web world that have build in functionality to parse JSON structs.
257-
virtual void Notify(const string& message) = 0;
258-
virtual void Notify(const string& event, const string& parameters) = 0;
255+
// It is expected to be JSON formatted strings (message) as it is assumed that this is for reaching websockets clients
256+
// living in the web world that have build in functionality to parse JSON structs.
257+
void Notify(const string& message) {
258+
Notify(EMPTY_STRING, message);
259+
}
260+
virtual void Notify(const string& event, const string& message) = 0;
259261

260262
// Allow access to the Shells, configured for the different Plugins found in the configuration.
261263
// Calling the QueryInterfaceByCallsign with an empty callsign will query for interfaces located

Source/plugins/Metadata.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,7 @@ namespace PluginHost
112112
, ProcessedRequests(0)
113113
, ProcessedObjects(0)
114114
#endif
115-
#if THUNDER_RESTFULL_API
116115
, Observers(0)
117-
#endif
118116
, ServiceVersion()
119117
, Module()
120118
, InterfaceVersion()
@@ -124,9 +122,7 @@ namespace PluginHost
124122
Add(_T("processedrequests"), &ProcessedRequests);
125123
Add(_T("processedobjects"), &ProcessedObjects);
126124
#endif
127-
#if THUNDER_RESTFULL_API
128125
Add(_T("observers"), &Observers);
129-
#endif
130126
Add(_T("module"), &Module);
131127
Add(_T("version"), &ServiceVersion);
132128
Add(_T("interface"), &InterfaceVersion);
@@ -138,9 +134,7 @@ namespace PluginHost
138134
, ProcessedRequests(std::move(move.ProcessedRequests))
139135
, ProcessedObjects(std::move(move.ProcessedObjects))
140136
#endif
141-
#if THUNDER_RESTFULL_API
142137
, Observers(std::move(move.Observers))
143-
#endif
144138
, ServiceVersion(std::move(move.ServiceVersion))
145139
, Module(std::move(move.Module))
146140
, InterfaceVersion(std::move(move.InterfaceVersion))

Source/plugins/Service.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,24 +67,19 @@ namespace PluginHost {
6767
return (Core::ProxyType<Core::IDispatch>(Core::ProxyType<IShell::Job>::Create(shell, toState, why)));
6868
}
6969

70-
#if THUNDER_RESTFULL_API
7170
void Service::Notification(const string& message)
7271
{
7372
_notifierLock.Lock();
7473

7574
ASSERT(message.empty() != true);
7675
{
77-
std::list<Channel*>::iterator index(_notifiers.begin());
78-
79-
while (index != _notifiers.end()) {
80-
(*index)->Submit(message);
81-
index++;
76+
for (auto entry : _notifiers) {
77+
entry->Submit(message);
8278
}
8379
}
8480

8581
_notifierLock.Unlock();
8682
}
87-
#endif
8883

8984
void Service::FileToServe(const string& webServiceRequest, Web::Response& response, bool allowUnsafePath)
9085
{

0 commit comments

Comments
 (0)