summaryrefslogtreecommitdiffstats
path: root/nsframework/framework_unified/client/NS_FrameworkCore/src/frameworkunified_framework_dispatch.cpp
blob: cb573c97d3eed9631db9c3a684f70c2d52782794 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
/*
 * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

///////////////////////////////////////////////////////////////////////////////
/// \ingroup  tag_NSFramework
/// \brief
///
///
///
///////////////////////////////////////////////////////////////////////////////
#include <sys/epoll.h>

#include <native_service/frameworkunified_framework_if.h>
#include <native_service/ns_message_center_if.h>
#include <native_service/ns_logger_if.h>
#include <native_service/ns_plogger_if.h>
#include <other_service/strlcpy.h>

#include <map>
#include <utility>

#include "frameworkunified_framework_core.h"
///////////////////////////////////////////////////
//        Utility
///////////////////////////////////////////////////

//////////////////////////////////////////
// Function : FrameworkunifiedGetAppName
//////////////////////////////////////////
PCSTR FrameworkunifiedGetAppName(HANDLE hApp) {
  if (frameworkunifiedCheckValidAppHandle(hApp)) {
    const CFrameworkunifiedFrameworkApp *pApp = reinterpret_cast<CFrameworkunifiedFrameworkApp *>(hApp);
    return ((PCSTR)pApp->cAppName);
  } else {
    return NULL;
  }
}

//////////////////////////////////////////
// Function : FrameworkunifiedSetThreadSpecificData
//////////////////////////////////////////
EFrameworkunifiedStatus FrameworkunifiedSetThreadSpecificData(HANDLE hApp, PVOID data) {
  EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusInvldHandle;

  if (frameworkunifiedCheckValidAppHandle(hApp)) {
    CFrameworkunifiedFrameworkApp *pApp = reinterpret_cast<CFrameworkunifiedFrameworkApp *>(hApp);
    pApp->FrameworkData = data;

    eStatus = eFrameworkunifiedStatusOK;
  }

  return eStatus;
}

//////////////////////////////////////////
// Function : FrameworkunifiedGetThreadSpecificData
//////////////////////////////////////////
PVOID FrameworkunifiedGetThreadSpecificData(HANDLE hApp) {
  if (frameworkunifiedCheckValidAppHandle(hApp)) {
    const CFrameworkunifiedFrameworkApp *pApp = reinterpret_cast< CFrameworkunifiedFrameworkApp * >(hApp);
    return pApp->FrameworkData;
  } else {
    return NULL;
  }
}



template <typename K, typename V, class C, class A>
std::ostream &operator<< (std::ostream &os, std::map<K, V, C, A> const &m) {
  os << "{ ";
  typename std::map<K, V, C, A>::const_iterator p;
  for (p = m.begin(); p != m.end(); ++p) {
    os << p->first << ":" << p->second << ", ";
  }
  return os << "}";
}







///////////////////////////////////////////////////
//   Service Protocol attach/detach to dispatcher
///////////////////////////////////////////////////







/////////////////////////////////////////////////////
// Function : FrameworkunifiedAttachCallbacksToDispatcher
/////////////////////////////////////////////////////
EFrameworkunifiedStatus FrameworkunifiedAttachCallbacksToDispatcher(HANDLE hApp, PCSTR pServiceName, const FrameworkunifiedProtocolCallbackHandler *handlers,
                                          UI_32 handlerCount, HANDLE hSession) {
  EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;

  if (frameworkunifiedCheckValidAppHandle(hApp) && NULL != pServiceName && NULL != handlers && 0 != handlerCount) {
    // setup callbacks
    for (UI_32 i = 0; i < handlerCount; ++i) {
      if (eFrameworkunifiedStatusOK != (eStatus = FrameworkunifiedAttachCallbackToDispatcher(hApp, pServiceName, handlers[ i ].iCmd,
                                                                   handlers[ i ].callBack, hSession))) {
        break;
      }
    }
  } else {
    eStatus = eFrameworkunifiedStatusInvldParam;
  }

  return eStatus;
}


/////////////////////////////////////////////
// Function : FrameworkunifiedAttachCallbackToDispatcher
/////////////////////////////////////////////
EFrameworkunifiedStatus FrameworkunifiedAttachCallbackToDispatcher(HANDLE hApp, PCSTR pServiceName, UI_32 iCmd, CbFuncPtr fpOnCmd,
                                         HANDLE hSession) {
  EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;

  if (frameworkunifiedCheckValidAppHandle(hApp) && NULL != pServiceName && NULL != fpOnCmd) {
    CFrameworkunifiedFrameworkApp *pApp = static_cast<CFrameworkunifiedFrameworkApp *>(hApp);
    Services::iterator s_iterator;
    SessionTable::iterator session_iterator;

    UI_32 uiSessionId = 0;
    if (hSession) {
      uiSessionId = FrameworkunifiedGetSessionId(hSession);
    }

    // finding the service
    s_iterator = pApp->services.find(pServiceName);
    if (s_iterator == pApp->services.end()) {
      FRAMEWORKUNIFIEDLOG(ZONE_NS_DIS, __FUNCTION__, "%s : (New service entry): service name [%s]", pApp->cAppName, pServiceName);
      s_iterator = pApp->services.insert(std::make_pair(pServiceName, SessionTable())).first;
    }

    session_iterator = s_iterator->second.find(uiSessionId);
    if (session_iterator == s_iterator->second.end()) {
      session_iterator = s_iterator->second.insert(std::make_pair(uiSessionId, ServiceProtocolTable())).first;
    }

    session_iterator->second.insert(std::make_pair(iCmd, fpOnCmd));
  } else {
    eStatus = eFrameworkunifiedStatusInvldParam;
  }

  return eStatus;
}

///////////////////////////////////////////////////
// Function : FrameworkunifiedAttachCallbacksToDispatcherWithFd
///////////////////////////////////////////////////
EFrameworkunifiedStatus FrameworkunifiedAttachCallbacksToDispatcherWithFd(HANDLE hApp, const FrameworkunifiedFdProtocolCallbackHandler *handlers,
                                                UI_32 handlerCount) {
  EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;

  if (frameworkunifiedCheckValidAppHandle(hApp) && NULL != handlers && 0 != handlerCount) {
    // setup callbacksWithFd
    for (UI_32 i = 0; i < handlerCount; ++i) {
      if (eFrameworkunifiedStatusOK != (eStatus = FrameworkunifiedAttachCallbackToDispatcherWithFd(hApp, handlers[ i ].fd,
        handlers[ i ].callBack))) {
        break;
      }
    }
  } else {
    eStatus = eFrameworkunifiedStatusInvldParam;
    FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Error : %d, Invalid param ", eStatus);
  }

  return eStatus;
}

///////////////////////////////////////////////////
// Function : FrameworkunifiedAttachCallbackToDispatcherWithFd
///////////////////////////////////////////////////
EFrameworkunifiedStatus FrameworkunifiedAttachCallbackToDispatcherWithFd(HANDLE hApp, int fd, CbFuncPtr fpOnCmd) {
  EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
  int efd;        // FD for multi waiting
  struct epoll_event ev;  // Info struct to associate with multiwaiting FD

  if (frameworkunifiedCheckValidAppHandle(hApp) && 0 < fd && NULL != fpOnCmd) {
    CFrameworkunifiedFrameworkApp *pApp = static_cast<CFrameworkunifiedFrameworkApp *>(hApp);

    // attach callbackFuncPtr and FD to FdTable.
    pApp->fds.insert(std::make_pair(fd, fpOnCmd));

    // Monitor FD by epoll.
    efd = pApp->efd;
    if (0 < efd) {
      ev.events = EPOLLIN;
      ev.data.fd = fd;
      if (-1 == epoll_ctl(efd, EPOLL_CTL_ADD, fd, &ev)) {
        /**
         *  Duplicate registering the same FD in the Dispatcher causes an internal epoll_ctl errno EEXIST(val17) to be returned, which results in an error.
         */
        eStatus = eFrameworkunifiedStatusFail;
        FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "ERROR : epoll_ctl(ADD) Failed, status=%d, errno=%d", eStatus, errno);
      }
    } else {
      eStatus = eFrameworkunifiedStatusFail;
      FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Multi waiting FD is Invalid , status=%d, efd=%d", eStatus, efd);
    }
  } else {
    eStatus = eFrameworkunifiedStatusInvldParam;
    FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Error : %d, Invalid param ", eStatus);
  }

  return eStatus;
}

