-
Notifications
You must be signed in to change notification settings - Fork 387
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RDK-53610 - sample hello world plugin that uses auto generated stubs (#…
…5789) * RDK-53610 - sample hello world plugin that uses auto generated stubs * RDK-53610 - sample hello world plugin that uses auto generated stubs
- Loading branch information
1 parent
bdbdaea
commit 4934003
Showing
11 changed files
with
790 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Changelog | ||
|
||
All notable changes to this RDK Service will be documented in this file. | ||
|
||
* Each RDK Service has a CHANGELOG file that contains all changes done so far. When version is updated, add a entry in the CHANGELOG.md at the top with user friendly information on what was changed with the new version. Please don't mention JIRA tickets in CHANGELOG. | ||
|
||
* Please Add entry in the CHANGELOG for each version change and indicate the type of change with these labels: | ||
* **Added** for new features. | ||
* **Changed** for changes in existing functionality. | ||
* **Deprecated** for soon-to-be removed features. | ||
* **Removed** for now removed features. | ||
* **Fixed** for any bug fixes. | ||
* **Security** in case of vulnerabilities. | ||
|
||
* Changes in CHANGELOG should be updated when commits are added to the main or release branches. There should be one CHANGELOG entry per JIRA Ticket. This is not enforced on sprint branches since there could be multiple changes for the same JIRA ticket during development. | ||
|
||
* For more details, refer to [versioning](https://github.com/rdkcentral/rdkservices#versioning) section under Main README. | ||
|
||
## [1.0.0] - 2024-06-05 | ||
### Added | ||
- Add CHANGELOG | ||
|
||
### Change | ||
- Reset API version to 1.0.0 | ||
- Change README to inform how to update changelog and API version |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# If not stated otherwise in this file or this component's LICENSE file the | ||
# following copyright and licenses apply: | ||
# | ||
# Copyright 2024 RDK Management | ||
# | ||
# 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. | ||
|
||
set(PLUGIN_NAME HelloWorld) | ||
set(MODULE_NAME ${NAMESPACE}${PLUGIN_NAME}) | ||
set(PLUGIN_IMPLEMENTATION ${MODULE_NAME}Implementation) | ||
|
||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") | ||
|
||
find_package(${NAMESPACE}Plugins REQUIRED) | ||
find_package(${NAMESPACE}Definitions REQUIRED) | ||
find_package(CompileSettingsDebug CONFIG REQUIRED) | ||
|
||
add_library(${MODULE_NAME} SHARED | ||
HelloWorld.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 ${CMAKE_INSTALL_PREFIX}/lib/${STORAGE_DIRECTORY}/plugins) | ||
|
||
add_library(${PLUGIN_IMPLEMENTATION} SHARED | ||
HelloWorldImplementation.cpp | ||
Module.cpp) | ||
|
||
include_directories( | ||
../helpers) | ||
|
||
set_target_properties(${PLUGIN_IMPLEMENTATION} PROPERTIES | ||
CXX_STANDARD 11 | ||
CXX_STANDARD_REQUIRED YES) | ||
|
||
target_link_libraries(${PLUGIN_IMPLEMENTATION} | ||
PRIVATE | ||
CompileSettingsDebug::CompileSettingsDebug | ||
${NAMESPACE}Plugins::${NAMESPACE}Plugins) | ||
|
||
install(TARGETS ${PLUGIN_IMPLEMENTATION} | ||
DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/${STORAGE_DIRECTORY}/plugins) | ||
|
||
write_config(${PLUGIN_NAME}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
precondition = ["Platform"] | ||
callsign = "org.rdk.HelloWorld" | ||
autostart = "false" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
set (autostart false) | ||
set (preconditions Platform) | ||
set (callsign "org.rdk.HelloWorld") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
/* | ||
* If not stated otherwise in this file or this component's LICENSE file the | ||
* following copyright and licenses apply: | ||
* | ||
* Copyright 2024 RDK Management | ||
* | ||
* 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 "HelloWorld.h" | ||
|
||
#define API_VERSION_NUMBER_MAJOR 1 | ||
#define API_VERSION_NUMBER_MINOR 0 | ||
#define API_VERSION_NUMBER_PATCH 0 | ||
|
||
namespace WPEFramework | ||
{ | ||
|
||
namespace { | ||
|
||
static Plugin::Metadata<Plugin::HelloWorld> metadata( | ||
// Version (Major, Minor, Patch) | ||
API_VERSION_NUMBER_MAJOR, API_VERSION_NUMBER_MINOR, API_VERSION_NUMBER_PATCH, | ||
// Preconditions | ||
{}, | ||
// Terminations | ||
{}, | ||
// Controls | ||
{} | ||
); | ||
} | ||
|
||
namespace Plugin | ||
{ | ||
|
||
/* | ||
*Register HelloWorld module as wpeframework plugin | ||
**/ | ||
SERVICE_REGISTRATION(HelloWorld, API_VERSION_NUMBER_MAJOR, API_VERSION_NUMBER_MINOR, API_VERSION_NUMBER_PATCH); | ||
|
||
HelloWorld::HelloWorld() : _service(nullptr), _connectionId(0), _helloWorld(nullptr), _helloWorldNotification(this) | ||
{ | ||
SYSLOG(Logging::Startup, (_T("HelloWorld Constructor"))); | ||
} | ||
|
||
HelloWorld::~HelloWorld() | ||
{ | ||
SYSLOG(Logging::Shutdown, (string(_T("HelloWorld Destructor")))); | ||
} | ||
|
||
const string HelloWorld::Initialize(PluginHost::IShell* service) | ||
{ | ||
string message=""; | ||
|
||
ASSERT(nullptr != service); | ||
ASSERT(nullptr == _service); | ||
ASSERT(nullptr == _helloWorld); | ||
ASSERT(0 == _connectionId); | ||
|
||
SYSLOG(Logging::Startup, (_T("HelloWorld::Initialize: PID=%u"), getpid())); | ||
|
||
_service = service; | ||
_service->AddRef(); | ||
_service->Register(&_helloWorldNotification); | ||
_helloWorld = _service->Root<Exchange::IHelloWorld>(_connectionId, 5000, _T("HelloWorldImplementation")); | ||
|
||
if(nullptr != _helloWorld) | ||
{ | ||
// Register for notifications | ||
_helloWorld->Register(&_helloWorldNotification); | ||
// Invoking Plugin API register to wpeframework | ||
Exchange::JHelloWorld::Register(*this, _helloWorld); | ||
} | ||
else | ||
{ | ||
SYSLOG(Logging::Startup, (_T("HelloWorld::Initialize: Failed to initialise HelloWorld plugin"))); | ||
Deinitialize(service); | ||
message = _T("HelloWorld plugin could not be initialised"); | ||
} | ||
return message; | ||
} | ||
|
||
void HelloWorld::Deinitialize(PluginHost::IShell* service) | ||
{ | ||
ASSERT(_service == service); | ||
|
||
SYSLOG(Logging::Shutdown, (string(_T("HelloWorld::Deinitialize")))); | ||
|
||
// Make sure the Activated and Deactivated are no longer called before we start cleaning up.. | ||
_service->Unregister(&_helloWorldNotification); | ||
|
||
if (nullptr != _helloWorld) | ||
{ | ||
_helloWorld->Unregister(&_helloWorldNotification); | ||
Exchange::JHelloWorld::Unregister(*this); | ||
|
||
// Stop processing: | ||
RPC::IRemoteConnection* connection = service->RemoteConnection(_connectionId); | ||
VARIABLE_IS_NOT_USED uint32_t result = _helloWorld->Release(); | ||
|
||
_helloWorld = nullptr; | ||
|
||
// It should have been the last reference we are releasing, | ||
// so it should endup in a DESTRUCTION_SUCCEEDED, if not we | ||
// are leaking... | ||
ASSERT(result == Core::ERROR_DESTRUCTION_SUCCEEDED); | ||
|
||
// If this was running in a (container) process... | ||
if (nullptr != connection) | ||
{ | ||
// Lets trigger the cleanup sequence for | ||
// out-of-process code. Which will guard | ||
// that unwilling processes, get shot if | ||
// not stopped friendly :-) | ||
connection->Terminate(); | ||
connection->Release(); | ||
} | ||
} | ||
|
||
_connectionId = 0; | ||
_service->Release(); | ||
_service = nullptr; | ||
SYSLOG(Logging::Shutdown, (string(_T("HelloWorld de-initialised")))); | ||
} | ||
|
||
string HelloWorld::Information() const | ||
{ | ||
// No additional info to report | ||
return (string()); | ||
} | ||
|
||
void HelloWorld::Deactivated(RPC::IRemoteConnection* connection) | ||
{ | ||
if (connection->Id() == _connectionId) { | ||
ASSERT(nullptr != _service); | ||
Core::IWorkerPool::Instance().Submit(PluginHost::IShell::Job::Create(_service, PluginHost::IShell::DEACTIVATED, PluginHost::IShell::FAILURE)); | ||
} | ||
} | ||
} // namespace Plugin | ||
} // namespace WPEFramework |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
/* | ||
* If not stated otherwise in this file or this component's LICENSE file the | ||
* following copyright and licenses apply: | ||
* | ||
* Copyright 2024 RDK Management | ||
* | ||
* 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/json/JsonData_HelloWorld.h> | ||
#include <interfaces/json/JHelloWorld.h> | ||
#include <interfaces/IHelloWorld.h> | ||
#include "UtilsLogging.h" | ||
#include "tracing/Logging.h" | ||
#include <mutex> | ||
|
||
namespace WPEFramework { | ||
namespace Plugin { | ||
|
||
class HelloWorld: public PluginHost::IPlugin, public PluginHost::JSONRPC | ||
{ | ||
private: | ||
class Notification : public RPC::IRemoteConnection::INotification, | ||
public Exchange::IHelloWorld::INotification | ||
{ | ||
private: | ||
Notification() = delete; | ||
Notification(const Notification&) = delete; | ||
Notification& operator=(const Notification&) = delete; | ||
|
||
public: | ||
explicit Notification(HelloWorld* parent) | ||
: _parent(*parent) | ||
{ | ||
ASSERT(parent != nullptr); | ||
} | ||
|
||
virtual ~Notification() | ||
{ | ||
} | ||
|
||
BEGIN_INTERFACE_MAP(Notification) | ||
INTERFACE_ENTRY(Exchange::IHelloWorld::INotification) | ||
INTERFACE_ENTRY(RPC::IRemoteConnection::INotification) | ||
END_INTERFACE_MAP | ||
|
||
void Activated(RPC::IRemoteConnection*) override | ||
{ | ||
LOGINFO("HelloWorld Notification Activated"); | ||
} | ||
|
||
void Deactivated(RPC::IRemoteConnection *connection) override | ||
{ | ||
LOGINFO("HelloWorld Notification Deactivated"); | ||
_parent.Deactivated(connection); | ||
} | ||
|
||
void onEcho(const string& message) override | ||
{ | ||
LOGINFO("Helloworld echo: %s\n", message.c_str()); | ||
Exchange::JHelloWorld::Event::OnEcho(_parent, message); | ||
} | ||
|
||
private: | ||
HelloWorld& _parent; | ||
}; | ||
|
||
public: | ||
// We do not allow this plugin to be copied !! | ||
HelloWorld(const HelloWorld&) = delete; | ||
HelloWorld& operator=(const HelloWorld&) = delete; | ||
|
||
HelloWorld(); | ||
virtual ~HelloWorld(); | ||
|
||
BEGIN_INTERFACE_MAP(HelloWorld) | ||
INTERFACE_ENTRY(PluginHost::IPlugin) | ||
INTERFACE_ENTRY(PluginHost::IDispatcher) | ||
INTERFACE_AGGREGATE(Exchange::IHelloWorld, _helloWorld) | ||
END_INTERFACE_MAP | ||
|
||
// 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); | ||
|
||
private: | ||
PluginHost::IShell* _service{}; | ||
uint32_t _connectionId{}; | ||
Exchange::IHelloWorld* _helloWorld{}; | ||
Core::Sink<Notification> _helloWorldNotification; | ||
}; | ||
|
||
} // namespace Plugin | ||
} // namespace WPEFramework |
Oops, something went wrong.