Skip to content

Commit

Permalink
Cleanup versions support in RDKServices
Browse files Browse the repository at this point in the history
  • Loading branch information
anand-ky committed Dec 6, 2020
1 parent 46f9a7a commit 3692632
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 38 deletions.
19 changes: 5 additions & 14 deletions Bluetooth/Bluetooth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
// For example, the exposed "startScan" method is mapped to "startScanWrapper()" and that one calls to "startDeviceDiscovery()" internally,
// which finally calls to "BTRMGR_StartDeviceDiscovery()" in Bluetooth Manager.

const short WPEFramework::Plugin::Bluetooth::API_VERSION_NUMBER_MAJOR = 1; // corresponds to org.rdk.Bluetooth_5
const short WPEFramework::Plugin::Bluetooth::API_VERSION_NUMBER_MAJOR = 2; // corresponds to org.rdk.Bluetooth_5
const short WPEFramework::Plugin::Bluetooth::API_VERSION_NUMBER_MINOR = 0;
const string WPEFramework::Plugin::Bluetooth::SERVICE_NAME = "org.rdk.Bluetooth";
const string WPEFramework::Plugin::Bluetooth::METHOD_START_SCAN = "startScan";
Expand Down Expand Up @@ -132,15 +132,13 @@ namespace WPEFramework
}