/////////////////////////////////////////////////////
// Function : FrameworkunifiedAttachParentCallbacksToDispatcher
/////////////////////////////////////////////////////
EFrameworkunifiedStatus FrameworkunifiedAttachParentCallbacksToDispatcher(HANDLE hChildApp, const FrameworkunifiedProtocolCallbackHandler *handlers,
                                                UI_32 handlerCount) {
  EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;

  if (frameworkunifiedCheckValidAppHandle(hChildApp) && NULL != handlers && 0 != handlerCount) {
    CFrameworkunifiedFrameworkApp *pApp = static_cast<CFrameworkunifiedFrameworkApp *>(hChildApp);

    eStatus = FrameworkunifiedAttachCallbacksToDispatcher(hChildApp, pApp->cParentAppName, handlers, handlerCount);
  } else {
    eStatus = eFrameworkunifiedStatusInvldParam;
  }

  return eStatus;
}


/////////////////////////////////////////////////////
// Function : FrameworkunifiedDetachParentCallbacksFromDispatcher
/////////////////////////////////////////////////////
EFrameworkunifiedStatus FrameworkunifiedDetachParentCallbacksFromDispatcher(HANDLE hChildApp, const PUI_32 puiCmdArray, UI_32 uiCommandCount) {
  EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;

  if (frameworkunifiedCheckValidAppHandle(hChildApp) && NULL != puiCmdArray && 0 != uiCommandCount) {
    CFrameworkunifiedFrameworkApp *pApp = static_cast<CFrameworkunifiedFrameworkApp *>(hChildApp);

    eStatus = FrameworkunifiedDetachCallbacksFromDispatcher(hChildApp, pApp->cParentAppName, puiCmdArray, uiCommandCount);
  } else {
    eStatus = eFrameworkunifiedStatusInvldParam;
  }

  return eStatus;
}

/////////////////////////////////////////////////////
// Function : FrameworkunifiedDetachCallbacksFromDispatcher
/////////////////////////////////////////////////////
EFrameworkunifiedStatus FrameworkunifiedDetachCallbacksFromDispatcher(HANDLE hApp, PCSTR pServiceName, const PUI_32 puiCmdArray,
                                            UI_32 uiCommandCount, HANDLE hSession) {
  EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;

  if (frameworkunifiedCheckValidAppHandle(hApp) && NULL != pServiceName && NULL != puiCmdArray && 0 != uiCommandCount) {
    // setup callbacks
    for (UI_32 i = 0; i < uiCommandCount; ++i) {
      if (eFrameworkunifiedStatusOK != (eStatus = FrameworkunifiedDetachCallbackFromDispatcher(hApp, pServiceName,
        puiCmdArray[ i ], hSession))) {
        break;
      }
    }
  } else {
    eStatus = eFrameworkunifiedStatusInvldParam;
  }

  return eStatus;
}



