28 #include "hostIf_NotificationHandler.h"
30 #include "hostIf_tr69ReqHandler.h"
31 #include "webpa_notification.h"
35 #define NOTIFY_PARAM_VALUE_CHANGE ""
37 parodusNotificationCallback NotificationHandler::notifyUpdateCallback = NULL;
38 GAsyncQueue* NotificationHandler::notificationQueue = NULL;
40 static void addToJsonObject (cJSON* json,
const char* key,
const char* value,
const WAL_DATA_TYPE type);
48 char * download_status;
49 char * system_ready_time;
54 NotificationHandler::NotificationHandler()
57 notificationQueue = g_async_queue_new();
61 NotificationHandler::~NotificationHandler()
63 g_async_queue_unref(notificationQueue);
73 GAsyncQueue* NotificationHandler::GetNotificationQueue()
75 return notificationQueue;
78 void NotificationHandler::registerUpdateCallback(parodusNotificationCallback cb)
80 notifyUpdateCallback = cb;
83 void NotificationHandler::pushNotification(
const char* destination,
const char* payload)
89 if (NULL == notificationQueue || NULL == notifyUpdateCallback)
91 RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF,
"%s: notificationQueue = %p, notifyUpdateCallback %p \n",
92 __FUNCTION__, notificationQueue, notifyUpdateCallback);
94 else if (NULL == destination || NULL == payload)
96 RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF,
"%s: Input error: destination %s payload %s \n", __FUNCTION__, destination, payload);
100 RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF,
"%s: Could not allocate notifyDataPtr\n", __FUNCTION__);
104 RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF,
"%s: Could not allocate notify_data\n", __FUNCTION__);
105 free (notifyDataPtr);
109 RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF,
"%s: Could not allocate paramNotify\n", __FUNCTION__);
111 free (notifyDataPtr);
115 paramNotify->notifyDest = destination ? strdup (destination) : NULL;
116 paramNotify->notifyPayload = (
char*) payload;
118 notify_data->notify = paramNotify;
120 notifyDataPtr->type = PARAM_VALUE_CHANGE_NOTIFY;
121 notifyDataPtr->data = notify_data;
124 g_async_queue_push(notificationQueue, notifyDataPtr);
125 (*notifyUpdateCallback)();
131 cJSON* notifyPayload = cJSON_CreateObject ();
132 cJSON_AddStringToObject(notifyPayload,
"device_id",
getNotifySource ());
135 converttoWalType(event.paramtype, &pwalType);
137 cJSON_AddNumberToObject(notifyPayload,
"datatype", pwalType);
138 cJSON_AddStringToObject(notifyPayload,
"paramName", event.paramName);
139 cJSON_AddStringToObject(notifyPayload,
"notificationType",
"VALUE_CHANGE_NOTIFICATION");
140 addToJsonObject (notifyPayload,
"paramValue", event.paramValue, pwalType);
142 char* payload = cJSON_PrintUnformatted (notifyPayload);
143 cJSON_Delete (notifyPayload);
144 RDK_LOG (RDK_LOG_DEBUG, LOG_PARODUS_IF,
"%s: Generated payload: %s\n", __FUNCTION__, payload);
146 NotificationHandler::getInstance()->pushNotification(
"event:VALUE_CHANGE_NOTIFICATION", payload);
149 void NotificationHandler::pushKeyValueNotification(
const char* destination,
const char* key,
const char* value)
151 cJSON* notifyPayload = cJSON_CreateObject ();
152 cJSON_AddStringToObject(notifyPayload,
"device_id",
getNotifySource ());
154 cJSON_AddStringToObject(notifyPayload, key, value);
156 char* payload = cJSON_PrintUnformatted (notifyPayload);
157 cJSON_Delete (notifyPayload);
158 RDK_LOG (RDK_LOG_DEBUG, LOG_PARODUS_IF,
"%s: Generated payload: %s\n", __FUNCTION__, payload);
160 NotificationHandler::getInstance()->pushNotification(destination, payload);
164 void addToJsonObject (cJSON* json,
const char* key,
const char* value,
const WAL_DATA_TYPE type)
170 cJSON_AddStringToObject(json, key, value);
175 const int* paramNewValue = (
const int*) ((value));
176 cJSON_AddNumberToObject(json, key, *paramNewValue);
181 const unsigned int* paramNewValue = (
const unsigned int*) ((value));
182 cJSON_AddNumberToObject(json, key, *paramNewValue);
187 const bool* paramNewValue = (
const bool*) ((value));
188 cJSON_AddBoolToObject(json, key, *paramNewValue);
193 const unsigned long *paramNewValue = (
const unsigned long *) ((value));
194 cJSON_AddNumberToObject(json, key, *paramNewValue);
199 cJSON_AddStringToObject(json, key, value);
207 RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,
"Inside converttoWalType \n");
210 case hostIf_StringType:
211 *pwalType = WAL_STRING;
213 case hostIf_UnsignedIntType:
214 *pwalType = WAL_UINT;
216 case hostIf_IntegerType:
219 case hostIf_BooleanType:
220 *pwalType = WAL_BOOLEAN;
222 case hostIf_UnsignedLongType:
223 *pwalType = WAL_ULONG;
225 case hostIf_DateTimeType:
226 *pwalType = WAL_DATETIME;
229 *pwalType = WAL_STRING;
234 void NotificationHandler::push_device_mgmt_notifications(
char* delay,
char* time,
char* download_status,
char* status,
char* system_ready_time)
237 cJSON *notifyPayload = NULL;
238 unsigned long bootTime = 0;
242 notifyPayload = cJSON_CreateObject();
244 if(notifyPayload != NULL)
246 cJSON_AddStringToObject(notifyPayload,
"device_id",
getNotifySource ());
249 cJSON_AddStringToObject(notifyPayload,
"status", status);
253 cJSON_AddStringToObject(notifyPayload,
"start-time", time);
256 if(download_status !=NULL)
258 cJSON_AddStringToObject(notifyPayload,
"download-status", (strcmp(download_status,
"true") == 0)?
"success":
"failure");
261 if ((status !=NULL) && (strcmp(status,
"reboot-pending") == 0))
264 hostIf_DeviceInfo::getInstance(0)->get_X_RDKCENTRAL_COM_BootTime(&stBootUpData);
265 bootTime = get_ulong(stBootUpData.
paramValue);
266 cJSON_AddNumberToObject(notifyPayload,
"boot-time", bootTime);
268 char* lastRebootReason = NULL;
270 hostIf_DeviceInfo::getInstance(0)->get_X_RDKCENTRAL_COM_LastRebootReason(&stMgsData);
272 RDK_LOG (RDK_LOG_DEBUG, LOG_PARODUS_IF,
"LastRebootReason is %s\n", lastRebootReason);
274 if(lastRebootReason !=NULL)
276 cJSON_AddStringToObject(notifyPayload,
"reboot-reason", lastRebootReason);
281 cJSON_AddNumberToObject(notifyPayload,
"delay", atoi(delay));
285 if ((status !=NULL) && (strcmp(status,
"fully-manageable") == 0) && (system_ready_time != NULL))
288 hostIf_DeviceInfo::getInstance(0)->get_X_RDKCENTRAL_COM_BootTime(&stBootUpData);
289 bootTime = get_ulong(stBootUpData.
paramValue);
290 cJSON_AddNumberToObject(notifyPayload,
"boot-time", bootTime);
291 cJSON_AddNumberToObject(notifyPayload,
"system-ready-time", atoi(system_ready_time));
294 char* payload = cJSON_PrintUnformatted (notifyPayload);
295 cJSON_Delete(notifyPayload);
297 const char *destination =
"event:device-status";
298 NotificationHandler::getInstance()->pushNotification(destination, payload);