Remove unused directories and files in video_in_hal
[staging/basesystem.git] / systemservice / logger_service / server / src / ss_logger_error_event_can_evt_reply.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_SS_LoggerService
19 /// \brief    This file supports notifying CAN abou HK and CAN error events
20 ///
21 ///////////////////////////////////////////////////////////////////////////////
22 #include <stdio.h>
23 #include <time.h>
24 #include <stub/Clock_API.h>
25 #include "ss_logger_error_event_can_evt_reply.h"
26 CLoggerErrorEventCANEvtReply::CLoggerErrorEventCANEvtReply() {
27 }
28
29 CLoggerErrorEventCANEvtReply::~CLoggerErrorEventCANEvtReply() {  // LCOV_EXCL_START 14:globle instance
30   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
31 }
32 // LCOV_EXCL_STOP
33
34 EFrameworkunifiedStatus CLoggerErrorEventCANEvtReply::Initialize(CLoggerCfg* f_pLoggerCfg) {
35   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
36   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
37   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
38   return (l_eStatus);
39 }
40
41 BOOL CLoggerErrorEventCANEvtReply::IsEventNeeded(TLoggerErrorEvent f_event) {
42   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
43   BOOL l_ret =
44       ((f_event.EventBitMask & EVENT_BIT_CAN_NOTIFICATION) != 0) ? TRUE : FALSE;
45   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
46   return (l_ret);
47 }
48
49 EFrameworkunifiedStatus CLoggerErrorEventCANEvtReply::PublishStartEvent(
50     HANDLE f_hApp, TLoggerErrorEvent f_event) {
51   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
52   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
53   if (TRUE == IsEventNeeded(f_event)) {
54     l_eStatus = FrameworkunifiedPublishPublicEvent(f_hApp, eSSLoggerCANEventStart, NULL, 0);
55     LOG_STATUS_IF_ERRORED(
56         l_eStatus,
57         "FrameworkunifiedPublishPublicEvent(f_hApp,eSSLoggerCANEventStart,NULL,0)");
58   }
59   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
60   return (l_eStatus);
61 }
62
63 EFrameworkunifiedStatus CLoggerErrorEventCANEvtReply::PublishEndEvent(
64     HANDLE f_hApp, TLoggerErrorEvent f_event, UI_32 f_triggerNumber,
65     uint32_t f_time) {
66   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
67   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
68   if (TRUE == IsEventNeeded(f_event)) {
69     STEventCANLoggerEventInfo l_info;
70     struct tm l_tm;
71     CLOCK_RETURN clock_ret = Clock_getLocalTimeY2K38(&f_time, &l_tm);
72     if (CLOCK_OK == clock_ret) {
73       l_info.valid = TRUE;
74       l_info.success = TRUE;
75       l_info.triggerNumber = f_triggerNumber;
76       l_info.dateAndTime.DateTime_Stat = 0;
77       l_info.dateAndTime.DateTimeDay = static_cast<UI_8>(l_tm.tm_mday);
78       l_info.dateAndTime.DateTimeHour = static_cast<UI_8>(l_tm.tm_hour);
79       l_info.dateAndTime.DateTimeMinute = static_cast<UI_8>(l_tm.tm_min);
80       l_info.dateAndTime.DateTimeMonth = static_cast<UI_8>(l_tm.tm_mon + 1);
81       l_info.dateAndTime.DateTimeSecond = static_cast<UI_8>(l_tm.tm_sec);
82       l_info.dateAndTime.DateTimeYear = static_cast<UI_8>(l_tm.tm_year % 100);
83       l_info.dateAndTime.TimeFormat = 0;
84       FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
85              " Info. Time sent to CAN is: 20%2d/%2d/%2d %2d:%2d:%2d",
86              l_info.dateAndTime.DateTimeYear, l_info.dateAndTime.DateTimeMonth,
87              l_info.dateAndTime.DateTimeDay, l_info.dateAndTime.DateTimeHour,
88              l_info.dateAndTime.DateTimeMinute,
89              l_info.dateAndTime.DateTimeSecond);
90
91     } else {
92       l_info.success = TRUE;
93       l_info.valid = FALSE;
94       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error. Passed time is invalid.");
95     }
96     l_eStatus = FrameworkunifiedPublishPublicEvent(f_hApp, eSSLoggerCANEventFinished,
97                                       &l_info, sizeof(l_info));
98
99     LOG_STATUS_IF_ERRORED(
100         l_eStatus,
101         "FrameworkunifiedPublishPublicEvent(f_hApp,eSSLoggerCANEventFinished,NULL,0)");
102   }
103   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
104   return (l_eStatus);
105 }
106
107 EFrameworkunifiedStatus CLoggerErrorEventCANEvtReply::PublishErrorEvent(
108     HANDLE f_hApp, TLoggerErrorEvent f_event, BOOL f_isValid,
109     UI_32 f_triggerNumber, uint32_t f_time) {
110   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
111   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
112   if (TRUE == IsEventNeeded(f_event)) {
113     STEventCANLoggerEventInfo l_info;
114     struct tm l_tm;
115     CLOCK_RETURN clock_ret = Clock_getLocalTimeY2K38(&f_time, &l_tm);
116     l_info.valid = f_isValid;
117     l_info.success = FALSE;
118     if (CLOCK_OK == clock_ret) {
119       l_info.triggerNumber = f_triggerNumber;
120       l_info.dateAndTime.DateTime_Stat = 0;
121       l_info.dateAndTime.DateTimeDay = static_cast<UI_8>(l_tm.tm_mday);
122       l_info.dateAndTime.DateTimeHour = static_cast<UI_8>(l_tm.tm_hour);
123       l_info.dateAndTime.DateTimeMinute = static_cast<UI_8>(l_tm.tm_min);
124       l_info.dateAndTime.DateTimeMonth = static_cast<UI_8>(l_tm.tm_mon + 1);
125       l_info.dateAndTime.DateTimeSecond = static_cast<UI_8>(l_tm.tm_sec);
126       l_info.dateAndTime.DateTimeYear = static_cast<UI_8>(l_tm.tm_year % 100);
127       l_info.dateAndTime.TimeFormat = 0;
128       FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
129              " Info. Time sent to CAN is: 20%2d/%2d/%2d %2d:%2d:%2d",
130              l_info.dateAndTime.DateTimeYear, l_info.dateAndTime.DateTimeMonth,
131              l_info.dateAndTime.DateTimeDay, l_info.dateAndTime.DateTimeHour,
132              l_info.dateAndTime.DateTimeMinute,
133              l_info.dateAndTime.DateTimeSecond);
134
135     } else {
136       l_info.valid = FALSE;
137       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error. Passed time is invalid.");
138     }
139     l_eStatus = FrameworkunifiedPublishPublicEvent(f_hApp, eSSLoggerCANEventFinished,
140                                       &l_info, sizeof(l_info));
141     LOG_STATUS_IF_ERRORED(  // LCOV_EXCL_BR_LINE 15: macro
142         l_eStatus,
143         "FrameworkunifiedPublishPublicEvent(f_hApp,eSSLoggerCANEventFinished,NULL,0)");
144   }
145   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
146   return (l_eStatus);
147 }