Init basesystem source codes.
[staging/basesystem.git] / video_in_hal / vehicleservice / positioning_base_library / library / src / _pbMsg.cpp
1 /*
2  * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 /**
18  * @file
19  *    _pbMsg.cpp
20  */
21
22 /*---------------------------------------------------------------------------------*
23  * Include Files                                                                   *
24  *---------------------------------------------------------------------------------*/
25 #include <native_service/frameworkunified_types.h>
26 #include <vehicle_service/positioning_base_library.h>
27 #include <native_service/ns_message_center_if.h>
28 #include "_pbEvent_Internal.h"
29 #include "_pbInternalProc.h"
30
31 #include <native_service/frameworkunified_framework_if.h>
32 #include "WPF_STD_private.h"
33 #include "tchar.h"
34
35 /*---------------------------------------------------------------------------------*
36  * Define                                                                          *
37  *---------------------------------------------------------------------------------*/
38 #define MSG_MAX_NUM_CTRL_MSGQUE       (32)    /* Maximum number of message queues              */
39 #define MSG_MAX_NUM_CTRL_THREAD       (16)    /* Maximum number of threads/process           */
40
41 #define FULL_MSG_NUM_CTRL_MSGQUE      (MSG_MAX_NUM_CTRL_MSGQUE - 4)  /* Message control table threshold (no free) */
42 #define WARN_MSG_NUM_CTRL_MSGQUE      (MSG_MAX_NUM_CTRL_MSGQUE - 10) /* Message control table threshold (warning) */
43
44 /*---------------------------------------------------------------------------------*
45  * Structure                                                                       *
46  *---------------------------------------------------------------------------------*/
47 /*!
48    @brief    Control table for message queues
49 */
50 typedef struct {
51     PNO     pno;                                 /**< Process No.             */
52     char    name[MAX_QUEUE_NAME_SIZE];           /**< Message Que Name         */
53     HANDLE  h_positioningbaselibrary_sender[MSG_MAX_NUM_CTRL_THREAD]; /**< handle to the Sender   */
54     HANDLE  h_sender;                             /**< handle to the Sender   */
55     HANDLE  h_receiver;                           /**< handle to the Receiver */
56     HANDLE  h_zc_sender;                           /**< handle to the ZcSender */
57     uint8_t msg_rcv_buf[MAX_QUEUE_MSG_SIZE];       /**< Message buffer         */
58 } MSG_CTRL_DETAIL_INFO;
59
60 /*!
61    @brief    Control table for message queues
62 */
63 typedef struct {
64     MSG_CTRL_DETAIL_INFO info[MSG_MAX_NUM_CTRL_MSGQUE];   /**< message infomation */
65     uint32_t             use_cnt;                          /**< Use Counter        */
66     uint32_t             rsv_cnt;                          /**< Reserve Counter    */
67 } MSG_CTRL_INFO;
68
69 /*---------------------------------------------------------------------------------*
70  * Grobal Value                                                                    *
71  *---------------------------------------------------------------------------------*/
72 /**
73    Message control table
74    Note: Access to this instance shall be made through the operation module.
75 */
76 static MSG_CTRL_INFO    g_msg_ctrl_tbl;   // NOLINT(readability/nolint)  global Class instance
77
78 /** Message-control-table-locking Mutex handles */
79 static HANDLE            g_h_mtx;
80
81 /*---------------------------------------------------------------------------------*
82  * Local Function Prototype                                                        *
83  *---------------------------------------------------------------------------------*/
84 /* Message Control Table Operation Functions */
85 static void     MsgSetPnoOfCtrlTbl(u_int32 idx, PNO pno);                  /* PNO setting                     */
86 static PNO      MsgGetPnoOfCtrlTbl(u_int32 idx);                           /* PNO acquisition                     */
87 static void     MsgSetNameOfCtrlTbl(u_int32 idx, LPCTSTR name);            /* Message queue name setting        */
88 static char*    MsgGetNameOfCtrlTbl(u_int32 idx);                          /* Get Message Queue Name        */
89 static void     MsgSetReceiverHandleOfCtrlTbl(u_int32 idx, HANDLE handle); /* Message queue handle setting    */
90 static HANDLE   MsgGetReceiverHandleOfCtrlTbl(u_int32 idx);                /* Get message queue handle    */
91 static void     MsgSetSenderHandleOfCtrlTbl(u_int32 idx, HANDLE handle);    /* Message send handle setting    */
92 static HANDLE   MsgGetSenderHandleOfCtrlTbl(u_int32 idx);                    /* Get message send handle    */
93 /* Message send handle setting*/
94 static void     MsgSetPositioningbaselibrarySenderHandleOfCtrlTbl(u_int32 idx, HANDLE handle, uint32_t offset);
95 static HANDLE   MsgGetPositioningbaselibrarySenderHandleOfCtrlTbl(u_int32 idx, uint32_t offset);   /* Get message send handle */
96 static void     MsgSetZcSenderHandleOfCtrlTbl(u_int32 idx, HANDLE handle);     /* Message send handle setting */
97 static HANDLE   MsgGetZcSenderHandleOfCtrlTbl(u_int32 idx);     /* Get message send handle   */
98 static uint8_t* MsgGetMsgRcvBufOfCtrlTbl(uint32_t idx);       /* Get message receive buffer   */
99 static u_int32  MsgSearchEmptyOfCtrlTbl(void);                   /* Retrieval of free space in control table        */
100 static u_int32  MsgSearchPnoOfCtrlTbl(PNO pno);               /* Retrieval of control table PNO            */
101 static u_int32  MsgSearchNameOfCtrlTbl(LPCTSTR name);           /* Retrieve control table queue name        */
102 static void     MsgIncUseCntOfCtrlTbl(void);                  /* Control table usage counter increment */
103 static void     MsgDecUseCntOfCtrlTbl(void);                  /* Control table usage counter increment */
104 static void     MsgIncRsvCntOfCtrlTbl(void);                  /* Control table reservation counter increment */
105 static void     MsgDecRsvCntOfCtrlTbl(void);                  /* Control table reservation counter increment */
106
107 /* Mutex handling Functions for Accessing Message Control Tables */
108 static void MsgCreateMutex(void);    /* Mutex generating */
109 /* Message send handle setting */
110 /* static void MsgDeleteMutex(void); */   // Todo:Uncomment out after completion of implementation of termination processing
111 static void MsgLockMutex(void);    /* Mutex retrieval */
112 static void MsgUnlockMutex(void);    /* Mutex release */
113
114 /*---------------------------------------------------------------------------------*
115  * Function                                                                        *
116  *---------------------------------------------------------------------------------*/
117 /**
118  * @brief
119  *   Initialize the message function
120  *
121  *   Message control table initialization
122  *
123  * @return    RET_NORMAL        Normal completion<br>
124  *            RET_ERRPARAM    Parameter error
125  */
126 RET_API MsgInit(void) {
127     RET_API ret_api = RET_NORMAL;
128     u_int32 i;
129
130     MsgCreateMutex();
131
132     /* Control table initialization */
133     memset(g_msg_ctrl_tbl.info, 0x00, sizeof(g_msg_ctrl_tbl.info));
134
135     for (i = 0; i < MSG_MAX_NUM_CTRL_MSGQUE; i++) {
136         /* Empty character is set for the message queue name. */
137         _tcscpy(g_msg_ctrl_tbl.info[i].name, "");
138     }
139     g_msg_ctrl_tbl.use_cnt = 0;
140     g_msg_ctrl_tbl.rsv_cnt = 0;
141
142     return ret_api;
143 }
144
145 /**
146  * @brief
147  *   Term
148  *
149  * @return    RET_NORMAL    Normal completion<br>
150  *               RET_ERROR    ABENDs
151  */
152 RET_API MsgTerm(void) {  // LCOV_EXCL_START 8:dead code
153     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
154     RET_API    ret_api = RET_ERROR;
155     RET_API    ret;
156     EFrameworkunifiedStatus estatus;
157     HANDLE     handle;
158     u_int32    idx;
159     PNO        pno;
160
161     MsgLockMutex();
162
163     /* Release Message Transmission/Reception Handle */
164     for (idx = 0; idx < MSG_MAX_NUM_CTRL_MSGQUE; idx++) {
165         /* Receive handle acquisition */
166         pno = MsgGetPnoOfCtrlTbl(idx);
167         if (pno != 0) {
168             /* For queue information for internal threads */
169             /* Delete Message Queue */
170             ret = PbDeleteMsg(pno);
171             if (ret != RET_NORMAL) {
172                 FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, "McClose ERROR " \
173                     "[ret:%d, pno:%d]", ret, pno);
174                 /* The module returns OK even if it fails. */
175             }
176         } else {
177             /* Other than the above(Send handle to external process) */
178             /* Get send handle */
179             handle = MsgGetSenderHandleOfCtrlTbl(idx);
180             if (handle != NULL) {
181                 estatus = FrameworkunifiedMcClose(handle);
182                 if (estatus != eFrameworkunifiedStatusOK) {
183                     FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, "FrameworkunifiedMcClose ERROR " \
184                         "[estatus:%d, handle:%p]", estatus, handle);
185                     /* The module returns OK even if it fails. */
186                 } else {
187                     /* Message control table update */
188                     MsgSetSenderHandleOfCtrlTbl(idx, NULL); /* Send handle */
189
190                     MsgSetNameOfCtrlTbl(idx, ""); /* Name */
191                 }
192
193                 FRAMEWORKUNIFIEDLOG(ZONE_20, __FUNCTION__, "### MESSAGE TABLE INFORMATION # " \
194                     "(--) idx=%d, pno=%d, h_positioningbaselibrary_sender[%d]=%p, h_sender=%p, h_receiver=%p, name=%s",
195                     idx, MsgGetPnoOfCtrlTbl(idx), PbGetLocalTid(), MsgGetPositioningbaselibrarySenderHandleOfCtrlTbl(idx, \
196                     PbGetLocalTid()), MsgGetSenderHandleOfCtrlTbl(idx), MsgGetReceiverHandleOfCtrlTbl(idx), \
197                     MsgGetNameOfCtrlTbl(idx));
198             }
199         }
200     }
201
202     MsgUnlockMutex();
203
204     /* MsgDeleteMutex(); */  // Todo:Uncomment out after completion of implementation of termination processing
205
206     /* TODO:Delete the shared memory for the message management table */
207
208     return ret_api;
209 }
210 // LCOV_EXCL_STOP
211
212 /**
213  * @brief
214  *   Create the message queue
215  *
216  *    Creates a message queue.
217  *   This function is implemented on the assumption that a thread name is assigned by prctl() and then called from that thread.
218  *   The generated message queue name is the same as the thread name.
219  *
220  * @param[in]  pno    Process number
221  *
222  * @return    RET_NORMAL        Normal completion<br>
223  *            RET_ERRPARAM    Parameter error<br>
224  *            RET_ERROR        Other errors
225  */
226 RET_API _pb_CreateMsg(PNO pno) {   // NOLINT(readability/nolint)  interface
227     RET_API    ret_api = RET_NORMAL; /* Results of this Module process */
228     u_int32    idx;
229     HANDLE    handle = NULL;
230     char    name[MAX_QUEUE_NAME_SIZE];
231     size_t  len;
232
233     /* If PNO is invalid (0), the parameter is abnormal and processing is not performed. */
234     if (pno == 0) {
235         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Argument ERROR [pno:%d]", pno);
236         ret_api = RET_ERRPARAM;
237     } else {
238         /* Get Thread Name */
239         (void)prctl(PR_GET_NAME, name);
240
241         len = _tcslen(name);
242         if (len >= MAX_QUEUE_NAME_SIZE) {
243             FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Length of thread name is too long(>=%d). "  \
244                 "[len:%zu]", MAX_QUEUE_NAME_SIZE, len);
245             ret_api = RET_ERRPARAM;
246         } else {
247             MsgLockMutex();  // LCOV_EXCL_BR_LINE 200: no branch
248
249             /* Check if the specified PNO is already registered */
250             idx = MsgSearchPnoOfCtrlTbl(pno);  // LCOV_EXCL_BR_LINE 200: no branch
251
252             /* When the entry is already stored */
253             if (idx != MSG_MAX_NUM_CTRL_MSGQUE) {
254                 /* No processing */
255                 FRAMEWORKUNIFIEDLOG(ZONE_20, __FUNCTION__, "### MESSAGE TABLE INFORMATION # " \
256                     "(+) idx=%d, pno=%d, h_positioningbaselibrary_sender[%d]=%p, h_sender=%p, h_receiver=%p, name=%s", \
257                     idx, MsgGetPnoOfCtrlTbl(idx), PbGetLocalTid(), MsgGetPositioningbaselibrarySenderHandleOfCtrlTbl(idx, \
258                     PbGetLocalTid()), MsgGetSenderHandleOfCtrlTbl(idx), MsgGetReceiverHandleOfCtrlTbl(idx), \
259                     MsgGetNameOfCtrlTbl(idx));
260             } else {
261                 /* Not registered */
262                 /* Search for free space */
263                 idx = MsgSearchEmptyOfCtrlTbl();
264                 if (idx == MSG_MAX_NUM_CTRL_MSGQUE) {  // LCOV_EXCL_BR_LINE 200: idx can not be MSG_MAX_NUM_CTRL_MSGQUE
265                     /* Be impossible by design */
266                     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "MsgSearchEmptyOfCtrlTbl ERROR " \
267                         "[idx:%d]", idx);
268                     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
269                     _pb_Exit();  // LCOV_EXCL_LINE 200: idx can not be MSG_MAX_NUM_CTRL_MSGQUE
270
271                     /* don't arrive here. */
272                 } else {
273                     /* Create Message Queue */
274                     handle = McOpenReceiver(name);  // LCOV_EXCL_BR_LINE 4: nsfw error
275                     if (handle == NULL) {  // LCOV_EXCL_BR_LINE 4: nsfw error
276                         /* In the event of failure */
277                         // LCOV_EXCL_START 5: standard lib error
278                         AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
279                         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "McOpenReceiver ERROR " \
280                             "[handle:%p, name:%s]", handle, name);
281                         _pb_Exit();
282                         // LCOV_EXCL_STOP
283                         /* don't arrive here. */
284                     } else {
285                         /* If successful */
286                         /* Message control table update */
287                         MsgSetPnoOfCtrlTbl(idx, pno); /* PNO */  // LCOV_EXCL_BR_LINE 200: no branch
288
289                         MsgSetReceiverHandleOfCtrlTbl(idx, handle); /* Receive handle */  // LCOV_EXCL_BR_LINE 200: no branch  // NOLINT(whitespace/line_length)
290
291                         MsgSetNameOfCtrlTbl(idx, name); /* Name */  // LCOV_EXCL_BR_LINE 200: no branch
292
293                         /* Increment Message Control Table Usage Counter */
294                         MsgIncUseCntOfCtrlTbl();
295
296                         FRAMEWORKUNIFIEDLOG(ZONE_20, __FUNCTION__, \
297                             "### MESSAGE TABLE INFORMATION # (++) idx=%d, pno=%d, h_positioningbaselibrary_sender[%d]=%p, " \
298                             "h_sender=%p, h_receiver=%p, name=%s", idx, MsgGetPnoOfCtrlTbl(idx), \
299                             PbGetLocalTid(), MsgGetPositioningbaselibrarySenderHandleOfCtrlTbl(idx, PbGetLocalTid()), \
300                             MsgGetSenderHandleOfCtrlTbl(idx), MsgGetReceiverHandleOfCtrlTbl(idx), \
301                             MsgGetNameOfCtrlTbl(idx));
302                     }
303                 }
304             }
305
306             MsgUnlockMutex();  // LCOV_EXCL_BR_LINE 200: no branch
307         }
308     }
309
310     return ret_api;
311 }
312
313 /**
314  * @brief
315  *   Delete the message queue
316  *
317  *    Delete a message queue.
318  *   Deleted from the message control table even if closing of the send/receive handle fails
319  *
320  * @param[in]  pno
321  *
322  * @return    RET_NORMAL    Normal completion
323  */
324 RET_API PbDeleteMsg(PNO pno) {  // LCOV_EXCL_START 8:dead code
325     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
326     RET_API    ret_api = RET_NORMAL; /* Results of this Module process        */
327     uint32_t idx;
328     uint32_t i;
329     HANDLE handle;
330     EFrameworkunifiedStatus estatus;
331
332     idx = MsgSearchPnoOfCtrlTbl(pno);
333     if (idx != MSG_MAX_NUM_CTRL_MSGQUE) {
334         /* Receive handle acquisition */
335         handle = MsgGetReceiverHandleOfCtrlTbl(idx);
336         if (handle != NULL) {
337             estatus = McClose(handle);
338             if (estatus != eFrameworkunifiedStatusOK) {
339                 FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, "McClose ERROR " \
340                     "[estatus:%d, handle:%p]", estatus, handle);
341                 /* The module returns OK even if the Close fails. */
342             }
343         }
344
345         /* Get send handle */
346         handle = MsgGetSenderHandleOfCtrlTbl(idx);
347         if (handle != NULL) {
348             estatus = McClose(handle);
349             if (estatus != eFrameworkunifiedStatusOK) {
350                 FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, "McClose ERROR " \
351                     "[estatus:%d, handle:%p]", estatus, handle);
352                 /* The module returns OK even if the Close fails. */
353             }
354         }
355
356         /* Get send handle */
357         handle = MsgGetZcSenderHandleOfCtrlTbl(idx);
358         if (handle != NULL) {
359             estatus = McZcClose(handle);
360             if (estatus != eFrameworkunifiedStatusOK) {
361                 FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, "McZcClose ERROR " \
362                     "[estatus:%d, handle:%p]", estatus, handle);
363                 /* The module returns OK even if the Close fails. */
364             }
365         }
366
367         /* Message control table update */
368         MsgSetPnoOfCtrlTbl(idx, 0); /* PNO */
369
370         for (i = 0; i < MSG_MAX_NUM_CTRL_THREAD; i++) {
371             MsgSetPositioningbaselibrarySenderHandleOfCtrlTbl(idx, NULL, i); /* Send handle */
372         }
373
374         MsgSetSenderHandleOfCtrlTbl(idx, NULL); /* Send handle */
375
376         MsgSetReceiverHandleOfCtrlTbl(idx, NULL); /* Receive handle */
377
378         MsgSetNameOfCtrlTbl(idx, ""); /* Name */
379
380         /* Decrement Message Control Table Usage Counter */
381         MsgDecUseCntOfCtrlTbl();
382
383         FRAMEWORKUNIFIEDLOG(ZONE_20, __FUNCTION__, "### MESSAGE TABLE INFORMATION # " \
384             "(--) idx=%d, pno=%d, h_positioningbaselibrary_sender[%d]=%p, h_sender=%p, h_receiver=%p, name=%s", \
385             idx, MsgGetPnoOfCtrlTbl(idx), PbGetLocalTid(), MsgGetPositioningbaselibrarySenderHandleOfCtrlTbl(idx, \
386             PbGetLocalTid()), MsgGetSenderHandleOfCtrlTbl(idx), MsgGetReceiverHandleOfCtrlTbl(idx), \
387             MsgGetNameOfCtrlTbl(idx));
388     }
389
390     return ret_api;
391 }
392 // LCOV_EXCL_STOP
393
394 /**
395  * @brief
396  *   Receive the message
397  *
398  *    Receive a message for the specified PNO.If the specified PNO is invalid, an error is returned.
399  *    If the size of the received data exceeds the size specified in the parameter, an error is returned.
400  *
401  * @param[in]  pno            Process number
402  * @param[in]  size        Message size
403  * @param[out]  msgbuf    Pointer to message area
404  * @param[in]  mode        Not used
405  *
406  * @return    RET_NORMAL        Normal completion<br>
407  *            RET_ERRPARAM    Parameter error<br>
408  *            RET_ERROR        Other errors
409  */
410 RET_API _pb_RcvMsg(PNO pno, u_int16 size, void** msgbuf, u_int16 mode) {   // NOLINT(readability/nolint)  interface
411     RET_API    ret_api = RET_RCVMSG;   /* Results of this Module process        */
412     u_int32    idx;
413     HANDLE     h_msg_que = NULL;
414     char       source[MAX_QUEUE_NAME_SIZE];
415     u_int32    cmd_id;
416     EFrameworkunifiedStatus rcv_sts;
417     u_int8*    p_msg_rcv_buf;
418     u_int32    msg_len = 0;
419     void*      p_rcv_data;
420
421     /* Null Check */
422     if (msgbuf == NULL) {
423         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Argument ERROR [msgbuf:%p]", msgbuf);
424         ret_api = RET_ERRPARAM;
425     } else if (pno == 0) {
426         /* PNO-invalid Check */
427         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Argument ERROR [pno:%d]", pno);
428         ret_api = RET_ERRPARAM;
429     } else {
430         /* Search if the specified PNO is registered in the control table */
431         idx = MsgSearchPnoOfCtrlTbl(pno);  // LCOV_EXCL_BR_LINE 200: no branch
432         /* Not stored */
433         if (idx == MSG_MAX_NUM_CTRL_MSGQUE) {
434             FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "MsgSearchPnoOfCtrlTbl ERROR " \
435                 "[idx:%d, pno:0x%x]", idx, pno);
436             ret_api = RET_ERRPARAM;
437         } else {
438             /* If it is registered */
439             /* Handle acquisition */
440             h_msg_que = MsgGetReceiverHandleOfCtrlTbl(idx);  // LCOV_EXCL_BR_LINE 200: recv handle created in _pb_CreateMsg  //NOLINT(whitespace/line_length)
441             if (h_msg_que == NULL) {  // LCOV_EXCL_BR_LINE 200: recv handle created in _pb_CreateMsg
442                 /* Be impossible by design */
443                 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Msg_getMsgQueHandleOfCtrlTbl ERROR " \
444                     "[h_msg_que:%p, idx:%d]", h_msg_que, idx);
445                 AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
446                 _pb_Exit();  // LCOV_EXCL_LINE 200: recv handle created in _pb_CreateMsg
447
448                 /* don't arrive here. */
449             }
450
451             /* Get Message Buffer */
452             p_msg_rcv_buf = MsgGetMsgRcvBufOfCtrlTbl(idx);  // LCOV_EXCL_BR_LINE 200: no branch
453
454             /* Receive message */
455             // LCOV_EXCL_BR_START 4: nsfw error
456             rcv_sts = McReceive(h_msg_que,
457                                source, /* app that sent this message */
458                                &cmd_id, /* Command ID */
459                                MAX_QUEUE_MSG_SIZE,
460                                (PVOID)p_msg_rcv_buf);
461             // LCOV_EXCL_BR_STOP
462
463             if (rcv_sts != eFrameworkunifiedStatusOK) {  // LCOV_EXCL_BR_LINE 4: nsfw error
464                 /* In the event of failure */
465                 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "McReceive ERROR " \
466                     "[rcv_sts:%d, h_msg_que:%p, source:%s, cmd_id:0x%x]", rcv_sts, h_msg_que, source, cmd_id);
467                 AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
468                 ret_api = RET_ERROR;  // LCOV_EXCL_LINE 4: nsfw error
469             } else {
470                 /* If successful */
471                 /* Size check */
472                 msg_len = McGetLength(p_msg_rcv_buf);  // LCOV_EXCL_BR_LINE 4: nsfw error
473                 if ((msg_len <= size) && (msg_len > 0)) {  // LCOV_EXCL_BR_LINE 4: nsfw error
474                     /* OK */
475                     /* Get Message */
476                     p_rcv_data = McGetDataPointer(p_msg_rcv_buf);  // LCOV_EXCL_BR_LINE 4: nsfw error
477                     if (p_rcv_data == NULL) {  // LCOV_EXCL_BR_LINE 4: nsfw error
478                         // LCOV_EXCL_START 4: nsfw error
479                         AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
480                         rcv_sts = McGetDataOfSize(p_msg_rcv_buf, *msgbuf, msg_len);
481                         if (rcv_sts != eFrameworkunifiedStatusOK) {  // LCOV_EXCL_BR_LINE 4: nsfw error
482                             /* Message acquisition failure */
483                             FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, \
484                                 "McGetDataOfSize ERROR [rcv_sts:%d]", rcv_sts);
485                             ret_api = RET_ERROR;
486                             // LCOV_EXCL_STOP
487                         } else {
488                             FRAMEWORKUNIFIEDLOG(ZONE_20, __FUNCTION__, \
489                                 "McReceive/McGetDataOfSize SUCCESS [rcv_sts:%d, h_msg_que:%p, source:%s, " \
490                                 "cmd_id:0x%x, msg_len:%d]", rcv_sts, h_msg_que, source, cmd_id, msg_len);
491                         }
492                     } else {
493                         *msgbuf = p_rcv_data;
494                     }
495                 } else {
496                     /* NG */
497                     // LCOV_EXCL_START 4: nsfw error
498                     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
499                     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "McGetLength ERROR " \
500                         "[size:%d < msg_len:%d]", size, msg_len);
501                     ret_api = RET_ERROR;
502                     // LCOV_EXCL_STOP
503                 }
504             }
505         }
506     }
507
508     return ret_api;
509 }
510
511 /**
512  * @brief
513  *   Send the message
514  *
515  *   For in-process communication
516  *    Sends a message to the specified PNO.If the specified PNO is invalid, an error is returned.
517  *
518  * @param[in]  pno        Process number
519  * @param[in]  size    Message size
520  * @param[in]  msgbuf    Pointer to message storage area
521  * @param[in]  mode    Not used
522  *
523  * @return    RET_NORMAL        Normal completion<br>
524  *            RET_ERRPARAM    Parameter error<br>
525  *            RET_ERROR        Other errors
526  */
527 RET_API _pb_SndMsg(PNO pno, u_int16 size, void* msgbuf, u_int16 mode) {   // NOLINT(readability/nolint)  interface
528     RET_API    ret_api = RET_NORMAL; /* Results of this Module process */
529     u_int32    idx;
530     PCSTR      msg_que_name;
531     HANDLE     handle; /* handle to the send message queue */
532     EFrameworkunifiedStatus estatus;
533     T_APIMSG_MSGBUF_HEADER *p_msg_header;
534     CID        cid;
535
536     /* Null Check */
537     if (msgbuf == NULL) {
538         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Argument ERROR [msgbuf:%p]", msgbuf);
539         ret_api = RET_ERRPARAM;
540     } else if (pno == 0) {
541         /* PNO-invalid Check */
542         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Argument ERROR [pno:%d]", pno);
543         ret_api = RET_ERRPARAM;
544     } else {
545         MsgLockMutex();
546
547         /* Check if the specified PNO is registered in the message control table */
548         idx = MsgSearchPnoOfCtrlTbl(pno);
549         if (idx == MSG_MAX_NUM_CTRL_MSGQUE) {
550             /* Not stored */
551             FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "MsgSearchPnoOfCtrlTbl ERROR!! " \
552                 "[pno=%d]", pno);
553
554             ret_api = RET_ERRPARAM;
555         } else {
556             /* If it is registered */
557             /* Acquire transmission handle from management table */
558             handle = MsgGetSenderHandleOfCtrlTbl(idx);
559             if (handle == NULL) {
560                 /* Get message queue name */
561                 msg_que_name = MsgGetNameOfCtrlTbl(idx);
562
563                 /* Get send handle  */
564                 handle = McOpenSender(msg_que_name);  // LCOV_EXCL_BR_LINE 4: nsfw error
565                 /* When handle acquisition fails */
566                 if (handle == NULL) {  // LCOV_EXCL_BR_LINE 4: nsfw error
567                     // LCOV_EXCL_START 4: nsfw error
568                     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
569                     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "McOpenSender ERROR " \
570                         "[handle:%p, msg_que_name:%s]", handle, msg_que_name);
571
572                     ret_api = RET_ERROR;
573                     // LCOV_EXCL_STOP
574                 }
575
576                 /* Message control table update */
577                 MsgSetSenderHandleOfCtrlTbl(idx, handle); /* Send handle */
578
579                 FRAMEWORKUNIFIEDLOG(ZONE_20, __FUNCTION__, "### MESSAGE TABLE INFORMATION # " \
580                     "(+) idx=%d, pno=%d, h_positioningbaselibrary_sender[%d]=%p, h_sender=%p, h_receiver=%p, name=%s", \
581                     idx, MsgGetPnoOfCtrlTbl(idx), PbGetLocalTid(), MsgGetPositioningbaselibrarySenderHandleOfCtrlTbl(idx, \
582                     PbGetLocalTid()), MsgGetSenderHandleOfCtrlTbl(idx), MsgGetReceiverHandleOfCtrlTbl(idx), \
583                     MsgGetNameOfCtrlTbl(idx));
584             }
585             /* When handle acquisition is successful */
586             if (handle != NULL) {
587                 p_msg_header = reinterpret_cast<T_APIMSG_MSGBUF_HEADER*>(msgbuf);
588                 cid = p_msg_header->hdr.cid;
589
590                 /* Messaging */
591                 estatus = McSend(handle,
592                                  "", /* Sender name */
593                                  cid, /* Command ID */
594                                  size,
595                                  msgbuf);  // LCOV_EXCL_BR_LINE 4: nsfw error
596                 /* When transmission fails */
597                 if (estatus != eFrameworkunifiedStatusOK) {  // LCOV_EXCL_BR_LINE 4: nsfw error
598                     // LCOV_EXCL_START 4: nsfw error
599                     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
600                     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "McSend ERROR " \
601                         "[estatus:%d, idx:%d, handle:%p, cid:0x%x, size:%d]", estatus, idx, handle, cid, size);
602                     ret_api = RET_ERROR;
603                     // LCOV_EXCL_STOP
604                 } else {
605                     FRAMEWORKUNIFIEDLOG(ZONE_20, __FUNCTION__, "McSend SUCCESS " \
606                         "[estatus:%d, idx:%d, handle:%p, cid:0x%x, size:%d]", estatus, idx, handle, cid, size);
607                 }
608
609                 /* Close all handles at the time of termination */
610             }
611         }
612
613         MsgUnlockMutex();
614     }
615
616     return ret_api;
617 }
618
619 /**
620  * @brief
621  *   Acquire transmission buffer for in-process communication (for non-copy API)
622  *   Gets the buffer for sending messages to the specified PNO.If the specified PNO is invalid, an error is returned.
623  *   Set the send data in the acquired buffer and send it with _pb_ZcSndMsg().
624  *
625  * @param[in]  pno        Process number
626  * @param[out] p_snd_buf    Transmitting buffer
627  *
628  * @return    RET_NORMAL        Normal completion<br>
629  *            RET_ERRPARAM    Parameter error<br>
630  *            RET_ERROR        Other errors
631  */
632 RET_API _pb_GetZcSndBuf(PNO pno, void** p_snd_buf) {   // NOLINT(readability/nolint)  interface
633     RET_API     ret_api = RET_NORMAL; /* Results of this Module process */
634     u_int32     idx;
635     PCSTR       msg_que_name;
636     HANDLE      handle; /* handle to the send message queue */
637
638     /* PNO-invalid Check */
639     if (pno == 0) {
640         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Argument ERROR [pno:%d]", pno);
641         ret_api = RET_ERRPARAM;
642     } else {
643         MsgLockMutex();
644
645         /* Check if the specified PNO is registered in the message control table */
646         idx = MsgSearchPnoOfCtrlTbl(pno);
647         if (idx == MSG_MAX_NUM_CTRL_MSGQUE) {
648             /* Not stored */
649             FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "MsgSearchPnoOfCtrlTbl ERROR!! [pno=%d]", pno);
650
651             ret_api = RET_ERRPARAM;
652         } else {
653             /* If it is registered */
654             /* Acquire transmission handle from management table */
655             handle = MsgGetZcSenderHandleOfCtrlTbl(idx);
656             if (handle == NULL) {
657                 /* Get message queue name */
658                 msg_que_name = MsgGetNameOfCtrlTbl(idx);
659
660                 /* Get send handle  */
661                 handle = McZcOpenSender(msg_que_name);  // LCOV_EXCL_BR_LINE 4: nsfw error
662                 if (handle == NULL) {  // LCOV_EXCL_BR_LINE 4: nsfw error
663                     // LCOV_EXCL_START 4: nsfw error
664                     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
665                     /* When handle acquisition fails */
666                     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "McOpenSender ERROR " \
667                         "[handle:%p, msg_que_name:%s]", handle, msg_que_name);
668
669                     ret_api = RET_ERROR;
670                     // LCOV_EXCL_STOP
671                 }
672
673                 /* Message control table update */
674                 MsgSetZcSenderHandleOfCtrlTbl(idx, handle); /* Send handle */
675
676                 FRAMEWORKUNIFIEDLOG(ZONE_20, __FUNCTION__, "### MESSAGE TABLE INFORMATION # " \
677                     "(+) idx=%d, pno=%d, h_positioningbaselibrary_sender[%d]=%p, h_sender=%p, h_receiver=%p, name=%s",
678                     idx, MsgGetPnoOfCtrlTbl(idx), PbGetLocalTid(), MsgGetPositioningbaselibrarySenderHandleOfCtrlTbl(idx, \
679                     PbGetLocalTid()), MsgGetSenderHandleOfCtrlTbl(idx), MsgGetReceiverHandleOfCtrlTbl(idx), \
680                     MsgGetNameOfCtrlTbl(idx));
681             }
682
683             if (handle != NULL) {
684                 /* When handle acquisition is successful */
685                 /* Get message send buffer */
686                 *p_snd_buf = McZcGetBuf(handle);  // LCOV_EXCL_BR_LINE 4: nsfw error
687                 if (*p_snd_buf == NULL) {  // LCOV_EXCL_BR_LINE 4: nsfw error
688                     // LCOV_EXCL_START 4: nsfw error
689                     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
690                     /* When buffer acquisition fails */
691                     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "McZcSetParam ERROR " \
692                         "[idx:%d, handle:%p]", idx, handle);
693                     ret_api = RET_ERROR;
694                     // LCOV_EXCL_STOP
695                 }
696
697                 /* Close all handles at the time of termination */
698             }
699         }
700
701         MsgUnlockMutex();
702     }
703
704     return ret_api;
705 }
706
707 /**
708  * @brief
709  *   Send the message
710  *
711  *   For in-process communication(for non-copy API)
712  *   Sends a message to the specified PNO.If the specified PNO is invalid, an error is returned.
713  *   Before calling this function, send data must be set in the area acquired by _pb_GetZcSndBuf().
714  *
715  * @param[in]  pno        Process number
716  * @param[in]  size    Message size
717  * @param[in]  mode    Not used
718  *
719  * @return    RET_NORMAL        Normal completion<br>
720  *            RET_ERRPARAM    Parameter error<br>
721  *            RET_ERROR        Other errors
722  */
723 RET_API _pb_ZcSndMsg(PNO pno, u_int16 size, u_int16 mode) {   // NOLINT(readability/nolint)  interface
724     RET_API    ret_api = RET_NORMAL; /* Results of this Module process */
725     u_int32    idx;
726     HANDLE    handle; /* handle to the send message queue */
727     EFrameworkunifiedStatus    estatus;
728     T_APIMSG_MSGBUF_HEADER *p_msg_header;
729     CID        cid;
730     void* p_send_data;
731
732     /* PNO-invalid Check */
733     if (pno == 0) {
734         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Argument ERROR [pno:%d]", pno);
735         ret_api = RET_ERRPARAM;
736     } else {
737         MsgLockMutex();
738
739         /* Check if the specified PNO is registered in the message control table */
740         idx = MsgSearchPnoOfCtrlTbl(pno);
741         if (idx == MSG_MAX_NUM_CTRL_MSGQUE) {
742             /* Not stored */
743             FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "MsgSearchPnoOfCtrlTbl ERROR!! [pno=%d]", pno);
744
745             ret_api = RET_ERRPARAM;
746         } else {
747             /* If it is registered */
748             /* Acquire transmission handle from management table */
749             handle = MsgGetZcSenderHandleOfCtrlTbl(idx);  // LCOV_EXCL_BR_LINE 200: sender handle set in _pb_GetZcSndBuf
750             if (handle == NULL) {  // LCOV_EXCL_BR_LINE 200: sender handle set in _pb_GetZcSndBuf
751                 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "handle ERROR " \
752                     "[pno=%d, idx=%d]", pno, idx);
753
754                 AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
755                 ret_api = RET_ERROR;  // LCOV_EXCL_LINE 200: sender handle set in _pb_GetZcSndBuf
756             }
757             /* When handle acquisition is successful */
758             if (handle != NULL) {
759                 /* Messaging */
760                 /* Set the transmission data in advance. */
761                 p_send_data = McZcGetBuf(handle);
762                 if (p_send_data != NULL) {  // LCOV_EXCL_BR_LINE 4: nsfw error
763                     p_msg_header = reinterpret_cast<T_APIMSG_MSGBUF_HEADER*>(p_send_data);
764                     cid = p_msg_header->hdr.cid;
765                     estatus = McZcSetParam(handle, cid, size);
766                     if (estatus == eFrameworkunifiedStatusOK) {  // LCOV_EXCL_BR_LINE 4: nsfw error
767                         estatus = McZcSend(handle);  // LCOV_EXCL_BR_LINE 4: nsfw error
768                         /* When transmission fails */
769                         if (estatus != eFrameworkunifiedStatusOK) {  // LCOV_EXCL_BR_LINE 4: nsfw error
770                             FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "McZcSend ERROR "  \
771                                 "[estatus:%d, idx:%d, handle:%p, cid:0x%x, size:%d]", estatus, \
772                                 idx, handle, cid, size);
773                             AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
774                             ret_api = RET_ERROR;  // LCOV_EXCL_LINE 4: nsfw error
775                         } else {
776                             FRAMEWORKUNIFIEDLOG(ZONE_20, __FUNCTION__, "McZcSend SUCCESS " \
777                                 "[estatus:%d, idx:%d, handle:%p, cid:0x%x, size:%d]", estatus, \
778                                 idx, handle, cid, size);
779                         }
780                     } else {
781                         /* When parameter setting fails */
782                         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "McZcSetParam ERROR " \
783                             "[estatus:%d, idx:%d, handle:%p, cid:0x%x, size:%d]", estatus, idx, handle, cid, size);
784                         ret_api = RET_ERROR;
785                     }
786                 } else {
787                     /* When parameter buffer acquisition fails */
788                     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "McZcGetBuf ERROR " \
789                         "[idx:%d, handle:%p, size:%d]", idx, handle, size);
790                     ret_api = RET_ERROR;
791                 }
792
793                 /* Close all handles at the time of termination */
794             }
795         }
796
797         MsgUnlockMutex();
798     }
799
800     return ret_api;
801 }
802
803 /**
804  * @brief
805  *   Send the message
806  *
807  *   For interprocess communication
808  *    Sends a message to the specified process.If the specified process is invalid, an error is returned.
809  *
810  *   Note: Since the data sent by this function is to be received by the dispatcher, the message header
811  *      must not be included in the send data specified by the argument.
812  *
813  * @param[in]  name    Destination Process Name
814  * @param[in]  cid        Command ID
815  * @param[in]  size    Message size
816  * @param[in]  msgbuf    Pointer to message storage area
817  * @param[in]  mode    Not used
818  *
819  * @return    RET_NORMAL        Normal completion<br>
820  *            RET_ERRPARAM    Parameter error<br>
821  *            RET_ERROR        Other errors
822  */
823 RET_API _pb_SndMsg_Ext(PCSTR name, CID cid, u_int16 size, const void* msgbuf,   // NOLINT(readability/nolint) interface
824         u_int16 mode) {
825     RET_API     ret_api = RET_NORMAL; /* Results of this Module process */
826     uint32_t    thread_offset;
827     u_int32     idx;
828     HANDLE      h_positioningbaselibrary_service = NULL;
829     EFrameworkunifiedStatus  estatus;
830     size_t      len;
831     HANDLE      h_app;
832
833     /* Null Check */
834     if ((name == NULL) || (msgbuf == NULL)) {
835         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Argument ERROR " \
836             "[name:%p, msgbuf:%p]", name, msgbuf);
837         ret_api = RET_ERRPARAM;
838     } else {
839         h_app = _pb_GetAppHandle();
840
841         len = _tcslen(name);
842         if (len >= MAX_QUEUE_NAME_SIZE) {
843             FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Argument ERROR!! " \
844                 "Length of thread name is too long(>=%d). [len:%zu]", MAX_QUEUE_NAME_SIZE, len);
845             ret_api = RET_ERRPARAM;
846         } else {
847             thread_offset = PbGetLocalTid();
848
849             MsgLockMutex();
850
851             idx = MsgSearchNameOfCtrlTbl(name);
852
853             if (idx != MSG_MAX_NUM_CTRL_MSGQUE) {
854                 h_positioningbaselibrary_service = MsgGetPositioningbaselibrarySenderHandleOfCtrlTbl(idx, thread_offset);
855                 if (h_positioningbaselibrary_service == NULL) {
856                     h_positioningbaselibrary_service = FrameworkunifiedMcOpenSender(h_app, name);  // LCOV_EXCL_BR_LINE 4: nsfw error
857                     /* When handle acquisition fails */
858                     if (h_positioningbaselibrary_service == NULL) {  // LCOV_EXCL_BR_LINE 4: nsfw error
859                         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "FrameworkunifiedMcOpenSender ERROR!! " \
860                             "[h_positioningbaselibrary_service=%p, h_app=%p, name=%s]", h_positioningbaselibrary_service, h_app, name);
861                         AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
862                         ret_api = RET_ERROR;  // LCOV_EXCL_LINE 4: nsfw error
863                     } else {
864                         /* Message control table update */
865                         MsgSetPositioningbaselibrarySenderHandleOfCtrlTbl(idx, h_positioningbaselibrary_service, thread_offset); /* Send handle */
866
867                         FRAMEWORKUNIFIEDLOG(ZONE_20, __FUNCTION__, "### MESSAGE TABLE INFORMATION # " \
868                             "(+) idx=%d, pno=%d, h_positioningbaselibrary_sender[%d]=%p, h_sender=%p, h_receiver=%p, name=%s", \
869                             idx, MsgGetPnoOfCtrlTbl(idx), PbGetLocalTid(), \
870                             MsgGetPositioningbaselibrarySenderHandleOfCtrlTbl(idx, PbGetLocalTid()), MsgGetSenderHandleOfCtrlTbl(idx), \
871                             MsgGetReceiverHandleOfCtrlTbl(idx), MsgGetNameOfCtrlTbl(idx));
872                     }
873                 }
874             } else {
875                 /* Search for free space */
876                 idx = MsgSearchEmptyOfCtrlTbl();
877                 if (idx == MSG_MAX_NUM_CTRL_MSGQUE) {  // LCOV_EXCL_BR_LINE 200: idx can not be MSG_MAX_NUM_CTRL_MSGQUE
878                     /* Be impossible by design */
879                     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "MsgSearchEmptyOfCtrlTbl ERROR!! " \
880                         "[idx:%d]", idx);
881                     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
882                     _pb_Exit();  // LCOV_EXCL_LINE 200: idx can not be MSG_MAX_NUM_CTRL_MSGQUE
883
884                     /* don't arrive here. */
885                 } else {
886                     /* Get send handle */
887                     h_positioningbaselibrary_service = FrameworkunifiedMcOpenSender(h_app, name);  // LCOV_EXCL_BR_LINE 4: nsfw error
888                     /* When handle acquisition fails */
889                     if (h_positioningbaselibrary_service == NULL) {  // LCOV_EXCL_BR_LINE 4: nsfw error
890                         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "FrameworkunifiedMcOpenSender ERROR!! " \
891                             "[h_positioningbaselibrary_service=%p, h_app=%p, name=%s]", h_positioningbaselibrary_service, h_app, name);
892                         AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
893                         ret_api = RET_ERROR;  // LCOV_EXCL_LINE 4: nsfw error
894                     } else {
895                         /* Message control table update */
896                         MsgSetPositioningbaselibrarySenderHandleOfCtrlTbl(idx, h_positioningbaselibrary_service, thread_offset); /* Send handle */
897
898                         MsgSetNameOfCtrlTbl(idx, name); /* Name */
899
900                         /* Increment Message Control Table Usage Counter */
901                         MsgIncUseCntOfCtrlTbl();
902
903                         FRAMEWORKUNIFIEDLOG(ZONE_20, __FUNCTION__, \
904                             "### MESSAGE TABLE INFORMATION # (++) idx=%d, pno=%d, h_positioningbaselibrary_sender[%d]=%p, " \
905                             "h_sender=%p, h_receiver=%p, name=%s", idx, MsgGetPnoOfCtrlTbl(idx), \
906                             PbGetLocalTid(), MsgGetPositioningbaselibrarySenderHandleOfCtrlTbl(idx, PbGetLocalTid()), \
907                             MsgGetSenderHandleOfCtrlTbl(idx), MsgGetReceiverHandleOfCtrlTbl(idx), \
908                             MsgGetNameOfCtrlTbl(idx));
909                     }
910                 }
911             }
912
913             MsgUnlockMutex();
914             /* When handle acquisition is successful */
915             if (h_positioningbaselibrary_service != NULL) {
916                 /* Messaging */
917                 estatus = FrameworkunifiedSendMsg(h_positioningbaselibrary_service, cid, size, msgbuf);  // LCOV_EXCL_BR_LINE 4: nsfw error
918                 /* When transmission fails */
919                 if (estatus != eFrameworkunifiedStatusOK) {  // LCOV_EXCL_BR_LINE 4: nsfw error
920                     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "FrameworkunifiedSendMsg ERROR!! " \
921                         "[name=%s, estatus=%d, h_positioningbaselibrary_service=%p, cid=%d, size=%d]", \
922                         name, estatus, h_positioningbaselibrary_service, cid, size);
923                     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
924                     ret_api = RET_ERROR;  // LCOV_EXCL_LINE 4: nsfw error
925                 } else {
926                     FRAMEWORKUNIFIEDLOG(ZONE_17, __FUNCTION__, "Send message = " \
927                         "[Destination:%s][CID:0x%X]", name, cid);
928                 }
929                 /* Close all handles at the time of termination */
930             }
931         }
932     }
933
934     return ret_api;
935 }
936
937 /*---------------------------------------------------------------------------------*
938  * Local Function                                                                  *
939  *---------------------------------------------------------------------------------*/
940 /**
941  * @brief
942  *   PNO setting(Message control table)
943  *
944  *   If an invalid value is specified for an argument, the system assumes that it is a design problem and calls _pb_Exit().
945  *
946  * @param[in]    idx    Control Table Element Number
947  * @param[in]    pno Process number
948  */
949 static void MsgSetPnoOfCtrlTbl(u_int32 idx, PNO pno) {
950     /* check index */
951     if (idx >= MSG_MAX_NUM_CTRL_MSGQUE) {  // LCOV_EXCL_BR_LINE 6: idx cannot greater
952         /* forbidden */
953         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Argument ERROR [idx:%d, pno:%d]", idx, pno);
954         AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
955         _pb_Exit();  // LCOV_EXCL_LINE 6: idx cannot greater
956
957         /* don't arrive here. */
958     } else {
959         g_msg_ctrl_tbl.info[idx].pno = pno;
960     }
961
962     return;
963 }
964
965 /**
966  * @brief
967  *   PNO acquisition(Message control table)
968  *
969  *   If an invalid value is specified for an argument, the system assumes that it is a design problem and calls _pb_Exit().
970  *
971  * @param[in]    idx    Control Table Element Number
972  * @param[in]    pno Process number
973  */
974 static PNO MsgGetPnoOfCtrlTbl(u_int32 idx) {
975     /* check index */
976     if (idx >= MSG_MAX_NUM_CTRL_MSGQUE) {  // LCOV_EXCL_BR_LINE 6: idx cannot greater
977         /* forbidden */
978         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Argument ERROR [idx:%d]", idx);
979         AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
980         _pb_Exit();  // LCOV_EXCL_LINE 6: idx cannot greater
981
982         /* don't arrive here. */
983     }
984
985     return g_msg_ctrl_tbl.info[idx].pno;
986 }
987
988 /**
989  * @brief
990  *   Message queue name setting(Message control table)
991  *
992  *   If an invalid value is specified for an argument, the system assumes that it is a design problem and calls _pb_Exit().
993  *
994  * @param[in]    idx    Control Table Element Number
995  * @param[in]    name Message queue name
996  */
997 static void MsgSetNameOfCtrlTbl(u_int32 idx, LPCTSTR name) {
998     /* check index */
999     if (idx >= MSG_MAX_NUM_CTRL_MSGQUE) {  // LCOV_EXCL_BR_LINE 6: idx cannot greater
1000         /* forbidden */
1001         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Argument ERROR [idx:%d, name:%s]", idx, name);
1002         AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
1003         _pb_Exit();  // LCOV_EXCL_LINE 6: idx cannot greater
1004
1005         /* don't arrive here. */
1006     }
1007
1008     _tcscpy(g_msg_ctrl_tbl.info[idx].name, name);
1009
1010     return;
1011 }
1012
1013 /**
1014  * @brief
1015  *   Get Message Queue Name(Message control table)
1016  *
1017  *   If an invalid value is specified for an argument, the system assumes that it is a design problem and calls _pb_Exit().
1018  *
1019  * @param[in]    idx  Control Table Element Number
1020  *
1021  * @return Message queue name
1022  */
1023 static char* MsgGetNameOfCtrlTbl(u_int32 idx) {
1024     /* check index */
1025     if (idx >= MSG_MAX_NUM_CTRL_MSGQUE) {  // LCOV_EXCL_BR_LINE 6: idx cannot greater
1026         /* forbidden */
1027         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Argument ERROR [idx:%d]", idx);
1028         AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
1029         _pb_Exit();  // LCOV_EXCL_LINE 6: idx cannot greater
1030
1031         /* don't arrive here. */
1032     }
1033
1034     return g_msg_ctrl_tbl.info[idx].name;
1035 }
1036
1037 /**
1038  * @brief
1039  *   Message reception handle setting(Message control table)
1040  *
1041  *   If an invalid value is specified for an argument, the system assumes that it is a design problem and calls _pb_Exit().
1042  *
1043  * @param[in]    idx        Control Table Element Number
1044  * @param[in]    handle    Message queue handle
1045  */
1046 static void MsgSetReceiverHandleOfCtrlTbl(u_int32 idx, HANDLE handle) {
1047     /* check index */
1048     if (idx >= MSG_MAX_NUM_CTRL_MSGQUE) {  // LCOV_EXCL_BR_LINE 6: idx cannot greater
1049         /* forbidden */
1050         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Argument ERROR " \
1051             "[idx:%d, handle:%p]", idx, handle);
1052         AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
1053         _pb_Exit();  // LCOV_EXCL_LINE 6: idx cannot greater
1054
1055         /* don't arrive here. */
1056     } else {
1057         g_msg_ctrl_tbl.info[idx].h_receiver = handle;
1058     }
1059
1060     return;
1061 }
1062
1063 /**
1064  * @brief
1065  *   Get message reception handle(Message control table)
1066  *
1067  *   If an invalid value is specified for an argument, the system assumes that it is a design problem and calls _pb_Exit().
1068  *
1069  * @param[in]    idx    Control Table Element Number
1070  *
1071  * @return    Message queue handle
1072  */
1073 static HANDLE MsgGetReceiverHandleOfCtrlTbl(u_int32 idx) {
1074     /* check index */
1075     if (idx >= MSG_MAX_NUM_CTRL_MSGQUE) {  // LCOV_EXCL_BR_LINE 6: idx cannot greater
1076         /* forbidden */
1077         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Argument ERROR [idx:%d]", idx);
1078         AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
1079         _pb_Exit();  // LCOV_EXCL_LINE 6: idx cannot greater
1080
1081         /* don't arrive here. */
1082     }
1083
1084     return g_msg_ctrl_tbl.info[idx].h_receiver;
1085 }
1086
1087 /**
1088  * @brief
1089  *   Message send handle setting(Message control table)
1090  *
1091  *   If an invalid value is specified for an argument, the system assumes that it is a design problem and calls _pb_Exit().
1092  *
1093  * @param[in]    idx        Control Table Element Number
1094  * @param[in]    handle    Message queue handle
1095  */
1096 static void MsgSetSenderHandleOfCtrlTbl(u_int32 idx, HANDLE handle) {
1097     /* check index */
1098     if (idx >= MSG_MAX_NUM_CTRL_MSGQUE) {    // LCOV_EXCL_BR_LINE 6: idx cannot greater
1099         /* forbidden */
1100         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Argument ERROR " \
1101             "[idx:%d, handle:%p]", idx, handle);
1102         AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
1103         _pb_Exit();    // LCOV_EXCL_LINE 6: idx cannot greater
1104
1105         /* don't arrive here. */
1106     } else {
1107         g_msg_ctrl_tbl.info[idx].h_sender = handle;
1108     }
1109
1110     return;
1111 }
1112
1113 /**
1114  * @brief
1115  *   Get message send handle(Message control table)
1116  *
1117  *   If an invalid value is specified for an argument, the system assumes that it is a design problem and calls _pb_Exit().
1118  *
1119  * @param[in]    idx    Control Table Element Number
1120  *
1121  * @return    Message queue handle
1122  */
1123 static HANDLE MsgGetSenderHandleOfCtrlTbl(u_int32 idx) {
1124     /* check index */
1125     if (idx >= MSG_MAX_NUM_CTRL_MSGQUE) {    // LCOV_EXCL_BR_LINE 6: idx cannot greater
1126         /* forbidden */
1127         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Argument ERROR [idx:%d]", idx);
1128         AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
1129         _pb_Exit();  // LCOV_EXCL_LINE 6: idx cannot greater
1130
1131         /* don't arrive here. */
1132     }
1133
1134     return g_msg_ctrl_tbl.info[idx].h_sender;
1135 }
1136
1137
1138 /**
1139  * @brief
1140  *   Positioningbaselibrary message send handle setting(Message control table)
1141  *
1142  *   If an invalid value is specified for an argument, the system assumes that it is a design problem and calls _pb_Exit().
1143  *
1144  * @param[in]    idx        Control Table Element Number
1145  * @param[in]    handle    Message queue handle
1146  * @param[in]    offset  Local thread ID
1147  */
1148 static void MsgSetPositioningbaselibrarySenderHandleOfCtrlTbl(u_int32 idx, HANDLE handle, uint32_t offset) {
1149     /* check index */
1150     if (idx >= MSG_MAX_NUM_CTRL_MSGQUE) {  // LCOV_EXCL_BR_LINE 6: idx cannot greater
1151         /* forbidden */
1152         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Argument ERROR " \
1153             "[idx:%d, handle:%p]", idx, handle);
1154         AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
1155         _pb_Exit();  // LCOV_EXCL_LINE 6: idx cannot greater
1156
1157         /* don't arrive here. */
1158     } else {
1159         g_msg_ctrl_tbl.info[idx].h_positioningbaselibrary_sender[offset] = handle;
1160     }
1161
1162     return;
1163 }
1164
1165 /**
1166  * @brief
1167  *   Positioningbaselibrary message send handle acquisition(Message control table)
1168  *
1169  *   If an invalid value is specified for an argument, the system assumes that it is a design problem and calls _pb_Exit().
1170  *
1171  * @param[in]    idx    Control Table Element Number
1172  * @param[in]    offset  Local thread ID
1173  *
1174  * @return    Message queue handle
1175  */
1176 static HANDLE MsgGetPositioningbaselibrarySenderHandleOfCtrlTbl(u_int32 idx, uint32_t offset) {
1177     /* check index */
1178     if (idx >= MSG_MAX_NUM_CTRL_MSGQUE) {  // LCOV_EXCL_BR_LINE 6: idx cannot greater
1179         /* forbidden */
1180         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Argument ERROR [idx:%d]", idx);
1181         AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
1182         _pb_Exit();  // LCOV_EXCL_LINE 6: idx cannot greater
1183
1184         /* don't arrive here. */
1185     }
1186
1187     return g_msg_ctrl_tbl.info[idx].h_positioningbaselibrary_sender[offset];
1188 }
1189
1190 /**
1191  * @brief
1192  *   Message send handle setting(Message control table)
1193  *
1194  *   If an invalid value is specified for an argument, the system assumes that it is a design problem and calls _pb_Exit().
1195  *
1196  * @param[in]    idx        Control Table Element Number
1197  * @param[in]    handle    Message queue handle
1198  */
1199 static void MsgSetZcSenderHandleOfCtrlTbl(u_int32 idx, HANDLE handle) {
1200     /* check index */
1201     if (idx >= MSG_MAX_NUM_CTRL_MSGQUE) {  // LCOV_EXCL_BR_LINE 6: idx cannot greater
1202         /* forbidden */
1203         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Argument ERROR " \
1204             "[idx:%d, handle:%p]", idx, handle);
1205         AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
1206         _pb_Exit();  // LCOV_EXCL_LINE 6: idx cannot greater
1207
1208         /* don't arrive here. */
1209     } else {
1210         g_msg_ctrl_tbl.info[idx].h_zc_sender = handle;
1211     }
1212
1213     return;
1214 }
1215
1216 /**
1217  * @brief
1218  *   Get message send handle(Message control table)
1219  *
1220  *   If an invalid value is specified for an argument, the system assumes that it is a design problem and calls _pb_Exit().
1221  *
1222  * @param[in]    idx    Control Table Element Number
1223  *
1224  * @return    Message queue handle
1225  */
1226 static HANDLE MsgGetZcSenderHandleOfCtrlTbl(u_int32 idx) {
1227     /* check index */
1228     if (idx >= MSG_MAX_NUM_CTRL_MSGQUE) {  // LCOV_EXCL_BR_LINE 6: idx cannot greater
1229         /* forbidden */
1230         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Argument ERROR [idx:%d]", idx);
1231         AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
1232         _pb_Exit();  // LCOV_EXCL_LINE 6: idx cannot greater
1233
1234         /* don't arrive here. */
1235     }
1236
1237     return g_msg_ctrl_tbl.info[idx].h_zc_sender;
1238 }
1239
1240 /**
1241  * @brief
1242  *   Get message receive buffer(Message control table)
1243  *
1244  * @param[in]    idx    Control Table Element Number
1245  *
1246  * @return    Pointer to message receive buffer
1247  */
1248 static uint8_t* MsgGetMsgRcvBufOfCtrlTbl(uint32_t idx) {
1249     /* check index */
1250     if (idx >= MSG_MAX_NUM_CTRL_MSGQUE) {  // LCOV_EXCL_BR_LINE 6: idx cannot greater
1251         /* forbidden */
1252         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Argument ERROR [idx:%d]", idx);
1253         AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
1254         _pb_Exit();  // LCOV_EXCL_LINE 6: idx cannot greater
1255
1256         /* don't arrive here. */
1257     }
1258
1259     return g_msg_ctrl_tbl.info[idx].msg_rcv_buf;
1260 }
1261
1262 /**
1263  * @brief
1264  *   Search unused area(Message control table)
1265  *
1266  *   Returns the index (minimum value) for accessing the unused area in the message control table.<br>
1267  *   Returns the maximum message queue management value (MSG_MAX_NUM_CTRL_MSGQUE) <br>
1268  *   when no unused area exists
1269  *
1270  * @return    Index for access(Unused area exists.)<br>
1271  *                 Maximum mutex management value(No unused area)
1272  */
1273 static u_int32 MsgSearchEmptyOfCtrlTbl(void) {
1274     int32   ret;
1275     u_int32    idx;
1276
1277     for (idx = 0; idx < MSG_MAX_NUM_CTRL_MSGQUE; idx++) {
1278         ret = _tcscmp(g_msg_ctrl_tbl.info[idx].name, "");
1279
1280         /* For unused space */
1281         if (ret == 0) {
1282             break;
1283         }
1284     }
1285
1286     return idx;
1287 }
1288
1289 /**
1290  * @brief
1291  *   PNO search(Message control table)
1292  *
1293  *   Retrieves whether the specified PNO is already registered in the message control table.<br>
1294  *   If it is registered, the access index is returned.If it is not stored,<br>
1295  *   Returns the maximum message queue management value (MSG_MAX_NUM_CTRL_MSGQUE).
1296  *
1297  * @param[in]    pno Process number
1298  *
1299  * @return    Index for access(If it is registered)<br>
1300  *            Maximum value of message queue management(Not stored)
1301  */
1302 static u_int32 MsgSearchPnoOfCtrlTbl(PNO pno) {
1303     u_int32    idx;
1304     PNO        lPno;
1305
1306     for (idx = 0; idx < MSG_MAX_NUM_CTRL_MSGQUE; idx++) {
1307         lPno = MsgGetPnoOfCtrlTbl(idx);
1308
1309         /* If there is a match */
1310         if (lPno == pno) {
1311             break;
1312         }
1313     }
1314
1315     return idx;
1316 }
1317
1318
1319 /**
1320  * @brief
1321  *   Queue name search(Message control table)
1322  *
1323  *   Retrieves whether the specified queue name is already registered in the message control table.<br>
1324  *   If it is registered, the access index is returned.If it is not stored,<br>
1325  *   Returns the maximum message queue management value (MSG_MAX_NUM_CTRL_MSGQUE).
1326  *
1327  * @param[in]    Name queue-name
1328  *
1329  * @return    Index for access(If it is registered)<br>
1330  *            Maximum value of message queue management(Not stored)
1331  */
1332 static u_int32 MsgSearchNameOfCtrlTbl(LPCTSTR name) {
1333     int32   ret;
1334     u_int32    idx;
1335
1336     for (idx = 0; idx < MSG_MAX_NUM_CTRL_MSGQUE; idx++) {
1337         ret = _tcscmp(g_msg_ctrl_tbl.info[idx].name, name);
1338
1339         /* If there is a match */
1340         if (ret == 0) {
1341             break;
1342         }
1343     }
1344
1345     return idx;
1346 }
1347
1348
1349 /**
1350  * @brief
1351  *   Creation of Mutex for accessing the message control table
1352  */
1353 static void MsgCreateMutex(void) {
1354     g_h_mtx = _pb_CreateMutex(NULL, 0, "Msg_Mutex");
1355     if (g_h_mtx == NULL) {  // LCOV_EXCL_BR_LINE 200: can not be not NULL
1356         // LCOV_EXCL_START 200: can not be not NULL
1357         AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
1358         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "_pb_CreateMutex ERROR [g_h_mtx:%p]", g_h_mtx);
1359         _pb_Exit();
1360         // LCOV_EXCL_STOP
1361
1362         /* don't arrive here. */
1363     }
1364
1365     return;
1366 }
1367
1368 /**
1369  * @brief
1370  *   Acquire Mutex for accessing the message control table
1371  */
1372 static void MsgLockMutex(void) {
1373     DWORD    ret;
1374     ret = PbMutexLock(g_h_mtx, INFINITE);  // LCOV_EXCL_BR_LINE 200: mutex lock can not failed
1375     if (ret != WAIT_OBJECT_0) {  // LCOV_EXCL_BR_LINE 200: mutex lock can not failed
1376         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "PbMutexLock ERROR " \
1377             "[ret:%lu, g_h_mtx:%p]", ret, g_h_mtx);
1378         AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
1379         _pb_Exit();  // LCOV_EXCL_LINE 200: mutex lock can not failed
1380
1381         /* don't arrive here. */
1382     }
1383
1384     return;
1385 }
1386
1387 /**
1388  * @brief
1389  *   Releasing the Mutex for accessing the message control table
1390  */
1391 static void MsgUnlockMutex(void) {
1392     BOOL    ret;
1393     ret = PbMutexUnlock(g_h_mtx);  // LCOV_EXCL_BR_LINE 200: mutex lock can not failed
1394     if (ret != TRUE) {  // LCOV_EXCL_BR_LINE 200: mutex lock can not failed
1395         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "PbMutexUnlock ERROR " \
1396             "[ret:%d, g_h_mtx:%p]", ret, g_h_mtx);
1397         AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
1398         _pb_Exit();  // LCOV_EXCL_LINE 200: mutex lock can not failed
1399
1400         /* don't arrive here. */
1401     }
1402
1403     return;
1404 }
1405
1406 /**
1407  * @brief
1408  *   Obtain dump information
1409  *
1410  * @param[out]     pBuf    Dump info
1411  * @param[in/out]  pLen    Buffer size
1412  */
1413 void _pb_GetDebugMsgMngTbl(void* pBuf, uint8_t* pLen) {
1414     static uint8_t  buf[DEBUG_DUMP_MAX_SIZE];
1415     static uint8_t  bufPositioningbaselibrarySender[DEBUG_DUMP_MAX_SIZE];
1416     static uint8_t  bufTmp[DEBUG_DUMP_MAX_SIZE];
1417     static uint8_t  bufMsg[DEBUG_DUMP_MAX_SIZE];
1418     uint32_t         i;
1419     uint32_t         e;
1420     uint8_t          cnt = 0;
1421
1422     if ((pBuf != NULL) && (pLen != NULL)) {
1423         memset(&buf[0], 0x00, sizeof(buf));
1424         memset(&bufMsg[0], 0x00, sizeof(bufMsg));
1425         for (i = 0; i < MSG_MAX_NUM_CTRL_MSGQUE; i++) {
1426             memset(&bufPositioningbaselibrarySender[0], 0x00, sizeof(bufPositioningbaselibrarySender));
1427             for (e = 0; e < MSG_MAX_NUM_CTRL_THREAD; e++) {
1428                 memset(&bufTmp[0], 0x00, sizeof(bufTmp));
1429                 snprintf(reinterpret_cast<char *>(&bufTmp[0]), sizeof(bufTmp),
1430                         "[%02d]%10p ", e, g_msg_ctrl_tbl.info[i].h_positioningbaselibrary_sender[e]);
1431                 strncat(reinterpret_cast<char *>(&bufPositioningbaselibrarySender[0]), reinterpret_cast<char *>(&bufTmp[0]), \
1432                     strlen(reinterpret_cast<char *>(&bufTmp[0])));
1433             }
1434             memset(&bufTmp[0], 0x00, sizeof(bufTmp));
1435             snprintf(reinterpret_cast<char *>(&bufTmp[0]), sizeof(bufTmp),
1436                     "\n [%02d] pno:0x%04x, name:%16s, hSnd:%10p, hRcv:%10p, hPSnd:%s",
1437                     i,
1438                     g_msg_ctrl_tbl.info[i].pno,
1439                     g_msg_ctrl_tbl.info[i].name,
1440                     g_msg_ctrl_tbl.info[i].h_sender,
1441                     g_msg_ctrl_tbl.info[i].h_receiver,
1442                     &bufPositioningbaselibrarySender[0]);
1443             strncat(reinterpret_cast<char *>(&bufMsg[0]), reinterpret_cast<char *>(&bufTmp[0]), \
1444                 strlen(reinterpret_cast<char *>(&bufTmp[0])));
1445             if (((i+1) % 8) == 0) {
1446                 cnt++;
1447                 memset(&buf[0], 0x00, sizeof(buf));
1448                 snprintf(reinterpret_cast<char *>(&buf[0]), sizeof(buf),
1449                         "Message-%d%s",
1450                         cnt,
1451                         &bufMsg[0]);
1452                 memcpy(pBuf, &buf[0], sizeof(buf));
1453                 pBuf = reinterpret_cast<void *>((reinterpret_cast<uint8_t *>(pBuf)) + sizeof(buf));
1454                 memset(&bufMsg[0], 0x00, sizeof(bufMsg));
1455                 if (cnt >= *pLen) {
1456                     break;
1457                 }
1458             }
1459         }
1460         if (cnt < *pLen) {
1461             if (bufMsg[0] != 0x00) {
1462                 cnt++;
1463                 memset(&buf[0], 0x00, sizeof(buf));
1464                 snprintf(reinterpret_cast<char *>(&buf[0]), sizeof(buf),
1465                         "Message-%d%s",
1466                         cnt,
1467                         &bufMsg[0]);
1468                 memcpy(pBuf, &buf[0], sizeof(buf));
1469             }
1470             *pLen = cnt;
1471         }
1472     }
1473 }
1474
1475 /**
1476  * @brief
1477  *   Message Control Table Usage Counter Increment
1478  *
1479  * @param[in] none
1480  */
1481 static void MsgIncUseCntOfCtrlTbl(void) {
1482     g_msg_ctrl_tbl.use_cnt++;
1483     return;
1484 }
1485
1486 /**
1487  * @brief
1488  *   Message control table usage counter decrement
1489  *
1490  * @param[in] none
1491  */
1492 static void MsgDecUseCntOfCtrlTbl(void) {  // LCOV_EXCL_START 8:dead code
1493     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
1494     g_msg_ctrl_tbl.use_cnt--;
1495     return;
1496 }
1497 // LCOV_EXCL_STOP
1498
1499 /**
1500  * @brief
1501  *   Message Control Table Reserved Counter Increment
1502  *
1503  * @param[in] none
1504  */
1505 static void MsgIncRsvCntOfCtrlTbl(void) {
1506     g_msg_ctrl_tbl.rsv_cnt++;
1507     return;
1508 }
1509
1510 /**
1511  * @brief
1512  *   Message Control Table Reserved Counter Decrement
1513  *
1514  * @param[in] none
1515  */
1516 static void MsgDecRsvCntOfCtrlTbl(void) {
1517     g_msg_ctrl_tbl.rsv_cnt--;
1518     return;
1519 }
1520
1521 /**
1522  * @brief
1523  *   Resource Acquisition Decision(Message control table)
1524  *
1525  * @param[in]  none
1526  *
1527  * @return BOOL
1528  * @retval TRUE  : Normal
1529  * @retval FALSE : Anomaly (Resource shortage)
1530  */
1531 BOOL _pb_GetMsgResource(void) {
1532     BOOL ret = TRUE;
1533     uint32_t cnt;
1534
1535     MsgLockMutex();
1536
1537     /* Increment Message Control Table Reservation Counter */
1538     MsgIncRsvCntOfCtrlTbl();
1539
1540     cnt = g_msg_ctrl_tbl.use_cnt + g_msg_ctrl_tbl.rsv_cnt;
1541     if (cnt >= FULL_MSG_NUM_CTRL_MSGQUE) {
1542         ret = FALSE;
1543         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Lack of resources " \
1544             "[FATAL][use_cnt:%d rsv_cnt:%d]", g_msg_ctrl_tbl.use_cnt, g_msg_ctrl_tbl.rsv_cnt);
1545     } else if (cnt >= WARN_MSG_NUM_CTRL_MSGQUE) {
1546         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Lack of resources " \
1547             "[WARN][use_cnt:%d rsv_cnt:%d]", g_msg_ctrl_tbl.use_cnt, g_msg_ctrl_tbl.rsv_cnt);
1548     }
1549
1550     MsgUnlockMutex();
1551
1552     return ret;
1553 }
1554
1555 /**
1556  * @brief
1557  *   Resource release(Message control table)
1558  *
1559  * @param[in]  none
1560  *
1561  * @return none
1562  */
1563 void _pb_ReleaseMsgResource(void) {
1564     MsgLockMutex();
1565
1566     /* Decrement Message Control Table Reservation Counter */
1567     MsgDecRsvCntOfCtrlTbl();
1568
1569     MsgUnlockMutex();
1570
1571     return;
1572 }