////////////////////////////////////////////
// Function : FrameworkunifiedDetachCallbackFromDispatcher
/////////////////////////////////////////////
EFrameworkunifiedStatus FrameworkunifiedDetachCallbackFromDispatcher(HANDLE hApp, PCSTR pServiceName, UI_32 iCmd, HANDLE hSession) {
  EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;

  if (frameworkunifiedCheckValidAppHandle(hApp) && NULL != pServiceName) {
    CFrameworkunifiedFrameworkApp *pApp = static_cast<CFrameworkunifiedFrameworkApp *>(hApp);
    Services::iterator s_iterator;

    UI_32 uiSessionId = 0;
    if (hSession) {
      uiSessionId = FrameworkunifiedGetSessionId(hSession);
    }

    // finding the service
    s_iterator = pApp->services.find(pServiceName);
    if (s_iterator != pApp->services.end()) {
      SessionTable::iterator session_iterator;
      session_iterator = (s_iterator->second).find(uiSessionId);
      if (session_iterator != (s_iterator->second).end()) {
        ServiceProtocolTable::iterator spt_iterator;
        FRAMEWORKUNIFIEDLOG(ZONE_NS_DIS, __FUNCTION__, "%s : (found): service [%s]", pApp->cAppName, pServiceName);

        spt_iterator = (session_iterator->second).find(iCmd);
        if (spt_iterator != (session_iterator->second).end()) {
          FRAMEWORKUNIFIEDLOG(ZONE_NS_DIS, __FUNCTION__, "%s : Detaching command [0x%X] service [%s]",
            pApp->cAppName, iCmd, pServiceName);
          (session_iterator->second).erase(spt_iterator);
        } else {
          FRAMEWORKUNIFIEDLOG(ZONE_NS_WAR, __FUNCTION__, "%s : Warning : Cmd NOT found [%d] service [%s]",
            pApp->cAppName, iCmd, pServiceName);
        }
      }

    } else {
      FRAMEWORKUNIFIEDLOG(ZONE_NS_WAR, __FUNCTION__, "%s : Warning : Cannot find service [%s]", pApp->cAppName, pServiceName);
      eStatus = eFrameworkunifiedStatusFail;
    }
  } else {
    eStatus = eFrameworkunifiedStatusInvldParam;
  }


  return eStatus;
}

/////////////////////////////////////////////////////
// Function : FrameworkunifiedDetachCallbacksFromDispatcherWithFd
/////////////////////////////////////////////////////
EFrameworkunifiedStatus FrameworkunifiedDetachCallbacksFromDispatcherWithFd(HANDLE hApp, const int *fdArray, UI_32 uiCommandCount) {
  EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;

  if (frameworkunifiedCheckValidAppHandle(hApp) && NULL != fdArray && 0 != uiCommandCount) {
    // setup callbacks
    for (UI_32 i = 0; i < uiCommandCount; ++i) {
      if (eFrameworkunifiedStatusOK != (eStatus = FrameworkunifiedDetachCallbackFromDispatcherWithFd(hApp, fdArray[ i ]))) {
        break;
      }
    }
  } else {
    eStatus = eFrameworkunifiedStatusInvldParam;
    FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Error : %d, Invalid param ", eStatus);
  }

  return eStatus;
}

////////////////////////////////////////////////////
// Function : FrameworkunifiedDetachCallbackFromDispatcherWithFd
////////////////////////////////////////////////////
EFrameworkunifiedStatus FrameworkunifiedDetachCallbackFromDispatcherWithFd(HANDLE hApp, int fd) {
  EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;

  if (frameworkunifiedCheckValidAppHandle(hApp) && 0 < fd) {
    CFrameworkunifiedFrameworkApp *pApp = static_cast<CFrameworkunifiedFrameworkApp *>(hApp);
    FdTable::iterator f_iterator;
    int efd;        // FD for multi waiting
    struct epoll_event ev;  // Info struct to associate with multiwaiting FD

    // finding the FD from FD table
    f_iterator = pApp->fds.find(fd);
    if (f_iterator != pApp->fds.end()) {
      FRAMEWORKUNIFIEDLOG(ZONE_NS_DIS, __FUNCTION__, "%s : Detaching fd [0x%x]", pApp->cAppName, fd);
      pApp->fds.erase(f_iterator);

      // Remove the monitoring of FD from multi waiting FD
      efd = pApp->efd;
      if (0 < efd) {
        ev.events = EPOLLIN;
        ev.data.fd = fd;
        if (-1 == epoll_ctl(efd, EPOLL_CTL_DEL, fd, &ev)) {
          eStatus = eFrameworkunifiedStatusFail;
          FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "ERROR : epoll_ctl(DEL) Failed, status=%d, errno=%d", eStatus, errno);
        }
      } else {
        eStatus = eFrameworkunifiedStatusFail;
        FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Multi waiting FD is Invalid , status=%d, efd=%d", eStatus, efd);
      }
    } else {
      eStatus = eFrameworkunifiedStatusFail;
      FRAMEWORKUNIFIEDLOG(ZONE_NS_WAR, __FUNCTION__, "%s : Warning : Cannot find fd [0x%x]", pApp->cAppName, fd);
    }
  } else {
    eStatus = eFrameworkunifiedStatusInvldParam;
    FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Error :: %d, Invalid param ", eStatus);
  }


  return eStatus;
}

