Init basesystem source codes.
[staging/basesystem.git] / nsframework / framework_unified / client / NS_FrameworkCore / src / frameworkunified_framework_logger.cpp
1 /*
2  * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 ///////////////////////////////////////////////////////////////////////////////
18 /// \ingroup  tag_NSFramework
19 /// \brief    Framework wrapper over the logger interface APIs
20 ///
21 ///
22 ///
23 ///////////////////////////////////////////////////////////////////////////////
24
25 ///////////////////////////////////////////////////////////////////////////////
26 // Include Files
27 ///////////////////////////////////////////////////////////////////////////////
28 #include <native_service/ns_rcs_logger_types.h>
29 #include <native_service/frameworkunified_framework_if.h>
30 #include <native_service/ns_logger_if.h>
31 #include <native_service/nslogutil_cmd_if.h>
32 #include <native_service/ns_message_center_if.h>
33 #include <cstdio>
34 #include "frameworkunified_framework_core.h"
35 #include "frameworkunified_framework_internal.h"
36 #include "frameworkunified_framework_utility.h"
37
38 FrameworkunifiedProtocolCallbackHandler rcs_logging_callbacks[] = {
39   { NSRCS_SET_LOG_SETTINGS_REQ,   NSRcsSetLogSettings },
40   { NSRCS_GET_LOG_SETTINGS_REQ,   NSRcsGetLogSettings },
41   { NSRCS_SET_LOG_MASK_REQ,       NSRcsSetLogMask },
42   { NSRCS_SET_LOG_OUT_OPT_REQ,    NSRcsSetOutputLogOpts },
43   { NSRCS_SET_LOG_SEVERITY_REQ,     NSRcsSetLogSeverity },
44 };
45
46
47 FrameworkunifiedProtocolCallbackHandler logging_callbacks[] = {
48   { SET_LOG_MASK,         FrameworkunifiedSetLogMask },
49   { GET_LOG_MASK,         FrameworkunifiedGetLogMask },
50   { SET_LOG_OUT_OPT,        FrameworkunifiedSetOutputLogOpts },
51   { GET_LOG_OUT_OPT,        FrameworkunifiedGetOutputLogOpts },
52   // { kDebugDumpRequest,      FrameworkunifiedDebugDumpRequest }, /// < Added to help Debug Issues with in CCR Radio
53   // Callback attach with frameworkunifieddebug is moved to SystemServices
54   { SET_LOG_SEVERITY,       FrameworkunifiedSetLogSeverity },
55   { GET_LOG_SEVERITY,       FrameworkunifiedGetLogSeverity },
56 };
57
58
59 ////////////////////////////////////////////////////////////////////////////////////////////
60 /// FrameworkunifiedNPRegisterNotification
61 ////////////////////////////////////////////////////////////////////////////////////////////
62 EFrameworkunifiedStatus FrameworkunifiedAttachLoggerCallbacksDispatcher(HANDLE hApp) {
63   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
64
65   if (frameworkunifiedCheckValidAppHandle(hApp)) {
66     eStatus = FrameworkunifiedAttachCallbacksToDispatcher(hApp, "nslogutil", logging_callbacks,
67                                              static_cast<UI_32>(_countof(logging_callbacks)));
68     // Callback attach with of kDebugDumpRequest with frameworkunifieddebug is moved to SystemServices. Keep only nslogutil.
69     eStatus = (eStatus != eFrameworkunifiedStatusOK) ? eStatus : FrameworkunifiedAttachCallbackToDispatcher(hApp, "nslogutil", kDebugDumpRequest,
70                                                                                   FrameworkunifiedDebugDumpRequest);
71     eStatus = (eStatus != eFrameworkunifiedStatusOK) ? eStatus : FrameworkunifiedAttachCallbacksToDispatcher(hApp,
72                                                                     "SS_LoggerService",
73                                                                     logging_callbacks,
74                                                                     static_cast<UI_32>(_countof(logging_callbacks)));
75     eStatus = FrameworkunifiedSubscribeNotificationWithCallback(hApp, NTFY_LOGGER_SETCONTROLMASK, FrameworkunifiedSetLogMask);
76
77     // This is optional only for remote control service. Therefore return value not checked
78     if (eFrameworkunifiedStatusOK != FrameworkunifiedAttachCallbacksToDispatcher(hApp, FRAMEWORKUNIFIED_NS_REMOTECONTROLSERVICE, rcs_logging_callbacks,
79                                                        static_cast<UI_32>(_countof(rcs_logging_callbacks)))) {
80       // LCOV_EXCL_BR_START 15:marco defined in "native_service/ns_logger_if.h"
81       FRAMEWORKUNIFIEDLOG0(ZONE_NS_WAR, __FUNCTION__,
82               " FrameworkunifiedAttachCallbacksToDispatcher failed for rcs_logging_callbacks with FRAMEWORKUNIFIED_NS_REMOTECONTROLSERVICE");
83       // LCOV_EXCL_BR_STOP
84     }
85   } else {
86     eStatus = eFrameworkunifiedStatusInvldParam;
87   }
88   return eStatus;
89 }
90
91 ////////////////////////////////////////////////////////////////////////////////////////////
92 /// FrameworkunifiedNPRegisterNotification
93 ////////////////////////////////////////////////////////////////////////////////////////////
94 EFrameworkunifiedStatus FrameworkunifiedSetLogMask(HANDLE hApp) {  // LCOV_EXCL_START 7:debug code
95   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
96   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
97   CHANGELOGPARAMS chngLogOpts;
98   FRAMEWORKUNIFIEDLOG0(ZONE_NS_INFO, __FUNCTION__, "+");
99
100   if (FrameworkunifiedGetMsgLength(hApp) == sizeof(CHANGELOGPARAMS)) {
101     if (eFrameworkunifiedStatusOK == FrameworkunifiedGetMsgDataOfSize(hApp, (PVOID)&chngLogOpts, sizeof(chngLogOpts))) {
102       // Set the mask to the value that was just sent.
103       NsLogSetControlMask(chngLogOpts.uiZoneMask);
104     } else {
105       FRAMEWORKUNIFIEDLOG0(ZONE_NS_ERR, __FUNCTION__, "Retervial of Data Failed");
106       eStatus = eFrameworkunifiedStatusErrOther;
107     }
108   } else {
109     FRAMEWORKUNIFIEDLOG0(ZONE_NS_ERR, __FUNCTION__, " Incorrect message sz");
110     eStatus = eFrameworkunifiedStatusInvldBuf;
111   }
112
113   FRAMEWORKUNIFIEDLOG0(ZONE_NS_INFO, __FUNCTION__, "-");
114   return eStatus;
115 }
116 // LCOV_EXCL_STOP
117
118 ////////////////////////////////////////////////////////////////////////////////////////////
119 /// FrameworkunifiedNPRegisterNotification
120 ////////////////////////////////////////////////////////////////////////////////////////////
121 EFrameworkunifiedStatus FrameworkunifiedGetLogMask(HANDLE hApp) {  // LCOV_EXCL_START 7:debug code
122   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
123   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
124   FRAMEWORKUNIFIEDLOG0(ZONE_NS_INFO, __FUNCTION__, "+");
125
126   if (frameworkunifiedCheckValidAppHandle(hApp)) {
127     PCSTR pAppName = FrameworkunifiedGetAppName(hApp);
128     PCSTR pSrcName = FrameworkunifiedGetMsgSrc(hApp);
129
130     if (NULL != pAppName && NULL != pSrcName) {
131       HANDLE echoBack = McOpenSender(pSrcName);
132       if (NULL != echoBack) {
133         CHANGELOGPARAMS chng_log_params;
134
135         NsLogGetControlMask(chng_log_params.uiZoneMask);
136         if (eFrameworkunifiedStatusOK != (eStatus = McSend(echoBack, pAppName, GET_LOG_MASK_RESPONSE, sizeof(chng_log_params),
137                                               &chng_log_params))) {
138           FRAMEWORKUNIFIEDLOG0(ZONE_NS_ERR, __FUNCTION__, "Error sending message  GET_LOG_MASK_RESPONSE");
139         }
140
141         McClose(echoBack);
142         echoBack = NULL;
143       } else {
144         eStatus = eFrameworkunifiedStatusInvldHandle;
145       }
146     } else {
147       eStatus = eFrameworkunifiedStatusNullPointer;
148     }
149   } else {
150     eStatus = eFrameworkunifiedStatusInvldParam;
151   }
152
153   FRAMEWORKUNIFIEDLOG0(ZONE_NS_INFO, __FUNCTION__, "-");
154   return eStatus;
155 }
156 // LCOV_EXCL_STOP
157
158 ////////////////////////////////////////////////////////////////////////////////////////////
159 /// FrameworkunifiedNPRegisterNotification
160 ////////////////////////////////////////////////////////////////////////////////////////////
161 EFrameworkunifiedStatus FrameworkunifiedSetOutputLogOpts(HANDLE hApp) {  // LCOV_EXCL_START 7:debug code
162   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
163   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
164   CHANGELOGPARAMS chngLogOpts;
165   FRAMEWORKUNIFIEDLOG0(ZONE_NS_INFO, __FUNCTION__, "+");
166
167   if (FrameworkunifiedGetMsgLength(hApp) == sizeof(CHANGELOGPARAMS)) {
168     if (eFrameworkunifiedStatusOK == FrameworkunifiedGetMsgDataOfSize(hApp, (PVOID)&chngLogOpts, sizeof(chngLogOpts))) {
169       // Set the logging method to the value that was just received.
170       NsLogSetLogMethod(chngLogOpts.uiLogOptions);
171     } else {
172       FRAMEWORKUNIFIEDLOG0(ZONE_NS_ERR, __FUNCTION__, "Retervial of Data Failed");
173       eStatus = eFrameworkunifiedStatusErrOther;
174     }
175   } else {
176     FRAMEWORKUNIFIEDLOG0(ZONE_NS_ERR, __FUNCTION__, " Incorrect message sz");
177     eStatus = eFrameworkunifiedStatusInvldBuf;
178   }
179
180
181   FRAMEWORKUNIFIEDLOG0(ZONE_NS_INFO, __FUNCTION__, "-");
182   return eStatus;
183 }
184 // LCOV_EXCL_STOP
185
186 ////////////////////////////////////////////////////////////////////////////////////////////
187 /// FrameworkunifiedNPRegisterNotification
188 ////////////////////////////////////////////////////////////////////////////////////////////
189 EFrameworkunifiedStatus FrameworkunifiedGetOutputLogOpts(HANDLE hApp) {  // LCOV_EXCL_START 7:debug code
190   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
191   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
192   FRAMEWORKUNIFIEDLOG0(ZONE_NS_INFO, __FUNCTION__, "+");
193
194   if (frameworkunifiedCheckValidAppHandle(hApp)) {
195     PCSTR pAppName = FrameworkunifiedGetAppName(hApp);
196     PCSTR pSrcName = FrameworkunifiedGetMsgSrc(hApp);
197
198     if (NULL != pAppName && NULL != pSrcName) {
199       HANDLE echoBack = McOpenSender(pSrcName);
200
201       if (NULL != echoBack) {
202         CHANGELOGPARAMS chng_log_params;
203
204         chng_log_params.uiLogOptions = NsLogGetLogMethod();
205         if (eFrameworkunifiedStatusOK != (eStatus = McSend(echoBack, pAppName, GET_LOG_OUT_OPT_RESPONSE, sizeof(chng_log_params),
206                                               &chng_log_params))) {
207           FRAMEWORKUNIFIEDLOG0(ZONE_NS_ERR, __FUNCTION__, "Error sending message  GET_LOG_OUT_OPT_RESPONSE");
208         }
209
210         McClose(echoBack);
211         echoBack = NULL;
212       } else {
213         eStatus = eFrameworkunifiedStatusInvldHandle;
214       }
215     } else {
216       eStatus = eFrameworkunifiedStatusNullPointer;
217     }
218   } else {
219     eStatus = eFrameworkunifiedStatusInvldParam;
220   }
221
222   FRAMEWORKUNIFIEDLOG0(ZONE_NS_INFO, __FUNCTION__, "-");
223   return eStatus;
224 }
225 // LCOV_EXCL_STOP
226
227 ////////////////////////////////////////////////////////////////////////////////////////////
228 /// FrameworkunifiedSetLogSeverity
229 ////////////////////////////////////////////////////////////////////////////////////////////
230 EFrameworkunifiedStatus FrameworkunifiedSetLogSeverity(HANDLE hApp) {  // LCOV_EXCL_START 7:debug code
231   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
232   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
233   CHANGELOGPARAMS l_tChngLogOpts = {};
234   FRAMEWORKUNIFIEDLOG(ZONE_NS_INFO, __FUNCTION__, "+");
235
236   if (FrameworkunifiedGetMsgLength(hApp) == sizeof(CHANGELOGPARAMS)) {
237     if (eFrameworkunifiedStatusOK == FrameworkunifiedGetMsgDataOfSize(hApp, (PVOID)&l_tChngLogOpts, sizeof(l_tChngLogOpts))) {
238       // Set the logging method to the value that was just received.
239       NsLogSetSeverity(l_tChngLogOpts.eSeverity);
240     } else {
241       FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Retrieval of log severity data Failed");
242       eStatus = eFrameworkunifiedStatusErrOther;
243     }
244   } else {
245     FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, " Incorrect message size CHANGELOGPARAMS");
246     eStatus = eFrameworkunifiedStatusInvldBuf;
247   }
248
249   FRAMEWORKUNIFIEDLOG(ZONE_NS_INFO, __FUNCTION__, "-");
250   return eStatus;
251 }
252 // LCOV_EXCL_STOP
253
254 ////////////////////////////////////////////////////////////////////////////////////////////
255 /// FrameworkunifiedGetLogSeverity
256 ////////////////////////////////////////////////////////////////////////////////////////////
257 EFrameworkunifiedStatus FrameworkunifiedGetLogSeverity(HANDLE hApp) {  // LCOV_EXCL_START 7:debug code
258   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
259   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
260   FRAMEWORKUNIFIEDLOG0(ZONE_NS_INFO, __FUNCTION__, "+");
261
262   if (frameworkunifiedCheckValidAppHandle(hApp)) {
263     PCSTR l_cAppName   = FrameworkunifiedGetAppName(hApp);
264     PCSTR l_cSrcName   = FrameworkunifiedGetMsgSrc(hApp);
265
266     if (NULL != l_cAppName && NULL != l_cSrcName) {
267       HANDLE l_hEchoBack = McOpenSender(l_cSrcName);
268
269       if (NULL != l_hEchoBack) {
270         CHANGELOGPARAMS l_tChngLogParams = {};
271
272         l_tChngLogParams.eSeverity = NsLogGetSeverity();
273         if (eFrameworkunifiedStatusOK != (eStatus = McSend(l_hEchoBack, l_cAppName, GET_LOG_SEVERITY_RESPONSE,
274           sizeof(l_tChngLogParams), &l_tChngLogParams))) {
275           FRAMEWORKUNIFIEDLOG0(ZONE_NS_ERR, __FUNCTION__, "Error sending message  GET_LOG_OUT_OPT_RESPONSE");
276         }
277
278         McClose(l_hEchoBack);
279         l_hEchoBack = NULL;
280       } else {
281         eStatus = eFrameworkunifiedStatusInvldHandle;
282       }
283     } else {
284       eStatus = eFrameworkunifiedStatusNullPointer;
285     }
286   } else {
287     eStatus = eFrameworkunifiedStatusInvldParam;
288   }
289
290   FRAMEWORKUNIFIEDLOG0(ZONE_NS_INFO, __FUNCTION__, "-");
291   return eStatus;
292 }
293 // LCOV_EXCL_STOP
294
295 ////////////////////////////////////////////////////////////////////////////////////////////
296 /// FrameworkunifiedDebugDumpRequest: Calls an Applications FrameworkunifiedOnDebugDump method.
297 ////////////////////////////////////////////////////////////////////////////////////////////
298 EFrameworkunifiedStatus FrameworkunifiedDebugDumpRequest(HANDLE hApp) {  // LCOV_EXCL_START 7:debug code
299   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
300   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
301   FRAMEWORKUNIFIEDLOG0(ZONE_NS_DEBUG_DUMP, __FUNCTION__, "+");
302   eStatus = FrameworkunifiedOnDebugDumpInternal(hApp);
303   FRAMEWORKUNIFIEDLOG0(ZONE_NS_DEBUG_DUMP, __FUNCTION__, "+");
304   return eStatus;
305 }
306 // LCOV_EXCL_STOP
307
308 EFrameworkunifiedStatus NSRcsSetLogSettings(HANDLE hApp) {  // LCOV_EXCL_START 7:debug code
309   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
310   FRAMEWORKUNIFIEDLOG(ZONE_NS_INFO, __FUNCTION__, "+");
311   if (frameworkunifiedCheckValidAppHandle(hApp)) {
312     if (FrameworkunifiedGetMsgLength(hApp) == sizeof(TNSRCS_SetLogSettingsReq)) {
313       TNSRCS_SetLogSettingsReq l_tSetLogSettings = {};
314
315       if (eFrameworkunifiedStatusOK == FrameworkunifiedGetMsgDataOfSize(hApp, (PVOID)&l_tSetLogSettings, sizeof(l_tSetLogSettings))) {
316         // Set the log mask
317         NsLogSetControlMask(l_tSetLogSettings.m_pui32ZoneMask);
318         // set the log output option
319         NsLogSetLogMethod(l_tSetLogSettings.m_ui8OutputLogOption);
320         // set the log severity
321         NsLogSetSeverity(l_tSetLogSettings.m_si32Severity);
322         FRAMEWORKUNIFIEDLOG(ZONE_NS_INFO, __FUNCTION__, "Log settings applied");
323
324         // send the response back with the current settings
325         TNSRCS_SetLogSettingsResp l_tSetLogSettingsResp = {};
326         PCSTR l_cAppName   = FrameworkunifiedGetAppName(hApp);
327         PCSTR l_cSrcName   = FrameworkunifiedGetMsgSrc(hApp);
328         HANDLE l_hSendTo = McOpenSender(l_cSrcName);
329
330         if (NULL != l_hSendTo) {
331           l_tSetLogSettingsResp.m_ui8ClientId = l_tSetLogSettings.m_ui8ClientId;
332           l_tSetLogSettingsResp.m_ui8SetStatus = static_cast<UI_8>(eFrameworkunifiedStatusOK);
333
334           NsLogGetControlMask(l_tSetLogSettingsResp.m_pui32ZoneMask);
335           l_tSetLogSettingsResp.m_ui8OutputLogOption = NsLogGetLogMethod();
336           l_tSetLogSettingsResp.m_si32Severity = NsLogGetSeverity();
337
338           if (eFrameworkunifiedStatusOK !=
339               McSend(l_hSendTo, l_cAppName, NSRCS_SET_LOG_SETTINGS_RESP,
340                      sizeof(TNSRCS_SetLogSettingsResp), &l_tSetLogSettingsResp)) {
341             FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Error sending message  "
342                    "NSRCS_SET_LOG_SETTINGS_RESP to %s", l_cSrcName);
343           }
344           McClose(l_hSendTo);
345           l_hSendTo = NULL;
346         } else {
347           FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Sender handle NULL when sending response to %s", l_cSrcName);
348         }
349       } else {
350         FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Retrieval of Data Failed");
351       }
352     } else {
353       FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, " Incorrect message size. Received: %d expected: %ld",
354              FrameworkunifiedGetMsgLength(hApp),
355              static_cast<long int>(sizeof(TNSRCS_SetLogSettingsReq)));  // NOLINT  (readability/nolint)
356     }
357   } else {
358     FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "hApp is NULL");
359   }
360   FRAMEWORKUNIFIEDLOG(ZONE_NS_INFO, __FUNCTION__, "-");
361   return eFrameworkunifiedStatusOK;
362 }
363 // LCOV_EXCL_STOP
364
365 EFrameworkunifiedStatus NSRcsGetLogSettings(HANDLE hApp) {  // LCOV_EXCL_START 7:debug code
366   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
367   FRAMEWORKUNIFIEDLOG(ZONE_NS_INFO, __FUNCTION__, "+");
368   if (frameworkunifiedCheckValidAppHandle(hApp)) {
369     if (FrameworkunifiedGetMsgLength(hApp) == sizeof(TNSRCS_GetLogSettingsReq)) {
370       TNSRCS_GetLogSettingsReq l_tGetLogSettings = {};
371
372       if (eFrameworkunifiedStatusOK == FrameworkunifiedGetMsgDataOfSize(hApp, (PVOID)&l_tGetLogSettings, sizeof(l_tGetLogSettings))) {
373         // send the response back with the current settings
374         TNSRCS_GetLogSettingsResp l_tGetLogSettingsResp = {};
375         PCSTR l_cAppName   = FrameworkunifiedGetAppName(hApp);
376         PCSTR l_cSrcName   = FrameworkunifiedGetMsgSrc(hApp);
377         HANDLE l_hSendTo = McOpenSender(l_cSrcName);
378
379         if (NULL != l_hSendTo) {
380           l_tGetLogSettingsResp.m_ui8ClientId = l_tGetLogSettings.m_ui8ClientId;
381           NsLogGetZoneTextList(l_tGetLogSettingsResp.m_cZoneList);
382           NsLogGetControlMask(l_tGetLogSettingsResp.m_pui32ZoneMask);
383           l_tGetLogSettingsResp.m_ui8OutputLogOption = NsLogGetLogMethod();
384           l_tGetLogSettingsResp.m_si32Severity = NsLogGetSeverity();
385
386           if (eFrameworkunifiedStatusOK !=
387               McSend(l_hSendTo, l_cAppName, NSRCS_GET_LOG_SETTINGS_RESP,
388                      sizeof(TNSRCS_GetLogSettingsResp), &l_tGetLogSettingsResp)) {
389             FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Error sending message  "
390                    "NSRCS_GET_LOG_SETTINGS_RESP to %s", l_cSrcName);
391           }
392           McClose(l_hSendTo);
393           l_hSendTo = NULL;
394         } else {
395           FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Sender handle NULL when sending response to %s", l_cSrcName);
396         }
397       } else {
398         FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Retrieval of Data Failed");
399       }
400     } else {
401       FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, " Incorrect message size. Received: %d expected: %ld",
402              FrameworkunifiedGetMsgLength(hApp),
403              static_cast<long int>(sizeof(TNSRCS_GetLogSettingsReq)));  // NOLINT  (readability/nolint)
404     }
405   } else {
406     FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "hApp is NULL");
407   }
408   FRAMEWORKUNIFIEDLOG(ZONE_NS_INFO, __FUNCTION__, "-");
409   return eFrameworkunifiedStatusOK;
410 }
411 // LCOV_EXCL_STOP
412
413 EFrameworkunifiedStatus NSRcsSetLogMask(HANDLE hApp) {  // LCOV_EXCL_START 7:debug code
414   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
415   FRAMEWORKUNIFIEDLOG(ZONE_NS_INFO, __FUNCTION__, "+");
416   if (frameworkunifiedCheckValidAppHandle(hApp)) {
417     if (FrameworkunifiedGetMsgLength(hApp) == sizeof(TNSRCS_SetLogSettingsReq)) {
418       TNSRCS_SetLogSettingsReq l_tSetLogSettings = {};
419
420       if (eFrameworkunifiedStatusOK == FrameworkunifiedGetMsgDataOfSize(hApp, (PVOID)&l_tSetLogSettings, sizeof(l_tSetLogSettings))) {
421         // Set the log mask
422         NsLogSetControlMask(l_tSetLogSettings.m_pui32ZoneMask);
423
424         // 11 = number of chars in UI_32, 1 - nul char at the end
425         CHAR l_cOutMask[(ZONE_MASK_ARRAY_ELTS * 11) + 1] = {};
426         CHAR l_cMask[12] = {};  // 12 = 11+1: 11 = number of chars in UI_32, 1 - nul char at the end
427         for (UI_32 zoneIndex = 0; zoneIndex < ZONE_MASK_ARRAY_ELTS; zoneIndex++) {
428           std::strncpy(l_cMask, "", 11);
429           snprintf(l_cMask, sizeof(l_cMask), "0x%X,", l_tSetLogSettings.m_pui32ZoneMask[zoneIndex]);
430           std::strncat(l_cOutMask, l_cMask, (sizeof(l_cOutMask) - std::strlen(l_cMask) - 1));
431         }
432         FRAMEWORKUNIFIEDLOG(ZONE_NS_INFO, __FUNCTION__, "Log settings (zone mask) applied: %s", l_cOutMask);
433
434         // send the response back with the current settings
435         TNSRCS_SetLogMaskResp l_tSetLogMaskResp = {};
436         PCSTR l_cAppName   = FrameworkunifiedGetAppName(hApp);
437         PCSTR l_cSrcName   = FrameworkunifiedGetMsgSrc(hApp);
438         HANDLE l_hSendTo = McOpenSender(l_cSrcName);
439
440         if (NULL != l_hSendTo) {
441           l_tSetLogMaskResp.m_ui8ClientId = l_tSetLogSettings.m_ui8ClientId;
442           l_tSetLogMaskResp.m_ui8SetStatus = static_cast<UI_8>(eFrameworkunifiedStatusOK);
443
444           NsLogGetControlMask(l_tSetLogMaskResp.m_pui32ZoneMask);
445
446           if (eFrameworkunifiedStatusOK !=
447               McSend(l_hSendTo, l_cAppName, NSRCS_SET_LOG_MASK_RESP,
448                      sizeof(TNSRCS_SetLogMaskResp), &l_tSetLogMaskResp)) {
449             FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Error sending message  "
450                    "NSRCS_SET_LOG_MASK_RESP to %s", l_cSrcName);
451           }
452           McClose(l_hSendTo);
453           l_hSendTo = NULL;
454         } else {
455           FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Sender handle NULL when sending response to %s", l_cSrcName);
456         }
457       } else {
458         FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Retrieval of Data Failed");
459       }
460     } else {
461       FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, " Incorrect message size. Received: %d expected: %ld",
462              FrameworkunifiedGetMsgLength(hApp),
463              static_cast<long int>(sizeof(TNSRCS_SetLogSettingsReq)));  // NOLINT  (readability/nolint)
464     }
465   } else {
466     FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "hApp is NULL");
467   }
468   FRAMEWORKUNIFIEDLOG(ZONE_NS_INFO, __FUNCTION__, "-");
469   return eFrameworkunifiedStatusOK;
470 }
471 // LCOV_EXCL_STOP
472
473 EFrameworkunifiedStatus NSRcsSetOutputLogOpts(HANDLE hApp) {  // LCOV_EXCL_START 7:debug code
474   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
475   FRAMEWORKUNIFIEDLOG(ZONE_NS_INFO, __FUNCTION__, "+");
476   if (frameworkunifiedCheckValidAppHandle(hApp)) {
477     if (FrameworkunifiedGetMsgLength(hApp) == sizeof(TNSRCS_SetLogSettingsReq)) {
478       TNSRCS_SetLogSettingsReq l_tSetLogSettings = {};
479
480       if (eFrameworkunifiedStatusOK == FrameworkunifiedGetMsgDataOfSize(hApp, (PVOID)&l_tSetLogSettings, sizeof(l_tSetLogSettings))) {
481         // set the log output option
482         NsLogSetLogMethod(l_tSetLogSettings.m_ui8OutputLogOption);
483         FRAMEWORKUNIFIEDLOG(ZONE_NS_INFO, __FUNCTION__, "Log settings(log output option) applied: %d.",
484                l_tSetLogSettings.m_ui8OutputLogOption);
485
486         // send the response back with the current settings
487         TNSRCS_SetLogOutOptResp l_tSetLogOutputOptResp = {};
488         PCSTR l_cAppName   = FrameworkunifiedGetAppName(hApp);
489         PCSTR l_cSrcName   = FrameworkunifiedGetMsgSrc(hApp);
490         HANDLE l_hSendTo = McOpenSender(l_cSrcName);
491
492         if (NULL != l_hSendTo) {
493           l_tSetLogOutputOptResp.m_ui8ClientId = l_tSetLogSettings.m_ui8ClientId;
494           l_tSetLogOutputOptResp.m_ui8SetStatus = static_cast<UI_8>(eFrameworkunifiedStatusOK);
495
496           l_tSetLogOutputOptResp.m_ui8OutputLogOption = NsLogGetLogMethod();
497
498           if (eFrameworkunifiedStatusOK !=
499               McSend(l_hSendTo, l_cAppName, NSRCS_SET_LOG_OUT_OPT_RESP,
500                      sizeof(TNSRCS_SetLogOutOptResp), &l_tSetLogOutputOptResp)) {
501             FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Error sending message  "
502                    "NSRCS_SET_LOG_OUT_OPT_RESP to %s", l_cSrcName);
503           }
504           McClose(l_hSendTo);
505           l_hSendTo = NULL;
506         } else {
507           FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Sender handle NULL when sending response to %s", l_cSrcName);
508         }
509       } else {
510         FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Retrieval of Data Failed");
511       }
512     } else {
513       FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, " Incorrect message size. Received: %d expected: %ld",
514              FrameworkunifiedGetMsgLength(hApp),
515              static_cast<long int>(sizeof(TNSRCS_SetLogSettingsReq)));  // NOLINT  (readability/nolint)
516     }
517   } else {
518     FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "hApp is NULL");
519   }
520   FRAMEWORKUNIFIEDLOG(ZONE_NS_INFO, __FUNCTION__, "-");
521   return eFrameworkunifiedStatusOK;
522 }
523 // LCOV_EXCL_STOP
524
525 EFrameworkunifiedStatus NSRcsSetLogSeverity(HANDLE hApp) {  // LCOV_EXCL_START 7:debug code
526   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
527   FRAMEWORKUNIFIEDLOG(ZONE_NS_INFO, __FUNCTION__, "+");
528   if (frameworkunifiedCheckValidAppHandle(hApp)) {
529     if (FrameworkunifiedGetMsgLength(hApp) == sizeof(TNSRCS_SetLogSettingsReq)) {
530       TNSRCS_SetLogSettingsReq l_tSetLogSettings = {};
531
532       if (eFrameworkunifiedStatusOK == FrameworkunifiedGetMsgDataOfSize(hApp, (PVOID)&l_tSetLogSettings, sizeof(l_tSetLogSettings))) {
533         // set the log severity
534         NsLogSetSeverity(l_tSetLogSettings.m_si32Severity);
535         FRAMEWORKUNIFIEDLOG(ZONE_NS_INFO, __FUNCTION__, "Log settings(log severity) applied: %d.",
536           l_tSetLogSettings.m_si32Severity);
537
538         // send the response back with the current settings
539         TNSRCS_SetLogSeverityResp l_tSetLogSeverityResp = {};
540         PCSTR l_cAppName   = FrameworkunifiedGetAppName(hApp);
541         PCSTR l_cSrcName   = FrameworkunifiedGetMsgSrc(hApp);
542         HANDLE l_hSendTo = McOpenSender(l_cSrcName);
543
544         if (NULL != l_hSendTo) {
545           l_tSetLogSeverityResp.m_ui8ClientId = l_tSetLogSettings.m_ui8ClientId;
546           l_tSetLogSeverityResp.m_ui8SetStatus = static_cast<UI_8>(eFrameworkunifiedStatusOK);
547
548           l_tSetLogSeverityResp.m_si32Severity = NsLogGetSeverity();
549
550           if (eFrameworkunifiedStatusOK !=
551               McSend(l_hSendTo, l_cAppName, NSRCS_SET_LOG_SEVERITY_RESP,
552                      sizeof(TNSRCS_SetLogSeverityResp), &l_tSetLogSeverityResp)) {
553             FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Error sending message  "
554                    "NSRCS_SET_LOG_SEVERITY_RESP to %s", l_cSrcName);
555           }
556           McClose(l_hSendTo);
557           l_hSendTo = NULL;
558         } else {
559           FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Sender handle NULL when sending response to %s", l_cSrcName);
560         }
561       } else {
562         FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Retrieval of Data Failed");
563       }
564     } else {
565       FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, " Incorrect message size. Received: %d expected: %ld",
566       FrameworkunifiedGetMsgLength(hApp),
567       static_cast<long int>(sizeof(TNSRCS_SetLogSettingsReq)));  // NOLINT  (readability/nolint)
568     }
569   } else {
570     FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "hApp is NULL");
571   }
572   FRAMEWORKUNIFIEDLOG(ZONE_NS_INFO, __FUNCTION__, "-");
573   return eFrameworkunifiedStatusOK;
574 }
575 // LCOV_EXCL_STOP