Skip to content

Commit

Permalink
Merge pull request #5417 from npoltorapavlo/DELIA-65017_qs030
Browse files Browse the repository at this point in the history
Delia 65017 qs030
  • Loading branch information
anand-ky committed Jun 14, 2024
2 parents c1dba90 + ef37228 commit 1bd4234
Show file tree
Hide file tree
Showing 21 changed files with 660 additions and 487 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/L2-PersistentStore-grpc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,9 @@ jobs:
run: |
cmake -S ${GITHUB_REPOSITORY}/PersistentStore/grpc/l2test -B build/grpcl2test -DCMAKE_INSTALL_PREFIX="install/usr" -DCMAKE_CXX_FLAGS="-Wall -Werror"
cmake --build build/grpcl2test --target install
# (Optional)
# Rebuild with real token (here: kToken = "Bearer TOKEN"):
# cmake --build build/grpcl2test --target install
# Run:
# PATH=${PWD}/install/usr/bin:${PATH} LD_LIBRARY_PATH=${PWD}/install/usr/lib:${LD_LIBRARY_PATH} valgrind --tool=memcheck --log-file=valgrind_log --leak-check=yes --show-reachable=yes --track-fds=yes --fair-sched=try grpcl2test
45 changes: 45 additions & 0 deletions .github/workflows/L2-PersistentStore.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: L2-PersistentStore

