common_library: gettid is multiple declaration in cl_error
[staging/basesystem.git] / video_in_hal / nsframework / framework_unified / client / NS_FrameworkCore / src / frameworkunified_framework_npservice.cpp
1 /*
2  * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 ///////////////////////////////////////////////////////////////////////////////
18 /// \ingroup  tag_NSFramework
19 /// \brief    Framework wrapper over the NPService interface APIs
20 ///
21 ///
22 ///
23 ///////////////////////////////////////////////////////////////////////////////
24
25 ///////////////////////////////////////////////////////////////////////////////
26 // Include Files
27 ///////////////////////////////////////////////////////////////////////////////
28 #include <string.h>
29
30 #include <native_service/frameworkunified_framework_types.h>
31 #include <native_service/frameworkunified_framework_if.h>
32 #include <native_service/ns_np_service_if.h>
33 #include <native_service/ns_np_service_protocol.h>
34 #include <other_service/strlcpy.h>
35
36 #include "frameworkunified_framework_core.h"
37 #include "ns_np_service_internal.h"
38
39 ////////////////////////////////////////////////////////////////////////////////////////////
40 /// FrameworkunifiedNPRegisterNotification
41 ////////////////////////////////////////////////////////////////////////////////////////////
42 EFrameworkunifiedStatus FrameworkunifiedNPRegisterNotification(HANDLE hApp, PCSTR pNotification,  const UI_32 max_length,
43                                      const EFrameworkunifiedNotificationType persType) {
44   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
45
46   if (frameworkunifiedCheckValidAppHandle(hApp) && pNotification) {
47     if (strlen(pNotification) && strlen(pNotification) < MAX_STRING_SIZE_NOTIFICATION) {
48       CFrameworkunifiedFrameworkApp *pApp = static_cast<CFrameworkunifiedFrameworkApp *>(hApp);
49       MsgQInfo *pMqInfo = static_cast<MsgQInfo *>(pApp->hNPSndMsgQ);
50
51       NotificationInfo notifInfo = {};
52       strlcpy(notifInfo.notificationName, pNotification, sizeof(notifInfo.notificationName));
53       notifInfo.persType = persType;
54       notifInfo.maxLength = max_length;
55
56       eStatus = NPRegisterNotifications(pMqInfo->hMsgQ, pApp->cAppName, 1, &notifInfo);
57     } else {
58       eStatus = eFrameworkunifiedStatusInvldParam;
59     }
60   } else {
61     eStatus = eFrameworkunifiedStatusInvldParam;
62   }
63
64   return eStatus;
65 }
66
67 EFrameworkunifiedStatus FrameworkunifiedNPRegisterImmediatePersistNotification(HANDLE hApp, PCSTR pNotification,  const UI_32 max_length,
68                                                      const UI_32 delay) {
69   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
70
71   if (frameworkunifiedCheckValidAppHandle(hApp) && NULL != pNotification) {
72     if (strlen(pNotification) && strlen(pNotification) <= MAX_STRING_SIZE_NOTIFICATION) {
73       CFrameworkunifiedFrameworkApp *pApp = static_cast<CFrameworkunifiedFrameworkApp *>(hApp);
74       MsgQInfo *pMqInfo = static_cast<MsgQInfo *>(pApp->hNPSndMsgQ);
75
76       ImmediateNotificationInfo notifInfo = {};
77       strlcpy(notifInfo.notificationName, pNotification, sizeof(notifInfo.notificationName));
78       notifInfo.persType = eFrameworkunifiedImmediatePersistedStateVar;
79       notifInfo.maxLength = max_length;
80       notifInfo.delay = delay;
81
82       eStatus = NPRegisterImmediateNotifications(pMqInfo->hMsgQ, pApp->cAppName, 1, &notifInfo);
83     } else {
84       eStatus = eFrameworkunifiedStatusInvldParam;
85     }
86   } else {
87     eStatus = eFrameworkunifiedStatusInvldParam;
88   }
89
90   return eStatus;
91 }
92
93 ////////////////////////////////////////////////////////////////////////////////////////////
94 /// FrameworkunifiedNPPersistentSync
95 ////////////////////////////////////////////////////////////////////////////////////////////
96 EFrameworkunifiedStatus FrameworkunifiedNPPersistentSync(HANDLE hApp) {
97   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
98   if (frameworkunifiedCheckValidAppHandle(hApp)) {
99     CFrameworkunifiedFrameworkApp *pApp = static_cast<CFrameworkunifiedFrameworkApp *>(hApp);
100     MsgQInfo *pMqInfo = static_cast<MsgQInfo *>(pApp->hNPSndMsgQ);
101
102     eStatus = NPPersistentSync(pMqInfo->cSrcName, pMqInfo->hMsgQ, pMqInfo->sessionId,  pApp->cAppName);
103   } else {
104     eStatus = eFrameworkunifiedStatusInvldParam;
105   }
106   return eStatus;
107 }
108 ////////////////////////////////////////////////////////////////////////////////////////////
109 /// FrameworkunifiedNPRegisterNotifications
110 ////////////////////////////////////////////////////////////////////////////////////////////
111 EFrameworkunifiedStatus FrameworkunifiedNPRegisterNotifications(HANDLE hApp, const  FrameworkunifiedNotificationsList *pList, UI_32 uiListLength) {
112   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
113   if (frameworkunifiedCheckValidAppHandle(hApp) && pList) {
114     CFrameworkunifiedFrameworkApp *pApp = static_cast<CFrameworkunifiedFrameworkApp *>(hApp);
115     MsgQInfo *pMqInfo = static_cast<MsgQInfo *>(pApp->hNPSndMsgQ);
116
117     if (NULL != pMqInfo) {
118       NotificationInfo *pNotificationList =
119       reinterpret_cast<NotificationInfo *>(malloc(sizeof(NotificationInfo) * uiListLength));
120
121       for (UI_32 i = 0; i < uiListLength; ++i) {
122         strlcpy(pNotificationList[i].notificationName, pList[i].cNotification,
123           sizeof(pNotificationList[i].notificationName));
124         pNotificationList[i].maxLength = pList[i].uiLengthData;
125         pNotificationList[i].persType = pList[i].persType;
126       }
127       eStatus = NPRegisterNotifications(pMqInfo->hMsgQ, pApp->cAppName, uiListLength, pNotificationList);
128
129       free(pNotificationList);
130       pNotificationList = NULL;  // mb20110110 Fixed per  comment 295
131     } else {
132       eStatus = eFrameworkunifiedStatusNullPointer;
133     }
134   } else {
135     eStatus = eFrameworkunifiedStatusInvldParam;
136   }
137
138   return eStatus;
139 }
140
141 ////////////////////////////////////////////////////////////////////////////////////////////
142 /// FrameworkunifiedNPUnRegisterNotification
143 ////////////////////////////////////////////////////////////////////////////////////////////
144 EFrameworkunifiedStatus FrameworkunifiedNPUnRegisterNotification(HANDLE hApp, PCSTR pNotification) {
145   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
146
147   if (frameworkunifiedCheckValidAppHandle(hApp) && pNotification && strlen(pNotification)) {
148     CFrameworkunifiedFrameworkApp *pApp = static_cast<CFrameworkunifiedFrameworkApp *>(hApp);
149     MsgQInfo *pMqInfo = static_cast<MsgQInfo *>(pApp->hNPSndMsgQ);
150
151     NotificationInfo notifInfo = {};
152     strlcpy(notifInfo.notificationName, pNotification, sizeof(notifInfo.notificationName));
153
154     eStatus = NPUnRegisterNotifications(pMqInfo->hMsgQ, pApp->cAppName, 1, &notifInfo);
155   } else {
156     eStatus = eFrameworkunifiedStatusInvldParam;
157   }
158
159   return eStatus;
160 }
161
162 ////////////////////////////////////////////////////////////////////////////////////////////
163 /// FrameworkunifiedNPUnRegisterNotifications
164 ////////////////////////////////////////////////////////////////////////////////////////////
165 EFrameworkunifiedStatus FrameworkunifiedNPUnRegisterNotifications(HANDLE hApp, const  FrameworkunifiedNotificationsList *pList, UI_32 uiListLength) {
166   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
167   if (frameworkunifiedCheckValidAppHandle(hApp) && pList) {
168     CFrameworkunifiedFrameworkApp *pApp = static_cast<CFrameworkunifiedFrameworkApp *>(hApp);
169     MsgQInfo *pMqInfo = static_cast<MsgQInfo *>(pApp->hNPSndMsgQ);
170     if (NULL != pMqInfo) {
171       NotificationInfo *pNotificationList =
172       reinterpret_cast<NotificationInfo *>(malloc(sizeof(NotificationInfo) * uiListLength));
173
174       for (UI_32 i = 0; i < uiListLength; ++i) {
175         strlcpy(pNotificationList[i].notificationName, pList[i].cNotification,
176           sizeof(pNotificationList[i].notificationName));
177         pNotificationList[i].maxLength = pList[i].uiLengthData;
178         pNotificationList[i].persType = pList[i].persType;
179       }
180       eStatus = NPUnRegisterNotifications(pMqInfo->hMsgQ, pApp->cAppName, uiListLength, pNotificationList);
181
182       free(pNotificationList);
183     } else {
184       eStatus = eFrameworkunifiedStatusNullPointer;
185     }
186   } else {
187     eStatus = eFrameworkunifiedStatusInvldParam;
188   }
189
190   return eStatus;
191 }
192
193 ////////////////////////////////////////////////////////////////////////////////////////////
194 /// FrameworkunifiedNPPublishNotification
195 ////////////////////////////////////////////////////////////////////////////////////////////
196 EFrameworkunifiedStatus FrameworkunifiedNPPublishNotification(HANDLE hApp, PCSTR pNotification,
197                                     PCVOID pData, UI_32 iLength) {
198   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
199
200   if (frameworkunifiedCheckValidAppHandle(hApp) && NULL != pNotification) {
201     CFrameworkunifiedFrameworkApp *pApp = static_cast<CFrameworkunifiedFrameworkApp *>(hApp);
202     MsgQInfo *pMqInfo = static_cast<MsgQInfo *>(pApp->hNPSndMsgQ);
203
204     if ((NULL != pMqInfo->hMsgQ) && (0 != std::strlen(pApp->cAppName))) {
205       eStatus = NPPublishNotification(pMqInfo->hMsgQ, pApp->cAppName, pNotification, pData, iLength);
206     } else {
207       eStatus = eFrameworkunifiedStatusInvldHandle;
208     }
209   } else {
210     eStatus = eFrameworkunifiedStatusInvldParam;
211   }
212
213   return eStatus;
214 }
215
216
217 ////////////////////////////////////////////////////////////////////////////////////////////
218 /// FrameworkunifiedNPSubscribeToNotification
219 ////////////////////////////////////////////////////////////////////////////////////////////
220 EFrameworkunifiedStatus FrameworkunifiedNPSubscribeToNotification(HANDLE hApp, PCSTR pNotification) {
221   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
222
223   if (frameworkunifiedCheckValidAppHandle(hApp) && pNotification) {
224     CFrameworkunifiedFrameworkApp *pApp = static_cast<CFrameworkunifiedFrameworkApp *>(hApp);
225     MsgQInfo *pMqInfo = static_cast<MsgQInfo *>(pApp->hNPSndMsgQ);
226
227     eStatus = NPSubscribeToNotification(pMqInfo->hMsgQ,  pApp->cAppName, pNotification);
228   } else {
229     eStatus = eFrameworkunifiedStatusInvldParam;
230   }
231
232   return eStatus;
233 }
234
235
236 EFrameworkunifiedStatus FrameworkunifiedNPSubscribeToNotifications(HANDLE hApp, const  FrameworkunifiedNotificationCallbackHandler *pList,
237                                          UI_32 uiListLength) {
238   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
239
240   if (frameworkunifiedCheckValidAppHandle(hApp) && pList) {
241     CFrameworkunifiedFrameworkApp *pApp = static_cast<CFrameworkunifiedFrameworkApp *>(hApp);
242     MsgQInfo *pMqInfo = static_cast<MsgQInfo *>(pApp->hNPSndMsgQ);
243
244     SubscribeInfo *pSubscribeList =
245     reinterpret_cast<SubscribeInfo *>(malloc(sizeof(SubscribeInfo) * uiListLength));
246
247     for (UI_32 i = 0; i < uiListLength; ++i) {
248       strlcpy(pSubscribeList[i].notificationName, pList[i].cNotification,
249         sizeof(pSubscribeList[i].notificationName));
250     }
251     eStatus = NPSubscribeToNotifications(pMqInfo->hMsgQ, pApp->cAppName, uiListLength, pSubscribeList);
252
253     free(pSubscribeList);
254     pSubscribeList = NULL;  // mb20110110 Fixed per  comment 307
255   } else {
256     eStatus = eFrameworkunifiedStatusInvldParam;
257   }
258
259   return eStatus;
260 }
261
262
263 ////////////////////////////////////////////////////////////////////////////////////////////
264 /// FrameworkunifiedNPUnSubscribeNotifications
265 ////////////////////////////////////////////////////////////////////////////////////////////
266 EFrameworkunifiedStatus FrameworkunifiedNPUnsubscribeFromNotifications(HANDLE hApp, const  FrameworkunifiedNotificationCallbackHandler *pList,
267                                              UI_32 uiListLength) {
268   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
269
270   if (frameworkunifiedCheckValidAppHandle(hApp) && pList) {
271     CFrameworkunifiedFrameworkApp *pApp = static_cast<CFrameworkunifiedFrameworkApp *>(hApp);
272     MsgQInfo *pMqInfo = static_cast<MsgQInfo *>(pApp->hNPSndMsgQ);
273
274     SubscribeInfo *pSubscribeList =
275     reinterpret_cast<SubscribeInfo *>(malloc(sizeof(SubscribeInfo) * uiListLength));
276
277     for (UI_32 i = 0; i < uiListLength; ++i) {
278       strlcpy(pSubscribeList[i].notificationName, pList[i].cNotification, MAX_STRING_SIZE_NOTIFICATION);
279     }
280     eStatus = NPUnsubscribeFromNotifications(pMqInfo->hMsgQ, pApp->cAppName, uiListLength, pSubscribeList);
281
282     free(pSubscribeList);
283     pSubscribeList = NULL;  // mb20110110 Fixed per  comment 307
284   } else {
285     eStatus = eFrameworkunifiedStatusInvldParam;
286   }
287
288   return eStatus;
289 }
290
291
292 ////////////////////////////////////////////////////////////////////////////////////////////
293 /// FrameworkunifiedNPUnsubscribeFromNotification
294 ////////////////////////////////////////////////////////////////////////////////////////////
295 EFrameworkunifiedStatus FrameworkunifiedNPUnsubscribeFromNotification(HANDLE hApp, PCSTR pNotification) {
296   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
297
298   if (frameworkunifiedCheckValidAppHandle(hApp) && pNotification) {
299     CFrameworkunifiedFrameworkApp *pApp = static_cast<CFrameworkunifiedFrameworkApp *>(hApp);
300     MsgQInfo *pMqInfo = static_cast<MsgQInfo *>(pApp->hNPSndMsgQ);
301
302     eStatus = NPUnsubscribeFromNotification(pMqInfo->hMsgQ, pApp->cAppName, pNotification);
303   } else {
304     eStatus = eFrameworkunifiedStatusInvldParam;
305   }
306
307   return eStatus;
308 }
309
310 ////////////////////////////////////////////////////////////////////////////////////////////
311 /// FrameworkunifiedNPReadPersistedData
312 ////////////////////////////////////////////////////////////////////////////////////////////
313 EFrameworkunifiedStatus FrameworkunifiedNPReadPersistedData(HANDLE hApp, PCSTR pNotification) {
314   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
315
316   if (frameworkunifiedCheckValidAppHandle(hApp) && pNotification) {
317     CFrameworkunifiedFrameworkApp *pApp = static_cast<CFrameworkunifiedFrameworkApp *>(hApp);
318     MsgQInfo *pMqInfo = static_cast<MsgQInfo *>(pApp->hNPSndMsgQ);
319
320     eStatus = NPReadPersistedData(pMqInfo->hMsgQ,  pApp->cAppName, pNotification);
321   } else {
322     eStatus = eFrameworkunifiedStatusInvldParam;
323   }
324
325   return eStatus;
326 }
327
328 ////////////////////////////////////////////////////////////////////////////////////////////
329 /// FrameworkunifiedNPSavePersistentData
330 ////////////////////////////////////////////////////////////////////////////////////////////
331 // LCOV_EXCL_START 8: dead code
332 EFrameworkunifiedStatus FrameworkunifiedNPSavePersistentData(HANDLE hApp) {
333   AGL_ASSERT_NOT_TESTED();
334   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
335
336   if (frameworkunifiedCheckValidAppHandle(hApp)) {
337     CFrameworkunifiedFrameworkApp *pApp = static_cast<CFrameworkunifiedFrameworkApp *>(hApp);
338     MsgQInfo *pMqInfo = static_cast<MsgQInfo *>(pApp->hNPSndMsgQ);
339
340     eStatus = NPSavePersistentData(pMqInfo->hMsgQ,  pApp->cAppName);
341   } else {
342     eStatus = eFrameworkunifiedStatusInvldParam;
343   }
344
345   return eStatus;
346 }
347 // LCOV_EXCL_STOP
348
349
350 ////////////////////////////////////////////////////////////////////////////////////////////
351 /// FrameworkunifiedNPRegisterPersistentFile
352 ////////////////////////////////////////////////////////////////////////////////////////////
353 EFrameworkunifiedStatus FrameworkunifiedNPRegisterPersistentFile(HANDLE hApp, PCSTR pTag, BOOL bIsUserFile) {
354   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
355   if (frameworkunifiedCheckValidAppHandle(hApp) && pTag) {
356     CFrameworkunifiedFrameworkApp *pApp = static_cast<CFrameworkunifiedFrameworkApp *>(hApp);
357     MsgQInfo *pMqInfo = static_cast<MsgQInfo *>(pApp->hNPSndMsgQ);
358     if (NULL != pMqInfo) {
359       eStatus = NPRegisterPersistentFile(pMqInfo->hMsgQ,  pApp->cAppName, pTag, bIsUserFile);
360     } else {
361       eStatus = eFrameworkunifiedStatusNullPointer;
362     }
363   } else {
364     eStatus = eFrameworkunifiedStatusInvldParam;
365   }
366
367   return eStatus;
368 }
369
370
371 ////////////////////////////////////////////////////////////////////////////////////////////
372 /// FrameworkunifiedNPLoadPersistentFile
373 ////////////////////////////////////////////////////////////////////////////////////////////
374 EFrameworkunifiedStatus FrameworkunifiedNPLoadPersistentFile(HANDLE hApp, PCSTR pDstFilePath, PCSTR pTag, HANDLE hUser) {
375   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
376
377   if (frameworkunifiedCheckValidAppHandle(hApp) && pDstFilePath && pTag) {
378     CFrameworkunifiedFrameworkApp *pApp = static_cast<CFrameworkunifiedFrameworkApp *>(hApp);
379     MsgQInfo *pMqInfo = static_cast<MsgQInfo *>(pApp->hNPSndMsgQ);
380
381     if (NULL != pMqInfo) {
382       eStatus = NPLoadPersistentFile(pMqInfo->hMsgQ,  pApp->cAppName, pDstFilePath, pTag, hUser);
383     } else {
384       eStatus = eFrameworkunifiedStatusNullPointer;
385     }
386   } else {
387     eStatus = eFrameworkunifiedStatusInvldParam;
388   }
389
390   return eStatus;
391 }
392
393
394 ////////////////////////////////////////////////////////////////////////////////////////////
395 /// FrameworkunifiedNPReleasePersistentFile
396 ////////////////////////////////////////////////////////////////////////////////////////////
397 EFrameworkunifiedStatus FrameworkunifiedNPReleasePersistentFile(HANDLE hApp, BOOL bIsPersist, PCSTR pTag,
398                                       PCSTR pFullFilePath, HANDLE hUser) {
399   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
400   if (frameworkunifiedCheckValidAppHandle(hApp) && pTag && pFullFilePath) {
401     CFrameworkunifiedFrameworkApp *pApp = static_cast<CFrameworkunifiedFrameworkApp *>(hApp);
402     MsgQInfo *pMqInfo = static_cast<MsgQInfo *>(pApp->hNPSndMsgQ);
403
404     if (NULL != pMqInfo) {
405       EFrameworkunifiedReleaseType eReleaseType = (bIsPersist == FALSE) ? eFrameworkunifiedNotOnRelease : eFrameworkunifiedPersistOnShutdown;
406       eStatus = NPReleasePersistentFile(pMqInfo->hMsgQ,  pApp->cAppName, eReleaseType, pTag,
407                                         pFullFilePath, hUser);
408     } else {
409       eStatus = eFrameworkunifiedStatusNullPointer;
410     }
411   } else {
412     eStatus = eFrameworkunifiedStatusInvldParam;
413   }
414
415   return eStatus;
416 }
417
418 ////////////////////////////////////////////////////////////////////////////////////////////
419 /// FrameworkunifiedNPReleasePersistentFile
420 ////////////////////////////////////////////////////////////////////////////////////////////
421 EFrameworkunifiedStatus FrameworkunifiedNPReleasePersistentFile(HANDLE hApp, EFrameworkunifiedReleaseType eReleaseType, PCSTR pTag,
422                                       PCSTR pFullFilePath, HANDLE hUser) {
423   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
424   if (frameworkunifiedCheckValidAppHandle(hApp) && pTag && pFullFilePath) {
425     CFrameworkunifiedFrameworkApp *pApp = static_cast<CFrameworkunifiedFrameworkApp *>(hApp);
426     MsgQInfo *pMqInfo = static_cast<MsgQInfo *>(pApp->hNPSndMsgQ);
427
428     if (NULL != pMqInfo) {
429       eStatus = NPReleasePersistentFile(pMqInfo->hMsgQ,  pApp->cAppName, eReleaseType, pTag,
430                                         pFullFilePath, hUser);
431     } else {
432       eStatus = eFrameworkunifiedStatusNullPointer;
433     }
434   } else {
435     eStatus = eFrameworkunifiedStatusInvldParam;
436   }
437
438   return eStatus;
439 }
440
441 ////////////////////////////////////////////////////////////////////////////////////////////
442 /// FrameworkunifiedNPRegisterPersistentFolder
443 ////////////////////////////////////////////////////////////////////////////////////////////
444 EFrameworkunifiedStatus FrameworkunifiedNPRegisterPersistentFolder(HANDLE hApp, PCSTR pTag, BOOL bIsUserFolder) {
445   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
446   if (frameworkunifiedCheckValidAppHandle(hApp) && pTag) {
447     CFrameworkunifiedFrameworkApp *pApp = static_cast<CFrameworkunifiedFrameworkApp *>(hApp);
448     MsgQInfo *pMqInfo = static_cast<MsgQInfo *>(pApp->hNPSndMsgQ);
449
450     if (NULL != pMqInfo) {
451       eStatus = NPRegisterPersistentFolder(pMqInfo->hMsgQ,  pApp->cAppName, pTag, bIsUserFolder);
452     } else {
453       eStatus = eFrameworkunifiedStatusNullPointer;
454     }
455   } else {
456     eStatus = eFrameworkunifiedStatusInvldParam;
457   }
458
459   return eStatus;
460 }
461
462
463 ////////////////////////////////////////////////////////////////////////////////////////////
464 /// FrameworkunifiedNPLoadPersistentFolder
465 ////////////////////////////////////////////////////////////////////////////////////////////
466 EFrameworkunifiedStatus FrameworkunifiedNPLoadPersistentFolder(HANDLE hApp, PCSTR pDstFolderPath, PCSTR pTag, HANDLE hUser) {
467   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
468   if (frameworkunifiedCheckValidAppHandle(hApp) && pTag && pDstFolderPath) {
469     CFrameworkunifiedFrameworkApp *pApp = static_cast<CFrameworkunifiedFrameworkApp *>(hApp);
470     MsgQInfo *pMqInfo = static_cast<MsgQInfo *>(pApp->hNPSndMsgQ);
471     if (NULL != pMqInfo) {
472       eStatus = NPLoadPersistentFolder(pMqInfo->hMsgQ,  pApp->cAppName, pDstFolderPath, pTag, hUser);
473     } else {
474       eStatus = eFrameworkunifiedStatusNullPointer;
475     }
476   } else {
477     eStatus = eFrameworkunifiedStatusInvldParam;
478   }
479
480   return eStatus;
481 }
482
483
484 ////////////////////////////////////////////////////////////////////////////////////////////
485 /// FrameworkunifiedNPReleasePersistentFolder
486 ////////////////////////////////////////////////////////////////////////////////////////////
487 EFrameworkunifiedStatus FrameworkunifiedNPReleasePersistentFolder(HANDLE hApp, BOOL bIsPersist, PCSTR pTag, PCSTR pFullFolderPath,
488                                         HANDLE hUser) {
489   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
490   if (frameworkunifiedCheckValidAppHandle(hApp) && pTag && pFullFolderPath) {
491     CFrameworkunifiedFrameworkApp *pApp = static_cast<CFrameworkunifiedFrameworkApp *>(hApp);
492     MsgQInfo *pMqInfo = static_cast<MsgQInfo *>(pApp->hNPSndMsgQ);
493     if (NULL != pMqInfo) {
494       EFrameworkunifiedReleaseType eReleaseType = (bIsPersist == FALSE) ? eFrameworkunifiedNotOnRelease : eFrameworkunifiedPersistOnShutdown;
495       eStatus = NPReleasePersistentFolder(pMqInfo->hMsgQ,  pApp->cAppName, eReleaseType, pTag,
496                                           pFullFolderPath, hUser);
497     } else {
498       eStatus = eFrameworkunifiedStatusNullPointer;
499     }
500   } else {
501     eStatus = eFrameworkunifiedStatusInvldParam;
502   }
503
504   return eStatus;
505 }
506 ////////////////////////////////////////////////////////////////////////////////////////////
507 /// FrameworkunifiedNPReleasePersistentFolder
508 ////////////////////////////////////////////////////////////////////////////////////////////
509 EFrameworkunifiedStatus FrameworkunifiedNPReleasePersistentFolder(HANDLE hApp, EFrameworkunifiedReleaseType eReleaseType, PCSTR pTag,
510                                         PCSTR pFullFolderPath,
511                                         HANDLE hUser) {
512   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
513   if (frameworkunifiedCheckValidAppHandle(hApp) && pTag && pFullFolderPath) {
514     CFrameworkunifiedFrameworkApp *pApp = static_cast<CFrameworkunifiedFrameworkApp *>(hApp);
515     MsgQInfo *pMqInfo = static_cast<MsgQInfo *>(pApp->hNPSndMsgQ);
516     if (NULL != pMqInfo) {
517       eStatus = NPReleasePersistentFolder(pMqInfo->hMsgQ,  pApp->cAppName, eReleaseType, pTag,
518                                           pFullFolderPath, hUser);
519     } else {
520       eStatus = eFrameworkunifiedStatusNullPointer;
521     }
522   } else {
523     eStatus = eFrameworkunifiedStatusInvldParam;
524   }
525
526   return eStatus;
527 }
528
529 // 20110429_brp
530 // defined for backward compatibility; will be removed once the persistence feature is finalized
531 EFrameworkunifiedStatus FrameworkunifiedRegisterPersistentStorage(HANDLE hApp, PCSTR pFullFilePath) {
532   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
533
534   if (frameworkunifiedCheckValidAppHandle(hApp) && pFullFilePath) {
535     eStatus = FrameworkunifiedNPRegisterPersistentFile(hApp, pFullFilePath);
536   } else {
537     eStatus = eFrameworkunifiedStatusInvldParam;
538   }
539
540   return eStatus;
541 }
542 EFrameworkunifiedStatus FrameworkunifiedReleaseFileToPersistentStorage(HANDLE hApp, PCSTR pFullFilePath, BOOL persist) {
543   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
544
545   if (frameworkunifiedCheckValidAppHandle(hApp) && pFullFilePath) {
546     eStatus = FrameworkunifiedNPReleasePersistentFile(hApp, persist, pFullFilePath, pFullFilePath);
547   } else {
548     eStatus = eFrameworkunifiedStatusInvldParam;
549   }
550
551   return eStatus;
552 }
553
554 ////////////////////////////////////////////////////////////////////////////////////////////
555 /// FrameworkunifiedNPHSMRegisterNotificationsEvents
556 /// API to send message to Notification Service to register a notification
557 ////////////////////////////////////////////////////////////////////////////////////////////
558 EFrameworkunifiedStatus FrameworkunifiedNPHSMRegisterNotificationsEvents(HANDLE hApp, const  FrameworkunifiedNotificationsList *pList,
559                                                UI_32 uiListLength) {
560   return FrameworkunifiedNPRegisterNotifications(hApp, pList, uiListLength);
561 }
562
563 ////////////////////////////////////////////////////////////////////////////////////////////
564 /// FrameworkunifiedNPHSMRegisterNotificatsionEvent
565 /// API to send message to Notification Service to register a notification
566 ////////////////////////////////////////////////////////////////////////////////////////////
567 EFrameworkunifiedStatus FrameworkunifiedNPHSMRegisterNotificatsionEvent(HANDLE hApp, PCSTR pNotification, const UI_32 max_length,
568                                               const EFrameworkunifiedNotificationType persType) {
569   return FrameworkunifiedNPRegisterNotification(hApp, pNotification, max_length, persType);
570 }
571
572 ////////////////////////////////////////////////////////////////////////////////////////////
573 /// FrameworkunifiedNPHSMUnRegisterNotificationEvent
574 /// API to send message to Notification Service to remove a notification
575 ////////////////////////////////////////////////////////////////////////////////////////////
576 EFrameworkunifiedStatus FrameworkunifiedNPHSMUnRegisterNotificationEvent(HANDLE hApp, PCSTR pNotification) {
577   return FrameworkunifiedNPUnRegisterNotification(hApp, pNotification);
578 }
579
580 ////////////////////////////////////////////////////////////////////////////////////////////
581 /// FrameworkunifiedNPHSMSubscribeToNotificationsEvents
582 /// API to send message to Notification Service to add multiple subscriptions list for
583 /// that notification
584 ////////////////////////////////////////////////////////////////////////////////////////////
585 EFrameworkunifiedStatus FrameworkunifiedNPHSMSubscribeToNotificationsEvents(HANDLE hApp, const  FrameworkunifiedNotificationEvent *pList,
586                                                   UI_32 uiListLength) {
587   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
588
589   if (frameworkunifiedCheckValidAppHandle(hApp) && pList) {
590     CFrameworkunifiedFrameworkApp *pApp = static_cast<CFrameworkunifiedFrameworkApp *>(hApp);
591     MsgQInfo *pMqInfo = static_cast<MsgQInfo *>(pApp->hNPSndMsgQ);
592
593     SubscribeInfo *pSubscribeList =
594       reinterpret_cast<SubscribeInfo *>(malloc(sizeof(SubscribeInfo) * uiListLength));
595
596     for (UI_32 i = 0; i < uiListLength; ++i) {
597       strlcpy(pSubscribeList[i].notificationName, pList[i].cNotification,
598         sizeof(pSubscribeList[i].notificationName));
599     }
600     eStatus = NPSubscribeToNotifications(pMqInfo->hMsgQ, pApp->cAppName, uiListLength, pSubscribeList);
601
602     free(pSubscribeList);
603     pSubscribeList = NULL;  // mb20110110 Fixed per  comment 307
604   } else {
605     eStatus = eFrameworkunifiedStatusInvldParam;
606   }
607
608   return eStatus;
609 }
610
611 ////////////////////////////////////////////////////////////////////////////////////////////
612 ///  FrameworkunifiedNPHSMSubscribeToNotificationEvent
613 /// API to send message to Notification Service to add to subscription list for
614 /// that notification
615 ////////////////////////////////////////////////////////////////////////////////////////////
616 EFrameworkunifiedStatus FrameworkunifiedNPHSMSubscribeToNotificationEvent(HANDLE hApp, PCSTR pNotification) {
617   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
618
619   if (frameworkunifiedCheckValidAppHandle(hApp) && pNotification) {
620     CFrameworkunifiedFrameworkApp *pApp = static_cast<CFrameworkunifiedFrameworkApp *>(hApp);
621     MsgQInfo *pMqInfo = static_cast<MsgQInfo *>(pApp->hNPSndMsgQ);
622
623     eStatus = NPSubscribeToNotification(pMqInfo->hMsgQ,  pApp->cAppName, pNotification);
624   } else {
625     eStatus = eFrameworkunifiedStatusInvldParam;
626   }
627
628   return eStatus;
629 }
630
631 ////////////////////////////////////////////////////////////////////////////////////////////
632 /// FrameworkunifiedNPHSMUnsubscribeFromNotificationEvent
633 /// API to send message to Notification Service to remove from subscription list for
634 /// that notification
635 ////////////////////////////////////////////////////////////////////////////////////////////
636 EFrameworkunifiedStatus FrameworkunifiedNPHSMUnsubscribeFromNotificationEvent(HANDLE hApp, PCSTR pNotification) {
637   return FrameworkunifiedNPUnsubscribeFromNotification(hApp, pNotification);
638 }
639
640 ////////////////////////////////////////////////////////////////////////////////////////////
641 /// FrameworkunifiedNPHSMUnsubscribeFromNotificationEvents
642 /// API to send message to Notification Service to remove from subscription list for
643 /// that notification
644 ////////////////////////////////////////////////////////////////////////////////////////////
645 EFrameworkunifiedStatus FrameworkunifiedNPHSMUnsubscribeFromNotificationEvents(HANDLE hApp, const  FrameworkunifiedNotificationEvent *pList,
646                                                      UI_32 uiListLength) {
647   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
648
649   if (frameworkunifiedCheckValidAppHandle(hApp) && pList) {
650     CFrameworkunifiedFrameworkApp *pApp = static_cast<CFrameworkunifiedFrameworkApp *>(hApp);
651     MsgQInfo *pMqInfo = static_cast<MsgQInfo *>(pApp->hNPSndMsgQ);
652
653     SubscribeInfo *pSubscribeList =
654     reinterpret_cast<SubscribeInfo *>(malloc(sizeof(SubscribeInfo) * uiListLength));
655
656     for (UI_32 i = 0; i < uiListLength; ++i) {
657       strlcpy(pSubscribeList[i].notificationName, pList[i].cNotification,
658         sizeof(pSubscribeList[i].notificationName));
659     }
660     eStatus = NPUnsubscribeFromNotifications(pMqInfo->hMsgQ, pApp->cAppName, uiListLength, pSubscribeList);
661
662     free(pSubscribeList);
663     pSubscribeList = NULL;  // mb20110110 Fixed per  comment 307
664   } else {
665     eStatus = eFrameworkunifiedStatusInvldParam;
666   }
667
668   return eStatus;
669 }
670
671 ////////////////////////////////////////////////////////////////////////////////////////////
672 /// FrameworkunifiedNPSetPersonality
673 ////////////////////////////////////////////////////////////////////////////////////////////
674 EFrameworkunifiedStatus FrameworkunifiedNPSetPersonality(HANDLE hApp, PCSTR pUserName) {
675   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
676
677   if (frameworkunifiedCheckValidAppHandle(hApp) && pUserName) {
678     CFrameworkunifiedFrameworkApp *pApp = static_cast<CFrameworkunifiedFrameworkApp *>(hApp);
679     MsgQInfo *pMqInfo = static_cast<MsgQInfo *>(pApp->hNPSndMsgQ);
680
681     eStatus = NPSetPersonality(pMqInfo->hMsgQ,  pApp->cAppName, pUserName);
682   } else {
683     eStatus = eFrameworkunifiedStatusInvldParam;
684   }
685
686   return eStatus;
687 }
688
689 ////////////////////////////////////////////////////////////////////////////////////////////
690 /// FrameworkunifiedNPChangePersonality
691 ////////////////////////////////////////////////////////////////////////////////////////////
692 EFrameworkunifiedStatus FrameworkunifiedNPChangePersonality(HANDLE hApp, PCSTR pUserName) {
693   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
694
695   if (frameworkunifiedCheckValidAppHandle(hApp) && pUserName) {
696     CFrameworkunifiedFrameworkApp *pApp = static_cast<CFrameworkunifiedFrameworkApp *>(hApp);
697     MsgQInfo *pMqInfo = static_cast<MsgQInfo *>(pApp->hNPSndMsgQ);
698
699     eStatus = NPChangePersonality(pMqInfo->hMsgQ,  pApp->cAppName, pUserName);
700   } else {
701     eStatus = eFrameworkunifiedStatusInvldParam;
702   }
703
704   return eStatus;
705 }
706
707 ////////////////////////////////////////////////////////////////////////////////////////////
708 /// FrameworkunifiedSendStopToNSNPP
709 ////////////////////////////////////////////////////////////////////////////////////////////
710 EFrameworkunifiedStatus FrameworkunifiedSendStopToNSNPP(HANDLE hApp, EFrameworkunifiedShutdownType eShutdownType, UI_32 uiStopMsgData) {
711   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
712
713   if (frameworkunifiedCheckValidAppHandle(hApp)) {
714     CFrameworkunifiedFrameworkApp *pApp = static_cast<CFrameworkunifiedFrameworkApp *>(hApp);
715     MsgQInfo *pMqInfo = static_cast<MsgQInfo *>(pApp->hNPSndMsgQ);
716
717     eStatus = SendStopToNSNPP(pMqInfo->hMsgQ,  pApp->cAppName, eShutdownType, uiStopMsgData);
718   } else {
719     eStatus = eFrameworkunifiedStatusInvldParam;
720   }
721
722   return eStatus;
723 }
724
725 ////////////////////////////////////////////////////////////////////////////////////////////
726 /// FrameworkunifiedNPGetReadyStatusOfNPP
727 ////////////////////////////////////////////////////////////////////////////////////////////
728 EFrameworkunifiedStatus FrameworkunifiedNPGetReadyStatusOfNPP(HANDLE hApp) {
729   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
730
731   if (frameworkunifiedCheckValidAppHandle(hApp)) {
732     CFrameworkunifiedFrameworkApp *pApp = static_cast<CFrameworkunifiedFrameworkApp *>(hApp);
733     MsgQInfo *pMqInfo = static_cast<MsgQInfo *>(pApp->hNPSndMsgQ);
734
735     eStatus = NPGetReadyStatusOfNPP(pMqInfo->hMsgQ,  pApp->cAppName);
736   } else {
737     eStatus = eFrameworkunifiedStatusInvldParam;
738   }
739
740   return eStatus;
741 }
742
743 ////////////////////////////////////////////////////////////////////////////////////////////
744 /// FrameworkunifiedNPClearPersistedData
745 ////////////////////////////////////////////////////////////////////////////////////////////
746 EFrameworkunifiedStatus FrameworkunifiedNPClearPersistedData(HANDLE hApp, EFrameworkunifiedClearPersistence eFrameworkunifiedClearPersistenceScope) {
747   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
748   CFrameworkunifiedFrameworkApp *pApp = static_cast<CFrameworkunifiedFrameworkApp *>(hApp);
749   if (frameworkunifiedCheckValidAppHandle(hApp)) {
750     MsgQInfo *pMqInfo = static_cast<MsgQInfo *>(pApp->hNPSndMsgQ);
751     if (NULL != pMqInfo) {
752       eStatus = NPClearPersistedData(pMqInfo->hMsgQ,  pApp->cAppName, eFrameworkunifiedClearPersistenceScope);
753     } else {
754       eStatus = eFrameworkunifiedStatusNullPointer;
755     }
756   } else {
757     eStatus = eFrameworkunifiedStatusNullPointer;
758   }
759
760   return eStatus;
761 }
762
763 ////////////////////////////////////////////////////////////////////////////////////////////
764 /// FrameworkunifiedNPSetPersistNotfnDefaultValue
765 ////////////////////////////////////////////////////////////////////////////////////////////
766 EFrameworkunifiedStatus FrameworkunifiedNPSetPersistNotfnDefaultValue(HANDLE hApp, PCSTR pNotification, PVOID pData,
767                                             const UI_32 uiLength) {
768   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
769
770   if ((frameworkunifiedCheckValidAppHandle(hApp)) && (NULL != pNotification)) {
771     CFrameworkunifiedFrameworkApp *pApp = static_cast<CFrameworkunifiedFrameworkApp *>(hApp);
772
773     MsgQInfo *pMqInfo = static_cast<MsgQInfo *>(pApp->hNPSndMsgQ);
774
775     if (NULL != pMqInfo) {
776       eStatus = NPSetPersistNotfnDefaultValue(pMqInfo->hMsgQ,
777                                               pApp->cAppName,
778                                               pNotification,
779                                               pData,
780                                               uiLength);
781     } else {
782       eStatus = eFrameworkunifiedStatusNullPointer;
783     }
784   } else {
785     eStatus = eFrameworkunifiedStatusInvldParam;
786   }
787
788   return eStatus;
789 }
790
791 ////////////////////////////////////////////////////////////////////////////////////////////
792 /// FrameworkunifiedNPSetPersistentNotfnType
793 ////////////////////////////////////////////////////////////////////////////////////////////
794 EFrameworkunifiedStatus FrameworkunifiedNPSetPersistentNotfnType(HANDLE hApp, PCSTR pNotification, EFrameworkunifiedPersistCategory ePersistCategory) {
795   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
796
797   if ((frameworkunifiedCheckValidAppHandle(hApp)) && (NULL != pNotification)) {
798     CFrameworkunifiedFrameworkApp *pApp = static_cast<CFrameworkunifiedFrameworkApp *>(hApp);
799
800     MsgQInfo *pMqInfo = static_cast<MsgQInfo *>(pApp->hNPSndMsgQ);
801     if (NULL != pMqInfo) {
802       eStatus = NPSetPersistentNotfnType(pMqInfo->hMsgQ,
803                                          pApp->cAppName,
804                                          pNotification,
805                                          ePersistCategory);
806     } else {
807       eStatus = eFrameworkunifiedStatusNullPointer;
808     }
809   } else {
810     eStatus = eFrameworkunifiedStatusInvldParam;
811   }
812
813   return eStatus;
814 }
815
816 ////////////////////////////////////////////////////////////////////////////////////////////
817 /// FrameworkunifiedNPSetFilePersistentType
818 ////////////////////////////////////////////////////////////////////////////////////////////
819 EFrameworkunifiedStatus FrameworkunifiedNPSetFilePersistentType(HANDLE hApp, PCSTR pTag, EFrameworkunifiedPersistCategory ePersistCategory) {
820   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
821
822   if ((frameworkunifiedCheckValidAppHandle(hApp)) && (NULL != pTag)) {
823     CFrameworkunifiedFrameworkApp *pApp = static_cast<CFrameworkunifiedFrameworkApp *>(hApp);
824
825     MsgQInfo *pMqInfo = static_cast<MsgQInfo *>(pApp->hNPSndMsgQ);
826
827     if (NULL != pMqInfo) {
828       eStatus = NPSetFilePersistentType(pMqInfo->hMsgQ,
829                                         pApp->cAppName,
830                                         pTag,
831                                         ePersistCategory);
832     } else {
833       eStatus = eFrameworkunifiedStatusNullPointer;
834     }
835   } else {
836     eStatus = eFrameworkunifiedStatusInvldParam;
837   }
838
839   return eStatus;
840 }
841
842 ////////////////////////////////////////////////////////////////////////////////////////////
843 /// FrameworkunifiedNPSetFolderPersistentType
844 ////////////////////////////////////////////////////////////////////////////////////////////
845 EFrameworkunifiedStatus FrameworkunifiedNPSetFolderPersistentType(HANDLE hApp, PCSTR pTag, EFrameworkunifiedPersistCategory ePersistCategory) {
846   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
847
848   if ((frameworkunifiedCheckValidAppHandle(hApp)) && (NULL != pTag)) {
849     CFrameworkunifiedFrameworkApp *pApp = static_cast<CFrameworkunifiedFrameworkApp *>(hApp);
850
851     MsgQInfo *pMqInfo = static_cast<MsgQInfo *>(pApp->hNPSndMsgQ);
852
853     if (NULL != pMqInfo) {
854       eStatus = NPSetFolderPersistentType(pMqInfo->hMsgQ,
855                                           pApp->cAppName,
856                                           pTag,
857                                           ePersistCategory);
858     } else {
859       eStatus = eFrameworkunifiedStatusNullPointer;
860     }
861   } else {
862     eStatus = eFrameworkunifiedStatusInvldParam;
863   }
864
865   return eStatus;
866 }
867