Re-organized sub-directory by category
[staging/basesystem.git] / service / native / framework_unified / client / NS_FrameworkCore / src / statemachine / frameworkunified_sm_framework_dispatch.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
20 ///
21 ///
22 //////////////////////////////////////////////////////////////////////////////////////////////////
23
24 #include <native_service/frameworkunified_sm_framework_dispatch.h>
25 #include <native_service/frameworkunified_framework_if.h>
26 #include <native_service/frameworkunified_service_protocol.h>
27 #include <native_service/ns_message_center_if.h>
28 #include <native_service/ns_logger_if.h>
29 #include <map>
30 #include <utility>
31 #include "frameworkunified_framework_core.h"
32
33 ////////////////////////////////////////////////////////////////////////////////////////////
34 /// Registers a single event with the dispatcher for a given service.
35 ////////////////////////////////////////////////////////////////////////////////////////////
36 EFrameworkunifiedStatus FrameworkunifiedAttachHSMEventToDispatcher(HANDLE hApp,
37                                          PCSTR pServiceName,
38                                          UI_32 iCmd,
39                                          UI_32 iEvent,
40                                          HANDLE hSession) {
41   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
42
43   if (frameworkunifiedCheckValidAppHandle(hApp) && pServiceName) {
44     CFrameworkunifiedFrameworkApp *pApp = static_cast<CFrameworkunifiedFrameworkApp *>(hApp);
45     EventServices::iterator s_iterator;
46     EventSessionTable::iterator session_iterator;
47
48     UI_32 uiSessionId = 0;
49     if (hSession) {
50       uiSessionId = FrameworkunifiedGetSessionId(hSession);
51     }
52
53     // finding the service
54     s_iterator = pApp->eventservices.find(pServiceName);
55     if (s_iterator == pApp->eventservices.end()) {
56       FRAMEWORKUNIFIEDLOG(ZONE_NS_DIS, __FUNCTION__, "%s : (service NOT found): service name [%s]", pApp->cAppName, pServiceName);
57       pApp->eventservices.insert(std::make_pair(pServiceName, EventSessionTable()));
58     }
59
60     session_iterator = pApp->eventservices[pServiceName].find(uiSessionId);
61     if (session_iterator == pApp->eventservices[pServiceName].end()) {
62       pApp->eventservices[pServiceName].insert
63       (std::make_pair(uiSessionId, ServiceEventProtocolTable()));
64     }
65
66     (pApp->eventservices[pServiceName].find(uiSessionId)->second).insert(std::make_pair(iCmd, iEvent));
67   } else {
68     eStatus = eFrameworkunifiedStatusInvldHandle;
69   }
70
71   return eStatus;
72 }
73
74
75 ////////////////////////////////////////////////////////////////////////////////////////////
76 /// FrameworkunifiedAttachHSMEventsToDispatcher
77 /// Registers a multiple event with the dispatcher for a given service.
78 ////////////////////////////////////////////////////////////////////////////////////////////
79
80 EFrameworkunifiedStatus FrameworkunifiedAttachHSMEventsToDispatcher(HANDLE hApp, PCSTR pServiceName,
81                                           const FrameworkunifiedProtocolEvent *pEventIds, UI_32 uiEventCount, HANDLE hSession) {
82   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
83
84   if (frameworkunifiedCheckValidAppHandle(hApp) && pServiceName && pEventIds) {
85     // setup callbacks
86     for (UI_32 i = 0; i < uiEventCount; ++i) {
87       if (eFrameworkunifiedStatusOK != (eStatus = FrameworkunifiedAttachHSMEventToDispatcher(hApp,
88                                                                    pServiceName,
89                                                                    pEventIds[ i ].iCmd,
90                                                                    pEventIds[ i ].iEventId,
91                                                                    hSession))) {
92         break;
93       }
94     }
95   } else {
96     eStatus = eFrameworkunifiedStatusInvldHandle;
97   }
98
99   return eStatus;
100 }
101
102 /////////////////////////////////////////////////////
103 // Function : FrameworkunifiedAttachParentCallbacksToDispatcher
104 /////////////////////////////////////////////////////
105 EFrameworkunifiedStatus FrameworkunifiedAttachParentHSMEventsToDispatcher(HANDLE hChildApp, const FrameworkunifiedProtocolEvent *pEventIds,
106                                                 UI_32 uiEventCount) {
107   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
108
109   if (frameworkunifiedCheckValidAppHandle(hChildApp)) {
110     CFrameworkunifiedFrameworkApp *pApp = static_cast<CFrameworkunifiedFrameworkApp *>(hChildApp);
111
112     eStatus = FrameworkunifiedAttachHSMEventsToDispatcher(hChildApp, pApp->cParentAppName, pEventIds, uiEventCount);
113   } else {
114     eStatus = eFrameworkunifiedStatusInvldHandle;
115   }
116
117   return eStatus;
118 }
119
120 /////////////////////////////////////////////////////
121 // Function : FrameworkunifiedDetachParentCallbacksFromDispatcher
122 /////////////////////////////////////////////////////
123 EFrameworkunifiedStatus FrameworkunifiedDetachParentHSMEventsFromDispatcher(HANDLE hChildApp,
124                                                   const PUI_32 puiEventArray, UI_32 uiEventCount) {
125   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
126
127   if (frameworkunifiedCheckValidAppHandle(hChildApp)) {
128     CFrameworkunifiedFrameworkApp *pApp = static_cast<CFrameworkunifiedFrameworkApp *>(hChildApp);
129
130     eStatus = FrameworkunifiedDetachHSMEventsFromDispatcher(hChildApp, pApp->cParentAppName, puiEventArray, uiEventCount);
131   } else {
132     eStatus = eFrameworkunifiedStatusInvldHandle;
133   }
134
135   return eStatus;
136 }
137
138
139 /////////////////////////////////////////////////////
140 // Function : FrameworkunifiedDetachHSMEventsFromDispatcher
141 /////////////////////////////////////////////////////
142 EFrameworkunifiedStatus FrameworkunifiedDetachHSMEventsFromDispatcher(HANDLE hApp, PCSTR pServiceName, const PUI_32 puiEventArray,
143                                             UI_32 uiEventCount, HANDLE hSession) {
144   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
145
146   if (frameworkunifiedCheckValidAppHandle(hApp) && pServiceName) {
147     // setup callbacks
148     for (UI_32 i = 0; i < uiEventCount; ++i) {
149       /**
150        * @todo
151        *  When an event-struct pointer is turned NULL, the array is accessed without NULL checking,
152        *  and a segmentation fault occurs.
153        */
154       if (eFrameworkunifiedStatusOK != (eStatus = FrameworkunifiedDetachHSMEventFromDispatcher(hApp, pServiceName,
155                                                                 puiEventArray[ i ], hSession))) {
156         break;
157       }
158     }
159   } else {
160     eStatus = eFrameworkunifiedStatusInvldHandle;
161   }
162
163   return eStatus;
164 }
165
166
167 /////////////////////////////////////////////
168 // Function : FrameworkunifiedDetachHSMEventFromDispatcher
169 /////////////////////////////////////////////
170 EFrameworkunifiedStatus FrameworkunifiedDetachHSMEventFromDispatcher(HANDLE hApp, PCSTR pServiceName, UI_32 iEvent, HANDLE hSession) {
171   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
172   if (frameworkunifiedCheckValidAppHandle(hApp) && pServiceName) {
173     CFrameworkunifiedFrameworkApp *pApp = static_cast<CFrameworkunifiedFrameworkApp *>(hApp);
174     EventServices::iterator s_iterator;
175
176     UI_32 uiSessionId = 0;
177     if (hSession) {
178       uiSessionId = FrameworkunifiedGetSessionId(hSession);
179     }
180
181     // finding the service
182     s_iterator = pApp->eventservices.find(pServiceName);
183     if (s_iterator != pApp->eventservices.end()) {
184       EventSessionTable::iterator session_iterator;
185       session_iterator = (s_iterator->second).find(uiSessionId);
186       if (session_iterator != (s_iterator->second).end()) {
187         ServiceEventProtocolTable::iterator spt_iterator;
188         FRAMEWORKUNIFIEDLOG(ZONE_NS_DIS, __FUNCTION__, "%s : (found): service [%s]", pApp->cAppName, pServiceName);
189
190         spt_iterator = (session_iterator->second).find(iEvent);
191         if (spt_iterator != (session_iterator->second).end()) {
192           FRAMEWORKUNIFIEDLOG(ZONE_NS_DIS, __FUNCTION__, "%s : Cmd found [%d] service [%s]",
193             pApp->cAppName, iEvent, pServiceName);
194           (session_iterator->second).erase(spt_iterator);
195         } else {
196           FRAMEWORKUNIFIEDLOG(ZONE_NS_DIS, __FUNCTION__, "%s : Error : Cmd NOT found [%d] service [%s]",
197             pApp->cAppName, iEvent, pServiceName);
198         }
199       }
200
201     } else {
202       FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "%s : Error : Cannot find service [%s]", pApp->cAppName, pServiceName);
203       eStatus = eFrameworkunifiedStatusFail;
204     }
205
206   } else {
207     eStatus = eFrameworkunifiedStatusInvldHandle;
208   }
209
210   return eStatus;
211 }
212
213 ////////////////////////////////////////////////////////////////////////////////////////////
214 /// FrameworkunifiedAttachNotificationEventsToDispatcher
215 /// API to attach a event to the dispatcher on receiving a specific notification.
216 ////////////////////////////////////////////////////////////////////////////////////////////
217 EFrameworkunifiedStatus FrameworkunifiedSubscribeNotificationsWithHSMEvent(HANDLE hApp,  const FrameworkunifiedNotificationEvent *pNtfyEvent,
218                                                  UI_32 uiEventCount) {
219   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
220
221   if (frameworkunifiedCheckValidAppHandle(hApp) && pNtfyEvent) {
222     CFrameworkunifiedFrameworkApp *pApp = static_cast<CFrameworkunifiedFrameworkApp *>(hApp);
223
224     /// Deal with handling batch processing of subscriptions.
225     if (eFrameworkunifiedStatusOK == (eStatus = FrameworkunifiedNPHSMSubscribeToNotificationsEvents(hApp, pNtfyEvent, uiEventCount))) {
226       for (UI_32 i = 0; i < uiEventCount; ++i) {
227         // service found
228         pApp->notificationevents.insert(std::make_pair(pNtfyEvent[ i ].cNotification, pNtfyEvent[ i ].iEventId));
229
230         FRAMEWORKUNIFIEDLOG(ZONE_NS_DIS, __FUNCTION__, "%s : attaching call-back for notification [%s]", pApp->cAppName,
231                pNtfyEvent[ i ].cNotification);
232       }
233     } else {
234       FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "%s : Error : [%d] Unable to Subscribe "
235         "to batch set of notifications", pApp->cAppName,
236              eStatus);
237     }
238   } else {
239     eStatus = eFrameworkunifiedStatusInvldParam;
240   }
241
242   return eStatus;
243 }
244
245 ////////////////////////////////////////////////////////////////////////////////////////////
246 /// FrameworkunifiedAttachNotificationEventToDispatcher
247 /// API to attach a event to the dispatcher on receiving a specific notification.
248 ////////////////////////////////////////////////////////////////////////////////////////////
249 EFrameworkunifiedStatus FrameworkunifiedSubscribeNotificationWithHSMEvent(HANDLE hApp, PCSTR pNotification, UI_32 iEventId) {
250   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
251
252   if (frameworkunifiedCheckValidAppHandle(hApp) && pNotification) {
253     CFrameworkunifiedFrameworkApp *pApp = static_cast<CFrameworkunifiedFrameworkApp *>(hApp);
254
255     if (eFrameworkunifiedStatusOK == (eStatus = FrameworkunifiedNPHSMSubscribeToNotificationEvent(hApp, pNotification))) {
256       // service found
257       pApp->notificationevents.insert(std::make_pair(pNotification, iEventId));
258
259       FRAMEWORKUNIFIEDLOG(ZONE_NS_DIS, __FUNCTION__, "%s : attaching call-back for notification [%s]",
260         pApp->cAppName, pNotification);
261     } else {
262       FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "%s : Error : [%d] Unable to Subscribe "
263         "to notification [%s]", pApp->cAppName, eFrameworkunifiedStatusOK, pNotification);
264     }
265   } else {
266     eStatus = eFrameworkunifiedStatusInvldHandle;
267   }
268
269   return eStatus;
270 }
271
272
273
274 ////////////////////////////////////////////////////////////////////////////////////////////
275 /// FrameworkunifiedDetachNotificationEventsFromDispatcher
276 /// API to detach a notification event from the dispatcher.
277 ////////////////////////////////////////////////////////////////////////////////////////////
278 EFrameworkunifiedStatus FrameworkunifiedUnsubscribeNotificationsWithHSMEvent(HANDLE hApp,  const FrameworkunifiedNotificationEvent *pNtfyEvent,
279                                                    UI_32 uiEventCount) {
280   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
281
282   if (frameworkunifiedCheckValidAppHandle(hApp) && pNtfyEvent) {
283     CFrameworkunifiedFrameworkApp *pApp = static_cast<CFrameworkunifiedFrameworkApp *>(hApp);
284
285     NotificationEventTable::iterator n_iterator;
286     PCSTR pNotification = NULL;
287
288     if (eFrameworkunifiedStatusOK == (eStatus = FrameworkunifiedNPHSMUnsubscribeFromNotificationEvents(hApp, pNtfyEvent, uiEventCount))) {
289       for (UI_32 l_unCount = 0; l_unCount < uiEventCount; ++l_unCount) {
290         pNotification = pNtfyEvent[ l_unCount ].cNotification;
291         n_iterator = pApp->notificationevents.find(pNotification);
292         if (n_iterator != pApp->notificationevents.end()) {
293           pApp->notificationevents.erase(n_iterator);
294           FRAMEWORKUNIFIEDLOG(ZONE_NS_DIS, __FUNCTION__, "%s : removed notification [%s]", pApp->cAppName, pNotification);
295         } else {
296           FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "%s : Error : Cannot find notification [%s]",
297             pApp->cAppName, pNotification);
298           eStatus = eFrameworkunifiedStatusFail;
299         }
300       }
301
302       FRAMEWORKUNIFIEDLOG(ZONE_NS_DIS, __FUNCTION__, "%s : detaching call-back for notification [%s]",
303         pApp->cAppName, pNotification);
304     } else {
305       FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "%s : Error : [%d] Unable to UnSubscribe from notifications ",
306         pApp->cAppName, eFrameworkunifiedStatusOK);
307     }
308   } else {
309     eStatus = eFrameworkunifiedStatusInvldHandle;
310   }
311
312   return eStatus;
313 }
314
315
316 ////////////////////////////////////////////////////////////////////////////////////////////
317 /// FrameworkunifiedDetachNotificationEventsFromDispatcher
318 /// API to detach a notification event from the dispatcher.
319 ////////////////////////////////////////////////////////////////////////////////////////////
320 EFrameworkunifiedStatus FrameworkunifiedUnsubscribeNotificationWithHSMEvent(HANDLE hApp, PCSTR pNotification) {
321   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
322
323   if (frameworkunifiedCheckValidAppHandle(hApp) && pNotification) {
324     CFrameworkunifiedFrameworkApp *pApp = static_cast<CFrameworkunifiedFrameworkApp *>(hApp);
325     NotificationEventTable::iterator n_iterator;
326
327     if (eFrameworkunifiedStatusOK == (eStatus = FrameworkunifiedNPHSMUnsubscribeFromNotificationEvent(hApp, pNotification))) {
328       // \todo : error handling on all map function calls
329       n_iterator = pApp->notificationevents.find(pNotification);
330       if (n_iterator != pApp->notificationevents.end()) {
331         pApp->notificationevents.erase(n_iterator);
332         FRAMEWORKUNIFIEDLOG(ZONE_NS_DIS, __FUNCTION__, "%s : removed notification [%s]", pApp->cAppName, pNotification);
333       } else {
334         FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "%s : Error : Cannot find notification [%s]",
335           pApp->cAppName, pNotification);
336         eStatus = eFrameworkunifiedStatusFail;
337       }
338     } else {
339       FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "%s : Error : [%d] Unable to UnSubscribe from notification [%s]",
340         pApp->cAppName, eFrameworkunifiedStatusOK, pNotification);
341     }
342   } else {
343     eStatus = eFrameworkunifiedStatusInvldHandle;
344   }
345
346   return eStatus;
347 }
348
349 ////////////////////////////////////////////////////////////////////////////////////////////
350 /// FrameworkunifiedGetStateMachine
351 ///   returns the pointer to the statemachine object
352 ////////////////////////////////////////////////////////////////////////////////////////////
353 CFrameworkunifiedHSMFramework *FrameworkunifiedGetStateMachine(HANDLE hApp) {
354   CFrameworkunifiedHSMFramework *l_pHSMFramework = NULL;
355
356   if (frameworkunifiedCheckValidAppHandle(hApp)) {
357     CFrameworkunifiedFrameworkApp *pApp = static_cast<CFrameworkunifiedFrameworkApp *>(hApp);
358     l_pHSMFramework = pApp->m_pFrameworkunifiedStateMachine;
359   }
360
361   return l_pHSMFramework;
362 }
363
364 ////////////////////////////////////////////////////////////////////////////////////////////
365 /// FrameworkunifiedSetStateMachine
366 ///   sets the statemachine object
367 ////////////////////////////////////////////////////////////////////////////////////////////
368 EFrameworkunifiedStatus FrameworkunifiedSetStateMachine(HANDLE hApp,
369                               CFrameworkunifiedHSM *f_pFrameworkunifiedHSM) {
370   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
371
372   if (frameworkunifiedCheckValidAppHandle(hApp)) {
373     if (NULL != f_pFrameworkunifiedHSM) {
374       (reinterpret_cast<CFrameworkunifiedFrameworkApp *>(hApp))->m_pFrameworkunifiedStateMachine =
375       reinterpret_cast<CFrameworkunifiedHSMFramework *>(f_pFrameworkunifiedHSM);
376     } else {
377       eStatus = eFrameworkunifiedStatusNullPointer;
378     }
379   } else {
380     eStatus = eFrameworkunifiedStatusInvldHandle;
381   }
382
383   return eStatus;
384 }
385
386 ////////////////////////////////////////////////////////////////////////////////////////////
387 /// FrameworkunifiedSubscribeToSessionEventWithHSMEvent
388 /// This API is used for subscribing to single event of a service.
389 /// This API also attaches the session event with HSM events.
390 ////////////////////////////////////////////////////////////////////////////////////////////
391 EFrameworkunifiedStatus FrameworkunifiedSubscribeToSessionEventWithHSMEvent(HANDLE hApp,
392                                                   UI_32 uiEventId,
393                                                   UI_32 uiHSMEventId,
394                                                   HANDLE hSession) {
395   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
396
397   if (frameworkunifiedCheckValidAppHandle(hApp) && frameworkunifiedCheckValidMsgQ(hSession)) {
398     if (eFrameworkunifiedStatusOK == (eStatus = FrameworkunifiedAttachHSMEventToDispatcher(hApp,
399                                                     (reinterpret_cast<MsgQInfo *>(hSession))->cMsgQName, uiEventId,
400                                                     uiHSMEventId, hSession))) {
401       eStatus = FrameworkunifiedSendMsg(hSession, PROTOCOL_REGISTER_EVENTS, sizeof(UI_32), (PVOID)&uiEventId);
402     } else {
403       FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "FrameworkunifiedAttachCallbackToDispatcher "
404         "for PROTOCOL_REGISTER_EVENTS Failed Status:: %d", eStatus);
405     }
406   } else {
407     eStatus = eFrameworkunifiedStatusInvldHandle;
408   }
409
410   return eStatus;
411 }
412
413 ////////////////////////////////////////////////////////////////////////////////////////////
414 /// FrameworkunifiedSubscribeToSessionEventsWithHSMEvents
415 /// This API is used for subscribing to multiple events of a service.
416 /// This API also attaches the session events with hsm events.
417 ////////////////////////////////////////////////////////////////////////////////////////////
418 EFrameworkunifiedStatus FrameworkunifiedSubscribeToSessionEventsWithHSMEvents(HANDLE hApp, const FrameworkunifiedProtocolEvent *pEventIds,
419                                                     UI_32 uiEventCount,
420                                                     HANDLE hSession) {
421   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
422
423   if (frameworkunifiedCheckValidAppHandle(hApp) && frameworkunifiedCheckValidMsgQ(hSession) && NULL != pEventIds) {
424     eStatus = FrameworkunifiedAttachHSMEventsToDispatcher(hApp,
425       (reinterpret_cast<MsgQInfo *>(hSession))->cMsgQName, pEventIds,
426       uiEventCount, hSession);
427
428     UI_32 l_uiCmdList[uiEventCount];  // NOLINT  (readability/nolint)
429     for (UI_32 l_uiCnt = 0; l_uiCnt < uiEventCount; l_uiCnt++) {
430       l_uiCmdList[l_uiCnt] = pEventIds[l_uiCnt].iCmd;
431     }
432
433     eStatus = FrameworkunifiedSendMsg(hSession, PROTOCOL_REGISTER_EVENTS, static_cast<UI_32>(uiEventCount * sizeof(UI_32)),
434       l_uiCmdList);
435   } else {
436     eStatus = eFrameworkunifiedStatusInvldHandle;
437   }
438
439   return eStatus;
440 }
441
442 ////////////////////////////////////////////////////////////////////////////////////////////
443 /// FrameworkunifiedUnSubscribeSessionEventWithHSMEvent
444 /// API to unsubscribe from event of a service. Also detaches HSM event.
445 ////////////////////////////////////////////////////////////////////////////////////////////
446 EFrameworkunifiedStatus FrameworkunifiedUnSubscribeSessionEventWithHSMEvent(HANDLE hApp, UI_32 uiEventId, HANDLE hSession) {
447   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
448
449   if (frameworkunifiedCheckValidAppHandle(hApp) && frameworkunifiedCheckValidMsgQ(hSession)) {
450     eStatus = FrameworkunifiedSendMsg(hSession, PROTOCOL_UNREGISTER_EVENTS, sizeof(uiEventId), (PVOID)&uiEventId);
451
452     if (eFrameworkunifiedStatusOK != FrameworkunifiedDetachHSMEventFromDispatcher(hApp,
453       (reinterpret_cast<MsgQInfo *>(hSession))->cMsgQName, uiEventId, hSession)) {
454       FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Error : FrameworkunifiedDetachCallbackFromDispatcher failed status:: %d", eStatus);
455     }
456   } else {
457     eStatus = eFrameworkunifiedStatusInvldHandle;
458   }
459
460   return eStatus;
461 }
462
463 ////////////////////////////////////////////////////////////////////////////////////////////
464 /// FrameworkunifiedUnSubscribeSessionEventsWithHSMEvents
465 /// API to unsubscribe from multiple events of a service. Also detaches HSM events.
466 ////////////////////////////////////////////////////////////////////////////////////////////
467 EFrameworkunifiedStatus FrameworkunifiedUnSubscribeSessionEventsWithHSMEvents(HANDLE hApp, PUI_32 pEventsArray, UI_32 uiListSize,
468                                                     HANDLE hSession) {
469   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
470
471   if (frameworkunifiedCheckValidAppHandle(hApp) && frameworkunifiedCheckValidMsgQ(hSession) && NULL != pEventsArray) {
472     eStatus = FrameworkunifiedSendMsg(hSession, PROTOCOL_UNREGISTER_EVENTS,
473       static_cast<UI_32>(uiListSize * sizeof(uiListSize)), pEventsArray);
474
475     if (eFrameworkunifiedStatusOK != FrameworkunifiedDetachHSMEventsFromDispatcher(hApp,
476                                   (reinterpret_cast<MsgQInfo *>(hSession))->cMsgQName, pEventsArray,
477                                    uiListSize)) {
478       FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Error : FrameworkunifiedDetachCallbackFromDispatcher failed status:: %d", eStatus);
479     }
480   } else {
481     eStatus = eFrameworkunifiedStatusInvldHandle;
482   }
483
484   return eStatus;
485 }