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_NSFramework
19 /// \brief Framework service protocol session APIs implementation
23 ///////////////////////////////////////////////////////////////////////////////
26 #include <native_service/frameworkunified_framework_if.h>
27 #include <native_service/frameworkunified_framework_types.h>
28 #include <native_service/frameworkunified_service_protocol.h>
29 #include <native_service/ns_logger_if.h>
30 #include <other_service/strlcpy.h>
32 #include "frameworkunified_framework_core.h"
33 #include "frameworkunified_framework_internal.h"
35 //////////////////////////////////////////////////////
36 /// FrameworkunifiedOpenService
37 //////////////////////////////////////////////////////
38 HANDLE FrameworkunifiedOpenService(HANDLE hApp, PCSTR pServiceName) {
39 HANDLE hService = NULL;
41 if (frameworkunifiedCheckValidAppHandle(hApp) && NULL != pServiceName) {
42 if (NULL == (hService = FrameworkunifiedMcOpenSender(hApp, pServiceName))) {
43 // LCOV_EXCL_BR_START 15:marco defined in "native_service/ns_logger_if.h"
44 FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Error::hApp:0x%p, %s failed to FrameworkunifiedMcOpenSender", hApp, pServiceName);
47 CFrameworkunifiedFrameworkApp *pApp = static_cast<CFrameworkunifiedFrameworkApp *>(hApp);
48 frameworkunifiedAddConnectMonitor(hApp, pServiceName, pApp->cAppName);
51 FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__,
52 "Invalid param. hApp:0x%p, name:0x%p",
56 return static_cast<HANDLE>(hService);
59 //////////////////////////////////////////////////////
60 /// FrameworkunifiedCloseService
61 //////////////////////////////////////////////////////
62 EFrameworkunifiedStatus FrameworkunifiedCloseService(HANDLE hApp, HANDLE hService) {
63 EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
65 if (frameworkunifiedCheckValidAppHandle(hApp) && frameworkunifiedCheckValidMsgQ(hService)) {
66 CFrameworkunifiedFrameworkApp *pApp = static_cast<CFrameworkunifiedFrameworkApp *>(hApp);
67 MsgQInfo *pMsgQ = static_cast<MsgQInfo *>(hService);
69 if (eFrameworkunifiedStatusOK != frameworkunifiedDelConnectMonitor(hApp, pMsgQ->cMsgQName, pApp->cAppName)) {
70 FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Error : frameworkunifiedDelConnectMonitor(%s, %s) fail",
71 pMsgQ->cMsgQName != 0 ? pMsgQ->cMsgQName : NULL, pApp->cAppName != 0 ? pApp->cAppName : NULL);
74 if (eFrameworkunifiedStatusOK != (eStatus = FrameworkunifiedMcClose(hService))) {
75 FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Error : %s Failed to FrameworkunifiedMcClose",
76 pApp->cAppName != 0 ? pApp->cAppName : NULL);
79 eStatus = eFrameworkunifiedStatusInvldHandle;
85 HANDLE FrameworkunifiedGenerateSessionHandle(HANDLE hApp, PCSTR pServiceName) {
86 HANDLE l_pSession = NULL;
87 if ((frameworkunifiedCheckValidAppHandle(hApp)) && (NULL != pServiceName)) {
88 l_pSession = FrameworkunifiedMcOpenSender(hApp, pServiceName);
90 if (NULL != l_pSession) {
91 MsgQInfo *pMsgQ = reinterpret_cast<MsgQInfo *>(l_pSession);
92 pMsgQ->sessionId = FrameworkunifiedGenerateNewSessionId();
99 //////////////////////////////////////////////////////
100 /// FrameworkunifiedOpenSessionWithData
101 //////////////////////////////////////////////////////
102 EFrameworkunifiedStatus FrameworkunifiedOpenSessionWithData(HANDLE hService, PVOID pData, UI_32 length) {
103 return FrameworkunifiedSendMsg(hService, PROTOCOL_OPEN_SESSION_REQ, length, pData);
107 //////////////////////////////////////////////////////
108 /// FrameworkunifiedOpenSession
109 //////////////////////////////////////////////////////
110 EFrameworkunifiedStatus FrameworkunifiedOpenSession(HANDLE hService) {
112 return FrameworkunifiedSendMsg(hService, PROTOCOL_OPEN_SESSION_REQ, 0, &l_uiDummy);
115 //////////////////////////////////////////////////////
116 /// FrameworkunifiedOpenSessionWithDataSync
117 //////////////////////////////////////////////////////
118 EFrameworkunifiedStatus FrameworkunifiedOpenSessionWithDataSync(HANDLE hService, PVOID pData, UI_32 length, OpenSessionAck *ack) {
120 return FrameworkunifiedInvokeSync(hService, PROTOCOL_OPEN_SESSION_REQ_SYNC, length, pData, sizeof(OpenSessionAck), ack, &rcvLen);
124 //////////////////////////////////////////////////////
125 /// FrameworkunifiedOpenSessionSync
126 //////////////////////////////////////////////////////
127 EFrameworkunifiedStatus FrameworkunifiedOpenSessionSync(HANDLE hService, OpenSessionAck *ack) {
130 return FrameworkunifiedInvokeSync(hService, PROTOCOL_OPEN_SESSION_REQ_SYNC, 0, &l_uiDummy, sizeof(OpenSessionAck), ack, &rcvLen);
133 //////////////////////////////////////////////////////
134 /// FrameworkunifiedGetSessionHandle
135 //////////////////////////////////////////////////////
136 HANDLE FrameworkunifiedGetOpenSessionHandle(HANDLE hApp) {
137 HANDLE hSession = NULL;
139 if (frameworkunifiedCheckValidAppHandle(hApp)) {
142 if (sizeof(OpenSessionAck) == FrameworkunifiedGetMsgLength(hApp)) {
143 if (eFrameworkunifiedStatusOK != FrameworkunifiedGetMsgDataOfSize(hApp, &tAck, sizeof(tAck))) {
144 FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Error : FrameworkunifiedGetMsgDataOfSize");
146 if (eFrameworkunifiedStatusOK == tAck.eStatus) {
147 hSession = FrameworkunifiedMcOpenSender(hApp, tAck.cSessionName);
148 if (NULL != hSession) {
149 (reinterpret_cast<MsgQInfo *>(hSession))->sessionId = tAck.sessionId;
154 FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Error : FrameworkunifiedGetOpenSessionHandle");
161 //////////////////////////////////////////////////////
162 /// FrameworkunifiedGetOpenSessionSyncHandle
163 //////////////////////////////////////////////////////
164 HANDLE FrameworkunifiedGetOpenSessionSyncHandle(HANDLE hApp, OpenSessionAck *tAck) {
165 HANDLE hSession = NULL;
167 if (frameworkunifiedCheckValidAppHandle(hApp) && (NULL != tAck)) {
168 if (eFrameworkunifiedStatusOK == tAck->eStatus) {
169 hSession = FrameworkunifiedMcOpenSender(hApp, tAck->cSessionName);
170 if (NULL != hSession) {
171 (reinterpret_cast<MsgQInfo *>(hSession))->sessionId = tAck->sessionId;
179 //////////////////////////////////////////////////////
180 /// frameworkunifiedCloseSessionInner
181 //////////////////////////////////////////////////////
182 static EFrameworkunifiedStatus frameworkunifiedCloseSessionInner(HANDLE hService, HANDLE hSession, CloseSessionAck *ack) {
183 EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusInvldHandle;
184 CloseSessionReq tClose = {};
186 if (frameworkunifiedCheckValidMsgQ(hService) && frameworkunifiedCheckValidMsgQ(hSession)) {
187 tClose.sessionId = (reinterpret_cast<MsgQInfo *>(hSession))->sessionId;
188 strlcpy(tClose.cSessionName, (reinterpret_cast<MsgQInfo *>(hSession))->cMsgQName, sizeof(tClose.cSessionName));
190 FRAMEWORKUNIFIEDLOG(ZONE_NS_INFO, __FUNCTION__, "Info : sessionid %d", tClose.sessionId);
194 eStatus = FrameworkunifiedInvokeSync(hService, PROTOCOL_CLOSE_SESSION_REQ_SYNC, sizeof(tClose), (PVOID)&tClose,
195 sizeof(CloseSessionAck), ack, &rcvLen);
196 if (rcvLen != sizeof(CloseSessionAck)) {
197 FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Error : Invalid receive length %d", rcvLen);
200 eStatus = FrameworkunifiedSendMsg(hService, PROTOCOL_CLOSE_SESSION_REQ, sizeof(tClose), (PVOID)&tClose);
202 if (eFrameworkunifiedStatusOK == eStatus) {
203 eStatus = FrameworkunifiedMcClose(hSession);
210 //////////////////////////////////////////////////////
211 /// FrameworkunifiedCloseSession
212 //////////////////////////////////////////////////////
213 EFrameworkunifiedStatus FrameworkunifiedCloseSession(HANDLE hService, HANDLE hSession) {
214 return frameworkunifiedCloseSessionInner(hService, hSession, NULL);
217 //////////////////////////////////////////////////////
218 /// FrameworkunifiedCloseSessionSync
219 //////////////////////////////////////////////////////
220 EFrameworkunifiedStatus FrameworkunifiedCloseSessionSync(HANDLE hService, HANDLE hSession, CloseSessionAck *ack) {
222 return eFrameworkunifiedStatusInvldParam;
224 return frameworkunifiedCloseSessionInner(hService, hSession, ack);
227 //////////////////////////////////////////////////////
228 /// FrameworkunifiedGetSessionId -> On Client side
229 //////////////////////////////////////////////////////
230 UI_32 FrameworkunifiedGetSessionId(HANDLE hSession) {
231 if (frameworkunifiedCheckValidMsgQ(hSession)) {
232 return ((reinterpret_cast<MsgQInfo *>(hSession))->sessionId);
234 return MAX_SESSION_ID_VAL;
238 //////////////////////////////////////////////////////
239 /// FrameworkunifiedGetSessionId -> On Client side
240 //////////////////////////////////////////////////////
241 UI_32 FrameworkunifiedGetMsgSessionId(HANDLE hApp) {
242 if (frameworkunifiedCheckValidAppHandle(hApp)) {
243 CFrameworkunifiedFrameworkApp *pApp = static_cast<CFrameworkunifiedFrameworkApp *>(hApp);
244 return pApp->uiSessionId;
246 return MAX_SESSION_ID_VAL;
250 //////////////////////////////////////////////////////
251 /// GenerateNewSessionId -> On Server side
252 //////////////////////////////////////////////////////
253 UI_32 FrameworkunifiedGenerateNewSessionId() {
254 static UI_16 lastSessionId = 0;
256 UI_32 sessionId = (lastSessionId % MAX_SESSION_ID_VAL);
262 //////////////////////////////////////////////////////
263 /// FrameworkunifiedRegisterEvents
264 //////////////////////////////////////////////////////
265 EFrameworkunifiedStatus FrameworkunifiedRegisterEvents(HANDLE hSession, PVOID puiEventsArray, UI_32 uiListSize) {
266 EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
269 eStatus = FrameworkunifiedSendMsg(hSession, PROTOCOL_REGISTER_EVENTS,
270 static_cast<UI_32>(uiListSize * sizeof(uiListSize)), puiEventsArray);
272 eStatus = eFrameworkunifiedStatusInvldHandle;
278 //////////////////////////////////////////////////////
279 /// FrameworkunifiedRegisterEvent
280 //////////////////////////////////////////////////////
281 EFrameworkunifiedStatus FrameworkunifiedRegisterEvent(HANDLE hSession, UI_32 uiEvent) {
282 EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
285 eStatus = FrameworkunifiedSendMsg(hSession, PROTOCOL_REGISTER_EVENTS, sizeof(uiEvent), (PVOID)&uiEvent);
287 eStatus = eFrameworkunifiedStatusInvldHandle;
293 //////////////////////////////////////////////////////
294 /// FrameworkunifiedUnRegisterEvents
295 //////////////////////////////////////////////////////
296 EFrameworkunifiedStatus FrameworkunifiedUnRegisterEvents(HANDLE hSession, PVOID puiEventsArray, UI_32 uiListSize) {
297 EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
300 eStatus = FrameworkunifiedSendMsg(hSession, PROTOCOL_UNREGISTER_EVENTS,
301 static_cast<UI_32>(uiListSize * sizeof(uiListSize)), puiEventsArray);
303 eStatus = eFrameworkunifiedStatusInvldHandle;
309 //////////////////////////////////////////////////////
310 /// FrameworkunifiedUnRegisterEvent
311 //////////////////////////////////////////////////////
312 EFrameworkunifiedStatus FrameworkunifiedUnRegisterEvent(HANDLE hSession, UI_32 uiEvent) {
313 EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
316 eStatus = FrameworkunifiedSendMsg(hSession, PROTOCOL_UNREGISTER_EVENTS, sizeof(uiEvent), (PVOID)&uiEvent);
318 eStatus = eFrameworkunifiedStatusInvldHandle;
324 //////////////////////////////////////////////////////
325 /// FrameworkunifiedDefineStateEvents
326 //////////////////////////////////////////////////////
327 EFrameworkunifiedStatus FrameworkunifiedDefineStateEvents(HANDLE hApp, PVOID puiEvents, UI_32 uiListSize) {
328 EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
330 if (frameworkunifiedCheckValidAppHandle(hApp) && puiEvents) {
331 CFrameworkunifiedFrameworkApp *pApp = static_cast<CFrameworkunifiedFrameworkApp *>(hApp);
333 EventData *l_pEventData = NULL;
336 PUI_32 l_pEventList = (PUI_32)puiEvents;
338 for (UI_32 uiCount = 0; uiCount < uiListSize; uiCount++) {
339 l_uiEventId = l_pEventList[uiCount];
341 // checks if event exists in state event list
342 if (pApp->publicstateeventtable.end() == pApp->publicstateeventtable.find(l_uiEventId)) {
343 // insert the event in state event list, data is passed as NULL as there is no data published
344 pApp->publicstateeventtable.insert(std::make_pair(l_uiEventId, l_pEventData));
346 FRAMEWORKUNIFIEDLOG(ZONE_NS_INFO, __FUNCTION__, "Event %d already registered as state event ", l_uiEventId);
350 eStatus = eFrameworkunifiedStatusInvldHandle;
356 //////////////////////////////////////////////////////
357 /// FrameworkunifiedBroadcastEvent
358 //////////////////////////////////////////////////////
359 EFrameworkunifiedStatus FrameworkunifiedBroadcastEvent(HANDLE hApp, UI_32 uiEventId, PCVOID pData, UI_32 uiLength) {
360 EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
362 if (frameworkunifiedCheckValidAppHandle(hApp)) {
363 eStatus = FrameworkunifiedPublishEvent(hApp, uiEventId, NULL, pData, uiLength);
365 eStatus = eFrameworkunifiedStatusNullPointer;
371 //////////////////////////////////////////////////////
372 /// FrameworkunifiedPublishEvent
373 //////////////////////////////////////////////////////
374 EFrameworkunifiedStatus FrameworkunifiedPublishEvent(HANDLE hApp, UI_32 uiEventId, PCSTR pClientName, PCVOID pData, UI_32 uiLength) {
375 EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
376 EFrameworkunifiedStatus eRetStatus = eFrameworkunifiedStatusOK;
378 if (frameworkunifiedCheckValidAppHandle(hApp)) {
379 EventTable::iterator e_iterator;
380 ServiceSessionIdListTable::iterator ssidl_iterator;
382 PCSTR l_cServiceName = "";
384 // set the data, if event is a state events
385 UpdatePublicStateEventData(hApp, uiEventId, pData, uiLength);
387 CFrameworkunifiedFrameworkApp *pApp = static_cast<CFrameworkunifiedFrameworkApp *>(hApp);
389 // check if event is registered by client/s
390 e_iterator = pApp->eventtable.find(uiEventId);
392 if (pApp->eventtable.end() != e_iterator) {
393 // for loop for event table
394 for (ssidl_iterator = e_iterator->second.begin();
395 ssidl_iterator != e_iterator->second.end();
397 l_cServiceName = ssidl_iterator->first.c_str();
399 if (NULL != pClientName) {
400 // send message to only specified client
401 if (!std::strcmp(pClientName, l_cServiceName)) {
402 eStatus = SendEventMessage(hApp, ssidl_iterator->second, uiEventId, l_cServiceName, pData, uiLength);
406 // send message to all registered client
407 eRetStatus = SendEventMessage(hApp, ssidl_iterator->second, uiEventId, l_cServiceName, pData, uiLength);
408 if (eFrameworkunifiedStatusOK != eRetStatus) {
409 eStatus = eRetStatus;
414 FRAMEWORKUNIFIEDLOG(ZONE_NS_IMP_INFO, __FUNCTION__, "No subscriber has subscribed for event %d.", uiEventId);
417 eStatus = eFrameworkunifiedStatusInvldHandle;
423 //////////////////////////////////////////////////////
424 /// UpdatePublicStateEventData
425 //////////////////////////////////////////////////////
426 EFrameworkunifiedStatus UpdatePublicStateEventData(HANDLE hApp, UI_32 uiEventId, PCVOID pData, UI_32 uiLength) {
427 EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
429 if (frameworkunifiedCheckValidAppHandle(hApp)) {
430 if ((NULL == pData) && (uiLength > 0)) {
431 eStatus = eFrameworkunifiedStatusInvldParam;
433 PublicStateEventTable::iterator se_iterator;
434 EventData *l_pEventData = NULL;
436 CFrameworkunifiedFrameworkApp *pApp = static_cast<CFrameworkunifiedFrameworkApp *>(hApp);
438 // set the data, if event is a state events
439 se_iterator = pApp->publicstateeventtable.find(uiEventId);
440 if (pApp->publicstateeventtable.end() != se_iterator) {
441 l_pEventData = se_iterator->second;
442 if (NULL != l_pEventData) {
443 if (NULL != l_pEventData->pData) {
444 delete[](static_cast<PCHAR>(l_pEventData->pData));
445 (se_iterator->second)->pData = NULL;
449 se_iterator->second = NULL;
452 l_pEventData = new(std::nothrow) EventData();
455 * UpdatePublicStateEventData() in the pApp->publicstateeventtable
456 * The data area is being created, but there is no process to release.
458 if (NULL != l_pEventData) {
459 l_pEventData->uiLength = uiLength;
460 // LCOV_EXCL_BR_START 6:pData is checked in the top of this function, it should be not NULL here.
463 // LCOV_EXCL_START 6:pData is checked in the top of this function, it should be not NULL here.
464 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
465 l_pEventData->pData = NULL;
468 l_pEventData->pData = new(std::nothrow) CHAR[uiLength];
469 if (NULL != l_pEventData->pData) {
470 std::memset(l_pEventData->pData, 0, uiLength);
471 std::memcpy(l_pEventData->pData, pData, uiLength);
473 eStatus = eFrameworkunifiedStatusNullPointer;
477 se_iterator->second = l_pEventData;
479 eStatus = eFrameworkunifiedStatusNullPointer;
484 eStatus = eFrameworkunifiedStatusInvldParam;
490 //////////////////////////////////////////////////////
492 //////////////////////////////////////////////////////
493 EFrameworkunifiedStatus SendEventMessage(HANDLE hApp,
494 const SessionIdList &vSessionIdList,
499 EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
500 EFrameworkunifiedStatus eStatusSendMsg = eFrameworkunifiedStatusOK;
502 UI_32 l_uiSessionId = 0;
503 HANDLE l_hClientHandle = NULL;
505 if ((frameworkunifiedCheckValidAppHandle(hApp)) && (NULL != cServiceName)) {
506 for (UI_32 l_uiCount = 0;
507 l_uiCount < vSessionIdList.size();
509 l_uiSessionId = vSessionIdList[l_uiCount];
510 l_hClientHandle = GetMsgQueueHandle(hApp, cServiceName, l_uiSessionId);
512 // send message to all the registered sessions of the service
513 if (NULL != l_hClientHandle) {
514 if (eFrameworkunifiedStatusOK != (eStatusSendMsg = FrameworkunifiedSendMsg(l_hClientHandle, uiEventId, uiLength, pData))) {
515 eStatus = eFrameworkunifiedStatusErrOther;
516 FRAMEWORKUNIFIEDLOG(ZONE_NS_WAR, __FUNCTION__, "FrameworkunifiedSendMsg failed for EventID %d to service %s, status %d",
517 uiEventId, cServiceName, eStatusSendMsg);
520 FRAMEWORKUNIFIEDLOG(ZONE_NS_WAR, __FUNCTION__, "Unable to send event %d to service %s, session %d. NULL handle found.",
521 uiEventId, cServiceName, l_uiSessionId);
522 eStatus = eFrameworkunifiedStatusErrOther;
526 eStatus = eFrameworkunifiedStatusInvldParam;
532 //////////////////////////////////////////////////////
533 /// RemoveEventEntryFromEventTable
534 //////////////////////////////////////////////////////
535 EFrameworkunifiedStatus RemoveEventEntryFromEventTable(HANDLE hApp, UI_32 uiEventId,
536 PCSTR cServiceName, const UI_32 uiSessionId) {
537 EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
539 if ((frameworkunifiedCheckValidAppHandle(hApp)) && (NULL != cServiceName)) {
540 CFrameworkunifiedFrameworkApp *pApp = static_cast<CFrameworkunifiedFrameworkApp *>(hApp);
542 EventTable::iterator e_iterator;
543 ServiceSessionIdListTable::iterator ssidl_iterator;
545 // event table = event id, service name, vector of session ids
546 // check if event is registered by client/s
547 e_iterator = pApp->eventtable.find(uiEventId);
549 if (pApp->eventtable.end() != e_iterator) {
550 ssidl_iterator = e_iterator->second.find(cServiceName);
552 if (e_iterator->second.end() != ssidl_iterator) {
553 // search for the session id in list of registered session of service with the event uiEventId
554 for (UI_32 l_uiCount = 0;
555 l_uiCount < ssidl_iterator->second.size();
557 if (uiSessionId == ssidl_iterator->second[l_uiCount]) {
558 ssidl_iterator->second.erase(ssidl_iterator->second.begin() + l_uiCount);
563 // no other session of service cServiceName is registered with the event uiEventId
564 if (ssidl_iterator->second.empty()) {
565 e_iterator->second.erase(ssidl_iterator);
567 // no other session is registered for the event uiEventId
568 if (e_iterator->second.empty()) {
569 pApp->eventtable.erase(e_iterator);
575 eStatus = eFrameworkunifiedStatusInvldParam;
581 ////////////////////////////////////////////
582 // Function : CleanAllEventsOfSession
583 ////////////////////////////////////////////
584 EFrameworkunifiedStatus CleanAllEventsOfSession(HANDLE hApp, PCSTR serviceName, UI_32 sessionId) {
585 FRAMEWORKUNIFIEDLOG_CUT(ZONE_NS_FUNC, __FUNCTION__, "+");
586 EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
588 if ((frameworkunifiedCheckValidAppHandle(hApp)) && (NULL != serviceName)) {
589 CFrameworkunifiedFrameworkApp *pApp = static_cast<CFrameworkunifiedFrameworkApp *>(hApp);
591 ServiceSessionHandleTable::iterator ssh_iterator;
592 SessionToEventInfo::iterator sh_iterator;
593 HANDLE l_pClientHandle = NULL;
594 SessionEventInfo *l_ptSessionEventInfo = NULL;
596 // check whether client has registered for private event/s
597 ssh_iterator = pApp->servicesessionhandletable.find(serviceName);
599 if (pApp->servicesessionhandletable.end() != ssh_iterator) {
600 // get the table of session id and session handle of the received service over which private events are
602 sh_iterator = ssh_iterator->second.find(sessionId);
604 // client has registered for private event/s over this session
605 if (ssh_iterator->second.end() != sh_iterator) {
606 l_ptSessionEventInfo = sh_iterator->second;
608 if (NULL != l_ptSessionEventInfo) {
609 l_pClientHandle = l_ptSessionEventInfo->m_hSession;
610 if (NULL != l_pClientHandle) {
611 // close the session handle
612 eStatus = FrameworkunifiedMcClose(l_pClientHandle);
613 l_ptSessionEventInfo->m_hSession = NULL;
615 // Remove all the event entries from Event registry table
616 for (UI_32 l_uiCount = 0;
617 l_uiCount < l_ptSessionEventInfo->m_vEvents.size();
619 (VOID)RemoveEventEntryFromEventTable(hApp,
620 l_ptSessionEventInfo->m_vEvents[l_uiCount],
624 l_ptSessionEventInfo->m_vEvents.clear(); // clear the event list
625 delete l_ptSessionEventInfo;
626 sh_iterator->second = NULL; // l_ptSessionEventInfo
629 FRAMEWORKUNIFIEDLOG(ZONE_NS_INFO, __FUNCTION__, "Deleting session event info entry for service: %s, session id: %d.",
630 serviceName, sessionId);
631 // remove the entry from SessionHandle table
632 ssh_iterator->second.erase(sh_iterator);
634 // remove the entry from ServiceSessionHandle table if this service have not registered for
635 // private events over other session
636 if (ssh_iterator->second.empty()) {
637 pApp->servicesessionhandletable.erase(ssh_iterator);
642 eStatus = eFrameworkunifiedStatusInvldParam;
643 FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Invalid application handle or service name NULL");
645 FRAMEWORKUNIFIEDLOG_CUT(ZONE_NS_FUNC, __FUNCTION__, "-");
649 //////////////////////////////////////////////////////
650 /// RemoveEntryFromSessionEventInfoTable
651 //////////////////////////////////////////////////////
652 EFrameworkunifiedStatus RemoveEntryFromSessionEventInfoTable(HANDLE hApp, PCSTR serviceName, UI_32 sessionId, UI_32 eventId) {
653 FRAMEWORKUNIFIEDLOG_CUT(ZONE_NS_FUNC, __FUNCTION__, "+");
654 EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
656 if ((frameworkunifiedCheckValidAppHandle(hApp)) && (NULL != serviceName)) {
657 CFrameworkunifiedFrameworkApp *pApp = static_cast<CFrameworkunifiedFrameworkApp *>(hApp);
659 ServiceSessionHandleTable::iterator ssh_iterator;
660 SessionToEventInfo::iterator sh_iterator;
661 HANDLE l_pClientHandle = NULL;
662 SessionEventInfo *l_ptSessionEventInfo = NULL;
664 // check whether client has registered for private event/s
665 ssh_iterator = pApp->servicesessionhandletable.find(serviceName);
667 if (pApp->servicesessionhandletable.end() != ssh_iterator) {
668 // get the table of session id and session handle of the received service over which private events are
670 sh_iterator = ssh_iterator->second.find(sessionId);
672 // client has registered for private event/s over this session
673 if (ssh_iterator->second.end() != sh_iterator) {
674 l_ptSessionEventInfo = sh_iterator->second;
676 if (NULL != l_ptSessionEventInfo) {
677 // Remove event entry from session event info table
678 for (UI_32 l_uiCount = 0;
679 l_uiCount < l_ptSessionEventInfo->m_vEvents.size();
681 if (eventId == l_ptSessionEventInfo->m_vEvents[l_uiCount]) {
682 FRAMEWORKUNIFIEDLOG(ZONE_NS_INFO, __FUNCTION__, "Removing session event info entry for "
683 "service:%s, session id:%d. event:%d",
684 serviceName, sessionId, eventId);
685 l_ptSessionEventInfo->m_vEvents.erase(l_ptSessionEventInfo->m_vEvents.begin() + l_uiCount);
690 if (l_ptSessionEventInfo->m_vEvents.empty()) {
691 l_pClientHandle = l_ptSessionEventInfo->m_hSession;
692 if (NULL != l_pClientHandle) {
693 // close the session handle
694 eStatus = FrameworkunifiedMcClose(l_pClientHandle);
695 l_ptSessionEventInfo->m_hSession = NULL;
697 delete l_ptSessionEventInfo;
698 sh_iterator->second = NULL; // l_ptSessionEventInfo
700 // remove the entry from SessionHandle table
701 ssh_iterator->second.erase(sh_iterator);
705 // remove the entry from ServiceSessionHandle table if this service have not registered for
706 // private events over other session
707 if (ssh_iterator->second.empty()) {
708 pApp->servicesessionhandletable.erase(ssh_iterator);
713 eStatus = eFrameworkunifiedStatusInvldParam;
714 FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Invalid application handle status:: %d", eStatus);
717 FRAMEWORKUNIFIEDLOG_CUT(ZONE_NS_FUNC, __FUNCTION__, "-");
722 //////////////////////////////////////////////////////
723 /// FrameworkunifiedDefinePublicStateEvents
724 //////////////////////////////////////////////////////
725 EFrameworkunifiedStatus FrameworkunifiedDefinePublicStateEvents(HANDLE hApp, PUI_32 puiEvents, UI_32 uiListSize) {
726 EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
728 if (frameworkunifiedCheckValidAppHandle(hApp) && NULL != puiEvents) {
729 CFrameworkunifiedFrameworkApp *pApp = static_cast<CFrameworkunifiedFrameworkApp *>(hApp);
733 for (UI_32 uiCount = 0; uiCount < uiListSize; uiCount++) {
734 l_uiEventId = puiEvents[uiCount];
736 // checks if event exists in state event list
737 if (pApp->publicstateeventtable.end() == pApp->publicstateeventtable.find(l_uiEventId)) {
738 EventData *l_pEventData = NULL;
739 // insert the event in state event list, data is passed as NULL as there is no data published
740 pApp->publicstateeventtable.insert(std::make_pair(l_uiEventId, l_pEventData));
742 FRAMEWORKUNIFIEDLOG(ZONE_NS_INFO, __FUNCTION__, "Event %d already registered as public state event ", l_uiEventId);
746 eStatus = eFrameworkunifiedStatusInvldHandle;
752 //////////////////////////////////////////////////////
753 /// FrameworkunifiedDefinePrivateStateEvents
754 //////////////////////////////////////////////////////
755 EFrameworkunifiedStatus FrameworkunifiedDefinePrivateStateEvents(HANDLE hApp, PUI_32 puiEvents, UI_32 uiListSize) {
756 EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
758 if (frameworkunifiedCheckValidAppHandle(hApp) && NULL != puiEvents) {
759 CFrameworkunifiedFrameworkApp *pApp = static_cast<CFrameworkunifiedFrameworkApp *>(hApp);
761 UI_32 l_uiEventId = 0;
763 for (UI_32 uiCount = 0; uiCount < uiListSize; uiCount++) {
764 l_uiEventId = puiEvents[uiCount];
766 // checks if event exists in state event list
767 if (pApp->privatestateeventtable.end() == pApp->privatestateeventtable.find(l_uiEventId)) {
768 ServiceSessionEventData servicesessioneventdata;
769 pApp->privatestateeventtable.insert(std::make_pair(l_uiEventId, servicesessioneventdata));
771 FRAMEWORKUNIFIEDLOG(ZONE_NS_INFO, __FUNCTION__, "Event %d already registered as private state event", l_uiEventId);
775 eStatus = eFrameworkunifiedStatusInvldHandle;
781 //////////////////////////////////////////////////////
782 /// FrameworkunifiedSubscribeToSessionEventWithCallback
783 //////////////////////////////////////////////////////
784 EFrameworkunifiedStatus FrameworkunifiedSubscribeToSessionEventWithCallback(HANDLE hApp, UI_32 uiCmd, CbFuncPtr fpOnCmd, HANDLE hSession) {
785 EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
787 if (frameworkunifiedCheckValidAppHandle(hApp) && frameworkunifiedCheckValidMsgQ(hSession)) {
788 if (eFrameworkunifiedStatusOK == (eStatus = FrameworkunifiedAttachCallbackToDispatcher(hApp,
789 (reinterpret_cast<MsgQInfo *>(hSession))->cMsgQName,
793 eStatus = FrameworkunifiedSendMsg(hSession, PROTOCOL_REGISTER_EVENTS, sizeof(UI_32), (PVOID)&uiCmd);
795 FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "FrameworkunifiedAttachCallbackToDispatcher for "
796 "PROTOCOL_REGISTER_EVENTS Failed Status:: %d", eStatus);
799 eStatus = eFrameworkunifiedStatusInvldHandle;
805 //////////////////////////////////////////////////////
806 /// FrameworkunifiedSubscribeToSessionEventsWithCallbacks
807 //////////////////////////////////////////////////////
808 EFrameworkunifiedStatus FrameworkunifiedSubscribeToSessionEventsWithCallbacks(HANDLE hApp, const FrameworkunifiedProtocolCallbackHandler *pMsgHandler,
809 UI_32 uiHandlerCount, HANDLE hSession) {
810 EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
812 if (NULL == pMsgHandler) {
813 eStatus = eFrameworkunifiedStatusInvldParam;
814 } else if (frameworkunifiedCheckValidAppHandle(hApp) && frameworkunifiedCheckValidMsgQ(hSession)) {
817 * If the CbFuncPtr in the pMsgHandler is set to NULL, the expected value is eFrameworkunifiedStatusInvldParam,
818 * but eFrameworkunifiedStatusOK is returned in the implementation.
819 * [Proposed measures]
820 * Exit by referring to the return code of the FrameworkunifiedAttachCallbacksToDispatcher executed in the FrameworkunifiedSubscribeToSessionEventsWithCallbacks.
824 * The behavior when NULL is set for a CbFuncPtr in a pMsgHandler in which more than one callback message is registered
825 * is not specified in the specifications.
826 * Ex: Prepare a pMsgHandler in which three callback information are registered,
827 * and specify NULL as the callback function pointer of the second callback information, and execute it.
828 * - Register the first callback function.
829 * - The second callback function is not registered with an error.
830 * - It is unspecified whether the third callback function is registered.
831 * [Proposed measures]
832 * Specifies that if there is callback information including NULL in the callback function pointer in pMsgHandler,
833 * the callback information will not be registered from the element following that callback function pointer.
835 eStatus = FrameworkunifiedAttachCallbacksToDispatcher(hApp,
836 (reinterpret_cast<MsgQInfo *>(hSession))->cMsgQName,
840 UI_32 l_uiCmdList[uiHandlerCount]; // NOLINT (readability/nolint)
841 for (UI_32 l_uiCnt = 0; l_uiCnt < uiHandlerCount; l_uiCnt++) {
842 l_uiCmdList[l_uiCnt] = pMsgHandler[l_uiCnt].iCmd;
845 eStatus = FrameworkunifiedSendMsg(hSession, PROTOCOL_REGISTER_EVENTS,
846 static_cast<UI_32>(uiHandlerCount * sizeof(UI_32)), l_uiCmdList);
848 eStatus = eFrameworkunifiedStatusInvldHandle;
854 //////////////////////////////////////////////////////
855 /// FrameworkunifiedUnSubscribeSessionEventWithCallback
856 //////////////////////////////////////////////////////
857 EFrameworkunifiedStatus FrameworkunifiedUnSubscribeSessionEventWithCallback(HANDLE hApp, UI_32 uiEvent, HANDLE hSession) {
858 EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
860 if (frameworkunifiedCheckValidAppHandle(hApp) && frameworkunifiedCheckValidMsgQ(hSession)) {
861 eStatus = FrameworkunifiedSendMsg(hSession, PROTOCOL_UNREGISTER_EVENTS, sizeof(uiEvent), (PVOID)&uiEvent);
862 if (eFrameworkunifiedStatusOK == eStatus) {
863 if (eFrameworkunifiedStatusOK != (eStatus = FrameworkunifiedDetachCallbackFromDispatcher(hApp,
864 (reinterpret_cast<MsgQInfo *>(hSession))->cMsgQName,
867 FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Error : FrameworkunifiedDetachCallbackFromDispatcher failed status:: %d", eStatus);
870 FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Error : Failed to send PROTOCOL_UNREGISTER_EVENTS request to service:: %d",
874 eStatus = eFrameworkunifiedStatusInvldHandle;
880 //////////////////////////////////////////////////////
881 /// FrameworkunifiedUnSubscribeSessionEventsWithCallbacks
882 //////////////////////////////////////////////////////
883 EFrameworkunifiedStatus FrameworkunifiedUnSubscribeSessionEventsWithCallbacks(HANDLE hApp, PUI_32 puiEventsArray, UI_32 uiListSize,
885 EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
887 if (frameworkunifiedCheckValidAppHandle(hApp) && frameworkunifiedCheckValidMsgQ(hSession)) {
888 eStatus = FrameworkunifiedSendMsg(hSession, PROTOCOL_UNREGISTER_EVENTS, static_cast<UI_32>(uiListSize * sizeof(uiListSize)),
890 if (eFrameworkunifiedStatusOK == eStatus) {
891 if (eFrameworkunifiedStatusOK != (eStatus = FrameworkunifiedDetachCallbacksFromDispatcher(hApp,
892 (reinterpret_cast<MsgQInfo *>(hSession))->cMsgQName,
896 FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Error : FrameworkunifiedDetachCallbackFromDispatcher failed status:: %d", eStatus);
899 FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Error : Failed to send PROTOCOL_UNREGISTER_EVENTS request to service:: %d",
903 eStatus = eFrameworkunifiedStatusInvldHandle;
909 //////////////////////////////////////////////////////
910 /// FrameworkunifiedPublishPrivateEvent
911 //////////////////////////////////////////////////////
912 EFrameworkunifiedStatus FrameworkunifiedPublishPrivateEvent(HANDLE hApp, UI_32 uiEventId, PCVOID pData, UI_32 uiLength, HANDLE hSession) {
913 EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
915 if (frameworkunifiedCheckValidAppHandle(hApp) && frameworkunifiedCheckValidMsgQ(hSession)) {
916 EventTable::iterator e_iterator;
917 ServiceSessionIdListTable::iterator ssidl_iterator;
919 PCSTR l_cServiceName = "";
920 BOOL l_bIsPublished = FALSE;
922 CFrameworkunifiedFrameworkApp *pApp = static_cast<CFrameworkunifiedFrameworkApp *>(hApp);
924 // set the data, if event is a public state events
925 UpdatePrivateStateEventData(hApp,
927 (reinterpret_cast<MsgQInfo *>(hSession))->cMsgQName,
928 (reinterpret_cast<MsgQInfo *>(hSession))->sessionId,
932 // check if event is registered by client/s
933 e_iterator = pApp->eventtable.find(uiEventId);
935 if (pApp->eventtable.end() != e_iterator) {
936 // for loop for event table
937 for (ssidl_iterator = e_iterator->second.begin();
938 ssidl_iterator != e_iterator->second.end();
940 l_cServiceName = ssidl_iterator->first.c_str();
942 // send message to only specified client
943 if (!std::strcmp(l_cServiceName, (reinterpret_cast<MsgQInfo *>(hSession))->cMsgQName)) {
944 for (UI_32 l_uiCount = 0;
945 l_uiCount < ssidl_iterator->second.size();
947 if ((reinterpret_cast<MsgQInfo *>(hSession))->sessionId == ssidl_iterator->second[l_uiCount]) {
948 if (eFrameworkunifiedStatusOK != (eStatus = FrameworkunifiedSendMsg(hSession, uiEventId, uiLength, pData))) {
949 FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "FrameworkunifiedSendMsg Failed for Event %d", uiEventId);
952 l_bIsPublished = TRUE;
958 if (l_bIsPublished) {
963 if (!l_bIsPublished) {
964 FRAMEWORKUNIFIEDLOG(ZONE_NS_WAR, __FUNCTION__, "Failed to publish event %d to client [%s], session: [%d]. "
965 "Client not subscribed to the event on specified session.",
966 uiEventId, (reinterpret_cast<MsgQInfo *>(hSession))->cMsgQName != 0 ? \
967 (reinterpret_cast<MsgQInfo *>(hSession))->cMsgQName : NULL,
968 (reinterpret_cast<MsgQInfo *>(hSession))->sessionId);
969 eStatus = eFrameworkunifiedStatusServNotFound;
972 FRAMEWORKUNIFIEDLOG(ZONE_NS_WAR, __FUNCTION__, "Client %s is not subscribed to Event %d, session: [%d]",
973 (reinterpret_cast<MsgQInfo *>(hSession))->cMsgQName, uiEventId,
974 (reinterpret_cast<MsgQInfo *>(hSession))->sessionId);
975 eStatus = eFrameworkunifiedStatusServNotFound;
978 eStatus = eFrameworkunifiedStatusInvldParam;
984 //////////////////////////////////////////////////////
985 /// FrameworkunifiedPublishPublicEvent
986 //////////////////////////////////////////////////////
987 EFrameworkunifiedStatus FrameworkunifiedPublishPublicEvent(HANDLE hApp, UI_32 uiEventId, PCVOID pData, UI_32 uiLength) {
988 EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
989 EFrameworkunifiedStatus eRetStatus = eFrameworkunifiedStatusOK;
991 if (frameworkunifiedCheckValidAppHandle(hApp)) {
992 EventTable::iterator e_iterator;
993 ServiceSessionIdListTable::iterator ssidl_iterator;
995 PCSTR l_cServiceName = "";
997 // set the data, if event is a state events
998 UpdatePublicStateEventData(hApp, uiEventId, pData, uiLength);
1000 CFrameworkunifiedFrameworkApp *pApp = static_cast<CFrameworkunifiedFrameworkApp *>(hApp);
1002 // check if event is registered by client/s
1003 e_iterator = pApp->eventtable.find(uiEventId);
1005 if (pApp->eventtable.end() != e_iterator) {
1006 // for loop for event table
1007 for (ssidl_iterator = e_iterator->second.begin();
1008 ssidl_iterator != e_iterator->second.end();
1010 l_cServiceName = ssidl_iterator->first.c_str();
1012 eRetStatus = SendEventMessage(hApp, ssidl_iterator->second, uiEventId, l_cServiceName, pData, uiLength);
1013 if (eFrameworkunifiedStatusOK != eRetStatus) {
1014 eStatus = eRetStatus;
1018 FRAMEWORKUNIFIEDLOG(ZONE_NS_WAR, __FUNCTION__, "No client subscribed to EventID %d.", uiEventId);
1021 eStatus = eFrameworkunifiedStatusInvldHandle;
1027 //////////////////////////////////////////////////////
1028 /// UpdatePrivateStateEventData
1029 //////////////////////////////////////////////////////
1030 EFrameworkunifiedStatus UpdatePrivateStateEventData(HANDLE hApp, UI_32 uiEventId, PCSTR pClientName, UI_32 uiSessionId,
1033 EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
1035 if ((NULL == pData) && (uiLength > 0)) {
1036 eStatus = eFrameworkunifiedStatusInvldParam;
1039 if ((eFrameworkunifiedStatusOK == eStatus) && (frameworkunifiedCheckValidAppHandle(hApp)) && (NULL != pClientName)) {
1040 PrivateStateEventTable::iterator pse_iterator;
1041 ServiceSessionEventData::iterator ssed_iterator;
1042 SessionEventData::iterator sed_iterator;
1044 EventData *l_pEventData = NULL;
1046 CFrameworkunifiedFrameworkApp *pApp = static_cast<CFrameworkunifiedFrameworkApp *>(hApp);
1048 // set the data, if event is a state events
1049 pse_iterator = pApp->privatestateeventtable.find(uiEventId);
1050 if (pApp->privatestateeventtable.end() != pse_iterator) {
1051 ssed_iterator = (pse_iterator->second).find(pClientName);
1053 if ((pse_iterator->second).end() != ssed_iterator) {
1054 sed_iterator = (ssed_iterator->second).find(uiSessionId);
1055 if ((ssed_iterator->second).end() != sed_iterator) {
1056 l_pEventData = sed_iterator->second;
1058 if (NULL != l_pEventData) {
1059 if (NULL != l_pEventData->pData) {
1060 delete[](static_cast<PCHAR>(l_pEventData->pData));
1061 (sed_iterator->second)->pData = NULL;
1064 delete l_pEventData;
1065 sed_iterator->second = NULL;
1068 l_pEventData = new(std::nothrow) EventData();
1070 if (NULL != l_pEventData) {
1071 l_pEventData->uiLength = uiLength;
1073 if (NULL == pData) {
1074 l_pEventData->pData = NULL;
1076 l_pEventData->pData = new(std::nothrow) CHAR[uiLength];
1077 if (NULL != l_pEventData->pData) {
1078 std::memset(l_pEventData->pData, 0, uiLength);
1079 std::memcpy(l_pEventData->pData, pData, uiLength);
1081 eStatus = eFrameworkunifiedStatusNullPointer;
1082 l_pEventData->uiLength = 0;
1086 sed_iterator->second = l_pEventData;
1088 eStatus = eFrameworkunifiedStatusNullPointer;
1090 } else { // if client has not yet subscribed to this event over the session uiSessionId
1091 l_pEventData = new(std::nothrow) EventData();
1093 if (NULL != l_pEventData) {
1094 l_pEventData->uiLength = uiLength;
1096 if (NULL == pData) {
1097 l_pEventData->pData = NULL;
1099 l_pEventData->pData = new(std::nothrow) CHAR[uiLength];
1100 if (NULL != l_pEventData->pData) {
1101 std::memset(l_pEventData->pData, 0, uiLength);
1102 std::memcpy(l_pEventData->pData, pData, uiLength);
1104 eStatus = eFrameworkunifiedStatusNullPointer;
1108 (ssed_iterator->second).insert(std::make_pair(uiSessionId, l_pEventData));
1110 eStatus = eFrameworkunifiedStatusNullPointer;
1113 } else { // if client has not yet subscribed to this event
1114 SessionEventData sessionEventData;
1116 l_pEventData = new(std::nothrow) EventData();
1118 if (NULL != l_pEventData) {
1119 l_pEventData->uiLength = uiLength;
1121 if (NULL == pData) {
1122 l_pEventData->pData = NULL;
1124 l_pEventData->pData = new(std::nothrow) CHAR[uiLength];
1125 if (NULL != l_pEventData->pData) {
1126 std::memset(l_pEventData->pData, 0, uiLength);
1127 std::memcpy(l_pEventData->pData, pData, uiLength);
1129 eStatus = eFrameworkunifiedStatusNullPointer;
1130 l_pEventData->uiLength = 0;
1133 sessionEventData.insert(std::make_pair(uiSessionId, l_pEventData));
1135 (pse_iterator->second).insert(std::make_pair(pClientName, sessionEventData));
1137 eStatus = eFrameworkunifiedStatusNullPointer;
1142 eStatus = eFrameworkunifiedStatusInvldParam;
1148 //////////////////////////////////////////////////////
1149 /// DeleteSessionEventData
1150 //////////////////////////////////////////////////////
1151 EFrameworkunifiedStatus DeleteSessionEventData(HANDLE hApp, PCSTR pClientName, UI_32 uiSessionId) {
1152 EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
1154 // map: eventid -> servicename -> sessionid -> eventdata(data, length)
1156 if (frameworkunifiedCheckValidAppHandle(hApp) && NULL != pClientName) {
1157 PrivateStateEventTable::iterator pse_iterator;
1158 ServiceSessionEventData::iterator ssed_iterator;
1159 SessionEventData::iterator sed_iterator;
1161 EventData *l_pEventData = NULL;
1163 CFrameworkunifiedFrameworkApp *pApp = static_cast<CFrameworkunifiedFrameworkApp *>(hApp);
1165 // delete the private event data associated with the service over this session
1166 for (pse_iterator = pApp->privatestateeventtable.begin();
1167 pse_iterator != pApp->privatestateeventtable.end();
1169 ssed_iterator = (pse_iterator->second).find(pClientName);
1171 if ((pse_iterator->second).end() != ssed_iterator) {
1172 sed_iterator = (ssed_iterator->second).find(uiSessionId);
1173 if ((ssed_iterator->second).end() != sed_iterator) {
1174 l_pEventData = sed_iterator->second;
1176 if (NULL != l_pEventData) {
1177 if (NULL != l_pEventData->pData) {
1178 delete[](static_cast<PCHAR>(l_pEventData->pData));
1179 (sed_iterator->second)->pData = NULL;
1182 delete l_pEventData;
1183 sed_iterator->second = NULL;
1189 eStatus = eFrameworkunifiedStatusNullPointer;
1195 //////////////////////////////////////////////////////
1196 /// Returns the number of session opened by the server for one client
1197 //////////////////////////////////////////////////////
1198 UI_32 FrameworkunifiedGetNumberOfSession(HANDLE hApp, PCSTR strServiceName) {
1199 UI_32 l_uiSessionCount = 0;
1201 if (frameworkunifiedCheckValidAppHandle(hApp)) {
1202 CFrameworkunifiedFrameworkApp *pApp = static_cast<CFrameworkunifiedFrameworkApp *>(hApp);
1203 Services::iterator s_iterator = pApp->services.find(strServiceName);
1204 if (s_iterator != pApp->services.end()) {
1205 l_uiSessionCount = static_cast<UI_32>((s_iterator->second).size());
1209 return l_uiSessionCount;
1212 //////////////////////////////////////////////////////
1213 /// Sets the handle in the Application Framework
1214 //////////////////////////////////////////////////////
1215 EFrameworkunifiedStatus FrameworkunifiedSetSessionHandle(HANDLE hApp, PCSTR strServiceName, HANDLE hSession) {
1216 EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
1217 UI_32 l_uiSessionId = 0;
1218 if (frameworkunifiedCheckValidMsgQ(hSession) && NULL != strServiceName && frameworkunifiedCheckValidAppHandle(hApp) &&
1219 0 != std::strlen(strServiceName)) {
1220 MsgQInfo *pMsgQ = reinterpret_cast<MsgQInfo *>(hSession);
1223 l_uiSessionId = pMsgQ->sessionId;
1225 CFrameworkunifiedFrameworkApp *pApp = static_cast<CFrameworkunifiedFrameworkApp *>(hApp);
1226 ServiceSessionTable::iterator session_iterator;
1227 SessionHandleTable::iterator session_handle_iterator;
1229 // Find the service name
1230 session_iterator = pApp->sessiontable.find(strServiceName);
1231 if (session_iterator == pApp->sessiontable.end()) {
1232 pApp->sessiontable.insert(std::make_pair(strServiceName, SessionHandleTable()));
1235 // Find the session id
1236 session_handle_iterator = pApp->sessiontable[strServiceName].find(l_uiSessionId);
1237 if (session_handle_iterator != pApp->sessiontable[strServiceName].end()) {
1238 pApp->sessiontable[strServiceName].erase(l_uiSessionId);
1241 // Set the session handle
1242 pApp->sessiontable[strServiceName].insert(std::make_pair(l_uiSessionId, hSession));
1245 eStatus = eFrameworkunifiedStatusFail;
1250 //////////////////////////////////////////////////////
1251 /// reads the handle from the Application Framework
1252 //////////////////////////////////////////////////////
1253 HANDLE FrameworkunifiedGetSessionHandle(HANDLE hApp, PCSTR strServiceName, UI_32 uiSessionId) {
1254 HANDLE hSession = NULL;
1255 if (frameworkunifiedCheckValidAppHandle(hApp) && strServiceName) {
1256 CFrameworkunifiedFrameworkApp *pApp = static_cast<CFrameworkunifiedFrameworkApp *>(hApp);
1257 ServiceSessionTable::iterator session_iterator;
1258 SessionHandleTable::iterator session_handle_iterator;
1260 // Find the service name
1261 session_iterator = pApp->sessiontable.find(strServiceName);
1262 if (session_iterator != pApp->sessiontable.end()) {
1263 // Find the session id
1264 session_handle_iterator = pApp->sessiontable[strServiceName].find(uiSessionId);
1265 if (session_handle_iterator != pApp->sessiontable[strServiceName].end()) {
1266 // Fetch the session handle
1267 hSession = session_handle_iterator->second;
1273 //////////////////////////////////////////////////////
1274 /// Close the handle stored in the Application Framework
1275 //////////////////////////////////////////////////////
1276 EFrameworkunifiedStatus FrameworkunifiedRemoveSessionHandle(HANDLE hApp, PCSTR strServiceName, UI_32 uiSessionId) {
1277 EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
1278 if (frameworkunifiedCheckValidAppHandle(hApp) && strServiceName && 0 != std::strlen(strServiceName)) {
1279 CFrameworkunifiedFrameworkApp *pApp = static_cast<CFrameworkunifiedFrameworkApp *>(hApp);
1281 pApp->sessiontable[strServiceName].erase(uiSessionId);
1282 if (0 == pApp->sessiontable[strServiceName].size()) {
1283 // If no entry is available for current service then remove the servicename
1284 pApp->sessiontable.erase(strServiceName);
1287 eStatus = eFrameworkunifiedStatusFail;
1293 //////////////////////////////////////////////////////
1294 /// FrameworkunifiedGetSession|Name -> On Client side
1295 //////////////////////////////////////////////////////
1296 PCSTR FrameworkunifiedGetSessionName(HANDLE hSession) {
1297 if (frameworkunifiedCheckValidMsgQ(hSession)) {
1298 return ((reinterpret_cast<MsgQInfo *>(hSession))->cMsgQName);
1305 HANDLE FrameworkunifiedGetCurrentSessionHandle(HANDLE hApp) {
1306 HANDLE hSession = NULL;
1307 if (frameworkunifiedCheckValidAppHandle(hApp)) {
1308 UI_32 l_uiSessionId = FrameworkunifiedGetMsgSessionId(hApp);
1309 PCSTR pRequester = FrameworkunifiedGetMsgSrc(hApp);
1311 hSession = FrameworkunifiedGetSessionHandle(hApp, pRequester, l_uiSessionId);
1316 HANDLE FrameworkunifiedCreateSession(HANDLE hApp, PCSTR pSessionName) {
1317 EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
1318 HANDLE hSession = NULL;
1319 if (frameworkunifiedCheckValidAppHandle(hApp) && pSessionName && strlen(pSessionName)) {
1320 hSession = FrameworkunifiedGenerateSessionHandle(hApp, pSessionName);
1322 if (eFrameworkunifiedStatusOK != (eStatus = FrameworkunifiedSetSessionHandle(hApp, pSessionName, hSession))) {
1323 if (eFrameworkunifiedStatusOK != (eStatus = FrameworkunifiedMcClose(hSession))) {
1324 FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __PRETTY_FUNCTION__, "Close session failed");
1328 FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __PRETTY_FUNCTION__, "FrameworkunifiedCreateSession Failed Status:0x%x ", eStatus);
1332 eStatus = eFrameworkunifiedStatusInvldParam;
1337 EFrameworkunifiedStatus FrameworkunifiedDestroySession(HANDLE hApp, HANDLE hSession) {
1338 EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusFail;
1340 if (frameworkunifiedCheckValidAppHandle(hApp) && frameworkunifiedCheckValidMsgQ(hSession)) {
1341 UI_32 uiSessionId = (reinterpret_cast<MsgQInfo *>(hSession))->sessionId;
1342 CHAR pRequester[MAX_NAME_SIZE_APP] = {};
1343 strncpy(pRequester, (reinterpret_cast<MsgQInfo *>(hSession))->cMsgQName, sizeof(pRequester) - 1);
1345 if (eFrameworkunifiedStatusOK != (eStatus = FrameworkunifiedMcClose(hSession))) {
1346 FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __PRETTY_FUNCTION__, "Close session failed. Status: %d", eStatus);
1349 if (eFrameworkunifiedStatusOK != (eStatus = FrameworkunifiedRemoveSessionHandle(hApp, pRequester, uiSessionId))) {
1350 FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __PRETTY_FUNCTION__, "Remove session failed. Status: %d", eStatus);
1353 DeleteSessionEventData(hApp, pRequester, uiSessionId);