Bluetooth::Bluetooth()
: AbstractPlugin()
: AbstractPlugin(Bluetooth::API_VERSION_NUMBER_MAJOR) // pass the current supported version
, m_apiVersionNumber(API_VERSION_NUMBER_MAJOR)
, m_discoveryRunning(false)
, m_discoveryTimer(this)
{
LOGINFO();

Core::JSONRPC::Handler& systemVersion_2 = JSONRPC::CreateHandler({ 2 }, *this);

Bluetooth::_instance = this;
registerMethod(METHOD_GET_API_VERSION_NUMBER, &Bluetooth::getApiVersionNumber, this);
registerMethod(METHOD_START_SCAN, &Bluetooth::startScanWrapper, this);
Expand All @@ -165,8 +163,9 @@ namespace WPEFramework
registerMethod(METHOD_GET_AUDIO_INFO, &Bluetooth::getMediaTrackInfoWrapper, this);
registerMethod(METHOD_GET_STATUS_SUPPORT, &Bluetooth::getStatusSupportWrapper, this);

systemVersion_2.Register<JsonObject, JsonObject>(METHOD_SET_PROPERTIES, &Bluetooth::setPropertiesWrapper, this);
systemVersion_2.Register<JsonObject, JsonObject>(METHOD_GET_PROPERTIES, &Bluetooth::getPropertiesWrapper, this);
//version 2 APIs
registerMethod(METHOD_SET_PROPERTIES, &Bluetooth::setPropertiesWrapper, this, {2});
registerMethod(METHOD_GET_PROPERTIES, &Bluetooth::getPropertiesWrapper, this, {2});

BTRMGR_Result_t rc = BTRMGR_RESULT_SUCCESS;
rc = BTRMGR_Init();
Expand All @@ -183,14 +182,6 @@ namespace WPEFramework
{
LOGINFO();

Core::JSONRPC::Handler* systemVersion_2 = JSONRPC::GetHandler(2);
if (systemVersion_2) {
systemVersion_2->Unregister(METHOD_SET_PROPERTIES);
systemVersion_2->Unregister(METHOD_GET_PROPERTIES);
}
else
LOGERR("Failed to get handler for version 2");

Bluetooth::_instance = nullptr;

if (m_executionThread.joinable())
Expand Down
22 changes: 5 additions & 17 deletions SystemServices/SystemServices.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,11 +248,9 @@ namespace WPEFramework {
* Register SystemService module as wpeframework plugin
*/
SystemServices::SystemServices()
: AbstractPlugin()
: AbstractPlugin(2)
, m_cacheService(SYSTEM_SERVICE_SETTINGS_FILE)
{
Core::JSONRPC::Handler& systemVersion_2 = JSONRPC::CreateHandler({ 2 }, *this);

SystemServices::_instance = this;

//Initialise timer with interval and callback function.
Expand Down Expand Up @@ -358,26 +356,16 @@ namespace WPEFramework {
registerMethod("getNetworkStandbyMode", &SystemServices::getNetworkStandbyMode, this);
registerMethod("getPowerStateIsManagedByDevice", &SystemServices::getPowerStateIsManagedByDevice, this);

systemVersion_2.Register<JsonObject, JsonObject>(_T("getTimeZones"), &SystemServices::getTimeZones, this);
// version 2 APIs
registerMethod(_T("getTimeZones"), &SystemServices::getTimeZones, this, {2});
#ifdef ENABLE_DEEP_SLEEP
systemVersion_2.Register<JsonObject, JsonObject>(_T("getWakeupReason"),&SystemServices::getWakeupReason, this);
registerMethod(_T("getWakeupReason"),&SystemServices::getWakeupReason, this, {2});
#endif
systemVersion_2.Register<JsonObject, JsonObject>("uploadLogs", &SystemServices::uploadLogs, this);
registerMethod("uploadLogs", &SystemServices::uploadLogs, this, {2});
}

SystemServices::~SystemServices()
{
Core::JSONRPC::Handler* systemVersion_2 = JSONRPC::GetHandler(2);
if (systemVersion_2) {
systemVersion_2->Unregister("getTimeZones");
#ifdef ENABLE_DEEP_SLEEP
systemVersion_2->Unregister("getWakeupReason");
#endif
systemVersion_2->Unregister("uploadLogs");
}
else
LOGERR("Failed to get handler for version 2");

SystemServices::_instance = nullptr;
}

Expand Down
52 changes: 45 additions & 7 deletions helpers/AbstractPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

#pragma once

//#include "Module.h"
#include <unordered_map>

namespace WPEFramework {

Expand Down Expand Up @@ -54,26 +54,63 @@ namespace WPEFramework {
//End methods

protected:

//registerMethod to register a method in all versions
template <typename METHOD, typename REALOBJECT>
void registerMethod(const string& methodName, const METHOD& method, REALOBJECT* objectPtr)
{
Register(methodName, method, objectPtr);
m_registeredMethods.push_back(methodName);
for(uint8_t ver = 1; ver <= m_currVersion; ver++)
{
auto handler = m_versionHandlers.find(ver);
if(handler != m_versionHandlers.end())
handler->second->Register<WPEFramework::Core::JSON::VariantContainer, WPEFramework::Core::JSON::VariantContainer, METHOD, REALOBJECT>(methodName, method, objectPtr);
}
}

//registerMethod to register a method in specific versions
template <typename METHOD, typename REALOBJECT>
void registerMethod(const string& methodName, const METHOD& method, REALOBJECT* objectPtr, const std::vector<uint8_t> versions)
{
for(auto ver : versions)
{
auto handler = m_versionHandlers.find(ver);
if(handler != m_versionHandlers.end())
handler->second->Register<WPEFramework::Core::JSON::VariantContainer, WPEFramework::Core::JSON::VariantContainer, METHOD, REALOBJECT>(methodName, method, objectPtr);
}
}

public:
AbstractPlugin() : PluginHost::JSONRPC()
AbstractPlugin() : PluginHost::JSONRPC(), m_currVersion(1)
{
LOGINFO();

// For default constructor assume that only version 1 is supported.
// Also version 1 handler would always be the current object.
m_versionHandlers[1] = GetHandler(1);

registerMethod("getQuirks", &AbstractPlugin::getQuirks, this);
}

virtual ~AbstractPlugin()
AbstractPlugin(const uint8_t currVersion) : PluginHost::JSONRPC(), m_currVersion(currVersion)
{
LOGINFO();

for (auto& i : m_registeredMethods) { Unregister(i); }
// Create handlers for all the versions upto m_currVersion
m_versionHandlers[1] = GetHandler(1);
for(uint8_t i = 2; i <= m_currVersion; i++)
{
std::vector<uint8_t> vec;
vec.push_back(i);
CreateHandler(vec);
m_versionHandlers[i] = GetHandler(i);
}

registerMethod("getQuirks", &AbstractPlugin::getQuirks, this);
}

virtual ~AbstractPlugin()
{
LOGINFO();
}

//Build QueryInterface implementation, specifying all possible interfaces to be returned.
Expand Down Expand Up @@ -101,7 +138,8 @@ namespace WPEFramework {
return(string());
}
private:
std::vector<std::string> m_registeredMethods;
std::unordered_map<uint8_t, WPEFramework::Core::JSONRPC::Handler*> m_versionHandlers;
uint8_t m_currVersion; // current supported version
};
} // namespace Plugin
} // namespace WPEFramework

0 comments on commit 3692632

Please sign in to comment.