Skip to content

Commit b2e98f4

Browse files
authored
Merge pull request rdkcentral#5856 from yuvaramachandran-gurusamy/sprint/24Q4/RDK-53913_XCast_OutOfProcess
RDK-53913: Convert XCast plugin as OutOfProcess with fix for crash and event subscription failure
2 parents adbfee1 + 2b4a894 commit b2e98f4

File tree

5 files changed

+73
-59
lines changed

5 files changed

+73
-59
lines changed

XCast/XCast.cpp

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

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

321327
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();

XCast/XCastManager.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ bool XCastManager::initialize(const std::string& gdial_interface_name, bool netw
289289

290290
void XCastManager::deinitialize()
291291
{
292+
LOGINFO("Destroying gdialService instance");
292293
lock_guard<recursive_mutex> lock(m_mutexSync);
293294
if (nullptr != gdialCastObj)
294295
{
@@ -422,7 +423,7 @@ bool XCastManager::envGetValue(const char *key, std::string &value)
422423
int XCastManager::applicationStateChanged( string app, string state, string id, string error)
423424
{
424425
int status = 0;
425-
LOGINFO("XcastService::ApplicationStateChanged ARGS = %s : %s : %s : %s ", app.c_str(), id.c_str() , state.c_str() , error.c_str());
426+
LOGINFO("ARGS = %s : %s : %s : %s ", app.c_str(), id.c_str() , state.c_str() , error.c_str());
426427
lock_guard<recursive_mutex> lock(m_mutexSync);
427428
if (gdialCastObj != NULL)
428429
{
@@ -436,7 +437,7 @@ int XCastManager::applicationStateChanged( string app, string state, string id,
436437

437438
void XCastManager::enableCastService(string friendlyname,bool enableService)
438439
{
439-
LOGINFO("XcastService::enableCastService ARGS = %s : %d ", friendlyname.c_str(), enableService);
440+
LOGINFO("ARGS = %s : %d ", friendlyname.c_str(), enableService);
440441
lock_guard<recursive_mutex> lock(m_mutexSync);
441442
if(gdialCastObj != NULL)
442443
{
@@ -450,12 +451,12 @@ void XCastManager::enableCastService(string friendlyname,bool enableService)
450451

451452
void XCastManager::updateFriendlyName(string friendlyname)
452453
{
453-
LOGINFO("XcastService::updateFriendlyName ARGS = %s ", friendlyname.c_str());
454+
LOGINFO("ARGS = %s ", friendlyname.c_str());
454455
lock_guard<recursive_mutex> lock(m_mutexSync);
455456
if(gdialCastObj != NULL)
456457
{
457458
gdialCastObj->FriendlyNameChanged( friendlyname);
458-
LOGINFO("XcastService send onFriendlyNameChanged");
459+
LOGINFO("XcastService send FriendlyNameChanged");
459460
}
460461
else
461462
LOGINFO(" gdialCastObj is NULL ");
@@ -507,11 +508,9 @@ void XCastManager::registerApplications(std::vector<DynamicAppConfig*>& appConfi
507508
LOGINFO(" gdialCastObj is NULL ");
508509
if (nullptr != appReqList)
509510
{
510-
for (RegisterAppEntry* appEntry : appReqList->getValues())
511-
{
512-
delete appEntry;
513-
}
511+
LOGINFO("[%p] Freeing appConfigList",appReqList);
514512
delete appReqList;
513+
appReqList = nullptr;
515514
}
516515
}
517516
}
@@ -563,4 +562,4 @@ bool XCastManager::IsAppEnabled(char* strAppName)
563562
#endif //RFC_ENABLED
564563

565564
return ret;
566-
}
565+
}

0 commit comments

Comments
 (0)