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.
17 ///////////////////////////////////////////////////////////////////////////////
18 /// \ingroup tag_NS_InterfaceunifiedLogCapture
19 /// \brief This file supports USB logging threads.
21 ///////////////////////////////////////////////////////////////////////////////
32 #include <sys/usbdi.h>
36 #include <native_service/ns_message_center_if.h>
37 #include <ss_logger_fs_directory.h>
38 #include <boost/bind.hpp>
41 #include <loggerservicedebug_loggerservicelog.h>
42 #include <ss_logger_device_detection.h>
43 #include <loggerservicedebug_thread_if.h>
44 #include <native_service/frameworkunified_framework_if.h>
45 #include <system_service/ss_logger_service.h>
46 #include <system_service/ss_devicedetection_service_notifications.h>
47 #include <system_service/ss_devicedetection_service_ifc.h>
48 #include <system_service/ss_sm_client_if.h>
50 #include "ss_logger_common.h"
53 const SI_32 INVALID_FD = -1;
55 // Max command line length
56 const UI_32 MAX_SYS_CMD_LN_LENGTH = 120;
58 CLoggerDeviceDetection::CLoggerDeviceDetection() :
63 CLoggerDeviceDetection::~CLoggerDeviceDetection() { // LCOV_EXCL_START 14:global instance
64 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
68 EFrameworkunifiedStatus CLoggerDeviceDetection::Initialize(HANDLE f_hApp, CLoggerCfg * f_pLoggerCfg) {
69 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
70 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
71 m_pLoggerCfg = f_pLoggerCfg;
72 // Device Detection Obj initialization
73 if (m_devDetect.Initialize(f_hApp)) { // LCOV_EXCL_BR_LINE 200:To ensure success
74 if (eFrameworkunifiedStatusOK != (l_eStatus = m_devDetect.NotifyOnDeviceDetectionAvailability(
75 boost::bind(&CLoggerDeviceDetection::DD_ServiceAvailabilityCallBack, this, _1) ))) {
76 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "ServiceAvailabilityCallback registration failed");
79 if (eFrameworkunifiedStatusOK != (l_eStatus = m_devDetect.NotifyOnOpenSessionAck(
80 boost::bind(&CLoggerDeviceDetection::DD_OpenSessionAckCallBack, this, _1) ))) {
81 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "OpenSessionAckCallback registration failed");
84 if (eFrameworkunifiedStatusOK != (l_eStatus = m_devDetect.NotifyOnCloseSessionAck(
85 boost::bind(&CLoggerDeviceDetection::DD_CloseSessionAckCallBack, this, _1) ))) {
86 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "CloseSessionCallback registration failed");
89 // LCOV_EXCL_START 200:To ensure success
90 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
91 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Device Detection Object Initialization failed!");
95 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
99 //////////////////////////////////////////
100 // Function : ServiceAvailabilityCallBack
101 //////////////////////////////////////////
102 EFrameworkunifiedStatus CLoggerDeviceDetection::DD_ServiceAvailabilityCallBack(HANDLE hApp) {
103 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
104 EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
106 if (FrameworkunifiedIsServiceAvailable(hApp)) {
107 if (eFrameworkunifiedStatusOK != (eStatus = m_devDetect.OpenSessionRequest())) {
108 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Open session request failed");
111 if (eFrameworkunifiedStatusOK != (eStatus = m_devDetect.CloseSessionRequest())) {
112 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Close session request failed");
116 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
120 //////////////////////////////////////////
121 // Function : OpenSessionAckCallBack
122 //////////////////////////////////////////
123 EFrameworkunifiedStatus CLoggerDeviceDetection::DD_OpenSessionAckCallBack(HANDLE hApp) {
124 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
125 EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
127 if (eFrameworkunifiedStatusOK == (eStatus = m_devDetect.DecodeOpenSessionResponse())) {
128 if (eFrameworkunifiedStatusOK != (eStatus = m_devDetect.RegisterForDeviceDetectionEvent(SS_DEV_DETECT_ANY_USB_EV,
129 boost::bind(&CLoggerDeviceDetection::DD_MediaDetectCallBack, this, _1)))) {
130 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Registration for SS_DEV_DETECT_ANY_USB_EV failed");
133 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Decode open session response failed");
135 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
138 //////////////////////////////////////////
139 // Function : OpenSessionAckCallBack
140 //////////////////////////////////////////
141 EFrameworkunifiedStatus CLoggerDeviceDetection::DD_CloseSessionAckCallBack(HANDLE hApp) { // LCOV_EXCL_START 200: can not called from devicedetection_service // NOLINT[whitespace/line_length]
142 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
143 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
144 EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
145 CloseSessionAck tCloseSessionAck;
148 if (eFrameworkunifiedStatusOK == (eStatus = FrameworkunifiedGetMsgDataOfSize(hApp, &tCloseSessionAck, sizeof (tCloseSessionAck)))) {
149 if (eFrameworkunifiedStatusOK == tCloseSessionAck.eStatus) {
150 UI_32 l_uiSessionId = tCloseSessionAck.sessionId;
151 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "session %d closed successfully", l_uiSessionId);
155 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
160 EFrameworkunifiedStatus CLoggerDeviceDetection::DD_CloseSessionWithDevDetectionSrv(HANDLE hApp) { // LCOV_EXCL_START 200: can not called from devicedetection_service // NOLINT[whitespace/line_length]
161 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
162 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
163 EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
165 if (eFrameworkunifiedStatusOK == (eStatus = m_devDetect.
166 NotifyOnCloseSessionAck(boost::bind(&CLoggerDeviceDetection::DD_CloseSessionAckCallBack, this, _1)))) {
167 if (eFrameworkunifiedStatusOK != (eStatus = m_devDetect.CloseSessionRequest())) {
168 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Failed to send CloseSessionRequest");
171 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Failed to register closeSessionAckCallback");
174 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
179 EFrameworkunifiedStatus CLoggerDeviceDetection::DD_MediaDetectCallBack(HANDLE hApp) { // LCOV_EXCL_START 200: can not called from devicedetection_service // NOLINT[whitespace/line_length]
180 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
181 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
182 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
183 std::string l_devstr;
184 std::string l_filePathStr;
185 SS_MediaDetectInfo l_tMediaDetectInfo;
188 if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedGetMsgDataOfSize(hApp, &l_tMediaDetectInfo, sizeof (l_tMediaDetectInfo)))) {
189 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __PRETTY_FUNCTION__, "FrameworkunifiedGetMsgDataOfSize Failed Status:0x%x ", l_eStatus);
191 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " Device = %d", l_tMediaDetectInfo.dev_type);
192 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " Availability = %d", l_tMediaDetectInfo.bIsDeviceAvailable);
193 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " device path = %s", l_tMediaDetectInfo.deviceMountpath);
194 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " File path = %s", l_tMediaDetectInfo.filepathName);
196 if (l_tMediaDetectInfo.dev_type == eUSB) {
197 if (l_tMediaDetectInfo.bIsDeviceAvailable == TRUE && m_pLoggerCfg != NULL) {
198 std::string l_usbMountPath;
199 l_usbMountPath = l_tMediaDetectInfo.deviceMountpath;
200 m_pLoggerCfg->setUsb0MountPath(l_usbMountPath);
201 m_loggerUtil->SetUsbMountPath(l_usbMountPath);
206 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");