Skip to content
Draft
Show file tree
Hide file tree
Changes from 5 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
5 changes: 5 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,7 @@ if (EXAMPLE_SIMPLECOMRPC_TEST)
add_subdirectory(SimpleCOMRPCPluginServer)
add_subdirectory(SimpleCOMRPCClient)
endif()

if (EXAMPLE_FIREBOLTPLUGIN)
add_subdirectory(FireboltPrivacy)
endif()
57 changes: 57 additions & 0 deletions examples/FireboltPrivacy/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(FireboltPrivacy)

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_FIREBOLTPRIVACY_AUTOSTART "Activated" CACHE STRING "Automatically start FireboltPrivacy 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
FireboltPrivacy.cpp
FireboltPrivacyImplementation.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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finding the package required is step 1, inclusing them is step 2 :-) You should include Core and Messaging here as well.

${NAMESPACE}Definitions::${NAMESPACE}Definitions)

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

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this intentional? Typically we use the name of the file (FireboltPrivacy -> FireboltPrivacy.json) and than the callsign automatically becomes FireboltPrivacy. You are now overruling this name by setting the callsign. This is, like mentioned deviating from the standard.... If required, please make sure to document it her that it is required for backwards compatibility.

Copy link
Contributor Author

@Karthick-Somasundaresan Karthick-Somasundaresan Mar 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is intentional. The Firebolt APIs didn't have the prefix Firebolt (eg. Privacy.AllowResumePoints) . I have changed the callsign to Privacy to maintain the same method names. I felt having Privacy alone as the plugin name, doesn't add meaning hence kept the plugin name as FireboltPrivacy and callsign as Privacy.


configuration = JSON()

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

139 changes: 139 additions & 0 deletions examples/FireboltPrivacy/FireboltPrivacy.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
/*
* 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 "FireboltPrivacy.h"
#include <interfaces/IConfiguration.h>

namespace WPEFramework {

namespace Plugin
{

namespace {

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


FireboltPrivacy::FireboltPrivacy()
: _connectionId(0)
, _service(nullptr)
, _fireboltPrivacy(nullptr)
, _notificationSink(*this)
{
}

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

ASSERT(service != nullptr);
ASSERT(_service == nullptr);
ASSERT(_connectionId == 0);
ASSERT(_fireboltPrivacy == 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.
_service->Register(&_notificationSink);

_fireboltPrivacy = service->Root<Exchange::IFireboltPrivacy>(_connectionId, RPC::CommunicationTimeOut, _T("FireboltPrivacyImplementation"));
if (_fireboltPrivacy != nullptr) {
_fireboltPrivacy->Register(&_notificationSink);

Exchange::IConfiguration* configFireboltPrivacy = _fireboltPrivacy->QueryInterface<Exchange::IConfiguration>();
if (configFireboltPrivacy != nullptr) {
if (configFireboltPrivacy->Configure(service) != Core::ERROR_NONE) {
message = _T("FireboltPrivacy could not be configured.");
}
configFireboltPrivacy->Release();
configFireboltPrivacy = nullptr;
}
}
else {
message = _T("FireboltPrivacy could not be instantiated.");
}
Exchange::JFireboltPrivacy::Register(*this, _fireboltPrivacy);

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

void FireboltPrivacy::Deinitialize(PluginHost::IShell* service VARIABLE_IS_NOT_USED)
{
if (_service != nullptr) {
ASSERT(_service == service);
_service->Unregister(&_notificationSink);

if (_fireboltPrivacy != nullptr) {
_fireboltPrivacy->Unregister(&_notificationSink);
Exchange::JFireboltPrivacy::Unregister(*this);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure if you register the JSONRPC only if all succeeded, that you only Unregister it if all was succeeded..


RPC::IRemoteConnection* connection(_service->RemoteConnection(_connectionId));
VARIABLE_IS_NOT_USED uint32_t result = _fireboltPrivacy->Release();
ASSERT(result == Core::ERROR_DESTRUCTION_SUCCEEDED);
_fireboltPrivacy = 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 FireboltPrivacy::Information() const
{
// No additional info to report.
return (string());
}


void FireboltPrivacy::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));
}
}

void FireboltPrivacy::OnAllowResumePointsChanged(const bool allowResumePoint) {
Exchange::JFireboltPrivacy::Event::OnAllowResumePointsChanged(*this, allowResumePoint);
}
} // namespace Plugin
} // namespace WPEFramework

111 changes: 111 additions & 0 deletions examples/FireboltPrivacy/FireboltPrivacy.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/*
* 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/IFireboltPrivacy.h>
#include <interfaces/json/JFireboltPrivacy.h>
#include <interfaces/json/JsonData_FireboltPrivacy.h>

namespace WPEFramework {
namespace Plugin {

class FireboltPrivacy : public PluginHost::IPlugin,
public PluginHost::JSONRPC {
private:
class NotificationHandler : public RPC::IRemoteConnection::INotification, public Exchange::IFireboltPrivacy::INotification {
public:
NotificationHandler() = delete;
NotificationHandler(const NotificationHandler&) = delete;
NotificationHandler(NotificationHandler&&) = delete;
NotificationHandler& operator=(const NotificationHandler&) = delete;
NotificationHandler& operator=(NotificationHandler&&) = delete;

NotificationHandler(FireboltPrivacy& 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::IFireboltPrivacy::INotification)
END_INTERFACE_MAP

private:
FireboltPrivacy& _parent;
};
public:
FireboltPrivacy(const FireboltPrivacy&) = delete;
FireboltPrivacy(FireboltPrivacy&&) = delete;
FireboltPrivacy& operator=(const FireboltPrivacy&) = delete;
FireboltPrivacy& operator=(FireboltPrivacy&) = delete;

FireboltPrivacy();
~FireboltPrivacy() override = default;

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

public:
// IPlugin methods
// -------------------------------------------------------------------------------------------------------
const string Initialize(PluginHost::IShell* service) override;
void Deinitialize(PluginHost::IShell* service) override;
string Information() const override;


private:
void Deactivated(RPC::IRemoteConnection* connection);
void OnAllowResumePointsChanged(const bool allowResumePoint);

private:
uint32_t _connectionId;
PluginHost::IShell* _service;
Exchange::IFireboltPrivacy* _fireboltPrivacy;
Core::SinkType<NotificationHandler> _notificationSink;

};

} // namespace Plugin
} // namespace WPEFramework
Loading