///////////////////////////////////////////////////
// Function : FrameworkunifiedDetachServiceFromDispatcher
///////////////////////////////////////////////////
EFrameworkunifiedStatus FrameworkunifiedDetachServiceFromDispatcher(HANDLE hApp, PCSTR pServiceName) {
  EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;

  if (frameworkunifiedCheckValidAppHandle(hApp) && NULL != pServiceName) {
    CFrameworkunifiedFrameworkApp *pApp = static_cast<CFrameworkunifiedFrameworkApp *>(hApp);
    Services::iterator s_iterator;
    EventServices::iterator es_iterator;

    // finding the service
    s_iterator = pApp->services.find(pServiceName);
    if (s_iterator != pApp->services.end()) {
      FRAMEWORKUNIFIEDLOG(ZONE_NS_DIS, __FUNCTION__, "%s : (found): service [%s]", pApp->cAppName, pServiceName);
      pApp->services.erase(s_iterator);
    } else {
      FRAMEWORKUNIFIEDLOG(ZONE_NS_WAR, __FUNCTION__, "%s : Warning: Cannot find service [%s]", pApp->cAppName, pServiceName);
      eStatus = eFrameworkunifiedStatusFail;
    }

    // finding the service
    es_iterator = pApp->eventservices.find(pServiceName);
    if (es_iterator != pApp->eventservices.end()) {
      eStatus = eFrameworkunifiedStatusOK;
      FRAMEWORKUNIFIEDLOG(ZONE_NS_DIS, __FUNCTION__, "%s : (found): service [%s] in event map", pApp->cAppName, pServiceName);
      pApp->eventservices.erase(es_iterator);
    } else {
      FRAMEWORKUNIFIEDLOG(ZONE_NS_WAR, __FUNCTION__, "%s : Warning : Cannot find service [%s] in event map",
        pApp->cAppName, pServiceName);
    }
  } else {
    eStatus = eFrameworkunifiedStatusInvldParam;
  }

  return eStatus;
}

///////////////////////////////////////////////////
//        Notification functions
///////////////////////////////////////////////////


////////////////////////////////////////////////////////
// Function : FrameworkunifiedAttachNotificationCallbacksToDispatcher
////////////////////////////////////////////////////////
EFrameworkunifiedStatus FrameworkunifiedSubscribeNotificationsWithCallback(HANDLE hApp,  const FrameworkunifiedNotificationCallbackHandler *pNtfyHandler,
                                                 UI_32 uiHandlerCount) {
  EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;

  if (frameworkunifiedCheckValidAppHandle(hApp) && pNtfyHandler && (uiHandlerCount > 0)) {
    CFrameworkunifiedFrameworkApp *pApp = static_cast<CFrameworkunifiedFrameworkApp *>(hApp);

    /// Deal with handling batch processing of subscriptions.
    if (eFrameworkunifiedStatusOK == (eStatus = FrameworkunifiedNPSubscribeToNotifications(hApp, pNtfyHandler, uiHandlerCount))) {
      for (UI_32 i = 0; i < uiHandlerCount; ++i) {
        // Notification names are character arrays of the MAX_STRING_SIZE_NOTIFICATION byte
        // If there are no NULL characters in the array of Notification names, they will overrun during make_pair,
        // so use a strlcpy that substitutes a trailing NULL character.
        char tmp_notification[MAX_STRING_SIZE_NOTIFICATION] = {0};
        strlcpy(tmp_notification, pNtfyHandler[ i ].cNotification, MAX_STRING_SIZE_NOTIFICATION);
        // service found
        pApp->notifications.insert(std::make_pair(tmp_notification, pNtfyHandler[ i ].callBack));

        FRAMEWORKUNIFIEDLOG(ZONE_NS_DIS, __FUNCTION__, "%s : attaching call-back for notification [%s]", pApp->cAppName,
               pNtfyHandler[ i ].cNotification);
      }
    } else {
      FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "%s : Error : [%d] Unable to Subscribe to batch set of notifications",
        pApp->cAppName, eStatus);
    }
  } else {
    eStatus = eFrameworkunifiedStatusInvldParam;
  }

  return eStatus;
}

////////////////////////////////////////////////////////
// Function : FrameworkunifiedAttachNotificationCallbackToDispatcher
////////////////////////////////////////////////////////
EFrameworkunifiedStatus FrameworkunifiedSubscribeNotificationWithCallback(HANDLE hApp, PCSTR pNotification, CbFuncPtr fpOnCmd) {
  EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;

  if (frameworkunifiedCheckValidAppHandle(hApp) && NULL != pNotification && NULL != fpOnCmd) {
    CFrameworkunifiedFrameworkApp *pApp = static_cast<CFrameworkunifiedFrameworkApp *>(hApp);
    NotificationTableRetStatus mRet;

    if (eFrameworkunifiedStatusOK == (eStatus = FrameworkunifiedNPSubscribeToNotification(hApp, pNotification))) {
      // Notification names are character arrays of the MAX_STRING_SIZE_NOTIFICATION byte
      // If there are no NULL characters in the array of Notification names, they will overrun during make_pair,
      // so use a strlcpy that substitutes a trailing NULL character.
              char tmp_notification[MAX_STRING_SIZE_NOTIFICATION] = {0};
              strlcpy(tmp_notification, pNotification, MAX_STRING_SIZE_NOTIFICATION);

      // service found
      mRet = pApp->notifications.insert(std::make_pair(tmp_notification, fpOnCmd));
      if (false == mRet.second) {
        eStatus = eFrameworkunifiedStatusDuplicate;
        FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "%s:Error:[%d] Unable to Subscribe to notification [%s]",
          pApp->cAppName, eStatus, pNotification);
      } else {
        FRAMEWORKUNIFIEDLOG(ZONE_NS_DIS, __FUNCTION__, "%s:attaching call-back for notification [%s]",
          pApp->cAppName, pNotification);
      }
    } else {
      FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "%s:Error:[%d] Unable to Subscribe to notification [%s]",
        pApp->cAppName, eStatus, pNotification);
    }
  } else {
    eStatus = eFrameworkunifiedStatusInvldParam;
  }

  return eStatus;
}



