Init basesystem source codes.
[staging/basesystem.git] / vehicleservice / positioning / server / src / ServiceInterface / BackupMgrIf.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  *    BackupMgrIf.cpp
20  * @brief
21  *    BackupMgr service-to-service interface
22  */
23
24 /*---------------------------------------------------------------------------------*
25  * Include Files                                                                   *
26  *---------------------------------------------------------------------------------*/
27 #include <vehicle_service/positioning_base_library.h>
28 #include "BackupMgrIf.h"
29
30 /*---------------------------------------------------------------------------------*
31  * Definition                                                                      *
32  *---------------------------------------------------------------------------------*/
33
34 /*---------------------------------------------------------------------------------*
35  * Structre                                                                        *
36  *---------------------------------------------------------------------------------*/
37
38 /*---------------------------------------------------------------------------------*
39  * Local Function Prototype                                                        *
40  *---------------------------------------------------------------------------------*/
41
42 /*---------------------------------------------------------------------------------*
43  * Grobal Value                                                                    *
44  *---------------------------------------------------------------------------------*/
45
46 // static BOOL g_backup_mgr_availability = FALSE;
47 BOOL g_backup_mgr_availability = FALSE;
48
49 /*---------------------------------------------------------------------------------*
50  * Function                                                                        *
51  *---------------------------------------------------------------------------------*/
52
53 /**
54  * @brief
55  *    BackupMgr Services IF Availability Change Notification Registration
56  *
57  * @param[in]  fp_on_cmd    Callback function
58  * @return     eFrameworkunifiedStatusOK
59  * @return     eFrameworkunifiedStatusFail
60  */
61 EFrameworkunifiedStatus BackupMgrIfNotifyOnBackupMgrAvailability(CbFuncPtr fp_on_cmd) {
62     EFrameworkunifiedStatus estatus = eFrameworkunifiedStatusFail;
63     HANDLE happ;
64
65     happ = _pb_GetAppHandle();
66     if (happ != NULL) {
67         /* NS_BackupMgr/Availability Changing notification registration */
68         estatus = FrameworkunifiedSubscribeNotificationWithCallback(happ, NTFY_BackupMgr_Availability, (CbFuncPtr)fp_on_cmd);  // LCOV_EXCL_BR_LINE 6:unexpected branch  //NOLINT (whitespace/line_length)
69         if (eFrameworkunifiedStatusOK != estatus) {
70             FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, \
71                           "PositioningSubscriveNotificationswithCallback ERROR!! [estatus=%d]", estatus);
72         }
73     } else {
74         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "_pb_GetAppHandle ERROR!! [happ=%p]", happ);
75     }
76
77     return estatus;
78 }
79
80 /**
81  * @brief
82  *    BackupMgr Services IF-Availability Settings
83  *
84  * @param[in]  b_is_available    Available state
85  * @return     none
86  */
87 void BackupMgrIfSetAvailability(BOOL b_is_available) {
88     g_backup_mgr_availability = b_is_available;
89
90     FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, \
91         "g_backup_mgr_availability=%d", g_backup_mgr_availability);
92
93     return;
94 }
95
96 #ifdef __cplusplus
97 extern "C" {
98 #endif
99 /**
100  * @brief
101  *    BackupMgr Services IF-Availability Acquisition
102  *
103  * @param[in]  none
104  * @return     gb_BackupMgrAvailability
105  */
106
107 BOOL BackupMgrIf_GetAvailability(void)
108 {
109     return g_backup_mgr_availability;
110 }
111 #ifdef __cplusplus
112 }
113 #endif
114
115 /**
116  * @brief
117  *    Import BackupMgr Services IFs
118  *
119  * @param[in]  tag_id
120  * @param[in]  ui_offset
121  * @param[in]  *pv_buf
122  * @param[in]  ui_size
123  * @param[out] pb_is_available    Available state
124  * @return     eFrameworkunifiedStatusOK
125  * @return     eFrameworkunifiedStatusFail
126  */
127 EFrameworkunifiedStatus BackupMgrIfBackupDataRd(PCSTR tag_id, uint32_t ui_offset, void *pv_buf, \
128         uint32_t ui_size, BOOL* pb_is_available) {
129     EFrameworkunifiedStatus estatus = eFrameworkunifiedStatusFail;
130     int32_t lret;
131
132     if (BackupMgrIf_GetAvailability() == TRUE) {
133         lret = Backup_DataRd(tag_id, ui_offset, pv_buf, ui_size);
134         if (lret == BKUP_RET_NORMAL) {
135             /* 8Byte fixed outputs */
136             FRAMEWORKUNIFIEDLOG(ZONE_28, __FUNCTION__,  \
137              "Backup_DataRd Done [tag_id=%s, pv_buf(Hex):%02x %02x %02x %02x %02x %02x %02x %02x, offset=%d, size=%d]",
138              tag_id,
139              *(reinterpret_cast<int8_t*>(pv_buf)),
140              *((reinterpret_cast<int8_t*>(pv_buf))+1),
141              *((reinterpret_cast<int8_t*>(pv_buf))+2),
142              *((reinterpret_cast<int8_t*>(pv_buf))+3),
143              *((reinterpret_cast<int8_t*>(pv_buf))+4),
144              *((reinterpret_cast<int8_t*>(pv_buf))+5),
145              *((reinterpret_cast<int8_t*>(pv_buf))+6),
146              *((reinterpret_cast<int8_t*>(pv_buf))+7),
147              ui_offset, ui_size);
148
149             estatus = eFrameworkunifiedStatusOK;
150         } else {
151             FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, \
152                 "Backup_DataRd ERROR!! [lret=%d, tag_id=%s, ui_offset=%d, pv_buf=%p, ui_size=%d]", \
153                 lret, tag_id, ui_offset, pv_buf, ui_size);
154         }
155     } else {
156         /* nop */
157     }
158
159     *pb_is_available = BackupMgrIf_GetAvailability();
160
161     return estatus;
162 }
163
164 /**
165  * @brief
166  *    BackupMgr Services IF Write
167  *
168  * @param[in]  tag_id
169  * @param[in]  *pv_buf
170  * @param[in]  ui_offset
171  * @param[in]  ui_size
172  * @param[out] pb_is_available    Available state
173  * @return     eFrameworkunifiedStatusOK
174  * @return     eFrameworkunifiedStatusFail
175  */
176 EFrameworkunifiedStatus BackupMgrIfBackupDataWt(PCSTR tag_id, void *pv_buf, uint32_t ui_offset, \
177         uint32_t ui_size, BOOL* pb_is_available) {
178     EFrameworkunifiedStatus estatus = eFrameworkunifiedStatusFail;
179     int32_t lret;
180
181     if (BackupMgrIf_GetAvailability() == TRUE) {
182         lret = Backup_DataWt(tag_id, pv_buf, ui_offset, ui_size);
183         if (lret == BKUP_RET_NORMAL) {
184             /* 8Byte fixed outputs */
185             FRAMEWORKUNIFIEDLOG(ZONE_28, __FUNCTION__, 
186              "Backup_DataWt Done [tag_id=%s, pv_buf(Hex):%02x %02x %02x %02x %02x %02x %02x %02x, offset=%d, size=%d]",
187              tag_id,
188              *(reinterpret_cast<int8_t*>(pv_buf)),
189              *((reinterpret_cast<int8_t*>(pv_buf))+1),
190              *((reinterpret_cast<int8_t*>(pv_buf))+2),
191              *((reinterpret_cast<int8_t*>(pv_buf))+3),
192              *((reinterpret_cast<int8_t*>(pv_buf))+4),
193              *((reinterpret_cast<int8_t*>(pv_buf))+5),
194              *((reinterpret_cast<int8_t*>(pv_buf))+6),
195              *((reinterpret_cast<int8_t*>(pv_buf))+7),
196              ui_offset, ui_size);
197
198             estatus = eFrameworkunifiedStatusOK;
199         } else {
200             FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, \
201                 "Backup_DataWt ERROR!! [lret=%d, tag_id=%s, pv_buf=%p, ui_offset=%d, ui_size=%d]", \
202                 lret, tag_id, pv_buf, ui_offset, ui_size);
203         }
204     } else {
205         /* nop */
206     }
207
208     *pb_is_available = BackupMgrIf_GetAvailability();
209
210     return estatus;
211 }