Skip to content

Commit

Permalink
Development/linked thunders (rdkcentral#1461)
Browse files Browse the repository at this point in the history
* [JSONRPC] Complete the work to handle JSONRPC over COMRPC so WPEFrameworks can be linked together.

* Merge! (rdkcentral#1460)

* Adding a missing Closing of the new messaging redirect feature (rdkcentral#1452)

* Update vscode configs (rdkcentral#1451)

Co-authored-by: Pierre Wielders <[email protected]>

* [docs]: Add 'Time' documentation. (rdkcentral#1432)

* [docs]: Add 'Time' documentation.

METROL-847

* [docs]: Update 'Time' documentation.

METROL-847 and PR-1432

---------

Co-authored-by: Pierre Wielders <[email protected]>
Co-authored-by: Wouter Meek <[email protected]>
Co-authored-by: MFransen69 <[email protected]>

* Terminate after signal (rdkcentral#1459)

---------

Co-authored-by: Mateusz Daniluk <[email protected]>
Co-authored-by: Bram Oosterhuis <[email protected]>
Co-authored-by: msieben <[email protected]>
Co-authored-by: Wouter Meek <[email protected]>
Co-authored-by: MFransen69 <[email protected]>
Co-authored-by: sebaszm <[email protected]>

* [SYNC] Fixes for linux.

* [SYNC] Merging issues resolved..

* [TESTS] Fixes after testing and including the merges!

* [FIXES] Compilation issue resolving.

* Update CMakeLists.txt

* Update CMakeLists.txt

* Update MetaData.h

* Update PluginServer.h

---------

Co-authored-by: Mateusz Daniluk <[email protected]>
Co-authored-by: Bram Oosterhuis <[email protected]>
Co-authored-by: msieben <[email protected]>
Co-authored-by: Wouter Meek <[email protected]>
Co-authored-by: MFransen69 <[email protected]>
Co-authored-by: sebaszm <[email protected]>
  • Loading branch information
7 people committed Apr 26, 2024
1 parent 8cb5dc3 commit f53d11e
Show file tree
Hide file tree
Showing 24 changed files with 1,299 additions and 1,317 deletions.
83 changes: 45 additions & 38 deletions Source/WPEFramework/Controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@
#include "Controller.h"
#include "SystemInfo.h"

#include "JsonData_SystemManagement.h"
#include "JsonData_LifeTime.h"
#include "JsonData_Discovery.h"
#include "JsonData_Metadata.h"
#include <plugins/json/JsonData_SystemManagement.h>
#include <plugins/json/JsonData_LifeTime.h>
#include <plugins/json/JsonData_Discovery.h>
#include <plugins/json/JsonData_Metadata.h>

#include "JDiscovery.h"
#include "JConfiguration.h"
#include "JSystemManagement.h"
#include "JLifeTime.h"
#include "JMetadata.h"
#include <plugins/json/JDiscovery.h>
#include <plugins/json/JConfiguration.h>
#include <plugins/json/JSystemManagement.h>
#include <plugins/json/JLifeTime.h>
#include <plugins/json/JMetadata.h>

namespace WPEFramework {

Expand Down Expand Up @@ -380,17 +380,15 @@ namespace Plugin {
Core::ProxyType<Web::JSONBodyType<PluginHost::MetaData>> response(jsonBodyMetaDataFactory.Element());

// No more parameters, flush it all..
_pluginServer->Dispatcher().GetMetaData(response->Channels);
_pluginServer->Services().GetMetaData(response->Channels);
_pluginServer->Services().GetMetaData(response->Plugins);
_pluginServer->Metadata(response->Channels);
_pluginServer->Metadata(response->Plugins);
WorkerPoolMetaData(response->Process);

result->Body(Core::ProxyType<Web::IBody>(response));
} else if (index.Current() == _T("Links")) {
Core::ProxyType<Web::JSONBodyType<PluginHost::MetaData>> response(jsonBodyMetaDataFactory.Element());

_pluginServer->Dispatcher().GetMetaData(response->Channels);
_pluginServer->Services().GetMetaData(response->Channels);
_pluginServer->Metadata(response->Channels);

result->Body(Core::ProxyType<Web::IBody>(response));
} else if (index.Current() == _T("Plugins")) {
Expand Down Expand Up @@ -685,7 +683,7 @@ namespace Plugin {
void Controller::StartupResume(const string& callsign, PluginHost::IShell* plugin)
{
if (_resumes.size() > 0) {
std::list<string>::iterator index(_resumes.begin());
Resumes::iterator index(_resumes.begin());

ASSERT(_service != nullptr);

Expand Down Expand Up @@ -794,11 +792,7 @@ namespace Plugin {
}
}

uint32_t Controller::Validate(const string& token, const string& method, const string& paramaters) const /* override */ {
return(PluginHost::JSONRPC::Validate(token, Core::JSONRPC::Message::Method(method), paramaters));
}

uint32_t Controller::Invoke(const uint32_t channelId, const uint32_t id, const string& token, const string& method, const string& parameters, string& response /* @out */) /* override */
Core::hresult Controller::Invoke(const uint32_t channelId, const uint32_t id, const string& token, const string& method, const string& parameters, string& response /* @out */) /* override */
{
Core::hresult result = Core::ERROR_BAD_REQUEST;
string callsign(Core::JSONRPC::Message::Callsign(method));
Expand All @@ -821,16 +815,11 @@ namespace Plugin {
else {
ASSERT(service.IsValid());

PluginHost::IDispatcher* dispatcher = reinterpret_cast<PluginHost::IDispatcher*>(service->QueryInterface(PluginHost::IDispatcher::ID));
PluginHost::IDispatcher* dispatcher = service->QueryInterface<PluginHost::IDispatcher>();

if (dispatcher != nullptr) {
PluginHost::ILocalDispatcher* localDispatcher = dispatcher->Local();
result = dispatcher->Invoke(channelId, id, token, method, parameters, response);

ASSERT(localDispatcher != nullptr);

if (localDispatcher != nullptr) {
result = localDispatcher->Invoke(channelId, id, token, Core::JSONRPC::Message::VersionedFullMethod(method), parameters, response);
}
dispatcher->Release();
}
}
Expand All @@ -845,9 +834,9 @@ namespace Plugin {
_adminLock.Lock();

// Make sure a sink is not registered multiple times.
ASSERT(std::find(_observers.begin(), _observers.end(), notification) == _observers.end());
ASSERT(std::find(_lifeTimeObservers.begin(), _lifeTimeObservers.end(), notification) == _lifeTimeObservers.end());

_observers.push_back(notification);
_lifeTimeObservers.push_back(notification);
notification->AddRef();

_adminLock.Unlock();
Expand All @@ -859,21 +848,35 @@ namespace Plugin {
{
_adminLock.Lock();

std::list<Exchange::Controller::ILifeTime::INotification*>::iterator index(std::find(_observers.begin(), _observers.end(), notification));
LifeTimeNotifiers::iterator index(std::find(_lifeTimeObservers.begin(), _lifeTimeObservers.end(), notification));

// Make sure you do not unregister something you did not register !!!
ASSERT(index != _observers.end());
ASSERT(index != _lifeTimeObservers.end());

if (index != _observers.end()) {
if (index != _lifeTimeObservers.end()) {
(*index)->Release();
_observers.erase(index);
_lifeTimeObservers.erase(index);
}

_adminLock.Unlock();

return (Core::ERROR_NONE);
}

Core::hresult Controller::Register(Exchange::Controller::IShells::INotification* notification)
{
_pluginServer->Services().Register(notification);

return (Core::ERROR_NONE);
}

Core::hresult Controller::Unregister(Exchange::Controller::IShells::INotification* notification)
{
_pluginServer->Services().Unregister(notification);

return (Core::ERROR_NONE);
}

Core::hresult Controller::Activate(const string& callsign)
{
Core::hresult result = Core::ERROR_NONE;
Expand Down Expand Up @@ -1022,8 +1025,13 @@ namespace Plugin {
Core::hresult Controller::Clone(const string& callsign, const string& newcallsign, string& response)
{
Core::hresult result = Clone(callsign, newcallsign);

if (result == Core::ERROR_NONE) {
response = newcallsign;
PluginHost::IShell* shell = reinterpret_cast<PluginHost::IShell*>(_pluginServer->Services().QueryInterfaceByCallsign(PluginHost::IShell::ID, newcallsign));

if (shell != nullptr) {
response = newcallsign;
}
}
return result;
}
Expand Down Expand Up @@ -1196,8 +1204,7 @@ namespace Plugin {

ASSERT(_pluginServer != nullptr);

_pluginServer->Dispatcher().GetMetaData(meta);
_pluginServer->Services().GetMetaData(meta);
_pluginServer->Metadata(meta);

if (meta.Length() > 0) {
std::list<IMetadata::Data::Link> links;
Expand Down Expand Up @@ -1388,9 +1395,9 @@ namespace Plugin {
{
_adminLock.Lock();

std::list<Exchange::Controller::ILifeTime::INotification*>::const_iterator index = _observers.begin();
LifeTimeNotifiers::const_iterator index = _lifeTimeObservers.begin();

while(index != _observers.end()) {
while(index != _lifeTimeObservers.end()) {
(*index)->StateChange(callsign, state, reason);
index++;
}
Expand Down
92 changes: 50 additions & 42 deletions Source/WPEFramework/Controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,44 +39,13 @@ namespace Plugin {
, public Exchange::Controller::IDiscovery
, public Exchange::Controller::ISystemManagement
, public Exchange::Controller::IMetadata
, public Exchange::Controller::ILifeTime {
public:
class SubsystemsData : public Core::JSON::Container {
public:
SubsystemsData()
: Core::JSON::Container()
{
Init();
}

SubsystemsData(const SubsystemsData& other)
: Core::JSON::Container()
, Subsystem(other.Subsystem)
, Active(other.Active)
{
Init();
}

SubsystemsData& operator=(const SubsystemsData& rhs)
{
Subsystem = rhs.Subsystem;
Active = rhs.Active;
return (*this);
}

private:
void Init()
{
Add(_T("subsystem"), &Subsystem);
Add(_T("active"), &Active);
}

public:
Core::JSON::EnumType<PluginHost::ISubSystem::subsystem> Subsystem;
Core::JSON::Boolean Active;
};

, public Exchange::Controller::ILifeTime
, public Exchange::Controller::IShells {
private:
using Resumes = std::vector<string>;
using ExternalSubSystems = std::vector<PluginHost::ISubSystem::subsystem>;
using LifeTimeNotifiers = std::vector<Exchange::Controller::ILifeTime::INotification*>;

class Sink
: public PluginHost::IPlugin::INotification
, public PluginHost::ISubSystem::INotification {
Expand Down Expand Up @@ -149,6 +118,40 @@ namespace Plugin {
// PUT -> URL /<MetaDataCallsign>/Deactivate/<Callsign>
// DELETE -> URL /<MetaDataCallsign>/Plugin/<Callsign>
public:
class SubsystemsData : public Core::JSON::Container {
public:
SubsystemsData()
: Core::JSON::Container()
{
Init();
}

SubsystemsData(const SubsystemsData& other)
: Core::JSON::Container()
, Subsystem(other.Subsystem)
, Active(other.Active)
{
Init();
}

SubsystemsData& operator=(const SubsystemsData& rhs)
{
Subsystem = rhs.Subsystem;
Active = rhs.Active;
return (*this);
}

private:
void Init()
{
Add(_T("subsystem"), &Subsystem);
Add(_T("active"), &Active);
}

public:
Core::JSON::EnumType<PluginHost::ISubSystem::subsystem> Subsystem;
Core::JSON::Boolean Active;
};
class Config : public Core::JSON::Container {
private:
Config(const Config&) = delete;
Expand Down Expand Up @@ -216,7 +219,7 @@ namespace Plugin {
, _resumes()
, _lastReported()
, _externalSubsystems()
, _observers()
, _lifeTimeObservers()
{
}
POP_WARNING()
Expand Down Expand Up @@ -354,6 +357,10 @@ namespace Plugin {
Core::hresult Subsystems(IMetadata::Data::ISubsystemsIterator*& subsystems) const override;
Core::hresult Version(IMetadata::Data::Version& version) const override;

// Pushing notifications to interested sinks
Core::hresult Register(Exchange::Controller::IShells::INotification* sink) override;
Core::hresult Unregister(Exchange::Controller::IShells::INotification* sink) override;

// IUnknown methods
// -------------------------------------------------------------------------------------------------------
BEGIN_INTERFACE_MAP(Controller)
Expand All @@ -366,12 +373,12 @@ namespace Plugin {
INTERFACE_ENTRY(Exchange::Controller::ISystemManagement)
INTERFACE_ENTRY(Exchange::Controller::IMetadata)
INTERFACE_ENTRY(Exchange::Controller::ILifeTime)
INTERFACE_ENTRY(Exchange::Controller::IShells)
END_INTERFACE_MAP

private:
// ILocalDispatcher methods
// -------------------------------------------------------------------------------------------------------
uint32_t Validate(const string& token, const string& method, const string& paramaters) const override;
uint32_t Invoke(const uint32_t channelId, const uint32_t id, const string& token, const string& method, const string& parameters, string& response /* @out */) override;

inline Core::ProxyType<PluginHost::IShell> FromIdentifier(const string& callsign) const
Expand Down Expand Up @@ -405,11 +412,12 @@ namespace Plugin {
PluginHost::IShell* _service;
Probe* _probe;
Core::Sink<Sink> _systemInfoReport;
std::list<string> _resumes;
Resumes _resumes;
uint32_t _lastReported;
std::vector<PluginHost::ISubSystem::subsystem> _externalSubsystems;
std::list<Exchange::Controller::ILifeTime::INotification*> _observers;
ExternalSubSystems _externalSubsystems;
LifeTimeNotifiers _lifeTimeObservers;
};

POP_WARNING()
}
}
Expand Down
2 changes: 1 addition & 1 deletion Source/WPEFramework/ExampleConfigWindows.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
"classname": "BridgeLink",
"autostart": false,
"configuration": {
"source": "192.168.1.102:62000",
"source": "192.168.11.24:62000",
"retries": 255,
"interval": 10
}
Expand Down
3 changes: 1 addition & 2 deletions Source/WPEFramework/PluginHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -742,8 +742,7 @@ POP_WARNING()
}
case 'C': {
Core::JSON::ArrayType<MetaData::Channel> metaData;
_dispatcher->Dispatcher().GetMetaData(metaData);
_dispatcher->Services().GetMetaData(metaData);
_dispatcher->Metadata(metaData);
Core::JSON::ArrayType<MetaData::Channel>::Iterator index(metaData.Elements());

printf("\nChannels:\n");
Expand Down
Loading

0 comments on commit f53d11e

Please sign in to comment.