2 * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 ///////////////////////////////////////////////////////////////////////////////
18 /// \ingroup tag_NPService
19 /// \brief APIs to be used by clients while invoking Notification Service.
21 /// Implementation of APIs for Publishers and Subscribers of notifications.
23 ///////////////////////////////////////////////////////////////////////////////
25 ///////////////////////////////////////////////////////////////////////////////
27 ///////////////////////////////////////////////////////////////////////////////
28 #include <native_service/ns_np_service.h>
29 #include <native_service/ns_np_service_protocol.h>
30 #include <native_service/ns_np_service_if.h>
31 #include <native_service/ns_message_center_if.h>
32 #include <native_service/ns_mc_system_info.h>
38 #include <other_service/strlcpy.h>
40 // define user name as blank for global persistence file
41 #define GLOBAL_PERSISTENCE ""
43 // this is the maximum number of notifications that can be registered/ unregistered at once
44 const UI_32 maxNotification = UINT_MAX / sizeof(NC_register_notif_msg);
48 ////////////////////////////////////////////////////////////////////////////////////////////
49 /// NPRegisterNotifications
50 /// API to send message to Notification Service to register a set of notifications
52 /// \param [in] hNPMsgQ
53 /// HANDLE - Handle to message queue of Notification service.
54 /// \param [in] pPublisherName
55 /// PCSTR - Name of Publisher message queue
56 /// \param [in] numNotifications
57 /// PCSTR - Name of Notification
58 /// \param [in] pNotificationArray
59 /// NotificationInfo - Array of notifications
62 /// EFrameworkunifiedStatus - success or error
63 ////////////////////////////////////////////////////////////////////////////////////////////
64 EFrameworkunifiedStatus NPRegisterNotifications(HANDLE hNPMsgQ, PCSTR pPublisherName, UI_32 numNotifications,
65 NotificationInfo *pNotificationArray) {
66 EFrameworkunifiedStatus eFrameworkunifiedStatus = eFrameworkunifiedStatusOK;
68 if (maxNotification < numNotifications) {
69 return eFrameworkunifiedStatusFail;
72 size_t sizeOfMsg = (sizeof(NC_register_notif_msg) * numNotifications) + sizeof(UI_32);
73 if (NULL == pNotificationArray) {
74 return eFrameworkunifiedStatusInvldParam;
77 PCHAR *pMsgBuffer = (PCHAR *)malloc(sizeOfMsg);
79 if (NULL == pMsgBuffer) {
80 return eFrameworkunifiedStatusFail;
83 NC_register_multiple_notif_msg *pNotifMsg = (NC_register_multiple_notif_msg *)pMsgBuffer;
85 pNotifMsg->numNotifications = numNotifications;
86 memcpy(&pNotifMsg->notifierList[0], pNotificationArray, sizeof(NC_register_notif_msg) * numNotifications);
88 for(UI_32 i = 0; i < numNotifications; i++) {
89 // Insert \0 at the end of character (up to 64bytes) by copying with strlcpy.
90 strlcpy(pNotifMsg->notifierList[i].notificationName,
91 pNotificationArray[i].notificationName,
92 sizeof(pNotificationArray[i].notificationName));
95 eFrameworkunifiedStatus = McSend(hNPMsgQ, pPublisherName, NPS_REGISTER_EV_REQ, (UI_32)sizeOfMsg, (PVOID)pNotifMsg) ;
100 return eFrameworkunifiedStatus;
103 ////////////////////////////////////////////////////////////////////////////////////////////
104 /// \ingroup NPUnRegisterNotifications
105 /// API to send message to Notification Service to remove a set of notifications
107 /// \param [in] hNPMsgQ
108 /// HANDLE - Handle to message queue of Notification service.
109 /// \param [in] pPublisherName
110 /// PCSTR - Name of Publisher message queue
111 /// \param [in] numNotifications
112 /// PCSTR - Name of Notification
113 /// \param [in] pNotificationArray
114 /// NotificationInfo - Array of notifications
117 /// EFrameworkunifiedStatus - success or error
118 ////////////////////////////////////////////////////////////////////////////////////////////
119 EFrameworkunifiedStatus NPUnRegisterNotifications(HANDLE hNPMsgQ, PCSTR pPublisherName, UI_32 numNotifications,
120 NotificationInfo *pNotificationArray) {
121 EFrameworkunifiedStatus eFrameworkunifiedStatus = eFrameworkunifiedStatusOK;
123 if (maxNotification < numNotifications) {
124 return eFrameworkunifiedStatusFail;
127 size_t sizeOfMsg = (sizeof(NC_unregister_notif_msg) * numNotifications) + sizeof(UI_32);
129 if (NULL == pNotificationArray) {
130 return eFrameworkunifiedStatusInvldParam;
133 PCHAR *pMsgBuffer = (PCHAR *)malloc(sizeOfMsg);
135 if (NULL == pMsgBuffer) {
136 return eFrameworkunifiedStatusFail;
139 NC_unregister_multiple_notif_msg *pNotifMsg = (NC_unregister_multiple_notif_msg *)pMsgBuffer;
141 pNotifMsg->numNotifications = numNotifications;
143 for (i = 0; i < numNotifications; ++i) {
144 strlcpy(pNotifMsg->notificationList[i].notificationName, pNotificationArray[i].notificationName,
145 sizeof(pNotifMsg->notificationList[i].notificationName));
148 // mb20110110 Fixed issue 135
149 eFrameworkunifiedStatus = McSend(hNPMsgQ, pPublisherName, NPS_UNREGISTER_EV_REQ, (UI_32)sizeOfMsg, (VOID *)pMsgBuffer) ;
152 pMsgBuffer = NULL; // mb20110110 issue 134
154 return eFrameworkunifiedStatus;
157 ////////////////////////////////////////////////////////////////////////////////////////////
158 /// NPRegisterNotification
159 /// API to send message to Notification Service to register a notification
161 /// \param [in] hNPMsgQ
162 /// HANDLE - Handle to message queue of Notification service.
163 /// \param [in] pPublisherName
164 /// PCSTR - Name of Publisher message queue
165 /// \param [in] notif_name
166 /// PCSTR - Name of Notification
167 /// \param [in] max_length
168 /// const UI_32 - Max size of the notification message
169 /// \param [in] bIsPersistent
170 /// const UI_8 - Flag to indicate if it has to be persistent
173 /// EFrameworkunifiedStatus - success or error
174 ////////////////////////////////////////////////////////////////////////////////////////////
175 EFrameworkunifiedStatus NPRegisterNotification(HANDLE hNPMsgQ, PCSTR pPublisherName, PCSTR notificationName,
176 const UI_32 maxLength, const EFrameworkunifiedNotificationType perstype)
179 EFrameworkunifiedStatus eFrameworkunifiedStatus = eFrameworkunifiedStatusOK;
181 if (NULL != hNPMsgQ && NULL != pPublisherName && NULL != notificationName) {
182 if (strlen(pPublisherName) && strlen(notificationName)) {
183 NotificationInfo data = {};
184 strlcpy(data.notificationName, notificationName, sizeof(data.notificationName));
185 data.persType = perstype;
186 data.maxLength = maxLength;
188 eFrameworkunifiedStatus = NPRegisterNotifications(hNPMsgQ, pPublisherName, 1, &data);
190 eFrameworkunifiedStatus = eFrameworkunifiedStatusInvldParam;
193 eFrameworkunifiedStatus = eFrameworkunifiedStatusInvldParam;
196 return eFrameworkunifiedStatus;
199 ////////////////////////////////////////////////////////////////////////////////////////////
200 /// NPUnRegisterNotification
201 /// API to send message to Notification Service to remove a notification
203 /// \param [in] hNPMsgQ
204 /// HANDLE - Handle to message queue of Notification service.
205 /// \param [in] pPublisherName
206 /// PCSTR - Name of Publisher message queue
207 /// \param [in] pNotification
208 /// PCSTR - Name of Notification
211 /// EFrameworkunifiedStatus - success or error
212 ////////////////////////////////////////////////////////////////////////////////////////////
213 EFrameworkunifiedStatus NPUnRegisterNotification(HANDLE hNPMsgQ, PCSTR pPublisherName, PCSTR pNotification) {
215 NotificationInfo data = {};
216 strlcpy(data.notificationName, pNotification, sizeof(data.notificationName));
217 return (NPUnRegisterNotifications(hNPMsgQ, pPublisherName, 1, &data));
220 ////////////////////////////////////////////////////////////////////////////////////////////
221 /// NPPublishNotification
222 /// API to send message to Notification Service to notify subscribers
224 /// \param [in] hNPMsgQ
225 /// HANDLE - Handle to message queue of Notification service.
226 /// \param [in] pPublisherName
227 /// PCSTR - Name of Publisher message queue
228 /// \param [in] pNotification
229 /// PCSTR - Name of Notification
230 /// \param [in] pData
231 /// VOID * - Data buffer
232 /// \param [in] iLength
233 /// const UI_32 - Size of data buffer
236 /// EFrameworkunifiedStatus - success or error
237 ////////////////////////////////////////////////////////////////////////////////////////////
238 EFrameworkunifiedStatus NPPublishNotification(HANDLE hNPMsgQ, PCSTR pPublisherName, PCSTR pNotification,
239 PCVOID pData, const UI_32 iLength) {
240 EFrameworkunifiedStatus eFrameworkunifiedStatus = eFrameworkunifiedStatusOK;
242 if (NULL != hNPMsgQ && NULL != pPublisherName && NULL != pNotification) {
243 if (strlen(pPublisherName) && strlen(pNotification)) {
244 if (strlen(pNotification) < MAX_STRING_SIZE_NOTIFICATION) {
245 // Insert \0 at the end of characters (up to 64bytes) by copying pNotification to local variables with strlcpy.
246 char tmp_notification[MAX_STRING_SIZE_NOTIFICATION] = {0};
247 strlcpy(tmp_notification, pNotification, MAX_STRING_SIZE_NOTIFICATION);
248 eFrameworkunifiedStatus = McSendWithSysInfo(hNPMsgQ, pPublisherName, NPS_PUBLISH_EV_REQ,
249 tmp_notification, iLength, pData, 0);
251 eFrameworkunifiedStatus = eFrameworkunifiedStatusInvldParam;
254 eFrameworkunifiedStatus = eFrameworkunifiedStatusInvldParam;
257 eFrameworkunifiedStatus = eFrameworkunifiedStatusInvldParam;
260 return eFrameworkunifiedStatus;
263 ////////////////////////////////////////////////////////////////////////////////////////////
264 /// NPSubscribeToNotification
265 /// API to send message to Notification Service to add to subscription list for
266 /// that notification
268 /// \param [in] hNPMsgQ
269 /// HANDLE - Handle to message queue of Notification service.
270 /// \param [in] pSubscriberName
271 /// PCSTR - Name of subscriber message queue
272 /// \param [in] pNotification
273 /// PCSTR - Name of Notification
276 /// EFrameworkunifiedStatus - success or error
277 ////////////////////////////////////////////////////////////////////////////////////////////
278 EFrameworkunifiedStatus NPSubscribeToNotification(HANDLE hNPMsgQ, PCSTR pSubscriberName, PCSTR pNotification) {
279 EFrameworkunifiedStatus eFrameworkunifiedStatus = eFrameworkunifiedStatusOK;
280 if (NULL != hNPMsgQ && NULL != pSubscriberName && NULL != pNotification) {
281 if (strlen(pSubscriberName) && strlen(pNotification)) {
282 NC_subscribe_msg data;
283 snprintf(data.notificationName, sizeof(data.notificationName), "%s", pNotification);
285 eFrameworkunifiedStatus = McSend(hNPMsgQ, pSubscriberName, NPS_SUBSCRIBE_TO_EV_REQ, sizeof(NC_subscribe_msg), (PVOID)&data);
287 eFrameworkunifiedStatus = eFrameworkunifiedStatusInvldParam;
290 eFrameworkunifiedStatus = eFrameworkunifiedStatusInvldParam;
293 return eFrameworkunifiedStatus;
296 ////////////////////////////////////////////////////////////////////////////////////////////
297 // NPSubscribeToNotifications
298 ////////////////////////////////////////////////////////////////////////////////////////////
299 EFrameworkunifiedStatus NPSubscribeToNotifications(HANDLE hNPMsgQ, PCSTR pSubscriberName, UI_32 numNotifications,
300 SubscribeInfo *pSubscribeInfoArray) {
301 EFrameworkunifiedStatus eFrameworkunifiedStatus = eFrameworkunifiedStatusOK;
303 if (maxNotification < numNotifications) {
304 return eFrameworkunifiedStatusFail;
307 size_t sizeOfMsg = (sizeof(NC_subscribe_msg) * numNotifications) + sizeof(UI_32);
308 if (NULL == pSubscribeInfoArray) {
309 return eFrameworkunifiedStatusInvldParam;
312 PCHAR *pMsgBuffer = (PCHAR *)malloc(sizeOfMsg);
314 if (NULL == pMsgBuffer) {
315 return eFrameworkunifiedStatusFail;
318 NC_subscribe_multiple_notif_msg *pSubscribeMsg = (NC_subscribe_multiple_notif_msg *)pMsgBuffer;
320 pSubscribeMsg->numNotifications = numNotifications;
321 memcpy(&pSubscribeMsg->notificationList[0], pSubscribeInfoArray, sizeof(NC_subscribe_msg) * numNotifications);
323 for(UI_32 i = 0; i < numNotifications; i++) {
324 // Insert \0 at the end of character (up to 64bytes) by copying with strlcpy.
325 strlcpy(pSubscribeMsg->notificationList[i].notificationName,
326 pSubscribeInfoArray[i].notificationName,
327 sizeof(pSubscribeInfoArray[i].notificationName));
330 eFrameworkunifiedStatus = McSend(hNPMsgQ, pSubscriberName, NPS_BATCH_SUBSCRIBE_TO_EV_REQ, (UI_32)sizeOfMsg, (PVOID)pSubscribeMsg) ;
335 return eFrameworkunifiedStatus;
338 ////////////////////////////////////////////////////////////////////////////////////////////
339 /// NPUnsubscribeFromNotification
340 /// API to send message to Notification Service to remove from subscription list for
341 /// that notification
343 /// \param [in] hNPMsgQ
344 /// HANDLE - Handle to message queue of Notification service.
345 /// \param [in] pSubscriberName
346 /// PCSTR - Name of subscriber message queue
347 /// \param [in] pNotification
348 /// PCSTR - Name of Notification
351 /// EFrameworkunifiedStatus - success or error
352 ////////////////////////////////////////////////////////////////////////////////////////////
353 EFrameworkunifiedStatus NPUnsubscribeFromNotification(HANDLE hNPMsgQ, PCSTR pSubscriberName, PCSTR pNotification) {
354 EFrameworkunifiedStatus eFrameworkunifiedStatus = eFrameworkunifiedStatusOK;
356 if (NULL != hNPMsgQ && NULL != pSubscriberName && NULL != pNotification) {
357 if (strlen(pSubscriberName) && strlen(pNotification)) {
358 NC_unsubscribe_frm_notif_msg data;
359 snprintf(data.notificationName, sizeof(data.notificationName), "%s", pNotification);
361 eFrameworkunifiedStatus = McSend(hNPMsgQ, pSubscriberName, NPS_UNSUBSCRIBE_FROM_EV_REQ, sizeof(NC_unsubscribe_frm_notif_msg),
364 eFrameworkunifiedStatus = eFrameworkunifiedStatusInvldParam;
367 eFrameworkunifiedStatus = eFrameworkunifiedStatusInvldParam;
370 return eFrameworkunifiedStatus;
373 ////////////////////////////////////////////////////////////////////////////////////////////
374 // NPUnsubscribeToNotifications
375 ////////////////////////////////////////////////////////////////////////////////////////////
376 EFrameworkunifiedStatus NPUnsubscribeFromNotifications(HANDLE hNPMsgQ, PCSTR pUnSubscriberName, UI_32 numNotifications,
377 SubscribeInfo *pUnSubscribeInfoArray) {
378 EFrameworkunifiedStatus eFrameworkunifiedStatus = eFrameworkunifiedStatusOK;
380 if (NULL != hNPMsgQ && NULL != pUnSubscriberName) {
381 if (strlen(pUnSubscriberName)) {
382 if (maxNotification < numNotifications) {
383 return eFrameworkunifiedStatusFail;
386 size_t sizeOfMsg = (sizeof(NC_subscribe_msg) * numNotifications) + sizeof(UI_32);
387 if (NULL == pUnSubscribeInfoArray) {
388 return eFrameworkunifiedStatusInvldParam;
391 PCHAR *pMsgBuffer = (PCHAR *)malloc(sizeOfMsg);
393 if (NULL == pMsgBuffer) {
394 return eFrameworkunifiedStatusFail;
397 NC_unsubscribe_multiple_notif_msg *pUnSubscribeMsg = (NC_unsubscribe_multiple_notif_msg *)pMsgBuffer;
399 pUnSubscribeMsg->numNotifications = numNotifications;
400 memcpy(&pUnSubscribeMsg->notificationList[0], pUnSubscribeInfoArray, sizeof(NC_subscribe_msg) * numNotifications);
402 for(UI_32 i = 0; i < numNotifications; i++) {
403 // Insert \0 at the end of character (up to 64bytes) by copying with strlcpy.
404 strlcpy(pUnSubscribeMsg->notificationList[i].notificationName,
405 pUnSubscribeInfoArray[i].notificationName,
406 sizeof(pUnSubscribeInfoArray[i].notificationName));
409 eFrameworkunifiedStatus = McSend(hNPMsgQ, pUnSubscriberName, NPS_BATCH_UNSUBSCRIBE_FROM_EV_REQ, (UI_32)sizeOfMsg, (PVOID)pUnSubscribeMsg) ;
414 eFrameworkunifiedStatus = eFrameworkunifiedStatusInvldParam;
417 eFrameworkunifiedStatus = eFrameworkunifiedStatusInvldParam;
420 return eFrameworkunifiedStatus;
423 ////////////////////////////////////////////////////////////////////////////////////////////
424 /// NPReadPersistedData
425 /// API to requested the persistent data corresponding to specified notification if available
426 /// The caller recieves an acknowledgement once NPS completes data retrieval and sends it.
428 /// \param [in] hNPMsgQ
429 /// HANDLE - Handle to message queue of Notification service.
430 /// \param [in] pPublisherName
431 /// PCSTR - Name of publisher message queue
432 /// \param [in] notification
433 /// PCSTR - Name of Notification
436 /// EFrameworkunifiedStatus - success or error
437 ////////////////////////////////////////////////////////////////////////////////////////////
438 EFrameworkunifiedStatus NPReadPersistedData(HANDLE hNPMsgQ, PCSTR pPublisherName, PCSTR notification) {
439 EFrameworkunifiedStatus eFrameworkunifiedStatus = eFrameworkunifiedStatusOK;
441 if (NULL != hNPMsgQ && NULL != pPublisherName && NULL != notification) {
442 if (strlen(pPublisherName) && strlen(notification)) {
443 NC_get_pers_data_msg msg;
445 snprintf(msg.notificationName, sizeof(msg.notificationName), "%s", notification);
447 eFrameworkunifiedStatus = McSend(hNPMsgQ, pPublisherName, NPS_GET_PERS_DATA_REQ, sizeof(msg), (PVOID)&msg) ;
449 eFrameworkunifiedStatus = eFrameworkunifiedStatusInvldParam;
452 eFrameworkunifiedStatus = eFrameworkunifiedStatusInvldParam;
455 return eFrameworkunifiedStatus;
458 ////////////////////////////////////////////////////////////////////////////////////////////
459 /// \ingroup NPSavePersistentData
460 /// API to send message to Notification Service to save all persisted data that in Ram
461 /// to the filesystem via a file write.
463 /// \param [in] hNPMsgQ
464 /// HANDLE - Handle to message queue of Notification service.
465 /// \param [in] pPublisherName
466 /// PCSTR - Name of publisher message queue
469 /// EFrameworkunifiedStatus - success or error
470 ////////////////////////////////////////////////////////////////////////////////////////////
471 EFrameworkunifiedStatus NPSavePersistentData(HANDLE hNPMsgQ, PCSTR pPublisherName) {
472 EFrameworkunifiedStatus eFrameworkunifiedStatus = eFrameworkunifiedStatusOK;
474 eFrameworkunifiedStatus = McSend(hNPMsgQ, pPublisherName, NPS_SAVE_PERS_DATA_REQ, 0, NULL) ;
476 return eFrameworkunifiedStatus;
479 ////////////////////////////////////////////////////////////////////////////////////////////
480 /// NPRegisterPersistentFile
481 ////////////////////////////////////////////////////////////////////////////////////////////
482 EFrameworkunifiedStatus NPRegisterPersistentFile(HANDLE hNPMsgQ, PCSTR pPublisherName, PCSTR pTag,
483 BOOL bIsUserFile) { // EFrameworkunifiedRegisterType eRegisterType)
484 EFrameworkunifiedStatus eFrameworkunifiedStatus = eFrameworkunifiedStatusOK;
486 if (NULL != hNPMsgQ && NULL != pPublisherName && NULL != pTag) {
487 if (strlen(pPublisherName) && strlen(pTag)) {
488 NC_RegisterPersistentFileMsg tMsg;
490 snprintf(tMsg.cFileTag, sizeof(tMsg.cFileTag), "%s", pTag);
491 tMsg.bIsUserFile = bIsUserFile;
493 eFrameworkunifiedStatus = McSend(hNPMsgQ, pPublisherName, NPS_SET_PERSIST_FILE_PATH_REQ, sizeof(tMsg),
496 eFrameworkunifiedStatus = eFrameworkunifiedStatusInvldParam;
499 eFrameworkunifiedStatus = eFrameworkunifiedStatusInvldParam;
502 return eFrameworkunifiedStatus;
505 ////////////////////////////////////////////////////////////////////////////////////////////
506 /// NPLoadPersistentFile
507 ////////////////////////////////////////////////////////////////////////////////////////////
508 EFrameworkunifiedStatus NPLoadPersistentFile(HANDLE hNPMsgQ, PCSTR pPublisherName, PCSTR pDstFilePath,
509 PCSTR pTag, HANDLE hUser) {
510 EFrameworkunifiedStatus eFrameworkunifiedStatus = eFrameworkunifiedStatusOK;
512 if (NULL != hNPMsgQ && NULL != pPublisherName &&
513 NULL != pDstFilePath && NULL != pTag) {
514 if (strlen(pPublisherName) && strlen(pDstFilePath) && strlen(pTag)) {
515 NC_LoadPersistedFileMsg tMsg = {};
517 snprintf(tMsg.cFilePath, sizeof(tMsg.cFilePath), "%s", pDstFilePath);
518 snprintf(tMsg.cFileTag, sizeof(tMsg.cFileTag), "%s", pTag);
521 NC_User *pUser = (NC_User *) hUser;
522 snprintf(tMsg.cUsername, sizeof(tMsg.cUsername), "%s", pUser->cUsername != 0 ? pUser->cUsername : NULL);
524 strlcpy(tMsg.cUsername, GLOBAL_PERSISTENCE, sizeof(tMsg.cUsername));
527 eFrameworkunifiedStatus = McSend(hNPMsgQ, pPublisherName, NPS_GET_PERS_FILE_REQ, sizeof(tMsg), (PVOID)&tMsg) ;
529 eFrameworkunifiedStatus = eFrameworkunifiedStatusInvldParam;
532 eFrameworkunifiedStatus = eFrameworkunifiedStatusInvldParam;
535 return eFrameworkunifiedStatus;
538 ////////////////////////////////////////////////////////////////////////////////////////////
539 /// NPReleasePersistentFile
540 ////////////////////////////////////////////////////////////////////////////////////////////
541 EFrameworkunifiedStatus NPReleasePersistentFile(HANDLE hNPMsgQ, PCSTR pPublisherName, EFrameworkunifiedReleaseType eFrameworkunifiedReleaseType, PCSTR pTag,
542 PCSTR pFullFilePath, HANDLE hUser) {
543 EFrameworkunifiedStatus eFrameworkunifiedStatus = eFrameworkunifiedStatusOK;
545 if (NULL != hNPMsgQ && NULL != pPublisherName &&
546 NULL != pTag && NULL != pFullFilePath) {
547 if (strlen(pPublisherName) && strlen(pTag) && strlen(pFullFilePath)) {
548 NC_ReleasePersistentFileMsg tMsg = {eFrameworkunifiedReleaseType, {0}, {0}};
550 snprintf(tMsg.cFilePath, sizeof(tMsg.cFilePath), "%s", pFullFilePath);
551 snprintf(tMsg.cFileTag, sizeof(tMsg.cFileTag), "%s", pTag);
554 NC_User *pUser = (NC_User *) hUser;
555 snprintf(tMsg.cUsername, sizeof(tMsg.cUsername), "%s", pUser->cUsername != 0 ? pUser->cUsername : NULL);
557 strlcpy(tMsg.cUsername, GLOBAL_PERSISTENCE, sizeof(tMsg.cUsername));
560 eFrameworkunifiedStatus = McSend(hNPMsgQ, pPublisherName, NPS_RELEASE_PERS_FILE_REQ, sizeof(tMsg), (PVOID)&tMsg) ;
562 eFrameworkunifiedStatus = eFrameworkunifiedStatusInvldParam;
565 eFrameworkunifiedStatus = eFrameworkunifiedStatusInvldParam;
568 return eFrameworkunifiedStatus;
570 ////////////////////////////////////////////////////////////////////////////////////////////
572 ////////////////////////////////////////////////////////////////////////////////////////////
573 EFrameworkunifiedStatus NPPersistentSync(PCSTR SrcName, HANDLE hNPMsgQ, UI_32 sessionid, PCSTR pPublisherName) {
574 EFrameworkunifiedStatus eFrameworkunifiedStatus = eFrameworkunifiedStatusOK;
578 char mc_invoker_name[MAX_QUEUE_NAME_SIZE];
580 McCreateInvokerName(SrcName, sessionid, mc_invoker_name, sizeof(mc_invoker_name));
581 hResponse = McOpenSyncReceiver(&mc_invoker_name[0]);
582 if (hResponse != NULL) {
583 eFrameworkunifiedStatus = McInvokeSync(hNPMsgQ, pPublisherName, NPS_NPP_SYNC_REQ , sizeof(data), data, sessionid,
584 hResponse, 0, NULL, &length);
587 eFrameworkunifiedStatus = eFrameworkunifiedStatusFail;
589 return eFrameworkunifiedStatus;
591 ////////////////////////////////////////////////////////////////////////////////////////////
593 ////////////////////////////////////////////////////////////////////////////////////////////
594 EFrameworkunifiedStatus NPSetPersonality(HANDLE hNPMsgQ, PCSTR pPublisherName, PCSTR pUserName) {
595 EFrameworkunifiedStatus eFrameworkunifiedStatus = eFrameworkunifiedStatusOK;
597 if (NULL != hNPMsgQ && NULL != pPublisherName && NULL != pUserName) {
598 if (strlen(pPublisherName) && strlen(pUserName)) {
599 // NC_SetPersonalityMsg tMsg;
602 snprintf(tMsg.cUsername, sizeof(tMsg.cUsername), "%s", pUserName);
604 // eFrameworkunifiedStatus = McSend(hNPMsgQ, pPublisherName, NPS_SET_PERSONALITY_REQ, sizeof(tMsg), (PVOID)&tMsg ) ;
605 eFrameworkunifiedStatus = McSend(hNPMsgQ, pPublisherName, NPS_CHANGE_PERSONALITY_REQ, sizeof(tMsg), (PVOID)&tMsg) ;
607 eFrameworkunifiedStatus = eFrameworkunifiedStatusInvldParam;
610 eFrameworkunifiedStatus = eFrameworkunifiedStatusInvldParam;
613 return eFrameworkunifiedStatus;
615 ////////////////////////////////////////////////////////////////////////////////////////////
616 /// NPRegisterPersistentFolder
617 /// API to register persistence tag to folder that need to persist
619 /// \param [in] hNPMsgQ
620 /// HANDLE - Handle to message queue of Notification service.
621 /// \param [in] pPublisherName
622 /// PCSTR - Name of publisher message queue
624 /// PCSTR - Tag associated to folder that need to persist
625 /// \param [in] bIsUserFolder
626 /// BOOL - TRUE - user specific folder
627 /// FALSE - global file
630 /// EFrameworkunifiedStatus - success or error
631 ////////////////////////////////////////////////////////////////////////////////////////////
632 EFrameworkunifiedStatus NPRegisterPersistentFolder(HANDLE hNPMsgQ, PCSTR pPublisherName, PCSTR pTag, BOOL bIsUserFolder) {
633 EFrameworkunifiedStatus eFrameworkunifiedStatus = eFrameworkunifiedStatusOK;
635 if (NULL != hNPMsgQ && NULL != pPublisherName && NULL != pTag) {
636 if (strlen(pPublisherName) && strlen(pTag)) {
637 NC_RegisterPersistentFolderMsg tMsg;
639 snprintf(tMsg.cFolderTag, sizeof(tMsg.cFolderTag), "%s", pTag);
640 tMsg.bIsUserFolder = bIsUserFolder;
642 eFrameworkunifiedStatus = McSend(hNPMsgQ, pPublisherName, NPS_SET_PERSIST_FOLDER_PATH_REQ, sizeof(tMsg),
645 eFrameworkunifiedStatus = eFrameworkunifiedStatusInvldParam;
648 eFrameworkunifiedStatus = eFrameworkunifiedStatusInvldParam;
651 return eFrameworkunifiedStatus;
654 ////////////////////////////////////////////////////////////////////////////////////////////
655 /// NPLoadPersistentFolder
656 /// API to load folder to given path and associated with given tag from persistent memory
658 /// \param [in] hNPMsgQ
659 /// HANDLE - Handle to message queue of Notification service.
660 /// \param [in] pPublisherName
661 /// PCSTR - Name of publisher message queue
662 /// \param [in] pDstFolderPath
663 /// PCSTR - Destination where folder needs to be loaded
665 /// PCSTR - Tag associated to folder that need to loaded from persistent memory
666 /// \param [in] hUser
667 /// HANDLE - Handle of the user
670 /// EFrameworkunifiedStatus - success or error
671 ////////////////////////////////////////////////////////////////////////////////////////////
672 EFrameworkunifiedStatus NPLoadPersistentFolder(HANDLE hNPMsgQ, PCSTR pPublisherName, PCSTR pDstFolderPath,
673 PCSTR pTag, HANDLE hUser) {
674 EFrameworkunifiedStatus eFrameworkunifiedStatus = eFrameworkunifiedStatusOK;
676 if (NULL != hNPMsgQ && NULL != pPublisherName &&
677 NULL != pDstFolderPath && NULL != pTag) {
678 if (strlen(pPublisherName) && strlen(pDstFolderPath) && strlen(pTag)) {
679 NC_LoadPersistedFolderMsg tMsg;
681 snprintf(tMsg.cFolderPath, sizeof(tMsg.cFolderPath), "%s", pDstFolderPath);
682 snprintf(tMsg.cFolderTag, sizeof(tMsg.cFolderTag), "%s", pTag);
685 NC_User *pUser = (NC_User *) hUser;
686 snprintf(tMsg.cUsername, sizeof(tMsg.cUsername), "%s", pUser->cUsername != 0 ? pUser->cUsername : NULL);
688 strlcpy(tMsg.cUsername, GLOBAL_PERSISTENCE, sizeof(tMsg.cUsername));
691 eFrameworkunifiedStatus = McSend(hNPMsgQ, pPublisherName, NPS_GET_PERS_FOLDER_REQ, sizeof(tMsg), (PVOID)&tMsg) ;
693 eFrameworkunifiedStatus = eFrameworkunifiedStatusInvldParam;
696 eFrameworkunifiedStatus = eFrameworkunifiedStatusInvldParam;
699 return eFrameworkunifiedStatus;
702 ////////////////////////////////////////////////////////////////////////////////////////////
703 /// NPReleasePersistentFolder
704 /// API to release folder for saving with tag name to persistent memory
706 /// \param [in] hNPMsgQ
707 /// HANDLE - Handle to message queue of Notification service.
708 /// \param [in] pPublisherName
709 /// PCSTR - Name of publisher message queue
710 /// \param [in] eFrameworkunifiedReleaseType
711 /// EFrameworkunifiedReleaseType - eFrameworkunifiedNotOnRelease :not on release
712 /// eFrameworkunifiedPersistOnShutdown:persist on shutdown
713 /// eFrameworkunifiedPersistInstantly :persist instantly
715 /// PCSTR - Tag associated to folder that need to persist
716 /// \param [in] pFullFolderPath
717 /// PCSTR - full folder path of folder that need to be stored in persistent memory
718 /// \param [in] hUser
719 /// HANDLE - Handle of the user
722 /// EFrameworkunifiedStatus - success or error
723 ////////////////////////////////////////////////////////////////////////////////////////////
724 EFrameworkunifiedStatus NPReleasePersistentFolder(HANDLE hNPMsgQ, PCSTR pPublisherName, EFrameworkunifiedReleaseType eFrameworkunifiedReleaseType,
725 PCSTR pTag, PCSTR pFullFolderPath, HANDLE hUser) {
726 EFrameworkunifiedStatus eFrameworkunifiedStatus = eFrameworkunifiedStatusOK;
728 if (NULL != hNPMsgQ && NULL != pPublisherName &&
729 NULL != pTag && NULL != pFullFolderPath) {
730 if (strlen(pPublisherName) && strlen(pFullFolderPath) && strlen(pTag)) {
731 NC_ReleasePersistentFolderMsg tMsg = {eFrameworkunifiedReleaseType, {0}, {0}};
733 snprintf(tMsg.cFolderPath, sizeof(tMsg.cFolderPath), "%s", pFullFolderPath);
734 snprintf(tMsg.cFolderTag, sizeof(tMsg.cFolderTag), "%s", pTag);
737 NC_User *pUser = (NC_User *) hUser;
738 snprintf(tMsg.cUsername, sizeof(tMsg.cUsername), "%s", pUser->cUsername != 0 ? pUser->cUsername : NULL);
740 strlcpy(tMsg.cUsername, GLOBAL_PERSISTENCE, sizeof(tMsg.cUsername));
743 eFrameworkunifiedStatus = McSend(hNPMsgQ, pPublisherName, NPS_RELEASE_PERS_FOLDER_REQ, sizeof(tMsg), (PVOID)&tMsg) ;
745 eFrameworkunifiedStatus = eFrameworkunifiedStatusInvldParam;
748 eFrameworkunifiedStatus = eFrameworkunifiedStatusInvldParam;
751 return eFrameworkunifiedStatus;
754 ////////////////////////////////////////////////////////////////////////////////////////////
755 /// NPChangePersonality
756 ////////////////////////////////////////////////////////////////////////////////////////////
757 EFrameworkunifiedStatus NPChangePersonality(HANDLE hNPMsgQ, PCSTR pPublisherName, PCSTR pUserName) {
758 EFrameworkunifiedStatus eFrameworkunifiedStatus = eFrameworkunifiedStatusOK;
760 if (NULL != pUserName && 0 != strlen(pUserName)) {
761 eFrameworkunifiedStatus = McSend(hNPMsgQ, pPublisherName, NPS_CHANGE_PERSONALITY_REQ, sizeof(pUserName), (PVOID)&pUserName) ;
763 eFrameworkunifiedStatus = eFrameworkunifiedStatusInvldParam;
765 return eFrameworkunifiedStatus;
768 ////////////////////////////////////////////////////////////////////////////////////////////
770 ////////////////////////////////////////////////////////////////////////////////////////////
771 EFrameworkunifiedStatus SendStopToNSNPP(HANDLE hNPMsgQ, PCSTR pPublisherName, EFrameworkunifiedShutdownType eShutdownType, UI_32 uiStopMsgData) {
772 EFrameworkunifiedStatus eFrameworkunifiedStatus = eFrameworkunifiedStatusOK;
774 if (NULL != pPublisherName && 0 != strlen(pPublisherName)) {
776 tMsg.eShutdownType = eShutdownType;
777 tMsg.uiStopMsgData = uiStopMsgData;
779 eFrameworkunifiedStatus = McSend(hNPMsgQ, pPublisherName, NPS_NPP_STOP_REQ, sizeof(tMsg), (PVOID)&tMsg);
781 eFrameworkunifiedStatus = eFrameworkunifiedStatusInvldParam;
783 return eFrameworkunifiedStatus;
786 ////////////////////////////////////////////////////////////////////////////////////////////
787 /// NPGetReadyStatusOfNPP
788 ////////////////////////////////////////////////////////////////////////////////////////////
789 EFrameworkunifiedStatus NPGetReadyStatusOfNPP(HANDLE hNPMsgQ, PCSTR pRequesterName) {
790 EFrameworkunifiedStatus eFrameworkunifiedStatus = eFrameworkunifiedStatusOK;
792 if (NULL != pRequesterName && 0 != strlen(pRequesterName)) {
793 eFrameworkunifiedStatus = McSend(hNPMsgQ, pRequesterName, NPS_GET_READYSTATUS_REQ, 0, NULL);
795 eFrameworkunifiedStatus = eFrameworkunifiedStatusInvldParam;
797 return eFrameworkunifiedStatus;
800 ////////////////////////////////////////////////////////////////////////////////////////////
801 /// NPRegisterImmediateNotifications
802 /// API to send message to Notification Service to register a set of notifications
804 /// \param [in] hNPMsgQ
805 /// HANDLE - Handle to message queue of Notification service.
806 /// \param [in] pPublisherName
807 /// PCSTR - Name of Publisher message queue
808 /// \param [in] numNotifications
809 /// PCSTR - Name of Notification
810 /// \param [in] pNotificationArray
811 /// ImmediateNotificationInfo - Array of notifications
814 /// EFrameworkunifiedStatus - success or error
815 ////////////////////////////////////////////////////////////////////////////////////////////
816 EFrameworkunifiedStatus NPRegisterImmediateNotifications(HANDLE hNPMsgQ, PCSTR pPublisherName, UI_32 numNotifications,
817 ImmediateNotificationInfo *pNotificationArray) {
818 EFrameworkunifiedStatus eFrameworkunifiedStatus = eFrameworkunifiedStatusOK;
820 if (maxNotification < numNotifications) {
821 return eFrameworkunifiedStatusFail;
824 size_t sizeOfMsg = (sizeof(NC_register_immediate_notif_msg) * numNotifications) + sizeof(UI_32);
825 if (NULL == pNotificationArray) {
826 return eFrameworkunifiedStatusInvldParam;
829 PCHAR *pMsgBuffer = (PCHAR *)malloc(sizeOfMsg);
831 if (NULL == pMsgBuffer) {
832 return eFrameworkunifiedStatusFail;
835 NC_register_multiple_immediate_notif_msg *pNotifMsg = (NC_register_multiple_immediate_notif_msg *)pMsgBuffer;
837 if (NULL != pNotifMsg) {
838 pNotifMsg->numNotifications = numNotifications;
841 memcpy(&pNotifMsg->notifierList[0], pNotificationArray, sizeof(NC_register_immediate_notif_msg) * numNotifications);
843 for(UI_32 i = 0; i < numNotifications; i++ ) {
844 // Insert \0 at the end of character (up to 64bytes) by copying with strlcpy.
845 strlcpy(pNotifMsg->notifierList[i].notificationName,
846 pNotificationArray[i].notificationName,
847 sizeof(pNotificationArray[i].notificationName));
850 eFrameworkunifiedStatus = McSend(hNPMsgQ, pPublisherName, NPS_REGISTER_NOR_EV_REQ, (UI_32)sizeOfMsg, (PVOID)pNotifMsg) ;
852 if (NULL != pMsgBuffer) {
856 return eFrameworkunifiedStatus;
859 ////////////////////////////////////////////////////////////////////////////////////////////
860 /// NPClearPersistedData
861 ////////////////////////////////////////////////////////////////////////////////////////////
862 EFrameworkunifiedStatus NPClearPersistedData(HANDLE hNPMsgQ, PCSTR pRequesterName, EFrameworkunifiedClearPersistence eFrameworkunifiedClearPersistenceScope) {
863 EFrameworkunifiedStatus eFrameworkunifiedStatus = eFrameworkunifiedStatusOK;
865 if ((NULL != hNPMsgQ) && (NULL != pRequesterName) && (0 != strlen(pRequesterName))) {
866 NC_ClearPersistedDataReq tMsg = {};
867 tMsg.ePersistenceData = eFrameworkunifiedClearPersistenceScope;
869 eFrameworkunifiedStatus = McSend(hNPMsgQ,
871 NPS_DELETE_PERSISTED_DATA_REQ,
875 eFrameworkunifiedStatus = eFrameworkunifiedStatusInvldParam;
877 return eFrameworkunifiedStatus;
880 ////////////////////////////////////////////////////////////////////////////////////////////
881 /// NPSetPersistNotfnDefaultValue
882 ////////////////////////////////////////////////////////////////////////////////////////////
883 EFrameworkunifiedStatus NPSetPersistNotfnDefaultValue(HANDLE hNPMsgQ, PCSTR pPublisherName, PCSTR pNotification, PCVOID pData,
884 const UI_32 iLength) {
885 EFrameworkunifiedStatus eFrameworkunifiedStatus = eFrameworkunifiedStatusOK;
887 if (NULL != hNPMsgQ && NULL != pPublisherName && NULL != pNotification) {
888 if ((0 != strlen(pPublisherName)) && (0 != strlen(pNotification))) {
890 // Insert \0 at the end of characters (up to 64bytes) by copying pNotification to local variables with strlcpy.
891 char tmp_notification[MAX_STRING_SIZE_NOTIFICATION] = {0};
892 strlcpy(tmp_notification, pNotification, MAX_STRING_SIZE_NOTIFICATION);
894 eFrameworkunifiedStatus = McSendWithSysInfo(hNPMsgQ,
896 NPS_SET_DEFAULT_PERS_DATA,
897 (PCHAR)tmp_notification,
902 eFrameworkunifiedStatus = eFrameworkunifiedStatusInvldParam;
905 eFrameworkunifiedStatus = eFrameworkunifiedStatusInvldParam;
908 return eFrameworkunifiedStatus;
911 ////////////////////////////////////////////////////////////////////////////////////////////
912 /// NPSetPersistentNotfnType
913 ////////////////////////////////////////////////////////////////////////////////////////////
914 EFrameworkunifiedStatus NPSetPersistentNotfnType(HANDLE hNPMsgQ, PCSTR pPublisherName, PCSTR pNotification,
915 EFrameworkunifiedPersistCategory ePersistCategory) {
916 EFrameworkunifiedStatus eFrameworkunifiedStatus = eFrameworkunifiedStatusOK;
918 if (NULL != hNPMsgQ && NULL != pPublisherName && NULL != pNotification) {
919 if ((0 != strlen(pPublisherName)) && (0 != strlen(pNotification))) {
921 // Insert \0 at the end of characters (up to 64bytes) by copying pNotification to local variables with strlcpy.
922 char tmp_notification[MAX_STRING_SIZE_NOTIFICATION] = {0};
923 strlcpy(tmp_notification, pNotification, MAX_STRING_SIZE_NOTIFICATION);
925 eFrameworkunifiedStatus = McSendWithSysInfo(hNPMsgQ,
927 NPS_SET_NOTFN_PERSISTENT_TYPE,
928 (PCHAR)tmp_notification,
929 sizeof(ePersistCategory),
933 eFrameworkunifiedStatus = eFrameworkunifiedStatusInvldParam;
936 eFrameworkunifiedStatus = eFrameworkunifiedStatusInvldParam;
939 return eFrameworkunifiedStatus;
942 ////////////////////////////////////////////////////////////////////////////////////////////
943 /// NPSetFilePersistentType
944 ////////////////////////////////////////////////////////////////////////////////////////////
945 EFrameworkunifiedStatus NPSetFilePersistentType(HANDLE hNPMsgQ, PCSTR pPublisherName,
946 PCSTR pTag, EFrameworkunifiedPersistCategory ePersistCategory) {
947 EFrameworkunifiedStatus eFrameworkunifiedStatus = eFrameworkunifiedStatusOK;
949 if (NULL != hNPMsgQ && NULL != pPublisherName && NULL != pTag) {
950 if ((0 != strlen(pPublisherName)) && (0 != strlen(pTag))) {
951 NC_SetFilePersistType tMsg = {};
953 tMsg.ePersistType = ePersistCategory;
955 snprintf(tMsg.cTag, sizeof(tMsg.cTag), "%s", pTag);
957 eFrameworkunifiedStatus = McSend(hNPMsgQ,
959 NPS_SET_FILE_PERSISTENT_TYPE,
963 eFrameworkunifiedStatus = eFrameworkunifiedStatusInvldParam;
966 eFrameworkunifiedStatus = eFrameworkunifiedStatusInvldParam;
969 return eFrameworkunifiedStatus;
972 ////////////////////////////////////////////////////////////////////////////////////////////
973 /// NPSetFolderPersistentType
974 ////////////////////////////////////////////////////////////////////////////////////////////
975 EFrameworkunifiedStatus NPSetFolderPersistentType(HANDLE hNPMsgQ, PCSTR pPublisherName,
976 PCSTR pTag, EFrameworkunifiedPersistCategory ePersistCategory) {
977 EFrameworkunifiedStatus eFrameworkunifiedStatus = eFrameworkunifiedStatusOK;
979 if (NULL != hNPMsgQ && NULL != pPublisherName && NULL != pTag) {
980 if ((0 != strlen(pPublisherName)) && (0 != strlen(pTag))) {
981 NC_SetFolderPersistType tMsg = {};
983 tMsg.ePersistType = ePersistCategory;
984 snprintf(tMsg.cTag, sizeof(tMsg.cTag), "%s", pTag);
986 eFrameworkunifiedStatus = McSend(hNPMsgQ,
988 NPS_SET_FOLDER_PERSISTENT_TYPE,
992 eFrameworkunifiedStatus = eFrameworkunifiedStatusInvldParam;
995 eFrameworkunifiedStatus = eFrameworkunifiedStatusInvldParam;
998 return eFrameworkunifiedStatus;