////////////////////////////////////////////////////////
// Function : FrameworkunifiedDetachNotificationCallbacksFromDispatcher
////////////////////////////////////////////////////////
EFrameworkunifiedStatus FrameworkunifiedUnsubscribeNotificationsWithCallback(HANDLE hApp, const FrameworkunifiedNotificationCallbackHandler *pNtfyHandler,
                                                   UI_32 uiHandlerCount) {
  EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
  NotificationTable::iterator n_iterator;
  PCSTR pNotification = NULL;

  if (frameworkunifiedCheckValidAppHandle(hApp) && NULL != pNtfyHandler && (uiHandlerCount > 0)) {
    CFrameworkunifiedFrameworkApp *pApp = static_cast<CFrameworkunifiedFrameworkApp *>(hApp);

    if (eFrameworkunifiedStatusOK == (eStatus = FrameworkunifiedNPUnsubscribeFromNotifications(hApp, pNtfyHandler, uiHandlerCount))) {
      for (UI_32 l_unCount = 0; l_unCount < uiHandlerCount; ++l_unCount) {
        // When registering using FrameworkunifiedSubscribeNotificationWithCallback, etc., the Nortification names NULL the 64th byte.
        // In response to this, the UnRegister uses a strlcpy that puts a NULL in the 64th byte.
        char tmp_notification[MAX_STRING_SIZE_NOTIFICATION] = {0};
        strlcpy(tmp_notification, pNtfyHandler[ l_unCount ].cNotification, MAX_STRING_SIZE_NOTIFICATION);

        n_iterator = pApp->notifications.find(tmp_notification);
        if (n_iterator != pApp->notifications.end()) {
          pApp->notifications.erase(n_iterator);
          FRAMEWORKUNIFIEDLOG(ZONE_NS_DIS, __FUNCTION__, "%s : removed notification [%s]", pApp->cAppName, pNotification);
        } else {
          FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "%s : Error : Cannot find notification [%s]", pApp->cAppName,
                 pNotification != 0 ? pNotification : NULL);
          eStatus = eFrameworkunifiedStatusFail;
        }
      }

      FRAMEWORKUNIFIEDLOG(ZONE_NS_DIS, __FUNCTION__, "%s : detaching call-back for notification [%s]", pApp->cAppName,
             pNotification != 0 ? pNotification : NULL);
    } else {
      FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "%s : Error : [%d] Unable to UnSubscribe from notifications ", pApp->cAppName,
             eFrameworkunifiedStatusOK);
    }
  } else {
    eStatus = eFrameworkunifiedStatusInvldParam;
  }

  return eStatus;
}


////////////////////////////////////////////////////////
// Function : FrameworkunifiedDetachNotificationCallbackToDispatcher
////////////////////////////////////////////////////////
EFrameworkunifiedStatus FrameworkunifiedUnsubscribeNotificationWithCallback(HANDLE hApp, PCSTR pNotification) {
  EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;

  if (frameworkunifiedCheckValidAppHandle(hApp) && NULL != pNotification) {
    CFrameworkunifiedFrameworkApp *pApp = static_cast<CFrameworkunifiedFrameworkApp *>(hApp);
    NotificationTable::iterator n_iterator;

    if (eFrameworkunifiedStatusOK == (eStatus = FrameworkunifiedNPUnsubscribeFromNotification(hApp, pNotification))) {
      // \todo : error handling on all map function calls

      // When registering using FrameworkunifiedSubscribeNotificationWithCallback, etc., the Nortification names NULL the 64th byte.
      // In response to this, the UnRegister uses a strlcpy that puts a NULL in the 64th byte.
      char tmp_notification[MAX_STRING_SIZE_NOTIFICATION] = {0};
      strlcpy(tmp_notification, pNotification, MAX_STRING_SIZE_NOTIFICATION);

      n_iterator = pApp->notifications.find(tmp_notification);
      if (n_iterator != pApp->notifications.end()) {
        pApp->notifications.erase(n_iterator);
        FRAMEWORKUNIFIEDLOG(ZONE_NS_DIS, __FUNCTION__, "%s:removed notification [%s]", pApp->cAppName, pNotification);
      } else {
        FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "%s:Error:Cannot find notification [%s]", pApp->cAppName, pNotification);
        eStatus = eFrameworkunifiedStatusFail;
      }
    } else {
      FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "%s:Error:[%d] Unable to UnSubscribe from notification [%s]",
        pApp->cAppName, eStatus, pNotification);
    }
  } else {
    eStatus = eFrameworkunifiedStatusInvldParam;
  }

  return eStatus;
}

///////////////////////////////////////////////////
//        Defer Message functions
///////////////////////////////////////////////////

////////////////////////////////////////////////////////
// Function : FrameworkunifiedGetDeferQueueCnt
////////////////////////////////////////////////////////
UI_32 FrameworkunifiedGetDeferQueueCnt(HANDLE hApp) {
  UI_32 l_uiCnt = 0;

  if (frameworkunifiedCheckValidAppHandle(hApp)) {
    CFrameworkunifiedFrameworkApp *pApp = static_cast<CFrameworkunifiedFrameworkApp *>(hApp);
    l_uiCnt = static_cast<UI_32>(pApp->deferedMsgQueue.size());
  }

  return l_uiCnt;
}

