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

Adding a sample Firebolt plugin. #784

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion Dictionary/Dictionary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ ENUM_CONVERSION_BEGIN(Plugin::Dictionary::enumType)
{ Plugin::Dictionary::enumType::PERSISTENT, _TXT("persistent") },
{ Plugin::Dictionary::enumType::CLOSURE, _TXT("closure") },

ENUM_CONVERSION_END(Plugin::Dictionary::enumType);
ENUM_CONVERSION_END(Plugin::Dictionary::enumType)

namespace Plugin {

Expand Down
11 changes: 11 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ option(EXAMPLE_IOCONNECTOR_TEST "Include IOConnector test suite" OFF)
option(EXAMPLE_MESSAGECONTROL_UDP_CLIENT "Include UDP output client for message control" OFF)
option(EXAMPLE_DYNAMICLOADING "Include dynamic loading examples" OFF)
option(EXAMPLE_SIMPLECOMRPC_TEST "Include Simple COMRPC test client" OFF)
option(EXAMPLE_FIREBOLTPLUGIN "Include Simple Firebolt Privacy module" OFF)

if(EXAMPLE_COMRPCCLIENT)
add_subdirectory(COMRPCClient)
Expand Down Expand Up @@ -92,3 +93,13 @@ if (EXAMPLE_SIMPLECOMRPC_TEST)
add_subdirectory(SimpleCOMRPCPluginServer)
add_subdirectory(SimpleCOMRPCClient)
endif()

if (EXAMPLE_FIREBOLTPRIVACY)
add_subdirectory(FireboltPrivacy)
endif()

if (EXAMPLE_FIREBOLTDISCOVERY)
add_subdirectory(FireboltDiscovery)
endif()
add_subdirectory(FireboltPrivacy)
add_subdirectory(FireboltDiscovery)
Binary file not shown.
57 changes: 57 additions & 0 deletions examples/FireboltDiscovery/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# 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.

project(FireboltDiscovery)

cmake_minimum_required(VERSION 3.3)

find_package(WPEFramework)

project_version(1.0.0)

set(MODULE_NAME ${NAMESPACE}${PROJECT_NAME})

message("Setup ${MODULE_NAME} v${PROJECT_VERSION}")

set(PLUGIN_FIREBOLTDISCOVERY_AUTOSTART "Activated" CACHE STRING "Automatically start FireboltDiscovery plugin")

find_package(${NAMESPACE}Core REQUIRED)
find_package(${NAMESPACE}Messaging REQUIRED)
find_package(${NAMESPACE}Plugins REQUIRED)
find_package(${NAMESPACE}Definitions REQUIRED)
find_package(CompileSettingsDebug CONFIG REQUIRED)

add_library(${MODULE_NAME} SHARED
FireboltDiscovery.cpp
FireboltDiscoveryImplementation.cpp
Module.cpp)


set_target_properties(${MODULE_NAME} PROPERTIES
CXX_STANDARD 11
CXX_STANDARD_REQUIRED YES)

target_link_libraries(${MODULE_NAME}
PRIVATE
CompileSettingsDebug::CompileSettingsDebug
${NAMESPACE}Plugins::${NAMESPACE}Plugins
${NAMESPACE}Definitions::${NAMESPACE}Definitions)

install(TARGETS ${MODULE_NAME}
DESTINATION lib/${STORAGE_DIRECTORY}/plugins)

write_config()
10 changes: 10 additions & 0 deletions examples/FireboltDiscovery/FireboltDiscovery.conf.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
startmode = "@PLUGIN_FIREBOLTDISCOVERY_AUTOSTART@"
callsign = "Privacy"

configuration = JSON()

rootobject = JSON()
rootobject.add("mode", "Local")
rootobject.add("locator", "lib@[email protected]")
configuration.add("root", rootobject)

146 changes: 146 additions & 0 deletions examples/FireboltDiscovery/FireboltDiscovery.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
/*
* 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.
*/

#include "FireboltDiscovery.h"
#include <interfaces/IConfiguration.h>

namespace WPEFramework {

namespace Plugin
{

namespace {

static Metadata<FireboltDiscovery> metadata(
// Version
1, 0, 0,
// Preconditions
{},
// Terminations
{},
// Controls
{}
);
}


FireboltDiscovery::FireboltDiscovery()
: _connectionId(0)
, _service(nullptr)
, _fireboltDiscovery(nullptr)
{
}

#if 0
PluginHost::JSONRPC::classification FireboltDiscovery::CheckToken(const string& token, const string& method, const string& parameters){
SYSLOG(Logging::Startup, (_T("Received Token: %s method: %s, Params: %s"), token.c_str(), method.c_str(), parameters.c_str()));
return PluginHost::JSONRPC::classification::VALID;
}
#endif

const string FireboltDiscovery::Initialize(PluginHost::IShell * service)
{
string message;

ASSERT(service != nullptr);
ASSERT(_service == nullptr);
ASSERT(_connectionId == 0);
ASSERT(_fireboltDiscovery == nullptr);
_service = service;
_service->AddRef();

// Register the Process::Notification stuff. The Remote process might die before we get a
// change to "register" the sink for these events !!! So do it ahead of instantiation.

_fireboltDiscovery = service->Root<Exchange::IFDiscovery>(_connectionId, RPC::CommunicationTimeOut, _T("FireboltDiscoveryImplementation"));
if (_fireboltDiscovery != nullptr) {

Exchange::IConfiguration* configFireboltDiscovery = _fireboltDiscovery->QueryInterface<Exchange::IConfiguration>();
if (configFireboltDiscovery != nullptr) {
if (configFireboltDiscovery->Configure(service) != Core::ERROR_NONE) {
message = _T("FireboltDiscovery could not be configured.");
}
configFireboltDiscovery->Release();
configFireboltDiscovery = nullptr;
}
}
else {
message = _T("FireboltDiscovery could not be instantiated.");
}
//Exchange::JSONRPC::JFireboltDiscovery::Register(*this, _fireboltDiscovery);
Exchange::JSONRPC::JFireboltDiscovery::Register(*this, this);

// On success return empty, to indicate there is no error text.
return (message);
}

void FireboltDiscovery::Deinitialize(PluginHost::IShell* service VARIABLE_IS_NOT_USED)
{
if (_service != nullptr) {
ASSERT(_service == service);

if (_fireboltDiscovery != nullptr) {
Exchange::JSONRPC::JFireboltDiscovery::Unregister(*this);

RPC::IRemoteConnection* connection(_service->RemoteConnection(_connectionId));
VARIABLE_IS_NOT_USED uint32_t result = _fireboltDiscovery->Release();
ASSERT(result == Core::ERROR_DESTRUCTION_SUCCEEDED);
_fireboltDiscovery = nullptr;

// The connection can disappear in the meantime...
if (connection != nullptr) {
// But if it did not dissapear in the meantime, forcefully terminate it. Shoot to kill :-)
connection->Terminate();
connection->Release();
}
}

_service->Release();
_service = nullptr;
_connectionId = 0;
}
}

string FireboltDiscovery::Information() const
{
// No additional info to report.
return (string());
}

Core::hresult FireboltDiscovery::SignIn(const Core::JSONRPC::Context& context, const bool param ) {
std::cout<<"Context appId: "<<context.Token().c_str();
std::cout<<" `Context param: "<<param <<'\n';
return Core::ERROR_NONE;
}

void FireboltDiscovery::Deactivated(RPC::IRemoteConnection* connection)
{
// This can potentially be called on a socket thread, so the deactivation (wich in turn kills this object) must be done
// on a seperate thread. Also make sure this call-stack can be unwound before we are totally destructed.
if (_connectionId == connection->Id()) {
ASSERT(_service != nullptr);
Core::IWorkerPool::Instance().Submit(PluginHost::IShell::Job::Create(_service, PluginHost::IShell::DEACTIVATED, PluginHost::IShell::FAILURE));
}
}



} // namespace Plugin
} // namespace WPEFramework

113 changes: 113 additions & 0 deletions examples/FireboltDiscovery/FireboltDiscovery.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/*
* 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"

#include <interfaces/IFireboltDiscovery.h>
#include <interfaces/json/JFireboltDiscovery.h>
#include <interfaces/json/JsonData_FireboltDiscovery.h>

namespace WPEFramework {
namespace Plugin {

class FireboltDiscovery : public PluginHost::IPlugin
, public PluginHost::JSONRPC
, public Exchange::JSONRPC::IFireboltDiscovery {
private:
#if 0
class NotificationHandler : public RPC::IRemoteConnection::INotification, public Exchange::IFireboltDiscovery::INotification {
public:
NotificationHandler() = delete;
NotificationHandler(const NotificationHandler&) = delete;
NotificationHandler(NotificationHandler&&) = delete;
NotificationHandler& operator=(const NotificationHandler&) = delete;
NotificationHandler& operator=(NotificationHandler&&) = delete;

NotificationHandler(FireboltDiscovery& parent)
: _parent(parent)
{
}
~NotificationHandler() override = default;

public:
void Activated(RPC::IRemoteConnection* /* connection */) override
{
}
void Deactivated(RPC::IRemoteConnection* connection) override
{
_parent.Deactivated(connection);
}
void Terminated (RPC::IRemoteConnection* /* connection */) override
{
}


