Init basesystem source codes.
[staging/basesystem.git] / video_in_hal / vehicleservice / positioning / server / src / ServiceInterface / CommUsbIf.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  *    CommUsbIf.cpp
20  * @brief
21  *    CommUSB service-to-service interface
22  */
23
24 /*---------------------------------------------------------------------------------*
25  * Include Files                                                                   *
26  *---------------------------------------------------------------------------------*/
27 #include <vehicle_service/positioning_base_library.h>
28 #include "CommUsbIf.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 static BOOL g_comm_usb_availability = FALSE;
46
47 /*---------------------------------------------------------------------------------*
48  * Function                                                                        *
49  *---------------------------------------------------------------------------------*/
50 /**
51  * @brief
52  *    Registering CommUSB Services IF Callback Functions
53  *
54  * @param[in]  *p_msg_handler    Callback function table
55  * @param[in]  Ui_handler_count Number of callback functions
56  * @return     eFrameworkunifiedStatusOK
57  * @return     eFrameworkunifiedStatusFail
58  */
59 EFrameworkunifiedStatus CommUsbIfAttachCallbacksToDispatcher(    // NOLINT(readability/nolint)
60                                                 _FrameworkunifiedProtocolCallbackHandler const* p_msg_handler,
61                                                 unsigned int ui_handler_count) {
62     EFrameworkunifiedStatus estatus = eFrameworkunifiedStatusFail;
63     HANDLE happ;
64
65     happ = _pb_GetAppHandle();
66     if (happ != NULL) {
67         estatus = FrameworkunifiedAttachCallbacksToDispatcher(happ, "NS_ANY_SRC", p_msg_handler, ui_handler_count);
68         if (eFrameworkunifiedStatusOK != estatus) {  // LCOV_EXCL_BR_LINE 4: nsfw error
69             FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, 
70                           "FrameworkunifiedAttachCallbacksToDispatcher ERROR!! [estatus=%d]", estatus);
71         }
72     } else {
73         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "_pb_GetAppHandle ERROR!! [happ=%p]", happ);
74     }
75
76     return estatus;
77 }
78
79 /**
80  * @brief
81  *    Remove CommUSB Services IF Callback Functions
82  *
83  * @param[in]  *p_msg_handler    CID table
84  * @param[in]  ui_handler_count  Number of CIDs
85  * @return     eFrameworkunifiedStatusOK
86  * @return     eFrameworkunifiedStatusFail
87  */
88 EFrameworkunifiedStatus CommUsbIfDetachCallbacksFromDispatcher(const PUI_32 pui_cmd_array, UI_32 ui_command_count) {
89     EFrameworkunifiedStatus estatus = eFrameworkunifiedStatusFail;
90     HANDLE happ;
91
92     happ = _pb_GetAppHandle();
93     if (happ != NULL) {
94         estatus = FrameworkunifiedDetachCallbacksFromDispatcher(happ, "NS_ANY_SRC", pui_cmd_array, ui_command_count, NULL);
95         /* In the event of failure */
96         if (estatus != eFrameworkunifiedStatusOK) {
97             FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, \
98                           "PositioningDetachCallbacksToDispatcher Failed in FrameworkunifiedOnStop [estatus=%d]", estatus);
99         }
100     } else {
101         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "_pb_GetAppHandle ERROR!! [happ=%p]", happ);
102     }
103
104     return estatus;
105 }
106
107 /**
108  * @brief
109  *    CommUSB Services IF Availability Change Notification Registration
110  *
111  * @param[in]  fp_on_cmd    Callback function
112  * @return     eFrameworkunifiedStatusOK
113  * @return     eFrameworkunifiedStatusFail
114  */
115 EFrameworkunifiedStatus CommUsbIfNotifyOnCommUSBAvailability(CbFuncPtr fp_on_cmd) {
116     EFrameworkunifiedStatus estatus = eFrameworkunifiedStatusFail;
117     HANDLE happ;
118
119     happ = _pb_GetAppHandle();
120     if (happ != NULL) {  // LCOV_EXCL_BR_LINE 4: nsfw error
121         /* PS_CommUSB/Availability Changing notification registration */
122         estatus = FrameworkunifiedSubscribeNotificationWithCallback(happ, NTFY_CommUSB_Availability, fp_on_cmd);  // LCOV_EXCL_BR_LINE 6:unexpected branch  //NOLINT (whitespace/line_length)
123         if (eFrameworkunifiedStatusOK != estatus) {  // LCOV_EXCL_BR_LINE 4: nsfw error
124             FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, 
125                           "PositioningSubscriveNotificationswithCallback ERROR!! [estatus=%d]", estatus);
126         }
127     } else {
128         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "_pb_GetAppHandle ERROR!! [happ=%p]", happ);
129     }
130
131     return estatus;
132 }
133
134 /**
135  * @brief
136  *    CommUSB Services IF-Availability Settings
137  *
138  * @param[in]  pb_is_available
139  * @return     none
140  */
141 void CommUsbIfSetAvailability(BOOL b_is_available) {
142     g_comm_usb_availability = b_is_available;
143
144     FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "g_comm_usb_availability=%d", g_comm_usb_availability);
145
146     return;
147 }