////////////////////////////////////////////////////////
// Function : FrameworkunifiedIsDeferQueueEmpty
////////////////////////////////////////////////////////
BOOL FrameworkunifiedIsDeferQueueEmpty(HANDLE hApp) {
  BOOL l_bIsQEmpty = TRUE;

  if (frameworkunifiedCheckValidAppHandle(hApp)) {
    CFrameworkunifiedFrameworkApp *pApp = static_cast<CFrameworkunifiedFrameworkApp *>(hApp);
    l_bIsQEmpty = static_cast<BOOL>(pApp->deferedMsgQueue.empty());
  }

  return l_bIsQEmpty;
}

////////////////////////////////////////////////////////
// Function : FrameworkunifiedDeferMessage
////////////////////////////////////////////////////////
EFrameworkunifiedStatus FrameworkunifiedDeferMessage(HANDLE hApp) {
  EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;

  if (frameworkunifiedCheckValidAppHandle(hApp)) {
    CFrameworkunifiedFrameworkApp *pApp = static_cast<CFrameworkunifiedFrameworkApp *>(hApp);
    DeferedMsgInfo defer(pApp->uiProtocolCmd, pApp->cMsgSrcName, pApp->uiMsgRcvBuffer);
    pApp->deferedMsgQueue.push(defer);
  } else {
    eStatus = eFrameworkunifiedStatusInvldParam;
  }

  return eStatus;
}

////////////////////////////////////////////////////////
// Function : FrameworkunifiedClearDeferMessages
////////////////////////////////////////////////////////
EFrameworkunifiedStatus FrameworkunifiedClearDeferMessages(HANDLE hApp) {
  EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;

  if (frameworkunifiedCheckValidAppHandle(hApp)) {
    CFrameworkunifiedFrameworkApp *pApp = static_cast<CFrameworkunifiedFrameworkApp *>(hApp);

    // clear the pop flag!
    pApp->fPopDeferedMsg = FALSE;

    // remove all items from the queue!
    while (!pApp->deferedMsgQueue.empty()) {
      pApp->deferedMsgQueue.pop();
    }
  } else {
    eStatus = eFrameworkunifiedStatusInvldParam;
  }

  return eStatus;
}

////////////////////////////////////////////////////////
// Function : FrameworkunifiedRetrieveDeferMessage
////////////////////////////////////////////////////////
EFrameworkunifiedStatus FrameworkunifiedRetrieveDeferMessage(HANDLE hApp) {
  EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
  uint64_t data = 1;
  if (frameworkunifiedCheckValidAppHandle(hApp)) {
    CFrameworkunifiedFrameworkApp *pApp = static_cast<CFrameworkunifiedFrameworkApp *>(hApp);
    pApp->fPopDeferedMsg = pApp->deferedMsgQueue.empty() ? FALSE : TRUE;
    if (pApp->fPopDeferedMsg) {
      if (-1 == (write(pApp->defer_evfd, &data, sizeof(uint64_t)))) {
        eStatus = eFrameworkunifiedStatusFail;
        FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "ERROR : write Failed, status=%d, errno=%d, defer_evfd=%d",
               eStatus, errno, pApp->defer_evfd);
      }
    }


  } else {
    eStatus = eFrameworkunifiedStatusInvldParam;
  }

  return eStatus;
}


////////////////////////////////////////////////////////////////////////////////////////////
/// FrameworkunifiedIsStateMachineApp
/// Returns TRUE if it's a state machine application else FALSE.
////////////////////////////////////////////////////////////////////////////////////////////
BOOL FrameworkunifiedIsStateMachineApp(HANDLE hApp) {
  BOOL l_bIsStateMachine = FALSE;

  if (frameworkunifiedCheckValidAppHandle(hApp)) {
    CFrameworkunifiedFrameworkApp *pApp = static_cast<CFrameworkunifiedFrameworkApp *>(hApp);
    if (NULL != pApp->m_pFrameworkunifiedStateMachine) {
      l_bIsStateMachine = TRUE;
    }
  }

  return l_bIsStateMachine;
}

////////////////////////////////////////////////////////////////////////////////////////////
/// FrameworkunifiedGetXMLConfigHandle
///   Returns the handle to config file handle
////////////////////////////////////////////////////////////////////////////////////////////
HANDLE FrameworkunifiedGetXMLConfigHandle(HANDLE hApp) {
  FRAMEWORKUNIFIEDLOG(ZONE_NS_WAR, __PRETTY_FUNCTION__, "This function is not implemented!!!!");
  return NULL;
}

EFrameworkunifiedStatus FrameworkunifiedSetMandatoryServiceInfo(HANDLE hApp, PCSTR pNotification, UI_32 uiEventId) {
  EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;

  if (frameworkunifiedCheckValidAppHandle(hApp) && NULL != pNotification) {
    CFrameworkunifiedFrameworkApp *pApp = static_cast<CFrameworkunifiedFrameworkApp *>(hApp);
    ServiceNotificationInfo objNotification = {};
    if (strlen(pNotification) < MAX_STRING_SIZE_NOTIFICATION) {
      strlcpy(objNotification.sNotificationName, pNotification, sizeof(objNotification.sNotificationName));
      objNotification.uiEventId = uiEventId;
      pApp->servicenotificationlist.push_back(objNotification);
    } else {
      FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__,
             " Error : Aborting ... Exceeds Max Notification name size MAX_STRING_SIZE_NOTIFICATION : %d ",
             MAX_STRING_SIZE_NOTIFICATION);
      eStatus = eFrameworkunifiedStatusFail;
    }
  } else {
    eStatus = eFrameworkunifiedStatusInvldParam;
  }

  return eStatus;
}

