|
30 | 30 | #endif
|
31 | 31 |
|
32 | 32 | #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 |
36 | 35 | #define MAX_SECURITY_TOKEN_SIZE 1024
|
37 | 36 |
|
38 | 37 | #define API_VERSION_NUMBER_MAJOR 1
|
@@ -65,6 +64,11 @@ namespace Plugin {
|
65 | 64 | XCastImplementation::~XCastImplementation()
|
66 | 65 | {
|
67 | 66 | Deinitialize();
|
| 67 | + if (nullptr != mShell) |
| 68 | + { |
| 69 | + mShell->Release(); |
| 70 | + mShell = nullptr; |
| 71 | + } |
68 | 72 | }
|
69 | 73 |
|
70 | 74 | void XCastImplementation::Register(Exchange::IXCast::INotification* sink)
|
@@ -123,6 +127,15 @@ namespace Plugin {
|
123 | 127 | }
|
124 | 128 | }
|
125 | 129 |
|
| 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 | + |
126 | 139 | uint32_t XCastImplementation::enableCastService(string friendlyname,bool enableService) const
|
127 | 140 | {
|
128 | 141 | LOGINFO("XcastService::enableCastService: ARGS = %s : %d", friendlyname.c_str(), enableService);
|
@@ -395,68 +408,59 @@ namespace Plugin {
|
395 | 408 |
|
396 | 409 | std::string XCastImplementation::getSecurityToken()
|
397 | 410 | {
|
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("")); |
435 | 414 | }
|
436 | 415 |
|
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"); |
441 | 436 | }
|
442 | 437 |
|
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; |
445 | 441 | }
|
446 | 442 |
|
447 | 443 | // Thunder plugins communication
|
448 |
| - void XCastImplementation::getThunderPlugins() |
| 444 | + void XCastImplementation::getThunderPlugins() |
449 | 445 | {
|
450 | 446 | string token = getSecurityToken();
|
451 | 447 |
|
452 | 448 | if (nullptr == m_ControllerObj)
|
453 | 449 | {
|
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 | + } |
455 | 458 |
|
456 | 459 | if (nullptr != m_ControllerObj)
|
457 | 460 | {
|
| 461 | + LOGINFO("JSONRPC: Controller: initialization ok"); |
458 | 462 | 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); |
460 | 464 | if (ev_ret == Core::ERROR_NONE)
|
461 | 465 | {
|
462 | 466 | LOGINFO("Controller - statechange event subscribed");
|
|
0 commit comments