Skip to content

Commit 62be198

Browse files
authored
Merge pull request rdkcentral#5921 from bvanav648/main/RDK-53740-MigrationPreparer
New Thunder Plugin - MigrationPreparer
2 parents 5717c7c + ebb0b14 commit 62be198

15 files changed

+1751
-0
lines changed

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,10 @@ if (PLUGIN_ANALYTICS)
409409
add_subdirectory(Analytics)
410410
endif()
411411

412+
if(PLUGIN_MIGRATIONPREPARER)
413+
add_subdirectory(MigrationPreparer)
414+
endif()
415+
412416
if(WPEFRAMEWORK_CREATE_IPKG_TARGETS)
413417
set(CPACK_GENERATOR "DEB")
414418
set(CPACK_DEB_COMPONENT_INSTALL ON)

MigrationPreparer/CHANGELOG.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
All notable changes to this RDK Service will be documented in this file.
2+
3+
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.
4+
5+
Please Add entry in the CHANGELOG for each version change and indicate the type of change with these labels:
6+
Added for new features.
7+
Changed for changes in existing functionality.
8+
Deprecated for soon-to-be removed features.
9+
Removed for now removed features.
10+
Fixed for any bug fixes.
11+
Security in case of vulnerabilities.
12+
13+
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.
14+
15+
For more details, refer to versioning section under Main README.
16+
17+
## [1.0.0] - 2024-12-01
18+
### Added
19+
- New RDK Service MigrationPreparer to aid the Data Harvesting process, where it exposes APIs to applications such as ResidentApp and others to store user settings in a standardized format (as a JSON file) suitable for EntOS consumption. The MigrationPreparer Thunder plugin will exist only in the RDKV ecosystem.

