Init basesystem source codes.
[staging/basesystem.git] / vehicleservice / positioning / server / src / ServiceInterface / ClockIf.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  *    ClockIf.cpp
20  * @brief
21  *    Clock service-to-service interface
22  */
23
24 /*---------------------------------------------------------------------------------*
25  * Include Files                                                                   *
26  *---------------------------------------------------------------------------------*/
27 #include <vehicle_service/positioning_base_library.h>
28 #include "ClockIf.h"
29 #include <stub/clock_notifications.h>
30
31 /*---------------------------------------------------------------------------------*
32  * Definition                                                                      *
33  *---------------------------------------------------------------------------------*/
34
35 /*---------------------------------------------------------------------------------*
36  * Structre                                                                        *
37  *---------------------------------------------------------------------------------*/
38
39 /*---------------------------------------------------------------------------------*
40  * Local Function Prototype                                                        *
41  *---------------------------------------------------------------------------------*/
42
43 /*---------------------------------------------------------------------------------*
44  * Grobal Value                                                                    *
45  *---------------------------------------------------------------------------------*/
46 static BOOL g_clock_availability = FALSE;
47
48 /*---------------------------------------------------------------------------------*
49  * Function                                                                        *
50  *---------------------------------------------------------------------------------*/
51 /**
52  * @brief
53  *    Clock Services IF Availability Change Notification Registration
54  *
55  * @param[in]  fp_on_cmd    Callback function
56  * @return     eFrameworkunifiedStatusOK
57  * @return     eFrameworkunifiedStatusFail
58  */
59 EFrameworkunifiedStatus ClockIfNotifyOnClockAvailability(CbFuncPtr fp_on_cmd) {
60     EFrameworkunifiedStatus estatus = eFrameworkunifiedStatusFail;
61     HANDLE happ;
62
63     happ = _pb_GetAppHandle();
64     if (happ != NULL) {
65         /* Clock/Availability Changing notification registration */
66         estatus = FrameworkunifiedSubscribeNotificationWithCallback(happ, NTFY_Clock_Availability, fp_on_cmd);  // LCOV_EXCL_BR_LINE 6:unexpected branch  //NOLINT (whitespace/line_length)
67         if (eFrameworkunifiedStatusOK != estatus) {  // LCOV_EXCL_BR_LINE 4: nsfw error
68             FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, 
69                           "PositioningSubscriveNotificationswithCallback ERROR!! [estatus=%d]", estatus);
70         }
71     } else {
72         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "_pb_GetAppHandle ERROR!! [happ=%p]", happ);
73     }
74
75     return estatus;
76 }
77
78 /**
79  * @brief
80  *    Clock Services IF-Availability Settings
81  *
82  * @param[in]  b_is_available    Available state
83  * @return     none
84  */
85 void ClockIfSetAvailability(BOOL b_is_available) {
86     g_clock_availability = b_is_available;
87
88     FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "g_clock_availability=%d", g_clock_availability);
89
90     return;
91 }
92
93 /**
94  * @brief
95  *    Clock Services IF GPS Time
96  *
97  * @param[in]  *gps_time        GPS time
98  * @param[out] *b_is_available    Available state
99  * @return     eFrameworkunifiedStatusOK
100  * @return     eFrameworkunifiedStatusFail
101  */
102 EFrameworkunifiedStatus ClockIfDtimeSetGpsTime(const SENSOR_MSG_GPSTIME *pst_gps_time, BOOL* pb_is_available) {
103     EFrameworkunifiedStatus estatus = eFrameworkunifiedStatusFail;
104     HANDLE happ;
105     T_DTIME_MSG_GPSTIME st_dtime_gpstime;
106
107     if (g_clock_availability == TRUE) {
108         happ = _pb_GetAppHandle();
109         if (happ != NULL) {  // LCOV_EXCL_BR_LINE 4: nsfw error
110             st_dtime_gpstime.utc.year   = pst_gps_time->utc.year;
111             st_dtime_gpstime.utc.month  = pst_gps_time->utc.month;
112             st_dtime_gpstime.utc.date   = pst_gps_time->utc.date;
113             st_dtime_gpstime.utc.hour   = pst_gps_time->utc.hour;
114             st_dtime_gpstime.utc.minute = pst_gps_time->utc.minute;
115             st_dtime_gpstime.utc.second = pst_gps_time->utc.second;
116             st_dtime_gpstime.tdsts      = pst_gps_time->tdsts;
117
118             /* Set GPS time for Clock services */
119             estatus = DTime_setGpsTime(happ, &st_dtime_gpstime);
120             if (estatus != eFrameworkunifiedStatusOK) {
121                 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, \
122                     "DTime_setGpsTime ERROR!! [ret=%d, y=%d, m=%d, d=%d, h=%d, n=%d, s=%d, sts=%d]", \
123                     estatus, st_dtime_gpstime.utc.year, st_dtime_gpstime.utc.month, st_dtime_gpstime.utc.date, \
124                     st_dtime_gpstime.utc.hour, st_dtime_gpstime.utc.minute, st_dtime_gpstime.utc.second, \
125                     st_dtime_gpstime.tdsts);
126             }
127         } else {
128             FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "_pb_GetAppHandle ERROR!! [happ=%p]", happ);
129         }
130     } else {
131         /* nop */
132     }
133
134     *pb_is_available = g_clock_availability;
135
136     return estatus;
137 }
138