Skip to content

Commit 3a9fe45

Browse files
RDK-53913: Fixed the event subscription failure in Controller and Network plugins
Signed-off-by: yuvaramachandran_gurusamy <[email protected]>
1 parent e13fd37 commit 3a9fe45

File tree

4 files changed

+65
-50
lines changed

4 files changed

+65
-50
lines changed

XCast/XCast.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,12 @@ const string XCast::Initialize(PluginHost::IShell *service)
315315
ASSERT(_connectionId != 0);
316316
#endif
317317

318+
auto configConnection = _xcast->QueryInterface<Exchange::IConfiguration>();
319+
if (configConnection != nullptr) {
320+
configConnection->Configure(_service);
321+
configConnection->Release();
322+
}
323+
318324
PluginHost::IStateControl* stateControl(_xcast->QueryInterface<PluginHost::IStateControl>());
319325

320326
if (stateControl == nullptr) {

XCast/XCast.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
#include "Module.h"
3535
#include <interfaces/IXCast.h>
36+
#include <interfaces/IConfiguration.h>
3637
#include "tracing/Logging.h"
3738
#include "tptimer.h"
3839
#include "libIBus.h"

XCast/XCastImplementation.cpp

Lines changed: 53 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,8 @@
3030
#endif
3131

3232
#define SERVER_DETAILS "127.0.0.1:9998"
33-
#define NETWORK_CALLSIGN "org.rdk.Network"
34-
#define NETWORK_CALLSIGN_VER NETWORK_CALLSIGN ".1"
35-
#define THUNDER_RPC_TIMEOUT 2000
33+
#define NETWORK_CALLSIGN_VER "org.rdk.Network.1"
34+
#define THUNDER_RPC_TIMEOUT 5000
3635
#define MAX_SECURITY_TOKEN_SIZE 1024
3736

3837
#define API_VERSION_NUMBER_MAJOR 1
@@ -65,6 +64,11 @@ namespace Plugin {
6564
XCastImplementation::~XCastImplementation()
6665
{
6766
Deinitialize();
67+
if (nullptr != mShell)
68+
{
69+
mShell->Release();
70+
mShell = nullptr;
71+
}
6872
}
6973

7074
void XCastImplementation::Register(Exchange::IXCast::INotification* sink)
@@ -123,6 +127,15 @@ namespace Plugin {
123127
}
124128
}
125129

130+
uint32_t XCastImplementation::Configure(PluginHost::IShell* service)
131+
{
132+
LOGINFO("Configuring XCast");
133+
ASSERT(service != nullptr);
134+
mShell = service;
135+
mShell->AddRef();
136+
return Core::ERROR_NONE;
137+
}
138+
126139
uint32_t XCastImplementation::enableCastService(string friendlyname,bool enableService) const
127140
{
128141
LOGINFO("XcastService::enableCastService: ARGS = %s : %d", friendlyname.c_str(), enableService);
@@ -395,68 +408,59 @@ namespace Plugin {
395408

396409
std::string XCastImplementation::getSecurityToken()
397410
{
398-
std::string token = "token=";
399-
int tokenLength = 0;
400-
unsigned char buffer[MAX_SECURITY_TOKEN_SIZE] = {0};
401-
static std::string endpoint;
402-
403-
if(endpoint.empty()) {
404-
Core::SystemInfo::GetEnvironment(_T("THUNDER_ACCESS"), endpoint);
405-
LOGINFO("Thunder RPC Endpoint read from env - %s", endpoint.c_str());
406-
}
407-
408-
if(endpoint.empty()) {
409-
Core::File file("/etc/WPEFramework/config.json");
410-
if(file.Open(true)) {
411-
JsonObject config;
412-
if(config.IElement::FromFile(file)) {
413-
Core::JSON::String port = config.Get("port");
414-
Core::JSON::String binding = config.Get("binding");
415-
if(!binding.Value().empty() && !port.Value().empty())
416-
endpoint = binding.Value() + ":" + port.Value();
417-
}
418-
file.Close();
419-
}
420-
421-
if(endpoint.empty())
422-
endpoint = _T("127.0.0.1:9998");
423-
424-
LOGINFO("Thunder RPC Endpoint read from config file - %s", endpoint.c_str());
425-
Core::SystemInfo::SetEnvironment(_T("THUNDER_ACCESS"), endpoint);
426-
}
427-
428-
string payload = "http://localhost";
429-
if(payload.empty()) {
430-
tokenLength = GetSecurityToken(sizeof(buffer), buffer);
431-
} else {
432-
int buffLength = std::min(sizeof(buffer), payload.length());
433-
::memcpy(buffer, payload.c_str(), buffLength);
434-
tokenLength = GetToken(sizeof(buffer), buffLength, buffer);
411+
if (nullptr == mShell)
412+
{
413+
return (std::string(""));
435414
}
436415

437-
if(tokenLength > 0) {
438-
token.append((char*)buffer);
439-
} else {
440-
token.clear();
416+
std::string token;
417+
auto security = mShell->QueryInterfaceByCallsign<PluginHost::IAuthenticate>("SecurityAgent");
418+
if (nullptr != security)
419+
{
420+
std::string payload = "http://localhost";
421+
if (security->CreateToken(static_cast<uint16_t>(payload.length()),
422+
reinterpret_cast<const uint8_t *>(payload.c_str()),
423+
token) == Core::ERROR_NONE)
424+
{
425+
LOGINFO("got security token - %s", token.empty() ? "" : token.c_str());
426+
}
427+
else
428+
{
429+
LOGERR("failed to get security token");
430+
}
431+
security->Release();
432+
}
433+
else
434+
{
435+
LOGERR("No security agent\n");
441436
}
442437

443-
LOGINFO("Thunder token - %s", token.empty() ? "" : token.c_str());
444-
return token;
438+
std::string query = "token=" + token;
439+
Core::SystemInfo::SetEnvironment(_T("THUNDER_ACCESS"), (_T(SERVER_DETAILS)));
440+
return query;
445441
}
446442

447443
// Thunder plugins communication
448-
void XCastImplementation::getThunderPlugins()
444+
void XCastImplementation::getThunderPlugins()
449445
{
450446
string token = getSecurityToken();
451447

452448
if (nullptr == m_ControllerObj)
453449
{
454-
m_ControllerObj = new WPEFramework::JSONRPC::LinkType<Core::JSON::IElement>("", "", false, token);
450+
if(token.empty())
451+
{
452+
m_ControllerObj = new WPEFramework::JSONRPC::LinkType<Core::JSON::IElement>("", "", false);
453+
}
454+
else
455+
{
456+
m_ControllerObj = new WPEFramework::JSONRPC::LinkType<Core::JSON::IElement>("","", false, token);
457+
}
455458

456459
if (nullptr != m_ControllerObj)
457460
{
461+
LOGINFO("JSONRPC: Controller: initialization ok");
458462
bool isSubscribed = false;
459-
auto ev_ret = m_ControllerObj->Subscribe<JsonObject>(1000, _T("statechange"),&XCastImplementation::eventHandler_pluginState,this);
463+
auto ev_ret = m_ControllerObj->Subscribe<JsonObject>(THUNDER_RPC_TIMEOUT, _T("statechange"),&XCastImplementation::eventHandler_pluginState,this);
460464
if (ev_ret == Core::ERROR_NONE)
461465
{
462466
LOGINFO("Controller - statechange event subscribed");

XCast/XCastImplementation.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "Module.h"
2323
#include <interfaces/Ids.h>
2424
#include <interfaces/IXCast.h>
25+
#include <interfaces/IConfiguration.h>
2526
#include "tracing/Logging.h"
2627
#include "XCastManager.h"
2728
#include "XCastNotifier.h"
@@ -102,7 +103,6 @@ namespace Plugin {
102103
virtual uint32_t Request(const command state) override { return Core::ERROR_GENERAL; }
103104
virtual void Register(IStateControl::INotification* notification) override {}
104105
virtual void Unregister(IStateControl::INotification* notification) override {}
105-
virtual uint32_t Configure(PluginHost::IShell* service) override { return Core::ERROR_NONE; }
106106

107107
virtual uint32_t Initialize(bool networkStandbyMode) override;
108108
virtual void Deinitialize(void) override;
@@ -137,6 +137,7 @@ namespace Plugin {
137137
std::list<Exchange::IXCast::INotification*> _notificationClients;
138138
static XCastImplementation* _instance;
139139
bool m_networkStandbyMode{false};
140+
PluginHost::IShell* mShell;
140141

141142
void dispatchEvent(Event,string callsign, const JsonObject &params);
142143
void Dispatch(Event event,string callsign, const JsonObject params);
@@ -161,6 +162,9 @@ namespace Plugin {
161162
bool getDefaultNameAndIPAddress(std::string& interface, std::string& ipaddress);
162163
void updateNWConnectivityStatus(std::string nwInterface, bool nwConnected, std::string ipaddress = "");
163164

165+
// IConfiguration interface
166+
uint32_t Configure(PluginHost::IShell* shell);
167+
164168
public:
165169
XCastImplementation();
166170
virtual ~XCastImplementation();

0 commit comments

Comments
 (0)