BOOL FrameworkunifiedIsServiceAvailable(HANDLE hApp) {
  BOOL l_bIsServiceAvailable = FALSE;

  if (frameworkunifiedCheckValidAppHandle(hApp)) {
    // Publish notification
    ServiceAvailability tServiceAvailability = {};

    UI_32 l_uiLength = FrameworkunifiedGetMsgLength(hApp);

    if (sizeof(tServiceAvailability) == l_uiLength) {
      // Read the data from the message
      if (eFrameworkunifiedStatusOK != FrameworkunifiedGetMsgDataOfSize(hApp, &tServiceAvailability, sizeof(tServiceAvailability))) {
        FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, " FrameworkunifiedGetMsgDataOfSize Failed");
      } else {
        // Check the Service availability
        if (eFrameworkunifiedServiceAvailable == tServiceAvailability.eServiceAvailability) {
          l_bIsServiceAvailable = TRUE;
        }
      }
    } else {
      FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, " Error: Received message data size not matched :: %d", l_uiLength);
    }
  }

  return l_bIsServiceAvailable;
}

EFrameworkunifiedStatus FrameworkunifiedPublishServiceAvailability(HANDLE hApp, BOOL bIsAvailable) {
  EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;

  if (frameworkunifiedCheckValidAppHandle(hApp)) {
    CFrameworkunifiedFrameworkApp *pApp = static_cast<CFrameworkunifiedFrameworkApp *>(hApp);
    if (strlen(pApp->sServiceAvailabilityNotification)) {
      // Publish Service available this can also be published from FrameworkunifiedOnStart callback
      pApp->bIsAvailable = bIsAvailable;
      ServiceAvailability tServiceAvailability = {};
      strlcpy(tServiceAvailability.cServiceName, FrameworkunifiedGetAppName(hApp), sizeof(tServiceAvailability.cServiceName));

      if (bIsAvailable) {
        tServiceAvailability.eServiceAvailability = eFrameworkunifiedServiceAvailable;
      } else {
        tServiceAvailability.eServiceAvailability = eFrameworkunifiedServiceNotAvailable;
      }

      if (eFrameworkunifiedStatusOK != (eStatus = FrameworkunifiedNPPublishNotification(hApp, pApp->sServiceAvailabilityNotification,
                                                              &tServiceAvailability, sizeof(tServiceAvailability)))) {
        FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __PRETTY_FUNCTION__,
               "Failed to Publish notification: %s, status: %d", pApp->sServiceAvailabilityNotification, eStatus);
        FRAMEWORKUNIFIEDLOG_PERFORMANCE("Service Availability Status: %s, ERRORED %d", bIsAvailable ? "TRUE" : "FALSE", eStatus);
      } else {
        FRAMEWORKUNIFIEDLOG_PERFORMANCE("Service Availability Status: %s", bIsAvailable ? "TRUE" : "FALSE");
        FRAMEWORKUNIFIEDLOG(ZONE_NS_IMP_INFO, __FUNCTION__,
               "Publish availability notfn:%s, status:%s", pApp->sServiceAvailabilityNotification,
               bIsAvailable ? "TRUE" : "FALSE");
      }
    } else {
      eStatus = eFrameworkunifiedStatusFail;
    }
  } else {
    eStatus = eFrameworkunifiedStatusInvldParam;
  }

  return eStatus;
}

BOOL FrameworkunifiedGetSelfAvailability(HANDLE hApp) {
  if (frameworkunifiedCheckValidAppHandle(hApp)) {
    CFrameworkunifiedFrameworkApp *pApp = static_cast<CFrameworkunifiedFrameworkApp *>(hApp);
    return pApp->bIsAvailable;
  }

  return FALSE;
}

EFrameworkunifiedStatus FrameworkunifiedRegisterServiceAvailabilityNotification(HANDLE hApp, PCSTR pNotification) {
  EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;

  if (frameworkunifiedCheckValidAppHandle(hApp) && NULL != pNotification) {
    CFrameworkunifiedFrameworkApp *pApp = static_cast<CFrameworkunifiedFrameworkApp *>(hApp);
    if (strlen(pNotification) < MAX_STRING_SIZE_NOTIFICATION) {
      strlcpy(pApp->sServiceAvailabilityNotification, pNotification, sizeof(pApp->sServiceAvailabilityNotification));

      //  Register Notifications
      if (eFrameworkunifiedStatusOK != (eStatus = FrameworkunifiedNPRegisterNotification(hApp, pNotification,
                                                               sizeof(ServiceAvailability), eFrameworkunifiedStateVar))) {
        FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "FrameworkunifiedNPRegisterNotifications %s Failed Status:0x%x ", pNotification, eStatus);
      } else {
        FRAMEWORKUNIFIEDLOG(ZONE_NS_INFO, __FUNCTION__, "FrameworkunifiedNPRegisterNotifications %s success Status:0x%x ",
          pNotification, eStatus);
      }
    } else {
      FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__,
             " Error : Aborting ... Exceeds Max Notification name size MAX_STRING_SIZE_NOTIFICATION : %d ",
             MAX_STRING_SIZE_NOTIFICATION);
      eStatus = eFrameworkunifiedStatusFail;
    }
  } else {
    eStatus = eFrameworkunifiedStatusInvldParam;
  }

  return eStatus;
}