on:
push:
paths:
- PersistentStore/**
pull_request:
paths:
- PersistentStore/**

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
path: ${{github.repository}}

- name: Install cmake, sqlite, protoc, grpc_cpp_plugin, grpc
run: |
sudo apt update
sudo apt install -y cmake libsqlite3-dev protobuf-compiler protobuf-compiler-grpc libgrpc++-dev
- name: Build Thunder
working-directory: ${{github.workspace}}
run: sh +x ${GITHUB_REPOSITORY}/.github/workflows/BuildThunder.sh

- name: Build
working-directory: ${{github.workspace}}
run: |
cmake -S ${GITHUB_REPOSITORY}/PersistentStore -B build/PersistentStore -DCMAKE_INSTALL_PREFIX="install/usr" -DCMAKE_CXX_FLAGS="-Wall -Werror" -DPLUGIN_PERSISTENTSTORE_PATH="/tmp/persistentstore/l2test/test"
cmake --build build/PersistentStore --target install
# (Optional)
# Thunder startup:
# PATH=${PWD}/install/usr/bin:${PATH} LD_LIBRARY_PATH=${PWD}/install/usr/lib:${LD_LIBRARY_PATH} valgrind --tool=memcheck --log-file=valgrind_log --leak-check=yes --show-reachable=yes --track-fds=yes --fair-sched=try WPEFramework -f -c ${PWD}/install/etc/WPEFramework/config.json
# (to stop press q & enter)
# API test:
# curl -d '{"jsonrpc":"2.0","id":0,"method":"org.rdk.PersistentStore.setValue","params":{"namespace":"test","key":"key1","value":"1","ttl":100}}' http://localhost:55555/jsonrpc
# curl -d '{"jsonrpc":"2.0","id":0,"method":"org.rdk.PersistentStore.getValue","params":{"namespace":"test","key":"key1"}}' http://localhost:55555/jsonrpc
# Crash test:
# kill -SIGFPE $(pidof WPEProcess)
# Deactivate test:
# curl -d '{"jsonrpc":"2.0","id":0,"method":"Controller.1.deactivate", "params":{"callsign":"org.rdk.PersistentStore"}}' http://localhost:55555/jsonrpc
6 changes: 6 additions & 0 deletions PersistentStore/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ All notable changes to this RDK Service will be documented in this file.

* For more details, refer to [versioning](https://github.com/rdkcentral/rdkservices#versioning) section under Main README.

## [1.0.14] - 2024-06-14
### Fixed
- Spawn 1 process instead of 2
- Do not activate if process times out
- Deactivate if process crashes

## [1.0.13] - 2024-05-31
### Fixed
- Add support for error 5 (NOT_FOUND) returned from SecureStore endpoint
Expand Down
9 changes: 7 additions & 2 deletions PersistentStore/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ cmake_minimum_required(VERSION 3.14)

set(PLUGIN_NAME PersistentStore)
find_package(WPEFramework)
if (NOT WPEFramework_FOUND)
find_package(Thunder)
if (Thunder_FOUND)
add_compile_definitions(WITH_THUNDER_NAMESPACE)
endif ()
endif ()
set(MODULE_NAME ${NAMESPACE}${PLUGIN_NAME})

set(CMAKE_CXX_STANDARD 11)
Expand Down Expand Up @@ -61,8 +67,8 @@ install(TARGETS ${MODULE_NAME}

set(PLUGIN_IMPLEMENTATION ${MODULE_NAME}Implementation)
add_library(${PLUGIN_IMPLEMENTATION} SHARED
sqlite/Store2.cpp
Module.cpp
PersistentStoreImplementation.cpp
)

target_link_libraries(${PLUGIN_IMPLEMENTATION} PRIVATE
Expand All @@ -84,7 +90,6 @@ if (IARMBUS_LIBRARIES)
endif ()

if (PLUGIN_PERSISTENTSTORE_WITH_ACCOUNT_SCOPE)
target_sources(${PLUGIN_IMPLEMENTATION} PRIVATE grpc/Store2.cpp)
find_package(Protobuf REQUIRED)
target_link_libraries(${PLUGIN_IMPLEMENTATION} PRIVATE ${Protobuf_LIBRARIES})

Expand Down
112 changes: 74 additions & 38 deletions PersistentStore/PersistentStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,17 @@

#define API_VERSION_NUMBER_MAJOR 1
#define API_VERSION_NUMBER_MINOR 0
#define API_VERSION_NUMBER_PATCH 13
#define API_VERSION_NUMBER_PATCH 14

namespace WPEFramework {

namespace {

#ifdef WITH_THUNDER_NAMESPACE
static Thunder::Plugin::Metadata<Plugin::PersistentStore> metadata(
#else
static Plugin::Metadata<Plugin::PersistentStore> metadata(
#endif
// Version (Major, Minor, Patch)
API_VERSION_NUMBER_MAJOR, API_VERSION_NUMBER_MINOR, API_VERSION_NUMBER_PATCH,
// Preconditions
Expand All @@ -51,8 +55,20 @@ namespace Plugin {
string result;

ASSERT(service != nullptr);
ASSERT(_store == nullptr);
ASSERT(_store2 == nullptr);
ASSERT(_storeCache == nullptr);
ASSERT(_storeInspector == nullptr);
ASSERT(_storeLimit == nullptr);
ASSERT(_service == nullptr);
ASSERT(_connectionId == 0);

SYSLOG(Logging::Startup, (_T("PersistentStore::Initialize: PID=%u"), getpid()));

_service = service;
_service->AddRef();

auto configLine = service->ConfigLine();
auto configLine = _service->ConfigLine();
_config.FromString(configLine);

{
Expand Down Expand Up @@ -91,50 +107,70 @@ namespace Plugin {
Core::SystemInfo::SetEnvironment(MAXVALUE_ENV, std::to_string(_config.MaxValue.Value()));
Core::SystemInfo::SetEnvironment(LIMIT_ENV, std::to_string(_config.Limit.Value()));

uint32_t connectionId;
_service->Register(&_notification);

_deviceStore2 = service->Root<Exchange::IStore2>(connectionId, RPC::CommunicationTimeOut, _T("SqliteStore2"));
if (_deviceStore2 != nullptr) {
_deviceStore2->Register(&_store2Sink);
_deviceStore2->Register(_store);
_deviceStoreCache = _deviceStore2->QueryInterface<Exchange::IStoreCache>();
_deviceStoreInspector = _deviceStore2->QueryInterface<Exchange::IStoreInspector>();
_deviceStoreLimit = _deviceStore2->QueryInterface<Exchange::IStoreLimit>();
}

_accountStore2 = service->Root<Exchange::IStore2>(connectionId, RPC::CommunicationTimeOut, _T("GrpcStore2"));
if (_accountStore2 != nullptr) {
_accountStore2->Register(&_store2Sink);
_store = _service->Root<Exchange::IStore>(_connectionId, RPC::CommunicationTimeOut, _T("PersistentStoreImplementation"));
if (_store != nullptr) {
_store2 = _store->QueryInterface<Exchange::IStore2>();
if (_store2 != nullptr) {
_store2->Register(&_store2Sink);
}
_storeCache = _store->QueryInterface<Exchange::IStoreCache>();
_storeInspector = _store->QueryInterface<Exchange::IStoreInspector>();
_storeLimit = _store->QueryInterface<Exchange::IStoreLimit>();

ASSERT(_store2 != nullptr);
ASSERT(_storeCache != nullptr);
ASSERT(_storeInspector != nullptr);
ASSERT(_storeLimit != nullptr);
} else {
result = _T("Couldn't create implementation instance");
}

return result;
}

void PersistentStore::Deinitialize(PluginHost::IShell* /* service */)
void PersistentStore::Deinitialize(PluginHost::IShell* service)
{
if (_deviceStore2 != nullptr) {
_deviceStore2->Unregister(&_store2Sink);
_deviceStore2->Unregister(_store);
_deviceStore2->Release();
_deviceStore2 = nullptr;
}
if (_deviceStoreCache != nullptr) {
_deviceStoreCache->Release();
_deviceStoreCache = nullptr;
}
if (_deviceStoreInspector != nullptr) {
_deviceStoreInspector->Release();
_deviceStoreInspector = nullptr;
}
if (_deviceStoreLimit != nullptr) {
_deviceStoreLimit->Release();
_deviceStoreLimit = nullptr;
}
if (_accountStore2 != nullptr) {
_accountStore2->Unregister(&_store2Sink);
_accountStore2->Release();
_accountStore2 = nullptr;
ASSERT(_service == service);

SYSLOG(Logging::Shutdown, (string(_T("DTV::Deinitialize"))));

_service->Unregister(&_notification);

if (_store != nullptr) {
if (_store2 != nullptr) {
_store2->Unregister(&_store2Sink);
_store2->Release();
_store2 = nullptr;
}
if (_storeCache != nullptr) {
_storeCache->Release();
_storeCache = nullptr;
}
if (_storeInspector != nullptr) {
_storeInspector->Release();
_storeInspector = nullptr;
}
if (_storeLimit != nullptr) {
_storeLimit->Release();
_storeLimit = nullptr;
}

auto connection = _service->RemoteConnection(_connectionId);
VARIABLE_IS_NOT_USED auto result = _store->Release();
_store = nullptr;
ASSERT(result == Core::ERROR_DESTRUCTION_SUCCEEDED);
if (connection != nullptr) {
connection->Terminate();
connection->Release();
}
}

_connectionId = 0;
_service->Release();
_service = nullptr;
SYSLOG(Logging::Shutdown, (string(_T("PersistentStore de-initialised"))));
}

string PersistentStore::Information() const
Expand Down
Loading

0 comments on commit 1bd4234

Please sign in to comment.