-
Notifications
You must be signed in to change notification settings - Fork 54
Adding a sample Firebolt plugin. #784
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
c518336
e2aadb5
682731c
fbd9ad3
b5d7f1e
8fd0cd5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| # 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}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 | ||
| ${NAMESPACE}Definitions::${NAMESPACE}Definitions) | ||
|
|
||
| install(TARGETS ${MODULE_NAME} | ||
| DESTINATION lib/${STORAGE_DIRECTORY}/plugins) | ||
|
|
||
| write_config() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| startmode = "@PLUGIN_FIREBOLTPRIVACY_AUTOSTART@" | ||
| callsign = "Privacy" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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() | ||
|
|
||
| configuration.add("storagelocation", "Disk") | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,140 @@ | ||
| /* | ||
| * 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) | ||
| , _connectionNotification(*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(&_connectionNotification); | ||
|
|
||
| _fireboltPrivacy = service->Root<Exchange::IFireboltPrivacy>(_connectionId, RPC::CommunicationTimeOut, _T("FireboltPrivacyImplementation")); | ||
| if (_fireboltPrivacy != nullptr) { | ||
| _fireboltPrivacy->Register(&_connectionNotification); | ||
| Exchange::JFireboltPrivacy::Register(*this, _fireboltPrivacy); | ||
|
||
|
|
||
| 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."); | ||
| } | ||
|
|
||
| // 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(&_connectionNotification); | ||
|
|
||
| if (_fireboltPrivacy != nullptr) { | ||
| Exchange::JFireboltPrivacy::Unregister(*this); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.. |
||
| _fireboltPrivacy->Unregister(&_connectionNotification); | ||
|
|
||
| RPC::IRemoteConnection* connection(_service->RemoteConnection(_connectionId)); | ||
| VARIABLE_IS_NOT_USED uint32_t result = _fireboltPrivacy->Release(); | ||
| _fireboltPrivacy = nullptr; | ||
| ASSERT(result == Core::ERROR_DESTRUCTION_SUCCEEDED); | ||
|
|
||
| // 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 | ||
|
|
||
| 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 ConnectionNotification : public RPC::IRemoteConnection::INotification, public Exchange::IFireboltPrivacy::INotification { | ||
| public: | ||
| ConnectionNotification() = delete; | ||
| ConnectionNotification(const ConnectionNotification&) = delete; | ||
| ConnectionNotification(ConnectionNotification&&) = delete; | ||
| ConnectionNotification& operator=(const ConnectionNotification&) = delete; | ||
| ConnectionNotification& operator=(ConnectionNotification&&) = delete; | ||
|
|
||
| ConnectionNotification(FireboltPrivacy& parent) | ||
| : _parent(parent) | ||
| { | ||
| } | ||
| ~ConnectionNotification() 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(ConnectionNotification) | ||
| 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<ConnectionNotification> _connectionNotification; | ||
|
|
||
| }; | ||
|
|
||
| } // namespace Plugin | ||
| } // namespace WPEFramework |
There was a problem hiding this comment.
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.