2 * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 * CommUSB service-to-service interface
24 /*---------------------------------------------------------------------------------*
26 *---------------------------------------------------------------------------------*/
27 #include <vehicle_service/positioning_base_library.h>
28 #include "CommUsbIf.h"
30 /*---------------------------------------------------------------------------------*
32 *---------------------------------------------------------------------------------*/
34 /*---------------------------------------------------------------------------------*
36 *---------------------------------------------------------------------------------*/
38 /*---------------------------------------------------------------------------------*
39 * Local Function Prototype *
40 *---------------------------------------------------------------------------------*/
42 /*---------------------------------------------------------------------------------*
44 *---------------------------------------------------------------------------------*/
45 static BOOL g_comm_usb_availability = FALSE;
47 /*---------------------------------------------------------------------------------*
49 *---------------------------------------------------------------------------------*/
52 * Registering CommUSB Services IF Callback Functions
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
59 EFrameworkunifiedStatus CommUsbIfAttachCallbacksToDispatcher( // NOLINT(readability/nolint)
60 _FrameworkunifiedProtocolCallbackHandler const* p_msg_handler,
61 unsigned int ui_handler_count) {
62 EFrameworkunifiedStatus estatus = eFrameworkunifiedStatusFail;
65 happ = _pb_GetAppHandle();
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);
73 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "_pb_GetAppHandle ERROR!! [happ=%p]", happ);
81 * Remove CommUSB Services IF Callback Functions
83 * @param[in] *p_msg_handler CID table
84 * @param[in] ui_handler_count Number of CIDs
85 * @return eFrameworkunifiedStatusOK
86 * @return eFrameworkunifiedStatusFail
88 EFrameworkunifiedStatus CommUsbIfDetachCallbacksFromDispatcher(const PUI_32 pui_cmd_array, UI_32 ui_command_count) {
89 EFrameworkunifiedStatus estatus = eFrameworkunifiedStatusFail;
92 happ = _pb_GetAppHandle();
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);
101 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "_pb_GetAppHandle ERROR!! [happ=%p]", happ);
109 * CommUSB Services IF Availability Change Notification Registration
111 * @param[in] fp_on_cmd Callback function
112 * @return eFrameworkunifiedStatusOK
113 * @return eFrameworkunifiedStatusFail
115 EFrameworkunifiedStatus CommUsbIfNotifyOnCommUSBAvailability(CbFuncPtr fp_on_cmd) {
116 EFrameworkunifiedStatus estatus = eFrameworkunifiedStatusFail;
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);
128 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "_pb_GetAppHandle ERROR!! [happ=%p]", happ);
136 * CommUSB Services IF-Availability Settings
138 * @param[in] pb_is_available
141 void CommUsbIfSetAvailability(BOOL b_is_available) {
142 g_comm_usb_availability = b_is_available;
144 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "g_comm_usb_availability=%d", g_comm_usb_availability);