EFrameworkunifiedStatus FrameworkunifiedUnRegisterServiceAvailabilityNotification(HANDLE hApp) {
  EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;

  if (frameworkunifiedCheckValidAppHandle(hApp)) {
    CFrameworkunifiedFrameworkApp *pApp = static_cast<CFrameworkunifiedFrameworkApp *>(hApp);

    //  Register Notifications
    if (eFrameworkunifiedStatusOK != (eStatus = FrameworkunifiedNPUnRegisterNotification(hApp, pApp->sServiceAvailabilityNotification))) {
      FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "FrameworkunifiedNPUnRegisterNotifications %s Failed Status:0x%x ",
             pApp->sServiceAvailabilityNotification != 0 ? pApp->sServiceAvailabilityNotification : NULL, eStatus);
    } else {
      FRAMEWORKUNIFIEDLOG(ZONE_NS_INFO, __FUNCTION__, "FrameworkunifiedNPUnRegisterNotifications %s success Status:0x%x ",
             pApp->sServiceAvailabilityNotification, eStatus);
    }
    memset(pApp->sServiceAvailabilityNotification, 0, MAX_SYS_INFO_SIZE);
    pApp->bIsAvailable = FALSE;
  } else {
    eStatus = eFrameworkunifiedStatusInvldParam;
  }

  return eStatus;
}

////////////////////////////////////////////////////////////////////////////////////////////
/// FrameworkunifiedGetServiceNameOnServiceAvailabilityNotification
/// To be used when client receives service availability notification to get the available
/// service name.
////////////////////////////////////////////////////////////////////////////////////////////
EFrameworkunifiedStatus FrameworkunifiedGetServiceNameOnServiceAvailabilityNotification(HANDLE hApp, PSTR pServiceName) {
  EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
  // Publish notification
  ServiceAvailability tServiceAvailability;

  if (frameworkunifiedCheckValidAppHandle(hApp) && NULL != pServiceName) {
    UI_32 l_uiLength = FrameworkunifiedGetMsgLength(hApp);

    if (sizeof(tServiceAvailability) == l_uiLength) {
      // Read the data from the message
      if (eFrameworkunifiedStatusOK != (eStatus = FrameworkunifiedGetMsgDataOfSize(hApp, &tServiceAvailability, sizeof(tServiceAvailability)))) {
        FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, " FrameworkunifiedGetMsgDataOfSize Failed");
        eStatus = eFrameworkunifiedStatusFail;
      } else {
        if (NULL == std::strncpy(pServiceName, tServiceAvailability.cServiceName, MAX_NAME_SIZE_APP)) {
          FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, " strcpy failed Failed");
          eStatus = eFrameworkunifiedStatusFail;
        }
      }
    } else {
      eStatus = eFrameworkunifiedStatusFail;
      FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, " Error: Received message data size not matched :: %d", l_uiLength);
    }
  } else {
    eStatus = eFrameworkunifiedStatusInvldParam;
  }

  return eStatus;
}

//////////////////////////////////////////
// Function : FrameworkunifiedGetCurrentUser
//////////////////////////////////////////
HANDLE FrameworkunifiedGetCurrentUser(HANDLE hApp) {
  if (frameworkunifiedCheckValidAppHandle(hApp)) {
    const CFrameworkunifiedFrameworkApp *pApp = reinterpret_cast<CFrameworkunifiedFrameworkApp *>(hApp);
    return pApp->hUser;
  } else {
    return NULL;
  }
}

//////////////////////////////////////////
// Function : FrameworkunifiedSetUser
//////////////////////////////////////////
EFrameworkunifiedStatus FrameworkunifiedSetUser(HANDLE hApp, HANDLE hUser) {
  if (frameworkunifiedCheckValidAppHandle(hApp)) {
    CFrameworkunifiedFrameworkApp *pApp = reinterpret_cast<CFrameworkunifiedFrameworkApp *>(hApp);
    pApp->hUser = hUser;
    return eFrameworkunifiedStatusOK;
  } else {
    return eFrameworkunifiedStatusFail;
  }
}

//////////////////////////////////////////
// Function : FrameworkunifiedSetAppData
//////////////////////////////////////////
EFrameworkunifiedStatus FrameworkunifiedSetAppData(HANDLE hApp, PCSTR pKey, PVOID pData) {
  EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusInvldHandle;
  if (frameworkunifiedCheckValidAppHandle(hApp)) {
    CFrameworkunifiedFrameworkApp *pApp = reinterpret_cast<CFrameworkunifiedFrameworkApp *>(hApp);
    // Insert the data element
    std::pair<AppData::iterator, bool> l_tRet = pApp->appdata.insert(std::make_pair(pKey, pData));
    if (false == l_tRet.second) {
      eStatus = eFrameworkunifiedStatusFail;
    } else {
      eStatus = eFrameworkunifiedStatusOK;
    }
  }
  return eStatus;
}

//////////////////////////////////////////
// Function : FrameworkunifiedGetAppData
//////////////////////////////////////////
PVOID FrameworkunifiedGetAppData(HANDLE hApp, PCSTR pKey) {
  if (frameworkunifiedCheckValidAppHandle(hApp)) {
    CFrameworkunifiedFrameworkApp *pApp = reinterpret_cast<CFrameworkunifiedFrameworkApp *>(hApp);
    AppData::iterator n_iterator = pApp->appdata.find(pKey);
    if (n_iterator != pApp->appdata.end()) {
      return n_iterator->second;
    }
  }
  return NULL;
}


//////////////////////////////////////////
// Function : FrameworkunifiedRemoveAppData
//////////////////////////////////////////
EFrameworkunifiedStatus FrameworkunifiedRemoveAppData(HANDLE hApp, PCSTR pKey) {
  EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusInvldHandle;
  if (frameworkunifiedCheckValidAppHandle(hApp)) {
    CFrameworkunifiedFrameworkApp *pApp = reinterpret_cast<CFrameworkunifiedFrameworkApp *>(hApp);
    AppData::iterator n_iterator = pApp->appdata.find(pKey);
    if (n_iterator != pApp->appdata.end()) {
      pApp->appdata.erase(n_iterator);

      eStatus = eFrameworkunifiedStatusOK;
    } else {
      eStatus = eFrameworkunifiedStatusFail;
    }
  }
  return eStatus;
}