26 #include <core/core.h>
27 #include <websocket/websocket.h>
28 #include <securityagent/SecurityTokenUtil.h>
32 using namespace WPEFramework;
34 #define SERVER_DETAILS "127.0.0.1:9998"
35 #define MAX_LENGTH 1024
42 std::string securityToken;
55 controllerObject(NULL),
56 pluginCallsign(callsign),
59 AAMPLOG_INFO(
"[ThunderAccessAAMP]Inside");
61 uint32_t status = Core::ERROR_NONE;
63 Core::SystemInfo::SetEnvironment(_T(
"THUNDER_ACCESS"), (_T(SERVER_DETAILS)));
65 if(!gSecurityData.tokenQueried)
67 unsigned char buffer[MAX_LENGTH] = {0};
68 gSecurityData.tokenStatus = GetSecurityToken(MAX_LENGTH,buffer);
69 if(gSecurityData.tokenStatus > 0){
70 AAMPLOG_INFO(
"[ThunderAccessAAMP] : GetSecurityToken success");
71 string sToken = (
char*)buffer;
72 gSecurityData.securityToken =
"token=" + sToken;
74 gSecurityData.tokenQueried =
true;
79 if (NULL == controllerObject) {
81 if(gSecurityData.tokenStatus > 0){
82 controllerObject =
new JSONRPC::LinkType<Core::JSON::IElement>(_T(
""), _T(
""),
false, gSecurityData.securityToken);
85 controllerObject =
new JSONRPC::LinkType<Core::JSON::IElement>(_T(
""));
88 if (NULL == controllerObject) {
89 AAMPLOG_WARN(
"[ThunderAccessAAMP] Controller object creation failed");
91 AAMPLOG_INFO(
"[ThunderAccessAAMP] Controller object creation success");
95 if(gSecurityData.tokenStatus > 0){
96 remoteObject =
new JSONRPC::LinkType<Core::JSON::IElement>(_T(pluginCallsign), _T(
""),
false, gSecurityData.securityToken);
99 remoteObject =
new JSONRPC::LinkType<Core::JSON::IElement>(_T(pluginCallsign), _T(
""));
102 AAMPLOG_WARN(
"[ThunderAccessAAMP] %s Client initialization failed", pluginCallsign.c_str());
104 AAMPLOG_INFO(
"[ThunderAccessAAMP] %s Client initialization success", pluginCallsign.c_str());
113 SAFE_DELETE(controllerObject);
124 JsonObject controlParam;
125 std::string response;
126 uint32_t status = Core::ERROR_NONE;
128 if (NULL != controllerObject) {
129 controlParam[
"callsign"] = pluginCallsign;
130 status = controllerObject->Invoke<JsonObject, JsonObject>(THUNDER_RPC_TIMEOUT, _T(
"activate"), controlParam, result);
131 if (Core::ERROR_NONE == status){
132 result.ToString(response);
133 AAMPLOG_INFO(
"[ThunderAccessAAMP] %s plugin Activated. Response : %s ", pluginCallsign.c_str(), response.c_str());
137 AAMPLOG_WARN(
"[ThunderAccessAAMP] %s plugin Activation failed with error status : %u ", pluginCallsign.c_str(), status);
141 AAMPLOG_WARN(
"[ThunderAccessAAMP] Controller Object NULL ");
156 uint32_t status = Core::ERROR_NONE;
158 status =
remoteObject->Subscribe<JsonObject>(THUNDER_RPC_TIMEOUT, _T(eventName), functionHandler);
159 if (Core::ERROR_NONE == status) {
160 AAMPLOG_INFO(
"[ThunderAccessAAMP] Subscribed to : %s", eventName.c_str());
162 AAMPLOG_WARN(
"[ThunderAccessAAMP] Subscription failed for : %s with error status %u", eventName.c_str(), status);
166 AAMPLOG_WARN(
"[ThunderAccessAAMP] remoteObject not created for the plugin!");
182 remoteObject->Unsubscribe(THUNDER_RPC_TIMEOUT, _T(eventName));
183 AAMPLOG_INFO(
"[ThunderAccessAAMP] UnSubscribed : %s event", eventName.c_str());
185 AAMPLOG_WARN(
"[ThunderAccessAAMP] remoteObject not created for the plugin!");
199 std::string response;
200 uint32_t status = Core::ERROR_NONE;
204 AAMPLOG_WARN(
"[ThunderAccessAAMP] client not initialized! ");
208 JsonObject result_internal;
209 status =
remoteObject->Invoke<JsonObject, JsonObject>(waitTime, _T(method), param, result_internal);
210 if (Core::ERROR_NONE == status)
212 if (result_internal[
"success"].Boolean()) {
213 result_internal.ToString(response);
214 AAMPLOG_TRACE(
"[ThunderAccessAAMP] %s success! Response : %s", method.c_str() , response.c_str());
216 result_internal.ToString(response);
217 AAMPLOG_WARN(
"[ThunderAccessAAMP] %s call failed! Response : %s", method.c_str() , response.c_str());
221 AAMPLOG_WARN(
"[ThunderAccessAAMP] %s : invoke failed with error status %u", method.c_str(), status);
225 result = result_internal;