MigrationPreparer/CMakeLists.txt

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# If not stated otherwise in this file or this component's LICENSE file the
2+
# following copyright and licenses apply:
3+
#
4+
# Copyright 2024 RDK Management
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
18+
set(PLUGIN_NAME MigrationPreparer)
19+
set(MODULE_NAME ${NAMESPACE}${PLUGIN_NAME})
20+
set(PLUGIN_IMPLEMENTATION ${MODULE_NAME}Implementation)
21+
22+
set(PLUGIN_MIGRATIONPREPARER_AUTOSTART "true" CACHE STRING "Automatically start MigrationPreparer plugin")
23+
set(PLUGIN_MIGRATIONPREPARER_STARTUPORDER "" CACHE STRING "To configure startup order of MigrationPreparer plugin")
24+
set(PLUGIN_MIGRATIONPREPARER_MODE "Off" CACHE STRING "Controls if the plugin should run in process or out of process")
25+
26+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
27+
28+
find_package(${NAMESPACE}Plugins REQUIRED)
29+
find_package(${NAMESPACE}Definitions REQUIRED)
30+
find_package(CompileSettingsDebug CONFIG REQUIRED)
31+
32+
add_library(${MODULE_NAME} SHARED
33+
MigrationPreparer.cpp
34+
MigrationPreparerJsonRpc.cpp
35+
Module.cpp)
36+
37+
set_target_properties(${MODULE_NAME} PROPERTIES
38+
CXX_STANDARD 11
39+
CXX_STANDARD_REQUIRED YES)
40+
41+
target_link_libraries(${MODULE_NAME}
42+
PRIVATE
43+
CompileSettingsDebug::CompileSettingsDebug
44+
${NAMESPACE}Plugins::${NAMESPACE}Plugins
45+
${NAMESPACE}Definitions::${NAMESPACE}Definitions)
46+
47+
install(TARGETS ${MODULE_NAME}
48+
DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/${STORAGE_DIRECTORY}/plugins)
49+
50+
set_target_properties(${MODULE_NAME} PROPERTIES
51+
CXX_STANDARD 11
52+
CXX_STANDARD_REQUIRED YES)
53+
54+
target_include_directories(${MODULE_NAME} PRIVATE ../helpers)
55+
target_include_directories(${MODULE_NAME} PRIVATE ../common)
56+
target_include_directories(${MODULE_NAME} PRIVATE ./)
57+
58+
add_library(${PLUGIN_IMPLEMENTATION} SHARED
59+
MigrationPreparerImplementation.cpp
60+
Module.cpp)
61+
62+
set_target_properties(${PLUGIN_IMPLEMENTATION} PROPERTIES
63+
CXX_STANDARD 11
64+
CXX_STANDARD_REQUIRED YES)
65+
66+
target_include_directories(${PLUGIN_IMPLEMENTATION} PRIVATE ../helpers)
67+
target_include_directories(${PLUGIN_IMPLEMENTATION} PRIVATE ../common)
68+
target_include_directories(${PLUGIN_IMPLEMENTATION} PRIVATE ./)
69+
70+
# if (RDK_SERVICE_L2_TEST)
71+
# find_library(TESTMOCKLIB_LIBRARIES NAMES TestMocklib)
72+
# if (TESTMOCKLIB_LIBRARIES)
73+
# message ("linking mock libraries ${TESTMOCKLIB_LIBRARIES} library")
74+
# target_link_libraries(${PLUGIN_IMPLEMENTATION} PRIVATE ${TESTMOCKLIB_LIBRARIES})
75+
# else (TESTMOCKLIB_LIBRARIES)
76+
# message ("Require ${TESTMOCKLIB_LIBRARIES} library")
77+
# endif (TESTMOCKLIB_LIBRARIES)
78+
# endif (RDK_SERVICES_L2_TEST)
79+
80+
target_link_libraries(${PLUGIN_IMPLEMENTATION}
81+
PRIVATE
82+
CompileSettingsDebug::CompileSettingsDebug
83+
${NAMESPACE}Plugins::${NAMESPACE}Plugins
84+
${RBUS_LIBRARIES})
85+
86+
install(TARGETS ${PLUGIN_IMPLEMENTATION}
87+
DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/${STORAGE_DIRECTORY}/plugins)
88+
89+
write_config(${PLUGIN_NAME})
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
callsign = "org.rdk.MigrationPreparer"
2+
precondition = ["Platform"]
3+
autostart = "@PLUGIN_MIGRATIONPREPARER_AUTOSTART@"
4+
startuporder = "@PLUGIN_MIGRATIONPREPARER_STARTUPORDER@"
5+
6+
configuration = JSON()
7+
8+
rootobject = JSON()
9+
rootobject.add("mode", "@PLUGIN_MIGRATIONPREPARER_MODE@")
10+
rootobject.add("locator", "lib@[email protected]")
11+
configuration.add("root", rootobject)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
set(autostart ${PLUGIN_MIGRATIONPREPARER_AUTOSTART})
2+
set(preconditions Platform)
3+
4+
if(PLUGIN_MIGRATIONPREPARER_STARTUPORDER)
5+
set (startuporder ${PLUGIN_MIGRATIONPREPARER_STARTUPORDER})
6+
endif()
7+
8+
map()
9+
key(root)
10+
map()
11+
kv(mode ${PLUGIN_MIGRATIONPREPARER_MODE})
12+
kv(locator lib${PLUGIN_IMPLEMENTATION}.so)
13+
end()
14+
end()
15+
ans(configuration)
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
/*
2+
* If not stated otherwise in this file or this component's LICENSE file the
3+
* following copyright and licenses apply:
4+
*
5+
* Copyright 2024 RDK Management
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
20+
#include "MigrationPreparer.h"
21+
22+
#define API_VERSION_NUMBER_MAJOR 1
23+
#define API_VERSION_NUMBER_MINOR 0
24+
#define API_VERSION_NUMBER_PATCH 0
25+
26+
namespace WPEFramework
27+
{
28+
29+
namespace {
30+
31+
static Plugin::Metadata<Plugin::MigrationPreparer> metadata(
32+
// Version (Major, Minor, Patch)
33+
API_VERSION_NUMBER_MAJOR, API_VERSION_NUMBER_MINOR, API_VERSION_NUMBER_PATCH,
34+
// Preconditions
35+
{},
36+
// Terminations
37+
{},
38+
// Controls
39+
{}
40+
);
41+
}
42+
43+
namespace Plugin
44+
{
45+
46+
/*
47+
*Register MigrationPreparer module as wpeframework plugin
48+
**/
49+
SERVICE_REGISTRATION(MigrationPreparer, API_VERSION_NUMBER_MAJOR, API_VERSION_NUMBER_MINOR, API_VERSION_NUMBER_PATCH);
50+
51+
MigrationPreparer::MigrationPreparer() : _service(nullptr), _connectionId(0), _migrationPreparer(nullptr)
52+
{
53+
SYSLOG(Logging::Startup, (_T("MigrationPreparer Constructor")));
54+
RegisterAll();
55+
}
56+
57+
MigrationPreparer::~MigrationPreparer()
58+
{
59+
SYSLOG(Logging::Shutdown, (string(_T("MigrationPreparer Destructor"))));
60+
UnregisterAll();
61+
}
62+
63+
const string MigrationPreparer::Initialize(PluginHost::IShell* service)
64+
{
65+
string message="";
66+
67+
ASSERT(nullptr != service);
68+
ASSERT(nullptr == _service);
69+
ASSERT(nullptr == _migrationPreparer);
70+
ASSERT(0 == _connectionId);
71+
72+
SYSLOG(Logging::Startup, (_T("MigrationPreparer::Initialize: PID=%u"), getpid()));
73+
74+
_service = service;
75+
_service->AddRef();
76+
_migrationPreparer = _service->Root<Exchange::IMigrationPreparer>(_connectionId, 5000, _T("MigrationPreparerImplementation"));
77+
78+
if(nullptr == _migrationPreparer)
79+
{
80+
SYSLOG(Logging::Startup, (_T("MigrationPreparer::Initialize: Failed to initialise MigrationPreparer plugin")));
81+
message = _T("MigrationPreparer plugin could not be initialised");
82+
}
83+
84+
if (0 != message.length())
85+
{
86+
Deinitialize(service);
87+
}
88+
89+
return message;
90+
}
91+
92+
void MigrationPreparer::Deinitialize(PluginHost::IShell* service)
93+
{
94+
ASSERT(_service == service);
95+
96+
SYSLOG(Logging::Shutdown, (string(_T("MigrationPreparer::Deinitialize"))));
97+
98+
if (nullptr != _migrationPreparer)
99+
{
100+
// Stop processing:
101+
RPC::IRemoteConnection* connection = service->RemoteConnection(_connectionId);
102+
VARIABLE_IS_NOT_USED uint32_t result = _migrationPreparer->Release();
103+
104+
_migrationPreparer = nullptr;
105+
106+
// It should have been the last reference we are releasing,
107+
// so it should endup in a DESTRUCTION_SUCCEEDED, if not we
108+
// are leaking...
109+
ASSERT(result == Core::ERROR_DESTRUCTION_SUCCEEDED);
110+
111+
// If this was running in a (container) process...
112+
if (nullptr != connection)
113+
{
114+
// Lets trigger the cleanup sequence for
115+
// out-of-process code. Which will guard
116+
// that unwilling processes, get shot if
117+
// not stopped friendly :-)
118+
connection->Terminate();
119+
connection->Release();
120+
}
121+
}
122+
123+
_connectionId = 0;
124+
_service->Release();
125+
_service = nullptr;
126+
SYSLOG(Logging::Shutdown, (string(_T("MigrationPreparer de-initialised"))));
127+
}
128+
129+
string MigrationPreparer::Information() const
130+
{
131+
return (string("{\"service\": \"") + string("org.rdk.MigrationPreparer") + string("\"}"));
132+
}
133+
134+
} // namespace Plugin
135+
} // namespace WPEFramework
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
* If not stated otherwise in this file or this component's LICENSE file the
3+
* following copyright and licenses apply:
4+
*
5+
* Copyright 2024 RDK Management
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
20+
#pragma once
21+
22+
#include "Module.h"
23+
#include <interfaces/json/JsonData_MigrationPreparer.h>
24+
#include <interfaces/json/JMigrationPreparer.h>
25+
#include <interfaces/IMigrationPreparer.h>
26+
#include "UtilsLogging.h"
27+
#include "tracing/Logging.h"
28+
#include "UtilsJsonRpc.h"
29+
#include <mutex>
30+
31+
// PLUGIN SPECIFIC CUSTOM ERROR CODES
32+
#define ERROR_CREATE 4
33+
#define ERROR_OPEN 5
34+
#define ERROR_WRITE 6
35+
#define ERROR_NAME 7
36+
#define ERROR_DELETE 8
37+
#define ERROR_SET 9
38+
#define ERROR_RESET 10
39+
#define ERROR_INVALID 11
40+
#define ERROR_NOFILE 12
41+
#define ERROR_FILEEMPTY 13
42+
43+
namespace WPEFramework {
44+
namespace Plugin {
45+
46+
class MigrationPreparer: public PluginHost::IPlugin, public PluginHost::JSONRPC
47+
{
48+
public:
49+
// We do not allow this plugin to be copied !!
50+
MigrationPreparer(const MigrationPreparer&) = delete;
51+
MigrationPreparer& operator=(const MigrationPreparer&) = delete;
52+
53+
MigrationPreparer();
54+
virtual ~MigrationPreparer();
55+
56+
BEGIN_INTERFACE_MAP(MigrationPreparer)
57+
INTERFACE_ENTRY(PluginHost::IPlugin)
58+
INTERFACE_ENTRY(PluginHost::IDispatcher)
59+
INTERFACE_AGGREGATE(Exchange::IMigrationPreparer, _migrationPreparer)
60+
END_INTERFACE_MAP
61+
62+
// IPlugin methods
63+
// -------------------------------------------------------------------------------------------------------
64+
const string Initialize(PluginHost::IShell* service) override;
65+
void Deinitialize(PluginHost::IShell* service) override;
66+
string Information() const override;
67+
68+
private:
69+
void RegisterAll();
70+
void UnregisterAll();
71+
72+
uint32_t endpoint_write(const JsonObject& parameters, JsonObject& response);
73+
uint32_t endpoint_read(const JsonObject& parameters, JsonObject& response);
74+
uint32_t endpoint_delete(const JsonObject& parameters, JsonObject& response);
75+
uint32_t endpoint_getComponentReadiness(const JsonObject& parameters, JsonData::MigrationPreparer::GetcomponentreadinessResultData& response);
76+
uint32_t endpoint_setComponentReadiness(const JsonObject& parameters, JsonObject& response);
77+
uint32_t endpoint_reset(const JsonObject& parameters, JsonObject& response);
78+
79+
private:
80+
PluginHost::IShell* _service{};
81+
uint32_t _connectionId{};
82+
Exchange::IMigrationPreparer* _migrationPreparer{};
83+
};
84+
85+
} // namespace Plugin
86+
} // namespace WPEFramework

0 commit comments

Comments
 (0)