void OnAllowResumePointsChanged(const bool allowResumePoint) override
{
_parent.OnAllowResumePointsChanged(allowResumePoint);
}
BEGIN_INTERFACE_MAP(NotificationHandler)
INTERFACE_ENTRY(RPC::IRemoteConnection::INotification)
INTERFACE_ENTRY(Exchange::IFireboltDiscovery::INotification)
END_INTERFACE_MAP

private:
FireboltDiscovery& _parent;
};
#endif
public:
FireboltDiscovery(const FireboltDiscovery&) = delete;
FireboltDiscovery(FireboltDiscovery&&) = delete;
FireboltDiscovery& operator=(const FireboltDiscovery&) = delete;
FireboltDiscovery& operator=(FireboltDiscovery&) = delete;

FireboltDiscovery();
~FireboltDiscovery() override = default;

// Build QueryInterface implementation, specifying all possible interfaces to be returned.
BEGIN_INTERFACE_MAP(FireboltDiscovery)
INTERFACE_ENTRY(PluginHost::IPlugin)
INTERFACE_ENTRY(PluginHost::IDispatcher)
//INTERFACE_AGGREGATE(Exchange::IFDiscovery, _fireboltDiscovery)
END_INTERFACE_MAP

public:
// IPlugin methods
// -------------------------------------------------------------------------------------------------------
const string Initialize(PluginHost::IShell* service) override;
void Deinitialize(PluginHost::IShell* service) override;
string Information() const override;
Core::hresult SignIn(const Core::JSONRPC::Context& context, const bool param ) override;


private:
void Deactivated(RPC::IRemoteConnection* connection);

private:
uint32_t _connectionId;
PluginHost::IShell* _service;
Exchange::IFDiscovery* _fireboltDiscovery;

};

} // namespace Plugin
} // namespace WPEFramework
Loading
Loading