Skip to content

Commit feddce4

Browse files
authored
RDKTV-37375 : Unable to register event 'onDeviceMgtUpdateReceived'-xclass (rdkcentral#6311)
Reason for change: test Test Procedure: Mentioned in ticket Risks: Low Signed-off-by: vdinak240 <[email protected]>
1 parent ef5a707 commit feddce4

File tree

3 files changed

+31
-61
lines changed

3 files changed

+31
-61
lines changed

TextToSpeech/TextToSpeechImplementation.cpp

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#define TTS_MINOR_VERSION 0
3030

3131
#define GET_STR(map, key, def) ((map.HasLabel(key) && !map[key].String().empty() && map[key].String() != "null") ? map[key].String() : def)
32+
#define SERVER_DETAILS "127.0.0.1:9998"
3233

3334
#undef returnResponse
3435
#define returnResponse(success) \
@@ -78,8 +79,32 @@ namespace Plugin {
7879
JsonObject config;
7980
config.FromString(service->ConfigLine());
8081

82+
std::string token;
83+
auto security = service->QueryInterfaceByCallsign<PluginHost::IAuthenticate>("SecurityAgent");
84+
if (nullptr != security)
85+
{
86+
std::string payload = "http://localhost";
87+
if (security->CreateToken(static_cast<uint16_t>(payload.length()),
88+
reinterpret_cast<const uint8_t *>(payload.c_str()),
89+
token) == Core::ERROR_NONE)
90+
{
91+
TTSLOG_INFO("got security token - %s", token.empty() ? "" : token.c_str());
92+
}
93+
else
94+
{
95+
TTSLOG_INFO("Failed to get security token");
96+
}
97+
security->Release();
98+
}
99+
else
100+
{
101+
TTSLOG_INFO("No security agent\n");
102+
}
103+
std::string query = "token=" + token;
104+
Core::SystemInfo::SetEnvironment(_T("THUNDER_ACCESS"), (_T(SERVER_DETAILS)));
105+
81106
TTS::TTSConfiguration *ttsConfig = _ttsManager->configuration();
82-
TTS::RFCURLObserver::getInstance()->triggerRFC(ttsConfig);
107+
TTS::RFCURLObserver::getInstance()->triggerRFC(ttsConfig, query);
83108
ttsConfig->setEndPoint(GET_STR(config, "endpoint", ""));
84109
ttsConfig->setSecureEndPoint(GET_STR(config, "secureendpoint", ""));
85110
ttsConfig->setLocalEndPoint(GET_STR(config, "localendpoint", ""));

TextToSpeech/impl/RFCURLObserver.cpp

Lines changed: 3 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ RFCURLObserver* RFCURLObserver::getInstance() {
2727
}
2828

2929

30-
void RFCURLObserver::triggerRFC(TTSConfiguration *config)
30+
void RFCURLObserver::triggerRFC(TTSConfiguration *config,std::string token)
3131
{
3232
m_defaultConfig = config;
33+
m_token = token;
3334
fetchURLFromConfig();
3435
std::thread notificationThread(&RFCURLObserver::registerNotification, this);
3536
notificationThread.detach(); // Detach the thread to run independently
@@ -49,65 +50,9 @@ void RFCURLObserver::fetchURLFromConfig() {
4950
}
5051
}
5152

52-
string RFCURLObserver::getSecurityToken() {
53-
std::string token = "token=";
54-
int tokenLength = 0;
55-
unsigned char buffer[MAX_SECURITY_TOKEN_SIZE] = {0};
56-
static std::string endpoint;
57-
58-
if(endpoint.empty()) {
59-
Core::SystemInfo::GetEnvironment(_T("THUNDER_ACCESS"), endpoint);
60-
TTSLOG_INFO("Thunder RPC Endpoint read from env - %s", endpoint.c_str());
61-
}
62-
63-
if(endpoint.empty()) {
64-
Core::File file("/etc/WPEFramework/config.json");
65-
if(file.Open(true)) {
66-
JsonObject config;
67-
if(config.IElement::FromFile(file)) {
68-
Core::JSON::String port = config.Get("port");
69-
Core::JSON::String binding = config.Get("binding");
70-
if(!binding.Value().empty() && !port.Value().empty())
71-
endpoint = binding.Value() + ":" + port.Value();
72-
}
73-
file.Close();
74-
}
75-
if(endpoint.empty())
76-
endpoint = _T("127.0.0.1:9998");
77-
78-
TTSLOG_INFO("Thunder RPC Endpoint read from config file - %s", endpoint.c_str());
79-
Core::SystemInfo::SetEnvironment(_T("THUNDER_ACCESS"), endpoint);
80-
}
81-
82-
string payload = "http://localhost";
83-
if(payload.empty()) {
84-
tokenLength = GetSecurityToken(sizeof(buffer), buffer);
85-
} else {
86-
int buffLength = std::min(sizeof(buffer), payload.length());
87-
::memcpy(buffer, payload.c_str(), buffLength);
88-
tokenLength = GetToken(sizeof(buffer), buffLength, buffer);
89-
}
90-
91-
if(tokenLength > 0) {
92-
token.append((char*)buffer);
93-
} else {
94-
token.clear();
95-
}
96-
97-
TTSLOG_INFO("Thunder token - %s", token.empty() ? "" : token.c_str());
98-
return token;
99-
}
100-
101-
10253
void RFCURLObserver::registerNotification() {
10354
if (m_systemService == nullptr && !m_eventRegistered) {
104-
std::string token = getSecurityToken();
105-
if(token.empty()) {
106-
m_systemService = new WPEFramework::JSONRPC::LinkType<Core::JSON::IElement>(_T(SYSTEMSERVICE_CALLSIGN_VER),"");
107-
} else {
108-
m_systemService = new WPEFramework::JSONRPC::LinkType<Core::JSON::IElement>(_T(SYSTEMSERVICE_CALLSIGN_VER),"", false, token);
109-
}
110-
55+
m_systemService = new WPEFramework::JSONRPC::LinkType<Core::JSON::IElement>(_T(SYSTEMSERVICE_CALLSIGN_VER),"", false, m_token);
11156
while (!m_eventRegistered) {
11257
if (m_systemService->Subscribe<JsonObject>(3000, "onDeviceMgtUpdateReceived",
11358
&RFCURLObserver::onDeviceMgtUpdateReceivedHandler, this) == Core::ERROR_NONE) {

TextToSpeech/impl/RFCURLObserver.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace TTS {
88
class RFCURLObserver {
99
public:
1010
static RFCURLObserver* getInstance();
11-
void triggerRFC(TTSConfiguration*);
11+
void triggerRFC(TTSConfiguration*,std::string);
1212
~RFCURLObserver();
1313

1414
private:
@@ -18,12 +18,12 @@ class RFCURLObserver {
1818

1919
void fetchURLFromConfig();
2020
void registerNotification();
21-
string getSecurityToken();
2221

2322
void onDeviceMgtUpdateReceivedHandler(const JsonObject& parameters);
2423

2524
WPEFramework::JSONRPC::LinkType<WPEFramework::Core::JSON::IElement>* m_systemService{nullptr};
2625
bool m_eventRegistered {false};
26+
std::string m_token;
2727
TTSConfiguration *m_defaultConfig;
2828
};
2929

0 commit comments

Comments
 (0)