Skip to content

Commit

Permalink
[Controller] Bring back IController and fix COMRPCStarter (#1436)
Browse files Browse the repository at this point in the history
  • Loading branch information
MFransen69 committed Oct 21, 2023
1 parent e7806c4 commit 3249f7c
Show file tree
Hide file tree
Showing 8 changed files with 234 additions and 124 deletions.
39 changes: 18 additions & 21 deletions Source/WPEFramework/Controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,11 @@ namespace Plugin {
_service->DisableWebServer();
}

Register(this);
Exchange::IController::JConfiguration::Register(*this, this);
Exchange::IController::JDiscovery::Register(*this, this);
Exchange::IController::JSystemManagement::Register(*this, this);
Exchange::IController::JLifeTime::Register(*this, this);
Exchange::IController::JMetadata::Register(*this, this);
Exchange::Controller::JConfiguration::Register(*this, this);
Exchange::Controller::JDiscovery::Register(*this, this);
Exchange::Controller::JSystemManagement::Register(*this, this);
Exchange::Controller::JLifeTime::Register(*this, this);
Exchange::Controller::JMetadata::Register(*this, this);

// On succes return a name as a Callsign to be used in the URL, after the "service"prefix
return (_T(""));
Expand All @@ -144,11 +143,11 @@ namespace Plugin {
{
ASSERT(_service == service);

Exchange::IController::JConfiguration::Unregister(*this);
Exchange::IController::JDiscovery::Unregister(*this);
Exchange::IController::JSystemManagement::Unregister(*this);
Exchange::IController::JLifeTime::Unregister(*this);
Exchange::IController::JMetadata::Unregister(*this);
Exchange::Controller::JConfiguration::Unregister(*this);
Exchange::Controller::JDiscovery::Unregister(*this);
Exchange::Controller::JSystemManagement::Unregister(*this);
Exchange::Controller::JLifeTime::Unregister(*this);
Exchange::Controller::JMetadata::Unregister(*this);

// Detach the SubSystems, we are shutting down..
PluginHost::ISubSystem* subSystems(_service->SubSystems());
Expand All @@ -165,7 +164,6 @@ namespace Plugin {
_probe = nullptr;
}

Unregister(this);
_service->Unregister(&_systemInfoReport);

/* stop the file serving over http.... */
Expand Down Expand Up @@ -835,7 +833,7 @@ namespace Plugin {
return (result);
}

Core::hresult Controller::Register(Exchange::IController::ILifeTime::INotification* notification)
Core::hresult Controller::Register(Exchange::Controller::ILifeTime::INotification* notification)
{
_adminLock.Lock();

Expand All @@ -850,11 +848,11 @@ namespace Plugin {
return (Core::ERROR_NONE);
}

Core::hresult Controller::Unregister(Exchange::IController::ILifeTime::INotification* notification)
Core::hresult Controller::Unregister(Exchange::Controller::ILifeTime::INotification* notification)
{
_adminLock.Lock();

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

// Make sure you do not unregister something you did not register !!!
ASSERT(index != _observers.end());
Expand Down Expand Up @@ -1168,23 +1166,22 @@ ASSERT(_service != nullptr);
return Core::ERROR_NONE;
}

void Controller::StateChange(const string& callsign, const PluginHost::IShell::state& state, const PluginHost::IShell::reason& reason)
{
Exchange::IController::JLifeTime::Event::StateChange(*this, callsign, state, reason);
}

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

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

while(index != _observers.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);

}
}
}
36 changes: 19 additions & 17 deletions Source/WPEFramework/Controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ namespace Plugin {
: public PluginHost::IPlugin
, public PluginHost::IWeb
, public PluginHost::JSONRPC
, public Exchange::IController::IConfiguration
, public Exchange::IController::IDiscovery
, public Exchange::IController::ISystemManagement
, public Exchange::IController::IMetadata
, public Exchange::IController::ILifeTime
, public Exchange::IController::ILifeTime::INotification {
, public PluginHost::IController
, public Exchange::Controller::IConfiguration
, public Exchange::Controller::IDiscovery
, public Exchange::Controller::ISystemManagement
, public Exchange::Controller::IMetadata
, public Exchange::Controller::ILifeTime {
public:
class SubsystemsData : public Core::JSON::Container {
public:
Expand Down Expand Up @@ -333,8 +333,8 @@ namespace Plugin {
Core::hresult Configuration(const string& callsign, string& configuration) const override;
Core::hresult Configuration(const string& callsign, const string& configuration) override;

Core::hresult Register(Exchange::IController::ILifeTime::INotification* notification) override;
Core::hresult Unregister(Exchange::IController::ILifeTime::INotification* notification) override;
Core::hresult Register(Exchange::Controller::ILifeTime::INotification* notification) override;
Core::hresult Unregister(Exchange::Controller::ILifeTime::INotification* notification) override;

Core::hresult Activate(const string& callsign) override;
Core::hresult Deactivate(const string& callsign) override;
Expand All @@ -351,22 +351,24 @@ namespace Plugin {
Core::hresult Subsystems(string& response) const override;
Core::hresult Version(string& response) const override;

void StateChange(const string& callsign, const PluginHost::IShell::state& state, const PluginHost::IShell::reason& reason) override;

// IUnknown methods
// -------------------------------------------------------------------------------------------------------
PUSH_WARNING(DISABLE_WARNING_DEPRECATED_USE) // for now we must support the deprecated interface for backwards compatibility reasons

BEGIN_INTERFACE_MAP(Controller)
INTERFACE_ENTRY(PluginHost::IPlugin)
INTERFACE_ENTRY(PluginHost::IWeb)
INTERFACE_ENTRY(PluginHost::IDispatcher)
INTERFACE_ENTRY(Exchange::IController::IConfiguration)
INTERFACE_ENTRY(Exchange::IController::IDiscovery)
INTERFACE_ENTRY(Exchange::IController::ISystemManagement)
INTERFACE_ENTRY(Exchange::IController::IMetadata)
INTERFACE_ENTRY(Exchange::IController::ILifeTime)
INTERFACE_ENTRY(Exchange::IController::ILifeTime::INotification)
INTERFACE_ENTRY(PluginHost::IController)
INTERFACE_ENTRY(Exchange::Controller::IConfiguration)
INTERFACE_ENTRY(Exchange::Controller::IDiscovery)
INTERFACE_ENTRY(Exchange::Controller::ISystemManagement)
INTERFACE_ENTRY(Exchange::Controller::IMetadata)
INTERFACE_ENTRY(Exchange::Controller::ILifeTime)
END_INTERFACE_MAP

POP_WARNING()

private:
// ILocalDispatcher methods
// -------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -407,7 +409,7 @@ namespace Plugin {
std::list<string> _resumes;
uint32_t _lastReported;
std::vector<PluginHost::ISubSystem::subsystem> _externalSubsystems;
std::list<Exchange::IController::ILifeTime::INotification*> _observers;
std::list<Exchange::Controller::ILifeTime::INotification*> _observers;
};
}
}
Expand Down
8 changes: 7 additions & 1 deletion Source/plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ option(VIRTUALINPUT_TOOLS "Build VirtualInput tools" OFF)
ProxyStubGenerator(NAMESPACE "WPEFramework::PluginHost" INPUT "${CMAKE_CURRENT_SOURCE_DIR}/IPlugin.h" OUTDIR "${CMAKE_CURRENT_BINARY_DIR}/generated")
ProxyStubGenerator(NAMESPACE "WPEFramework::PluginHost" INPUT "${CMAKE_CURRENT_SOURCE_DIR}/IShell.h" OUTDIR "${CMAKE_CURRENT_BINARY_DIR}/generated")
ProxyStubGenerator(NAMESPACE "WPEFramework::Exchange" INPUT "${CMAKE_CURRENT_SOURCE_DIR}/IController.h" OUTDIR "${CMAKE_CURRENT_BINARY_DIR}/generated" INCLUDE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/..")
ProxyStubGenerator(NAMESPACE "WPEFramework::PluginHost" INPUT "${CMAKE_CURRENT_SOURCE_DIR}/IControllerDeprecated.h" OUTDIR "${CMAKE_CURRENT_BINARY_DIR}/generated" INCLUDE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/..")
ProxyStubGenerator(NAMESPACE "WPEFramework::PluginHost" INPUT "${CMAKE_CURRENT_SOURCE_DIR}/IStateControl.h" OUTDIR "${CMAKE_CURRENT_BINARY_DIR}/generated")
ProxyStubGenerator(NAMESPACE "WPEFramework::PluginHost" INPUT "${CMAKE_CURRENT_SOURCE_DIR}/ISubSystem.h" OUTDIR "${CMAKE_CURRENT_BINARY_DIR}/generated")
ProxyStubGenerator(NAMESPACE "WPEFramework::PluginHost" INPUT "${CMAKE_CURRENT_SOURCE_DIR}/IDispatcher.h" OUTDIR "${CMAKE_CURRENT_BINARY_DIR}/generated")

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

add_library(${TARGET} SHARED
Channel.cpp
Expand Down Expand Up @@ -56,6 +57,7 @@ set(PUBLIC_HEADERS
IPlugin.h
IShell.h
IController.h
IControllerDeprecated.h
Shell.h
IStateControl.h
StateControl.h
Expand Down Expand Up @@ -92,6 +94,10 @@ if (WARNING_REPORTING)
)
endif()

# when compiling proxy/stubs we should ignore deprecated warnings (which are treated as erros nowadays)
# as usage of those deprecated methods is valid here
target_compile_options(${TARGET_PROXYSTUBS} PRIVATE -Wno-deprecated-declarations)

target_link_libraries(${TARGET_PROXYSTUBS}
PRIVATE
CompileSettingsDebug::CompileSettingsDebug
Expand Down
7 changes: 6 additions & 1 deletion Source/plugins/IController.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,14 @@
#include "Module.h"
#include "IShell.h"

#include "IControllerDeprecated.h"

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

namespace WPEFramework {

namespace Exchange {
namespace IController {
namespace Controller {

/* @json */
struct EXTERNAL ISystemManagement : virtual public Core::IUnknown {
Expand Down Expand Up @@ -140,5 +143,7 @@ namespace IController {
virtual Core::hresult CallStack(const string& index /* @index */, string& callstack /* @out @opaque */) const = 0;
};
}

} // namespace Exchange

} // namespace WPEFramework
49 changes: 49 additions & 0 deletions Source/plugins/IControllerDeprecated.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* If not stated otherwise in this file or this component's LICENSE file the
* following copyright and licenses apply:
*
* Copyright 2020 Metrological
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#pragma once
#include "Module.h"

namespace WPEFramework {

namespace PluginHost {

struct DEPRECATED EXTERNAL IController : public virtual Core::IUnknown {

enum { ID = RPC::ID_CONTROLLER };

~IController() override = default;

virtual uint32_t Persist() = 0;

virtual uint32_t Delete(const string& path) = 0;

virtual uint32_t Reboot() = 0;

virtual uint32_t Environment(const string& index, string& environment /* @out */ ) const = 0;

virtual uint32_t Configuration(const string& callsign, string& configuration /* @out */) const = 0;
virtual uint32_t Configuration(const string& callsign, const string& configuration) = 0;

virtual uint32_t Clone(const string& basecallsign, const string& newcallsign) = 0;
};

}

} // namespace WPEFramework
97 changes: 97 additions & 0 deletions Source/plugins/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -361,5 +361,102 @@ POP_WARNING()
Monitor _monitor;
uint32_t _connectionId;
};

template <typename INTERFACE, Core::ProxyType<RPC::IIPCServer> ENGINE() = DefaultInvokeServer>
class SmartControllerInterfaceType {

public:
SmartControllerInterfaceType(const SmartControllerInterfaceType<INTERFACE, ENGINE>&) = delete;
SmartControllerInterfaceType<INTERFACE, ENGINE>& operator=(const SmartControllerInterfaceType<INTERFACE, ENGINE>&) = delete;

SmartControllerInterfaceType()
: _controller(nullptr)
, _administrator()
, _connectionId(~0)
{
}

~SmartControllerInterfaceType()
{
ASSERT(_controller == nullptr);
}

public:
uint32_t ConnectionId() const {
return (_connectionId);
}
bool IsOperational() const
{
return (_controller != nullptr);
}
uint32_t Open(const uint32_t waitTime, const Core::NodeId& node)
{
Core::IUnknown* controller = RPC::ConnectorController::Instance().Controller();

ASSERT(_controller == nullptr);

if (controller != nullptr) {
// Seems like we already have a connection to the IShell of the Controller plugin, reuse it.
_controller = controller->QueryInterface<PluginHost::IShell>();
controller->Release();
}
if (_controller == nullptr) {
_controller = _administrator.template Acquire<PluginHost::IShell>(waitTime, node, _T(""), ~0);
}
if (_controller != nullptr) {
Core::ProxyType<CommunicatorClient> channel(_administrator.Communicator(node));
if (channel.IsValid() == true) {
_connectionId = channel->ConnectionId();
}
}

return (_controller != nullptr ? Core::ERROR_NONE : Core::ERROR_UNAVAILABLE);
}
uint32_t Close(const uint32_t waitTime)
{
if (_controller != nullptr) {
_controller->Release();
_controller = nullptr;
}

return (Core::ERROR_NONE);
}

INTERFACE* Interface()
{
INTERFACE* result = nullptr;
if(_controller != nullptr) {
result = _controller->QueryInterface<INTERFACE>();
}
return result;
}
const INTERFACE* Interface() const
{
INTERFACE* result = nullptr;
if(_controller != nullptr) {
result = _controller->QueryInterface<INTERFACE>();
}
return result;
}
PluginHost::IShell* ControllerInterface()
{
return _controller;
}
const PluginHost::IShell* ControllerInterface() const
{
return _controller;
}

static Core::NodeId Connector()
{
return SmartInterfaceType<PluginHost::IShell>::Connector();
}

private:
PluginHost::IShell* _controller;
ConnectorType<ENGINE> _administrator;
uint32_t _connectionId;
};

}
}
Loading

0 comments on commit 3249f7c

Please sign in to comment.