diff --git a/DisplaySettings/DisplaySettings.cpp b/DisplaySettings/DisplaySettings.cpp index 8da0c12747..f97dd38c48 100644 --- a/DisplaySettings/DisplaySettings.cpp +++ b/DisplaySettings/DisplaySettings.cpp @@ -97,6 +97,7 @@ bool isStbHDRcapabilitiesCache = false; static int hdmiArcPortId = -1; static int retryPowerRequestCount = 0; static int hdmiArcVolumeLevel = 0; +bool audioPortInitActive = false; std::vector sad_list; #ifdef USE_IARM namespace @@ -572,6 +573,11 @@ namespace WPEFramework { { if (m_sendMsgThread.joinable()) m_sendMsgThread.join(); + int count = 0; + while(audioPortInitActive && count < 20){ + sleep(100); + count++; + } } catch(const std::system_error& e) { @@ -4706,7 +4712,9 @@ namespace WPEFramework { void DisplaySettings::initAudioPortsWorker(void) { + audioPortInitActive = true; DisplaySettings::_instance->InitAudioPorts(); + audioPortInitActive = false; } void DisplaySettings::powerEventHandler(const char *owner, IARM_EventId_t eventId, void *data, size_t len) diff --git a/MaintenanceManager/CHANGELOG.md b/MaintenanceManager/CHANGELOG.md index 2bcd4597bb..68d2d008be 100644 --- a/MaintenanceManager/CHANGELOG.md +++ b/MaintenanceManager/CHANGELOG.md @@ -16,6 +16,10 @@ 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.28] - 2024-03-20 +### Fixed +- Fixed Activation Logic for Maintenance Manager WAI + ## [1.0.27] - 2024-01-16 ### Fixed - Fixed Network Retry logic in Maintenance Manager in isDeviceOnline() diff --git a/MaintenanceManager/MaintenanceManager.cpp b/MaintenanceManager/MaintenanceManager.cpp index ece671676e..bb706ef085 100644 --- a/MaintenanceManager/MaintenanceManager.cpp +++ b/MaintenanceManager/MaintenanceManager.cpp @@ -300,7 +300,7 @@ namespace WPEFramework { } /* Controlled by CFLAGS */ -#if defined(SUPPRESS_MAINTENANCE) +#if defined(SUPPRESS_MAINTENANCE) && !defined(ENABLE_WHOAMI) bool activationStatus=false; bool skipFirmwareCheck=false; @@ -319,7 +319,7 @@ namespace WPEFramework { #endif #if defined(ENABLE_WHOAMI) - string activation_status = ""; + string activation_status = checkActivatedStatus(); if (UNSOLICITED_MAINTENANCE == g_maintenance_type) { /* WhoAmI check*/ bool whoAmIStatus = knowWhoAmI(activation_status); @@ -480,7 +480,6 @@ namespace WPEFramework { retryCount++; if (retryCount == 4 && !success) { - activation_status = checkActivatedStatus(); if (activation_status == "activated") { LOGINFO("Device is already activated. Exiting from knowWhoAmI()"); success = true; diff --git a/Miracast/MiracastService/MiracastController.cpp b/Miracast/MiracastService/MiracastController.cpp index 7b787b2db3..53808ada4e 100644 --- a/Miracast/MiracastService/MiracastController.cpp +++ b/Miracast/MiracastService/MiracastController.cpp @@ -637,7 +637,6 @@ void MiracastController::Controller_Thread(void *args) CONTROLLER_MSGQ_STRUCT controller_msgq_data = {0}; bool new_thunder_req_client_connection_sent = false, another_thunder_req_client_connection_sent = false, - start_discovering_enabled = false, session_restart_required = false, p2p_group_instance_alive = false; @@ -1067,7 +1066,7 @@ void MiracastController::Controller_Thread(void *args) m_notify_handler->onMiracastServiceClientConnectionError( mac_address , device_name , error_code ); } MIRACASTLOG_INFO("!!! Restarting Session !!!"); - restart_session(start_discovering_enabled); + restart_session(m_start_discovering_enabled); session_restart_required = false; } } @@ -1140,14 +1139,14 @@ void MiracastController::Controller_Thread(void *args) MIRACASTLOG_INFO("CONTROLLER_START_DISCOVERING Received\n"); set_WFDParameters(); discover_devices(); - start_discovering_enabled = true; + m_start_discovering_enabled = true; } break; case CONTROLLER_STOP_DISCOVERING: { MIRACASTLOG_INFO("CONTROLLER_STOP_DISCOVERING Received\n"); stop_session(true); - start_discovering_enabled = false; + m_start_discovering_enabled = false; } break; case CONTROLLER_RESTART_DISCOVERING: @@ -1163,7 +1162,7 @@ void MiracastController::Controller_Thread(void *args) reset_NewSourceName(); MIRACASTLOG_INFO("[%s] Cached Device info removed...",cached_mac_address.c_str()); } - restart_session(start_discovering_enabled); + restart_session(m_start_discovering_enabled); new_thunder_req_client_connection_sent = false; another_thunder_req_client_connection_sent = false; session_restart_required = true; @@ -1244,7 +1243,7 @@ void MiracastController::Controller_Thread(void *args) { MIRACASTLOG_INFO("TEARDOWN request sent to RTSP handler\n"); //stop_streaming(CONTROLLER_TEARDOWN_REQ_FROM_THUNDER); - restart_session(start_discovering_enabled); + restart_session(m_start_discovering_enabled); } break; default: @@ -1557,16 +1556,22 @@ void MiracastController::send_thundermsg_to_controller_thread(MIRACAST_SERVICE_S void MiracastController::set_enable(bool is_enabled) { - MIRACAST_SERVICE_STATES state = MIRACAST_SERVICE_WFD_STOP; - MIRACASTLOG_TRACE("Entering..."); if ( true == is_enabled) { - state = MIRACAST_SERVICE_WFD_START; + MIRACASTLOG_INFO("MIRACAST_SERVICE_WFD_START Received"); + set_WFDParameters(); + discover_devices(); + m_start_discovering_enabled = true; } - - send_thundermsg_to_controller_thread(state); + else + { + MIRACASTLOG_INFO("MIRACAST_SERVICE_WFD_STOP Received"); + stop_session(true); + m_start_discovering_enabled = false; + } + //send_thundermsg_to_controller_thread(state); MIRACASTLOG_TRACE("Exiting..."); } diff --git a/Miracast/P2P/MiracastP2P.cpp b/Miracast/P2P/MiracastP2P.cpp index 29d5e18673..327cf2ecf4 100644 --- a/Miracast/P2P/MiracastP2P.cpp +++ b/Miracast/P2P/MiracastP2P.cpp @@ -457,7 +457,7 @@ void MiracastP2P::reset_WFDParameters(void) MiracastError MiracastP2P::discover_devices(void) { MiracastError ret = MIRACAST_FAIL; - std::string command, retBuffer,opt_flag_buffer; + std::string command, retBuffer; MIRACASTLOG_TRACE("Entering.."); /*Start Passive Scanning*/ @@ -479,12 +479,14 @@ MiracastError MiracastP2P::stop_discover_devices(void) MIRACASTLOG_TRACE("Entering..."); /*Stop Passive Scanning*/ - command = "P2P_EXT_LISTEN 0 0"; + command = "P2P_STOP_FIND"; + ret = executeCommand(command, NON_GLOBAL_INTERFACE, retBuffer); if (ret != MIRACAST_OK) { MIRACASTLOG_ERROR("Failed to Stop discovering devices"); } + MIRACASTLOG_TRACE("Exiting..."); return ret; } diff --git a/Miracast/include/MiracastController.h b/Miracast/include/MiracastController.h index 7e1aad5967..e94e865c51 100644 --- a/Miracast/include/MiracastController.h +++ b/Miracast/include/MiracastController.h @@ -137,6 +137,7 @@ class MiracastController GroupInfo *m_groupInfo; bool m_connectionStatus; bool m_p2p_backend_discovery{false}; + bool m_start_discovering_enabled{false}; std::string m_current_device_name; std::string m_current_device_mac_addr; diff --git a/PersistentStore/CHANGELOG.md b/PersistentStore/CHANGELOG.md index d31d919f4d..593a204ccc 100644 --- a/PersistentStore/CHANGELOG.md +++ b/PersistentStore/CHANGELOG.md @@ -16,6 +16,11 @@ 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.9] - 2024-04-01 +### Added +- Get token from auth service, supply ids in the cloud calls +- Return ERROR_NOT_SUPPORTED if unsupported + ## [1.0.8] - 2024-03-21 ### Added - Account scope implementation diff --git a/PersistentStore/CMakeLists.txt b/PersistentStore/CMakeLists.txt index 8df164f077..fdefac6b4f 100644 --- a/PersistentStore/CMakeLists.txt +++ b/PersistentStore/CMakeLists.txt @@ -61,9 +61,6 @@ install(TARGETS ${MODULE_NAME} set(PLUGIN_IMPLEMENTATION ${MODULE_NAME}Implementation) add_library(${PLUGIN_IMPLEMENTATION} SHARED sqlite/Store2.cpp - sqlite/StoreCache.cpp - sqlite/StoreInspector.cpp - sqlite/StoreLimit.cpp grpc/Store2.cpp Module.cpp ) diff --git a/PersistentStore/Module.h b/PersistentStore/Module.h index fa393a364b..bce1d970a4 100644 --- a/PersistentStore/Module.h +++ b/PersistentStore/Module.h @@ -34,7 +34,6 @@ #define MAXSIZE_ENV "PERSISTENTSTORE_MAXSIZE" #define MAXVALUE_ENV "PERSISTENTSTORE_MAXVALUE" #define LIMIT_ENV "PERSISTENTSTORE_LIMIT" -#define TOKEN_COMMAND_ENV "PERSISTENTSTORE_TOKEN_COMMAND" #define IARM_INIT_NAME "Thunder_Plugins" #define URI_RFC "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.PersistentStore.Uri" diff --git a/PersistentStore/PersistentStore.conf.in b/PersistentStore/PersistentStore.conf.in index 244967ed15..d5b5965460 100644 --- a/PersistentStore/PersistentStore.conf.in +++ b/PersistentStore/PersistentStore.conf.in @@ -16,4 +16,3 @@ configuration.add("key", "@PLUGIN_PERSISTENTSTORE_KEY@") configuration.add("maxsize", "@PLUGIN_PERSISTENTSTORE_MAXSIZE@") configuration.add("maxvalue", "@PLUGIN_PERSISTENTSTORE_MAXVALUE@") configuration.add("limit", "@PLUGIN_PERSISTENTSTORE_LIMIT@") -configuration.add("tokencommand", "@PLUGIN_PERSISTENTSTORE_TOKEN_COMMAND@") diff --git a/PersistentStore/PersistentStore.config b/PersistentStore/PersistentStore.config index 5d6d4c59cd..3b6fde49f1 100644 --- a/PersistentStore/PersistentStore.config +++ b/PersistentStore/PersistentStore.config @@ -19,6 +19,5 @@ map() kv(maxsize ${PLUGIN_PERSISTENTSTORE_MAXSIZE}) kv(maxvalue ${PLUGIN_PERSISTENTSTORE_MAXVALUE}) kv(limit ${PLUGIN_PERSISTENTSTORE_LIMIT}) - kv(tokencommand ${PLUGIN_PERSISTENTSTORE_TOKEN_COMMAND}) end() ans(configuration) diff --git a/PersistentStore/PersistentStore.cpp b/PersistentStore/PersistentStore.cpp index 9ea464f11e..caf8a730ed 100644 --- a/PersistentStore/PersistentStore.cpp +++ b/PersistentStore/PersistentStore.cpp @@ -25,7 +25,7 @@ #define API_VERSION_NUMBER_MAJOR 1 #define API_VERSION_NUMBER_MINOR 0 -#define API_VERSION_NUMBER_PATCH 8 +#define API_VERSION_NUMBER_PATCH 9 namespace WPEFramework { @@ -90,57 +90,50 @@ namespace Plugin { Core::SystemInfo::SetEnvironment(MAXSIZE_ENV, std::to_string(_config.MaxSize.Value())); Core::SystemInfo::SetEnvironment(MAXVALUE_ENV, std::to_string(_config.MaxValue.Value())); Core::SystemInfo::SetEnvironment(LIMIT_ENV, std::to_string(_config.Limit.Value())); - Core::SystemInfo::SetEnvironment(TOKEN_COMMAND_ENV, _config.TokenCommand.Value()); uint32_t connectionId; - Store2::ScopeMapType initList1; - auto deviceStore2 = service->Root(connectionId, 2000, _T("SqliteStore2")); - if (deviceStore2 != nullptr) { - initList1.emplace(Exchange::IStore2::ScopeType::DEVICE, deviceStore2); + _deviceStore2 = service->Root(connectionId, 2000, _T("SqliteStore2")); + if (_deviceStore2 != nullptr) { + _deviceStore2->Register(&_store2Sink); + _deviceStore2->Register(_store); + _deviceStoreCache = _deviceStore2->QueryInterface(); + _deviceStoreInspector = _deviceStore2->QueryInterface(); + _deviceStoreLimit = _deviceStore2->QueryInterface(); } - auto accountStore2 = service->Root(connectionId, 2000, _T("GrpcStore2")); - if (accountStore2 != nullptr) { - initList1.emplace(Exchange::IStore2::ScopeType::ACCOUNT, accountStore2); - } - _store2 = Core::Service::Create(initList1); - if (deviceStore2 != nullptr) { - deviceStore2->Release(); - } - if (accountStore2 != nullptr) { - accountStore2->Release(); + + _accountStore2 = service->Root(connectionId, 2000, _T("GrpcStore2")); + if (_accountStore2 != nullptr) { + _accountStore2->Register(&_store2Sink); } - _store2->Register(&_store2Sink); - _store = Core::Service::Create(_store2); - _storeCache = service->Root(connectionId, 2000, _T("SqliteStoreCache")); - _storeInspector = service->Root(connectionId, 2000, _T("SqliteStoreInspector")); - _storeLimit = service->Root(connectionId, 2000, _T("SqliteStoreLimit")); return result; } void PersistentStore::Deinitialize(PluginHost::IShell* /* service */) { - if (_store != nullptr) { - _store->Release(); - _store = nullptr; + if (_deviceStore2 != nullptr) { + _deviceStore2->Unregister(&_store2Sink); + _deviceStore2->Unregister(_store); + _deviceStore2->Release(); + _deviceStore2 = nullptr; } - if (_store2 != nullptr) { - _store2->Unregister(&_store2Sink); - _store2->Release(); - _store2 = nullptr; + if (_deviceStoreCache != nullptr) { + _deviceStoreCache->Release(); + _deviceStoreCache = nullptr; } - if (_storeCache != nullptr) { - _storeCache->Release(); - _storeCache = nullptr; + if (_deviceStoreInspector != nullptr) { + _deviceStoreInspector->Release(); + _deviceStoreInspector = nullptr; } - if (_storeInspector != nullptr) { - _storeInspector->Release(); - _storeInspector = nullptr; + if (_deviceStoreLimit != nullptr) { + _deviceStoreLimit->Release(); + _deviceStoreLimit = nullptr; } - if (_storeLimit != nullptr) { - _storeLimit->Release(); - _storeLimit = nullptr; + if (_accountStore2 != nullptr) { + _accountStore2->Unregister(&_store2Sink); + _accountStore2->Release(); + _accountStore2 = nullptr; } } diff --git a/PersistentStore/PersistentStore.h b/PersistentStore/PersistentStore.h index 3d97f0b322..c0886b645c 100644 --- a/PersistentStore/PersistentStore.h +++ b/PersistentStore/PersistentStore.h @@ -20,7 +20,6 @@ #pragma once #include "Module.h" - #include #include #include @@ -50,7 +49,6 @@ namespace Plugin { Add(_T("maxsize"), &MaxSize); Add(_T("maxvalue"), &MaxValue); Add(_T("limit"), &Limit); - Add(_T("tokencommand"), &TokenCommand); } public: @@ -61,7 +59,6 @@ namespace Plugin { Core::JSON::DecUInt64 MaxSize; Core::JSON::DecUInt64 MaxValue; Core::JSON::DecUInt64 Limit; - Core::JSON::String TokenCommand; }; class Store2Notification : public Exchange::IStore2::INotification { @@ -70,15 +67,13 @@ namespace Plugin { Store2Notification& operator=(const Store2Notification&) = delete; public: - explicit Store2Notification(PersistentStore* parent) - : _parent(*parent) + explicit Store2Notification(PersistentStore& parent) + : _parent(parent) { } ~Store2Notification() override = default; public: - // IStore2::INotification methods - void ValueChanged(const Exchange::IStore2::ScopeType scope, const string& ns, const string& key, const string& value) override { JsonData::PersistentStore::SetValueParamsData params; @@ -99,66 +94,20 @@ namespace Plugin { }; // Deprecated - class Store : public Exchange::IStore { + class Store : public Exchange::IStore, + public Exchange::IStore2::INotification { private: Store(const Store&) = delete; Store& operator=(const Store&) = delete; - private: - class Store2Notification : public Exchange::IStore2::INotification { - private: - Store2Notification(const Store2Notification&) = delete; - Store2Notification& operator=(const Store2Notification&) = delete; - - public: - explicit Store2Notification(Store* parent) - : _parent(*parent) - { - } - ~Store2Notification() override = default; - - public: - // IStore2::INotification methods - - void ValueChanged(const Exchange::IStore2::ScopeType, const string& ns, const string& key, const string& value) override - { - Core::SafeSyncType lock(_parent._clientLock); - - std::list::iterator - index(_parent._clients.begin()); - - while (index != _parent._clients.end()) { - (*index)->ValueChanged(ns, key, value); - index++; - } - } - - BEGIN_INTERFACE_MAP(Store2Notification) - INTERFACE_ENTRY(Exchange::IStore2::INotification) - END_INTERFACE_MAP - - private: - Store& _parent; - }; - public: - Store(Exchange::IStore2* store2) - : _store2(store2) - , _store2Sink(this) + Store(PersistentStore& parent) + : _parent(parent) { - ASSERT(_store2 != nullptr); - _store2->AddRef(); - _store2->Register(&_store2Sink); - } - ~Store() override - { - _store2->Unregister(&_store2Sink); - _store2->Release(); } + ~Store() override = default; public: - // IStore methods - uint32_t Register(Exchange::IStore::INotification* notification) override { Core::SafeSyncType lock(_clientLock); @@ -188,95 +137,201 @@ namespace Plugin { } uint32_t SetValue(const string& ns, const string& key, const string& value) override { - return _store2->SetValue(Exchange::IStore2::ScopeType::DEVICE, ns, key, value, 0); + if (_parent._deviceStore2 != nullptr) { + return _parent._deviceStore2->SetValue(Exchange::IStore2::ScopeType::DEVICE, ns, key, value, 0); + } + return Core::ERROR_NOT_SUPPORTED; } uint32_t GetValue(const string& ns, const string& key, string& value) override { - uint32_t ttl; - return _store2->GetValue(Exchange::IStore2::ScopeType::DEVICE, ns, key, value, ttl); + if (_parent._deviceStore2 != nullptr) { + uint32_t ttl; + return _parent._deviceStore2->GetValue(Exchange::IStore2::ScopeType::DEVICE, ns, key, value, ttl); + } + return Core::ERROR_NOT_SUPPORTED; } uint32_t DeleteKey(const string& ns, const string& key) override { - return _store2->DeleteKey(Exchange::IStore2::ScopeType::DEVICE, ns, key); + if (_parent._deviceStore2 != nullptr) { + return _parent._deviceStore2->DeleteKey(Exchange::IStore2::ScopeType::DEVICE, ns, key); + } + return Core::ERROR_NOT_SUPPORTED; } uint32_t DeleteNamespace(const string& ns) override { - return _store2->DeleteNamespace(Exchange::IStore2::ScopeType::DEVICE, ns); + if (_parent._deviceStore2 != nullptr) { + return _parent._deviceStore2->DeleteNamespace(Exchange::IStore2::ScopeType::DEVICE, ns); + } + return Core::ERROR_NOT_SUPPORTED; + } + void ValueChanged(const Exchange::IStore2::ScopeType scope, const string& ns, const string& key, const string& value) override + { + ASSERT(scope == Exchange::IStore2::ScopeType::DEVICE); + + Core::SafeSyncType lock(_clientLock); + + std::list::iterator + index(_clients.begin()); + + while (index != _clients.end()) { + (*index)->ValueChanged(ns, key, value); + index++; + } } BEGIN_INTERFACE_MAP(Store) INTERFACE_ENTRY(Exchange::IStore) + INTERFACE_ENTRY(Exchange::IStore2::INotification) END_INTERFACE_MAP private: - Exchange::IStore2* _store2; + PersistentStore& _parent; std::list _clients; Core::CriticalSection _clientLock; - Core::Sink _store2Sink; }; - class Store2 : public Exchange::IStore2 { + class Store2 : public Exchange::IStore2, + public Exchange::IStoreCache, + public Exchange::IStoreInspector, + public Exchange::IStoreLimit { private: Store2(const Store2&) = delete; Store2& operator=(const Store2&) = delete; public: - typedef std::map ScopeMapType; + Store2(PersistentStore& parent) + : _parent(parent) + { + } + ~Store2() override = default; - Store2(const ScopeMapType& map) - : _scopeMap(map) + public: + uint32_t Register(INotification* notification) override { - for (auto const& x : _scopeMap) { - x.second->AddRef(); + if (_parent._deviceStore2 != nullptr) { + _parent._deviceStore2->Register(notification); + } + if (_parent._accountStore2 != nullptr) { + _parent._accountStore2->Register(notification); } + return Core::ERROR_NONE; } - ~Store2() override + uint32_t Unregister(INotification* notification) override { - for (auto const& x : _scopeMap) { - x.second->Release(); + if (_parent._deviceStore2 != nullptr) { + _parent._deviceStore2->Unregister(notification); + } + if (_parent._accountStore2 != nullptr) { + _parent._accountStore2->Unregister(notification); } + return Core::ERROR_NONE; } - - public: - // IStore2 methods - - uint32_t Register(Exchange::IStore2::INotification* notification) override + uint32_t SetValue(const IStore2::ScopeType scope, const string& ns, const string& key, const string& value, const uint32_t ttl) override { - for (auto const& x : _scopeMap) { - x.second->Register(notification); + if (scope == IStore2::ScopeType::ACCOUNT) { + if (_parent._accountStore2 != nullptr) { + return _parent._accountStore2->SetValue(scope, ns, key, value, ttl); + } + } else if (_parent._deviceStore2 != nullptr) { + return _parent._deviceStore2->SetValue(scope, ns, key, value, ttl); } - return Core::ERROR_NONE; + return Core::ERROR_NOT_SUPPORTED; } - uint32_t Unregister(Exchange::IStore2::INotification* notification) override + uint32_t GetValue(const IStore2::ScopeType scope, const string& ns, const string& key, string& value, uint32_t& ttl) override { - for (auto const& x : _scopeMap) { - x.second->Unregister(notification); + if (scope == IStore2::ScopeType::ACCOUNT) { + if (_parent._accountStore2 != nullptr) { + return _parent._accountStore2->GetValue(scope, ns, key, value, ttl); + } + } else if (_parent._deviceStore2 != nullptr) { + return _parent._deviceStore2->GetValue(scope, ns, key, value, ttl); } - return Core::ERROR_NONE; + return Core::ERROR_NOT_SUPPORTED; } - uint32_t SetValue(const ScopeType scope, const string& ns, const string& key, const string& value, const uint32_t ttl) override + uint32_t DeleteKey(const IStore2::ScopeType scope, const string& ns, const string& key) override { - return _scopeMap.at(scope)->SetValue(scope, ns, key, value, ttl); + if (scope == IStore2::ScopeType::ACCOUNT) { + if (_parent._accountStore2 != nullptr) { + return _parent._accountStore2->DeleteKey(scope, ns, key); + } + } else if (_parent._deviceStore2 != nullptr) { + return _parent._deviceStore2->DeleteKey(scope, ns, key); + } + return Core::ERROR_NOT_SUPPORTED; } - uint32_t GetValue(const ScopeType scope, const string& ns, const string& key, string& value, uint32_t& ttl) override + uint32_t DeleteNamespace(const IStore2::ScopeType scope, const string& ns) override { - return _scopeMap.at(scope)->GetValue(scope, ns, key, value, ttl); + if (scope == IStore2::ScopeType::ACCOUNT) { + if (_parent._accountStore2 != nullptr) { + return _parent._accountStore2->DeleteNamespace(scope, ns); + } + } else if (_parent._deviceStore2 != nullptr) { + return _parent._deviceStore2->DeleteNamespace(scope, ns); + } + return Core::ERROR_NOT_SUPPORTED; } - uint32_t DeleteKey(const ScopeType scope, const string& ns, const string& key) override + uint32_t FlushCache() override { - return _scopeMap.at(scope)->DeleteKey(scope, ns, key); + if (_parent._deviceStoreCache != nullptr) { + return _parent._deviceStoreCache->FlushCache(); + } + return Core::ERROR_NOT_SUPPORTED; } - uint32_t DeleteNamespace(const ScopeType scope, const string& ns) override + uint32_t GetKeys(const IStoreInspector::ScopeType scope, const string& ns, RPC::IStringIterator*& keys) override { - return _scopeMap.at(scope)->DeleteNamespace(scope, ns); + if (scope == IStoreInspector::ScopeType::DEVICE) { + if (_parent._deviceStoreInspector != nullptr) { + return _parent._deviceStoreInspector->GetKeys(scope, ns, keys); + } + } + return Core::ERROR_NOT_SUPPORTED; + } + uint32_t GetNamespaces(const IStoreInspector::ScopeType scope, RPC::IStringIterator*& namespaces) override + { + if (scope == IStoreInspector::ScopeType::DEVICE) { + if (_parent._deviceStoreInspector != nullptr) { + return _parent._deviceStoreInspector->GetNamespaces(scope, namespaces); + } + } + return Core::ERROR_NOT_SUPPORTED; + } + uint32_t GetStorageSizes(const IStoreInspector::ScopeType scope, INamespaceSizeIterator*& storageList) override + { + if (scope == IStoreInspector::ScopeType::DEVICE) { + if (_parent._deviceStoreInspector != nullptr) { + return _parent._deviceStoreInspector->GetStorageSizes(scope, storageList); + } + } + return Core::ERROR_NOT_SUPPORTED; + } + uint32_t SetNamespaceStorageLimit(const IStoreLimit::ScopeType scope, const string& ns, const uint32_t size) override + { + if (scope == IStoreLimit::ScopeType::DEVICE) { + if (_parent._deviceStoreLimit != nullptr) { + return _parent._deviceStoreLimit->SetNamespaceStorageLimit(scope, ns, size); + } + } + return Core::ERROR_NOT_SUPPORTED; + } + uint32_t GetNamespaceStorageLimit(const IStoreLimit::ScopeType scope, const string& ns, uint32_t& size) override + { + if (scope == IStoreLimit::ScopeType::DEVICE) { + if (_parent._deviceStoreLimit != nullptr) { + return _parent._deviceStoreLimit->GetNamespaceStorageLimit(scope, ns, size); + } + } + return Core::ERROR_NOT_SUPPORTED; } BEGIN_INTERFACE_MAP(Store2) - INTERFACE_ENTRY(Exchange::IStore2) + INTERFACE_ENTRY(IStore2) + INTERFACE_ENTRY(IStoreCache) + INTERFACE_ENTRY(IStoreInspector) + INTERFACE_ENTRY(IStoreLimit) END_INTERFACE_MAP private: - ScopeMapType _scopeMap; + PersistentStore& _parent; }; private: @@ -286,41 +341,47 @@ namespace Plugin { public: PersistentStore() : PluginHost::JSONRPC() - , _store(nullptr) - , _store2(nullptr) - , _storeCache(nullptr) - , _storeInspector(nullptr) - , _storeLimit(nullptr) - , _store2Sink(this) + , _deviceStore2(nullptr) + , _deviceStoreCache(nullptr) + , _deviceStoreInspector(nullptr) + , _deviceStoreLimit(nullptr) + , _accountStore2(nullptr) + , _store(Core::Service::Create(*this)) + , _store2(Core::Service::Create(*this)) + , _store2Sink(*this) { RegisterAll(); } ~PersistentStore() override { UnregisterAll(); + + if (_store != nullptr) { + _store->Release(); + _store = nullptr; + } + if (_store2 != nullptr) { + _store2->Release(); + _store2 = nullptr; + } } - // Build QueryInterface implementation, specifying all possible interfaces to be returned. BEGIN_INTERFACE_MAP(PersistentStore) INTERFACE_ENTRY(PluginHost::IPlugin) INTERFACE_ENTRY(PluginHost::IDispatcher) INTERFACE_AGGREGATE(Exchange::IStore, _store) INTERFACE_AGGREGATE(Exchange::IStore2, _store2) - INTERFACE_AGGREGATE(Exchange::IStoreCache, _storeCache) - INTERFACE_AGGREGATE(Exchange::IStoreInspector, _storeInspector) - INTERFACE_AGGREGATE(Exchange::IStoreLimit, _storeLimit) + INTERFACE_AGGREGATE(Exchange::IStoreCache, _store2) + INTERFACE_AGGREGATE(Exchange::IStoreInspector, _store2) + INTERFACE_AGGREGATE(Exchange::IStoreLimit, _store2) END_INTERFACE_MAP public: - // IPlugin methods - // ------------------------------------------------------------------------------------------------------- const string Initialize(PluginHost::IShell* service) override; void Deinitialize(PluginHost::IShell* service) override; string Information() const override; private: - // JSON RPC - void RegisterAll(); void UnregisterAll(); @@ -343,11 +404,13 @@ namespace Plugin { private: Config _config; - Exchange::IStore* _store; // Deprecated - Exchange::IStore2* _store2; - Exchange::IStoreCache* _storeCache; - Exchange::IStoreInspector* _storeInspector; - Exchange::IStoreLimit* _storeLimit; + Exchange::IStore2* _deviceStore2; + Exchange::IStoreCache* _deviceStoreCache; + Exchange::IStoreInspector* _deviceStoreInspector; + Exchange::IStoreLimit* _deviceStoreLimit; + Exchange::IStore2* _accountStore2; + Store* _store; // Deprecated + Store2* _store2; Core::Sink _store2Sink; }; diff --git a/PersistentStore/PersistentStoreJsonRpc.cpp b/PersistentStore/PersistentStoreJsonRpc.cpp index faa89dd147..f8c4c6a700 100644 --- a/PersistentStore/PersistentStoreJsonRpc.cpp +++ b/PersistentStore/PersistentStoreJsonRpc.cpp @@ -118,8 +118,8 @@ namespace Plugin { uint32_t PersistentStore::endpoint_getKeys(const DeleteNamespaceParamsInfo& params, GetKeysResultData& response) { RPC::IStringIterator* it; - auto result = _storeInspector->GetKeys( - Exchange::IStore2::ScopeType(params.Scope.Value()), + auto result = _store2->GetKeys( + Exchange::IStoreInspector::ScopeType(params.Scope.Value()), params.Namespace.Value(), it); if (result == Core::ERROR_NONE) { @@ -137,8 +137,8 @@ namespace Plugin { uint32_t PersistentStore::endpoint_getNamespaces(const GetNamespacesParamsInfo& params, GetNamespacesResultData& response) { RPC::IStringIterator* it; - auto result = _storeInspector->GetNamespaces( - Exchange::IStore2::ScopeType(params.Scope.Value()), + auto result = _store2->GetNamespaces( + Exchange::IStoreInspector::ScopeType(params.Scope.Value()), it); if (result == Core::ERROR_NONE) { string element; @@ -156,8 +156,8 @@ namespace Plugin { uint32_t PersistentStore::endpoint_getStorageSize(const GetNamespacesParamsInfo& params, JsonObject& response) { Exchange::IStoreInspector::INamespaceSizeIterator* it; - auto result = _storeInspector->GetStorageSizes( - Exchange::IStore2::ScopeType(params.Scope.Value()), + auto result = _store2->GetStorageSizes( + Exchange::IStoreInspector::ScopeType(params.Scope.Value()), it); if (result == Core::ERROR_NONE) { JsonObject jsonObject; @@ -176,8 +176,8 @@ namespace Plugin { uint32_t PersistentStore::endpoint_getStorageSizes(const GetNamespacesParamsInfo& params, GetStorageSizesResultData& response) { Exchange::IStoreInspector::INamespaceSizeIterator* it; - auto result = _storeInspector->GetStorageSizes( - Exchange::IStore2::ScopeType(params.Scope.Value()), + auto result = _store2->GetStorageSizes( + Exchange::IStoreInspector::ScopeType(params.Scope.Value()), it); if (result == Core::ERROR_NONE) { Exchange::IStoreInspector::NamespaceSize element; @@ -194,7 +194,7 @@ namespace Plugin { uint32_t PersistentStore::endpoint_flushCache(DeleteKeyResultInfo& response) { - auto result = _storeCache->FlushCache(); + auto result = _store2->FlushCache(); if (result == Core::ERROR_NONE) { response.Success = true; } @@ -205,8 +205,8 @@ namespace Plugin { uint32_t PersistentStore::endpoint_getNamespaceStorageLimit(const DeleteNamespaceParamsInfo& params, GetNamespaceStorageLimitResultData& response) { uint32_t size; - auto result = _storeLimit->GetNamespaceStorageLimit( - Exchange::IStore2::ScopeType(params.Scope.Value()), + auto result = _store2->GetNamespaceStorageLimit( + Exchange::IStoreLimit::ScopeType(params.Scope.Value()), params.Namespace.Value(), size); if (result == Core::ERROR_NONE) { @@ -218,8 +218,8 @@ namespace Plugin { uint32_t PersistentStore::endpoint_setNamespaceStorageLimit(const SetNamespaceStorageLimitParamsData& params) { - return _storeLimit->SetNamespaceStorageLimit( - Exchange::IStore2::ScopeType(params.Scope.Value()), + return _store2->SetNamespaceStorageLimit( + Exchange::IStoreLimit::ScopeType(params.Scope.Value()), params.Namespace.Value(), params.StorageLimit.Value()); } diff --git a/PersistentStore/grpc/Store2.h b/PersistentStore/grpc/Store2.h index 9caf1684e6..67de1e4889 100644 --- a/PersistentStore/grpc/Store2.h +++ b/PersistentStore/grpc/Store2.h @@ -39,15 +39,12 @@ namespace Plugin { public: Store2() - : Store2( - getenv(URI_ENV), - getenv(TOKEN_COMMAND_ENV)) + : Store2(getenv(URI_ENV)) { } - Store2(const string& uri, const string& tokenCommand) + Store2(const string& uri) : IStore2() , _uri(uri) - , _tokenCommand(tokenCommand) { Open(); } @@ -93,24 +90,34 @@ namespace Plugin { } string GetToken() const { - class Authorization : public Core::JSON::Container { - public: - Authorization() - : Core::JSON::Container() - , Expires(0) - , Received(0) - { - Add(_T("token"), &Token); - Add(_T("expires"), &Expires); - Add(_T("received"), &Received); - } - Core::JSON::String Token; - Core::JSON::DecUInt64 Expires; - Core::JSON::DecUInt64 Received; - }; - Authorization auth; - auth.FromString(ExecuteCmd(_tokenCommand.c_str())); - return auth.Token.Value(); + // TODO remove this + JsonObject jsonObject; + jsonObject.FromString(ExecuteCmd("curl -d '{\"jsonrpc\":\"2.0\",\"id\":0,\"method\":\"org.rdk.AuthService.getServiceAccessToken\"}' http://127.0.0.1:9998/jsonrpc")); + return jsonObject["result"].Object()["token"].String(); + } + static string ReadFromFile(const char* filename) + { + string result; + Core::File file(filename); + if (file.Open(true)) { + uint8_t buffer[1024]; + auto size = file.Read(buffer, 1024); + result.assign(reinterpret_cast(buffer), size); + result.erase(result.find_last_not_of(" \n\r\t") + 1); + } + return result; + } + string GetPartnerId() const + { + return ReadFromFile("/opt/www/authService/partnerId3.dat"); + } + string GetAccountId() const + { + return ReadFromFile("/opt/www/authService/said.dat"); + } + string GetDeviceId() const + { + return ReadFromFile("/opt/www/authService/xdeviceid.dat"); } public: @@ -153,6 +160,9 @@ namespace Plugin { context.AddMetadata("authorization", "Bearer " + GetToken()); } ::distp::gateway::secure_storage::v1::UpdateValueRequest request; + request.set_partner_id(GetPartnerId()); + request.set_account_id(GetAccountId()); + request.set_device_id(GetDeviceId()); auto v = new ::distp::gateway::secure_storage::v1::Value(); v->set_value(value); if (ttl != 0) { @@ -194,6 +204,9 @@ namespace Plugin { context.AddMetadata("authorization", "Bearer " + GetToken()); } ::distp::gateway::secure_storage::v1::GetValueRequest request; + request.set_partner_id(GetPartnerId()); + request.set_account_id(GetAccountId()); + request.set_device_id(GetDeviceId()); auto k = new ::distp::gateway::secure_storage::v1::Key(); k->set_app_id(ns); k->set_key(key); @@ -247,6 +260,9 @@ namespace Plugin { context.AddMetadata("authorization", "Bearer " + GetToken()); } ::distp::gateway::secure_storage::v1::DeleteValueRequest request; + request.set_partner_id(GetPartnerId()); + request.set_account_id(GetAccountId()); + request.set_device_id(GetDeviceId()); auto k = new ::distp::gateway::secure_storage::v1::Key(); k->set_app_id(ns); k->set_key(key); @@ -279,6 +295,9 @@ namespace Plugin { context.AddMetadata("authorization", "Bearer " + GetToken()); } ::distp::gateway::secure_storage::v1::DeleteAllValuesRequest request; + request.set_partner_id(GetPartnerId()); + request.set_account_id(GetAccountId()); + request.set_device_id(GetDeviceId()); request.set_app_id(ns); request.set_scope(::distp::gateway::secure_storage::v1::Scope::SCOPE_ACCOUNT); ::distp::gateway::secure_storage::v1::DeleteAllValuesResponse response; @@ -307,7 +326,7 @@ namespace Plugin { index(_clients.begin()); while (index != _clients.end()) { - (*index)->ValueChanged(ScopeType::DEVICE, ns, key, value); + (*index)->ValueChanged(ScopeType::ACCOUNT, ns, key, value); index++; } } @@ -318,7 +337,6 @@ namespace Plugin { private: const string _uri; - const string _tokenCommand; std::unique_ptr<::distp::gateway::secure_storage::v1::SecureStorageService::Stub> _stub; std::list _clients; Core::CriticalSection _clientLock; diff --git a/PersistentStore/grpc/l0test/Store2Test.cpp b/PersistentStore/grpc/l0test/Store2Test.cpp index a354e79691..d915570af3 100644 --- a/PersistentStore/grpc/l0test/Store2Test.cpp +++ b/PersistentStore/grpc/l0test/Store2Test.cpp @@ -30,7 +30,6 @@ using ::WPEFramework::Exchange::IStore2; using ::WPEFramework::Plugin::Grpc::Store2; const auto kUri = "0.0.0.0:50051"; -const auto kTokenCommand = ""; const auto kValue = "value_1"; const auto kKey = "key_1"; const auto kAppId = "app_id_1"; @@ -44,7 +43,7 @@ class AStore2 : public Test { WPEFramework::Core::ProxyType store2; AStore2() : server(kUri, &service) - , store2(WPEFramework::Core::ProxyType::Create(kUri, kTokenCommand)) + , store2(WPEFramework::Core::ProxyType::Create(kUri)) { } }; diff --git a/PersistentStore/grpc/secure_storage/secure_storage.proto b/PersistentStore/grpc/secure_storage/secure_storage.proto index 526eefb8eb..dc66cad38d 100644 --- a/PersistentStore/grpc/secure_storage/secure_storage.proto +++ b/PersistentStore/grpc/secure_storage/secure_storage.proto @@ -5,44 +5,65 @@ package distp.gateway.secure_storage.v1; import "google/protobuf/duration.proto"; import "google/protobuf/timestamp.proto"; -// SecureStorageService handles the storage and deletion of data (represented as string values) from applications given a particular key and scope. +// SecureStorageService handles the storage and deletion of data (represented +// as string values) from applications given a particular key and scope. service SecureStorageService { - // GetValue retrieves the value string stored in SecureStorage based on the scope and key provided for the current application. + // GetValue retrieves the value string stored in SecureStorage based on the + // scope and key provided for the current application. rpc GetValue(GetValueRequest) returns (GetValueResponse); - // UpdateValue stores the string value provided in SecureStorage against the scope and key provided for the current application. + + // UpdateValue stores the string value provided in SecureStorage against the + // scope and key provided for the current application. rpc UpdateValue(UpdateValueRequest) returns (UpdateValueResponse); - // DeleteValue removes the string value stored in SecureStorage, if present, defined by the scope and key provided for the current application/device. + + // DeleteValue removes the string value stored in SecureStorage, if present, + // defined by the scope and key provided for the current application/device. rpc DeleteValue(DeleteValueRequest) returns (DeleteValueResponse); - // DeleteAllValues removes all values stored against the provided application for the given account. This includes all key/value pairs - // stored against the device scope for other devices within the account. Please note that this method does not take a key as input. - // Also, DeleteAllValues is a separate method given that access to delete all values may be controlled by explicit capabilities. + + // DeleteAllValues removes all values stored against the provided application + // for the given account. This includes all key/value pairs stored against + // the device scope for other devices within the account. Please note that + // this method does not take a key as input. Also, DeleteAllValues is a + // separate method given that access to delete all values may be controlled + // by explicit capabilities. rpc DeleteAllValues(DeleteAllValuesRequest) returns (DeleteAllValuesResponse); - // SeedValue stores the string value provided in SecureStorage against the scope and key provided for the current application. - // This is a management API so the stored value will not cause the distributor's storage limits to be exceeded. + + // SeedValue stores the string value provided in SecureStorage against the + // scope and key provided for the current application. This is a management + // API so the stored value will not cause the distributor's storage limits to + // be exceeded. rpc SeedValue(SeedValueRequest) returns (SeedValueResponse); } -// Key is a group of fields that contribute to building the composite key that will be used to store the data in SecureStorage. +// Key is a group of fields that contribute to building the composite key that +// will be used to store the data in SecureStorage. message Key { // key of the key,value pair to be retrieved from SecureStorage. string key = 1; - // Scope describes the extent of the key,value pair. Scope is determined by the distributor. + + // Scope describes the extent of the key,value pair. Scope is determined by + // the distributor. Scope scope = 2; // app_id is the unique identifier of an app or family of apps. string app_id = 3; } -// Value contains the value of the requested data as well as some other relevant fields like scope and expiry useful for the client. +// Value contains the value of the requested data as well as some other +// relevant fields like scope and expiry useful for the client. message Value { // key of the key,value pair that was retrieved from SecureStorage. Key key = 1; - // value is the value associated with the key,value pair retrieved from SecureStorage. + + // value is the value associated with the key,value pair retrieved from + // SecureStorage. string value = 2; - // expiration returns the expire time of the retrieved value. Conforms to AIP-214. + + // expiration returns the expire time of the retrieved value. Conforms to + // AIP-214. oneof expiration { - // Timestamp in UTC of when this resource is considered expired. - // This is *always* provided on output, regardless of what was sent on input. + // Timestamp in UTC of when this resource is considered expired. This is + // *always* provided on output, regardless of what was sent on input. google.protobuf.Timestamp expire_time = 3; // Input only. The TTL for this resource. @@ -52,48 +73,104 @@ message Value { // GetValueRequest is the request to retrieve the SecureStorage data. message GetValueRequest { - // key is the group of fields that contribute to building the composite key that will be used to store the data in SecureStorage. + // XBO ID for the partner making the request + string partner_id = 3; + + // XBO ID for the account making the request + string account_id = 4; + + // XBO ID for the device making the request + string device_id = 2; + + // key is the group of fields that contribute to building the composite key + // that will be used to store the data in SecureStorage. Key key = 1; } -// GetValueResponse is the response containing the value of the requested key within the specified scope. +// GetValueResponse is the response containing the value of the requested key +// within the specified scope. message GetValueResponse { - // value contains the data associated with the key,value pair that was stored in SecureStorage. + // value contains the data associated with the key,value pair that was stored + // in SecureStorage. Value value = 1; } // UpdateValueRequest is the request to store data in SecureStorage. message UpdateValueRequest { - // key is the group of fields that contribute to building the composite key that will be used to store the data in SecureStorage. + // XBO ID for the partner making the request + string partner_id = 3; + + // XBO ID for the account making the request + string account_id = 4; + + // XBO ID for the device making the request + string device_id = 2; + + // The key-value pair that will be upserted into the secure storage database. Value value = 1; } // UpdateValueResponse is the response from the GetValue method. message UpdateValueResponse {} -// DeleteValueRequest is the request to remove a stored value given the key and scope. +// DeleteValueRequest is the request to remove a stored value given the key and +// scope. message DeleteValueRequest { - // key is the group of fields that contribute to building the composite key that will be used to store the data in SecureStorage. + // XBO ID for the partner making the request + string partner_id = 3; + + // XBO ID for the account making the request + string account_id = 4; + + // XBO ID for the device making the request + string device_id = 2; + + // Key is the group of fields that contribute to building the composite key + // that will be used to store the data in SecureStorage. Key key = 1; } // DeleteValueResponse is the response from the DeleteValue method. message DeleteValueResponse {} -// DeleteAllValuesRequest is the request to delete all of the keys associated with an app under the given account. +// DeleteAllValuesRequest is the request to delete all of the keys associated +// with an app under the given account. message DeleteAllValuesRequest { + // XBO ID for the partner making the request + string partner_id = 3; + + // XBO ID for the account making the request + string account_id = 4; + + // XBO ID for the device making the request + string device_id = 5; + // app_id is the unique identifier of an app or family of apps. string app_id = 1; - // Scope describes the extent of the key,value pair. Scope is determined by the distributor. + + // Scope describes the extent of the key,value pair. Scope is determined by + // the distributor. Scope scope = 2; } // DeleteAllValuesResponse is the response from the DeleteAllValues method. message DeleteAllValuesResponse {} -// SeedValueRequest is the request to store data in SecureStorage. Stored data will not cause the distributor's storage limits to be exceeded. +// SeedValueRequest is the request to store data in SecureStorage. Stored data +// will not cause the distributor's storage limits to be exceeded. message SeedValueRequest { - // value contains the data associated with the key,value pair that will be stored in SecureStorage. + // ID of the partner this change applies to. This field is optional IFF + // exactly one partner is provided in the request SAT. + string partner_id = 4; + + // XBO ID for the account making the request + string account_id = 2; + + // XBO ID for the device making the request + string device_id = 3; + + // value contains the data associated with the key,value pair that will be + // stored in SecureStorage. Value value = 1; } @@ -104,8 +181,10 @@ message SeedValueResponse {} enum Scope { // Represents an unset or invalid scope. SCOPE_UNSPECIFIED = 0; + // Account scope. SCOPE_ACCOUNT = 1; + // Device scope. SCOPE_DEVICE = 2; } diff --git a/PersistentStore/l0test/PersistentStoreTest.cpp b/PersistentStore/l0test/PersistentStoreTest.cpp index dfd7d8c980..6d65f5ffe3 100644 --- a/PersistentStore/l0test/PersistentStoreTest.cpp +++ b/PersistentStore/l0test/PersistentStoreTest.cpp @@ -4,9 +4,6 @@ #include "../PersistentStore.h" #include "ServiceMock.h" #include "Store2Mock.h" -#include "StoreCacheMock.h" -#include "StoreInspectorMock.h" -#include "StoreLimitMock.h" using ::testing::_; using ::testing::Eq; @@ -23,6 +20,7 @@ using ::WPEFramework::Exchange::IStoreInspector; using ::WPEFramework::JsonData::PersistentStore::DeleteKeyParamsInfo; using ::WPEFramework::JsonData::PersistentStore::DeleteNamespaceParamsInfo; using ::WPEFramework::JsonData::PersistentStore::GetKeysResultData; +using ::WPEFramework::JsonData::PersistentStore::GetNamespacesParamsInfo; using ::WPEFramework::JsonData::PersistentStore::GetNamespacesResultData; using ::WPEFramework::JsonData::PersistentStore::GetNamespaceStorageLimitResultData; using ::WPEFramework::JsonData::PersistentStore::GetStorageSizesResultData; @@ -69,8 +67,8 @@ TEST_F(APersistentStore, GetsValueInDeviceScopeViaJsonRpc) { EXPECT_CALL(*this, GetValue(_, _, _, _, _)) .WillRepeatedly(Invoke( - [](const ScopeType scope, const string& ns, const string& key, string& value, uint32_t& ttl) { - EXPECT_THAT(scope, Eq(ScopeType::DEVICE)); + [](const IStore2::ScopeType scope, const string& ns, const string& key, string& value, uint32_t& ttl) { + EXPECT_THAT(scope, Eq(IStore2::ScopeType::DEVICE)); EXPECT_THAT(ns, Eq(kAppId)); EXPECT_THAT(key, Eq(kKey)); value = kValue; @@ -106,8 +104,8 @@ TEST_F(APersistentStore, GetsValueInAccountScopeViaJsonRpc) { EXPECT_CALL(*this, GetValue(_, _, _, _, _)) .WillRepeatedly(Invoke( - [](const ScopeType scope, const string& ns, const string& key, string& value, uint32_t& ttl) { - EXPECT_THAT(scope, Eq(ScopeType::ACCOUNT)); + [](const IStore2::ScopeType scope, const string& ns, const string& key, string& value, uint32_t& ttl) { + EXPECT_THAT(scope, Eq(IStore2::ScopeType::ACCOUNT)); EXPECT_THAT(ns, Eq(kAppId)); EXPECT_THAT(key, Eq(kKey)); value = kValue; @@ -144,8 +142,8 @@ TEST_F(APersistentStore, SetsValueInDeviceScopeViaJsonRpc) { EXPECT_CALL(*this, SetValue(_, _, _, _, _)) .WillRepeatedly(Invoke( - [](const ScopeType scope, const string& ns, const string& key, const string& value, const uint32_t ttl) { - EXPECT_THAT(scope, Eq(ScopeType::DEVICE)); + [](const IStore2::ScopeType scope, const string& ns, const string& key, const string& value, const uint32_t ttl) { + EXPECT_THAT(scope, Eq(IStore2::ScopeType::DEVICE)); EXPECT_THAT(ns, Eq(kAppId)); EXPECT_THAT(key, Eq(kKey)); EXPECT_THAT(value, Eq(kValue)); @@ -179,8 +177,8 @@ TEST_F(APersistentStore, SetsValueInAccountScopeViaJsonRpc) { EXPECT_CALL(*this, SetValue(_, _, _, _, _)) .WillRepeatedly(Invoke( - [](const ScopeType scope, const string& ns, const string& key, const string& value, const uint32_t ttl) { - EXPECT_THAT(scope, Eq(ScopeType::ACCOUNT)); + [](const IStore2::ScopeType scope, const string& ns, const string& key, const string& value, const uint32_t ttl) { + EXPECT_THAT(scope, Eq(IStore2::ScopeType::ACCOUNT)); EXPECT_THAT(ns, Eq(kAppId)); EXPECT_THAT(key, Eq(kKey)); EXPECT_THAT(value, Eq(kValue)); @@ -215,8 +213,8 @@ TEST_F(APersistentStore, DeletesKeyInDeviceScopeViaJsonRpc) { EXPECT_CALL(*this, DeleteKey(_, _, _)) .WillRepeatedly(Invoke( - [](const ScopeType scope, const string& ns, const string& key) { - EXPECT_THAT(scope, Eq(ScopeType::DEVICE)); + [](const IStore2::ScopeType scope, const string& ns, const string& key) { + EXPECT_THAT(scope, Eq(IStore2::ScopeType::DEVICE)); EXPECT_THAT(ns, Eq(kAppId)); EXPECT_THAT(key, Eq(kKey)); return WPEFramework::Core::ERROR_NONE; @@ -246,8 +244,8 @@ TEST_F(APersistentStore, DeletesKeyInAccountScopeViaJsonRpc) { EXPECT_CALL(*this, DeleteKey(_, _, _)) .WillRepeatedly(Invoke( - [](const ScopeType scope, const string& ns, const string& key) { - EXPECT_THAT(scope, Eq(ScopeType::ACCOUNT)); + [](const IStore2::ScopeType scope, const string& ns, const string& key) { + EXPECT_THAT(scope, Eq(IStore2::ScopeType::ACCOUNT)); EXPECT_THAT(ns, Eq(kAppId)); EXPECT_THAT(key, Eq(kKey)); return WPEFramework::Core::ERROR_NONE; @@ -278,8 +276,8 @@ TEST_F(APersistentStore, DeletesNamespaceInDeviceScopeViaJsonRpc) { EXPECT_CALL(*this, DeleteNamespace(_, _)) .WillRepeatedly(Invoke( - [](const ScopeType scope, const string& ns) { - EXPECT_THAT(scope, Eq(ScopeType::DEVICE)); + [](const IStore2::ScopeType scope, const string& ns) { + EXPECT_THAT(scope, Eq(IStore2::ScopeType::DEVICE)); EXPECT_THAT(ns, Eq(kAppId)); return WPEFramework::Core::ERROR_NONE; })); @@ -307,8 +305,8 @@ TEST_F(APersistentStore, DeletesNamespaceInAccountScopeViaJsonRpc) { EXPECT_CALL(*this, DeleteNamespace(_, _)) .WillRepeatedly(Invoke( - [](const ScopeType scope, const string& ns) { - EXPECT_THAT(scope, Eq(ScopeType::ACCOUNT)); + [](const IStore2::ScopeType scope, const string& ns) { + EXPECT_THAT(scope, Eq(IStore2::ScopeType::ACCOUNT)); EXPECT_THAT(ns, Eq(kAppId)); return WPEFramework::Core::ERROR_NONE; })); @@ -331,15 +329,15 @@ TEST_F(APersistentStore, DeletesNamespaceInAccountScopeViaJsonRpc) TEST_F(APersistentStore, FlushesCacheViaJsonRpc) { - class SqliteStoreCache : public NiceMock { + class SqliteStore2 : public NiceMock { public: - SqliteStoreCache() + SqliteStore2() { EXPECT_CALL(*this, FlushCache()) .WillRepeatedly(Return(WPEFramework::Core::ERROR_NONE)); } }; - PublishedServiceType metadata(WPEFramework::Core::System::MODULE_NAME, 1, 0, 0); + PublishedServiceType metadata(WPEFramework::Core::System::MODULE_NAME, 1, 0, 0); ASSERT_THAT(plugin->Initialize(service), Eq("")); auto jsonRpc = plugin->QueryInterface(); ASSERT_THAT(jsonRpc, NotNull()); @@ -351,21 +349,21 @@ TEST_F(APersistentStore, FlushesCacheViaJsonRpc) TEST_F(APersistentStore, GetsKeysInDeviceScopeViaJsonRpc) { - class SqliteStoreInspector : public NiceMock { + class SqliteStore2 : public NiceMock { public: - SqliteStoreInspector() + SqliteStore2() { EXPECT_CALL(*this, GetKeys(_, _, _)) .WillRepeatedly(Invoke( - [](const ScopeType scope, const string& ns, IStringIterator*& keys) { - EXPECT_THAT(scope, Eq(ScopeType::DEVICE)); + [](const IStoreInspector::ScopeType scope, const string& ns, IStringIterator*& keys) { + EXPECT_THAT(scope, Eq(IStoreInspector::ScopeType::DEVICE)); EXPECT_THAT(ns, Eq(kAppId)); keys = (WPEFramework::Core::Service::Create(kKeys)); return WPEFramework::Core::ERROR_NONE; })); } }; - PublishedServiceType metadata(WPEFramework::Core::System::MODULE_NAME, 1, 0, 0); + PublishedServiceType metadata(WPEFramework::Core::System::MODULE_NAME, 1, 0, 0); ASSERT_THAT(plugin->Initialize(service), Eq("")); auto jsonRpc = plugin->QueryInterface(); ASSERT_THAT(jsonRpc, NotNull()); @@ -387,22 +385,38 @@ TEST_F(APersistentStore, GetsKeysInDeviceScopeViaJsonRpc) plugin->Deinitialize(service); } +TEST_F(APersistentStore, DoesNotGetKeysInAccountScopeViaJsonRpc) +{ + ASSERT_THAT(plugin->Initialize(service), Eq("")); + auto jsonRpc = plugin->QueryInterface(); + ASSERT_THAT(jsonRpc, NotNull()); + DeleteNamespaceParamsInfo params; + params.Scope = WPEFramework::JsonData::PersistentStore::ScopeType::ACCOUNT; + params.Namespace = kAppId; + string paramsJsonStr; + params.ToString(paramsJsonStr); + string resultJsonStr; + EXPECT_THAT(jsonRpc->Invoke(0, 0, "", "getKeys", paramsJsonStr, resultJsonStr), Eq(WPEFramework::Core::ERROR_NOT_SUPPORTED)); + jsonRpc->Release(); + plugin->Deinitialize(service); +} + TEST_F(APersistentStore, GetsNamespacesInDeviceScopeViaJsonRpc) { - class SqliteStoreInspector : public NiceMock { + class SqliteStore2 : public NiceMock { public: - SqliteStoreInspector() + SqliteStore2() { EXPECT_CALL(*this, GetNamespaces(_, _)) .WillRepeatedly(Invoke( - [](const ScopeType scope, IStringIterator*& namespaces) { - EXPECT_THAT(scope, Eq(ScopeType::DEVICE)); + [](const IStoreInspector::ScopeType scope, IStringIterator*& namespaces) { + EXPECT_THAT(scope, Eq(IStoreInspector::ScopeType::DEVICE)); namespaces = (WPEFramework::Core::Service::Create(kAppIds)); return WPEFramework::Core::ERROR_NONE; })); } }; - PublishedServiceType metadata(WPEFramework::Core::System::MODULE_NAME, 1, 0, 0); + PublishedServiceType metadata(WPEFramework::Core::System::MODULE_NAME, 1, 0, 0); ASSERT_THAT(plugin->Initialize(service), Eq("")); auto jsonRpc = plugin->QueryInterface(); ASSERT_THAT(jsonRpc, NotNull()); @@ -420,22 +434,37 @@ TEST_F(APersistentStore, GetsNamespacesInDeviceScopeViaJsonRpc) plugin->Deinitialize(service); } +TEST_F(APersistentStore, DoesNotGetNamespacesInAccountScopeViaJsonRpc) +{ + ASSERT_THAT(plugin->Initialize(service), Eq("")); + auto jsonRpc = plugin->QueryInterface(); + ASSERT_THAT(jsonRpc, NotNull()); + GetNamespacesParamsInfo params; + params.Scope = WPEFramework::JsonData::PersistentStore::ScopeType::ACCOUNT; + string paramsJsonStr; + params.ToString(paramsJsonStr); + string resultJsonStr; + EXPECT_THAT(jsonRpc->Invoke(0, 0, "", "getNamespaces", paramsJsonStr, resultJsonStr), Eq(WPEFramework::Core::ERROR_NOT_SUPPORTED)); + jsonRpc->Release(); + plugin->Deinitialize(service); +} + TEST_F(APersistentStore, GetsStorageSizesInDeviceScopeViaJsonRpc) { - class SqliteStoreInspector : public NiceMock { + class SqliteStore2 : public NiceMock { public: - SqliteStoreInspector() + SqliteStore2() { EXPECT_CALL(*this, GetStorageSizes(_, _)) .WillRepeatedly(Invoke( - [](const ScopeType scope, INamespaceSizeIterator*& storageList) { - EXPECT_THAT(scope, Eq(ScopeType::DEVICE)); + [](const IStoreInspector::ScopeType scope, INamespaceSizeIterator*& storageList) { + EXPECT_THAT(scope, Eq(IStoreInspector::ScopeType::DEVICE)); storageList = (WPEFramework::Core::Service>::Create(kSizes)); return WPEFramework::Core::ERROR_NONE; })); } }; - PublishedServiceType metadata(WPEFramework::Core::System::MODULE_NAME, 1, 0, 0); + PublishedServiceType metadata(WPEFramework::Core::System::MODULE_NAME, 1, 0, 0); ASSERT_THAT(plugin->Initialize(service), Eq("")); auto jsonRpc = plugin->QueryInterface(); ASSERT_THAT(jsonRpc, NotNull()); @@ -455,23 +484,38 @@ TEST_F(APersistentStore, GetsStorageSizesInDeviceScopeViaJsonRpc) plugin->Deinitialize(service); } +TEST_F(APersistentStore, DoesNotGetStorageSizesInAccountScopeViaJsonRpc) +{ + ASSERT_THAT(plugin->Initialize(service), Eq("")); + auto jsonRpc = plugin->QueryInterface(); + ASSERT_THAT(jsonRpc, NotNull()); + GetNamespacesParamsInfo params; + params.Scope = WPEFramework::JsonData::PersistentStore::ScopeType::ACCOUNT; + string paramsJsonStr; + params.ToString(paramsJsonStr); + string resultJsonStr; + EXPECT_THAT(jsonRpc->Invoke(0, 0, "", "getStorageSizes", paramsJsonStr, resultJsonStr), Eq(WPEFramework::Core::ERROR_NOT_SUPPORTED)); + jsonRpc->Release(); + plugin->Deinitialize(service); +} + TEST_F(APersistentStore, GetsNamespaceStorageLimitInDeviceScopeViaJsonRpc) { - class SqliteStoreLimit : public NiceMock { + class SqliteStore2 : public NiceMock { public: - SqliteStoreLimit() + SqliteStore2() { EXPECT_CALL(*this, GetNamespaceStorageLimit(_, _, _)) .WillRepeatedly(Invoke( - [](const ScopeType scope, const string& ns, uint32_t& size) { - EXPECT_THAT(scope, Eq(ScopeType::DEVICE)); + [](const IStoreLimit::ScopeType scope, const string& ns, uint32_t& size) { + EXPECT_THAT(scope, Eq(IStoreLimit::ScopeType::DEVICE)); EXPECT_THAT(ns, Eq(kAppId)); size = kSize; return WPEFramework::Core::ERROR_NONE; })); } }; - PublishedServiceType metadata(WPEFramework::Core::System::MODULE_NAME, 1, 0, 0); + PublishedServiceType metadata(WPEFramework::Core::System::MODULE_NAME, 1, 0, 0); ASSERT_THAT(plugin->Initialize(service), Eq("")); auto jsonRpc = plugin->QueryInterface(); ASSERT_THAT(jsonRpc, NotNull()); @@ -488,23 +532,39 @@ TEST_F(APersistentStore, GetsNamespaceStorageLimitInDeviceScopeViaJsonRpc) plugin->Deinitialize(service); } +TEST_F(APersistentStore, DoesNotGetNamespaceStorageLimitInAccountScopeViaJsonRpc) +{ + ASSERT_THAT(plugin->Initialize(service), Eq("")); + auto jsonRpc = plugin->QueryInterface(); + ASSERT_THAT(jsonRpc, NotNull()); + DeleteNamespaceParamsInfo params; + params.Scope = WPEFramework::JsonData::PersistentStore::ScopeType::ACCOUNT; + params.Namespace = kAppId; + string paramsJsonStr; + params.ToString(paramsJsonStr); + string resultJsonStr; + EXPECT_THAT(jsonRpc->Invoke(0, 0, "", "getNamespaceStorageLimit", paramsJsonStr, resultJsonStr), Eq(WPEFramework::Core::ERROR_NOT_SUPPORTED)); + jsonRpc->Release(); + plugin->Deinitialize(service); +} + TEST_F(APersistentStore, SetsNamespaceStorageLimitInDeviceScopeViaJsonRpc) { - class SqliteStoreLimit : public NiceMock { + class SqliteStore2 : public NiceMock { public: - SqliteStoreLimit() + SqliteStore2() { EXPECT_CALL(*this, SetNamespaceStorageLimit(_, _, _)) .WillRepeatedly(Invoke( - [](const ScopeType scope, const string& ns, const uint32_t size) { - EXPECT_THAT(scope, Eq(ScopeType::DEVICE)); + [](const IStoreLimit::ScopeType scope, const string& ns, const uint32_t size) { + EXPECT_THAT(scope, Eq(IStoreLimit::ScopeType::DEVICE)); EXPECT_THAT(ns, Eq(kAppId)); EXPECT_THAT(size, Eq(kSize)); return WPEFramework::Core::ERROR_NONE; })); } }; - PublishedServiceType metadata(WPEFramework::Core::System::MODULE_NAME, 1, 0, 0); + PublishedServiceType metadata(WPEFramework::Core::System::MODULE_NAME, 1, 0, 0); ASSERT_THAT(plugin->Initialize(service), Eq("")); auto jsonRpc = plugin->QueryInterface(); ASSERT_THAT(jsonRpc, NotNull()); @@ -519,6 +579,23 @@ TEST_F(APersistentStore, SetsNamespaceStorageLimitInDeviceScopeViaJsonRpc) plugin->Deinitialize(service); } +TEST_F(APersistentStore, DoesNotSetNamespaceStorageLimitInAccountScopeViaJsonRpc) +{ + ASSERT_THAT(plugin->Initialize(service), Eq("")); + auto jsonRpc = plugin->QueryInterface(); + ASSERT_THAT(jsonRpc, NotNull()); + SetNamespaceStorageLimitParamsData params; + params.Scope = WPEFramework::JsonData::PersistentStore::ScopeType::ACCOUNT; + params.Namespace = kAppId; + params.StorageLimit = kSize; + string paramsJsonStr; + params.ToString(paramsJsonStr); + string resultJsonStr; + EXPECT_THAT(jsonRpc->Invoke(0, 0, "", "setNamespaceStorageLimit", paramsJsonStr, resultJsonStr), Eq(WPEFramework::Core::ERROR_NOT_SUPPORTED)); + jsonRpc->Release(); + plugin->Deinitialize(service); +} + TEST_F(APersistentStore, GetsValueInDeviceScopeViaIStore) { class SqliteStore2 : public NiceMock { @@ -527,8 +604,8 @@ TEST_F(APersistentStore, GetsValueInDeviceScopeViaIStore) { EXPECT_CALL(*this, GetValue(_, _, _, _, _)) .WillRepeatedly(Invoke( - [](const ScopeType scope, const string& ns, const string& key, string& value, uint32_t& ttl) { - EXPECT_THAT(scope, Eq(ScopeType::DEVICE)); + [](const IStore2::ScopeType scope, const string& ns, const string& key, string& value, uint32_t& ttl) { + EXPECT_THAT(scope, Eq(IStore2::ScopeType::DEVICE)); EXPECT_THAT(ns, Eq(kAppId)); EXPECT_THAT(key, Eq(kKey)); value = kValue; @@ -555,8 +632,8 @@ TEST_F(APersistentStore, SetsValueInDeviceScopeViaIStore) { EXPECT_CALL(*this, SetValue(_, _, _, _, _)) .WillRepeatedly(Invoke( - [](const ScopeType scope, const string& ns, const string& key, const string& value, const uint32_t ttl) { - EXPECT_THAT(scope, Eq(ScopeType::DEVICE)); + [](const IStore2::ScopeType scope, const string& ns, const string& key, const string& value, const uint32_t ttl) { + EXPECT_THAT(scope, Eq(IStore2::ScopeType::DEVICE)); EXPECT_THAT(ns, Eq(kAppId)); EXPECT_THAT(key, Eq(kKey)); EXPECT_THAT(value, Eq(kValue)); @@ -582,8 +659,8 @@ TEST_F(APersistentStore, DeletesKeyInDeviceScopeViaIStore) { EXPECT_CALL(*this, DeleteKey(_, _, _)) .WillRepeatedly(Invoke( - [](const ScopeType scope, const string& ns, const string& key) { - EXPECT_THAT(scope, Eq(ScopeType::DEVICE)); + [](const IStore2::ScopeType scope, const string& ns, const string& key) { + EXPECT_THAT(scope, Eq(IStore2::ScopeType::DEVICE)); EXPECT_THAT(ns, Eq(kAppId)); EXPECT_THAT(key, Eq(kKey)); return WPEFramework::Core::ERROR_NONE; @@ -607,8 +684,8 @@ TEST_F(APersistentStore, DeletesNamespaceInDeviceScopeViaIStore) { EXPECT_CALL(*this, DeleteNamespace(_, _)) .WillRepeatedly(Invoke( - [](const ScopeType scope, const string& ns) { - EXPECT_THAT(scope, Eq(ScopeType::DEVICE)); + [](const IStore2::ScopeType scope, const string& ns) { + EXPECT_THAT(scope, Eq(IStore2::ScopeType::DEVICE)); EXPECT_THAT(ns, Eq(kAppId)); return WPEFramework::Core::ERROR_NONE; })); diff --git a/PersistentStore/l0test/Store2Mock.h b/PersistentStore/l0test/Store2Mock.h index 35ac62674f..a049bcbfc5 100644 --- a/PersistentStore/l0test/Store2Mock.h +++ b/PersistentStore/l0test/Store2Mock.h @@ -2,17 +2,30 @@ #include #include +#include -class Store2Mock : public WPEFramework::Exchange::IStore2 { +class Store2Mock : public WPEFramework::Exchange::IStore2, + public WPEFramework::Exchange::IStoreCache, + public WPEFramework::Exchange::IStoreInspector, + public WPEFramework::Exchange::IStoreLimit { public: ~Store2Mock() override = default; MOCK_METHOD(uint32_t, Register, (INotification*), (override)); MOCK_METHOD(uint32_t, Unregister, (INotification*), (override)); - MOCK_METHOD(uint32_t, SetValue, (const ScopeType scope, const string& ns, const string& key, const string& value, const uint32_t ttl), (override)); - MOCK_METHOD(uint32_t, GetValue, (const ScopeType scope, const string& ns, const string& key, string& value, uint32_t& ttl), (override)); - MOCK_METHOD(uint32_t, DeleteKey, (const ScopeType scope, const string& ns, const string& key), (override)); - MOCK_METHOD(uint32_t, DeleteNamespace, (const ScopeType scope, const string& ns), (override)); + MOCK_METHOD(uint32_t, SetValue, (const IStore2::ScopeType scope, const string& ns, const string& key, const string& value, const uint32_t ttl), (override)); + MOCK_METHOD(uint32_t, GetValue, (const IStore2::ScopeType scope, const string& ns, const string& key, string& value, uint32_t& ttl), (override)); + MOCK_METHOD(uint32_t, DeleteKey, (const IStore2::ScopeType scope, const string& ns, const string& key), (override)); + MOCK_METHOD(uint32_t, DeleteNamespace, (const IStore2::ScopeType scope, const string& ns), (override)); + MOCK_METHOD(uint32_t, FlushCache, (), (override)); + MOCK_METHOD(uint32_t, GetKeys, (const IStoreInspector::ScopeType scope, const string& ns, IStringIterator*& keys), (override)); + MOCK_METHOD(uint32_t, GetNamespaces, (const IStoreInspector::ScopeType scope, IStringIterator*& namespaces), (override)); + MOCK_METHOD(uint32_t, GetStorageSizes, (const IStoreInspector::ScopeType scope, INamespaceSizeIterator*& storageList), (override)); + MOCK_METHOD(uint32_t, GetNamespaceStorageLimit, (const IStoreLimit::ScopeType scope, const string& ns, uint32_t& size), (override)); + MOCK_METHOD(uint32_t, SetNamespaceStorageLimit, (const IStoreLimit::ScopeType scope, const string& ns, const uint32_t size), (override)); BEGIN_INTERFACE_MAP(Store2Mock) INTERFACE_ENTRY(IStore2) + INTERFACE_ENTRY(IStoreCache) + INTERFACE_ENTRY(IStoreInspector) + INTERFACE_ENTRY(IStoreLimit) END_INTERFACE_MAP }; diff --git a/PersistentStore/l0test/StoreCacheMock.h b/PersistentStore/l0test/StoreCacheMock.h deleted file mode 100644 index ed7715a013..0000000000 --- a/PersistentStore/l0test/StoreCacheMock.h +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once - -#include -#include - -class StoreCacheMock : public WPEFramework::Exchange::IStoreCache { -public: - ~StoreCacheMock() override = default; - MOCK_METHOD(uint32_t, FlushCache, (), (override)); - BEGIN_INTERFACE_MAP(StoreCacheMock) - INTERFACE_ENTRY(IStoreCache) - END_INTERFACE_MAP -}; diff --git a/PersistentStore/l0test/StoreInspectorMock.h b/PersistentStore/l0test/StoreInspectorMock.h deleted file mode 100644 index 7765f744a7..0000000000 --- a/PersistentStore/l0test/StoreInspectorMock.h +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once - -#include -#include - -class StoreInspectorMock : public WPEFramework::Exchange::IStoreInspector { -public: - ~StoreInspectorMock() override = default; - MOCK_METHOD(uint32_t, GetKeys, (const ScopeType scope, const string& ns, IStringIterator*& keys), (override)); - MOCK_METHOD(uint32_t, GetNamespaces, (const ScopeType scope, IStringIterator*& namespaces), (override)); - MOCK_METHOD(uint32_t, GetStorageSizes, (const ScopeType scope, INamespaceSizeIterator*& storageList), (override)); - BEGIN_INTERFACE_MAP(StoreInspectorMock) - INTERFACE_ENTRY(IStoreInspector) - END_INTERFACE_MAP -}; diff --git a/PersistentStore/l0test/StoreLimitMock.h b/PersistentStore/l0test/StoreLimitMock.h deleted file mode 100644 index 2b818984e9..0000000000 --- a/PersistentStore/l0test/StoreLimitMock.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include -#include - -class StoreLimitMock : public WPEFramework::Exchange::IStoreLimit { -public: - ~StoreLimitMock() override = default; - MOCK_METHOD(uint32_t, GetNamespaceStorageLimit, (const ScopeType scope, const string& ns, uint32_t& size), (override)); - MOCK_METHOD(uint32_t, SetNamespaceStorageLimit, (const ScopeType scope, const string& ns, const uint32_t size), (override)); - BEGIN_INTERFACE_MAP(StoreLimitMock) - INTERFACE_ENTRY(IStoreLimit) - END_INTERFACE_MAP -}; diff --git a/PersistentStore/sqlite/Store2.h b/PersistentStore/sqlite/Store2.h index c106b088b8..1b9b9bbb13 100644 --- a/PersistentStore/sqlite/Store2.h +++ b/PersistentStore/sqlite/Store2.h @@ -21,6 +21,7 @@ #include "../Module.h" #include +#include #include #ifdef WITH_SYSMGR #include @@ -31,7 +32,10 @@ namespace WPEFramework { namespace Plugin { namespace Sqlite { - class Store2 : public Exchange::IStore2 { + class Store2 : public Exchange::IStore2, + public Exchange::IStoreCache, + public Exchange::IStoreInspector, + public Exchange::IStoreLimit { private: Store2(const Store2&) = delete; Store2& operator=(const Store2&) = delete; @@ -47,6 +51,9 @@ namespace Plugin { } Store2(const string& path, const uint64_t maxSize, const uint64_t maxValue, const uint64_t limit) : IStore2() + , IStoreCache() + , IStoreInspector() + , IStoreLimit() , _path(path) , _maxSize(maxSize) , _maxValue(maxValue) @@ -141,10 +148,9 @@ namespace Plugin { return Core::ERROR_NONE; } - - uint32_t SetValue(const ScopeType scope, const string& ns, const string& key, const string& value, const uint32_t ttl) override + uint32_t SetValue(const IStore2::ScopeType scope, const string& ns, const string& key, const string& value, const uint32_t ttl) override { - ASSERT(scope == ScopeType::DEVICE); + ASSERT(scope == IStore2::ScopeType::DEVICE); uint32_t result; @@ -192,9 +198,9 @@ namespace Plugin { return result; } - uint32_t GetValue(const ScopeType scope, const string& ns, const string& key, string& value, uint32_t& ttl) override + uint32_t GetValue(const IStore2::ScopeType scope, const string& ns, const string& key, string& value, uint32_t& ttl) override { - ASSERT(scope == ScopeType::DEVICE); + ASSERT(scope == IStore2::ScopeType::DEVICE); uint32_t result; @@ -250,9 +256,9 @@ namespace Plugin { return result; } - uint32_t DeleteKey(const ScopeType scope, const string& ns, const string& key) override + uint32_t DeleteKey(const IStore2::ScopeType scope, const string& ns, const string& key) override { - ASSERT(scope == ScopeType::DEVICE); + ASSERT(scope == IStore2::ScopeType::DEVICE); uint32_t result; @@ -276,9 +282,9 @@ namespace Plugin { return result; } - uint32_t DeleteNamespace(const ScopeType scope, const string& ns) override + uint32_t DeleteNamespace(const IStore2::ScopeType scope, const string& ns) override { - ASSERT(scope == ScopeType::DEVICE); + ASSERT(scope == IStore2::ScopeType::DEVICE); uint32_t result; @@ -297,9 +303,189 @@ namespace Plugin { return result; } + uint32_t FlushCache() override + { + uint32_t result; + + auto rc = sqlite3_db_cacheflush(_data); + + if (rc == SQLITE_OK) { + result = Core::ERROR_NONE; + } else { + OnError(__FUNCTION__, rc); + result = Core::ERROR_GENERAL; + } + + sync(); + + return result; + } + uint32_t GetKeys(const IStoreInspector::ScopeType scope, const string& ns, RPC::IStringIterator*& keys) override + { + ASSERT(scope == IStoreInspector::ScopeType::DEVICE); + + uint32_t result; + + sqlite3_stmt* stmt; + sqlite3_prepare_v2(_data, "select key" + " from item" + " where ns in (select id from namespace where name = ?)" + ";", + -1, &stmt, nullptr); + sqlite3_bind_text(stmt, 1, ns.c_str(), -1, SQLITE_TRANSIENT); + std::list list; + int rc; + while ((rc = sqlite3_step(stmt)) == SQLITE_ROW) { + list.emplace_back((const char*)sqlite3_column_text(stmt, 0)); + } + sqlite3_finalize(stmt); + + if (rc == SQLITE_DONE) { + keys = (Core::Service::Create(list)); + result = Core::ERROR_NONE; + } else { + OnError(__FUNCTION__, rc); + result = Core::ERROR_GENERAL; + } + + return result; + } + uint32_t GetNamespaces(const IStoreInspector::ScopeType scope, RPC::IStringIterator*& namespaces) override + { + ASSERT(scope == IStoreInspector::ScopeType::DEVICE); + + uint32_t result; + + sqlite3_stmt* stmt; + sqlite3_prepare_v2(_data, "select name from namespace;", -1, &stmt, nullptr); + std::list list; + int rc; + while ((rc = sqlite3_step(stmt)) == SQLITE_ROW) { + list.emplace_back((const char*)sqlite3_column_text(stmt, 0)); + } + sqlite3_finalize(stmt); + + if (rc == SQLITE_DONE) { + namespaces = (Core::Service::Create(list)); + result = Core::ERROR_NONE; + } else { + OnError(__FUNCTION__, rc); + result = Core::ERROR_GENERAL; + } + + return result; + } + uint32_t GetStorageSizes(const IStoreInspector::ScopeType scope, INamespaceSizeIterator*& storageList) override + { + ASSERT(scope == IStoreInspector::ScopeType::DEVICE); + + uint32_t result; + + sqlite3_stmt* stmt; + sqlite3_prepare_v2(_data, "select name, sum(length(key)+length(value))" + " from item" + " inner join namespace on namespace.id = item.ns" + " group by name" + ";", + -1, &stmt, nullptr); + std::list list; + int rc; + while ((rc = sqlite3_step(stmt)) == SQLITE_ROW) { + NamespaceSize namespaceSize; + namespaceSize.ns = (const char*)sqlite3_column_text(stmt, 0); + namespaceSize.size = sqlite3_column_int(stmt, 1); + list.emplace_back(namespaceSize); + } + sqlite3_finalize(stmt); + + if (rc == SQLITE_DONE) { + storageList = (Core::Service>::Create(list)); + result = Core::ERROR_NONE; + } else { + OnError(__FUNCTION__, rc); + result = Core::ERROR_GENERAL; + } + + return result; + } + uint32_t SetNamespaceStorageLimit(const IStoreLimit::ScopeType scope, const string& ns, const uint32_t size) override + { + ASSERT(scope == IStoreLimit::ScopeType::DEVICE); + + uint32_t result; + + sqlite3_stmt* stmt; + sqlite3_prepare_v2(_data, "insert or ignore into namespace (name) values (?);", + -1, &stmt, nullptr); + sqlite3_bind_text(stmt, 1, ns.c_str(), -1, SQLITE_TRANSIENT); + auto rc = sqlite3_step(stmt); + sqlite3_finalize(stmt); + if (rc == SQLITE_DONE) { + sqlite3_prepare_v2(_data, "insert into limits (n,size)" + " select id, ?" + " from namespace" + " where name = ?" + ";", + -1, &stmt, nullptr); + sqlite3_bind_int(stmt, 1, size); + sqlite3_bind_text(stmt, 2, ns.c_str(), -1, SQLITE_TRANSIENT); + rc = sqlite3_step(stmt); + sqlite3_finalize(stmt); + } + + if (rc == SQLITE_DONE) { + result = Core::ERROR_NONE; + } else { + OnError(__FUNCTION__, rc); + if (rc == SQLITE_CONSTRAINT) { + result = Core::ERROR_INVALID_INPUT_LENGTH; + } else { + result = Core::ERROR_GENERAL; + } + } + + return result; + } + uint32_t GetNamespaceStorageLimit(const IStoreLimit::ScopeType scope, const string& ns, uint32_t& size) override + { + ASSERT(scope == IStoreLimit::ScopeType::DEVICE); + + uint32_t result; + + uint32_t s; + sqlite3_stmt* stmt; + sqlite3_prepare_v2(_data, "select size" + " from limits" + " inner join namespace on namespace.id = limits.n" + " where name = ?" + ";", + -1, &stmt, nullptr); + sqlite3_bind_text(stmt, 1, ns.c_str(), -1, SQLITE_TRANSIENT); + auto rc = sqlite3_step(stmt); + if (rc == SQLITE_ROW) { + s = (uint32_t)sqlite3_column_int(stmt, 0); + result = Core::ERROR_NONE; + } + sqlite3_finalize(stmt); + + if (rc == SQLITE_ROW) { + size = s; + result = Core::ERROR_NONE; + } else if (rc == SQLITE_DONE) { + result = Core::ERROR_NOT_EXIST; + } else { + OnError(__FUNCTION__, rc); + result = Core::ERROR_GENERAL; + } + + return result; + } BEGIN_INTERFACE_MAP(Store2) INTERFACE_ENTRY(IStore2) + INTERFACE_ENTRY(IStoreCache) + INTERFACE_ENTRY(IStoreInspector) + INTERFACE_ENTRY(IStoreLimit) END_INTERFACE_MAP private: @@ -311,7 +497,7 @@ namespace Plugin { index(_clients.begin()); while (index != _clients.end()) { - (*index)->ValueChanged(ScopeType::DEVICE, ns, key, value); + (*index)->ValueChanged(IStore2::ScopeType::DEVICE, ns, key, value); index++; } } diff --git a/PersistentStore/sqlite/StoreCache.cpp b/PersistentStore/sqlite/StoreCache.cpp deleted file mode 100644 index ec05da258b..0000000000 --- a/PersistentStore/sqlite/StoreCache.cpp +++ /dev/null @@ -1,8 +0,0 @@ -#include "StoreCache.h" - -namespace WPEFramework { -namespace Plugin { - class SqliteStoreCache : public Sqlite::StoreCache {}; - SERVICE_REGISTRATION(SqliteStoreCache, 1, 0); -} // namespace Plugin -} // namespace WPEFramework diff --git a/PersistentStore/sqlite/StoreCache.h b/PersistentStore/sqlite/StoreCache.h deleted file mode 100644 index d6811766af..0000000000 --- a/PersistentStore/sqlite/StoreCache.h +++ /dev/null @@ -1,114 +0,0 @@ -/* - * If not stated otherwise in this file or this component's LICENSE file the - * following copyright and licenses apply: - * - * Copyright 2022 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 -#include - -namespace WPEFramework { -namespace Plugin { - namespace Sqlite { - - class StoreCache : public Exchange::IStoreCache { - private: - StoreCache(const StoreCache&) = delete; - StoreCache& operator=(const StoreCache&) = delete; - - public: - StoreCache() - : StoreCache(getenv(PATH_ENV)) - { - } - StoreCache(const string& path) - : IStoreCache() - , _path(path) - { - Open(); - } - ~StoreCache() override - { - Close(); - } - - private: - void Open() - { - Core::File file(_path); - Core::Directory(file.PathName().c_str()).CreatePath(); - auto rc = sqlite3_open(_path.c_str(), &_data); - if (rc != SQLITE_OK) { - OnError(__FUNCTION__, rc); - } - const std::vector statements = { - "pragma busy_timeout = 1000000;" - }; - for (auto& sql : statements) { - auto rc = sqlite3_exec(_data, sql.c_str(), nullptr, nullptr, nullptr); - if (rc != SQLITE_OK) { - OnError(__FUNCTION__, rc); - } - } - } - void Close() - { - auto rc = sqlite3_close_v2(_data); - if (rc != SQLITE_OK) { - OnError(__FUNCTION__, rc); - } - } - - public: - uint32_t FlushCache() override - { - uint32_t result; - - auto rc = sqlite3_db_cacheflush(_data); - - if (rc == SQLITE_OK) { - result = Core::ERROR_NONE; - } else { - OnError(__FUNCTION__, rc); - result = Core::ERROR_GENERAL; - } - - sync(); - - return result; - } - - BEGIN_INTERFACE_MAP(StoreCache) - INTERFACE_ENTRY(IStoreCache) - END_INTERFACE_MAP - - private: - void OnError(const char* fn, const int status) const - { - TRACE(Trace::Error, (_T("%s sqlite error %d"), fn, status)); - } - - private: - const string _path; - sqlite3* _data; - }; - - } // namespace Sqlite -} // namespace Plugin -} // namespace WPEFramework diff --git a/PersistentStore/sqlite/StoreInspector.cpp b/PersistentStore/sqlite/StoreInspector.cpp deleted file mode 100644 index 543faab05a..0000000000 --- a/PersistentStore/sqlite/StoreInspector.cpp +++ /dev/null @@ -1,8 +0,0 @@ -#include "StoreInspector.h" - -namespace WPEFramework { -namespace Plugin { - class SqliteStoreInspector : public Sqlite::StoreInspector {}; - SERVICE_REGISTRATION(SqliteStoreInspector, 1, 0); -} // namespace Plugin -} // namespace WPEFramework diff --git a/PersistentStore/sqlite/StoreInspector.h b/PersistentStore/sqlite/StoreInspector.h deleted file mode 100644 index e1c03a99a8..0000000000 --- a/PersistentStore/sqlite/StoreInspector.h +++ /dev/null @@ -1,190 +0,0 @@ -/* - * If not stated otherwise in this file or this component's LICENSE file the - * following copyright and licenses apply: - * - * Copyright 2022 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 -#include - -namespace WPEFramework { -namespace Plugin { - namespace Sqlite { - - class StoreInspector : public Exchange::IStoreInspector { - private: - StoreInspector(const StoreInspector&) = delete; - StoreInspector& operator=(const StoreInspector&) = delete; - - typedef RPC::IteratorType NamespaceSizeIterator; - - public: - StoreInspector() - : StoreInspector(getenv(PATH_ENV)) - { - } - StoreInspector(const string& path) - : IStoreInspector() - , _path(path) - { - Open(); - } - ~StoreInspector() override - { - Close(); - } - - private: - void Open() - { - Core::File file(_path); - Core::Directory(file.PathName().c_str()).CreatePath(); - auto rc = sqlite3_open(_path.c_str(), &_data); - if (rc != SQLITE_OK) { - OnError(__FUNCTION__, rc); - } - const std::vector statements = { - "pragma foreign_keys = on;", - "pragma busy_timeout = 1000000;", - "create table if not exists namespace (id integer primary key,name text unique);", - "create table if not exists item (ns integer,key text,value text,foreign key(ns) references namespace(id) on delete cascade on update no action,unique(ns,key) on conflict replace);" - }; - for (auto& sql : statements) { - auto rc = sqlite3_exec(_data, sql.c_str(), nullptr, nullptr, nullptr); - if (rc != SQLITE_OK) { - OnError(__FUNCTION__, rc); - } - } - } - void Close() - { - auto rc = sqlite3_close_v2(_data); - if (rc != SQLITE_OK) { - OnError(__FUNCTION__, rc); - } - } - - public: - uint32_t GetKeys(const ScopeType scope, const string& ns, RPC::IStringIterator*& keys) override - { - ASSERT(scope == ScopeType::DEVICE); - - uint32_t result; - - sqlite3_stmt* stmt; - sqlite3_prepare_v2(_data, "select key" - " from item" - " where ns in (select id from namespace where name = ?)" - ";", - -1, &stmt, nullptr); - sqlite3_bind_text(stmt, 1, ns.c_str(), -1, SQLITE_TRANSIENT); - std::list list; - int rc; - while ((rc = sqlite3_step(stmt)) == SQLITE_ROW) { - list.emplace_back((const char*)sqlite3_column_text(stmt, 0)); - } - sqlite3_finalize(stmt); - - if (rc == SQLITE_DONE) { - keys = (Core::Service::Create(list)); - result = Core::ERROR_NONE; - } else { - OnError(__FUNCTION__, rc); - result = Core::ERROR_GENERAL; - } - - return result; - } - uint32_t GetNamespaces(const ScopeType scope, RPC::IStringIterator*& namespaces) override - { - ASSERT(scope == ScopeType::DEVICE); - - uint32_t result; - - sqlite3_stmt* stmt; - sqlite3_prepare_v2(_data, "select name from namespace;", -1, &stmt, nullptr); - std::list list; - int rc; - while ((rc = sqlite3_step(stmt)) == SQLITE_ROW) { - list.emplace_back((const char*)sqlite3_column_text(stmt, 0)); - } - sqlite3_finalize(stmt); - - if (rc == SQLITE_DONE) { - namespaces = (Core::Service::Create(list)); - result = Core::ERROR_NONE; - } else { - OnError(__FUNCTION__, rc); - result = Core::ERROR_GENERAL; - } - - return result; - } - uint32_t GetStorageSizes(const ScopeType scope, INamespaceSizeIterator*& storageList) override - { - ASSERT(scope == ScopeType::DEVICE); - - uint32_t result; - - sqlite3_stmt* stmt; - sqlite3_prepare_v2(_data, "select name, sum(length(key)+length(value))" - " from item" - " inner join namespace on namespace.id = item.ns" - " group by name" - ";", - -1, &stmt, nullptr); - std::list list; - int rc; - while ((rc = sqlite3_step(stmt)) == SQLITE_ROW) { - NamespaceSize namespaceSize; - namespaceSize.ns = (const char*)sqlite3_column_text(stmt, 0); - namespaceSize.size = sqlite3_column_int(stmt, 1); - list.emplace_back(namespaceSize); - } - sqlite3_finalize(stmt); - - if (rc == SQLITE_DONE) { - storageList = (Core::Service::Create(list)); - result = Core::ERROR_NONE; - } else { - OnError(__FUNCTION__, rc); - result = Core::ERROR_GENERAL; - } - - return result; - } - - BEGIN_INTERFACE_MAP(StoreInspector) - INTERFACE_ENTRY(IStoreInspector) - END_INTERFACE_MAP - - private: - void OnError(const char* fn, const int status) const - { - TRACE(Trace::Error, (_T("%s sqlite error %d"), fn, status)); - } - - private: - const string _path; - sqlite3* _data; - }; - - } // namespace Sqlite -} // namespace Plugin -} // namespace WPEFramework diff --git a/PersistentStore/sqlite/StoreLimit.cpp b/PersistentStore/sqlite/StoreLimit.cpp deleted file mode 100644 index c37cd1507a..0000000000 --- a/PersistentStore/sqlite/StoreLimit.cpp +++ /dev/null @@ -1,8 +0,0 @@ -#include "StoreLimit.h" - -namespace WPEFramework { -namespace Plugin { - class SqliteStoreLimit : public Sqlite::StoreLimit {}; - SERVICE_REGISTRATION(SqliteStoreLimit, 1, 0); -} // namespace Plugin -} // namespace WPEFramework diff --git a/PersistentStore/sqlite/StoreLimit.h b/PersistentStore/sqlite/StoreLimit.h deleted file mode 100644 index 86f9300a7f..0000000000 --- a/PersistentStore/sqlite/StoreLimit.h +++ /dev/null @@ -1,183 +0,0 @@ -/* - * If not stated otherwise in this file or this component's LICENSE file the - * following copyright and licenses apply: - * - * Copyright 2022 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 -#include - -namespace WPEFramework { -namespace Plugin { - namespace Sqlite { - - class StoreLimit : public Exchange::IStoreLimit { - private: - StoreLimit(const StoreLimit&) = delete; - StoreLimit& operator=(const StoreLimit&) = delete; - - public: - StoreLimit() - : StoreLimit( - getenv(PATH_ENV), - std::stoul(getenv(MAXSIZE_ENV)), - std::stoul(getenv(MAXVALUE_ENV))) - { - } - StoreLimit(const string& path, const uint64_t maxSize, const uint64_t maxValue) - : IStoreLimit() - , _path(path) - , _maxSize(maxSize) - , _maxValue(maxValue) - { - Open(); - } - ~StoreLimit() override - { - Close(); - } - - private: - void Open() - { - Core::File file(_path); - Core::Directory(file.PathName().c_str()).CreatePath(); - auto rc = sqlite3_open(_path.c_str(), &_data); - if (rc != SQLITE_OK) { - OnError(__FUNCTION__, rc); - } - const std::vector statements = { - "pragma foreign_keys = on;", - "pragma busy_timeout = 1000000;", - "create table if not exists namespace (id integer primary key,name text unique);", - "create table if not exists item (ns integer,key text,value text,foreign key(ns) references namespace(id) on delete cascade on update no action,unique(ns,key) on conflict replace);", - "create table if not exists limits (n integer,size integer,foreign key(n) references namespace(id) on delete cascade on update no action,unique(n) on conflict replace);", - "create temporary trigger if not exists ns_empty insert on namespace begin select case when length(new.name) = 0 then raise (fail, 'empty') end; end;", - "create temporary trigger if not exists ns_maxvalue insert on namespace begin select case when length(new.name) > " + std::to_string(_maxValue) + " then raise (fail, 'max value') end; end;", - "create temporary trigger if not exists ns_maxsize insert on namespace begin select case when (select sum(s) from (select sum(length(key)+length(value)) s from item union all select sum(length(name)) s from namespace union all select length(new.name) s)) > " + std::to_string(_maxSize) + " then raise (fail, 'max size') end; end;" - }; - for (auto& sql : statements) { - auto rc = sqlite3_exec(_data, sql.c_str(), nullptr, nullptr, nullptr); - if (rc != SQLITE_OK) { - OnError(__FUNCTION__, rc); - } - } - } - void Close() - { - auto rc = sqlite3_close_v2(_data); - if (rc != SQLITE_OK) { - OnError(__FUNCTION__, rc); - } - } - - public: - uint32_t SetNamespaceStorageLimit(const ScopeType scope, const string& ns, const uint32_t size) override - { - ASSERT(scope == ScopeType::DEVICE); - - uint32_t result; - - sqlite3_stmt* stmt; - sqlite3_prepare_v2(_data, "insert or ignore into namespace (name) values (?);", - -1, &stmt, nullptr); - sqlite3_bind_text(stmt, 1, ns.c_str(), -1, SQLITE_TRANSIENT); - auto rc = sqlite3_step(stmt); - sqlite3_finalize(stmt); - if (rc == SQLITE_DONE) { - sqlite3_prepare_v2(_data, "insert into limits (n,size)" - " select id, ?" - " from namespace" - " where name = ?" - ";", - -1, &stmt, nullptr); - sqlite3_bind_int(stmt, 1, size); - sqlite3_bind_text(stmt, 2, ns.c_str(), -1, SQLITE_TRANSIENT); - rc = sqlite3_step(stmt); - sqlite3_finalize(stmt); - } - - if (rc == SQLITE_DONE) { - result = Core::ERROR_NONE; - } else { - OnError(__FUNCTION__, rc); - if (rc == SQLITE_CONSTRAINT) { - result = Core::ERROR_INVALID_INPUT_LENGTH; - } else { - result = Core::ERROR_GENERAL; - } - } - - return result; - } - uint32_t GetNamespaceStorageLimit(const ScopeType scope, const string& ns, uint32_t& size) override - { - ASSERT(scope == ScopeType::DEVICE); - - uint32_t result; - - uint32_t s; - sqlite3_stmt* stmt; - sqlite3_prepare_v2(_data, "select size" - " from limits" - " inner join namespace on namespace.id = limits.n" - " where name = ?" - ";", - -1, &stmt, nullptr); - sqlite3_bind_text(stmt, 1, ns.c_str(), -1, SQLITE_TRANSIENT); - auto rc = sqlite3_step(stmt); - if (rc == SQLITE_ROW) { - s = (uint32_t)sqlite3_column_int(stmt, 0); - result = Core::ERROR_NONE; - } - sqlite3_finalize(stmt); - - if (rc == SQLITE_ROW) { - size = s; - result = Core::ERROR_NONE; - } else if (rc == SQLITE_DONE) { - result = Core::ERROR_NOT_EXIST; - } else { - OnError(__FUNCTION__, rc); - result = Core::ERROR_GENERAL; - } - - return result; - } - - BEGIN_INTERFACE_MAP(StoreLimit) - INTERFACE_ENTRY(IStoreLimit) - END_INTERFACE_MAP - - private: - void OnError(const char* fn, const int status) const - { - TRACE(Trace::Error, (_T("%s sqlite error %d"), fn, status)); - } - - private: - const string _path; - const uint64_t _maxSize; - const uint64_t _maxValue; - sqlite3* _data; - }; - - } // namespace Sqlite -} // namespace Plugin -} // namespace WPEFramework diff --git a/PersistentStore/sqlite/l1test/CMakeLists.txt b/PersistentStore/sqlite/l1test/CMakeLists.txt index 168d5ee7bc..698833ebf3 100644 --- a/PersistentStore/sqlite/l1test/CMakeLists.txt +++ b/PersistentStore/sqlite/l1test/CMakeLists.txt @@ -34,9 +34,6 @@ find_package(${NAMESPACE}Plugins REQUIRED) add_executable(${PROJECT_NAME} ../../Module.cpp Store2Test.cpp - StoreCacheTest.cpp - StoreInspectorTest.cpp - StoreLimitTest.cpp ) target_link_libraries(${PROJECT_NAME} PRIVATE diff --git a/PersistentStore/sqlite/l1test/Store2Test.cpp b/PersistentStore/sqlite/l1test/Store2Test.cpp index 9d30c9471d..2ee78da6a4 100644 --- a/PersistentStore/sqlite/l1test/Store2Test.cpp +++ b/PersistentStore/sqlite/l1test/Store2Test.cpp @@ -8,11 +8,18 @@ using ::testing::_; using ::testing::Eq; using ::testing::Gt; using ::testing::Invoke; +using ::testing::IsFalse; +using ::testing::IsTrue; using ::testing::Le; using ::testing::NiceMock; +using ::testing::NotNull; using ::testing::Test; using ::WPEFramework::Exchange::IStore2; +using ::WPEFramework::Exchange::IStoreCache; +using ::WPEFramework::Exchange::IStoreInspector; +using ::WPEFramework::Exchange::IStoreLimit; using ::WPEFramework::Plugin::Sqlite::Store2; +using ::WPEFramework::RPC::IStringIterator; const auto kPath = "/tmp/persistentstore/sqlite/l1test/store2test"; const auto kMaxSize = 100; @@ -23,82 +30,80 @@ const auto kKey = "key_1"; const auto kAppId = "app_id_1"; const auto kTtl = 2; const auto kNoTtl = 0; -const auto kScope = IStore2::ScopeType::DEVICE; const auto kEmpty = ""; const auto kOversize = "this is too large"; const auto kUnknown = "unknown"; +const auto kLimit20 = 20; +const auto kLimit30 = 30; +const auto kLimit40 = 40; class AStore2 : public Test { protected: - IStore2* store2; + WPEFramework::Core::ProxyType store2; AStore2() - : store2(WPEFramework::Core::Service::Create(kPath, kMaxSize, kMaxValue, kLimit)) + : store2(WPEFramework::Core::ProxyType::Create(kPath, kMaxSize, kMaxValue, kLimit)) { } - ~AStore2() override - { - store2->Release(); - } }; TEST_F(AStore2, DoesNotSetValueWhenNamespaceEmpty) { - EXPECT_THAT(store2->SetValue(kScope, kEmpty, kKey, kValue, kNoTtl), Eq(WPEFramework::Core::ERROR_INVALID_INPUT_LENGTH)); + EXPECT_THAT(store2->SetValue(IStore2::ScopeType::DEVICE, kEmpty, kKey, kValue, kNoTtl), Eq(WPEFramework::Core::ERROR_INVALID_INPUT_LENGTH)); } TEST_F(AStore2, DoesNotSetValueWhenKeyEmpty) { - EXPECT_THAT(store2->SetValue(kScope, kAppId, kEmpty, kValue, kNoTtl), Eq(WPEFramework::Core::ERROR_INVALID_INPUT_LENGTH)); + EXPECT_THAT(store2->SetValue(IStore2::ScopeType::DEVICE, kAppId, kEmpty, kValue, kNoTtl), Eq(WPEFramework::Core::ERROR_INVALID_INPUT_LENGTH)); } TEST_F(AStore2, DoesNotSetValueWhenNamespaceOversize) { - EXPECT_THAT(store2->SetValue(kScope, kOversize, kKey, kValue, kNoTtl), Eq(WPEFramework::Core::ERROR_INVALID_INPUT_LENGTH)); + EXPECT_THAT(store2->SetValue(IStore2::ScopeType::DEVICE, kOversize, kKey, kValue, kNoTtl), Eq(WPEFramework::Core::ERROR_INVALID_INPUT_LENGTH)); } TEST_F(AStore2, DoesNotSetValueWhenKeyOversize) { - EXPECT_THAT(store2->SetValue(kScope, kAppId, kOversize, kValue, kNoTtl), Eq(WPEFramework::Core::ERROR_INVALID_INPUT_LENGTH)); + EXPECT_THAT(store2->SetValue(IStore2::ScopeType::DEVICE, kAppId, kOversize, kValue, kNoTtl), Eq(WPEFramework::Core::ERROR_INVALID_INPUT_LENGTH)); } TEST_F(AStore2, DoesNotSetValueWhenValueOversize) { - EXPECT_THAT(store2->SetValue(kScope, kAppId, kKey, kOversize, kNoTtl), Eq(WPEFramework::Core::ERROR_INVALID_INPUT_LENGTH)); + EXPECT_THAT(store2->SetValue(IStore2::ScopeType::DEVICE, kAppId, kKey, kOversize, kNoTtl), Eq(WPEFramework::Core::ERROR_INVALID_INPUT_LENGTH)); } TEST_F(AStore2, DoesNotGetValueWhenNamespaceUnknown) { string value; uint32_t ttl; - EXPECT_THAT(store2->GetValue(kScope, kUnknown, kKey, value, ttl), Eq(WPEFramework::Core::ERROR_NOT_EXIST)); + EXPECT_THAT(store2->GetValue(IStore2::ScopeType::DEVICE, kUnknown, kKey, value, ttl), Eq(WPEFramework::Core::ERROR_NOT_EXIST)); } TEST_F(AStore2, DeletesKeyWhenNamespaceUnknown) { - EXPECT_THAT(store2->DeleteKey(kScope, kUnknown, kKey), Eq(WPEFramework::Core::ERROR_NONE)); + EXPECT_THAT(store2->DeleteKey(IStore2::ScopeType::DEVICE, kUnknown, kKey), Eq(WPEFramework::Core::ERROR_NONE)); } TEST_F(AStore2, DeletesNamespaceWhenNamespaceUnknown) { - EXPECT_THAT(store2->DeleteNamespace(kScope, kUnknown), Eq(WPEFramework::Core::ERROR_NONE)); + EXPECT_THAT(store2->DeleteNamespace(IStore2::ScopeType::DEVICE, kUnknown), Eq(WPEFramework::Core::ERROR_NONE)); } TEST_F(AStore2, SetsValueWhenValueEmpty) { - ASSERT_THAT(store2->SetValue(kScope, kAppId, kKey, kEmpty, kNoTtl), Eq(WPEFramework::Core::ERROR_NONE)); + ASSERT_THAT(store2->SetValue(IStore2::ScopeType::DEVICE, kAppId, kKey, kEmpty, kNoTtl), Eq(WPEFramework::Core::ERROR_NONE)); string value; uint32_t ttl; - ASSERT_THAT(store2->GetValue(kScope, kAppId, kKey, value, ttl), Eq(WPEFramework::Core::ERROR_NONE)); + ASSERT_THAT(store2->GetValue(IStore2::ScopeType::DEVICE, kAppId, kKey, value, ttl), Eq(WPEFramework::Core::ERROR_NONE)); EXPECT_THAT(value, Eq(kEmpty)); EXPECT_THAT(ttl, Eq(kNoTtl)); } TEST_F(AStore2, GetsValueWhenTtlNotExpired) { - ASSERT_THAT(store2->SetValue(kScope, kAppId, kKey, kValue, kTtl), Eq(WPEFramework::Core::ERROR_NONE)); + ASSERT_THAT(store2->SetValue(IStore2::ScopeType::DEVICE, kAppId, kKey, kValue, kTtl), Eq(WPEFramework::Core::ERROR_NONE)); string value; uint32_t ttl; - ASSERT_THAT(store2->GetValue(kScope, kAppId, kKey, value, ttl), Eq(WPEFramework::Core::ERROR_NONE)); + ASSERT_THAT(store2->GetValue(IStore2::ScopeType::DEVICE, kAppId, kKey, value, ttl), Eq(WPEFramework::Core::ERROR_NONE)); EXPECT_THAT(value, Eq(kValue)); EXPECT_THAT(ttl, Le(kTtl)); EXPECT_THAT(ttl, Gt(kNoTtl)); @@ -106,12 +111,12 @@ TEST_F(AStore2, GetsValueWhenTtlNotExpired) TEST_F(AStore2, DoesNotGetValueWhenTtlExpired) { - ASSERT_THAT(store2->SetValue(kScope, kAppId, kKey, kValue, kTtl), Eq(WPEFramework::Core::ERROR_NONE)); + ASSERT_THAT(store2->SetValue(IStore2::ScopeType::DEVICE, kAppId, kKey, kValue, kTtl), Eq(WPEFramework::Core::ERROR_NONE)); WPEFramework::Core::Event lock(false, true); lock.Lock(kTtl * WPEFramework::Core::Time::MilliSecondsPerSecond); string value; uint32_t ttl; - EXPECT_THAT(store2->GetValue(kScope, kAppId, kKey, value, ttl), Eq(WPEFramework::Core::ERROR_UNKNOWN_KEY)); + EXPECT_THAT(store2->GetValue(IStore2::ScopeType::DEVICE, kAppId, kKey, value, ttl), Eq(WPEFramework::Core::ERROR_UNKNOWN_KEY)); } TEST_F(AStore2, ValueChangedWhenSetValue) @@ -123,7 +128,7 @@ TEST_F(AStore2, ValueChangedWhenSetValue) EXPECT_CALL(*this, ValueChanged(_, _, _, _)) .WillRepeatedly(Invoke( [](const IStore2::ScopeType scope, const string& ns, const string& key, const string& value) { - EXPECT_THAT(scope, Eq(kScope)); + EXPECT_THAT(scope, Eq(IStore2::ScopeType::DEVICE)); EXPECT_THAT(ns, Eq(kAppId)); EXPECT_THAT(key, Eq(kKey)); EXPECT_THAT(value, Eq(kValue)); @@ -133,50 +138,170 @@ TEST_F(AStore2, ValueChangedWhenSetValue) }; WPEFramework::Core::Sink sink; store2->Register(&sink); - EXPECT_THAT(store2->SetValue(kScope, kAppId, kKey, kValue, kNoTtl), Eq(WPEFramework::Core::ERROR_NONE)); + EXPECT_THAT(store2->SetValue(IStore2::ScopeType::DEVICE, kAppId, kKey, kValue, kNoTtl), Eq(WPEFramework::Core::ERROR_NONE)); store2->Unregister(&sink); } TEST_F(AStore2, DoesNotGetValueWhenKeyUnknown) { - ASSERT_THAT(store2->SetValue(kScope, kAppId, kKey, kValue, kNoTtl), Eq(WPEFramework::Core::ERROR_NONE)); + ASSERT_THAT(store2->SetValue(IStore2::ScopeType::DEVICE, kAppId, kKey, kValue, kNoTtl), Eq(WPEFramework::Core::ERROR_NONE)); string value; uint32_t ttl; - EXPECT_THAT(store2->GetValue(kScope, kAppId, kUnknown, value, ttl), Eq(WPEFramework::Core::ERROR_UNKNOWN_KEY)); + EXPECT_THAT(store2->GetValue(IStore2::ScopeType::DEVICE, kAppId, kUnknown, value, ttl), Eq(WPEFramework::Core::ERROR_UNKNOWN_KEY)); } TEST_F(AStore2, DeletesKeyWhenKeyUnknown) { - ASSERT_THAT(store2->SetValue(kScope, kAppId, kKey, kValue, kNoTtl), Eq(WPEFramework::Core::ERROR_NONE)); - EXPECT_THAT(store2->DeleteKey(kScope, kAppId, kUnknown), Eq(WPEFramework::Core::ERROR_NONE)); + ASSERT_THAT(store2->SetValue(IStore2::ScopeType::DEVICE, kAppId, kKey, kValue, kNoTtl), Eq(WPEFramework::Core::ERROR_NONE)); + EXPECT_THAT(store2->DeleteKey(IStore2::ScopeType::DEVICE, kAppId, kUnknown), Eq(WPEFramework::Core::ERROR_NONE)); } TEST_F(AStore2, DeletesKey) { - ASSERT_THAT(store2->SetValue(kScope, kAppId, kKey, kValue, kNoTtl), Eq(WPEFramework::Core::ERROR_NONE)); - ASSERT_THAT(store2->DeleteKey(kScope, kAppId, kKey), Eq(WPEFramework::Core::ERROR_NONE)); + ASSERT_THAT(store2->SetValue(IStore2::ScopeType::DEVICE, kAppId, kKey, kValue, kNoTtl), Eq(WPEFramework::Core::ERROR_NONE)); + ASSERT_THAT(store2->DeleteKey(IStore2::ScopeType::DEVICE, kAppId, kKey), Eq(WPEFramework::Core::ERROR_NONE)); string value; uint32_t ttl; - EXPECT_THAT(store2->GetValue(kScope, kAppId, kKey, value, ttl), Eq(WPEFramework::Core::ERROR_UNKNOWN_KEY)); + EXPECT_THAT(store2->GetValue(IStore2::ScopeType::DEVICE, kAppId, kKey, value, ttl), Eq(WPEFramework::Core::ERROR_UNKNOWN_KEY)); } TEST_F(AStore2, DeletesNamespace) { - ASSERT_THAT(store2->SetValue(kScope, kAppId, kKey, kValue, kNoTtl), Eq(WPEFramework::Core::ERROR_NONE)); - ASSERT_THAT(store2->DeleteNamespace(kScope, kAppId), Eq(WPEFramework::Core::ERROR_NONE)); + ASSERT_THAT(store2->SetValue(IStore2::ScopeType::DEVICE, kAppId, kKey, kValue, kNoTtl), Eq(WPEFramework::Core::ERROR_NONE)); + ASSERT_THAT(store2->DeleteNamespace(IStore2::ScopeType::DEVICE, kAppId), Eq(WPEFramework::Core::ERROR_NONE)); string value; uint32_t ttl; - EXPECT_THAT(store2->GetValue(kScope, kAppId, kKey, value, ttl), Eq(WPEFramework::Core::ERROR_NOT_EXIST)); + EXPECT_THAT(store2->GetValue(IStore2::ScopeType::DEVICE, kAppId, kKey, value, ttl), Eq(WPEFramework::Core::ERROR_NOT_EXIST)); } TEST_F(AStore2, DoesNotSetValueWhenReachedMaxSize) { - ASSERT_THAT(store2->DeleteNamespace(kScope, kAppId), Eq(WPEFramework::Core::ERROR_NONE)); - ASSERT_THAT(store2->SetValue(kScope, "8InMXXU4hM", "YWKN74ODMf", "N0ed2C2h4n", kNoTtl), Eq(WPEFramework::Core::ERROR_NONE)); - ASSERT_THAT(store2->SetValue(kScope, "XhrICnuerw", "jPKODBDk5K", "d3BarkA5xF", kNoTtl), Eq(WPEFramework::Core::ERROR_NONE)); - ASSERT_THAT(store2->SetValue(kScope, "WNeBknDDI2", "GC96ZN6Fuq", "IBF2E1MLQh", kNoTtl), Eq(WPEFramework::Core::ERROR_NONE)); - EXPECT_THAT(store2->SetValue(kScope, kAppId, kKey, kValue, kNoTtl), Eq(WPEFramework::Core::ERROR_INVALID_INPUT_LENGTH)); - EXPECT_THAT(store2->DeleteNamespace(kScope, "8InMXXU4hM"), Eq(WPEFramework::Core::ERROR_NONE)); - EXPECT_THAT(store2->DeleteNamespace(kScope, "XhrICnuerw"), Eq(WPEFramework::Core::ERROR_NONE)); - EXPECT_THAT(store2->DeleteNamespace(kScope, "WNeBknDDI2"), Eq(WPEFramework::Core::ERROR_NONE)); + ASSERT_THAT(store2->DeleteNamespace(IStore2::ScopeType::DEVICE, kAppId), Eq(WPEFramework::Core::ERROR_NONE)); + ASSERT_THAT(store2->SetValue(IStore2::ScopeType::DEVICE, "8InMXXU4hM", "YWKN74ODMf", "N0ed2C2h4n", kNoTtl), Eq(WPEFramework::Core::ERROR_NONE)); + ASSERT_THAT(store2->SetValue(IStore2::ScopeType::DEVICE, "XhrICnuerw", "jPKODBDk5K", "d3BarkA5xF", kNoTtl), Eq(WPEFramework::Core::ERROR_NONE)); + ASSERT_THAT(store2->SetValue(IStore2::ScopeType::DEVICE, "WNeBknDDI2", "GC96ZN6Fuq", "IBF2E1MLQh", kNoTtl), Eq(WPEFramework::Core::ERROR_NONE)); + EXPECT_THAT(store2->SetValue(IStore2::ScopeType::DEVICE, kAppId, kKey, kValue, kNoTtl), Eq(WPEFramework::Core::ERROR_INVALID_INPUT_LENGTH)); + EXPECT_THAT(store2->DeleteNamespace(IStore2::ScopeType::DEVICE, "8InMXXU4hM"), Eq(WPEFramework::Core::ERROR_NONE)); + EXPECT_THAT(store2->DeleteNamespace(IStore2::ScopeType::DEVICE, "XhrICnuerw"), Eq(WPEFramework::Core::ERROR_NONE)); + EXPECT_THAT(store2->DeleteNamespace(IStore2::ScopeType::DEVICE, "WNeBknDDI2"), Eq(WPEFramework::Core::ERROR_NONE)); +} + +TEST_F(AStore2, FlushesCache) +{ + EXPECT_THAT(store2->FlushCache(), Eq(WPEFramework::Core::ERROR_NONE)); +} + +TEST_F(AStore2, GetsKeysWhenNamespaceUnknown) +{ + IStringIterator* it; + ASSERT_THAT(store2->GetKeys(IStoreInspector::ScopeType::DEVICE, kUnknown, it), Eq(WPEFramework::Core::ERROR_NONE)); + ASSERT_THAT(it, NotNull()); + string element; + EXPECT_THAT(it->Next(element), IsFalse()); + it->Release(); +} + +TEST_F(AStore2, GetsKeys) +{ + ASSERT_THAT(store2->SetValue(IStore2::ScopeType::DEVICE, kAppId, kKey, kValue, kNoTtl), Eq(WPEFramework::Core::ERROR_NONE)); + IStringIterator* it; + ASSERT_THAT(store2->GetKeys(IStoreInspector::ScopeType::DEVICE, kAppId, it), Eq(WPEFramework::Core::ERROR_NONE)); + ASSERT_THAT(it, NotNull()); + string element; + ASSERT_THAT(it->Next(element), IsTrue()); + EXPECT_THAT(element, Eq(kKey)); + EXPECT_THAT(it->Next(element), IsFalse()); + it->Release(); +} + +TEST_F(AStore2, GetsNamespaces) +{ + ASSERT_THAT(store2->SetValue(IStore2::ScopeType::DEVICE, kAppId, kKey, kValue, kNoTtl), Eq(WPEFramework::Core::ERROR_NONE)); + IStringIterator* it; + ASSERT_THAT(store2->GetNamespaces(IStoreInspector::ScopeType::DEVICE, it), Eq(WPEFramework::Core::ERROR_NONE)); + ASSERT_THAT(it, NotNull()); + string element; + ASSERT_THAT(it->Next(element), IsTrue()); + EXPECT_THAT(element, Eq(kAppId)); + EXPECT_THAT(it->Next(element), IsFalse()); + it->Release(); +} + +TEST_F(AStore2, GetsStorageSizes) +{ + ASSERT_THAT(store2->SetValue(IStore2::ScopeType::DEVICE, kAppId, kKey, kValue, kNoTtl), Eq(WPEFramework::Core::ERROR_NONE)); + IStoreInspector::INamespaceSizeIterator* it; + ASSERT_THAT(store2->GetStorageSizes(IStoreInspector::ScopeType::DEVICE, it), Eq(WPEFramework::Core::ERROR_NONE)); + ASSERT_THAT(it, NotNull()); + IStoreInspector::NamespaceSize element; + ASSERT_THAT(it->Next(element), IsTrue()); + EXPECT_THAT(element.ns, Eq(kAppId)); + EXPECT_THAT(element.size, Eq(strlen(kKey) + strlen(kValue))); + EXPECT_THAT(it->Next(element), IsFalse()); + it->Release(); +} + +TEST_F(AStore2, DoesNotGetNamespaceStorageLimitWhenNamespaceUnknown) +{ + uint32_t value; + EXPECT_THAT(store2->GetNamespaceStorageLimit(IStoreLimit::ScopeType::DEVICE, kUnknown, value), Eq(WPEFramework::Core::ERROR_NOT_EXIST)); +} + +TEST_F(AStore2, DoesNotSetNamespaceStorageLimitWhenNamespaceEmpty) +{ + EXPECT_THAT(store2->SetNamespaceStorageLimit(IStoreLimit::ScopeType::DEVICE, kEmpty, kLimit20), Eq(WPEFramework::Core::ERROR_INVALID_INPUT_LENGTH)); +} + +TEST_F(AStore2, DoesNotSetNamespaceStorageLimitWhenNamespaceOversize) +{ + EXPECT_THAT(store2->SetNamespaceStorageLimit(IStoreLimit::ScopeType::DEVICE, kOversize, kLimit20), Eq(WPEFramework::Core::ERROR_INVALID_INPUT_LENGTH)); +} + +TEST_F(AStore2, SetsNamespaceStorageLimit) +{ + ASSERT_THAT(store2->SetNamespaceStorageLimit(IStoreLimit::ScopeType::DEVICE, kAppId, kLimit20), Eq(WPEFramework::Core::ERROR_NONE)); + uint32_t value; + ASSERT_THAT(store2->GetNamespaceStorageLimit(IStoreLimit::ScopeType::DEVICE, kAppId, value), Eq(WPEFramework::Core::ERROR_NONE)); + EXPECT_THAT(value, Eq(kLimit20)); +} + +TEST_F(AStore2, SetsNamespaceStorageLimitWhenAlreadySet) +{ + ASSERT_THAT(store2->SetNamespaceStorageLimit(IStoreLimit::ScopeType::DEVICE, kAppId, kLimit30), Eq(WPEFramework::Core::ERROR_NONE)); + uint32_t value; + ASSERT_THAT(store2->GetNamespaceStorageLimit(IStoreLimit::ScopeType::DEVICE, kAppId, value), Eq(WPEFramework::Core::ERROR_NONE)); + EXPECT_THAT(value, Eq(kLimit30)); + ASSERT_THAT(store2->SetNamespaceStorageLimit(IStoreLimit::ScopeType::DEVICE, kAppId, kLimit40), Eq(WPEFramework::Core::ERROR_NONE)); + ASSERT_THAT(store2->GetNamespaceStorageLimit(IStoreLimit::ScopeType::DEVICE, kAppId, value), Eq(WPEFramework::Core::ERROR_NONE)); + EXPECT_THAT(value, Eq(kLimit40)); +} + +TEST_F(AStore2, DoesNotSetNamespaceStorageLimitWhenReachedMaxSize) +{ + ASSERT_THAT(store2->DeleteNamespace(IStore2::ScopeType::DEVICE, kAppId), Eq(WPEFramework::Core::ERROR_NONE)); + ASSERT_THAT(store2->SetValue(IStore2::ScopeType::DEVICE, "8InMXXU4hM", "YWKN74ODMf", "N0ed2C2h4n", kNoTtl), Eq(WPEFramework::Core::ERROR_NONE)); + ASSERT_THAT(store2->SetValue(IStore2::ScopeType::DEVICE, "XhrICnuerw", "jPKODBDk5K", "d3BarkA5xF", kNoTtl), Eq(WPEFramework::Core::ERROR_NONE)); + ASSERT_THAT(store2->SetValue(IStore2::ScopeType::DEVICE, "WNeBknDDI2", "GC96ZN6Fuq", "IBF2E1MLQh", kNoTtl), Eq(WPEFramework::Core::ERROR_NONE)); + ASSERT_THAT(store2->SetValue(IStore2::ScopeType::DEVICE, "V92", "R1R", "rHk", kNoTtl), Eq(WPEFramework::Core::ERROR_NONE)); + EXPECT_THAT(store2->SetNamespaceStorageLimit(IStoreLimit::ScopeType::DEVICE, kAppId, kLimit), Eq(WPEFramework::Core::ERROR_INVALID_INPUT_LENGTH)); + EXPECT_THAT(store2->DeleteNamespace(IStore2::ScopeType::DEVICE, "8InMXXU4hM"), Eq(WPEFramework::Core::ERROR_NONE)); + EXPECT_THAT(store2->DeleteNamespace(IStore2::ScopeType::DEVICE, "XhrICnuerw"), Eq(WPEFramework::Core::ERROR_NONE)); + EXPECT_THAT(store2->DeleteNamespace(IStore2::ScopeType::DEVICE, "WNeBknDDI2"), Eq(WPEFramework::Core::ERROR_NONE)); + EXPECT_THAT(store2->DeleteNamespace(IStore2::ScopeType::DEVICE, "V92"), Eq(WPEFramework::Core::ERROR_NONE)); +} + +TEST_F(AStore2, EnforcesSetValueToFailWhenReachedDefaultLimit) +{ + ASSERT_THAT(store2->DeleteNamespace(IStore2::ScopeType::DEVICE, kAppId), Eq(WPEFramework::Core::ERROR_NONE)); + ASSERT_THAT(store2->SetValue(IStore2::ScopeType::DEVICE, kAppId, "YWKN74ODMf", "N0ed2C2h4n", kNoTtl), Eq(WPEFramework::Core::ERROR_NONE)); + ASSERT_THAT(store2->SetValue(IStore2::ScopeType::DEVICE, kAppId, "jPKODBDk5K", "d3BarkA5xF", kNoTtl), Eq(WPEFramework::Core::ERROR_NONE)); + ASSERT_THAT(store2->SetValue(IStore2::ScopeType::DEVICE, kAppId, kKey, kValue, kNoTtl), Eq(WPEFramework::Core::ERROR_INVALID_INPUT_LENGTH)); +} + +TEST_F(AStore2, EnforcesSetValueToFailWhenReachedLimit) +{ + ASSERT_THAT(store2->DeleteNamespace(IStore2::ScopeType::DEVICE, kAppId), Eq(WPEFramework::Core::ERROR_NONE)); + EXPECT_THAT(store2->SetNamespaceStorageLimit(IStoreLimit::ScopeType::DEVICE, kAppId, kLimit20), Eq(WPEFramework::Core::ERROR_NONE)); + ASSERT_THAT(store2->SetValue(IStore2::ScopeType::DEVICE, kAppId, "YWKN74ODMf", "N0ed2C2h4n", kNoTtl), Eq(WPEFramework::Core::ERROR_NONE)); + ASSERT_THAT(store2->SetValue(IStore2::ScopeType::DEVICE, kAppId, kKey, kValue, kNoTtl), Eq(WPEFramework::Core::ERROR_INVALID_INPUT_LENGTH)); } diff --git a/PersistentStore/sqlite/l1test/StoreCacheTest.cpp b/PersistentStore/sqlite/l1test/StoreCacheTest.cpp deleted file mode 100644 index 5d2af5fd1d..0000000000 --- a/PersistentStore/sqlite/l1test/StoreCacheTest.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#include -#include - -#include "../StoreCache.h" - -using ::testing::Eq; -using ::testing::Test; -using ::WPEFramework::Exchange::IStoreCache; -using ::WPEFramework::Plugin::Sqlite::StoreCache; - -const auto kPath = "/tmp/persistentstore/sqlite/l1test/storecachetest"; - -class AStoreCache : public Test { -protected: - IStoreCache* cache; - AStoreCache() - : cache(WPEFramework::Core::Service::Create(kPath)) - { - } - ~AStoreCache() override - { - cache->Release(); - } -}; - -TEST_F(AStoreCache, FlushesCache) -{ - EXPECT_THAT(cache->FlushCache(), Eq(WPEFramework::Core::ERROR_NONE)); -} diff --git a/PersistentStore/sqlite/l1test/StoreInspectorTest.cpp b/PersistentStore/sqlite/l1test/StoreInspectorTest.cpp deleted file mode 100644 index ec3dd3866f..0000000000 --- a/PersistentStore/sqlite/l1test/StoreInspectorTest.cpp +++ /dev/null @@ -1,96 +0,0 @@ -#include -#include - -#include "../Store2.h" -#include "../StoreInspector.h" - -using ::testing::Eq; -using ::testing::IsFalse; -using ::testing::IsTrue; -using ::testing::NotNull; -using ::testing::Test; -using ::WPEFramework::Exchange::IStore2; -using ::WPEFramework::Exchange::IStoreInspector; -using ::WPEFramework::Plugin::Sqlite::Store2; -using ::WPEFramework::Plugin::Sqlite::StoreInspector; -using ::WPEFramework::RPC::IStringIterator; - -const auto kPath = "/tmp/persistentstore/sqlite/l1test/storeinspectortest"; -const auto kMaxSize = 100; -const auto kMaxValue = 10; -const auto kLimit = 50; -const auto kValue = "value_1"; -const auto kKey = "key_1"; -const auto kAppId = "app_id_1"; -const auto kNoTtl = 0; -const auto kScope = IStoreInspector::ScopeType::DEVICE; -const auto kUnknown = "unknown"; - -class AStoreInspector : public Test { -protected: - IStoreInspector* inspector; - AStoreInspector() - : inspector(WPEFramework::Core::Service::Create(kPath)) - { - } - ~AStoreInspector() override - { - inspector->Release(); - } -}; - -TEST_F(AStoreInspector, GetsKeysWhenNamespaceUnknown) -{ - IStringIterator* it; - ASSERT_THAT(inspector->GetKeys(kScope, kUnknown, it), Eq(WPEFramework::Core::ERROR_NONE)); - ASSERT_THAT(it, NotNull()); - string element; - EXPECT_THAT(it->Next(element), IsFalse()); - it->Release(); -} - -TEST_F(AStoreInspector, GetsKeys) -{ - auto store2 = WPEFramework::Core::Service::Create(kPath, kMaxSize, kMaxValue, kLimit); - ASSERT_THAT(store2->SetValue(kScope, kAppId, kKey, kValue, kNoTtl), Eq(WPEFramework::Core::ERROR_NONE)); - store2->Release(); - IStringIterator* it; - ASSERT_THAT(inspector->GetKeys(kScope, kAppId, it), Eq(WPEFramework::Core::ERROR_NONE)); - ASSERT_THAT(it, NotNull()); - string element; - ASSERT_THAT(it->Next(element), IsTrue()); - EXPECT_THAT(element, Eq(kKey)); - EXPECT_THAT(it->Next(element), IsFalse()); - it->Release(); -} - -TEST_F(AStoreInspector, GetsNamespaces) -{ - auto store2 = WPEFramework::Core::Service::Create(kPath, kMaxSize, kMaxValue, kLimit); - ASSERT_THAT(store2->SetValue(kScope, kAppId, kKey, kValue, kNoTtl), Eq(WPEFramework::Core::ERROR_NONE)); - store2->Release(); - IStringIterator* it; - ASSERT_THAT(inspector->GetNamespaces(kScope, it), Eq(WPEFramework::Core::ERROR_NONE)); - ASSERT_THAT(it, NotNull()); - string element; - ASSERT_THAT(it->Next(element), IsTrue()); - EXPECT_THAT(element, Eq(kAppId)); - EXPECT_THAT(it->Next(element), IsFalse()); - it->Release(); -} - -TEST_F(AStoreInspector, GetsStorageSizes) -{ - auto store2 = WPEFramework::Core::Service::Create(kPath, kMaxSize, kMaxValue, kLimit); - ASSERT_THAT(store2->SetValue(kScope, kAppId, kKey, kValue, kNoTtl), Eq(WPEFramework::Core::ERROR_NONE)); - store2->Release(); - IStoreInspector::INamespaceSizeIterator* it; - ASSERT_THAT(inspector->GetStorageSizes(kScope, it), Eq(WPEFramework::Core::ERROR_NONE)); - ASSERT_THAT(it, NotNull()); - IStoreInspector::NamespaceSize element; - ASSERT_THAT(it->Next(element), IsTrue()); - EXPECT_THAT(element.ns, Eq(kAppId)); - EXPECT_THAT(element.size, Eq(strlen(kKey) + strlen(kValue))); - EXPECT_THAT(it->Next(element), IsFalse()); - it->Release(); -} diff --git a/PersistentStore/sqlite/l1test/StoreLimitTest.cpp b/PersistentStore/sqlite/l1test/StoreLimitTest.cpp deleted file mode 100644 index 49409e91d3..0000000000 --- a/PersistentStore/sqlite/l1test/StoreLimitTest.cpp +++ /dev/null @@ -1,112 +0,0 @@ -#include -#include - -#include "../Store2.h" -#include "../StoreLimit.h" - -using ::testing::Eq; -using ::testing::Test; -using ::WPEFramework::Exchange::IStore2; -using ::WPEFramework::Exchange::IStoreLimit; -using ::WPEFramework::Plugin::Sqlite::Store2; -using ::WPEFramework::Plugin::Sqlite::StoreLimit; - -const auto kPath = "/tmp/persistentstore/sqlite/l1test/storelimittest"; -const auto kMaxSize = 100; -const auto kMaxValue = 10; -const auto kLimit = 50; -const auto kValue = "value_1"; -const auto kKey = "key_1"; -const auto kAppId = "app_id_1"; -const auto kNoTtl = 0; -const auto kScope = IStoreLimit::ScopeType::DEVICE; -const auto kEmpty = ""; -const auto kOversize = "this is too large"; -const auto kUnknown = "unknown"; -const auto kLimit20 = 20; -const auto kLimit30 = 30; -const auto kLimit40 = 40; - -class AStoreLimit : public Test { -protected: - IStoreLimit* limit; - AStoreLimit() - : limit(WPEFramework::Core::Service::Create(kPath, kMaxSize, kMaxValue)) - { - } - ~AStoreLimit() override - { - limit->Release(); - } -}; - -TEST_F(AStoreLimit, DoesNotGetNamespaceStorageLimitWhenNamespaceUnknown) -{ - uint32_t value; - EXPECT_THAT(limit->GetNamespaceStorageLimit(kScope, kUnknown, value), Eq(WPEFramework::Core::ERROR_NOT_EXIST)); -} - -TEST_F(AStoreLimit, DoesNotSetNamespaceStorageLimitWhenNamespaceEmpty) -{ - EXPECT_THAT(limit->SetNamespaceStorageLimit(kScope, kEmpty, kLimit20), Eq(WPEFramework::Core::ERROR_INVALID_INPUT_LENGTH)); -} - -TEST_F(AStoreLimit, DoesNotSetNamespaceStorageLimitWhenNamespaceOversize) -{ - EXPECT_THAT(limit->SetNamespaceStorageLimit(kScope, kOversize, kLimit20), Eq(WPEFramework::Core::ERROR_INVALID_INPUT_LENGTH)); -} - -TEST_F(AStoreLimit, SetsNamespaceStorageLimit) -{ - ASSERT_THAT(limit->SetNamespaceStorageLimit(kScope, kAppId, kLimit20), Eq(WPEFramework::Core::ERROR_NONE)); - uint32_t value; - ASSERT_THAT(limit->GetNamespaceStorageLimit(kScope, kAppId, value), Eq(WPEFramework::Core::ERROR_NONE)); - EXPECT_THAT(value, Eq(kLimit20)); -} - -TEST_F(AStoreLimit, SetsNamespaceStorageLimitWhenAlreadySet) -{ - ASSERT_THAT(limit->SetNamespaceStorageLimit(kScope, kAppId, kLimit30), Eq(WPEFramework::Core::ERROR_NONE)); - uint32_t value; - ASSERT_THAT(limit->GetNamespaceStorageLimit(kScope, kAppId, value), Eq(WPEFramework::Core::ERROR_NONE)); - EXPECT_THAT(value, Eq(kLimit30)); - ASSERT_THAT(limit->SetNamespaceStorageLimit(kScope, kAppId, kLimit40), Eq(WPEFramework::Core::ERROR_NONE)); - ASSERT_THAT(limit->GetNamespaceStorageLimit(kScope, kAppId, value), Eq(WPEFramework::Core::ERROR_NONE)); - EXPECT_THAT(value, Eq(kLimit40)); -} - -TEST_F(AStoreLimit, DoesNotSetNamespaceStorageLimitWhenReachedMaxSize) -{ - auto store2 = WPEFramework::Core::Service::Create(kPath, kMaxSize, kMaxValue, kLimit); - ASSERT_THAT(store2->DeleteNamespace(kScope, kAppId), Eq(WPEFramework::Core::ERROR_NONE)); - ASSERT_THAT(store2->SetValue(kScope, "8InMXXU4hM", "YWKN74ODMf", "N0ed2C2h4n", kNoTtl), Eq(WPEFramework::Core::ERROR_NONE)); - ASSERT_THAT(store2->SetValue(kScope, "XhrICnuerw", "jPKODBDk5K", "d3BarkA5xF", kNoTtl), Eq(WPEFramework::Core::ERROR_NONE)); - ASSERT_THAT(store2->SetValue(kScope, "WNeBknDDI2", "GC96ZN6Fuq", "IBF2E1MLQh", kNoTtl), Eq(WPEFramework::Core::ERROR_NONE)); - ASSERT_THAT(store2->SetValue(kScope, "V92", "R1R", "rHk", kNoTtl), Eq(WPEFramework::Core::ERROR_NONE)); - EXPECT_THAT(limit->SetNamespaceStorageLimit(kScope, kAppId, kLimit), Eq(WPEFramework::Core::ERROR_INVALID_INPUT_LENGTH)); - EXPECT_THAT(store2->DeleteNamespace(kScope, "8InMXXU4hM"), Eq(WPEFramework::Core::ERROR_NONE)); - EXPECT_THAT(store2->DeleteNamespace(kScope, "XhrICnuerw"), Eq(WPEFramework::Core::ERROR_NONE)); - EXPECT_THAT(store2->DeleteNamespace(kScope, "WNeBknDDI2"), Eq(WPEFramework::Core::ERROR_NONE)); - EXPECT_THAT(store2->DeleteNamespace(kScope, "V92"), Eq(WPEFramework::Core::ERROR_NONE)); - store2->Release(); -} - -TEST_F(AStoreLimit, EnforcesSetValueToFailWhenReachedDefaultLimit) -{ - auto store2 = WPEFramework::Core::Service::Create(kPath, kMaxSize, kMaxValue, kLimit); - ASSERT_THAT(store2->DeleteNamespace(kScope, kAppId), Eq(WPEFramework::Core::ERROR_NONE)); - ASSERT_THAT(store2->SetValue(kScope, kAppId, "YWKN74ODMf", "N0ed2C2h4n", kNoTtl), Eq(WPEFramework::Core::ERROR_NONE)); - ASSERT_THAT(store2->SetValue(kScope, kAppId, "jPKODBDk5K", "d3BarkA5xF", kNoTtl), Eq(WPEFramework::Core::ERROR_NONE)); - ASSERT_THAT(store2->SetValue(kScope, kAppId, kKey, kValue, kNoTtl), Eq(WPEFramework::Core::ERROR_INVALID_INPUT_LENGTH)); - store2->Release(); -} - -TEST_F(AStoreLimit, EnforcesSetValueToFailWhenReachedLimit) -{ - auto store2 = WPEFramework::Core::Service::Create(kPath, kMaxSize, kMaxValue, kLimit); - ASSERT_THAT(store2->DeleteNamespace(kScope, kAppId), Eq(WPEFramework::Core::ERROR_NONE)); - EXPECT_THAT(limit->SetNamespaceStorageLimit(kScope, kAppId, kLimit20), Eq(WPEFramework::Core::ERROR_NONE)); - ASSERT_THAT(store2->SetValue(kScope, kAppId, "YWKN74ODMf", "N0ed2C2h4n", kNoTtl), Eq(WPEFramework::Core::ERROR_NONE)); - ASSERT_THAT(store2->SetValue(kScope, kAppId, kKey, kValue, kNoTtl), Eq(WPEFramework::Core::ERROR_INVALID_INPUT_LENGTH)); - store2->Release(); -} diff --git a/RDKShell/RDKShell.cpp b/RDKShell/RDKShell.cpp index 7f91d6d311..cebb1f98c8 100755 --- a/RDKShell/RDKShell.cpp +++ b/RDKShell/RDKShell.cpp @@ -1063,7 +1063,7 @@ namespace WPEFramework { sem_wait(&request->mSemaphore); } gRdkShellMutex.lock(); - RdkShell::CompositorController::addListener(clientidentifier, mShell.mEventListener); + RdkShell::CompositorController::addListener(service->Callsign(), mShell.mEventListener); gRdkShellMutex.unlock(); gPluginDataMutex.lock(); std::string className = service->ClassName(); @@ -1269,7 +1269,7 @@ namespace WPEFramework { sem_wait(&request->mSemaphore); } gRdkShellMutex.lock(); - RdkShell::CompositorController::addListener(clientidentifier, mShell.mEventListener); + RdkShell::CompositorController::addListener(service->Callsign(), mShell.mEventListener); gRdkShellMutex.unlock(); gPluginDataMutex.lock(); std::string className = service->ClassName(); @@ -1366,7 +1366,7 @@ namespace WPEFramework { gRdkShellMutex.unlock(); sem_wait(&request->mSemaphore); gRdkShellMutex.lock(); - RdkShell::CompositorController::removeListener(clientidentifier, mShell.mEventListener); + RdkShell::CompositorController::removeListener(service->Callsign(), mShell.mEventListener); gRdkShellMutex.unlock(); } diff --git a/WebKitBrowser/BrowserConsoleLog.h b/WebKitBrowser/BrowserConsoleLog.h index 7017253d0c..1bc76276f5 100644 --- a/WebKitBrowser/BrowserConsoleLog.h +++ b/WebKitBrowser/BrowserConsoleLog.h @@ -37,7 +37,11 @@ class BrowserConsoleLog { BrowserConsoleLog(const string& prefix, const string& message, const uint64_t line, const uint64_t column) { _text = '[' + prefix + "][" + Core::NumberType(line).Text() + ',' + Core::NumberType(column).Text() + ']' + message; +#ifdef __CORE_MESSAGING__ + const uint16_t maxStringLength = Messaging::MessageUnit::DataSize - 1; +#else const uint16_t maxStringLength = Trace::TRACINGBUFFERSIZE - 1; +#endif if (_text.length() > maxStringLength) { _text = _text.substr(0, maxStringLength); } @@ -46,7 +50,11 @@ class BrowserConsoleLog { BrowserConsoleLog(const string& prefix, const WKStringRef message, const uint64_t line, const uint64_t column) { _text = '[' + prefix + "][" + Core::NumberType(line).Text() + ',' + Core::NumberType(column).Text() + ']' + WebKit::Utils::WKStringToString(message); +#ifdef __CORE_MESSAGING__ + const uint16_t maxStringLength = Messaging::MessageUnit::DataSize - 1; +#else const uint16_t maxStringLength = Trace::TRACINGBUFFERSIZE - 1; +#endif if (_text.length() > maxStringLength) { _text = _text.substr(0, maxStringLength); } diff --git a/WebKitBrowser/CookieJar.cpp b/WebKitBrowser/CookieJar.cpp index 432a9d6480..bb24c8da1c 100644 --- a/WebKitBrowser/CookieJar.cpp +++ b/WebKitBrowser/CookieJar.cpp @@ -106,7 +106,7 @@ static std::vector compress(const std::string& str) result[3] = (nbytes & 0x000000ff); break; case Z_MEM_ERROR: - TRACE_GLOBAL(Trace::Error,(_T("Z_MEM_ERROR: Not enough memory"))); + SYSLOG(Logging::Error,(_T("Z_MEM_ERROR: Not enough memory"))); result.resize(0); break; case Z_BUF_ERROR: @@ -126,7 +126,7 @@ static std::string uncompress(const std::vector& in) { if (nbytes < 4 || std::any_of(in.cbegin(), in.cend(), [](int v) {return v != 0;})) { - TRACE_GLOBAL(Trace::Error,(_T("Input data is corrupted"))); + SYSLOG(Logging::Error,(_T("Input data is corrupted"))); } return result; } @@ -146,11 +146,11 @@ static std::string uncompress(const std::vector& in) len *= 2; break; case Z_MEM_ERROR: - TRACE_GLOBAL(Trace::Error,(_T("Z_MEM_ERROR: Not enough memory"))); + SYSLOG(Logging::Error,(_T("Z_MEM_ERROR: Not enough memory"))); result.resize(0); break; case Z_DATA_ERROR: - TRACE_GLOBAL(Trace::Error,(_T("Z_DATA_ERROR: Input data is corrupted"))); + SYSLOG(Logging::Error,(_T("Z_DATA_ERROR: Input data is corrupted"))); result.resize(0); break; } @@ -201,7 +201,7 @@ struct CookieJar::CookieJarPrivate if (rc != Core::ERROR_NONE) { - TRACE_GLOBAL(Trace::Error,(_T("Encryption failed, rc = %u"), rc)); + SYSLOG(Logging::Error,(_T("Encryption failed, rc = %u"), rc)); } else { @@ -220,7 +220,7 @@ struct CookieJar::CookieJarPrivate if (rc != Core::ERROR_NONE) { - TRACE_GLOBAL(Trace::Error,(_T("Decryption failed, rc = %u"), rc)); + SYSLOG(Logging::Error,(_T("Decryption failed, rc = %u"), rc)); } else { @@ -232,7 +232,7 @@ struct CookieJar::CookieJarPrivate if (actualChecksum != checksum) { rc = Core::ERROR_GENERAL; - TRACE_GLOBAL(Trace::Error,(_T("Checksum does not match: actual=%d expected=%d"), actualChecksum, checksum)); + SYSLOG(Logging::Error,(_T("Checksum does not match: actual=%d expected=%d"), actualChecksum, checksum)); } else { diff --git a/WebKitBrowser/Extension/BridgeObject.cpp b/WebKitBrowser/Extension/BridgeObject.cpp index 2b83c507c3..06355b12c6 100644 --- a/WebKitBrowser/Extension/BridgeObject.cpp +++ b/WebKitBrowser/Extension/BridgeObject.cpp @@ -65,7 +65,7 @@ static void CallBridge(WebKitWebPage* page, const char* scriptSrc, WebKitUserMes gsize decodedLen = 0; gchar *decoded = reinterpret_cast(g_base64_decode(payloadPtr, &decodedLen)); if (g_utf8_validate(decoded, decodedLen, nullptr) == FALSE) { - TRACE_GLOBAL(Trace::Error, (_T("Decoded message is not a valid UTF8 string!"))); + SYSLOG(Logging::Error, (_T("Decoded message is not a valid UTF8 string!"))); gchar *tmp = decoded; #if GLIB_CHECK_VERSION(2, 52, 0) decoded = g_utf8_make_valid(tmp, decodedLen); diff --git a/WebKitBrowser/Extension/Module.h b/WebKitBrowser/Extension/Module.h index d56663c027..dfc4bb0983 100644 --- a/WebKitBrowser/Extension/Module.h +++ b/WebKitBrowser/Extension/Module.h @@ -25,7 +25,11 @@ #include #include +#ifdef __CORE_MESSAGING__ +#include +#else #include +#endif #undef EXTERNAL #define EXTERNAL diff --git a/WebKitBrowser/Extension/ProcessInfo.cpp b/WebKitBrowser/Extension/ProcessInfo.cpp index 999e072ee4..a561a3d9bc 100644 --- a/WebKitBrowser/Extension/ProcessInfo.cpp +++ b/WebKitBrowser/Extension/ProcessInfo.cpp @@ -40,9 +40,9 @@ void SetProcessName() #error("No implementation available to set process name on this platform") #endif if (0 != ret ) { - TRACE_GLOBAL(Trace::Error, (_T("Setting process name to '%s' FAILED with code %d\n"), processName.c_str(), ret)); + SYSLOG(Logging::Error, (_T("Setting process name to '%s' FAILED with code %d\n"), processName.c_str(), ret)); } else { - TRACE_GLOBAL(Trace::Error, (_T("Setting process name to '%s' SUCCESS\n"), processName.c_str())); + TRACE_GLOBAL(Trace::Information, (_T("Setting process name to '%s' SUCCESS\n"), processName.c_str())); } } diff --git a/WebKitBrowser/Extension/RequestHeaders.cpp b/WebKitBrowser/Extension/RequestHeaders.cpp index 257d9d7f08..3dad793d03 100644 --- a/WebKitBrowser/Extension/RequestHeaders.cpp +++ b/WebKitBrowser/Extension/RequestHeaders.cpp @@ -53,9 +53,9 @@ bool ParseHeaders(const string& json, Headers& out) } return true; } else { - TRACE_GLOBAL(Trace::Error, - (_T("Failed to parse headers array, error='%s', json='%s'\n"), - (error.IsSet() ? error.Value().Message().c_str() : "unknown"), json.c_str())); + SYSLOG(Logging::Error, + (_T("Failed to parse headers array, error='%s', json='%s'\n"), + (error.IsSet() ? error.Value().Message().c_str() : "unknown"), json.c_str())); } return false; diff --git a/WebKitBrowser/Extension/main.cpp b/WebKitBrowser/Extension/main.cpp index 5adf09e013..8f9ccd6531 100644 --- a/WebKitBrowser/Extension/main.cpp +++ b/WebKitBrowser/Extension/main.cpp @@ -78,7 +78,9 @@ static class PluginHost { : _engine(Core::ProxyType>::Create()) , _comClient(Core::ProxyType::Create(GetConnectionNode(), Core::ProxyType(_engine))) { +#if !defined(THUNDER_VERSION) || THUNDER_VERSION < 4 || (THUNDER_VERSION == 4 && defined(THUNDER_VERSION_MINOR) && THUNDER_VERSION_MINOR < 4) _engine->Announcements(_comClient->Announcement()); +#endif } ~PluginHost() { @@ -92,10 +94,14 @@ static class PluginHost { // We have something to report back, do so... uint32_t result = _comClient->Open(RPC::CommunicationTimeOut); if (result != Core::ERROR_NONE) { - TRACE(Trace::Error, (_T("Could not open connection to node %s. Error: %s"), _comClient->Source().RemoteId(), Core::NumberType(result).Text())); + SYSLOG(Logging::Error, (_T("Could not open connection to node %s. Error: %s"), _comClient->Source().RemoteId(), Core::NumberType(result).Text())); } else { // Due to the LXC container support all ID's get mapped. For the TraceBuffer, use the host given ID. +#ifdef __CORE_MESSAGING__ + Messaging::MessageUnit::Instance().Open(_comClient->ConnectionId()); +#else Trace::TraceUnit::Instance().Open(_comClient->ConnectionId()); +#endif /* __CORE_MESSAGING__ */ } _extension = WEBKIT_WEB_EXTENSION(g_object_ref(extension)); diff --git a/WebKitBrowser/LoggingUtils.cpp b/WebKitBrowser/LoggingUtils.cpp index 65fa91eeaa..d17a5e4156 100644 --- a/WebKitBrowser/LoggingUtils.cpp +++ b/WebKitBrowser/LoggingUtils.cpp @@ -38,6 +38,7 @@ bool RedirectAllLogsToService(const string& target_service) fprintf(stderr, "RedirectLog: Invalid argument. Logs target service expected\n"); return false; } + const string kServiceExt = ".service"; if (target_service.size() <= kServiceExt.size() || target_service.substr(target_service.size() - kServiceExt.size(), kServiceExt.size()) != kServiceExt) { @@ -45,10 +46,15 @@ bool RedirectAllLogsToService(const string& target_service) return false; } + const bool isCGroupV2 = g_file_test("/sys/fs/cgroup/unified", G_FILE_TEST_EXISTS); + const string targetHierarchy = isCGroupV2 ? "unified" : "systemd"; + const string targetPIDList = isCGroupV2 ? "cgroup.procs" : "tasks"; + const string targetServiceName = target_service.substr(0, target_service.size() - kServiceExt.size()); - const string kSystemdCgroupTargetTasksFilePath = "/sys/fs/cgroup/systemd/system.slice/" + target_service + "/tasks"; + const string kSystemdCgroupTargetTasksFilePath = "/sys/fs/cgroup/" + targetHierarchy + "/system.slice/" + target_service + "/" + targetPIDList; + if (!g_file_test(kSystemdCgroupTargetTasksFilePath.c_str(), G_FILE_TEST_EXISTS)) { - fprintf(stderr, "RedirectLog: %s unit cgroup doesn't exist\n", target_service.c_str()); + fprintf(stderr, "RedirectLog: %s doesn't exist for unit %s\n", kSystemdCgroupTargetTasksFilePath.c_str(), target_service.c_str()); return false; } @@ -57,10 +63,17 @@ bool RedirectAllLogsToService(const string& target_service) while (taskDir.Next() == true) { if (taskDir.Name() == "." || taskDir.Name() == "..") continue; + FILE* f = fopen(kSystemdCgroupTargetTasksFilePath.c_str(), "a"); if (f) { fprintf(f, "%s", taskDir.Name().c_str()); fclose(f); + + // In case of cgroup v2, it is enough to move just one task/thread + // to achieve migration of entire process + if (isCGroupV2) + break; + } else { fprintf(stderr, "RedirectLog: cannot move %s thread to '%s': %s\n", taskDir.Name().c_str(), kSystemdCgroupTargetTasksFilePath.c_str(), strerror(errno)); diff --git a/WebKitBrowser/Testing/Extension/testrunnerextension.cpp b/WebKitBrowser/Testing/Extension/testrunnerextension.cpp index f80e9a9c56..7b17dab732 100644 --- a/WebKitBrowser/Testing/Extension/testrunnerextension.cpp +++ b/WebKitBrowser/Testing/Extension/testrunnerextension.cpp @@ -50,7 +50,8 @@ static bool callEventListener(const std::string& eventName, JSCValue* event) g_warning("TestRunnerJS: Event listener %s not registered", eventName.c_str()); return false; } - jsc_value_function_call(it->second, JSC_TYPE_VALUE, event, G_TYPE_NONE); + JSCValue* ignore = jsc_value_function_call(it->second, JSC_TYPE_VALUE, event, G_TYPE_NONE); + g_object_unref(ignore); return true; } diff --git a/WebKitBrowser/TimeZone/TimeZoneSupport.cpp b/WebKitBrowser/TimeZone/TimeZoneSupport.cpp index 90af3d09ab..30771da9fa 100644 --- a/WebKitBrowser/TimeZone/TimeZoneSupport.cpp +++ b/WebKitBrowser/TimeZone/TimeZoneSupport.cpp @@ -54,7 +54,7 @@ namespace TZ { if (timeZone != tzSupport->_previousTimeZone) { tzSupport->_previousTimeZone = timeZone; timeZone = ":" + timeZone; - SYSLOG(Trace::Information, (_T("TimeZone is updated to \"%s\" from \"%s\" file"), timeZone.c_str(), tzSupport->_tzFile.c_str())); + SYSLOG(Logging::Notification, (_T("TimeZone is updated to \"%s\" from \"%s\" file"), timeZone.c_str(), tzSupport->_tzFile.c_str())); Core::SystemInfo::SetEnvironment(_T("TZ"), _T(timeZone), true); tzset(); } @@ -76,7 +76,7 @@ namespace TZ { void TimeZoneSupport::Initialize() { if(_tzFile.empty()) { - SYSLOG(Trace::Warning, (_T("Invalid file input for TZ update"))); + SYSLOG(Logging::Error, (_T("Invalid file input for TZ update"))); return; } @@ -89,7 +89,7 @@ namespace TZ { _timeZoneFileMonitor = g_file_monitor_file(file, G_FILE_MONITOR_NONE, nullptr, nullptr); _timeZoneFileMonitorId = g_signal_connect(_timeZoneFileMonitor, "changed", reinterpret_cast(HandleTimeZoneFileUpdate), this); - SYSLOG(Trace::Information, (_T("Installed file monitor for \"%s\""), _tzFile.c_str())); + SYSLOG(Logging::Notification, (_T("Installed file monitor for \"%s\""), _tzFile.c_str())); g_object_unref(file); } diff --git a/WebKitBrowser/TimeZone/TimeZoneSupport.h b/WebKitBrowser/TimeZone/TimeZoneSupport.h index 4fccc24d69..c65756ab8f 100644 --- a/WebKitBrowser/TimeZone/TimeZoneSupport.h +++ b/WebKitBrowser/TimeZone/TimeZoneSupport.h @@ -20,7 +20,7 @@ #ifndef __TIMEZONESUPPORTH #define __TIMEZONESUPPORTH -#include "Module.h" +#include "../Extension/Module.h" #include namespace WPEFramework { diff --git a/WebKitBrowser/WebKitBrowser.cpp b/WebKitBrowser/WebKitBrowser.cpp index f12ea5e40f..68850003aa 100644 --- a/WebKitBrowser/WebKitBrowser.cpp +++ b/WebKitBrowser/WebKitBrowser.cpp @@ -118,7 +118,6 @@ namespace Plugin { _cookieJar = _browser->QueryInterface(); if (_cookieJar) { _cookieJar->Register(&_notification); - Exchange::JBrowserCookieJar::Register(*this, _cookieJar); } _browserScripting = _browser->QueryInterface(); @@ -151,7 +150,6 @@ namespace Plugin { _browserScripting->Release(); } if (_cookieJar) { - Exchange::JBrowserCookieJar::Unregister(*this); _cookieJar->Unregister(&_notification); _cookieJar->Release(); } @@ -279,8 +277,13 @@ namespace Plugin { if (path.empty() == false) { string fullPath = _persistentStoragePath + path; Core::Directory dir(fullPath.c_str()); - if (!dir.Destroy(true)) { - TRACE(Trace::Error, (_T("Failed to delete %s\n"), fullPath.c_str())); +#if defined(THUNDER_VERSION) && THUNDER_VERSION >= 4 + bool success = dir.Destroy(); +#else + bool success = dir.Destroy(true); +#endif + if (!success) { + SYSLOG(Logging::Error, (_T("Failed to delete %s\n"), fullPath.c_str())); result = Core::ERROR_GENERAL; } } @@ -309,6 +312,7 @@ namespace Plugin { { string message(string("{ \"url\": \"") + URL + string("\", \"loaded\": ") + (loaded ? string("true") : string("false")) + string(" }")); TRACE(Trace::Information, (_T("URLChanged: %s"), message.c_str())); + _lastURL.assign(URL); _service->Notify(message); Exchange::JWebBrowser::Event::URLChange(*this, URL, loaded); } @@ -335,7 +339,7 @@ namespace Plugin { void WebKitBrowser::CookieJarChanged() { - Exchange::JBrowserCookieJar::Event::CookieJarChanged(*this); + Notify(_T("cookiejarchanged")); } void WebKitBrowser::StateChange(const PluginHost::IStateControl::state state) @@ -350,6 +354,8 @@ namespace Plugin { { if (connection->Id() == _connectionId) { + TRACE(Trace::Information, (_T("WebKitBrowser::Deactivated: { \"URL\": %.*s }"), 80, _lastURL.c_str())); + ASSERT(_service != nullptr); Core::IWorkerPool::Instance().Submit(PluginHost::IShell::Job::Create(_service, PluginHost::IShell::DEACTIVATED, PluginHost::IShell::FAILURE)); @@ -454,7 +460,11 @@ namespace WebKitBrowser { _children = Core::ProcessInfo::Iterator(_main.Id()); return ((_startTime == TimePoint::min()) || (_main.IsActive() == true) ? 1 : 0) + _children.Count(); } +#if defined(THUNDER_VERSION) && THUNDER_VERSION >= 4 + bool IsOperational() const override +#else const bool IsOperational() const override +#endif { uint32_t requiredProcesses = 0; diff --git a/WebKitBrowser/WebKitBrowser.h b/WebKitBrowser/WebKitBrowser.h index c2cad5f920..eeba30cc45 100644 --- a/WebKitBrowser/WebKitBrowser.h +++ b/WebKitBrowser/WebKitBrowser.h @@ -285,6 +285,7 @@ namespace Plugin { Core::Sink _notification; Core::ProxyPoolType> _jsonBodyDataFactory; string _persistentStoragePath; + string _lastURL; }; } } diff --git a/WebKitBrowser/WebKitImplementation.cpp b/WebKitBrowser/WebKitImplementation.cpp index 8d45555463..4a47622776 100644 --- a/WebKitBrowser/WebKitImplementation.cpp +++ b/WebKitBrowser/WebKitImplementation.cpp @@ -870,7 +870,6 @@ static GSourceFuncs _handlerIntervention = , _view(nullptr) , _guid(Core::Time::Now().Ticks()) , _httpCookieAcceptPolicy(WEBKIT_COOKIE_POLICY_ACCEPT_NO_THIRD_PARTY) - , _webprocessPID(-1) , _extensionPath() , _ignoreLoadFinishedOnce(false) #else @@ -1509,7 +1508,7 @@ static GSourceFuncs _handlerIntervention = if (error) { auto errorDomain = WKErrorCopyDomain(error); auto errorDescription = WKErrorCopyLocalizedDescription(error); - TRACE_GLOBAL(Trace::Error, + SYSLOG(Logging::Error, (_T("GetCookies failed, error(code=%d, domain=%s, message=%s)"), WKErrorGetErrorCode(error), WKStringToString(errorDomain).c_str(), @@ -1993,7 +1992,7 @@ static GSourceFuncs _handlerIntervention = Core::JSON::ArrayType array; if (!array.FromString(language, error)) { - TRACE(Trace::Error, + SYSLOG(Logging::Error, (_T("Failed to parse languages array, error='%s', array='%s'\n"), (error.IsSet() ? error.Value().Message().c_str() : "unknown"), language.c_str())); return Core::ERROR_GENERAL; @@ -2670,7 +2669,7 @@ static GSourceFuncs _handlerIntervention = static void loadFailedCallback(WebKitWebView*, WebKitLoadEvent loadEvent, const gchar* failingURI, GError* error, WebKitImplementation* browser) { string message(string("{ \"url\": \"") + failingURI + string("\", \"Error message\": \"") + error->message + string("\", \"loadEvent\":") + Core::NumberType(loadEvent).Text() + string(" }")); - SYSLOG(Trace::Information, (_T("LoadFailed: %s"), message.c_str())); + SYSLOG(Logging::Notification, (_T("LoadFailed: %s"), message.c_str())); if (g_error_matches(error, WEBKIT_NETWORK_ERROR, WEBKIT_NETWORK_ERROR_CANCELLED)) { browser->_ignoreLoadFinishedOnce = true; return; @@ -2681,13 +2680,13 @@ static GSourceFuncs _handlerIntervention = { switch (reason) { case WEBKIT_WEB_PROCESS_CRASHED: - SYSLOG(Trace::Fatal, (_T("CRASH: WebProcess crashed: exiting ..."))); + SYSLOG(Logging::Fatal, (_T("CRASH: WebProcess crashed: exiting ..."))); break; case WEBKIT_WEB_PROCESS_EXCEEDED_MEMORY_LIMIT: - SYSLOG(Trace::Fatal, (_T("CRASH: WebProcess terminated due to memory limit: exiting ..."))); + SYSLOG(Logging::Fatal, (_T("CRASH: WebProcess terminated due to memory limit: exiting ..."))); break; case WEBKIT_WEB_PROCESS_TERMINATED_BY_API: - SYSLOG(Trace::Fatal, (_T("CRASH: WebProcess terminated by API"))); + SYSLOG(Logging::Fatal, (_T("CRASH: WebProcess terminated by API"))); break; } g_signal_handlers_block_matched(webView, G_SIGNAL_MATCH_DATA, 0, 0, nullptr, nullptr, browser); @@ -2695,7 +2694,7 @@ static GSourceFuncs _handlerIntervention = { virtual void Dispatch() { exit(1); } }; - Core::IWorkerPool::Instance().Submit(Core::proxy_cast(Core::ProxyType::Create())); + Core::IWorkerPool::Instance().Submit(Core::ProxyType(Core::ProxyType::Create())); } static void closeCallback(VARIABLE_IS_NOT_USED WebKitWebView* webView, WebKitImplementation* browser) { @@ -2895,7 +2894,11 @@ static GSourceFuncs _handlerIntervention = } if (!_config.CertificateCheck) { +#if WEBKIT_CHECK_VERSION(2, 38, 0) + webkit_website_data_manager_set_tls_errors_policy(webkit_web_context_get_website_data_manager(wkContext), WEBKIT_TLS_ERRORS_POLICY_IGNORE); +#else webkit_web_context_set_tls_errors_policy(wkContext, WEBKIT_TLS_ERRORS_POLICY_IGNORE); +#endif } auto* languages = static_cast(g_new0(char*, _config.Languages.Length() + 1)); @@ -3330,7 +3333,7 @@ static GSourceFuncs _handlerIntervention = gchar* scriptContent; auto success = g_file_get_contents(path.c_str(), &scriptContent, nullptr, nullptr); if (!success) { - SYSLOG(Trace::Error, (_T("Unable to read user script '%s'"), path.c_str())); + SYSLOG(Logging::Error, (_T("Unable to read user script '%s'"), path.c_str())); return; } AddUserScriptImpl(scriptContent, false); @@ -3406,6 +3409,14 @@ static GSourceFuncs _handlerIntervention = #endif } + pid_t GetWebGetProcessIdentifier() { +#ifdef WEBKIT_GLIB_API + return webkit_web_view_get_web_process_identifier(_view); +#else + return WKPageGetProcessIdentifier(GetPage()); +#endif + } + void DidReceiveWebProcessResponsivenessReply(bool isWebProcessResponsive) { if (_config.WatchDogHangThresholdInSeconds.Value() == 0 || _config.WatchDogCheckTimeoutInSeconds.Value() == 0) @@ -3423,15 +3434,11 @@ static GSourceFuncs _handlerIntervention = if (isWebProcessResponsive && _unresponsiveReplyNum == 0) return; + pid_t webprocessPID = GetWebGetProcessIdentifier(); #ifdef WEBKIT_GLIB_API std::string activeURL(webkit_web_view_get_uri(_view)); - if (_webprocessPID == -1) { - _webprocessPID = webkit_web_view_get_web_process_identifier(_view); - } - pid_t webprocessPID = _webprocessPID; #else std::string activeURL = GetPageActiveURL(GetPage()); - pid_t webprocessPID = WKPageGetProcessIdentifier(GetPage()); #endif if (isWebProcessResponsive) { @@ -3453,7 +3460,7 @@ static GSourceFuncs _handlerIntervention = _unresponsiveReplyNum = kWebProcessUnresponsiveReplyDefaultLimit; Logging::DumpSystemFiles(webprocessPID); if (syscall(__NR_tgkill, webprocessPID, webprocessPID, SIGFPE) == -1) { - SYSLOG(Trace::Error, (_T("tgkill failed, signal=%d process=%u errno=%d (%s)"), SIGFPE, webprocessPID, errno, strerror(errno))); + SYSLOG(Logging::Error, (_T("tgkill failed, signal=%d process=%u errno=%d (%s)"), SIGFPE, webprocessPID, errno, strerror(errno))); } } else { DeactivateBrowser(PluginHost::IShell::FAILURE); @@ -3465,7 +3472,7 @@ static GSourceFuncs _handlerIntervention = Logging::DumpSystemFiles(webprocessPID); if (syscall(__NR_tgkill, webprocessPID, webprocessPID, SIGFPE) == -1) { - SYSLOG(Trace::Error, (_T("tgkill failed, signal=%d process=%u errno=%d (%s)"), SIGFPE, webprocessPID, errno, strerror(errno))); + SYSLOG(Logging::Error, (_T("tgkill failed, signal=%d process=%u errno=%d (%s)"), SIGFPE, webprocessPID, errno, strerror(errno))); } } else if (_unresponsiveReplyNum == (2 * kWebProcessUnresponsiveReplyDefaultLimit)) { DeactivateBrowser(PluginHost::IShell::WATCHDOG_EXPIRED); @@ -3519,7 +3526,6 @@ static GSourceFuncs _handlerIntervention = WebKitWebView* _view; uint64_t _guid; WebKitCookieAcceptPolicy _httpCookieAcceptPolicy; - pid_t _webprocessPID; string _extensionPath; bool _ignoreLoadFinishedOnce; #else @@ -3715,7 +3721,7 @@ static GSourceFuncs _handlerIntervention = string url = GetPageActiveURL(page); string message(string("{ \"url\": \"") + url + string("\", \"Error code\":") + Core::NumberType(errorcode).Text() + string(" }")); - SYSLOG(Trace::Information, (_T("LoadFailed: %s"), message.c_str())); + SYSLOG(Logging::Notification, (_T("LoadFailed: %s"), message.c_str())); bool isCanceled = errorDomain && @@ -3732,7 +3738,7 @@ static GSourceFuncs _handlerIntervention = /* static */ void webProcessDidCrash(WKPageRef, const void*) { - SYSLOG(Trace::Fatal, (_T("CRASH: WebProcess crashed, exiting..."))); + SYSLOG(Logging::Fatal, (_T("CRASH: WebProcess crashed, exiting..."))); exit(1); } diff --git a/XCast/XCast.cpp b/XCast/XCast.cpp index 6078a3034b..04c7ef52bf 100644 --- a/XCast/XCast.cpp +++ b/XCast/XCast.cpp @@ -107,6 +107,7 @@ bool XCast::m_standbyBehavior = false; bool XCast::m_enableStatus = false; IARM_Bus_PWRMgr_PowerState_t XCast::m_powerState = IARM_BUS_PWRMGR_POWERSTATE_STANDBY; +bool powerModeChangeActive = false; XCast::XCast() : PluginHost::JSONRPC() , m_apiVersionNumber(1), m_isDynamicRegistrationsRequired(false) @@ -224,6 +225,11 @@ const string XCast::Initialize(PluginHost::IShell *service) void XCast::Deinitialize(PluginHost::IShell* /* service */) { LOGINFO("XCast::Deinitialize called \n "); + int count = 0; + while(powerModeChangeActive && count < 20){ + sleep(100); + count++; + } if ( m_locateCastTimer.isActive()) { m_locateCastTimer.stop(); @@ -1140,6 +1146,7 @@ void XCast::onFriendlyNameUpdateHandler(const JsonObject& parameters) { void XCast::threadPowerModeChangeEvent(void) { + powerModeChangeActive = true; LOGINFO(" threadPowerModeChangeEvent m_standbyBehavior:%d , m_powerState:%d ",m_standbyBehavior,m_powerState); if(m_standbyBehavior == false) { @@ -1148,6 +1155,7 @@ void XCast::threadPowerModeChangeEvent(void) else _rtConnector->enableCastService(m_friendlyName,false); } + powerModeChangeActive = false; } diff --git a/docs/api/NetworkManagerPlugin.md b/docs/api/NetworkManagerPlugin.md new file mode 100644 index 0000000000..88b30ccfe1 --- /dev/null +++ b/docs/api/NetworkManagerPlugin.md @@ -0,0 +1,2104 @@ + + +# NetworkManager Plugin + +**Version: [0.1.0]()** + +A NetworkManager plugin for Thunder framework. + +### Table of Contents + +- [Abbreviation, Acronyms and Terms](#head.Abbreviation,_Acronyms_and_Terms) +- [Description](#head.Description) +- [Configuration](#head.Configuration) +- [Interfaces](#head.Interfaces) +- [Methods](#head.Methods) +- [Notifications](#head.Notifications) + + +# Abbreviation, Acronyms and Terms + +[[Refer to this link](userguide/aat.md)] + + +# Description + +A Unified `NetworkManager` plugin that allows you to manage Ethernet and Wifi interfaces on the device. + + The plugin is designed to be an out-of-process service to be handled by Thunder framework. For more information about the framework refer to [[Thunder](#ref.Thunder)]. + + +# Configuration + +The table below lists configuration options of the plugin. + +| Name | Type | Description | +| :-------- | :-------- | :-------- | +| callsign | string | Plugin instance name (default: *org.rdk.NetworkManager*) | +| classname | string | Class name: *NetworkManager* | +| locator | string | Library name: *libWPEFrameworkNetworkManager.so* | +| autostart | boolean | Determines if the plugin shall be started automatically along with the framework | + + +# Interfaces + +This plugin implements the following interfaces: + +- [NetworkManager.json](https://github.com/rdkcentral/ThunderInterfaces/blob/master/interfaces/NetworkManager.json) + + +# Methods + +The following methods are provided by the org.rdk.NetworkManager plugin: + +NetworkManager interface methods: + +| Method | Description | +| :-------- | :-------- | +| [GetAvailableInterfaces](#method.GetAvailableInterfaces) | Get device supported list of available interface including their state | +| [GetPrimaryInterface](#method.GetPrimaryInterface) | Gets the primary/default network interface for the device | +| [SetPrimaryInterface](#method.SetPrimaryInterface) | Sets the primary/default interface for the device | +| [GetIPSettings](#method.GetIPSettings) | Gets the IP setting for the given interface | +| [SetIPSettings](#method.SetIPSettings) | Sets the IP settings for the given interface | +| [GetStunEndpoint](#method.GetStunEndpoint) | Get the STUN Endpoint that is used to identify public IP of the device | +| [SetStunEndpoint](#method.SetStunEndpoint) | Set the STUN Endpoint to be used to identify public IP of the device | +| [GetConnectivityTestEndpoints](#method.GetConnectivityTestEndpoints) | Gets currently used test endpoints | +| [SetConnectivityTestEndpoints](#method.SetConnectivityTestEndpoints) | This method used to set up to 5 endpoints for a connectivity test | +| [IsConnectedToInternet](#method.IsConnectedToInternet) | Seeks Whether the device has internet connectivity | +| [GetCaptivePortalURI](#method.GetCaptivePortalURI) | Gets the captive portal URI if connected to any captive portal network | +| [StartConnectivityMonitoring](#method.StartConnectivityMonitoring) | Enable a continuous monitoring of internet connectivity with heart beat interval thats given | +| [StopConnectivityMonitoring](#method.StopConnectivityMonitoring) | Stops the connectivity monitoring | +| [GetPublicIP](#method.GetPublicIP) | Gets the internet/public IP Address of the device | +| [Ping](#method.Ping) | Pings the specified endpoint with the specified number of packets | +| [Trace](#method.Trace) | Traces the specified endpoint with the specified number of packets using `traceroute` | +| [StartWiFiScan](#method.StartWiFiScan) | Initiates WiFi scaning | +| [StopWiFiScan](#method.StopWiFiScan) | Stops WiFi scanning | +| [GetKnownSSIDs](#method.GetKnownSSIDs) | Gets list of saved SSIDs | +| [AddToKnownSSIDs](#method.AddToKnownSSIDs) | Saves the SSID, passphrase, and security mode for upcoming and future sessions | +| [RemoveKnownSSID](#method.RemoveKnownSSID) | Remove given SSID from saved SSIDs | +| [WiFiConnect](#method.WiFiConnect) | Initiates request to connect to the specified SSID with the given passphrase | +| [WiFiDisconnect](#method.WiFiDisconnect) | Disconnects from the currently connected SSID | +| [GetConnectedSSID](#method.GetConnectedSSID) | Returns the connected SSID information | +| [StartWPS](#method.StartWPS) | Initiates a connection using Wifi Protected Setup (WPS) | +| [StopWPS](#method.StopWPS) | Cancels the in-progress WPS pairing operation | +| [GetWiFiSignalStrength](#method.GetWiFiSignalStrength) | Get WiFiSignalStrength of connected SSID | +| [GetSupportedSecurityModes](#method.GetSupportedSecurityModes) | Returns the Wifi security modes that the device supports | +| [SetLogLevel](#method.SetLogLevel) | Set Log level for more information | +| [EnableInterface](#method.EnableInterface) | Enable the interface | +| [DisableInterface](#method.DisableInterface) | Disable the interface | +| [GetWifiState](#method.GetWifiState) | Returns the current Wifi State | + + + +## *GetAvailableInterfaces [method](#head.Methods)* + +Get device supported list of available interface including their state. + +### Events + +No Events + +### Parameters + +This method takes no parameters. + +### Result + +| Name | Type | Description | +| :-------- | :-------- | :-------- | +| result | object | | +| result?.Interfaces | array | *(optional)* An interface | +| result?.Interfaces[#] | object | *(optional)* | +| result?.Interfaces[#].type | string | Interface Type | +| result?.Interfaces[#].name | string | Interface Name. ex: eth0 or wlan0 | +| result?.Interfaces[#].mac | string | Interface MAC address | +| result?.Interfaces[#].isEnabled | boolean | Whether the interface is currently enabled | +| result?.Interfaces[#].isConnected | boolean | Whether the interface is currently connected | +| result.success | boolean | Whether the request succeeded | + +### Example + +#### Request + +```json +{ + "jsonrpc": "2.0", + "id": 42, + "method": "org.rdk.NetworkManager.GetAvailableInterfaces" +} +``` + +#### Response + +```json +{ + "jsonrpc": "2.0", + "id": 42, + "result": { + "Interfaces": [ + { + "type": "ETHERNET", + "name": "eth0", + "mac": "AA:AA:AA:AA:AA:AA", + "isEnabled": true, + "isConnected": true + } + ], + "success": true + } +} +``` + + +## *GetPrimaryInterface [method](#head.Methods)* + +Gets the primary/default network interface for the device. The active network interface is defined as the one that can make requests to the external network. Returns one of the supported interfaces as per `GetAvailableInterfaces`, or an empty value which indicates that there is no default network interface. + +### Events + +No Events + +### Parameters + +This method takes no parameters. + +### Result + +| Name | Type | Description | +| :-------- | :-------- | :-------- | +| result | object | | +| result.interface | string | An interface, such as `eth0` or `wlan0`, depending upon availability of the given interface | + +### Example + +#### Request + +```json +{ + "jsonrpc": "2.0", + "id": 42, + "method": "org.rdk.NetworkManager.GetPrimaryInterface" +} +``` + +#### Response + +```json +{ + "jsonrpc": "2.0", + "id": 42, + "result": { + "interface": "wlan0" + } +} +``` + + +## *SetPrimaryInterface [method](#head.Methods)* + +Sets the primary/default interface for the device. This call fails if the interface is not enabled. + +### Events + +| Event | Description | +| :-------- | :-------- | +| [onActiveInterfaceChange](#event.onActiveInterfaceChange) | Triggered when device’s default interface changed. | +| [onInterfaceStateChange](#event.onInterfaceStateChange) | Triggered when interface’s state changed | +| [onAddressChange](#event.onAddressChange) | Triggered when the device connects to router. | +| [onInternetStatusChange](#event.onInternetStatusChange) | Triggered when each IP address is lost or acquired. | +### Parameters + +| Name | Type | Description | +| :-------- | :-------- | :-------- | +| params | object | | +| params.interface | string | An interface, such as `eth0` or `wlan0`, depending upon availability of the given interface | + +### Result + +| Name | Type | Description | +| :-------- | :-------- | :-------- | +| result | object | | +| result.success | boolean | Whether the request succeeded | + +### Example + +#### Request + +```json +{ + "jsonrpc": "2.0", + "id": 42, + "method": "org.rdk.NetworkManager.SetPrimaryInterface", + "params": { + "interface": "wlan0" + } +} +``` + +#### Response + +```json +{ + "jsonrpc": "2.0", + "id": 42, + "result": { + "success": true + } +} +``` + + +## *GetIPSettings [method](#head.Methods)* + +Gets the IP setting for the given interface. + +### Events + +No Events + +### Parameters + +| Name | Type | Description | +| :-------- | :-------- | :-------- | +| params | object | | +| params.interface | string | An interface, such as `eth0` or `wlan0`, depending upon availability of the given interface | +| params?.ipversion | string | *(optional)* either IPv4 or IPv6 | + +### Result + +| Name | Type | Description | +| :-------- | :-------- | :-------- | +| result | object | | +| result.interface | string | An interface, such as `eth0` or `wlan0`, depending upon availability of the given interface | +| result.ipversion | string | either IPv4 or IPv6 | +| result.autoconfig | boolean | `true` if DHCP is used, `false` if IP is configured manually | +| result?.dhcpserver | string | *(optional)* The DHCP Server address | +| result.ipaddress | string | The IP address | +| result.prefix | integer | The prefix number | +| result.gateway | string | The gateway address | +| result.v6LinkLocal | string | The v6LinkLocal | +| result.primarydns | string | The primary DNS address | +| result.secondarydns | string | The secondary DNS address | +| result.success | boolean | Whether the request succeeded | + +### Example + +#### Request + +```json +{ + "jsonrpc": "2.0", + "id": 42, + "method": "org.rdk.NetworkManager.GetIPSettings", + "params": { + "interface": "wlan0", + "ipversion": "IPv4" + } +} +``` + +#### Response + +```json +{ + "jsonrpc": "2.0", + "id": 42, + "result": { + "interface": "wlan0", + "ipversion": "IPv4", + "autoconfig": true, + "dhcpserver": "192.168.1.1", + "ipaddress": "192.168.1.101", + "prefix": 24, + "gateway": "192.168.1.1", + "v6LinkLocal": "192.168.1.1", + "primarydns": "192.168.1.1", + "secondarydns": "192.168.1.2", + "success": true + } +} +``` + + +## *SetIPSettings [method](#head.Methods)* + +Sets the IP settings for the given interface. + +### Events + +| Event | Description | +| :-------- | :-------- | +| [onAddressChange](#event.onAddressChange) | Triggered when the device connects to router. | +| [onInternetStatusChange](#event.onInternetStatusChange) | Triggered when each IP address is lost or acquired. | +### Parameters + +| Name | Type | Description | +| :-------- | :-------- | :-------- | +| params | object | | +| params.interface | string | An interface, such as `eth0` or `wlan0`, depending upon availability of the given interface | +| params.ipversion | string | either IPv4 or IPv6 | +| params.autoconfig | boolean | `true` if DHCP is used, `false` if IP is configured manually | +| params.ipaddress | string | The IP address | +| params.prefix | integer | The prefix number | +| params.gateway | string | The gateway address | +| params.primarydns | string | The primary DNS address | +| params.secondarydns | string | The secondary DNS address | + +### Result + +| Name | Type | Description | +| :-------- | :-------- | :-------- | +| result | object | | +| result.success | boolean | Whether the request succeeded | + +### Example + +#### Request + +```json +{ + "jsonrpc": "2.0", + "id": 42, + "method": "org.rdk.NetworkManager.SetIPSettings", + "params": { + "interface": "wlan0", + "ipversion": "IPv4", + "autoconfig": true, + "ipaddress": "192.168.1.101", + "prefix": 24, + "gateway": "192.168.1.1", + "primarydns": "192.168.1.1", + "secondarydns": "192.168.1.2" + } +} +``` + +#### Response + +```json +{ + "jsonrpc": "2.0", + "id": 42, + "result": { + "success": true + } +} +``` + + +## *GetStunEndpoint [method](#head.Methods)* + +Get the STUN Endpoint that is used to identify public IP of the device. + +### Events + +No Events + +### Parameters + +This method takes no parameters. + +### Result + +| Name | Type | Description | +| :-------- | :-------- | :-------- | +| result | object | | +| result.endPoint | string | STUN server endPoint | +| result.port | integer | STUN server port | +| result.bindTimeout | integer | STUN server bind timeout | +| result.cacheTimeout | integer | STUN server cache timeout | +| result.success | boolean | Whether the request succeeded | + +### Example + +#### Request + +```json +{ + "jsonrpc": "2.0", + "id": 42, + "method": "org.rdk.NetworkManager.GetStunEndpoint" +} +``` + +#### Response + +```json +{ + "jsonrpc": "2.0", + "id": 42, + "result": { + "endPoint": "stun.l.google.com", + "port": 3478, + "bindTimeout": 30, + "cacheTimeout": 0, + "success": true + } +} +``` + + +## *SetStunEndpoint [method](#head.Methods)* + +Set the STUN Endpoint to be used to identify public IP of the device. + +### Events + +No Events + +### Parameters + +| Name | Type | Description | +| :-------- | :-------- | :-------- | +| params | object | | +| params.endPoint | string | STUN server endPoint | +| params.port | integer | STUN server port | +| params?.bindTimeout | integer | *(optional)* STUN server bind timeout | +| params?.cacheTimeout | integer | *(optional)* STUN server cache timeout | + +### Result + +| Name | Type | Description | +| :-------- | :-------- | :-------- | +| result | object | | +| result.success | boolean | Whether the request succeeded | + +### Example + +#### Request + +```json +{ + "jsonrpc": "2.0", + "id": 42, + "method": "org.rdk.NetworkManager.SetStunEndpoint", + "params": { + "endPoint": "stun.l.google.com", + "port": 3478, + "bindTimeout": 30, + "cacheTimeout": 0 + } +} +``` + +#### Response + +```json +{ + "jsonrpc": "2.0", + "id": 42, + "result": { + "success": true + } +} +``` + + +## *GetConnectivityTestEndpoints [method](#head.Methods)* + +Gets currently used test endpoints. on success list out the connectivity test points connections. + +### Events + +No Events + +### Parameters + +This method takes no parameters. + +### Result + +| Name | Type | Description | +| :-------- | :-------- | :-------- | +| result | object | | +| result.endpoints | array | | +| result.endpoints[#] | string | | +| result.success | boolean | Whether the request succeeded | + +### Example + +#### Request + +```json +{ + "jsonrpc": "2.0", + "id": 42, + "method": "org.rdk.NetworkManager.GetConnectivityTestEndpoints" +} +``` + +#### Response + +```json +{ + "jsonrpc": "2.0", + "id": 42, + "result": { + "endpoints": [ + "http://clients3.google.com/generate_204" + ], + "success": true + } +} +``` + + +## *SetConnectivityTestEndpoints [method](#head.Methods)* + +This method used to set up to 5 endpoints for a connectivity test. Successful connections are verified with HTTP Status code 204 (No Content). + +### Events + +No Events + +### Parameters + +| Name | Type | Description | +| :-------- | :-------- | :-------- | +| params | object | | +| params.endpoints | array | A list of endpoints to test | +| params.endpoints[#] | string | | + +### Result + +| Name | Type | Description | +| :-------- | :-------- | :-------- | +| result | object | | +| result.success | boolean | Whether the request succeeded | + +### Example + +#### Request + +```json +{ + "jsonrpc": "2.0", + "id": 42, + "method": "org.rdk.NetworkManager.SetConnectivityTestEndpoints", + "params": { + "endpoints": [ + "http://clients3.google.com/generate_204" + ] + } +} +``` + +#### Response + +```json +{ + "jsonrpc": "2.0", + "id": 42, + "result": { + "success": true + } +} +``` + + +## *IsConnectedToInternet [method](#head.Methods)* + +Seeks Whether the device has internet connectivity. This API might take up to 3s to validate internet connectivity. + +### Events + +No Events + +### Parameters + +| Name | Type | Description | +| :-------- | :-------- | :-------- | +| params | object | | +| params.ipversion | string | either IPv4 or IPv6 | + +### Result + +| Name | Type | Description | +| :-------- | :-------- | :-------- | +| result | object | | +| result.isConnectedToInternet | boolean | `true` if internet connectivity is detected, otherwise `false` | +| result.internetState | integer | The internet state | +| result.success | boolean | Whether the request succeeded | + +### Example + +#### Request + +```json +{ + "jsonrpc": "2.0", + "id": 42, + "method": "org.rdk.NetworkManager.IsConnectedToInternet", + "params": { + "ipversion": "IPv4" + } +} +``` + +#### Response + +```json +{ + "jsonrpc": "2.0", + "id": 42, + "result": { + "isConnectedToInternet": true, + "internetState": 4, + "success": true + } +} +``` + + +## *GetCaptivePortalURI [method](#head.Methods)* + +Gets the captive portal URI if connected to any captive portal network. + +### Events + +No Events + +### Parameters + +This method takes no parameters. + +### Result + +| Name | Type | Description | +| :-------- | :-------- | :-------- | +| result | object | | +| result.uri | string | Captive portal URI | +| result.success | boolean | Whether the request succeeded | + +### Example + +#### Request + +```json +{ + "jsonrpc": "2.0", + "id": 42, + "method": "org.rdk.NetworkManager.GetCaptivePortalURI" +} +``` + +#### Response + +```json +{ + "jsonrpc": "2.0", + "id": 42, + "result": { + "uri": "http://10.0.0.1/captiveportal.jst", + "success": true + } +} +``` + + +## *StartConnectivityMonitoring [method](#head.Methods)* + +Enable a continuous monitoring of internet connectivity with heart beat interval thats given. If the monitoring is already happening, it will be restarted with new given interval. + +### Events + +| Event | Description | +| :-------- | :-------- | +| [onInternetStatusChange](#event.onInternetStatusChange) | Triggered when internet connection state changed. | +### Parameters + +| Name | Type | Description | +| :-------- | :-------- | :-------- | +| params | object | | +| params.interval | number | Interval in sec | + +### Result + +| Name | Type | Description | +| :-------- | :-------- | :-------- | +| result | object | | +| result.success | boolean | Whether the request succeeded | + +### Example + +#### Request + +```json +{ + "jsonrpc": "2.0", + "id": 42, + "method": "org.rdk.NetworkManager.StartConnectivityMonitoring", + "params": { + "interval": 30 + } +} +``` + +#### Response + +```json +{ + "jsonrpc": "2.0", + "id": 42, + "result": { + "success": true + } +} +``` + + +## *StopConnectivityMonitoring [method](#head.Methods)* + +Stops the connectivity monitoring. + +### Events + +No Events + +### Parameters + +This method takes no parameters. + +### Result + +| Name | Type | Description | +| :-------- | :-------- | :-------- | +| result | object | | +| result.success | boolean | Whether the request succeeded | + +### Example + +#### Request + +```json +{ + "jsonrpc": "2.0", + "id": 42, + "method": "org.rdk.NetworkManager.StopConnectivityMonitoring" +} +``` + +#### Response + +```json +{ + "jsonrpc": "2.0", + "id": 42, + "result": { + "success": true + } +} +``` + + +## *GetPublicIP [method](#head.Methods)* + +Gets the internet/public IP Address of the device. + +### Events + +No Events + +### Parameters + +| Name | Type | Description | +| :-------- | :-------- | :-------- | +| params | object | it allows empty parameter too | +| params.ipversion | string | either IPv4 or IPv6 | + +### Result + +| Name | Type | Description | +| :-------- | :-------- | :-------- | +| result | object | | +| result.publicIP | string | Returns an public ip of the device | +| result.success | boolean | Whether the request succeeded | + +### Example + +#### Request + +```json +{ + "jsonrpc": "2.0", + "id": 42, + "method": "org.rdk.NetworkManager.GetPublicIP", + "params": { + "ipversion": "IPv4" + } +} +``` + +#### Response + +```json +{ + "jsonrpc": "2.0", + "id": 42, + "result": { + "publicIP": "69.136.49.95", + "success": true + } +} +``` + + +## *Ping [method](#head.Methods)* + +Pings the specified endpoint with the specified number of packets. + +### Events + +No Events + +### Parameters + +| Name | Type | Description | +| :-------- | :-------- | :-------- | +| params | object | | +| params.endpoint | string | The host name or IP address | +| params.ipversion | string | either IPv4 or IPv6 | +| params.noOfRequest | integer | The number of packets to send. Default is 15 | +| params.timeout | integer | Timeout | +| params.guid | string | The globally unique identifier | + +### Result + +| Name | Type | Description | +| :-------- | :-------- | :-------- | +| result | object | | +| result.target | string | The target IP address | +| result.packetsTransmitted | integer | The number of packets sent | +| result.packetsReceived | integer | The number of packets received | +| result.packetLoss | string | The number of packets lost | +| result.tripMin | string | The minimum amount of time to receive the packets | +| result.tripAvg | string | The average time to receive the packets | +| result.tripMax | string | The maximum amount of time to receive the packets | +| result.tripStdDev | string | The standard deviation for the trip | +| result.error | string | An error message | +| result.guid | string | The globally unique identifier | +| result.success | boolean | Whether the request succeeded | + +### Example + +#### Request + +```json +{ + "jsonrpc": "2.0", + "id": 42, + "method": "org.rdk.NetworkManager.Ping", + "params": { + "endpoint": "45.57.221.20", + "ipversion": "IPv4", + "noOfRequest": 10, + "timeout": 30, + "guid": "..." + } +} +``` + +#### Response + +```json +{ + "jsonrpc": "2.0", + "id": 42, + "result": { + "target": "45.57.221.20", + "packetsTransmitted": 10, + "packetsReceived": 10, + "packetLoss": "0.0", + "tripMin": "61.264", + "tripAvg": "130.397", + "tripMax": "230.832", + "tripStdDev": "80.919", + "error": "...", + "guid": "...", + "success": true + } +} +``` + + +## *Trace [method](#head.Methods)* + +Traces the specified endpoint with the specified number of packets using `traceroute`. + +### Events + +No Events + +### Parameters + +| Name | Type | Description | +| :-------- | :-------- | :-------- | +| params | object | | +| params.endpoint | string | The host name or IP address | +| params.ipversion | string | either IPv4 or IPv6 | +| params.noOfRequest | integer | The number of packets to send. Default is 15 | +| params.guid | string | The globally unique identifier | + +### Result + +| Name | Type | Description | +| :-------- | :-------- | :-------- | +| result | object | | +| result.target | string | The target IP address | +| result.packetsTransmitted | integer | The number of packets sent | +| result.packetsReceived | integer | The number of packets received | +| result.packetLoss | string | The number of packets lost | +| result.tripMin | string | The minimum amount of time to receive the packets | +| result.tripAvg | string | The average time to receive the packets | +| result.tripMax | string | The maximum amount of time to receive the packets | +| result.tripStdDev | string | The standard deviation for the trip | +| result.error | string | An error message | +| result.guid | string | The globally unique identifier | +| result.success | boolean | Whether the request succeeded | + +### Example + +#### Request + +```json +{ + "jsonrpc": "2.0", + "id": 42, + "method": "org.rdk.NetworkManager.Trace", + "params": { + "endpoint": "45.57.221.20", + "ipversion": "IPv4", + "noOfRequest": 10, + "guid": "..." + } +} +``` + +#### Response + +```json +{ + "jsonrpc": "2.0", + "id": 42, + "result": { + "target": "45.57.221.20", + "packetsTransmitted": 10, + "packetsReceived": 10, + "packetLoss": "0.0", + "tripMin": "61.264", + "tripAvg": "130.397", + "tripMax": "230.832", + "tripStdDev": "80.919", + "error": "...", + "guid": "...", + "success": true + } +} +``` + + +## *StartWiFiScan [method](#head.Methods)* + +Initiates WiFi scaning. This method supports scanning for specific range of frequency like 2.4GHz only or 5GHz only or 6GHz only or ALL. When no input passed about the frequency to be scanned, it scans for all. It publishes 'onAvailableSSIDs' event upon completion. + +### Events + +| Event | Description | +| :-------- | :-------- | +| [onAvailableSSIDs](#event.onAvailableSSIDs) | Triggered when list of SSIDs is available after the scan completes. | +### Parameters + +| Name | Type | Description | +| :-------- | :-------- | :-------- | +| params | object | | +| params.frequency | string | The frequency to scan. An empty or `null` value scans all frequencies. If a frequency is specified (2.4 or 5.0), then the results are only returned for matching frequencies | + +### Result + +| Name | Type | Description | +| :-------- | :-------- | :-------- | +| result | object | | +| result.success | boolean | Whether the request succeeded | + +### Example + +#### Request + +```json +{ + "jsonrpc": "2.0", + "id": 42, + "method": "org.rdk.NetworkManager.StartWiFiScan", + "params": { + "frequency": "..." + } +} +``` + +#### Response + +```json +{ + "jsonrpc": "2.0", + "id": 42, + "result": { + "success": true + } +} +``` + + +## *StopWiFiScan [method](#head.Methods)* + +Stops WiFi scanning. Any discovered SSIDs from the call to the `StartWiFiScan` method up to the point where this method is called are still returned as event. + +### Events + +No Events + +### Parameters + +This method takes no parameters. + +### Result + +| Name | Type | Description | +| :-------- | :-------- | :-------- | +| result | object | | +| result.success | boolean | Whether the request succeeded | + +### Example + +#### Request + +```json +{ + "jsonrpc": "2.0", + "id": 42, + "method": "org.rdk.NetworkManager.StopWiFiScan" +} +``` + +#### Response + +```json +{ + "jsonrpc": "2.0", + "id": 42, + "result": { + "success": true + } +} +``` + + +## *GetKnownSSIDs [method](#head.Methods)* + +Gets list of saved SSIDs. This method returns all the SSIDs that are saved as array. + +### Events + +No Events + +### Parameters + +This method takes no parameters. + +### Result + +| Name | Type | Description | +| :-------- | :-------- | :-------- | +| result | object | | +| result.ssids | array | Known SSIDS | +| result.ssids[#] | string | | +| result.success | boolean | Whether the request succeeded | + +### Example + +#### Request + +```json +{ + "jsonrpc": "2.0", + "id": 42, + "method": "org.rdk.NetworkManager.GetKnownSSIDs" +} +``` + +#### Response + +```json +{ + "jsonrpc": "2.0", + "id": 42, + "result": { + "ssids": [ + "Xfinity_Guest" + ], + "success": true + } +} +``` + + +## *AddToKnownSSIDs [method](#head.Methods)* + +Saves the SSID, passphrase, and security mode for upcoming and future sessions. This method only adds to the persistent memory; does not disconnect from currently connected SSID. + +### Events + +No Events + +### Parameters + +| Name | Type | Description | +| :-------- | :-------- | :-------- | +| params | object | | +| params.ssid | string | The paired SSID | +| params.passphrase | string | The access point password | +| params.securityMode | integer | The security mode. See `getSupportedSecurityModes` | + +### Result + +| Name | Type | Description | +| :-------- | :-------- | :-------- | +| result | object | | +| result.success | boolean | Whether the request succeeded | + +### Example + +#### Request + +```json +{ + "jsonrpc": "2.0", + "id": 42, + "method": "org.rdk.NetworkManager.AddToKnownSSIDs", + "params": { + "ssid": "123412341234", + "passphrase": "password", + "securityMode": 6 + } +} +``` + +#### Response + +```json +{ + "jsonrpc": "2.0", + "id": 42, + "result": { + "success": true + } +} +``` + + +## *RemoveKnownSSID [method](#head.Methods)* + +Remove given SSID from saved SSIDs. This method just removes from the list and of the list is having only one entry thats being removed, it will initiate a disconnect. + +### Events + +| Event | Description | +| :-------- | :-------- | +| [onWiFiStateChange](#event.onWiFiStateChange) | Triggered when Wifi state changes to DISCONNECTED | +| [onAddressChange](#event.onAddressChange) | Triggered when an IP Address is assigned or lost | +| [onInternetStatusChange](#event.onInternetStatusChange) | Triggered when internet connection state changed | +### Parameters + +| Name | Type | Description | +| :-------- | :-------- | :-------- | +| params | object | | +| params.ssid | string | The paired SSID | + +### Result + +| Name | Type | Description | +| :-------- | :-------- | :-------- | +| result | object | | +| result.success | boolean | Whether the request succeeded | + +### Example + +#### Request + +```json +{ + "jsonrpc": "2.0", + "id": 42, + "method": "org.rdk.NetworkManager.RemoveKnownSSID", + "params": { + "ssid": "123412341234" + } +} +``` + +#### Response + +```json +{ + "jsonrpc": "2.0", + "id": 42, + "result": { + "success": true + } +} +``` + + +## *WiFiConnect [method](#head.Methods)* + +Initiates request to connect to the specified SSID with the given passphrase. Passphrase can be `null` when the network security is `NONE`. When called with no arguments, this method attempts to connect to the saved SSID and password. See `AddToKnownSSIDs`. + +### Events + +| Event | Description | +| :-------- | :-------- | +| [onWiFiStateChange](#event.onWiFiStateChange) | Triggered when Wifi state changes to CONNECTING, CONNECTED . | +### Parameters + +| Name | Type | Description | +| :-------- | :-------- | :-------- | +| params | object | | +| params.ssid | string | The paired SSID | +| params.passphrase | string | The access point password | +| params.securityMode | integer | The security mode. See `getSupportedSecurityModes` | + +### Result + +| Name | Type | Description | +| :-------- | :-------- | :-------- | +| result | object | | +| result.success | boolean | Whether the request succeeded | + +### Example + +#### Request + +```json +{ + "jsonrpc": "2.0", + "id": 42, + "method": "org.rdk.NetworkManager.WiFiConnect", + "params": { + "ssid": "123412341234", + "passphrase": "password", + "securityMode": 6 + } +} +``` + +#### Response + +```json +{ + "jsonrpc": "2.0", + "id": 42, + "result": { + "success": true + } +} +``` + + +## *WiFiDisconnect [method](#head.Methods)* + +Disconnects from the currently connected SSID. A event will be posted upon completion. + +### Events + +| Event | Description | +| :-------- | :-------- | +| [onWIFIStateChange](#event.onWIFIStateChange) | Triggered when Wifi state changes to DISCONNECTED (only if currently connected). | +| [onAddressChange](#event.onAddressChange) | Triggered when an IP Address is assigned or lost | +| [onInternetStatusChange](#event.onInternetStatusChange) | Triggered when internet connection state changed | +### Parameters + +This method takes no parameters. + +### Result + +| Name | Type | Description | +| :-------- | :-------- | :-------- | +| result | object | | +| result.success | boolean | Whether the request succeeded | + +### Example + +#### Request + +```json +{ + "jsonrpc": "2.0", + "id": 42, + "method": "org.rdk.NetworkManager.WiFiDisconnect" +} +``` + +#### Response + +```json +{ + "jsonrpc": "2.0", + "id": 42, + "result": { + "success": true + } +} +``` + + +## *GetConnectedSSID [method](#head.Methods)* + +Returns the connected SSID information. + +### Events + +No Events + +### Parameters + +This method takes no parameters. + +### Result + +| Name | Type | Description | +| :-------- | :-------- | :-------- | +| result | object | | +| result.ssid | string | The paired SSID | +| result.bssid | string | The paired BSSID | +| result.securityMode | string | The security mode. See the `connect` method | +| result.signalStrength | string | The RSSI value in dBm | +| result.frequency | string | The supported frequency for this SSID in GHz | +| result.rate | string | The physical data rate in Mbps | +| result.noise | string | The average noise strength in dBm | +| result.success | boolean | Whether the request succeeded | + +### Example + +#### Request + +```json +{ + "jsonrpc": "2.0", + "id": 42, + "method": "org.rdk.NetworkManager.GetConnectedSSID" +} +``` + +#### Response + +```json +{ + "jsonrpc": "2.0", + "id": 42, + "result": { + "ssid": "123412341234", + "bssid": "ff:ff:ff:ff:ff:ff", + "securityMode": "5", + "signalStrength": "-27.000000", + "frequency": "2.442000", + "rate": "144.000000", + "noise": "-121.000000", + "success": true + } +} +``` + + +## *StartWPS [method](#head.Methods)* + +Initiates a connection using Wifi Protected Setup (WPS). An existing connection will be disconnected before attempting to initiate a new connection. Failure in WPS pairing will trigger an error event. + +If the `method` parameter is set to `SERIALIZED_PIN`, then RDK retrieves the serialized pin using the Manufacturer (MFR) API. If the `method` parameter is set to `PIN`, then RDK use the pin supplied as part of the request. If the `method` parameter is set to `PBC`, then RDK uses Push Button Configuration (PBC) to obtain the pin. + +### Events + +| Event | Description | +| :-------- | :-------- | +| [onWIFIStateChange](#event.onWIFIStateChange) | Triggered when Wifi state changes to DISCONNECTED (only if currently connected), CONNECTING, CONNECTED. | +| [onAddressChange](#event.onAddressChange) | Triggered when an IP Address is assigned or lost | +| [onInternetStatusChange](#event.onInternetStatusChange) | Triggered when internet connection state changed | +### Parameters + +| Name | Type | Description | +| :-------- | :-------- | :-------- | +| params | object | | +| params.method | integer | The method used to obtain the pin (must be one of the following: PBC=0, PIN=1, SERIALIZED_PIN=2) | +| params.wps_pin | string | A valid 8 digit WPS pin number. Use this parameter when the `method` parameter is set to `PIN` | + +### Result + +| Name | Type | Description | +| :-------- | :-------- | :-------- | +| result | object | | +| result?.pin | string | *(optional)* The WPS pin value. Valid only when `method` is set to `PIN` or `SERIALIZED_PIN` | +| result.success | boolean | Whether the request succeeded | + +### Example + +#### Request + +```json +{ + "jsonrpc": "2.0", + "id": 42, + "method": "org.rdk.NetworkManager.StartWPS", + "params": { + "method": 1, + "wps_pin": "88888888" + } +} +``` + +#### Response + +```json +{ + "jsonrpc": "2.0", + "id": 42, + "result": { + "pin": "88888888", + "success": true + } +} +``` + + +## *StopWPS [method](#head.Methods)* + +Cancels the in-progress WPS pairing operation. The operation forcefully stops the in-progress pairing attempt and aborts the current scan. WPS pairing must be in-progress for the operation to succeed. + +### Events + +| Event | Description | +| :-------- | :-------- | +| [onWIFIStateChange](#event.onWIFIStateChange) | Triggered when Wifi state changes to DISCONNECTED. | +### Parameters + +This method takes no parameters. + +### Result + +| Name | Type | Description | +| :-------- | :-------- | :-------- | +| result | object | | +| result.success | boolean | Whether the request succeeded | + +### Example + +#### Request + +```json +{ + "jsonrpc": "2.0", + "id": 42, + "method": "org.rdk.NetworkManager.StopWPS" +} +``` + +#### Response + +```json +{ + "jsonrpc": "2.0", + "id": 42, + "result": { + "success": true + } +} +``` + + +## *GetWiFiSignalStrength [method](#head.Methods)* + +Get WiFiSignalStrength of connected SSID. + +### Events + +| Event | Description | +| :-------- | :-------- | +| [onWiFiSignalStrengthChange](#event.onWiFiSignalStrengthChange) | Triggered when Wifi signal strength switches between Excellent, Good, Fair, Weak. | +### Parameters + +This method takes no parameters. + +### Result + +| Name | Type | Description | +| :-------- | :-------- | :-------- | +| result | object | | +| result.ssid | string | The paired SSID | +| result.signalStrength | string | The RSSI value in dBm | +| result.quality | integer | Signal strength Quality | +| result.success | boolean | Whether the request succeeded | + +### Example + +#### Request + +```json +{ + "jsonrpc": "2.0", + "id": 42, + "method": "org.rdk.NetworkManager.GetWiFiSignalStrength" +} +``` + +#### Response + +```json +{ + "jsonrpc": "2.0", + "id": 42, + "result": { + "ssid": "123412341234", + "signalStrength": "-27.000000", + "quality": 123, + "success": true + } +} +``` + + +## *GetSupportedSecurityModes [method](#head.Methods)* + +Returns the Wifi security modes that the device supports. + +### Events + +No Events + +### Parameters + +This method takes no parameters. + +### Result + +| Name | Type | Description | +| :-------- | :-------- | :-------- | +| result | object | | +| result.security_modes | object | The supported security modes and its associated integer value | +| result.security_modes?.NET_WIFI_SECURITY_NONE | integer | *(optional)* | +| result.security_modes?.NET_WIFI_SECURITY_WEP_64 | integer | *(optional)* | +| result.security_modes?.NET_WIFI_SECURITY_WEP_128 | integer | *(optional)* | +| result.security_modes?.NET_WIFI_SECURITY_WPA_PSK_TKIP | integer | *(optional)* | +| result.security_modes?.NET_WIFI_SECURITY_WPA_PSK_AES | integer | *(optional)* | +| result.security_modes?.NET_WIFI_SECURITY_WPA2_PSK_TKIP | integer | *(optional)* | +| result.security_modes?.NET_WIFI_SECURITY_WPA2_PSK_AES | integer | *(optional)* | +| result.security_modes?.NET_WIFI_SECURITY_WPA_ENTERPRISE_TKIP | integer | *(optional)* | +| result.security_modes?.NET_WIFI_SECURITY_WPA_ENTERPRISE_AES | integer | *(optional)* | +| result.security_modes?.NET_WIFI_SECURITY_WPA2_ENTERPRISE_TKIP | integer | *(optional)* | +| result.security_modes?.NET_WIFI_SECURITY_WPA2_ENTERPRISE_AES | integer | *(optional)* | +| result.security_modes?.NET_WIFI_SECURITY_WPA_WPA2_PSK | integer | *(optional)* | +| result.security_modes?.NET_WIFI_SECURITY_WPA_WPA2_ENTERPRISE | integer | *(optional)* | +| result.security_modes?.NET_WIFI_SECURITY_WPA3_PSK_AES | integer | *(optional)* | +| result.security_modes?.NET_WIFI_SECURITY_WPA3_SAE | integer | *(optional)* | +| result.success | boolean | Whether the request succeeded | + +### Example + +#### Request + +```json +{ + "jsonrpc": "2.0", + "id": 42, + "method": "org.rdk.NetworkManager.GetSupportedSecurityModes" +} +``` + +#### Response + +```json +{ + "jsonrpc": "2.0", + "id": 42, + "result": { + "security_modes": { + "NET_WIFI_SECURITY_NONE": 0, + "NET_WIFI_SECURITY_WEP_64": 1, + "NET_WIFI_SECURITY_WEP_128": 2, + "NET_WIFI_SECURITY_WPA_PSK_TKIP": 3, + "NET_WIFI_SECURITY_WPA_PSK_AES": 4, + "NET_WIFI_SECURITY_WPA2_PSK_TKIP": 5, + "NET_WIFI_SECURITY_WPA2_PSK_AES": 6, + "NET_WIFI_SECURITY_WPA_ENTERPRISE_TKIP": 7, + "NET_WIFI_SECURITY_WPA_ENTERPRISE_AES": 8, + "NET_WIFI_SECURITY_WPA2_ENTERPRISE_TKIP": 9, + "NET_WIFI_SECURITY_WPA2_ENTERPRISE_AES": 10, + "NET_WIFI_SECURITY_WPA_WPA2_PSK": 11, + "NET_WIFI_SECURITY_WPA_WPA2_ENTERPRISE": 12, + "NET_WIFI_SECURITY_WPA3_PSK_AES": 13, + "NET_WIFI_SECURITY_WPA3_SAE": 14 + }, + "success": true + } +} +``` + + +## *SetLogLevel [method](#head.Methods)* + +Set Log level for more information. The possible set log level are as follows. +* `0`: FATAL +* `1`: ERROR +* `2`: WARNING +* `3`: INFO +* `4`: VERBOSE +* `5`: TRACE +. + +### Events + +No Events + +### Parameters + +| Name | Type | Description | +| :-------- | :-------- | :-------- | +| params | object | | +| params.loglevel | integer | Set Log level to get more information | + +### Result + +| Name | Type | Description | +| :-------- | :-------- | :-------- | +| result | object | | +| result.success | boolean | Whether the request succeeded | + +### Example + +#### Request + +```json +{ + "jsonrpc": "2.0", + "id": 42, + "method": "org.rdk.NetworkManager.SetLogLevel", + "params": { + "loglevel": 1 + } +} +``` + +#### Response + +```json +{ + "jsonrpc": "2.0", + "id": 42, + "result": { + "success": true + } +} +``` + + +## *EnableInterface [method](#head.Methods)* + +Enable the specified interface. + +### Events + +| Event | Description | +| :-------- | :-------- | +| [onInterfaceStateChange](#event.onInterfaceStateChange) | Triggered when interface’s status changes to enabled. | + +### Parameters + +| Name | Type | Description | +| :-------- | :-------- | :-------- | +| params | object | | +| params.interface | string | An interface, such as `eth0` or `wlan0`, depending upon availability of the given interface in `GetAvailableInterfaces` | + +### Result + +| Name | Type | Description | +| :-------- | :-------- | :-------- | +| result | object | | +| result.success | boolean | Whether the request succeeded | + +### Example + +#### Request + +```json +{ + "jsonrpc": "2.0", + "id": 42, + "method": "org.rdk.NetworkManager.EnableInterface", + "params": { + "interface": "wlan0" + } +} +``` + +#### Response + +```json +{ + "jsonrpc": "2.0", + "id": 42, + "result": { + "success": true + } +} +``` + + +## *DisableInterface [method](#head.Methods)* + +Disable the specified interface. + +### Events + +| Event | Description | +| :-------- | :-------- | +| [onInterfaceStateChange](#event.onInterfaceStateChange) | Triggered when interface’s status changes to disabled. | + +### Parameters + +| Name | Type | Description | +| :-------- | :-------- | :-------- | +| params | object | | +| params.interface | string | An interface, such as `eth0` or `wlan0`, depending upon availability of the given interface in `GetAvailableInterfaces` | + +### Result + +| Name | Type | Description | +| :-------- | :-------- | :-------- | +| result | object | | +| result.success | boolean | Whether the request succeeded | + +### Example + +#### Request + +```json +{ + "jsonrpc": "2.0", + "id": 42, + "method": "org.rdk.NetworkManager.DisableInterface", + "params": { + "interface": "wlan0" + } +} +``` + +#### Response + +```json +{ + "jsonrpc": "2.0", + "id": 42, + "result": { + "success": true + } +} +``` + + +## *GetWifiState [method](#head.Methods)* + +Returns the current Wifi State. The possible Wifi states are as follows. +* `0`: UNINSTALLED - The device was in an installed state and was uninstalled; or, the device does not have a Wifi radio installed +* `1`: DISABLED - The device is installed but not yet enabled +* `2`: DISCONNECTED - The device is installed and enabled, but not yet connected to a network +* `3`: PAIRING - The device is in the process of pairing, but not yet connected to a network +* `4`: CONNECTING - The device is attempting to connect to a network +* `5`: CONNECTED - The device is successfully connected to a network +* `6`: SSID_NOT_FOUND - The requested SSID to connect is not found +* `7`: SSID_CHANGED - The device connected SSID is changed +* `8`: CONNECTION_LOST - The device network connection is lost +* `9`: CONNECTION_FAILED - The device network connection got failed +* `10`: CONNECTION_INTERRUPTED - The device connection is interrupted +* `11`: INVALID_CREDENTIALS - The credentials provided to connect is not valid +* `12`: AUTHENTICATION_FAILED - Authentication process as a whole could not be successfully completed +* `13`: ERROR - The device has encountered an unrecoverable error with the Wifi adapter + +### Events + +No Events + +### Parameters + +This method takes no parameters. + +### Result + +| Name | Type | Description | +| :-------- | :-------- | :-------- | +| result | object | | +| result.state | integer | The Wifi operational state | +| result.success | boolean | Whether the request succeeded | + +### Example + +#### Request + +```json +{ + "jsonrpc": "2.0", + "id": 42, + "method": "org.rdk.Wifi.GetWifiState" +} +``` + +#### Response + +```json +{ + "jsonrpc": "2.0", + "id": 42, + "result": { + "state": 2, + "success": true + } +} +``` + + +# Notifications + +Notifications are autonomous events, triggered by the internals of the implementation, and broadcasted via JSON-RPC to all registered observers. Refer to [[Thunder](#ref.Thunder)] for information on how to register for a notification. + +The following events are provided by the org.rdk.NetworkManager plugin: + +NetworkManager interface events: + +| Event | Description | +| :-------- | :-------- | +| [onInterfaceStateChange](#event.onInterfaceStateChange) | Triggered when an interface state is changed | +| [onAddressChange](#event.onAddressChange) | Triggered when an IP Address is assigned or lost | +| [onActiveInterfaceChange](#event.onActiveInterfaceChange) | Triggered when the primary/active interface changes, regardless if it's from a system operation or through the `SetPrimaryInterface` method | +| [onInternetStatusChange](#event.onInternetStatusChange) | Triggered when internet connection state changed | +| [onAvailableSSIDs](#event.onAvailableSSIDs) | Triggered when scan completes or when scan cancelled | +| [onWiFiStateChange](#event.onWiFiStateChange) | Triggered when WIFI connection state get changed | +| [onWiFiSignalStrengthChange](#event.onWiFiSignalStrengthChange) | Triggered when WIFI connection Signal Strength get changed | + + + +## *onInterfaceStateChange [event](#head.Notifications)* + +Triggered when an interface state is changed. The possible states are +* 'INTERFACE_ADDED' +* 'INTERFACE_LINK_UP' +* 'INTERFACE_LINK_DOWN' +* 'INTERFACE_ACQUIRING_IP' +* 'INTERFACE_REMOVED' +* 'INTERFACE_DISABLED' +. + +### Parameters + +| Name | Type | Description | +| :-------- | :-------- | :-------- | +| params | object | | +| params.interface | string | An interface, such as `eth0` or `wlan0`, depending upon availability of the given interface | +| params.state | string | Current state of the interface | + +### Example + +```json +{ + "jsonrpc": "2.0", + "method": "client.events.onInterfaceStateChange", + "params": { + "interface": "wlan0", + "state": "INTERFACE_ADDED" + } +} +``` + + +## *onAddressChange [event](#head.Notifications)* + +Triggered when an IP Address is assigned or lost. + +### Parameters + +| Name | Type | Description | +| :-------- | :-------- | :-------- | +| params | object | | +| params.interface | string | An interface, such as `eth0` or `wlan0`, depending upon availability of the given interface | +| params.isIPv6 | boolean | It will be true if the IP address is IPv6 | +| params.ipAddress | string | The IPv6 or IPv4 address for the interface | +| params.status | string | Whether IP address was acquired or lost (must be one of the following: 'ACQUIRED', 'LOST') (must be one of the following: *`ACQUIRED`*, *`LOST`*) | + +### Example + +```json +{ + "jsonrpc": "2.0", + "method": "client.events.onAddressChange", + "params": { + "interface": "wlan0", + "isIPv6": false, + "ipAddress": "192.168.1.100", + "status": "ACQUIRED" + } +} +``` + + +## *onActiveInterfaceChange [event](#head.Notifications)* + +Triggered when the primary/active interface changes, regardless if it's from a system operation or through the `SetPrimaryInterface` method. + +### Parameters + +| Name | Type | Description | +| :-------- | :-------- | :-------- | +| params | object | | +| params.oldInterfaceName | string | The previous interface that was changed | +| params.newInterfaceName | string | The current interface | + +### Example + +```json +{ + "jsonrpc": "2.0", + "method": "client.events.onActiveInterfaceChange", + "params": { + "oldInterfaceName": "wlan0", + "newInterfaceName": "eth0" + } +} +``` + + +## *onInternetStatusChange [event](#head.Notifications)* + +Triggered when internet connection state changed.The possible internet connection status are `NO_INTERNET`, `LIMITED_INTERNET`, `CAPTIVE_PORTAL`, `FULLY_CONNECTED`. + +### Parameters + +| Name | Type | Description | +| :-------- | :-------- | :-------- | +| params | object | | +| params.PrevState | integer | The privious internet connection state | +| params.PrevStatus | string | The previous internet connection status | +| params.state | integer | The internet connection state | +| params.status | string | The internet connection status | + +### Example + +```json +{ + "jsonrpc": "2.0", + "method": "client.events.onInternetStatusChange", + "params": { + "PrevState": 1, + "PrevStatus": "NO_INTERNET", + "state": 4, + "status": "FULLY_CONNECTED" + } +} +``` + + +## *onAvailableSSIDs [event](#head.Notifications)* + +Triggered when scan completes or when scan cancelled. + +### Parameters + +| Name | Type | Description | +| :-------- | :-------- | :-------- | +| params | object | | +| params.ssids | array | On Available SSID's | +| params.ssids[#] | object | | +| params.ssids[#].ssid | string | ssid | +| params.ssids[#].security | integer | security | +| params.ssids[#].signalStrength | string | signalStrength | +| params.ssids[#].frequency | string | frequency | + +### Example + +```json +{ + "jsonrpc": "2.0", + "method": "client.events.onAvailableSSIDs", + "params": { + "ssids": [ + { + "ssid": "myAP-2.4", + "security": 6, + "signalStrength": "-27.000000", + "frequency": "2.442000" + } + ] + } +} +``` + + +## *onWiFiStateChange [event](#head.Notifications)* + +Triggered when WIFI connection state get changed. The possible states are, + * '0' - 'WIFI_STATE_UNINSTALLED' + * '1' - 'WIFI_STATE_DISABLED' + * '2' - 'WIFI_STATE_DISCONNECTED' + * '3' - 'WIFI_STATE_PAIRING' + * '4' - 'WIFI_STATE_CONNECTING' + * '5' - 'WIFI_STATE_CONNECTED' + * '6' - 'WIFI_STATE_SSID_NOT_FOUND' + * '7' - 'WIFI_STATE_SSID_CHANGED' + * '8' - 'WIFI_STATE_CONNECTION_LOST' + * '9' - 'WIFI_STATE_CONNECTION_FAILED' + * '10'- 'WIFI_STATE_CONNECTION_INTERRUPTED' + * '11' - 'WIFI_STATE_INVALID_CREDENTIALS' + * '12' - 'WIFI_STATE_AUTHENTICATION_FAILED' + * '13' - 'WIFI_STATE_ERROR' +. + +### Parameters + +| Name | Type | Description | +| :-------- | :-------- | :-------- | +| params | object | | +| params.state | integer | onWiFiStateChange | + +### Example + +```json +{ + "jsonrpc": "2.0", + "method": "client.events.onWiFiStateChange", + "params": { + "state": 5 + } +} +``` + + +## *onWiFiSignalStrengthChange [event](#head.Notifications)* + +Triggered when WIFI connection Signal Strength get changed. + +### Parameters + +| Name | Type | Description | +| :-------- | :-------- | :-------- | +| params | object | | +| params.ssid | string | Signal Strength changed SSID | +| params.signalLevel | string | Signal Strength | +| params.signalQuality | string | Signal quality | + +### Example + +```json +{ + "jsonrpc": "2.0", + "method": "client.events.onWiFiSignalStrengthChange", + "params": { + "ssid": "home-new_123", + "signalLevel": "-27.000000", + "signalQuality": "Excellent" + } +} +``` +