diff options
author | Kozoriz <kozorizandriy@gmail.com> | 2016-04-26 12:41:54 +0300 |
---|---|---|
committer | Kozoriz <kozorizandriy@gmail.com> | 2016-04-26 15:50:21 +0300 |
commit | 4ecdb2a83871784f34430ed09d5ef6a2c0855506 (patch) | |
tree | dc36b449e5d32ac3e493e16865cf9d88d9991817 /src/components/transport_manager | |
parent | cf58bb97d09c536dce3b492d1517da0b837bc8eb (diff) | |
download | sdl_core-4ecdb2a83871784f34430ed09d5ef6a2c0855506.tar.gz |
Format all code in project
Formated all code in appMain, components, plugins to correct coding-style
Used clang-format-3.6
Used 2 commands :
find src/appMain/ -name "*.h" -o -name "*.cc" -o -name "*.hpp" -o -name "*.cpp" | xargs clang-format-3.6 -i -style=file
find src/components/ -name "*.h" -o -name "*.cc" -o -name "*.hpp" -o -name "*.cpp" | xargs clang-format-3.6 -i -style=file
find src/plugins/ -name "*.h" -o -name "*.cc" -o -name "*.hpp" -o -name "*.cpp" | xargs clang-format-3.6 -i -style=file
Diffstat (limited to 'src/components/transport_manager')
43 files changed, 1165 insertions, 844 deletions
diff --git a/src/components/transport_manager/include/transport_manager/bluetooth/bluetooth_connection_factory.h b/src/components/transport_manager/include/transport_manager/bluetooth/bluetooth_connection_factory.h index 4d1d474377..cdc820e555 100644 --- a/src/components/transport_manager/include/transport_manager/bluetooth/bluetooth_connection_factory.h +++ b/src/components/transport_manager/include/transport_manager/bluetooth/bluetooth_connection_factory.h @@ -48,15 +48,14 @@ class TransportAdapterController; */ class BluetoothConnectionFactory : public ServerConnectionFactory { public: - /** * @brief Constructor. * * @param controller Pointer to the device adapter controller. */ BluetoothConnectionFactory(TransportAdapterController* controller); - protected: + protected: /** * @brief Start BT connection factory. */ @@ -68,8 +67,8 @@ class BluetoothConnectionFactory : public ServerConnectionFactory { * @param device_uid Device unique identifier. * @param ap_handle Handle of application. */ - virtual TransportAdapter::Error CreateConnection(const DeviceUID& device_uid, - const ApplicationHandle& app_handle); + virtual TransportAdapter::Error CreateConnection( + const DeviceUID& device_uid, const ApplicationHandle& app_handle); /** * @brief @@ -88,6 +87,7 @@ class BluetoothConnectionFactory : public ServerConnectionFactory { * @brief Destructor. */ virtual ~BluetoothConnectionFactory(); + private: TransportAdapterController* controller_; }; diff --git a/src/components/transport_manager/include/transport_manager/bluetooth/bluetooth_device.h b/src/components/transport_manager/include/transport_manager/bluetooth/bluetooth_device.h index f28147a3b5..5194873597 100644 --- a/src/components/transport_manager/include/transport_manager/bluetooth/bluetooth_device.h +++ b/src/components/transport_manager/include/transport_manager/bluetooth/bluetooth_device.h @@ -56,7 +56,6 @@ typedef std::vector<uint8_t> RfcommChannelVector; */ class BluetoothDevice : public Device { public: - /** * @brief Return device unique identifier. * @@ -69,9 +68,11 @@ class BluetoothDevice : public Device { * * @param address Bluetooth address. * @param name Human-readable device name. - * @param rfcomm_channels List of RFCOMM channels where SmartDeviceLink service has been discovered. + * @param rfcomm_channels List of RFCOMM channels where SmartDeviceLink + *service has been discovered. **/ - BluetoothDevice(const bdaddr_t& device_address, const char* device_name, + BluetoothDevice(const bdaddr_t& device_address, + const char* device_name, const RfcommChannelVector& rfcomm_channels); /** @@ -112,7 +113,8 @@ class BluetoothDevice : public Device { bdaddr_t address_; /** - * @brief List of RFCOMM channels where SmartDeviceLink service has been discovered. + * @brief List of RFCOMM channels where SmartDeviceLink service has been + *discovered. **/ RfcommChannelVector rfcomm_channels_; }; diff --git a/src/components/transport_manager/include/transport_manager/bluetooth/bluetooth_device_scanner.h b/src/components/transport_manager/include/transport_manager/bluetooth/bluetooth_device_scanner.h index d1bed9b3dc..764b64fef3 100644 --- a/src/components/transport_manager/include/transport_manager/bluetooth/bluetooth_device_scanner.h +++ b/src/components/transport_manager/include/transport_manager/bluetooth/bluetooth_device_scanner.h @@ -62,11 +62,14 @@ class BluetoothDeviceScanner : public DeviceScanner { /** * @brief Constructor. * @param controller Transport adapter controller - * @param auto_repeat_search true - autorepeated or continous device search, false - search on demand - * @param repeat_search_pause_sec - pause between device searches, 0 means continous search + * @param auto_repeat_search true - autorepeated or continous device search, + * false - search on demand + * @param repeat_search_pause_sec - pause between device searches, 0 means + * continous search */ BluetoothDeviceScanner(TransportAdapterController* controller, - bool auto_repeat_search, int repeat_search_pause_sec); + bool auto_repeat_search, + int repeat_search_pause_sec); /** * @brief Destructor. */ @@ -75,8 +78,8 @@ class BluetoothDeviceScanner : public DeviceScanner { * @brief Main thread initialization. */ void Thread(); - protected: + protected: /** * @brief Start device scanner. * @@ -103,12 +106,13 @@ class BluetoothDeviceScanner : public DeviceScanner { * false - not initialized. */ virtual bool IsInitialised() const; - private: - class BluetoothDeviceScannerDelegate: public threads::ThreadDelegate { + private: + class BluetoothDeviceScannerDelegate : public threads::ThreadDelegate { public: explicit BluetoothDeviceScannerDelegate(BluetoothDeviceScanner* scanner); void threadMain() OVERRIDE; + private: BluetoothDeviceScanner* scanner_; }; @@ -116,7 +120,8 @@ class BluetoothDeviceScanner : public DeviceScanner { typedef std::vector<uint8_t> RfcommChannelVector; /** - * @brief Waits for external scan request or time out for repeated search or terminate request + * @brief Waits for external scan request or time out for repeated search or + * terminate request */ void TimedWaitForDeviceScanRequest(); @@ -126,7 +131,7 @@ class BluetoothDeviceScanner : public DeviceScanner { * @return List of RFCOMM-channels lists */ std::vector<RfcommChannelVector> DiscoverSmartDeviceLinkRFCOMMChannels( - const std::vector<bdaddr_t>& device_addresses); + const std::vector<bdaddr_t>& device_addresses); /** * @brief Finds RFCOMM-channels of SDL enabled applications for given device @@ -134,10 +139,11 @@ class BluetoothDeviceScanner : public DeviceScanner { * @return true - if search was OK, false if it failed */ bool DiscoverSmartDeviceLinkRFCOMMChannels(const bdaddr_t& device_address, - RfcommChannelVector* discovered); + RfcommChannelVector* discovered); /** - * @brief Summarizes the total list of devices (paired and scanned) and notifies controller + * @brief Summarizes the total list of devices (paired and scanned) and + * notifies controller */ void UpdateTotalDeviceList(); @@ -147,10 +153,12 @@ class BluetoothDeviceScanner : public DeviceScanner { void DoInquiry(); /** - * @brief Checks if given devices have SDL service and creates appropriate BluetoothDevice objects + * @brief Checks if given devices have SDL service and creates appropriate + * BluetoothDevice objects * @param bd_address List of bluetooth addresses to check * @param device_handle HCI handle - * @param[out] discovered_devices List of created BluetoothDevice objects to fill + * @param[out] discovered_devices List of created BluetoothDevice objects to + * fill */ void CheckSDLServiceOnDevices(const std::vector<bdaddr_t>& bd_address, int device_handle, diff --git a/src/components/transport_manager/include/transport_manager/bluetooth/bluetooth_socket_connection.h b/src/components/transport_manager/include/transport_manager/bluetooth/bluetooth_socket_connection.h index 3de77ab529..3f524dac0f 100644 --- a/src/components/transport_manager/include/transport_manager/bluetooth/bluetooth_socket_connection.h +++ b/src/components/transport_manager/include/transport_manager/bluetooth/bluetooth_socket_connection.h @@ -48,7 +48,6 @@ class TransportAdapterController; */ class BluetoothSocketConnection : public ThreadedSocketConnection { public: - /** * @brief Constructor. * @@ -64,8 +63,8 @@ class BluetoothSocketConnection : public ThreadedSocketConnection { * @brief Destructor. */ virtual ~BluetoothSocketConnection(); - protected: + protected: /** * @brief Establish connection. * diff --git a/src/components/transport_manager/include/transport_manager/tcp/tcp_client_listener.h b/src/components/transport_manager/include/transport_manager/tcp/tcp_client_listener.h index 620efff2b1..2640049ecc 100644 --- a/src/components/transport_manager/include/transport_manager/tcp/tcp_client_listener.h +++ b/src/components/transport_manager/include/transport_manager/tcp/tcp_client_listener.h @@ -59,7 +59,8 @@ class TcpClientListener : public ClientConnectionListener { * @param enable_keepalive If true enables TCP keepalive on accepted *connections */ - TcpClientListener(TransportAdapterController* controller, uint16_t port, + TcpClientListener(TransportAdapterController* controller, + uint16_t port, bool enable_keepalive); /** @@ -70,7 +71,8 @@ class TcpClientListener : public ClientConnectionListener { /** * @brief Run TCP client listener. * - * @return Error information about possible reason of starting TCP listener listener failure. + * @return Error information about possible reason of starting TCP listener + *listener failure. */ virtual TransportAdapter::Error Init(); @@ -101,15 +103,15 @@ class TcpClientListener : public ClientConnectionListener { #ifdef BUILD_TESTS uint16_t port() const { - return port_; + return port_; } int get_socket() const { - return socket_; + return socket_; } threads::Thread* thread() const { - return thread_; + return thread_; } #endif // BUILD_TESTS @@ -129,6 +131,7 @@ class TcpClientListener : public ClientConnectionListener { explicit ListeningThreadDelegate(TcpClientListener* parent); virtual void threadMain(); void exitThreadMain(); + private: TcpClientListener* parent_; }; diff --git a/src/components/transport_manager/include/transport_manager/tcp/tcp_socket_connection.h b/src/components/transport_manager/include/transport_manager/tcp/tcp_socket_connection.h index 432a0aa760..4d7901f4f0 100644 --- a/src/components/transport_manager/include/transport_manager/tcp/tcp_socket_connection.h +++ b/src/components/transport_manager/include/transport_manager/tcp/tcp_socket_connection.h @@ -77,7 +77,8 @@ class TcpSocketConnection : public ThreadedSocketConnection { }; /** - * @brief Class responsible for communication over sockets that originated by server. + * @brief Class responsible for communication over sockets that originated by + * server. */ class TcpServerOiginatedSocketConnection : public ThreadedSocketConnection { public: @@ -89,8 +90,8 @@ class TcpServerOiginatedSocketConnection : public ThreadedSocketConnection { * @param controller Pointer to the device adapter controller. */ TcpServerOiginatedSocketConnection(const DeviceUID& device_uid, - const ApplicationHandle& app_handle, - TransportAdapterController* controller); + const ApplicationHandle& app_handle, + TransportAdapterController* controller); /** * @brief Destructor. diff --git a/src/components/transport_manager/include/transport_manager/telemetry_observer.h b/src/components/transport_manager/include/transport_manager/telemetry_observer.h index 8fe98a1553..1097feaecb 100644 --- a/src/components/transport_manager/include/transport_manager/telemetry_observer.h +++ b/src/components/transport_manager/include/transport_manager/telemetry_observer.h @@ -49,7 +49,7 @@ class TMTelemetryObserver { virtual void StartRawMsg(const protocol_handler::RawMessage* ptr) = 0; virtual void StopRawMsg(const protocol_handler::RawMessage* ptr) = 0; - virtual ~TMTelemetryObserver(){} + virtual ~TMTelemetryObserver() {} }; } // transport_manager #endif // SRC_COMPONENTS_TRANSPORT_MANAGER_INCLUDE_TRANSPORT_MANAGER_TIME_METRIC_OBSERVER_H_ diff --git a/src/components/transport_manager/include/transport_manager/transport_adapter/client_connection_listener.h b/src/components/transport_manager/include/transport_manager/transport_adapter/client_connection_listener.h index 018dd46810..8df2c4d299 100644 --- a/src/components/transport_manager/include/transport_manager/transport_adapter/client_connection_listener.h +++ b/src/components/transport_manager/include/transport_manager/transport_adapter/client_connection_listener.h @@ -35,10 +35,8 @@ #include "transport_manager/transport_adapter/transport_adapter.h" - namespace transport_manager { - namespace transport_adapter { /** @@ -49,7 +47,8 @@ class ClientConnectionListener { /** * @brief Run client connection listener. * - * @return Error information about possible reason of starting client listener failure. + * @return Error information about possible reason of starting client listener + *failure. */ virtual TransportAdapter::Error Init() = 0; @@ -79,8 +78,7 @@ class ClientConnectionListener { /** * @brief Destructor. */ - virtual ~ClientConnectionListener() { - } + virtual ~ClientConnectionListener() {} }; } // namespace transport_adapter diff --git a/src/components/transport_manager/include/transport_manager/transport_adapter/connection.h b/src/components/transport_manager/include/transport_manager/transport_adapter/connection.h index e3f0b3d1d7..537e94b055 100644 --- a/src/components/transport_manager/include/transport_manager/transport_adapter/connection.h +++ b/src/components/transport_manager/include/transport_manager/transport_adapter/connection.h @@ -58,7 +58,8 @@ class Connection { * * @return Error Information about possible reason of sending data failure. */ - virtual TransportAdapter::Error SendData(::protocol_handler::RawMessagePtr message) = 0; + virtual TransportAdapter::Error SendData( + ::protocol_handler::RawMessagePtr message) = 0; /** * @brief Disconnect the current connection. @@ -70,4 +71,4 @@ typedef utils::SharedPtr<Connection> ConnectionSPtr; } // namespace transport_adapter } // namespace transport_manager -#endif // SRC_COMPONENTS_TRANSPORT_MANAGER_INCLUDE_TRANSPORT_MANAGER_TRANSPORT_ADAPTER_CONNECTION_H_ +#endif // SRC_COMPONENTS_TRANSPORT_MANAGER_INCLUDE_TRANSPORT_MANAGER_TRANSPORT_ADAPTER_CONNECTION_H_ diff --git a/src/components/transport_manager/include/transport_manager/transport_adapter/device_scanner.h b/src/components/transport_manager/include/transport_manager/transport_adapter/device_scanner.h index 36759a9385..6e58f692a9 100644 --- a/src/components/transport_manager/include/transport_manager/transport_adapter/device_scanner.h +++ b/src/components/transport_manager/include/transport_manager/transport_adapter/device_scanner.h @@ -76,8 +76,7 @@ class DeviceScanner { /** * @brief Destructor. */ - virtual ~DeviceScanner() { - } + virtual ~DeviceScanner() {} }; } // namespace transport_adapter diff --git a/src/components/transport_manager/include/transport_manager/transport_adapter/server_connection_factory.h b/src/components/transport_manager/include/transport_manager/transport_adapter/server_connection_factory.h index 19c37aa6a6..3cd93e1316 100644 --- a/src/components/transport_manager/include/transport_manager/transport_adapter/server_connection_factory.h +++ b/src/components/transport_manager/include/transport_manager/transport_adapter/server_connection_factory.h @@ -41,7 +41,8 @@ namespace transport_manager { namespace transport_adapter { /** - * @brief Implement transport dependent connection that was originated by the user. + * @brief Implement transport dependent connection that was originated by the + * user. */ class ServerConnectionFactory { public: @@ -79,8 +80,7 @@ class ServerConnectionFactory { /** * @brief Destructor. */ - virtual ~ServerConnectionFactory() { - } + virtual ~ServerConnectionFactory() {} }; } // namespace transport_adapter diff --git a/src/components/transport_manager/include/transport_manager/transport_adapter/threaded_socket_connection.h b/src/components/transport_manager/include/transport_manager/transport_adapter/threaded_socket_connection.h index d764979fbd..ab0c5cbf85 100644 --- a/src/components/transport_manager/include/transport_manager/transport_adapter/threaded_socket_connection.h +++ b/src/components/transport_manager/include/transport_manager/transport_adapter/threaded_socket_connection.h @@ -140,6 +140,7 @@ class ThreadedSocketConnection : public Connection { explicit SocketConnectionDelegate(ThreadedSocketConnection* connection); void threadMain() OVERRIDE; void exitThreadMain() OVERRIDE; + private: ThreadedSocketConnection* connection_; }; diff --git a/src/components/transport_manager/include/transport_manager/transport_adapter/transport_adapter_controller.h b/src/components/transport_manager/include/transport_manager/transport_adapter/transport_adapter_controller.h index f0148ad1af..1712f0f181 100644 --- a/src/components/transport_manager/include/transport_manager/transport_adapter/transport_adapter_controller.h +++ b/src/components/transport_manager/include/transport_manager/transport_adapter/transport_adapter_controller.h @@ -42,8 +42,7 @@ namespace transport_adapter { class TransportAdapterController { public: - virtual ~TransportAdapterController() { - } + virtual ~TransportAdapterController() {} /** * @brief Add device to the container(map), if container doesn't hold it yet. @@ -55,7 +54,8 @@ class TransportAdapterController { virtual DeviceSptr AddDevice(DeviceSptr device) = 0; /** - * @brief Search for device in container of devices, if it is not there - adds it. + * @brief Search for device in container of devices, if it is not there - adds + *it. * * @param devices Container(vector) of smart pointers to devices. */ @@ -100,7 +100,8 @@ class TransportAdapterController { const ApplicationHandle& app_handle) = 0; /** - * @brief Make state of specified connection - ESTABLISHED and launch OnConnectDone event in device adapter listener. + * @brief Make state of specified connection - ESTABLISHED and launch + *OnConnectDone event in device adapter listener. * * @param devcie_handle Device unique identifier. * @param app_handle Handle of application. @@ -109,7 +110,8 @@ class TransportAdapterController { const ApplicationHandle& app_handle) = 0; /** - * @brief Delete connection from the container of connections and launch OnConnectFailed event in the device adapter listener. + * @brief Delete connection from the container of connections and launch + *OnConnectFailed event in the device adapter listener. * * @param device_handle Device unique identifier. * @param app_handle Handle of application. @@ -128,7 +130,8 @@ class TransportAdapterController { const ApplicationHandle& app_handle) = 0; /** - * @brief Set specified connection state to FINALISING and launch OnUnexpectedDisconnect event in the device adapter listener. + * @brief Set specified connection state to FINALISING and launch + *OnUnexpectedDisconnect event in the device adapter listener. * * @param device_handle Device unique identifier. * @param app_handle Handle of application. @@ -147,7 +150,8 @@ class TransportAdapterController { const DisconnectDeviceError& error) = 0; /** - * @brief Delete specified connection from the container(map) of connections and launch event in the device adapter listener. + * @brief Delete specified connection from the container(map) of connections + *and launch event in the device adapter listener. * * @param device_handle Device unique identifier. * @param app_handle Handle of application. @@ -155,13 +159,13 @@ class TransportAdapterController { virtual void DisconnectDone(const DeviceUID& device_handle, const ApplicationHandle& app_handle) = 0; - /** - * @brief Launch OnDataReceiveDone event in the device adapter listener. - * - * @param device_handle Device unique identifier. - * @param app_handle Handle of application. - * @param message Smart pointer to the raw message. - */ + /** + * @brief Launch OnDataReceiveDone event in the device adapter listener. + * + * @param device_handle Device unique identifier. + * @param app_handle Handle of application. + * @param message Smart pointer to the raw message. + */ virtual void DataReceiveDone(const DeviceUID& device_handle, const ApplicationHandle& app_handle, ::protocol_handler::RawMessagePtr message) = 0; @@ -198,7 +202,8 @@ class TransportAdapterController { */ virtual void DataSendFailed(const DeviceUID& device_handle, const ApplicationHandle& app_handle, - ::protocol_handler::RawMessagePtr message, const DataSendError&) = 0; + ::protocol_handler::RawMessagePtr message, + const DataSendError&) = 0; }; } // namespace transport_adapter diff --git a/src/components/transport_manager/include/transport_manager/transport_adapter/transport_adapter_listener.h b/src/components/transport_manager/include/transport_manager/transport_adapter/transport_adapter_listener.h index 3c302caf14..0a1eeb6b4a 100644 --- a/src/components/transport_manager/include/transport_manager/transport_adapter/transport_adapter_listener.h +++ b/src/components/transport_manager/include/transport_manager/transport_adapter/transport_adapter_listener.h @@ -50,11 +50,11 @@ class TransportAdapterListener { /** * @brief Destructor. */ - virtual ~TransportAdapterListener() { - } + virtual ~TransportAdapterListener() {} /** - * @brief Search specified device adapter in the container of shared pointers to device adapters to be sure it is available, + * @brief Search specified device adapter in the container of shared pointers + *to device adapters to be sure it is available, * launch event ON_SEARCH_DONE in transport manager. * * @param transport_adapter Pointer to the device adapter. @@ -63,11 +63,13 @@ class TransportAdapterListener { const TransportAdapter* transport_adapter) = 0; /** - * @brief Search specified device adapter in the container of shared pointers to device adapters to be sure it is available, create search device error, + * @brief Search specified device adapter in the container of shared pointers + *to device adapters to be sure it is available, create search device error, * launch event ON_SEARCH_FAIL in transport manager. * * @param transport_adapter Pointer to the device adapter. - * @param error Error class with information about possible reason of search device failure. + * @param error Error class with information about possible reason of search + *device failure. */ virtual void OnSearchDeviceFailed(const TransportAdapter* transport_adapter, const SearchDeviceError& error) = 0; @@ -86,10 +88,12 @@ class TransportAdapterListener { * @brief Reaction to "Find new applications" request * @param adapter Current transport adapter */ - virtual void OnFindNewApplicationsRequest(const TransportAdapter* adapter) = 0; + virtual void OnFindNewApplicationsRequest( + const TransportAdapter* adapter) = 0; /** - * @brief Search specified device adapter in the container of shared pointers to device adapters to be sure it is available, + * @brief Search specified device adapter in the container of shared pointers + *to device adapters to be sure it is available, * launch event ON_CONNECT_DONE in transport manager. * * @param device_adater Pointer to the device adapter. @@ -101,13 +105,15 @@ class TransportAdapterListener { const ApplicationHandle& app_handle) = 0; /** - * @brief Search specified device adapter in the container of shared pointers to device adapters to be sure it is available, + * @brief Search specified device adapter in the container of shared pointers + *to device adapters to be sure it is available, * launch event ON_CONNECT_FAIL in transport manager. * * @param transport_adapter Pointer to the device adapter. * @param device Device unique identifier. * @param app_id Handle of application. - * @param error Error class with information about possible reason of connect failure. + * @param error Error class with information about possible reason of connect + *failure. */ virtual void OnConnectFailed(const TransportAdapter* transport_adapter, const DeviceUID& device_handle, @@ -126,20 +132,23 @@ class TransportAdapterListener { const ApplicationHandle& app_handle) = 0; /** - * @brief Search specified device adapter in the container of shared pointers to device adapters to be sure it is available, + * @brief Search specified device adapter in the container of shared pointers + *to device adapters to be sure it is available, * launch event ON_UNEXPECTED_DISCONNECT in transport manager. * * @param transport_adapter Pointer to the device adapter. * @param device Device unique identifier. * @param app_id Handle of application. - * @param error Error class with information about possible reason of unexpected Disconnect. + * @param error Error class with information about possible reason of + *unexpected Disconnect. */ virtual void OnUnexpectedDisconnect(const TransportAdapter* transport_adapter, const DeviceUID& device_handle, const ApplicationHandle& app_handle, const CommunicationError& error) = 0; /** - * @brief Search specified device adapter in the container of shared pointers to device adapters to be sure it is available, + * @brief Search specified device adapter in the container of shared pointers + *to device adapters to be sure it is available, * launch event ON_DISCONNECT_DONE in transport manager. * * @param transport_adapter Pointer to the device adapter. @@ -151,13 +160,15 @@ class TransportAdapterListener { const ApplicationHandle& app_handle) = 0; /** - * @brief Search specified device adapter in the container of shared pointers to device adapters to be sure it is available, create Disconnect error, + * @brief Search specified device adapter in the container of shared pointers + *to device adapters to be sure it is available, create Disconnect error, * launch event ON_DISCONNECT_FAIL in transport manager. * * @param transport_adapter Pointer to the device adapter. * @param device Device unique identifier. * @param app_id Handle of application. - * @param error Error class with information about possible reason of Disconnect failure. + * @param error Error class with information about possible reason of + *Disconnect failure. */ virtual void OnDisconnectFailed(const TransportAdapter* transport_adapter, const DeviceUID& device_handle, @@ -178,14 +189,17 @@ class TransportAdapterListener { * * @param transport_adapter Pointer to the device adapter. * @param device Device unique identifier. - * @param error Error class with information about possible reason of Disconnect from device failure. + * @param error Error class with information about possible reason of + *Disconnect from device failure. */ virtual void OnDisconnectDeviceFailed( - const TransportAdapter* transport_adapter, const DeviceUID& device_handle, + const TransportAdapter* transport_adapter, + const DeviceUID& device_handle, const DisconnectDeviceError& error) = 0; /** - * @brief Search specified device adapter in the container of shared pointers to device adapters to be sure it is available, create error, + * @brief Search specified device adapter in the container of shared pointers + *to device adapters to be sure it is available, create error, * launch event ON_RECEIVED_DONE in transport manager. * * @param transport_adapter Pointer to the device adapter. @@ -193,28 +207,33 @@ class TransportAdapterListener { * @param app_id Handle of application. * @param data_container Smart pointer to the raw message. */ - virtual void OnDataSendDone(const TransportAdapter* transport_adapter, - const DeviceUID& device_handle, - const ApplicationHandle& app_handle, - const ::protocol_handler::RawMessagePtr data_container) = 0; + virtual void OnDataSendDone( + const TransportAdapter* transport_adapter, + const DeviceUID& device_handle, + const ApplicationHandle& app_handle, + const ::protocol_handler::RawMessagePtr data_container) = 0; /** - * @brief Search specified device adapter in the container of shared pointers to device adapters to be sure it is available, create data receive error, + * @brief Search specified device adapter in the container of shared pointers + *to device adapters to be sure it is available, create data receive error, * launch event ON_RECEIVED_DONE in transport manager. * * @param transport_adapter Pointer to the device adapter. * @param device Device unique identifier. * @param app_id Handle of application. - * @param error Error class with information about possible reason of data receive failure. + * @param error Error class with information about possible reason of data + *receive failure. */ - virtual void OnDataSendFailed(const TransportAdapter* transport_adapter, - const DeviceUID& device_handle, - const ApplicationHandle& app_handle, - const ::protocol_handler::RawMessagePtr data_container, - const DataSendError& error) = 0; + virtual void OnDataSendFailed( + const TransportAdapter* transport_adapter, + const DeviceUID& device_handle, + const ApplicationHandle& app_handle, + const ::protocol_handler::RawMessagePtr data_container, + const DataSendError& error) = 0; /** - * @brief Search specified device adapter in the container of shared pointers to device adapters to be sure it is available, create error, + * @brief Search specified device adapter in the container of shared pointers + *to device adapters to be sure it is available, create error, * launch event ON_SEND_DONE in transport manager. * * @param transport_adapter Pointer to the device adapter. @@ -222,13 +241,15 @@ class TransportAdapterListener { * @param app_id Handle of application. * @param data_container Smart pointer to the raw message. */ - virtual void OnDataReceiveDone(const TransportAdapter* transport_adapter, - const DeviceUID& device_handle, - const ApplicationHandle& app_handle, - const ::protocol_handler::RawMessagePtr data_container) = 0; + virtual void OnDataReceiveDone( + const TransportAdapter* transport_adapter, + const DeviceUID& device_handle, + const ApplicationHandle& app_handle, + const ::protocol_handler::RawMessagePtr data_container) = 0; /** - * @brief Search specified device adapter in the container of shared pointers to device adapters to be sure it is available, create data send error, + * @brief Search specified device adapter in the container of shared pointers + * to device adapters to be sure it is available, create data send error, * launch event ON_SEND_FAIL in transport manager. */ virtual void OnDataReceiveFailed(const TransportAdapter* transport_adapter, @@ -237,7 +258,8 @@ class TransportAdapterListener { const DataReceiveError& error) = 0; /** - * @brief Search specified device adapter in the container of shared pointers to device adapters to be sure it is available, create error, + * @brief Search specified device adapter in the container of shared pointers + *to device adapters to be sure it is available, create error, * launch event ON_COMMUNICATION_ERROR in transport manager. * * @param transport_adapter Pointer to the device adapter. diff --git a/src/components/transport_manager/include/transport_manager/transport_adapter/transport_adapter_listener_impl.h b/src/components/transport_manager/include/transport_manager/transport_adapter/transport_adapter_listener_impl.h index 2a2d6dc401..a0daa7b594 100644 --- a/src/components/transport_manager/include/transport_manager/transport_adapter/transport_adapter_listener_impl.h +++ b/src/components/transport_manager/include/transport_manager/transport_adapter/transport_adapter_listener_impl.h @@ -222,10 +222,11 @@ class TransportAdapterListenerImpl * @param app_id Handle of application. * @param data_container Smart pointer to the raw message. */ - virtual void OnDataReceiveDone(const TransportAdapter* adapter, - const DeviceUID& device, - const ApplicationHandle& app_id, - const ::protocol_handler::RawMessagePtr data_container); + virtual void OnDataReceiveDone( + const TransportAdapter* adapter, + const DeviceUID& device, + const ApplicationHandle& app_id, + const ::protocol_handler::RawMessagePtr data_container); /** * @brief Search specified device adapter in the container of shared pointers @@ -253,21 +254,23 @@ class TransportAdapterListenerImpl * @param app_id Handle of application. * @param data_container Smart pointer to the raw message. */ - virtual void OnDataSendDone(const TransportAdapter* adapter, - const DeviceUID& device, - const ApplicationHandle& app_id, - const ::protocol_handler::RawMessagePtr data_container); + virtual void OnDataSendDone( + const TransportAdapter* adapter, + const DeviceUID& device, + const ApplicationHandle& app_id, + const ::protocol_handler::RawMessagePtr data_container); /** * @brief Search specified device adapter in the container of shared pointers * to device adapters to be sure it is available, create data send error, * launch event ON_SEND_FAIL in transport manager. */ - virtual void OnDataSendFailed(const TransportAdapter* adapter, - const DeviceUID& device, - const ApplicationHandle& app_id, - const ::protocol_handler::RawMessagePtr data_container, - const DataSendError& error); + virtual void OnDataSendFailed( + const TransportAdapter* adapter, + const DeviceUID& device, + const ApplicationHandle& app_id, + const ::protocol_handler::RawMessagePtr data_container, + const DataSendError& error); /** * @brief Search specified device adapter in the container of shared pointers diff --git a/src/components/transport_manager/include/transport_manager/usb/common.h b/src/components/transport_manager/include/transport_manager/usb/common.h index 283d224536..1c6011dbb2 100644 --- a/src/components/transport_manager/include/transport_manager/usb/common.h +++ b/src/components/transport_manager/include/transport_manager/usb/common.h @@ -53,14 +53,14 @@ static const uint16_t kAoaPid2 = 0x2d01; static const uint8_t kAoaInterfaceSubclass = 0xff; static const uint16_t kAppleVid = 0x05ac; -static const uint16_t kApplePid1 = 0x1290; // iPhone -static const uint16_t kApplePid2 = 0x1292; // iPhone 3G -static const uint16_t kApplePid3 = 0x1294; // iPhone 3GS -static const uint16_t kApplePid4 = 0x1297; // iPhone 4 -static const uint16_t kApplePid5 = 0x129a; // iPad -static const uint16_t kApplePid6 = 0x129f; // iPad 2 -static const uint16_t kApplePid7 = 0x12a0; // iPhone 4S -static const uint16_t kApplePid8 = 0x12a8; // iPhone 5 +static const uint16_t kApplePid1 = 0x1290; // iPhone +static const uint16_t kApplePid2 = 0x1292; // iPhone 3G +static const uint16_t kApplePid3 = 0x1294; // iPhone 3GS +static const uint16_t kApplePid4 = 0x1297; // iPhone 4 +static const uint16_t kApplePid5 = 0x129a; // iPad +static const uint16_t kApplePid6 = 0x129f; // iPad 2 +static const uint16_t kApplePid7 = 0x12a0; // iPhone 4S +static const uint16_t kApplePid8 = 0x12a8; // iPhone 5 static const int kUsbConfiguration = 1; @@ -70,7 +70,9 @@ class UsbDeviceListener { public: virtual ~UsbDeviceListener() {} - UsbHandlerSptr GetUsbHandler() { return usb_handler_; } + UsbHandlerSptr GetUsbHandler() { + return usb_handler_; + } void SetUsbHandler(UsbHandlerSptr usb_handler) { usb_handler_ = usb_handler; @@ -86,23 +88,24 @@ class UsbDeviceListener { inline bool IsGoogleAccessory(const PlatformUsbDevice* device) { return (kAoaVid == device->vendor_id()) && - ((kAoaPid1 == device->product_id()) || (kAoaPid2 == device->product_id())); + ((kAoaPid1 == device->product_id()) || + (kAoaPid2 == device->product_id())); } inline bool IsAppleIAPDevice(const PlatformUsbDevice* device) { return (kAppleVid == device->vendor_id()) && - ((kApplePid1 == device->product_id()) || - (kApplePid2 == device->product_id()) || - (kApplePid3 == device->product_id()) || - (kApplePid4 == device->product_id()) || - (kApplePid5 == device->product_id()) || - (kApplePid6 == device->product_id()) || - (kApplePid7 == device->product_id())); + ((kApplePid1 == device->product_id()) || + (kApplePid2 == device->product_id()) || + (kApplePid3 == device->product_id()) || + (kApplePid4 == device->product_id()) || + (kApplePid5 == device->product_id()) || + (kApplePid6 == device->product_id()) || + (kApplePid7 == device->product_id())); } inline bool IsAppleIAP2Device(const PlatformUsbDevice* device) { return (kAppleVid == device->vendor_id()) && - (kApplePid8 == device->product_id()); + (kApplePid8 == device->product_id()); } inline bool IsAppleDevice(const PlatformUsbDevice* device) { diff --git a/src/components/transport_manager/include/transport_manager/usb/libusb/platform_usb_device.h b/src/components/transport_manager/include/transport_manager/usb/libusb/platform_usb_device.h index b90c504a4b..1aa6881b38 100644 --- a/src/components/transport_manager/include/transport_manager/usb/libusb/platform_usb_device.h +++ b/src/components/transport_manager/include/transport_manager/usb/libusb/platform_usb_device.h @@ -45,19 +45,32 @@ namespace transport_adapter { class PlatformUsbDevice { public: - uint8_t bus_number() const { return bus_number_; } - uint8_t address() const { return address_; } - uint16_t vendor_id() const { return vendor_id_; } - uint16_t product_id() const { return product_id_; } + uint8_t bus_number() const { + return bus_number_; + } + uint8_t address() const { + return address_; + } + uint16_t vendor_id() const { + return vendor_id_; + } + uint16_t product_id() const { + return product_id_; + } std::string GetManufacturer() const; std::string GetProductName() const; std::string GetSerialNumber() const; - PlatformUsbDevice(uint8_t bus, uint8_t address, + PlatformUsbDevice(uint8_t bus, + uint8_t address, const libusb_device_descriptor& device_descriptor, libusb_device* device_libusb, libusb_device_handle* device_handle_libusb); - libusb_device_handle* GetLibusbHandle() { return libusb_device_handle_; } - libusb_device* GetLibusbDevice() { return libusb_device_; } + libusb_device_handle* GetLibusbHandle() { + return libusb_device_handle_; + } + libusb_device* GetLibusbDevice() { + return libusb_device_; + } private: std::string GetDescString(uint8_t index) const; diff --git a/src/components/transport_manager/include/transport_manager/usb/libusb/usb_connection.h b/src/components/transport_manager/include/transport_manager/usb/libusb/usb_connection.h index 7c1fbd4551..bad1cd7117 100644 --- a/src/components/transport_manager/include/transport_manager/usb/libusb/usb_connection.h +++ b/src/components/transport_manager/include/transport_manager/usb/libusb/usb_connection.h @@ -49,12 +49,14 @@ class UsbConnection : public Connection { UsbConnection(const DeviceUID& device_uid, const ApplicationHandle& app_handle, TransportAdapterController* controller, - const UsbHandlerSptr usb_handler, PlatformUsbDevice* device); + const UsbHandlerSptr usb_handler, + PlatformUsbDevice* device); bool Init(); virtual ~UsbConnection(); protected: - virtual TransportAdapter::Error SendData(::protocol_handler::RawMessagePtr message); + virtual TransportAdapter::Error SendData( + ::protocol_handler::RawMessagePtr message); virtual TransportAdapter::Error Disconnect(); private: diff --git a/src/components/transport_manager/include/transport_manager/usb/libusb/usb_handler.h b/src/components/transport_manager/include/transport_manager/usb/libusb/usb_handler.h index 215b66f6e3..b2ebd3a977 100644 --- a/src/components/transport_manager/include/transport_manager/usb/libusb/usb_handler.h +++ b/src/components/transport_manager/include/transport_manager/usb/libusb/usb_handler.h @@ -72,10 +72,11 @@ class UsbHandler { friend void UsbTransferSequenceCallback(libusb_transfer* transfer); private: - class UsbHandlerDelegate: public threads::ThreadDelegate { + class UsbHandlerDelegate : public threads::ThreadDelegate { public: explicit UsbHandlerDelegate(UsbHandler* handler); void threadMain() OVERRIDE; + private: UsbHandler* handler_; }; @@ -97,10 +98,14 @@ class UsbHandler { libusb_hotplug_callback_handle left_callback_handle_; friend void* UsbHandlerThread(void* data); - friend int ArrivedCallback(libusb_context* context, libusb_device* device, - libusb_hotplug_event event, void* data); - friend int LeftCallback(libusb_context* context, libusb_device* device, - libusb_hotplug_event event, void* data); + friend int ArrivedCallback(libusb_context* context, + libusb_device* device, + libusb_hotplug_event event, + void* data); + friend int LeftCallback(libusb_context* context, + libusb_device* device, + libusb_hotplug_event event, + void* data); }; } // namespace transport_adapter diff --git a/src/components/transport_manager/include/transport_manager/usb/qnx/platform_usb_device.h b/src/components/transport_manager/include/transport_manager/usb/qnx/platform_usb_device.h index ab35f862c6..9755a5eacd 100644 --- a/src/components/transport_manager/include/transport_manager/usb/qnx/platform_usb_device.h +++ b/src/components/transport_manager/include/transport_manager/usb/qnx/platform_usb_device.h @@ -45,19 +45,30 @@ namespace transport_adapter { class PlatformUsbDevice { public: - uint8_t bus_number() const { return bus_number_; } - uint8_t address() const { return address_; } - uint16_t vendor_id() const { return vendor_id_; } - uint16_t product_id() const { return product_id_; } + uint8_t bus_number() const { + return bus_number_; + } + uint8_t address() const { + return address_; + } + uint16_t vendor_id() const { + return vendor_id_; + } + uint16_t product_id() const { + return product_id_; + } std::string GetManufacturer() const; std::string GetProductName() const; std::string GetSerialNumber() const; - PlatformUsbDevice(usbd_device_instance_t* instance, usbd_device* device, + PlatformUsbDevice(usbd_device_instance_t* instance, + usbd_device* device, const usbd_device_descriptor_t& device_descriptor); const usbd_device_instance_t& GetDeviceInstance() { return usbd_device_instance_; } - usbd_device* GetUsbdDevice() { return usbd_device_; } + usbd_device* GetUsbdDevice() { + return usbd_device_; + } private: std::string GetDescString(uint8_t index) const; diff --git a/src/components/transport_manager/include/transport_manager/usb/qnx/usb_connection.h b/src/components/transport_manager/include/transport_manager/usb/qnx/usb_connection.h index d55c887bd1..e9f7344ee2 100644 --- a/src/components/transport_manager/include/transport_manager/usb/qnx/usb_connection.h +++ b/src/components/transport_manager/include/transport_manager/usb/qnx/usb_connection.h @@ -47,6 +47,7 @@ namespace transport_adapter { class UsbConnection : public Connection { static const uint32_t kInBufferSize = 2048; + public: UsbConnection(const DeviceUID& device_uid, const ApplicationHandle& app_handle, @@ -57,9 +58,12 @@ class UsbConnection : public Connection { bool Init(); virtual ~UsbConnection(); + protected: - virtual TransportAdapter::Error SendData(::protocol_handler::RawMessagePtr message); + virtual TransportAdapter::Error SendData( + ::protocol_handler::RawMessagePtr message); virtual TransportAdapter::Error Disconnect(); + private: friend void InTransferCallback(usbd_urb* urb, usbd_pipe*, void*); friend void OutTransferCallback(usbd_urb* urb, usbd_pipe*, void*); diff --git a/src/components/transport_manager/include/transport_manager/usb/usb_control_transfer.h b/src/components/transport_manager/include/transport_manager/usb/usb_control_transfer.h index c701a86e0a..a3597ff3d4 100644 --- a/src/components/transport_manager/include/transport_manager/usb/usb_control_transfer.h +++ b/src/components/transport_manager/include/transport_manager/usb/usb_control_transfer.h @@ -46,14 +46,9 @@ class UsbControlOutTransfer; class UsbControlTransfer { public: - enum TransferDirection { - IN, - OUT - }; + enum TransferDirection { IN, OUT }; - enum RequestType { - VENDOR - }; + enum RequestType { VENDOR }; virtual ~UsbControlTransfer() {} virtual TransferDirection Direction() const = 0; @@ -67,21 +62,27 @@ class UsbControlTransfer { class UsbControlInTransfer : public UsbControlTransfer { public: virtual ~UsbControlInTransfer() {} - virtual TransferDirection Direction() const { return IN; } + virtual TransferDirection Direction() const { + return IN; + } virtual bool OnCompleted(unsigned char* data) const = 0; }; class UsbControlOutTransfer : public UsbControlTransfer { public: virtual ~UsbControlOutTransfer() {} - virtual TransferDirection Direction() const { return OUT; } + virtual TransferDirection Direction() const { + return OUT; + } virtual const char* Data() const = 0; }; class UsbControlTransferSequence { public: typedef std::list<UsbControlTransfer*> Transfers; - const Transfers& transfers() const { return transfers_; } + const Transfers& transfers() const { + return transfers_; + } virtual ~UsbControlTransferSequence() { for (Transfers::iterator it = transfers_.begin(); it != transfers_.end(); diff --git a/src/components/transport_manager/include/transport_manager/usb/usb_device.h b/src/components/transport_manager/include/transport_manager/usb/usb_device.h index 48c5867f90..fdcfb6e155 100644 --- a/src/components/transport_manager/include/transport_manager/usb/usb_device.h +++ b/src/components/transport_manager/include/transport_manager/usb/usb_device.h @@ -45,11 +45,14 @@ namespace transport_adapter { class UsbDevice : public Device { public: - UsbDevice(PlatformUsbDevice* usb_device, const std::string& name, + UsbDevice(PlatformUsbDevice* usb_device, + const std::string& name, const DeviceUID& unique_device_id) : Device(name, unique_device_id), usb_device_(usb_device) {} - PlatformUsbDevice* usb_device() const { return usb_device_; } + PlatformUsbDevice* usb_device() const { + return usb_device_; + } protected: virtual ~UsbDevice() {} diff --git a/src/components/transport_manager/src/bluetooth/bluetooth_connection_factory.cc b/src/components/transport_manager/src/bluetooth/bluetooth_connection_factory.cc index 02224baf4e..bb27493701 100644 --- a/src/components/transport_manager/src/bluetooth/bluetooth_connection_factory.cc +++ b/src/components/transport_manager/src/bluetooth/bluetooth_connection_factory.cc @@ -45,20 +45,20 @@ namespace transport_adapter { CREATE_LOGGERPTR_GLOBAL(logger_, "TransportManager") BluetoothConnectionFactory::BluetoothConnectionFactory( - TransportAdapterController* controller) - : controller_(controller) { -} + TransportAdapterController* controller) + : controller_(controller) {} TransportAdapter::Error BluetoothConnectionFactory::Init() { return TransportAdapter::OK; } TransportAdapter::Error BluetoothConnectionFactory::CreateConnection( - const DeviceUID& device_uid, const ApplicationHandle& app_handle) { - LOG4CXX_TRACE(logger_, "enter. device_uid: " << &device_uid << ", app_handle: " << - &app_handle); + const DeviceUID& device_uid, const ApplicationHandle& app_handle) { + LOG4CXX_TRACE(logger_, + "enter. device_uid: " << &device_uid + << ", app_handle: " << &app_handle); BluetoothSocketConnection* connection( - new BluetoothSocketConnection(device_uid, app_handle, controller_)); + new BluetoothSocketConnection(device_uid, app_handle, controller_)); TransportAdapter::Error error = connection->Start(); if (TransportAdapter::OK != error) { LOG4CXX_ERROR(logger_, "connection::Start() failed"); @@ -68,15 +68,13 @@ TransportAdapter::Error BluetoothConnectionFactory::CreateConnection( return error; } -void BluetoothConnectionFactory::Terminate() { -} +void BluetoothConnectionFactory::Terminate() {} bool BluetoothConnectionFactory::IsInitialised() const { return true; } -BluetoothConnectionFactory::~BluetoothConnectionFactory() { -} +BluetoothConnectionFactory::~BluetoothConnectionFactory() {} } // namespace transport_adapter } // namespace transport_manager diff --git a/src/components/transport_manager/src/bluetooth/bluetooth_device.cc b/src/components/transport_manager/src/bluetooth/bluetooth_device.cc index c8061a7ac5..038515170d 100644 --- a/src/components/transport_manager/src/bluetooth/bluetooth_device.cc +++ b/src/components/transport_manager/src/bluetooth/bluetooth_device.cc @@ -54,19 +54,22 @@ CREATE_LOGGERPTR_GLOBAL(logger_, "TransportManager") bool BluetoothDevice::GetRfcommChannel(const ApplicationHandle app_handle, uint8_t* channel_out) { - LOG4CXX_TRACE(logger_, "enter. app_handle: " << app_handle << ", channel_out: " << - channel_out); + LOG4CXX_TRACE(logger_, + "enter. app_handle: " << app_handle + << ", channel_out: " << channel_out); if (app_handle < 0 || app_handle > std::numeric_limits<uint8_t>::max()) { LOG4CXX_TRACE(logger_, - "exit with FALSE. Condition: app_handle < 0 || app_handle > numeric_limits::max()"); + "exit with FALSE. Condition: app_handle < 0 || app_handle > " + "numeric_limits::max()"); return false; } const uint8_t channel = static_cast<uint8_t>(app_handle); - RfcommChannelVector::const_iterator it = std::find(rfcomm_channels_.begin(), - rfcomm_channels_.end(), - channel); + RfcommChannelVector::const_iterator it = + std::find(rfcomm_channels_.begin(), rfcomm_channels_.end(), channel); if (it == rfcomm_channels_.end()) { - LOG4CXX_TRACE(logger_, "exit with FALSE. Condition: channel not found in RfcommChannelVector"); + LOG4CXX_TRACE( + logger_, + "exit with FALSE. Condition: channel not found in RfcommChannelVector"); return false; } *channel_out = channel; @@ -82,31 +85,31 @@ std::string BluetoothDevice::GetUniqueDeviceId(const bdaddr_t& device_address) { return std::string("BT-") + device_address_string; } -BluetoothDevice::BluetoothDevice(const bdaddr_t& device_address, const char* device_name, +BluetoothDevice::BluetoothDevice(const bdaddr_t& device_address, + const char* device_name, const RfcommChannelVector& rfcomm_channels) - : Device(device_name, GetUniqueDeviceId(device_address)), - address_(device_address), - rfcomm_channels_(rfcomm_channels) { -} + : Device(device_name, GetUniqueDeviceId(device_address)) + , address_(device_address) + , rfcomm_channels_(rfcomm_channels) {} bool BluetoothDevice::IsSameAs(const Device* other) const { LOG4CXX_TRACE(logger_, "enter. device: " << other); bool result = false; const BluetoothDevice* other_bluetooth_device = - dynamic_cast<const BluetoothDevice*>(other); + dynamic_cast<const BluetoothDevice*>(other); if (0 != other_bluetooth_device) { - if (0 - == memcmp(&address_, &other_bluetooth_device->address_, - sizeof(bdaddr_t))) { + if (0 == memcmp(&address_, + &other_bluetooth_device->address_, + sizeof(bdaddr_t))) { result = true; } } if (result) { - LOG4CXX_TRACE(logger_, "exit with TRUE"); + LOG4CXX_TRACE(logger_, "exit with TRUE"); } else { - LOG4CXX_TRACE(logger_, "exit with FALSE"); + LOG4CXX_TRACE(logger_, "exit with FALSE"); } return result; } diff --git a/src/components/transport_manager/src/bluetooth/bluetooth_device_scanner.cc b/src/components/transport_manager/src/bluetooth/bluetooth_device_scanner.cc index c422d895d0..85e6dc3f96 100644 --- a/src/components/transport_manager/src/bluetooth/bluetooth_device_scanner.cc +++ b/src/components/transport_manager/src/bluetooth/bluetooth_device_scanner.cc @@ -92,35 +92,49 @@ int FindPairedDevs(std::vector<bdaddr_t>* result) { result->push_back(address); } } - delete [] buffer; + delete[] buffer; buffer = new char[1028]; } pclose(pipe); LOG4CXX_TRACE(logger_, "exit with 0"); - delete [] buffer; + delete[] buffer; return 0; } } // namespace BluetoothDeviceScanner::BluetoothDeviceScanner( - TransportAdapterController* controller, bool auto_repeat_search, - int auto_repeat_pause_sec) - : controller_(controller), - thread_(NULL), - shutdown_requested_(false), - ready_(true), - device_scan_requested_(false), - device_scan_requested_lock_(), - device_scan_requested_cv_(), - auto_repeat_search_(auto_repeat_search), - auto_repeat_pause_sec_(auto_repeat_pause_sec) { - uint8_t smart_device_link_service_uuid_data[] = { 0x93, 0x6D, 0xA0, 0x1F, - 0x9A, 0xBD, 0x4D, 0x9D, 0x80, 0xC7, 0x02, 0xAF, 0x85, 0xC8, 0x22, 0xA8 - }; + TransportAdapterController* controller, + bool auto_repeat_search, + int auto_repeat_pause_sec) + : controller_(controller) + , thread_(NULL) + , shutdown_requested_(false) + , ready_(true) + , device_scan_requested_(false) + , device_scan_requested_lock_() + , device_scan_requested_cv_() + , auto_repeat_search_(auto_repeat_search) + , auto_repeat_pause_sec_(auto_repeat_pause_sec) { + uint8_t smart_device_link_service_uuid_data[] = {0x93, + 0x6D, + 0xA0, + 0x1F, + 0x9A, + 0xBD, + 0x4D, + 0x9D, + 0x80, + 0xC7, + 0x02, + 0xAF, + 0x85, + 0xC8, + 0x22, + 0xA8}; sdp_uuid128_create(&smart_device_link_service_uuid_, smart_device_link_service_uuid_data); thread_ = threads::CreateThread("BT Device Scaner", - new BluetoothDeviceScannerDelegate(this)); + new BluetoothDeviceScannerDelegate(this)); } BluetoothDeviceScanner::~BluetoothDeviceScanner() { @@ -129,7 +143,6 @@ BluetoothDeviceScanner::~BluetoothDeviceScanner() { threads::DeleteThread(thread_); } - bool BluetoothDeviceScanner::IsInitialised() const { return thread_ && thread_->is_running(); } @@ -137,9 +150,11 @@ bool BluetoothDeviceScanner::IsInitialised() const { void BluetoothDeviceScanner::UpdateTotalDeviceList() { LOG4CXX_AUTO_TRACE(logger_); DeviceVector devices; - devices.insert(devices.end(), paired_devices_with_sdl_.begin(), + devices.insert(devices.end(), + paired_devices_with_sdl_.begin(), paired_devices_with_sdl_.end()); - devices.insert(devices.end(), found_devices_with_sdl_.begin(), + devices.insert(devices.end(), + found_devices_with_sdl_.begin(), found_devices_with_sdl_.end()); controller_->SearchDeviceDone(devices); } @@ -169,12 +184,13 @@ void BluetoothDeviceScanner::DoInquiry() { } } - LOG4CXX_INFO(logger_, "Check rfcomm channel on " - << paired_devices_.size() << " paired devices."); + LOG4CXX_INFO(logger_, + "Check rfcomm channel on " << paired_devices_.size() + << " paired devices."); paired_devices_with_sdl_.clear(); - CheckSDLServiceOnDevices(paired_devices_, device_handle, - &paired_devices_with_sdl_); + CheckSDLServiceOnDevices( + paired_devices_, device_handle, &paired_devices_with_sdl_); UpdateTotalDeviceList(); LOG4CXX_INFO(logger_, "Starting hci_inquiry on device " << device_id); @@ -182,20 +198,23 @@ void BluetoothDeviceScanner::DoInquiry() { const size_t max_devices = 256u; inquiry_info* inquiry_info_list = new inquiry_info[max_devices]; - const int number_of_devices = hci_inquiry(device_id, inquiry_time, - max_devices, 0, &inquiry_info_list, - IREQ_CACHE_FLUSH); + const int number_of_devices = hci_inquiry(device_id, + inquiry_time, + max_devices, + 0, + &inquiry_info_list, + IREQ_CACHE_FLUSH); if (number_of_devices >= 0) { LOG4CXX_INFO(logger_, "hci_inquiry: found " << number_of_devices << " devices"); - std::vector < bdaddr_t > found_devices(number_of_devices); + std::vector<bdaddr_t> found_devices(number_of_devices); for (int i = 0; i < number_of_devices; ++i) { found_devices[i] = inquiry_info_list[i].bdaddr; } found_devices_with_sdl_.clear(); - CheckSDLServiceOnDevices(found_devices, device_handle, - &found_devices_with_sdl_); + CheckSDLServiceOnDevices( + found_devices, device_handle, &found_devices_with_sdl_); } UpdateTotalDeviceList(); controller_->FindNewApplicationsRequest(); @@ -210,12 +229,15 @@ void BluetoothDeviceScanner::DoInquiry() { } void BluetoothDeviceScanner::CheckSDLServiceOnDevices( - const std::vector<bdaddr_t>& bd_addresses, int device_handle, - DeviceVector* discovered_devices) { - LOG4CXX_TRACE(logger_, "enter. bd_addresses: " << &bd_addresses << ", device_handle: " << - device_handle << ", discovered_devices: " << discovered_devices); + const std::vector<bdaddr_t>& bd_addresses, + int device_handle, + DeviceVector* discovered_devices) { + LOG4CXX_TRACE(logger_, + "enter. bd_addresses: " + << &bd_addresses << ", device_handle: " << device_handle + << ", discovered_devices: " << discovered_devices); std::vector<RfcommChannelVector> sdl_rfcomm_channels = - DiscoverSmartDeviceLinkRFCOMMChannels(bd_addresses); + DiscoverSmartDeviceLinkRFCOMMChannels(bd_addresses); for (size_t i = 0; i < bd_addresses.size(); ++i) { if (sdl_rfcomm_channels[i].empty()) { @@ -224,9 +246,12 @@ void BluetoothDeviceScanner::CheckSDLServiceOnDevices( const bdaddr_t& bd_address = bd_addresses[i]; char deviceName[256]; - int hci_read_remote_name_ret = hci_read_remote_name( - device_handle, &bd_address, sizeof(deviceName) / sizeof(deviceName[0]), - deviceName, 0); + int hci_read_remote_name_ret = + hci_read_remote_name(device_handle, + &bd_address, + sizeof(deviceName) / sizeof(deviceName[0]), + deviceName, + 0); if (hci_read_remote_name_ret != 0) { LOG4CXX_ERROR_WITH_ERRNO(logger_, "hci_read_remote_name failed"); @@ -235,8 +260,8 @@ void BluetoothDeviceScanner::CheckSDLServiceOnDevices( sizeof(deviceName) / sizeof(deviceName[0])); } - Device* bluetooth_device = new BluetoothDevice(bd_address, deviceName, - sdl_rfcomm_channels[i]); + Device* bluetooth_device = + new BluetoothDevice(bd_address, deviceName, sdl_rfcomm_channels[i]); if (bluetooth_device) { LOG4CXX_INFO(logger_, "Bluetooth device created successfully"); discovered_devices->push_back(bluetooth_device); @@ -249,7 +274,7 @@ void BluetoothDeviceScanner::CheckSDLServiceOnDevices( std::vector<BluetoothDeviceScanner::RfcommChannelVector> BluetoothDeviceScanner::DiscoverSmartDeviceLinkRFCOMMChannels( - const std::vector<bdaddr_t>& device_addresses) { + const std::vector<bdaddr_t>& device_addresses) { LOG4CXX_TRACE(logger_, "enter device_addresses: " << &device_addresses); const size_t size = device_addresses.size(); std::vector<RfcommChannelVector> result(size); @@ -264,7 +289,7 @@ BluetoothDeviceScanner::DiscoverSmartDeviceLinkRFCOMMChannels( continue; } const bool final = DiscoverSmartDeviceLinkRFCOMMChannels( - device_addresses[i], &result[i]); + device_addresses[i], &result[i]); if (final) { processed[i] = true; ++processed_count; @@ -275,18 +300,21 @@ BluetoothDeviceScanner::DiscoverSmartDeviceLinkRFCOMMChannels( } sleep(attempt_timeout); } - LOG4CXX_TRACE(logger_, "exit with vector<RfcommChannelVector>: size = " << result.size()); + LOG4CXX_TRACE( + logger_, + "exit with vector<RfcommChannelVector>: size = " << result.size()); return result; } bool BluetoothDeviceScanner::DiscoverSmartDeviceLinkRFCOMMChannels( - const bdaddr_t& device_address, RfcommChannelVector* channels) { - LOG4CXX_TRACE(logger_, "enter. device_address: " << &device_address << ", channels: " << - channels); - static bdaddr_t any_address = { { 0, 0, 0, 0, 0, 0 } }; + const bdaddr_t& device_address, RfcommChannelVector* channels) { + LOG4CXX_TRACE(logger_, + "enter. device_address: " << &device_address + << ", channels: " << channels); + static bdaddr_t any_address = {{0, 0, 0, 0, 0, 0}}; sdp_session_t* sdp_session = sdp_connect( - &any_address, &device_address, SDP_RETRY_IF_BUSY | SDP_WAIT_ON_CLOSE); + &any_address, &device_address, SDP_RETRY_IF_BUSY | SDP_WAIT_ON_CLOSE); if (sdp_session == 0) { bool result = !(errno == 31 || errno == 16 || errno == 117 || errno == 114); if (result) { @@ -297,14 +325,16 @@ bool BluetoothDeviceScanner::DiscoverSmartDeviceLinkRFCOMMChannels( return result; } - sdp_list_t* search_list = sdp_list_append(0, - &smart_device_link_service_uuid_); + sdp_list_t* search_list = + sdp_list_append(0, &smart_device_link_service_uuid_); uint32_t range = 0x0000ffff; sdp_list_t* attr_list = sdp_list_append(0, &range); sdp_list_t* response_list = 0; - if (0 == sdp_service_search_attr_req(sdp_session, search_list, - SDP_ATTR_REQ_RANGE, attr_list, + if (0 == sdp_service_search_attr_req(sdp_session, + search_list, + SDP_ATTR_REQ_RANGE, + attr_list, &response_list)) { for (sdp_list_t* r = response_list; 0 != r; r = r->next) { sdp_record_t* sdp_record = static_cast<sdp_record_t*>(r->data); @@ -352,21 +382,23 @@ bool BluetoothDeviceScanner::DiscoverSmartDeviceLinkRFCOMMChannels( std::stringstream rfcomm_channels_string; for (RfcommChannelVector::const_iterator it = channels->begin(); - it != channels->end(); ++it) { + it != channels->end(); + ++it) { if (it != channels->begin()) { rfcomm_channels_string << ", "; } rfcomm_channels_string << static_cast<uint32_t>(*it); } - LOG4CXX_INFO(logger_, - "SmartDeviceLink service was discovered on device " - << BluetoothDevice::GetUniqueDeviceId(device_address) - << " at channel(s): " << rfcomm_channels_string.str().c_str()); + LOG4CXX_INFO( + logger_, + "SmartDeviceLink service was discovered on device " + << BluetoothDevice::GetUniqueDeviceId(device_address) + << " at channel(s): " << rfcomm_channels_string.str().c_str()); } else { LOG4CXX_INFO(logger_, "SmartDeviceLink service was not discovered on device " - << BluetoothDevice::GetUniqueDeviceId(device_address)); + << BluetoothDevice::GetUniqueDeviceId(device_address)); } LOG4CXX_TRACE(logger_, "exit with TRUE"); return true; @@ -410,7 +442,8 @@ void BluetoothDeviceScanner::TimedWaitForDeviceScanRequest() { sync_primitives::AutoLock auto_lock(device_scan_requested_lock_); while (!(device_scan_requested_ || shutdown_requested_)) { const sync_primitives::ConditionalVariable::WaitStatus wait_status = - device_scan_requested_cv_.WaitFor(auto_lock, auto_repeat_pause_sec_ * 1000); + device_scan_requested_cv_.WaitFor(auto_lock, + auto_repeat_pause_sec_ * 1000); if (wait_status == sync_primitives::ConditionalVariable::kTimeout) { LOG4CXX_INFO(logger_, "Bluetooth scanner timeout, performing scan"); device_scan_requested_ = true; @@ -421,7 +454,7 @@ void BluetoothDeviceScanner::TimedWaitForDeviceScanRequest() { TransportAdapter::Error BluetoothDeviceScanner::Init() { LOG4CXX_AUTO_TRACE(logger_); - if(!thread_->start()) { + if (!thread_->start()) { LOG4CXX_ERROR(logger_, "Bluetooth device scanner thread start failed"); return TransportAdapter::FAIL; } @@ -468,10 +501,9 @@ TransportAdapter::Error BluetoothDeviceScanner::Scan() { return ret; } -BluetoothDeviceScanner::BluetoothDeviceScannerDelegate::BluetoothDeviceScannerDelegate( - BluetoothDeviceScanner* scanner) - : scanner_(scanner) { -} +BluetoothDeviceScanner::BluetoothDeviceScannerDelegate:: + BluetoothDeviceScannerDelegate(BluetoothDeviceScanner* scanner) + : scanner_(scanner) {} void BluetoothDeviceScanner::BluetoothDeviceScannerDelegate::threadMain() { LOG4CXX_AUTO_TRACE(logger_); @@ -481,4 +513,3 @@ void BluetoothDeviceScanner::BluetoothDeviceScannerDelegate::threadMain() { } // namespace transport_adapter } // namespace transport_manager - diff --git a/src/components/transport_manager/src/bluetooth/bluetooth_socket_connection.cc b/src/components/transport_manager/src/bluetooth/bluetooth_socket_connection.cc index d6f9f26317..5f1eed4c5e 100644 --- a/src/components/transport_manager/src/bluetooth/bluetooth_socket_connection.cc +++ b/src/components/transport_manager/src/bluetooth/bluetooth_socket_connection.cc @@ -51,13 +51,12 @@ namespace transport_adapter { CREATE_LOGGERPTR_GLOBAL(logger_, "TransportManager") BluetoothSocketConnection::BluetoothSocketConnection( - const DeviceUID& device_uid, const ApplicationHandle& app_handle, - TransportAdapterController* controller) - : ThreadedSocketConnection(device_uid, app_handle, controller) { -} + const DeviceUID& device_uid, + const ApplicationHandle& app_handle, + TransportAdapterController* controller) + : ThreadedSocketConnection(device_uid, app_handle, controller) {} -BluetoothSocketConnection::~BluetoothSocketConnection() { -} +BluetoothSocketConnection::~BluetoothSocketConnection() {} bool BluetoothSocketConnection::Establish(ConnectError** error) { LOG4CXX_AUTO_TRACE(logger_); @@ -65,21 +64,22 @@ bool BluetoothSocketConnection::Establish(ConnectError** error) { DeviceSptr device = controller()->FindDevice(device_handle()); BluetoothDevice* bluetooth_device = - static_cast<BluetoothDevice*>(device.get()); + static_cast<BluetoothDevice*>(device.get()); uint8_t rfcomm_channel; if (!bluetooth_device->GetRfcommChannel(application_handle(), &rfcomm_channel)) { LOG4CXX_DEBUG(logger_, - "Application " << application_handle() << " not found"); + "Application " << application_handle() << " not found"); *error = new ConnectError(); LOG4CXX_TRACE(logger_, "exit with FALSE"); return false; } - struct sockaddr_rc remoteSocketAddress = { 0 }; + struct sockaddr_rc remoteSocketAddress = {0}; remoteSocketAddress.rc_family = AF_BLUETOOTH; - memcpy(&remoteSocketAddress.rc_bdaddr, &bluetooth_device->address(), + memcpy(&remoteSocketAddress.rc_bdaddr, + &bluetooth_device->address(), sizeof(bdaddr_t)); remoteSocketAddress.rc_channel = rfcomm_channel; @@ -92,13 +92,14 @@ bool BluetoothSocketConnection::Establish(ConnectError** error) { rfcomm_socket = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM); if (-1 == rfcomm_socket) { LOG4CXX_ERROR_WITH_ERRNO(logger_, - "Failed to create RFCOMM socket for device " << device_handle()); + "Failed to create RFCOMM socket for device " + << device_handle()); *error = new ConnectError(); LOG4CXX_TRACE(logger_, "exit with FALSE"); return false; } connect_status = ::connect(rfcomm_socket, - (struct sockaddr*) &remoteSocketAddress, + (struct sockaddr*)&remoteSocketAddress, sizeof(remoteSocketAddress)); if (0 == connect_status) { LOG4CXX_DEBUG(logger_, "rfcomm Connect ok"); @@ -116,9 +117,11 @@ bool BluetoothSocketConnection::Establish(ConnectError** error) { } while (--attempts > 0); LOG4CXX_INFO(logger_, "rfcomm Connect attempts finished"); if (0 != connect_status) { - LOG4CXX_DEBUG(logger_, - "Failed to Connect to remote device " << BluetoothDevice::GetUniqueDeviceId( - remoteSocketAddress.rc_bdaddr) << " for session " << this); + LOG4CXX_DEBUG( + logger_, + "Failed to Connect to remote device " + << BluetoothDevice::GetUniqueDeviceId(remoteSocketAddress.rc_bdaddr) + << " for session " << this); *error = new ConnectError(); LOG4CXX_TRACE(logger_, "exit with FALSE"); return false; diff --git a/src/components/transport_manager/src/tcp/tcp_client_listener.cc b/src/components/transport_manager/src/tcp/tcp_client_listener.cc index 28a3c389da..a075b1afb7 100644 --- a/src/components/transport_manager/src/tcp/tcp_client_listener.cc +++ b/src/components/transport_manager/src/tcp/tcp_client_listener.cc @@ -42,12 +42,12 @@ #include <sys/sysctl.h> #include <sys/socket.h> #ifdef __linux__ -# include <linux/tcp.h> +#include <linux/tcp.h> #else // __linux__ -# include <sys/time.h> -# include <netinet/in.h> -# include <netinet/tcp.h> -# include <netinet/tcp_var.h> +#include <sys/time.h> +#include <netinet/in.h> +#include <netinet/tcp.h> +#include <netinet/tcp_var.h> #endif // __linux__ #include <sstream> @@ -66,12 +66,12 @@ CREATE_LOGGERPTR_GLOBAL(logger_, "TransportManager") TcpClientListener::TcpClientListener(TransportAdapterController* controller, const uint16_t port, const bool enable_keepalive) - : port_(port), - enable_keepalive_(enable_keepalive), - controller_(controller), - thread_(0), - socket_(-1), - thread_stop_requested_(false) { + : port_(port) + , enable_keepalive_(enable_keepalive) + , controller_(controller) + , thread_(0) + , socket_(-1) + , thread_stop_requested_(false) { thread_ = threads::CreateThread("TcpClientListener", new ListeningThreadDelegate(this)); } @@ -86,7 +86,7 @@ TransportAdapter::Error TcpClientListener::Init() { return TransportAdapter::FAIL; } - sockaddr_in server_address = { 0 }; + sockaddr_in server_address = {0}; server_address.sin_family = AF_INET; server_address.sin_port = htons(port_); server_address.sin_addr.s_addr = INADDR_ANY; @@ -94,7 +94,8 @@ TransportAdapter::Error TcpClientListener::Init() { int optval = 1; setsockopt(socket_, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval)); - if (bind(socket_, reinterpret_cast<sockaddr*>(&server_address), + if (bind(socket_, + reinterpret_cast<sockaddr*>(&server_address), sizeof(server_address)) != 0) { LOG4CXX_ERROR_WITH_ERRNO(logger_, "bind() failed"); return TransportAdapter::FAIL; @@ -148,8 +149,8 @@ void SetKeepaliveOptions(const int fd) { setsockopt(fd, IPPROTO_TCP, TCP_KEEPIDLE, &keepidle, sizeof(keepidle)); setsockopt(fd, IPPROTO_TCP, TCP_KEEPCNT, &keepcnt, sizeof(keepcnt)); setsockopt(fd, IPPROTO_TCP, TCP_KEEPINTVL, &keepintvl, sizeof(keepintvl)); - setsockopt(fd, IPPROTO_TCP, TCP_USER_TIMEOUT, &user_timeout, - sizeof(user_timeout)); + setsockopt( + fd, IPPROTO_TCP, TCP_USER_TIMEOUT, &user_timeout, sizeof(user_timeout)); #elif defined(__QNX__) // __linux__ // TODO(KKolodiy): Out of order! const int kMidLength = 4; @@ -177,7 +178,7 @@ void SetKeepaliveOptions(const int fd) { tval.tv_sec = keepidle; setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &yes, sizeof(yes)); setsockopt(fd, IPPROTO_TCP, TCP_KEEPALIVE, &tval, sizeof(tval)); -#endif // __QNX__ +#endif // __QNX__ } void TcpClientListener::Loop() { @@ -185,9 +186,8 @@ void TcpClientListener::Loop() { while (!thread_stop_requested_) { sockaddr_in client_address; socklen_t client_address_size = sizeof(client_address); - const int connection_fd = accept(socket_, - (struct sockaddr*) &client_address, - &client_address_size); + const int connection_fd = accept( + socket_, (struct sockaddr*)&client_address, &client_address_size); if (thread_stop_requested_) { LOG4CXX_DEBUG(logger_, "thread_stop_requested_"); close(connection_fd); @@ -206,7 +206,8 @@ void TcpClientListener::Loop() { } char device_name[32]; - strncpy(device_name, inet_ntoa(client_address.sin_addr), + strncpy(device_name, + inet_ntoa(client_address.sin_addr), sizeof(device_name) / sizeof(device_name[0])); LOG4CXX_INFO(logger_, "Connected client " << device_name); @@ -214,16 +215,15 @@ void TcpClientListener::Loop() { SetKeepaliveOptions(connection_fd); } - TcpDevice* tcp_device = new TcpDevice(client_address.sin_addr.s_addr, - device_name); + TcpDevice* tcp_device = + new TcpDevice(client_address.sin_addr.s_addr, device_name); DeviceSptr device = controller_->AddDevice(tcp_device); tcp_device = static_cast<TcpDevice*>(device.get()); - const ApplicationHandle app_handle = tcp_device->AddIncomingApplication( - connection_fd); + const ApplicationHandle app_handle = + tcp_device->AddIncomingApplication(connection_fd); - TcpSocketConnection* connection( - new TcpSocketConnection(device->unique_device_id(), app_handle, - controller_)); + TcpSocketConnection* connection(new TcpSocketConnection( + device->unique_device_id(), app_handle, controller_)); connection->set_socket(connection_fd); const TransportAdapter::Error error = connection->Start(); if (error != TransportAdapter::OK) { @@ -237,11 +237,12 @@ void TcpClientListener::StopLoop() { thread_stop_requested_ = true; // We need to connect to the listening socket to unblock accept() call int byesocket = socket(AF_INET, SOCK_STREAM, 0); - sockaddr_in server_address = { 0 }; + sockaddr_in server_address = {0}; server_address.sin_family = AF_INET; server_address.sin_port = htons(port_); server_address.sin_addr.s_addr = INADDR_ANY; - connect(byesocket, reinterpret_cast<sockaddr*>(&server_address), + connect(byesocket, + reinterpret_cast<sockaddr*>(&server_address), sizeof(server_address)); shutdown(byesocket, SHUT_RDWR); close(byesocket); @@ -250,8 +251,9 @@ void TcpClientListener::StopLoop() { TransportAdapter::Error TcpClientListener::StartListening() { LOG4CXX_AUTO_TRACE(logger_); if (thread_->is_running()) { - LOG4CXX_WARN(logger_, - "TransportAdapter::BAD_STATE. Listener has already been started"); + LOG4CXX_WARN( + logger_, + "TransportAdapter::BAD_STATE. Listener has already been started"); return TransportAdapter::BAD_STATE; } @@ -273,8 +275,7 @@ void TcpClientListener::ListeningThreadDelegate::threadMain() { TcpClientListener::ListeningThreadDelegate::ListeningThreadDelegate( TcpClientListener* parent) - : parent_(parent) { -} + : parent_(parent) {} TransportAdapter::Error TcpClientListener::StopListening() { LOG4CXX_AUTO_TRACE(logger_); diff --git a/src/components/transport_manager/src/tcp/tcp_connection_factory.cc b/src/components/transport_manager/src/tcp/tcp_connection_factory.cc index 7c6c06ddc0..22653e8343 100644 --- a/src/components/transport_manager/src/tcp/tcp_connection_factory.cc +++ b/src/components/transport_manager/src/tcp/tcp_connection_factory.cc @@ -42,8 +42,7 @@ CREATE_LOGGERPTR_GLOBAL(logger_, "TransportManager") TcpConnectionFactory::TcpConnectionFactory( TransportAdapterController* controller) - : controller_(controller) { -} + : controller_(controller) {} TransportAdapter::Error TcpConnectionFactory::Init() { return TransportAdapter::OK; @@ -52,12 +51,12 @@ TransportAdapter::Error TcpConnectionFactory::Init() { TransportAdapter::Error TcpConnectionFactory::CreateConnection( const DeviceUID& device_uid, const ApplicationHandle& app_handle) { LOG4CXX_AUTO_TRACE(logger_); - LOG4CXX_DEBUG( - logger_, - "DeviceUID: " << &device_uid << ", ApplicationHandle: " << &app_handle); + LOG4CXX_DEBUG(logger_, + "DeviceUID: " << &device_uid + << ", ApplicationHandle: " << &app_handle); TcpServerOiginatedSocketConnection* connection( - new TcpServerOiginatedSocketConnection(device_uid, app_handle, - controller_)); + new TcpServerOiginatedSocketConnection( + device_uid, app_handle, controller_)); controller_->ConnectionCreated(connection, device_uid, app_handle); if (connection->Start() == TransportAdapter::OK) { LOG4CXX_DEBUG(logger_, "TCP connection initialised"); @@ -68,15 +67,13 @@ TransportAdapter::Error TcpConnectionFactory::CreateConnection( } } -void TcpConnectionFactory::Terminate() { -} +void TcpConnectionFactory::Terminate() {} bool TcpConnectionFactory::IsInitialised() const { return true; } -TcpConnectionFactory::~TcpConnectionFactory() { -} +TcpConnectionFactory::~TcpConnectionFactory() {} } // namespace transport_adapter } // namespace transport_manager diff --git a/src/components/transport_manager/src/tcp/tcp_device.cc b/src/components/transport_manager/src/tcp/tcp_device.cc index 3bd2a9a06a..d3f132759a 100644 --- a/src/components/transport_manager/src/tcp/tcp_device.cc +++ b/src/components/transport_manager/src/tcp/tcp_device.cc @@ -33,18 +33,16 @@ #include "utils/logger.h" #include "transport_manager/tcp/tcp_device.h" - namespace transport_manager { namespace transport_adapter { CREATE_LOGGERPTR_GLOBAL(logger_, "TransportManager") - TcpDevice::TcpDevice(const in_addr_t& in_addr, const std::string& name) - : Device(name, name), - applications_mutex_(), - in_addr_(in_addr), - last_handle_(0) { + : Device(name, name) + , applications_mutex_() + , in_addr_(in_addr) + , last_handle_(0) { LOG4CXX_AUTO_TRACE(logger_); } @@ -69,7 +67,9 @@ ApplicationList TcpDevice::GetApplicationList() const { sync_primitives::AutoLock locker(applications_mutex_); ApplicationList app_list; for (std::map<ApplicationHandle, Application>::const_iterator it = - applications_.begin(); it != applications_.end(); ++it) { + applications_.begin(); + it != applications_.end(); + ++it) { app_list.push_back(it->first); } return app_list; @@ -117,8 +117,8 @@ TcpDevice::~TcpDevice() { int TcpDevice::GetApplicationSocket(const ApplicationHandle app_handle) const { LOG4CXX_AUTO_TRACE(logger_); LOG4CXX_DEBUG(logger_, "ApplicationHandle: " << app_handle); - std::map<ApplicationHandle, Application>::const_iterator it = applications_ - .find(app_handle); + std::map<ApplicationHandle, Application>::const_iterator it = + applications_.find(app_handle); if (applications_.end() == it) { LOG4CXX_WARN(logger_, "Application was not found"); return -1; @@ -134,8 +134,8 @@ int TcpDevice::GetApplicationSocket(const ApplicationHandle app_handle) const { int TcpDevice::GetApplicationPort(const ApplicationHandle app_handle) const { LOG4CXX_AUTO_TRACE(logger_); LOG4CXX_DEBUG(logger_, "ApplicationHandle: " << app_handle); - std::map<ApplicationHandle, Application>::const_iterator it = applications_ - .find(app_handle); + std::map<ApplicationHandle, Application>::const_iterator it = + applications_.find(app_handle); if (applications_.end() == it) { LOG4CXX_WARN(logger_, "Application was not found"); return -1; diff --git a/src/components/transport_manager/src/tcp/tcp_socket_connection.cc b/src/components/transport_manager/src/tcp/tcp_socket_connection.cc index c5d0e88d84..acab9f555f 100644 --- a/src/components/transport_manager/src/tcp/tcp_socket_connection.cc +++ b/src/components/transport_manager/src/tcp/tcp_socket_connection.cc @@ -51,24 +51,21 @@ CREATE_LOGGERPTR_GLOBAL(logger_, "TransportManager") TcpSocketConnection::TcpSocketConnection(const DeviceUID& device_uid, const ApplicationHandle& app_handle, TransportAdapterController* controller) - : ThreadedSocketConnection(device_uid, app_handle, controller) { -} + : ThreadedSocketConnection(device_uid, app_handle, controller) {} -TcpSocketConnection::~TcpSocketConnection() { -} +TcpSocketConnection::~TcpSocketConnection() {} bool TcpSocketConnection::Establish(ConnectError** error) { return true; } TcpServerOiginatedSocketConnection::TcpServerOiginatedSocketConnection( - const DeviceUID& device_uid, const ApplicationHandle& app_handle, + const DeviceUID& device_uid, + const ApplicationHandle& app_handle, TransportAdapterController* controller) - : ThreadedSocketConnection(device_uid, app_handle, controller) { -} + : ThreadedSocketConnection(device_uid, app_handle, controller) {} -TcpServerOiginatedSocketConnection::~TcpServerOiginatedSocketConnection() { -} +TcpServerOiginatedSocketConnection::~TcpServerOiginatedSocketConnection() {} bool TcpServerOiginatedSocketConnection::Establish(ConnectError** error) { LOG4CXX_AUTO_TRACE(logger_); @@ -84,9 +81,9 @@ bool TcpServerOiginatedSocketConnection::Establish(ConnectError** error) { const int port = tcp_device->GetApplicationPort(application_handle()); if (-1 == port) { - LOG4CXX_ERROR( - logger_, - "Application port for " << application_handle() << " not found"); + LOG4CXX_ERROR(logger_, + "Application port for " << application_handle() + << " not found"); *error = new ConnectError(); return false; } @@ -98,17 +95,17 @@ bool TcpServerOiginatedSocketConnection::Establish(ConnectError** error) { return false; } - struct sockaddr_in addr = { 0 }; + struct sockaddr_in addr = {0}; addr.sin_family = AF_INET; addr.sin_addr.s_addr = tcp_device->in_addr(); addr.sin_port = htons(port); LOG4CXX_DEBUG(logger_, - "Connecting " << inet_ntoa(addr.sin_addr) << ":" << port); - if (::connect(socket, (struct sockaddr*) &addr, sizeof(addr)) < 0) { - LOG4CXX_ERROR( - logger_, - "Failed to connect for application " << application_handle() << ", error " << errno); + "Connecting " << inet_ntoa(addr.sin_addr) << ":" << port); + if (::connect(socket, (struct sockaddr*)&addr, sizeof(addr)) < 0) { + LOG4CXX_ERROR(logger_, + "Failed to connect for application " << application_handle() + << ", error " << errno); *error = new ConnectError(); ::close(socket); return false; diff --git a/src/components/transport_manager/src/transport_adapter/threaded_socket_connection.cc b/src/components/transport_manager/src/transport_adapter/threaded_socket_connection.cc index f520841a47..65afdf4fc0 100644 --- a/src/components/transport_manager/src/transport_adapter/threaded_socket_connection.cc +++ b/src/components/transport_manager/src/transport_adapter/threaded_socket_connection.cc @@ -49,19 +49,20 @@ namespace transport_adapter { CREATE_LOGGERPTR_GLOBAL(logger_, "TransportManager") ThreadedSocketConnection::ThreadedSocketConnection( - const DeviceUID& device_id, const ApplicationHandle& app_handle, + const DeviceUID& device_id, + const ApplicationHandle& app_handle, TransportAdapterController* controller) - : read_fd_(-1), - write_fd_(-1), - controller_(controller), - frames_to_send_(), - frames_to_send_mutex_(), - socket_(-1), - terminate_flag_(false), - unexpected_disconnect_(false), - device_uid_(device_id), - app_handle_(app_handle), - thread_(NULL) { + : read_fd_(-1) + , write_fd_(-1) + , controller_(controller) + , frames_to_send_() + , frames_to_send_mutex_() + , socket_(-1) + , terminate_flag_(false) + , unexpected_disconnect_(false) + , device_uid_(device_id) + , app_handle_(app_handle) + , thread_(NULL) { const std::string thread_name = std::string("Socket ") + device_handle(); thread_ = threads::CreateThread(thread_name.c_str(), new SocketConnectionDelegate(this)); @@ -100,8 +101,8 @@ TransportAdapter::Error ThreadedSocketConnection::Start() { LOG4CXX_ERROR(logger_, "pipe creation failed"); return TransportAdapter::FAIL; } - const int fcntl_ret = fcntl(read_fd_, F_SETFL, - fcntl(read_fd_, F_GETFL) | O_NONBLOCK); + const int fcntl_ret = + fcntl(read_fd_, F_SETFL, fcntl(read_fd_, F_GETFL) | O_NONBLOCK); if (0 != fcntl_ret) { LOG4CXX_ERROR(logger_, "fcntl failed"); return TransportAdapter::FAIL; @@ -119,8 +120,8 @@ void ThreadedSocketConnection::Finalize() { LOG4CXX_AUTO_TRACE(logger_); if (unexpected_disconnect_) { LOG4CXX_DEBUG(logger_, "unexpected_disconnect"); - controller_->ConnectionAborted(device_handle(), application_handle(), - CommunicationError()); + controller_->ConnectionAborted( + device_handle(), application_handle(), CommunicationError()); } else { LOG4CXX_DEBUG(logger_, "not unexpected_disconnect"); controller_->ConnectionFinished(device_handle(), application_handle()); @@ -179,8 +180,8 @@ void ThreadedSocketConnection::threadMain() { LOG4CXX_INFO(logger_, "removing message"); ::protocol_handler::RawMessagePtr message = frames_to_send_.front(); frames_to_send_.pop(); - controller_->DataSendFailed(device_handle(), application_handle(), - message, DataSendError()); + controller_->DataSendFailed( + device_handle(), application_handle(), message, DataSendError()); } } @@ -199,8 +200,8 @@ void ThreadedSocketConnection::Transmit() { const bool is_queue_empty_on_poll = IsFramesToSendQueueEmpty(); - poll_fds[0].events = POLLIN | POLLPRI - | (is_queue_empty_on_poll ? 0 : POLLOUT); + poll_fds[0].events = + POLLIN | POLLPRI | (is_queue_empty_on_poll ? 0 : POLLOUT); poll_fds[1].fd = read_fd_; poll_fds[1].events = POLLIN | POLLPRI; @@ -210,10 +211,10 @@ void ThreadedSocketConnection::Transmit() { Abort(); return; } - LOG4CXX_DEBUG( - logger_, - "poll is ok " << this << " revents0: " << std::hex << poll_fds[0].revents << - " revents1:" << std::hex << poll_fds[1].revents); + LOG4CXX_DEBUG(logger_, + "poll is ok " << this << " revents0: " << std::hex + << poll_fds[0].revents << " revents1:" << std::hex + << poll_fds[1].revents); // error check if (0 != (poll_fds[1].revents & (POLLERR | POLLHUP | POLLNVAL))) { LOG4CXX_ERROR(logger_, @@ -276,13 +277,13 @@ bool ThreadedSocketConnection::Receive() { bytes_read = recv(socket_, buffer, sizeof(buffer), MSG_DONTWAIT); if (bytes_read > 0) { - LOG4CXX_DEBUG( - logger_, - "Received " << bytes_read << " bytes for connection " << this); + LOG4CXX_DEBUG(logger_, + "Received " << bytes_read << " bytes for connection " + << this); ::protocol_handler::RawMessagePtr frame( new protocol_handler::RawMessage(0, 0, buffer, bytes_read)); - controller_->DataReceiveDone(device_handle(), application_handle(), - frame); + controller_->DataReceiveDone( + device_handle(), application_handle(), frame); } else if (bytes_read < 0) { if (EAGAIN != errno && EWOULDBLOCK != errno) { LOG4CXX_ERROR_WITH_ERRNO(logger_, @@ -311,8 +312,8 @@ bool ThreadedSocketConnection::Send() { while (!frames_to_send_local.empty()) { LOG4CXX_INFO(logger_, "frames_to_send is not empty"); ::protocol_handler::RawMessagePtr frame = frames_to_send_local.front(); - const ssize_t bytes_sent = ::send(socket_, frame->data() + offset, - frame->data_size() - offset, 0); + const ssize_t bytes_sent = + ::send(socket_, frame->data() + offset, frame->data_size() - offset, 0); if (bytes_sent >= 0) { LOG4CXX_DEBUG(logger_, "bytes_sent >= 0"); @@ -327,8 +328,8 @@ bool ThreadedSocketConnection::Send() { LOG4CXX_ERROR_WITH_ERRNO(logger_, "Send failed for connection " << this); frames_to_send_local.pop(); offset = 0; - controller_->DataSendFailed(device_handle(), application_handle(), frame, - DataSendError()); + controller_->DataSendFailed( + device_handle(), application_handle(), frame, DataSendError()); } } @@ -337,8 +338,7 @@ bool ThreadedSocketConnection::Send() { ThreadedSocketConnection::SocketConnectionDelegate::SocketConnectionDelegate( ThreadedSocketConnection* connection) - : connection_(connection) { -} + : connection_(connection) {} void ThreadedSocketConnection::SocketConnectionDelegate::threadMain() { LOG4CXX_AUTO_TRACE(logger_); diff --git a/src/components/transport_manager/src/transport_adapter/transport_adapter_listener_impl.cc b/src/components/transport_manager/src/transport_adapter/transport_adapter_listener_impl.cc index b11358144a..2ab19ade86 100644 --- a/src/components/transport_manager/src/transport_adapter/transport_adapter_listener_impl.cc +++ b/src/components/transport_manager/src/transport_adapter/transport_adapter_listener_impl.cc @@ -42,236 +42,334 @@ namespace transport_manager { CREATE_LOGGERPTR_GLOBAL(logger_, "TransportManager") TransportAdapterListenerImpl::TransportAdapterListenerImpl( - TransportManager* manager, TransportAdapter* adapter) : - transport_manager_(manager), transport_adapter_(adapter) { -} + TransportManager* manager, TransportAdapter* adapter) + : transport_manager_(manager), transport_adapter_(adapter) {} void TransportAdapterListenerImpl::OnSearchDeviceDone( - const TransportAdapter* adapter) { + const TransportAdapter* adapter) { LOG4CXX_TRACE(logger_, "enter. adapter* " << adapter); const TransportAdapterEvent event( - TransportAdapterListenerImpl::EventTypeEnum::ON_SEARCH_DONE, - transport_adapter_, "", 0, ::protocol_handler::RawMessagePtr(), BaseErrorPtr()); - if (transport_manager_!= NULL && transport_manager::E_SUCCESS - != transport_manager_->ReceiveEventFromDevice(event)) { + TransportAdapterListenerImpl::EventTypeEnum::ON_SEARCH_DONE, + transport_adapter_, + "", + 0, + ::protocol_handler::RawMessagePtr(), + BaseErrorPtr()); + if (transport_manager_ != NULL && + transport_manager::E_SUCCESS != + transport_manager_->ReceiveEventFromDevice(event)) { LOG4CXX_WARN(logger_, "Failed to receive event from device"); } LOG4CXX_TRACE(logger_, "exit"); } void TransportAdapterListenerImpl::OnSearchDeviceFailed( - const TransportAdapter* adapter, const SearchDeviceError& error) { - LOG4CXX_TRACE(logger_, "enter. adapter: " << adapter << ", error: " << &error); + const TransportAdapter* adapter, const SearchDeviceError& error) { + LOG4CXX_TRACE(logger_, + "enter. adapter: " << adapter << ", error: " << &error); SearchDeviceError* err = new SearchDeviceError(error); const TransportAdapterEvent event( - TransportAdapterListenerImpl::EventTypeEnum::ON_SEARCH_FAIL, - transport_adapter_, "", 0, ::protocol_handler::RawMessagePtr(), BaseErrorPtr(err)); - if (transport_manager_!= NULL && transport_manager::E_SUCCESS - != transport_manager_->ReceiveEventFromDevice(event)) { + TransportAdapterListenerImpl::EventTypeEnum::ON_SEARCH_FAIL, + transport_adapter_, + "", + 0, + ::protocol_handler::RawMessagePtr(), + BaseErrorPtr(err)); + if (transport_manager_ != NULL && + transport_manager::E_SUCCESS != + transport_manager_->ReceiveEventFromDevice(event)) { LOG4CXX_WARN(logger_, "Failed to receive event from device"); } LOG4CXX_TRACE(logger_, "exit"); } void TransportAdapterListenerImpl::OnDeviceListUpdated( - const TransportAdapter* adapter) { + const TransportAdapter* adapter) { LOG4CXX_TRACE(logger_, "enter. adapter* " << adapter); const TransportAdapterEvent event( - TransportAdapterListenerImpl::EventTypeEnum::ON_DEVICE_LIST_UPDATED, - transport_adapter_, "", 0, ::protocol_handler::RawMessagePtr(), BaseErrorPtr()); - if (transport_manager_!= NULL && transport_manager::E_SUCCESS - != transport_manager_->ReceiveEventFromDevice(event)) { + TransportAdapterListenerImpl::EventTypeEnum::ON_DEVICE_LIST_UPDATED, + transport_adapter_, + "", + 0, + ::protocol_handler::RawMessagePtr(), + BaseErrorPtr()); + if (transport_manager_ != NULL && + transport_manager::E_SUCCESS != + transport_manager_->ReceiveEventFromDevice(event)) { LOG4CXX_WARN(logger_, "Failed to receive event from device"); } LOG4CXX_TRACE(logger_, "exit"); } void TransportAdapterListenerImpl::OnFindNewApplicationsRequest( - const TransportAdapter* adapter) { + const TransportAdapter* adapter) { LOG4CXX_TRACE(logger_, "enter. adapter* " << adapter); const TransportAdapterEvent event( - TransportAdapterListenerImpl::ON_FIND_NEW_APPLICATIONS_REQUEST, - transport_adapter_, "", 0, ::protocol_handler::RawMessagePtr(), BaseErrorPtr()); - if (transport_manager_!= NULL && transport_manager::E_SUCCESS - != transport_manager_->ReceiveEventFromDevice(event)) { + TransportAdapterListenerImpl::ON_FIND_NEW_APPLICATIONS_REQUEST, + transport_adapter_, + "", + 0, + ::protocol_handler::RawMessagePtr(), + BaseErrorPtr()); + if (transport_manager_ != NULL && + transport_manager::E_SUCCESS != + transport_manager_->ReceiveEventFromDevice(event)) { LOG4CXX_WARN(logger_, "Failed to receive event from device"); } LOG4CXX_TRACE(logger_, "exit"); } void TransportAdapterListenerImpl::OnConnectDone( - const TransportAdapter* adapter, const DeviceUID& device, - const ApplicationHandle& application_id) { - LOG4CXX_TRACE(logger_, "enter adapter*: " << adapter << ", device: " << &device << - ", application_id: " << &application_id); + const TransportAdapter* adapter, + const DeviceUID& device, + const ApplicationHandle& application_id) { + LOG4CXX_TRACE(logger_, + "enter adapter*: " << adapter << ", device: " << &device + << ", application_id: " << &application_id); const TransportAdapterEvent event( - TransportAdapterListenerImpl::EventTypeEnum::ON_CONNECT_DONE, - transport_adapter_, device, application_id, ::protocol_handler::RawMessagePtr(), - BaseErrorPtr(new BaseError())); - if (transport_manager_!= NULL && transport_manager::E_SUCCESS - != transport_manager_->ReceiveEventFromDevice(event)) { + TransportAdapterListenerImpl::EventTypeEnum::ON_CONNECT_DONE, + transport_adapter_, + device, + application_id, + ::protocol_handler::RawMessagePtr(), + BaseErrorPtr(new BaseError())); + if (transport_manager_ != NULL && + transport_manager::E_SUCCESS != + transport_manager_->ReceiveEventFromDevice(event)) { LOG4CXX_WARN(logger_, "Failed to receive event from device"); } LOG4CXX_TRACE(logger_, "exit"); } void TransportAdapterListenerImpl::OnConnectFailed( - const TransportAdapter* adapter, const DeviceUID& device, - const ApplicationHandle& app_id, const ConnectError& error) { - LOG4CXX_TRACE(logger_, "enter. adapter: " << adapter << ", device: " << &device << - ", application_id: " << &app_id << ", error: " << &error); + const TransportAdapter* adapter, + const DeviceUID& device, + const ApplicationHandle& app_id, + const ConnectError& error) { + LOG4CXX_TRACE(logger_, + "enter. adapter: " << adapter << ", device: " << &device + << ", application_id: " << &app_id + << ", error: " << &error); ConnectError* err = new ConnectError(error); const TransportAdapterEvent event( - TransportAdapterListenerImpl::EventTypeEnum::ON_CONNECT_FAIL, - transport_adapter_, device, app_id, ::protocol_handler::RawMessagePtr(), BaseErrorPtr(err)); - if (transport_manager_!= NULL && transport_manager::E_SUCCESS - != transport_manager_->ReceiveEventFromDevice(event)) { + TransportAdapterListenerImpl::EventTypeEnum::ON_CONNECT_FAIL, + transport_adapter_, + device, + app_id, + ::protocol_handler::RawMessagePtr(), + BaseErrorPtr(err)); + if (transport_manager_ != NULL && + transport_manager::E_SUCCESS != + transport_manager_->ReceiveEventFromDevice(event)) { LOG4CXX_WARN(logger_, "Failed to receive event from device"); } LOG4CXX_TRACE(logger_, "exit"); } void TransportAdapterListenerImpl::OnDisconnectDone( - const TransportAdapter* adapter, const DeviceUID& device, - const ApplicationHandle& app_id) { - LOG4CXX_TRACE(logger_, "enter. adapter: " << adapter << ", device: " << &device << - ", application_id: " << &app_id); + const TransportAdapter* adapter, + const DeviceUID& device, + const ApplicationHandle& app_id) { + LOG4CXX_TRACE(logger_, + "enter. adapter: " << adapter << ", device: " << &device + << ", application_id: " << &app_id); const TransportAdapterEvent event( - TransportAdapterListenerImpl::EventTypeEnum::ON_DISCONNECT_DONE, - transport_adapter_, device, app_id, ::protocol_handler::RawMessagePtr(), - BaseErrorPtr(new BaseError())); - if (transport_manager_!= NULL && transport_manager::E_SUCCESS - != transport_manager_->ReceiveEventFromDevice(event)) { + TransportAdapterListenerImpl::EventTypeEnum::ON_DISCONNECT_DONE, + transport_adapter_, + device, + app_id, + ::protocol_handler::RawMessagePtr(), + BaseErrorPtr(new BaseError())); + if (transport_manager_ != NULL && + transport_manager::E_SUCCESS != + transport_manager_->ReceiveEventFromDevice(event)) { LOG4CXX_WARN(logger_, "Failed to receive event from device"); } LOG4CXX_TRACE(logger_, "exit"); } void TransportAdapterListenerImpl::OnDisconnectFailed( - const TransportAdapter* adapter, const DeviceUID& device, - const ApplicationHandle& app_id, const DisconnectError& error) { - LOG4CXX_TRACE(logger_, "enter. adapter: " << adapter << ", device: " << &device << - ", application_id: " << &app_id << ", error: " << &error); + const TransportAdapter* adapter, + const DeviceUID& device, + const ApplicationHandle& app_id, + const DisconnectError& error) { + LOG4CXX_TRACE(logger_, + "enter. adapter: " << adapter << ", device: " << &device + << ", application_id: " << &app_id + << ", error: " << &error); DisconnectError* err = new DisconnectError(error); const TransportAdapterEvent event( - TransportAdapterListenerImpl::EventTypeEnum::ON_DISCONNECT_FAIL, - transport_adapter_, device, app_id, ::protocol_handler::RawMessagePtr(), BaseErrorPtr(err)); - if (transport_manager_!= NULL && transport_manager::E_SUCCESS - != transport_manager_->ReceiveEventFromDevice(event)) { + TransportAdapterListenerImpl::EventTypeEnum::ON_DISCONNECT_FAIL, + transport_adapter_, + device, + app_id, + ::protocol_handler::RawMessagePtr(), + BaseErrorPtr(err)); + if (transport_manager_ != NULL && + transport_manager::E_SUCCESS != + transport_manager_->ReceiveEventFromDevice(event)) { LOG4CXX_WARN(logger_, "Failed to receive event from device"); } LOG4CXX_TRACE(logger_, "exit"); } void TransportAdapterListenerImpl::OnDisconnectDeviceDone( - const TransportAdapter* adapter, const DeviceUID& device) { -} + const TransportAdapter* adapter, const DeviceUID& device) {} void TransportAdapterListenerImpl::OnDisconnectDeviceFailed( - const TransportAdapter* adapter, const DeviceUID& device, - const DisconnectDeviceError& error) { -} + const TransportAdapter* adapter, + const DeviceUID& device, + const DisconnectDeviceError& error) {} void TransportAdapterListenerImpl::OnDataReceiveDone( - const TransportAdapter* adapter, const DeviceUID& device, - const ApplicationHandle& app_id, const ::protocol_handler::RawMessagePtr data_container) { - LOG4CXX_TRACE(logger_, "enter. adapter: " << adapter << ", device: " << &device << - ", application_id: " << &app_id << ", data_container: " << data_container); + const TransportAdapter* adapter, + const DeviceUID& device, + const ApplicationHandle& app_id, + const ::protocol_handler::RawMessagePtr data_container) { + LOG4CXX_TRACE(logger_, + "enter. adapter: " << adapter << ", device: " << &device + << ", application_id: " << &app_id + << ", data_container: " << data_container); const TransportAdapterEvent event( - TransportAdapterListenerImpl::EventTypeEnum::ON_RECEIVED_DONE, - transport_adapter_, device, app_id, data_container, - BaseErrorPtr(new BaseError())); - if (transport_manager_!= NULL && transport_manager::E_SUCCESS - != transport_manager_->ReceiveEventFromDevice(event)) { + TransportAdapterListenerImpl::EventTypeEnum::ON_RECEIVED_DONE, + transport_adapter_, + device, + app_id, + data_container, + BaseErrorPtr(new BaseError())); + if (transport_manager_ != NULL && + transport_manager::E_SUCCESS != + transport_manager_->ReceiveEventFromDevice(event)) { LOG4CXX_WARN(logger_, "Failed to receive event from device"); } LOG4CXX_TRACE(logger_, "exit"); } void TransportAdapterListenerImpl::OnDataReceiveFailed( - const TransportAdapter* adapter, const DeviceUID& device, - const ApplicationHandle& app_id, const DataReceiveError& error) { - LOG4CXX_TRACE(logger_, "enter. adapter: " << adapter << ", device: " << &device << - ", application_id: " << &app_id << ", error: " << &error); + const TransportAdapter* adapter, + const DeviceUID& device, + const ApplicationHandle& app_id, + const DataReceiveError& error) { + LOG4CXX_TRACE(logger_, + "enter. adapter: " << adapter << ", device: " << &device + << ", application_id: " << &app_id + << ", error: " << &error); DataReceiveError* err = new DataReceiveError(error); const TransportAdapterEvent event( - TransportAdapterListenerImpl::EventTypeEnum::ON_RECEIVED_FAIL, - transport_adapter_, device, app_id, ::protocol_handler::RawMessagePtr(), BaseErrorPtr(err)); - if (transport_manager_!= NULL && transport_manager::E_SUCCESS - != transport_manager_->ReceiveEventFromDevice(event)) { + TransportAdapterListenerImpl::EventTypeEnum::ON_RECEIVED_FAIL, + transport_adapter_, + device, + app_id, + ::protocol_handler::RawMessagePtr(), + BaseErrorPtr(err)); + if (transport_manager_ != NULL && + transport_manager::E_SUCCESS != + transport_manager_->ReceiveEventFromDevice(event)) { LOG4CXX_WARN(logger_, "Failed to receive event from device"); } LOG4CXX_TRACE(logger_, "exit"); } void TransportAdapterListenerImpl::OnDataSendDone( - const TransportAdapter* adapter, const DeviceUID& device, - const ApplicationHandle& app_id, const ::protocol_handler::RawMessagePtr data_container) { - LOG4CXX_TRACE(logger_, "enter. adapter: " << adapter << ", device: " << &device << - ", application_id: " << &app_id << ", data_container: " << data_container); + const TransportAdapter* adapter, + const DeviceUID& device, + const ApplicationHandle& app_id, + const ::protocol_handler::RawMessagePtr data_container) { + LOG4CXX_TRACE(logger_, + "enter. adapter: " << adapter << ", device: " << &device + << ", application_id: " << &app_id + << ", data_container: " << data_container); const TransportAdapterEvent event( - TransportAdapterListenerImpl::EventTypeEnum::ON_SEND_DONE, - transport_adapter_, device, app_id, data_container, - new BaseError()); - if (transport_manager_!= NULL && transport_manager::E_SUCCESS - != transport_manager_->ReceiveEventFromDevice(event)) { + TransportAdapterListenerImpl::EventTypeEnum::ON_SEND_DONE, + transport_adapter_, + device, + app_id, + data_container, + new BaseError()); + if (transport_manager_ != NULL && + transport_manager::E_SUCCESS != + transport_manager_->ReceiveEventFromDevice(event)) { LOG4CXX_WARN(logger_, "Failed to receive event from device"); } LOG4CXX_TRACE(logger_, "exit"); } void TransportAdapterListenerImpl::OnDataSendFailed( - const TransportAdapter* adapter, const DeviceUID& device, - const ApplicationHandle& app_id, const ::protocol_handler::RawMessagePtr data_container, - const DataSendError& error) { - LOG4CXX_TRACE(logger_, "enter. adapter: " << adapter << ", device: " << &device << - ", application_id: " << &app_id << ", data_container: " << data_container << ", error: " - << &error); + const TransportAdapter* adapter, + const DeviceUID& device, + const ApplicationHandle& app_id, + const ::protocol_handler::RawMessagePtr data_container, + const DataSendError& error) { + LOG4CXX_TRACE(logger_, + "enter. adapter: " << adapter << ", device: " << &device + << ", application_id: " << &app_id + << ", data_container: " << data_container + << ", error: " << &error); DataSendError* err = new DataSendError(error); const TransportAdapterEvent event( - TransportAdapterListenerImpl::EventTypeEnum::ON_SEND_FAIL, - transport_adapter_, device, app_id, data_container, BaseErrorPtr(err)); - if (transport_manager_!= NULL && transport_manager::E_SUCCESS - != transport_manager_->ReceiveEventFromDevice(event)) { + TransportAdapterListenerImpl::EventTypeEnum::ON_SEND_FAIL, + transport_adapter_, + device, + app_id, + data_container, + BaseErrorPtr(err)); + if (transport_manager_ != NULL && + transport_manager::E_SUCCESS != + transport_manager_->ReceiveEventFromDevice(event)) { LOG4CXX_WARN(logger_, "Failed to receive event from device"); } LOG4CXX_TRACE(logger_, "exit"); } void TransportAdapterListenerImpl::OnConnectRequested( - const TransportAdapter* adapter, const DeviceUID& device_handle, - const ApplicationHandle& app_handle) { -} + const TransportAdapter* adapter, + const DeviceUID& device_handle, + const ApplicationHandle& app_handle) {} void TransportAdapterListenerImpl::OnUnexpectedDisconnect( - const TransportAdapter* adapter, const DeviceUID& device, - const ApplicationHandle& application, const CommunicationError& error) { - LOG4CXX_TRACE(logger_, "enter. adapter: " << adapter << ", device: " << &device << - ", application: " << &application << ", error: " << &error); + const TransportAdapter* adapter, + const DeviceUID& device, + const ApplicationHandle& application, + const CommunicationError& error) { + LOG4CXX_TRACE(logger_, + "enter. adapter: " << adapter << ", device: " << &device + << ", application: " << &application + << ", error: " << &error); CommunicationError* err = new CommunicationError(error); const TransportAdapterEvent event( - TransportAdapterListenerImpl::EventTypeEnum::ON_UNEXPECTED_DISCONNECT, - transport_adapter_, device, application, ::protocol_handler::RawMessagePtr(), BaseErrorPtr(err)); - if (transport_manager_!= NULL && transport_manager::E_SUCCESS - != transport_manager_->ReceiveEventFromDevice(event)) { + TransportAdapterListenerImpl::EventTypeEnum::ON_UNEXPECTED_DISCONNECT, + transport_adapter_, + device, + application, + ::protocol_handler::RawMessagePtr(), + BaseErrorPtr(err)); + if (transport_manager_ != NULL && + transport_manager::E_SUCCESS != + transport_manager_->ReceiveEventFromDevice(event)) { LOG4CXX_WARN(logger_, "Failed to receive event from device"); } LOG4CXX_TRACE(logger_, "exit"); } void TransportAdapterListenerImpl::OnCommunicationError( - const TransportAdapter* adapter, const DeviceUID& device, - const ApplicationHandle& app_id) { - LOG4CXX_TRACE(logger_, "enter. adapter: " << adapter << ", device: " << &device << - ", application_id: " << &app_id); + const TransportAdapter* adapter, + const DeviceUID& device, + const ApplicationHandle& app_id) { + LOG4CXX_TRACE(logger_, + "enter. adapter: " << adapter << ", device: " << &device + << ", application_id: " << &app_id); const TransportAdapterEvent event( - TransportAdapterListenerImpl::EventTypeEnum::ON_COMMUNICATION_ERROR, - transport_adapter_, device, app_id, ::protocol_handler::RawMessagePtr(), - BaseErrorPtr(new BaseError())); - if (transport_manager_!= NULL && transport_manager::E_SUCCESS - != transport_manager_->ReceiveEventFromDevice(event)) { + TransportAdapterListenerImpl::EventTypeEnum::ON_COMMUNICATION_ERROR, + transport_adapter_, + device, + app_id, + ::protocol_handler::RawMessagePtr(), + BaseErrorPtr(new BaseError())); + if (transport_manager_ != NULL && + transport_manager::E_SUCCESS != + transport_manager_->ReceiveEventFromDevice(event)) { LOG4CXX_WARN(logger_, "Failed to receive event from device"); } LOG4CXX_TRACE(logger_, "exit"); } -} // namespace transport_manager +} // namespace transport_manager diff --git a/src/components/transport_manager/src/usb/libusb/platform_usb_device.cc b/src/components/transport_manager/src/usb/libusb/platform_usb_device.cc index 1ca1a54b32..33709cf0f6 100644 --- a/src/components/transport_manager/src/usb/libusb/platform_usb_device.cc +++ b/src/components/transport_manager/src/usb/libusb/platform_usb_device.cc @@ -41,27 +41,29 @@ namespace transport_adapter { CREATE_LOGGERPTR_GLOBAL(logger_, "TransportManager") - PlatformUsbDevice::PlatformUsbDevice( - uint8_t bus_number, uint8_t address, - const libusb_device_descriptor& device_descriptor, - libusb_device* device_libusb, libusb_device_handle* device_handle_libusb) - : bus_number_(bus_number), - address_(address), - vendor_id_(device_descriptor.idVendor), - product_id_(device_descriptor.idProduct), - device_descriptor_(device_descriptor), - libusb_device_handle_(device_handle_libusb), - libusb_device_(device_libusb) {} + uint8_t bus_number, + uint8_t address, + const libusb_device_descriptor& device_descriptor, + libusb_device* device_libusb, + libusb_device_handle* device_handle_libusb) + : bus_number_(bus_number) + , address_(address) + , vendor_id_(device_descriptor.idVendor) + , product_id_(device_descriptor.idProduct) + , device_descriptor_(device_descriptor) + , libusb_device_handle_(device_handle_libusb) + , libusb_device_(device_libusb) {} std::string PlatformUsbDevice::GetDescString(uint8_t index) const { LOG4CXX_TRACE(logger_, "enter. index: " << int(index)); unsigned char buf[128]; const int libusb_ret = libusb_get_string_descriptor_ascii( - libusb_device_handle_, index, buf, sizeof(buf)); + libusb_device_handle_, index, buf, sizeof(buf)); if (libusb_ret < 0) { - LOG4CXX_ERROR(logger_, "Failed to get USB string descriptor: " - << libusb_error_name(libusb_ret)); + LOG4CXX_ERROR(logger_, + "Failed to get USB string descriptor: " + << libusb_error_name(libusb_ret)); LOG4CXX_TRACE(logger_, "exit with empty string"); return ""; } diff --git a/src/components/transport_manager/src/usb/libusb/usb_connection.cc b/src/components/transport_manager/src/usb/libusb/usb_connection.cc index b8096514bc..409209b2b2 100644 --- a/src/components/transport_manager/src/usb/libusb/usb_connection.cc +++ b/src/components/transport_manager/src/usb/libusb/usb_connection.cc @@ -48,32 +48,30 @@ namespace transport_adapter { CREATE_LOGGERPTR_GLOBAL(logger_, "TransportManager") - UsbConnection::UsbConnection(const DeviceUID& device_uid, const ApplicationHandle& app_handle, TransportAdapterController* controller, const UsbHandlerSptr usb_handler, PlatformUsbDevice* device) - : device_uid_(device_uid), - app_handle_(app_handle), - controller_(controller), - usb_handler_(usb_handler), - libusb_device_(device->GetLibusbDevice()), - device_handle_(device->GetLibusbHandle()), - in_endpoint_(0), - in_endpoint_max_packet_size_(0), - out_endpoint_(0), - out_endpoint_max_packet_size_(0), - in_buffer_(NULL), - in_transfer_(NULL), - out_transfer_(0), - out_messages_(), - current_out_message_(), - bytes_sent_(0), - disconnecting_(false), - waiting_in_transfer_cancel_(false), - waiting_out_transfer_cancel_(false) { -} + : device_uid_(device_uid) + , app_handle_(app_handle) + , controller_(controller) + , usb_handler_(usb_handler) + , libusb_device_(device->GetLibusbDevice()) + , device_handle_(device->GetLibusbHandle()) + , in_endpoint_(0) + , in_endpoint_max_packet_size_(0) + , out_endpoint_(0) + , out_endpoint_max_packet_size_(0) + , in_buffer_(NULL) + , in_transfer_(NULL) + , out_transfer_(0) + , out_messages_() + , current_out_message_() + , bytes_sent_(0) + , disconnecting_(false) + , waiting_in_transfer_cancel_(false) + , waiting_out_transfer_cancel_(false) {} UsbConnection::~UsbConnection() { LOG4CXX_TRACE(logger_, "enter with this" << this); @@ -94,22 +92,30 @@ void OutTransferCallback(libusb_transfer* transfer) { bool UsbConnection::PostInTransfer() { LOG4CXX_TRACE(logger_, "enter"); - libusb_fill_bulk_transfer(in_transfer_, device_handle_, in_endpoint_, - in_buffer_, in_endpoint_max_packet_size_, - InTransferCallback, this, 0); + libusb_fill_bulk_transfer(in_transfer_, + device_handle_, + in_endpoint_, + in_buffer_, + in_endpoint_max_packet_size_, + InTransferCallback, + this, + 0); const int libusb_ret = libusb_submit_transfer(in_transfer_); if (LIBUSB_SUCCESS != libusb_ret) { - LOG4CXX_ERROR(logger_, "libusb_submit_transfer failed: " - << libusb_error_name(libusb_ret)); - LOG4CXX_TRACE(logger_, - "exit with FALSE. Condition: LIBUSB_SUCCESS != libusb_submit_transfer"); + LOG4CXX_ERROR( + logger_, + "libusb_submit_transfer failed: " << libusb_error_name(libusb_ret)); + LOG4CXX_TRACE( + logger_, + "exit with FALSE. Condition: LIBUSB_SUCCESS != libusb_submit_transfer"); return false; } LOG4CXX_TRACE(logger_, "exit with TRUE"); return true; } -std::string hex_data(const unsigned char* const buffer, const int actual_length) { +std::string hex_data(const unsigned char* const buffer, + const int actual_length) { std::ostringstream hexdata; for (int i = 0; i < actual_length; ++i) { hexdata << " " << std::hex << std::setw(2) << std::setfill('0') @@ -122,23 +128,26 @@ void UsbConnection::OnInTransfer(libusb_transfer* transfer) { LOG4CXX_TRACE(logger_, "enter with Libusb_transfer*: " << transfer); if (transfer->status == LIBUSB_TRANSFER_COMPLETED) { LOG4CXX_DEBUG(logger_, - "USB incoming transfer, size:" << transfer->actual_length - << ", data:" << hex_data(transfer->buffer, transfer->actual_length)); + "USB incoming transfer, size:" + << transfer->actual_length << ", data:" + << hex_data(transfer->buffer, transfer->actual_length)); ::protocol_handler::RawMessagePtr data(new protocol_handler::RawMessage( - 0, 0, in_buffer_, transfer->actual_length)); + 0, 0, in_buffer_, transfer->actual_length)); controller_->DataReceiveDone(device_uid_, app_handle_, data); } else { - LOG4CXX_ERROR(logger_, "USB incoming transfer failed: " - << libusb_error_name(transfer->status)); - controller_->DataReceiveFailed(device_uid_, app_handle_, - DataReceiveError()); + LOG4CXX_ERROR(logger_, + "USB incoming transfer failed: " + << libusb_error_name(transfer->status)); + controller_->DataReceiveFailed( + device_uid_, app_handle_, DataReceiveError()); } if (disconnecting_) { waiting_in_transfer_cancel_ = false; } else { if (!PostInTransfer()) { - LOG4CXX_ERROR(logger_, "USB incoming transfer failed with " - << "LIBUSB_TRANSFER_NO_DEVICE. Abort connection."); + LOG4CXX_ERROR(logger_, + "USB incoming transfer failed with " + << "LIBUSB_TRANSFER_NO_DEVICE. Abort connection."); AbortConnection(); } } @@ -166,17 +175,24 @@ bool UsbConnection::PostOutTransfer() { LOG4CXX_TRACE(logger_, "exit with FALSE. Condition: 0 == out_transfer_"); return false; } - libusb_fill_bulk_transfer(out_transfer_, device_handle_, out_endpoint_, + libusb_fill_bulk_transfer(out_transfer_, + device_handle_, + out_endpoint_, current_out_message_->data() + bytes_sent_, current_out_message_->data_size() - bytes_sent_, - OutTransferCallback, this, 0); + OutTransferCallback, + this, + 0); const int libusb_ret = libusb_submit_transfer(out_transfer_); if (LIBUSB_SUCCESS != libusb_ret) { - LOG4CXX_ERROR(logger_, "libusb_submit_transfer failed: " - << libusb_error_name(libusb_ret) << ". Abort connection."); + LOG4CXX_ERROR( + logger_, + "libusb_submit_transfer failed: " << libusb_error_name(libusb_ret) + << ". Abort connection."); AbortConnection(); - LOG4CXX_TRACE(logger_, "exit with FALSE. Condition: " - << "LIBUSB_SUCCESS != libusb_fill_bulk_transfer"); + LOG4CXX_TRACE(logger_, + "exit with FALSE. Condition: " + << "LIBUSB_SUCCESS != libusb_fill_bulk_transfer"); return false; } LOG4CXX_TRACE(logger_, "exit with TRUE"); @@ -189,16 +205,18 @@ void UsbConnection::OnOutTransfer(libusb_transfer* transfer) { if (transfer->status == LIBUSB_TRANSFER_COMPLETED) { bytes_sent_ += transfer->actual_length; if (bytes_sent_ == current_out_message_->data_size()) { - LOG4CXX_DEBUG(logger_, "USB out transfer, data sent: " - << current_out_message_.get()); + LOG4CXX_DEBUG( + logger_, + "USB out transfer, data sent: " << current_out_message_.get()); controller_->DataSendDone(device_uid_, app_handle_, current_out_message_); PopOutMessage(); } } else { - LOG4CXX_ERROR(logger_, "USB out transfer failed: " - << libusb_error_name(transfer->status)); - controller_->DataSendFailed(device_uid_, app_handle_, current_out_message_, - DataSendError()); + LOG4CXX_ERROR( + logger_, + "USB out transfer failed: " << libusb_error_name(transfer->status)); + controller_->DataSendFailed( + device_uid_, app_handle_, current_out_message_, DataSendError()); PopOutMessage(); } if (!current_out_message_.valid()) { @@ -209,11 +227,13 @@ void UsbConnection::OnOutTransfer(libusb_transfer* transfer) { LOG4CXX_TRACE(logger_, "exit"); } -TransportAdapter::Error UsbConnection::SendData(::protocol_handler::RawMessagePtr message) { +TransportAdapter::Error UsbConnection::SendData( + ::protocol_handler::RawMessagePtr message) { LOG4CXX_TRACE(logger_, "enter with RawMessagePtr: " << message.get()); if (disconnecting_) { - LOG4CXX_TRACE(logger_, "exit with TransportAdapter::BAD_STATE. Condition: " - << "disconnecting_"); + LOG4CXX_TRACE(logger_, + "exit with TransportAdapter::BAD_STATE. Condition: " + << "disconnecting_"); return TransportAdapter::BAD_STATE; } sync_primitives::AutoLock locker(out_messages_mutex_); @@ -222,9 +242,11 @@ TransportAdapter::Error UsbConnection::SendData(::protocol_handler::RawMessagePt } else { current_out_message_ = message; if (!PostOutTransfer()) { - controller_->DataSendFailed(device_uid_, app_handle_, message, - DataSendError()); - LOG4CXX_TRACE(logger_, "exit with TransportAdapter::FAIL. Condition: !PostOutTransfer()"); + controller_->DataSendFailed( + device_uid_, app_handle_, message, DataSendError()); + LOG4CXX_TRACE( + logger_, + "exit with TransportAdapter::FAIL. Condition: !PostOutTransfer()"); return TransportAdapter::FAIL; } } @@ -240,19 +262,22 @@ void UsbConnection::Finalise() { disconnecting_ = true; if (out_transfer_) { waiting_out_transfer_cancel_ = true; - if ( LIBUSB_SUCCESS != libusb_cancel_transfer(out_transfer_)) { + if (LIBUSB_SUCCESS != libusb_cancel_transfer(out_transfer_)) { waiting_out_transfer_cancel_ = false; } } if (in_transfer_) { waiting_in_transfer_cancel_ = true; - if ( LIBUSB_SUCCESS != libusb_cancel_transfer(in_transfer_)) { + if (LIBUSB_SUCCESS != libusb_cancel_transfer(in_transfer_)) { waiting_in_transfer_cancel_ = false; } } - for (std::list<protocol_handler::RawMessagePtr>::iterator it = out_messages_.begin(); - it != out_messages_.end(); it = out_messages_.erase(it)) { - controller_->DataSendFailed(device_uid_, app_handle_, *it, DataSendError()); + for (std::list<protocol_handler::RawMessagePtr>::iterator it = + out_messages_.begin(); + it != out_messages_.end(); + it = out_messages_.erase(it)) { + controller_->DataSendFailed( + device_uid_, app_handle_, *it, DataSendError()); } } while (waiting_in_transfer_cancel_ || waiting_out_transfer_cancel_) { @@ -263,7 +288,8 @@ void UsbConnection::Finalise() { void UsbConnection::AbortConnection() { LOG4CXX_TRACE(logger_, "enter"); - controller_->ConnectionAborted(device_uid_, app_handle_, CommunicationError()); + controller_->ConnectionAborted( + device_uid_, app_handle_, CommunicationError()); Disconnect(); LOG4CXX_TRACE(logger_, "exit"); } @@ -292,8 +318,8 @@ bool UsbConnection::Init() { controller_->ConnectDone(device_uid_, app_handle_); if (!PostInTransfer()) { LOG4CXX_ERROR(logger_, "PostInTransfer failed. Call ConnectionAborted"); - controller_->ConnectionAborted(device_uid_, app_handle_, - CommunicationError()); + controller_->ConnectionAborted( + device_uid_, app_handle_, CommunicationError()); LOG4CXX_TRACE(logger_, "exit with FALSE. Condition: !PostInTransfer()"); return false; } @@ -306,11 +332,13 @@ bool UsbConnection::FindEndpoints() { LOG4CXX_TRACE(logger_, "enter"); struct libusb_config_descriptor* config; const int libusb_ret = - libusb_get_active_config_descriptor(libusb_device_, &config); + libusb_get_active_config_descriptor(libusb_device_, &config); if (LIBUSB_SUCCESS != libusb_ret) { - LOG4CXX_ERROR(logger_, "libusb_get_active_config_descriptor failed: " - << libusb_error_name(libusb_ret)); - LOG4CXX_TRACE(logger_, "exit with FALSE. Condition: LIBUSB_SUCCESS != libusb_ret"); + LOG4CXX_ERROR(logger_, + "libusb_get_active_config_descriptor failed: " + << libusb_error_name(libusb_ret)); + LOG4CXX_TRACE(logger_, + "exit with FALSE. Condition: LIBUSB_SUCCESS != libusb_ret"); return false; } @@ -323,10 +351,10 @@ bool UsbConnection::FindEndpoints() { const libusb_interface_descriptor& iface_desc = interface.altsetting[i]; for (int i = 0; i < iface_desc.bNumEndpoints; ++i) { const libusb_endpoint_descriptor& endpoint_desc = - iface_desc.endpoint[i]; + iface_desc.endpoint[i]; const uint8_t endpoint_dir = - endpoint_desc.bEndpointAddress & LIBUSB_ENDPOINT_DIR_MASK; + endpoint_desc.bEndpointAddress & LIBUSB_ENDPOINT_DIR_MASK; if (find_in_endpoint && endpoint_dir == LIBUSB_ENDPOINT_IN) { in_endpoint_ = endpoint_desc.bEndpointAddress; in_endpoint_max_packet_size_ = endpoint_desc.wMaxPacketSize; diff --git a/src/components/transport_manager/src/usb/libusb/usb_handler.cc b/src/components/transport_manager/src/usb/libusb/usb_handler.cc index 776bb56c5d..c62e80d1be 100644 --- a/src/components/transport_manager/src/usb/libusb/usb_handler.cc +++ b/src/components/transport_manager/src/usb/libusb/usb_handler.cc @@ -76,15 +76,15 @@ class UsbHandler::ControlTransferSequenceState { }; UsbHandler::UsbHandler() - : shutdown_requested_(false), - thread_(NULL), - usb_device_listeners_(), - devices_(), - transfer_sequences_(), - device_handles_to_close_(), - libusb_context_(NULL), - arrived_callback_handle_(), - left_callback_handle_() { + : shutdown_requested_(false) + , thread_(NULL) + , usb_device_listeners_() + , devices_() + , transfer_sequences_() + , device_handles_to_close_() + , libusb_context_(NULL) + , arrived_callback_handle_() + , left_callback_handle_() { thread_ = threads::CreateThread("UsbHandler", new UsbHandlerDelegate(this)); } @@ -113,7 +113,8 @@ void UsbHandler::DeviceArrived(libusb_device* device_libusb) { libusb_device_descriptor descriptor; int libusb_ret = libusb_get_device_descriptor(device_libusb, &descriptor); if (LIBUSB_SUCCESS != libusb_ret) { - LOG4CXX_ERROR(logger_, "libusb_get_device_descriptor failed: " << libusb_ret); + LOG4CXX_ERROR(logger_, + "libusb_get_device_descriptor failed: " << libusb_ret); LOG4CXX_TRACE(logger_, "exit. Condition: LIBUSB_SUCCESS != libusb_ret"); return; } @@ -121,7 +122,8 @@ void UsbHandler::DeviceArrived(libusb_device* device_libusb) { libusb_device_handle* device_handle_libusb; libusb_ret = libusb_open(device_libusb, &device_handle_libusb); if (libusb_ret != LIBUSB_SUCCESS) { - LOG4CXX_ERROR(logger_, "libusb_open failed: " << libusb_error_name(libusb_ret)); + LOG4CXX_ERROR(logger_, + "libusb_open failed: " << libusb_error_name(libusb_ret)); LOG4CXX_TRACE(logger_, "exit. Condition: libusb_ret != LIBUSB_SUCCESS"); return; } @@ -129,17 +131,20 @@ void UsbHandler::DeviceArrived(libusb_device* device_libusb) { int configuration; libusb_ret = libusb_get_configuration(device_handle_libusb, &configuration); if (LIBUSB_SUCCESS != libusb_ret) { - LOG4CXX_INFO(logger_, "libusb_get_configuration failed: " << libusb_error_name( - libusb_ret)); + LOG4CXX_INFO( + logger_, + "libusb_get_configuration failed: " << libusb_error_name(libusb_ret)); LOG4CXX_TRACE(logger_, "exit. Condition: LIBUSB_SUCCESS != libusb_ret"); return; } if (configuration != kUsbConfiguration) { - libusb_ret = libusb_set_configuration(device_handle_libusb, kUsbConfiguration); + libusb_ret = + libusb_set_configuration(device_handle_libusb, kUsbConfiguration); if (LIBUSB_SUCCESS != libusb_ret) { - LOG4CXX_INFO(logger_, "libusb_set_configuration failed: " << libusb_error_name( - libusb_ret)); + LOG4CXX_INFO( + logger_, + "libusb_set_configuration failed: " << libusb_error_name(libusb_ret)); LOG4CXX_TRACE(logger_, "exit. Condition: LIBUSB_SUCCESS != libusb_ret"); return; } @@ -147,20 +152,25 @@ void UsbHandler::DeviceArrived(libusb_device* device_libusb) { libusb_ret = libusb_claim_interface(device_handle_libusb, 0); if (LIBUSB_SUCCESS != libusb_ret) { - LOG4CXX_INFO(logger_, "libusb_claim_interface failed: " << libusb_error_name(libusb_ret)); + LOG4CXX_INFO( + logger_, + "libusb_claim_interface failed: " << libusb_error_name(libusb_ret)); CloseDeviceHandle(device_handle_libusb); LOG4CXX_TRACE(logger_, "exit. Condition: LIBUSB_SUCCESS != libusb_ret"); return; } - PlatformUsbDevice* device(new PlatformUsbDevice(bus_number, device_address, - descriptor, device_libusb, - device_handle_libusb)); + PlatformUsbDevice* device(new PlatformUsbDevice(bus_number, + device_address, + descriptor, + device_libusb, + device_handle_libusb)); devices_.push_back(device); for (std::list<UsbDeviceListener*>::iterator it = - usb_device_listeners_.begin(); - it != usb_device_listeners_.end(); ++it) { + usb_device_listeners_.begin(); + it != usb_device_listeners_.end(); + ++it) { (*it)->OnDeviceArrived(device); } LOG4CXX_TRACE(logger_, "exit"); @@ -181,8 +191,9 @@ void UsbHandler::DeviceLeft(libusb_device* device_libusb) { } for (std::list<UsbDeviceListener*>::iterator it = - usb_device_listeners_.begin(); - it != usb_device_listeners_.end(); ++it) { + usb_device_listeners_.begin(); + it != usb_device_listeners_.end(); + ++it) { (*it)->OnDeviceLeft(device); } @@ -202,12 +213,13 @@ void UsbHandler::DeviceLeft(libusb_device* device_libusb) { } void UsbHandler::StartControlTransferSequence( - UsbControlTransferSequence* sequence, PlatformUsbDevice* device) { - LOG4CXX_TRACE(logger_, "enter. UsbControlTransferSequence* " << sequence << - "PlatformUsbDevice* " << device); + UsbControlTransferSequence* sequence, PlatformUsbDevice* device) { + LOG4CXX_TRACE(logger_, + "enter. UsbControlTransferSequence* " + << sequence << "PlatformUsbDevice* " << device); TransferSequences::iterator it = transfer_sequences_.insert( - transfer_sequences_.end(), - new ControlTransferSequenceState(this, sequence, device)); + transfer_sequences_.end(), + new ControlTransferSequenceState(this, sequence, device)); SubmitControlTransfer(*it); LOG4CXX_TRACE(logger_, "exit"); } @@ -216,26 +228,32 @@ void UsbHandler::CloseDeviceHandle(libusb_device_handle* device_handle) { device_handles_to_close_.push_back(device_handle); } -int ArrivedCallback(libusb_context* context, libusb_device* device, - libusb_hotplug_event event, void* data) { - LOG4CXX_TRACE(logger_, "enter. libusb device arrived (bus number " - << static_cast<int>(libusb_get_bus_number(device)) - << ", device address " - << static_cast<int>( - libusb_get_device_address(device)) << ")"); +int ArrivedCallback(libusb_context* context, + libusb_device* device, + libusb_hotplug_event event, + void* data) { + LOG4CXX_TRACE(logger_, + "enter. libusb device arrived (bus number " + << static_cast<int>(libusb_get_bus_number(device)) + << ", device address " + << static_cast<int>(libusb_get_device_address(device)) + << ")"); UsbHandler* usb_handler = static_cast<UsbHandler*>(data); usb_handler->DeviceArrived(device); LOG4CXX_TRACE(logger_, "exit with 0"); return 0; } -int LeftCallback(libusb_context* context, libusb_device* device, - libusb_hotplug_event event, void* data) { - LOG4CXX_TRACE(logger_, "enter libusb device left (bus number " - << static_cast<int>(libusb_get_bus_number(device)) - << ", device address " - << static_cast<int>( - libusb_get_device_address(device)) << ")"); +int LeftCallback(libusb_context* context, + libusb_device* device, + libusb_hotplug_event event, + void* data) { + LOG4CXX_TRACE(logger_, + "enter libusb device left (bus number " + << static_cast<int>(libusb_get_bus_number(device)) + << ", device address " + << static_cast<int>(libusb_get_device_address(device)) + << ")"); UsbHandler* usb_handler = static_cast<UsbHandler*>(data); usb_handler->DeviceLeft(device); LOG4CXX_TRACE(logger_, "exit with 0"); @@ -249,49 +267,63 @@ TransportAdapter::Error UsbHandler::Init() { if (LIBUSB_SUCCESS != libusb_ret) { LOG4CXX_ERROR(logger_, "libusb_init failed: " << libusb_ret); LOG4CXX_TRACE(logger_, - "exit with TransportAdapter::FAIL. Condition: LIBUSB_SUCCESS != libusb_ret"); + "exit with TransportAdapter::FAIL. Condition: LIBUSB_SUCCESS " + "!= libusb_ret"); return TransportAdapter::FAIL; } if (!libusb_has_capability(LIBUSB_CAP_HAS_HOTPLUG)) { LOG4CXX_ERROR(logger_, "LIBUSB_CAP_HAS_HOTPLUG not supported"); LOG4CXX_TRACE(logger_, - "exit with TransportAdapter::FAIL. Condition: !libusb_has_capability(LIBUSB_CAP_HAS_HOTPLUG)"); + "exit with TransportAdapter::FAIL. Condition: " + "!libusb_has_capability(LIBUSB_CAP_HAS_HOTPLUG)"); return TransportAdapter::FAIL; } - libusb_ret = libusb_hotplug_register_callback( - libusb_context_, LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED, - LIBUSB_HOTPLUG_ENUMERATE, LIBUSB_HOTPLUG_MATCH_ANY, - LIBUSB_HOTPLUG_MATCH_ANY, LIBUSB_HOTPLUG_MATCH_ANY, ArrivedCallback, this, - &arrived_callback_handle_); + libusb_ret = + libusb_hotplug_register_callback(libusb_context_, + LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED, + LIBUSB_HOTPLUG_ENUMERATE, + LIBUSB_HOTPLUG_MATCH_ANY, + LIBUSB_HOTPLUG_MATCH_ANY, + LIBUSB_HOTPLUG_MATCH_ANY, + ArrivedCallback, + this, + &arrived_callback_handle_); if (LIBUSB_SUCCESS != libusb_ret) { LOG4CXX_ERROR(logger_, "libusb_hotplug_register_callback failed: " << libusb_ret); LOG4CXX_TRACE(logger_, - "exit with TransportAdapter::FAIL. Condition: LIBUSB_SUCCESS != libusb_ret"); + "exit with TransportAdapter::FAIL. Condition: LIBUSB_SUCCESS " + "!= libusb_ret"); return TransportAdapter::FAIL; } - libusb_ret = libusb_hotplug_register_callback( - libusb_context_, LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT, - static_cast<libusb_hotplug_flag>(0), LIBUSB_HOTPLUG_MATCH_ANY, - LIBUSB_HOTPLUG_MATCH_ANY, LIBUSB_HOTPLUG_MATCH_ANY, LeftCallback, this, - &left_callback_handle_); + libusb_ret = + libusb_hotplug_register_callback(libusb_context_, + LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT, + static_cast<libusb_hotplug_flag>(0), + LIBUSB_HOTPLUG_MATCH_ANY, + LIBUSB_HOTPLUG_MATCH_ANY, + LIBUSB_HOTPLUG_MATCH_ANY, + LeftCallback, + this, + &left_callback_handle_); if (LIBUSB_SUCCESS != libusb_ret) { LOG4CXX_ERROR(logger_, "libusb_hotplug_register_callback failed: " << libusb_ret); LOG4CXX_TRACE(logger_, - "exit with TransportAdapter::FAIL. Condition: LIBUSB_SUCCESS != libusb_ret"); + "exit with TransportAdapter::FAIL. Condition: LIBUSB_SUCCESS " + "!= libusb_ret"); return TransportAdapter::FAIL; } if (!thread_->start()) { - LOG4CXX_ERROR(logger_, "USB device scanner thread start failed, error code"); - LOG4CXX_TRACE(logger_, - "exit with TransportAdapter::FAIL."); + LOG4CXX_ERROR(logger_, + "USB device scanner thread start failed, error code"); + LOG4CXX_TRACE(logger_, "exit with TransportAdapter::FAIL."); return TransportAdapter::FAIL; } return TransportAdapter::OK; @@ -315,7 +347,7 @@ void UsbHandler::Thread() { } for (std::list<libusb_device_handle*>::iterator it = - device_handles_to_close_.begin(); + device_handles_to_close_.begin(); it != device_handles_to_close_.end(); it = device_handles_to_close_.erase(it)) { libusb_close(*it); @@ -327,14 +359,16 @@ void UsbHandler::Thread() { void UsbTransferSequenceCallback(libusb_transfer* transfer) { LOG4CXX_TRACE(logger_, "enter. libusb_transfer* " << transfer); UsbHandler::ControlTransferSequenceState* sequence_state = - static_cast<UsbHandler::ControlTransferSequenceState*>(transfer->user_data); + static_cast<UsbHandler::ControlTransferSequenceState*>( + transfer->user_data); sequence_state->usb_handler()->ControlTransferCallback(transfer); LOG4CXX_TRACE(logger_, "exit"); } void UsbHandler::SubmitControlTransfer( - ControlTransferSequenceState* sequence_state) { - LOG4CXX_TRACE(logger_, "enter. ControlTransferSequenceState* " << sequence_state); + ControlTransferSequenceState* sequence_state) { + LOG4CXX_TRACE(logger_, + "enter. ControlTransferSequenceState* " << sequence_state); UsbControlTransfer* transfer = sequence_state->CurrentTransfer(); if (NULL == transfer) { LOG4CXX_TRACE(logger_, "exit. Condition: NULL == transfer"); @@ -366,7 +400,7 @@ void UsbHandler::SubmitControlTransfer( const uint16_t length = transfer->Length(); unsigned char* buffer = - static_cast<unsigned char*>(malloc(length + LIBUSB_CONTROL_SETUP_SIZE)); + static_cast<unsigned char*>(malloc(length + LIBUSB_CONTROL_SETUP_SIZE)); if (NULL == buffer) { LOG4CXX_ERROR(logger_, "buffer allocation failed"); libusb_free_transfer(libusb_transfer); @@ -375,22 +409,26 @@ void UsbHandler::SubmitControlTransfer( return; } - libusb_fill_control_setup(buffer, request_type | endpoint_direction, request, - value, index, length); + libusb_fill_control_setup( + buffer, request_type | endpoint_direction, request, value, index, length); if (0 != length && endpoint_direction == LIBUSB_ENDPOINT_OUT) { const char* data = static_cast<UsbControlOutTransfer*>(transfer)->Data(); memcpy(buffer + LIBUSB_CONTROL_SETUP_SIZE, data, length); } - libusb_fill_control_transfer( - libusb_transfer, sequence_state->device()->GetLibusbHandle(), buffer, - UsbTransferSequenceCallback, sequence_state, 0); + libusb_fill_control_transfer(libusb_transfer, + sequence_state->device()->GetLibusbHandle(), + buffer, + UsbTransferSequenceCallback, + sequence_state, + 0); libusb_transfer->flags = LIBUSB_TRANSFER_FREE_BUFFER; const int libusb_ret = libusb_submit_transfer(libusb_transfer); if (LIBUSB_SUCCESS != libusb_ret) { - LOG4CXX_ERROR(logger_, "libusb_submit_transfer failed: " - << libusb_error_name(libusb_ret)); + LOG4CXX_ERROR( + logger_, + "libusb_submit_transfer failed: " << libusb_error_name(libusb_ret)); libusb_free_transfer(libusb_transfer); sequence_state->Finish(); } @@ -400,7 +438,7 @@ void UsbHandler::SubmitControlTransfer( void UsbHandler::ControlTransferCallback(libusb_transfer* transfer) { LOG4CXX_TRACE(logger_, "enter. libusb_transfer* " << transfer); ControlTransferSequenceState* sequence_state = - static_cast<ControlTransferSequenceState*>(transfer->user_data); + static_cast<ControlTransferSequenceState*>(transfer->user_data); if (transfer->status == LIBUSB_TRANSFER_COMPLETED) { LOG4CXX_INFO(logger_, "USB control transfer completed"); UsbControlTransfer* current_transfer = sequence_state->CurrentTransfer(); @@ -408,8 +446,8 @@ void UsbHandler::ControlTransferCallback(libusb_transfer* transfer) { if (current_transfer && current_transfer->Direction() == UsbControlTransfer::IN) { submit_next = - static_cast<UsbControlInTransfer*>(current_transfer) - ->OnCompleted(libusb_control_transfer_get_data(transfer)); + static_cast<UsbControlInTransfer*>(current_transfer) + ->OnCompleted(libusb_control_transfer_get_data(transfer)); } sequence_state->Next(); @@ -427,13 +465,14 @@ void UsbHandler::ControlTransferCallback(libusb_transfer* transfer) { } UsbHandler::ControlTransferSequenceState::ControlTransferSequenceState( - UsbHandler* usb_handler, UsbControlTransferSequence* sequence, - PlatformUsbDevice* device) - : usb_handler_(usb_handler), - device_(device), - finished_(false), - sequence_(sequence), - current_transfer_(sequence->transfers().begin()) {} + UsbHandler* usb_handler, + UsbControlTransferSequence* sequence, + PlatformUsbDevice* device) + : usb_handler_(usb_handler) + , device_(device) + , finished_(false) + , sequence_(sequence) + , current_transfer_(sequence->transfers().begin()) {} UsbHandler::ControlTransferSequenceState::~ControlTransferSequenceState() { delete sequence_; @@ -448,16 +487,21 @@ UsbControlTransfer* UsbHandler::ControlTransferSequenceState::Next() { if (++current_transfer_ == sequence_->transfers().end()) { Finish(); LOG4CXX_TRACE(logger_, - "exit with NULL. Condition: ++current_transfer_ == sequence_->transfers().end()"); + "exit with NULL. Condition: ++current_transfer_ == " + "sequence_->transfers().end()"); return NULL; } else { - LOG4CXX_TRACE(logger_, "exit with UsbControlTransfer* " << *current_transfer_ << - ".Condition: ++current_transfer_ !== sequence_->transfers().end()"); + LOG4CXX_TRACE(logger_, + "exit with UsbControlTransfer* " + << *current_transfer_ + << ".Condition: ++current_transfer_ !== " + "sequence_->transfers().end()"); return *current_transfer_; } } -UsbControlTransfer* UsbHandler::ControlTransferSequenceState::CurrentTransfer() { +UsbControlTransfer* +UsbHandler::ControlTransferSequenceState::CurrentTransfer() { return finished_ ? NULL : *current_transfer_; } @@ -465,10 +509,8 @@ void UsbHandler::ControlTransferSequenceState::Finish() { finished_ = true; } -UsbHandler::UsbHandlerDelegate::UsbHandlerDelegate( - UsbHandler* handler) - : handler_(handler) { -} +UsbHandler::UsbHandlerDelegate::UsbHandlerDelegate(UsbHandler* handler) + : handler_(handler) {} void UsbHandler::UsbHandlerDelegate::threadMain() { LOG4CXX_AUTO_TRACE(logger_); diff --git a/src/components/transport_manager/src/usb/qnx/platform_usb_device.cc b/src/components/transport_manager/src/usb/qnx/platform_usb_device.cc index 132fe52cae..e85ab12b10 100644 --- a/src/components/transport_manager/src/usb/qnx/platform_usb_device.cc +++ b/src/components/transport_manager/src/usb/qnx/platform_usb_device.cc @@ -44,15 +44,16 @@ namespace transport_adapter { CREATE_LOGGERPTR_GLOBAL(logger_, "TransportManager") PlatformUsbDevice::PlatformUsbDevice( - usbd_device_instance_t* instance, usbd_device* device, + usbd_device_instance_t* instance, + usbd_device* device, const usbd_device_descriptor_t& device_descriptor) - : bus_number_(instance->path), - address_(instance->devno), - vendor_id_(instance->ident.vendor), - product_id_(instance->ident.device), - device_descriptor_(device_descriptor), - usbd_device_instance_(*instance), - usbd_device_(device) {} + : bus_number_(instance->path) + , address_(instance->devno) + , vendor_id_(instance->ident.vendor) + , product_id_(instance->ident.device) + , device_descriptor_(device_descriptor) + , usbd_device_instance_(*instance) + , usbd_device_(device) {} std::string PlatformUsbDevice::GetDescString(uint8_t index) const { char* str = usbd_string(usbd_device_, index, 0); diff --git a/src/components/transport_manager/src/usb/qnx/usb_connection.cc b/src/components/transport_manager/src/usb/qnx/usb_connection.cc index a3844b2e04..516a367ebc 100644 --- a/src/components/transport_manager/src/usb/qnx/usb_connection.cc +++ b/src/components/transport_manager/src/usb/qnx/usb_connection.cc @@ -52,30 +52,31 @@ UsbConnection::UsbConnection(const DeviceUID& device_uid, TransportAdapterController* controller, const UsbHandlerSptr libusb_handler, PlatformUsbDevice* device) - : device_uid_(device_uid), - app_handle_(app_handle), - controller_(controller), - libusb_handler_(libusb_handler), - usbd_device_(device->GetUsbdDevice()), - in_pipe_(NULL), - out_pipe_(NULL), - in_buffer_(NULL), - out_buffer_(NULL), - in_urb_(NULL), - out_urb_(NULL), - out_messages_(), - current_out_message_(), - out_messages_mutex_(), - bytes_sent_(0), - disconnecting_(false), - pending_in_transfer_(false), - pending_out_transfer_(false) { -} + : device_uid_(device_uid) + , app_handle_(app_handle) + , controller_(controller) + , libusb_handler_(libusb_handler) + , usbd_device_(device->GetUsbdDevice()) + , in_pipe_(NULL) + , out_pipe_(NULL) + , in_buffer_(NULL) + , out_buffer_(NULL) + , in_urb_(NULL) + , out_urb_(NULL) + , out_messages_() + , current_out_message_() + , out_messages_mutex_() + , bytes_sent_(0) + , disconnecting_(false) + , pending_in_transfer_(false) + , pending_out_transfer_(false) {} UsbConnection::~UsbConnection() { Finalise(); - if (in_urb_) usbd_free_urb(in_urb_); - if (out_urb_) usbd_free_urb(out_urb_); + if (in_urb_) + usbd_free_urb(in_urb_); + if (out_urb_) + usbd_free_urb(out_urb_); if (in_pipe_) { const int close_pipe_rc = usbd_close_pipe(in_pipe_); @@ -121,9 +122,9 @@ void UsbConnection::OnInTransfer(usbd_urb* urb) { LOG4CXX_ERROR(logger_, "Get in urb status failed: " << urb_status_rc); error = true; } - LOG4CXX_INFO(logger_, "USB in transfer, status " << std::hex << status - << ", length " << std::dec - << len); + LOG4CXX_INFO(logger_, + "USB in transfer, status " << std::hex << status << ", length " + << std::dec << len); if (!error) { switch (status) { @@ -139,18 +140,19 @@ void UsbConnection::OnInTransfer(usbd_urb* urb) { if (error) { LOG4CXX_ERROR(logger_, "USB in transfer failed"); - controller_->DataReceiveFailed(device_uid_, app_handle_, - DataReceiveError()); + controller_->DataReceiveFailed( + device_uid_, app_handle_, DataReceiveError()); } else { - ::protocol_handler::RawMessagePtr msg(new protocol_handler::RawMessage(0, 0, in_buffer_, len)); + ::protocol_handler::RawMessagePtr msg( + new protocol_handler::RawMessage(0, 0, in_buffer_, len)); controller_->DataReceiveDone(device_uid_, app_handle_, msg); } pending_in_transfer_ = false; if (!disconnecting_) { if (!PostInTransfer()) { - controller_->ConnectionAborted(device_uid_, app_handle_, - CommunicationError()); + controller_->ConnectionAborted( + device_uid_, app_handle_, CommunicationError()); Disconnect(); } } @@ -173,8 +175,8 @@ bool UsbConnection::PostOutTransfer() { usbd_setup_bulk(out_urb_, URB_DIR_OUT, out_buffer_, len); LOG4CXX_INFO(logger_, "out transfer :" << len); pending_out_transfer_ = true; - const int io_rc = usbd_io(out_urb_, out_pipe_, OutTransferCallback, this, - USBD_TIME_INFINITY); + const int io_rc = usbd_io( + out_urb_, out_pipe_, OutTransferCallback, this, USBD_TIME_INFINITY); if (EOK != io_rc) { pending_out_transfer_ = false; usbd_free(out_buffer_); @@ -194,9 +196,9 @@ void UsbConnection::OnOutTransfer(usbd_urb* urb) { LOG4CXX_ERROR(logger_, "Get out urb status failed: " << urb_status_rc); error = true; } - LOG4CXX_INFO(logger_, "USB out transfer, status " << std::hex << status - << ", length " << std::dec - << len); + LOG4CXX_INFO(logger_, + "USB out transfer, status " << std::hex << status << ", length " + << std::dec << len); if (!error) { switch (status) { @@ -214,14 +216,15 @@ void UsbConnection::OnOutTransfer(usbd_urb* urb) { if (error) { LOG4CXX_ERROR(logger_, "USB out transfer failed"); - controller_->DataSendFailed(device_uid_, app_handle_, current_out_message_, - DataSendError()); + controller_->DataSendFailed( + device_uid_, app_handle_, current_out_message_, DataSendError()); PopOutMessage(); } else { bytes_sent_ += len; if (bytes_sent_ == current_out_message_->data_size()) { - LOG4CXX_INFO(logger_, "USB out transfer, data sent: " - << current_out_message_.get()); + LOG4CXX_INFO( + logger_, + "USB out transfer, data sent: " << current_out_message_.get()); controller_->DataSendDone(device_uid_, app_handle_, current_out_message_); PopOutMessage(); } @@ -234,7 +237,8 @@ void UsbConnection::OnOutTransfer(usbd_urb* urb) { } } -TransportAdapter::Error UsbConnection::SendData(::protocol_handler::RawMessagePtr message) { +TransportAdapter::Error UsbConnection::SendData( + ::protocol_handler::RawMessagePtr message) { if (disconnecting_) { return TransportAdapter::BAD_STATE; } @@ -244,8 +248,8 @@ TransportAdapter::Error UsbConnection::SendData(::protocol_handler::RawMessagePt } else { current_out_message_ = message; if (!PostOutTransfer()) { - controller_->DataSendFailed(device_uid_, app_handle_, message, - DataSendError()); + controller_->DataSendFailed( + device_uid_, app_handle_, message, DataSendError()); } } return TransportAdapter::OK; @@ -257,11 +261,14 @@ void UsbConnection::Finalise() { disconnecting_ = true; usbd_abort_pipe(in_pipe_); usbd_abort_pipe(out_pipe_); - for (std::list<protocol_handler::RawMessagePtr>::iterator it = out_messages_.begin(); - it != out_messages_.end(); it = out_messages_.erase(it)) { + for (std::list<protocol_handler::RawMessagePtr>::iterator it = + out_messages_.begin(); + it != out_messages_.end(); + it = out_messages_.erase(it)) { controller_->DataSendFailed(device_uid_, app_handle_, *it, DataSendError()); } - while (pending_in_transfer_ || pending_out_transfer_) sched_yield(); + while (pending_in_transfer_ || pending_out_transfer_) + sched_yield(); } TransportAdapter::Error UsbConnection::Disconnect() { @@ -272,7 +279,8 @@ TransportAdapter::Error UsbConnection::Disconnect() { } bool UsbConnection::Init() { - if (!OpenEndpoints()) return false; + if (!OpenEndpoints()) + return false; in_urb_ = usbd_alloc_urb(NULL); out_urb_ = usbd_alloc_urb(NULL); @@ -290,8 +298,8 @@ bool UsbConnection::Init() { controller_->ConnectDone(device_uid_, app_handle_); if (!PostInTransfer()) { - controller_->ConnectionAborted(device_uid_, app_handle_, - CommunicationError()); + controller_->ConnectionAborted( + device_uid_, app_handle_, CommunicationError()); return true; } @@ -315,21 +323,25 @@ bool UsbConnection::OpenEndpoints() { int cfg = 0; bool found = false; while (!found) { - config_desc = - usbd_parse_descriptors(usbd_device_, device_desc_node, - USB_DESC_CONFIGURATION, cfg++, &cfg_desc_node); + config_desc = usbd_parse_descriptors(usbd_device_, + device_desc_node, + USB_DESC_CONFIGURATION, + cfg++, + &cfg_desc_node); if (config_desc == NULL) { break; } - LOG4CXX_INFO(logger_, "USB configuration " - << static_cast<int>(config_desc->configuration - .bConfigurationValue)); + LOG4CXX_INFO(logger_, + "USB configuration " << static_cast<int>( + config_desc->configuration.bConfigurationValue)); int iface = 0; usbd_desc_node* iface_desc_node; while (!found) { - iface_desc = - usbd_parse_descriptors(usbd_device_, cfg_desc_node, - USB_DESC_INTERFACE, iface++, &iface_desc_node); + iface_desc = usbd_parse_descriptors(usbd_device_, + cfg_desc_node, + USB_DESC_INTERFACE, + iface++, + &iface_desc_node); if (iface_desc == NULL) { break; } @@ -338,11 +350,11 @@ bool UsbConnection::OpenEndpoints() { #endif const uint8_t interface_subclass = iface_desc->interface.bInterfaceSubClass; - LOG4CXX_INFO(logger_, "USB interface number " - << static_cast<int>(interface_number) - << ", subclass " << std::hex - << static_cast<int>(interface_subclass) - << std::dec); + LOG4CXX_INFO(logger_, + "USB interface number " + << static_cast<int>(interface_number) << ", subclass " + << std::hex << static_cast<int>(interface_subclass) + << std::dec); if (interface_subclass != 0xff) { continue; } @@ -352,15 +364,16 @@ bool UsbConnection::OpenEndpoints() { while (true) { usbd_descriptors_t* endpoint_desc = usbd_parse_descriptors( usbd_device_, iface_desc_node, USB_DESC_ENDPOINT, endpoint++, NULL); - if (NULL == endpoint_desc) break; + if (NULL == endpoint_desc) + break; const uint8_t attributes = endpoint_desc->endpoint.bmAttributes; if ((attributes & 0x03) == USB_ATTRIB_BULK) { const uint8_t endpoint_address = endpoint_desc->endpoint.bEndpointAddress; - LOG4CXX_INFO(logger_, "Endpoint with address " - << std::hex - << static_cast<int>(endpoint_address) - << std::dec << " found"); + LOG4CXX_INFO(logger_, + "Endpoint with address " + << std::hex << static_cast<int>(endpoint_address) + << std::dec << " found"); if (endpoint_address & USB_ENDPOINT_IN) { if (NULL == in_endpoint_desc) { in_endpoint_desc = endpoint_desc; @@ -378,7 +391,8 @@ bool UsbConnection::OpenEndpoints() { } } - if (!found) return false; + if (!found) + return false; int open_pipe_rc = usbd_open_pipe(usbd_device_, in_endpoint_desc, &in_pipe_); if (EOK != open_pipe_rc) { diff --git a/src/components/transport_manager/src/usb/qnx/usb_handler.cc b/src/components/transport_manager/src/usb/qnx/usb_handler.cc index d78b6c8184..2336a05f16 100644 --- a/src/components/transport_manager/src/usb/qnx/usb_handler.cc +++ b/src/components/transport_manager/src/usb/qnx/usb_handler.cc @@ -53,10 +53,10 @@ UsbHandler* usb_handler; } UsbHandler::UsbHandler() - : usb_device_listeners_(), - devices_(), - usbd_general_connection_(NULL), - usbd_aoa_connection_(NULL) { + : usb_device_listeners_() + , devices_() + , usbd_general_connection_(NULL) + , usbd_aoa_connection_(NULL) { usb_handler = this; } @@ -65,15 +65,15 @@ UsbHandler::~UsbHandler() { if (usbd_general_connection_) { const int disconnect_rc = usbd_disconnect(usbd_general_connection_); if (EOK != disconnect_rc) { - LOG4CXX_ERROR(logger_, "usbd_disconnect failed, error code " - << disconnect_rc); + LOG4CXX_ERROR(logger_, + "usbd_disconnect failed, error code " << disconnect_rc); } } if (usbd_aoa_connection_) { const int disconnect_rc = usbd_disconnect(usbd_aoa_connection_); if (EOK != disconnect_rc) { - LOG4CXX_ERROR(logger_, "usbd_disconnect failed, error code " - << disconnect_rc); + LOG4CXX_ERROR(logger_, + "usbd_disconnect failed, error code " << disconnect_rc); } } } @@ -87,7 +87,8 @@ void UsbHandler::DeviceArrived(usbd_connection* connection, usbd_device_instance_t* instance) { for (Devices::const_iterator it = devices_.begin(); it != devices_.end(); ++it) { - if ((*it)->GetDeviceInstance() == *instance) return; + if ((*it)->GetDeviceInstance() == *instance) + return; } usbd_device* device_usbd = 0; const int attach_rc = usbd_attach(connection, instance, 0, &device_usbd); @@ -109,7 +110,8 @@ void UsbHandler::DeviceArrived(usbd_connection* connection, devices_.push_back(device); for (std::list<UsbDeviceListener*>::iterator it = usb_device_listeners_.begin(); - it != usb_device_listeners_.end(); ++it) { + it != usb_device_listeners_.end(); + ++it) { (*it)->OnDeviceArrived(device); } } @@ -128,7 +130,8 @@ void UsbHandler::DeviceLeft(usbd_device_instance_t* instance) { for (std::list<UsbDeviceListener*>::iterator it = usb_device_listeners_.begin(); - it != usb_device_listeners_.end(); ++it) { + it != usb_device_listeners_.end(); + ++it) { (*it)->OnDeviceLeft(device); } @@ -163,7 +166,8 @@ void UsbHandler::StartControlTransferSequence( for (UsbControlTransferSequence::Transfers::const_iterator it = sequence->transfers().begin(); - it != sequence->transfers().end(); ++it) { + it != sequence->transfers().end(); + ++it) { UsbControlTransfer* transfer = *it; usbd_urb* urb = usbd_alloc_urb(NULL); @@ -187,15 +191,21 @@ void UsbHandler::StartControlTransferSequence( UsbControlOutTransfer* out_transfer = static_cast<UsbControlOutTransfer*>(transfer); std::copy(out_transfer->Data(), - out_transfer->Data() + out_transfer->Length(), buf); + out_transfer->Data() + out_transfer->Length(), + buf); } else { assert(0); } assert(transfer->Type() == UsbControlTransfer::VENDOR); - usbd_setup_vendor(urb, flags, transfer->Request(), USB_TYPE_VENDOR, - transfer->Value(), transfer->Index(), buf, + usbd_setup_vendor(urb, + flags, + transfer->Request(), + USB_TYPE_VENDOR, + transfer->Value(), + transfer->Index(), + buf, transfer->Length()); const int io_rc = usbd_io(urb, usb_pipe, 0, 0, USBD_TIME_DEFAULT); @@ -211,7 +221,8 @@ void UsbHandler::StartControlTransferSequence( } usbd_free(buf); usbd_free_urb(urb); - if (!submit_next) break; + if (!submit_next) + break; } usbd_close_pipe(usb_pipe); @@ -220,56 +231,66 @@ void UsbHandler::StartControlTransferSequence( void ArrivedCallback(usbd_connection* connection, usbd_device_instance_t* instance) { - if (kAoaVid == instance->ident.vendor) return; - LOG4CXX_INFO(logger_, "USB device arrived (path " - << static_cast<int>(instance->path) << ", devno " - << static_cast<int>(instance->devno) << ", config " - << static_cast<int>(instance->config) << ", iface " - << static_cast<int>(instance->iface) << ")"); + if (kAoaVid == instance->ident.vendor) + return; + LOG4CXX_INFO(logger_, + "USB device arrived (path " + << static_cast<int>(instance->path) << ", devno " + << static_cast<int>(instance->devno) << ", config " + << static_cast<int>(instance->config) << ", iface " + << static_cast<int>(instance->iface) << ")"); usb_handler->DeviceArrived(connection, instance); } void ArrivedAoaCallback(usbd_connection* connection, usbd_device_instance_t* instance) { - if (kAoaVid != instance->ident.vendor) return; - LOG4CXX_INFO(logger_, "USB AOA device arrived (path " - << static_cast<int>(instance->path) << ", devno " - << static_cast<int>(instance->devno) << ", config " - << static_cast<int>(instance->config) << ", iface " - << static_cast<int>(instance->iface) << ")"); + if (kAoaVid != instance->ident.vendor) + return; + LOG4CXX_INFO(logger_, + "USB AOA device arrived (path " + << static_cast<int>(instance->path) << ", devno " + << static_cast<int>(instance->devno) << ", config " + << static_cast<int>(instance->config) << ", iface " + << static_cast<int>(instance->iface) << ")"); usb_handler->DeviceArrived(connection, instance); } void LeftCallback(usbd_connection* connection, usbd_device_instance_t* instance) { - if (kAoaVid == instance->ident.vendor) return; - LOG4CXX_INFO(logger_, "USB device left (path " - << static_cast<int>(instance->path) << ", devno " - << static_cast<int>(instance->devno) << ", config " - << static_cast<int>(instance->config) << ", iface " - << static_cast<int>(instance->iface) << ")"); + if (kAoaVid == instance->ident.vendor) + return; + LOG4CXX_INFO(logger_, + "USB device left (path " + << static_cast<int>(instance->path) << ", devno " + << static_cast<int>(instance->devno) << ", config " + << static_cast<int>(instance->config) << ", iface " + << static_cast<int>(instance->iface) << ")"); usb_handler->DeviceLeft(instance); } void LeftAoaCallback(usbd_connection* connection, usbd_device_instance_t* instance) { - if (kAoaVid != instance->ident.vendor) return; - LOG4CXX_INFO(logger_, "USB AOA device left (path " - << static_cast<int>(instance->path) << ", devno " - << static_cast<int>(instance->devno) << ", config " - << static_cast<int>(instance->config) << ", iface " - << static_cast<int>(instance->iface) << ")"); + if (kAoaVid != instance->ident.vendor) + return; + LOG4CXX_INFO(logger_, + "USB AOA device left (path " + << static_cast<int>(instance->path) << ", devno " + << static_cast<int>(instance->devno) << ", config " + << static_cast<int>(instance->config) << ", iface " + << static_cast<int>(instance->iface) << ")"); usb_handler->DeviceLeft(instance); } TransportAdapter::Error UsbHandler::Init() { { - usbd_device_ident_t interest = { - USBD_CONNECT_WILDCARD, USBD_CONNECT_WILDCARD, kAoaInterfaceSubclass, - USBD_CONNECT_WILDCARD, USBD_CONNECT_WILDCARD}; + usbd_device_ident_t interest = {USBD_CONNECT_WILDCARD, + USBD_CONNECT_WILDCARD, + kAoaInterfaceSubclass, + USBD_CONNECT_WILDCARD, + USBD_CONNECT_WILDCARD}; usbd_funcs_t funcs = {_USBDI_NFUNCS, ArrivedCallback, LeftCallback, NULL}; - usbd_connect_parm_t cparms = {NULL, USB_VERSION, USBD_VERSION, 0, 0, - NULL, 0, &interest, &funcs}; + usbd_connect_parm_t cparms = { + NULL, USB_VERSION, USBD_VERSION, 0, 0, NULL, 0, &interest, &funcs}; const int connect_rc = usbd_connect(&cparms, &usbd_general_connection_); @@ -279,13 +300,15 @@ TransportAdapter::Error UsbHandler::Init() { } } { - usbd_device_ident_t interest = { - kAoaVid, USBD_CONNECT_WILDCARD, USBD_CONNECT_WILDCARD, - kAoaInterfaceSubclass, USBD_CONNECT_WILDCARD}; - usbd_funcs_t funcs = {_USBDI_NFUNCS, ArrivedAoaCallback, - LeftAoaCallback, NULL}; - usbd_connect_parm_t cparms = {NULL, USB_VERSION, USBD_VERSION, 0, 0, - NULL, 0, &interest, &funcs}; + usbd_device_ident_t interest = {kAoaVid, + USBD_CONNECT_WILDCARD, + USBD_CONNECT_WILDCARD, + kAoaInterfaceSubclass, + USBD_CONNECT_WILDCARD}; + usbd_funcs_t funcs = { + _USBDI_NFUNCS, ArrivedAoaCallback, LeftAoaCallback, NULL}; + usbd_connect_parm_t cparms = { + NULL, USB_VERSION, USBD_VERSION, 0, 0, NULL, 0, &interest, &funcs}; const int connect_rc = usbd_connect(&cparms, &usbd_aoa_connection_); diff --git a/src/components/transport_manager/src/usb/usb_connection_factory.cc b/src/components/transport_manager/src/usb/usb_connection_factory.cc index 4562473536..28992d8f40 100644 --- a/src/components/transport_manager/src/usb/usb_connection_factory.cc +++ b/src/components/transport_manager/src/usb/usb_connection_factory.cc @@ -47,8 +47,8 @@ namespace transport_adapter { CREATE_LOGGERPTR_GLOBAL(logger_, "TransportManager") UsbConnectionFactory::UsbConnectionFactory( - TransportAdapterController* controller) - : controller_(controller), usb_handler_() {} + TransportAdapterController* controller) + : controller_(controller), usb_handler_() {} TransportAdapter::Error UsbConnectionFactory::Init() { return TransportAdapter::OK; @@ -59,30 +59,38 @@ void UsbConnectionFactory::SetUsbHandler(const UsbHandlerSptr usb_handler) { } TransportAdapter::Error UsbConnectionFactory::CreateConnection( - const DeviceUID& device_uid, const ApplicationHandle& app_handle) { - LOG4CXX_TRACE(logger_, "enter DeviceUID: " << &device_uid << ", ApplicationHandle: " << - &app_handle); + const DeviceUID& device_uid, const ApplicationHandle& app_handle) { + LOG4CXX_TRACE(logger_, + "enter DeviceUID: " << &device_uid + << ", ApplicationHandle: " << &app_handle); DeviceSptr device = controller_->FindDevice(device_uid); if (!device.valid()) { LOG4CXX_ERROR(logger_, "device " << device_uid << " not found"); - LOG4CXX_TRACE(logger_, - "exit with TransportAdapter::BAD_PARAM. Condition: !device.valid()"); + LOG4CXX_TRACE( + logger_, + "exit with TransportAdapter::BAD_PARAM. Condition: !device.valid()"); return TransportAdapter::BAD_PARAM; } UsbDevice* usb_device = static_cast<UsbDevice*>(device.get()); - UsbConnection* usb_connection = - new UsbConnection(device_uid, app_handle, controller_, usb_handler_, - usb_device->usb_device()); + UsbConnection* usb_connection = new UsbConnection(device_uid, + app_handle, + controller_, + usb_handler_, + usb_device->usb_device()); controller_->ConnectionCreated(usb_connection, device_uid, app_handle); if (usb_connection->Init()) { LOG4CXX_INFO(logger_, "USB connection initialised"); - LOG4CXX_TRACE(logger_, "exit with TransportAdapter::OK. Condition: USB connection initialised"); + LOG4CXX_TRACE(logger_, + "exit with TransportAdapter::OK. Condition: USB connection " + "initialised"); return TransportAdapter::OK; } else { - LOG4CXX_TRACE(logger_, "exit with TransportAdapter::FAIL. Condition: USB connection NOT initialised"); + LOG4CXX_TRACE(logger_, + "exit with TransportAdapter::FAIL. Condition: USB connection " + "NOT initialised"); return TransportAdapter::FAIL; } } diff --git a/src/components/transport_manager/src/usb/usb_device_scanner.cc b/src/components/transport_manager/src/usb/usb_device_scanner.cc index dfc9f4697c..092fd29f1a 100644 --- a/src/components/transport_manager/src/usb/usb_device_scanner.cc +++ b/src/components/transport_manager/src/usb/usb_device_scanner.cc @@ -47,8 +47,7 @@ CREATE_LOGGERPTR_GLOBAL(logger_, "TransportManager") class AoaInitSequence : public UsbControlTransferSequence { public: AoaInitSequence(); - virtual ~AoaInitSequence() { - } + virtual ~AoaInitSequence() {} private: class AoaGetProtocolRequest; @@ -88,15 +87,12 @@ void UsbDeviceScanner::OnDeviceLeft(PlatformUsbDevice* device) { } UsbDeviceScanner::UsbDeviceScanner(TransportAdapterController* controller) - : controller_(controller) { -} + : controller_(controller) {} -UsbDeviceScanner::~UsbDeviceScanner() { -} +UsbDeviceScanner::~UsbDeviceScanner() {} class AoaInitSequence::AoaGetProtocolRequest : public UsbControlInTransfer { - virtual ~AoaGetProtocolRequest() { - } + virtual ~AoaGetProtocolRequest() {} virtual RequestType Type() const { return VENDOR; } @@ -126,14 +122,10 @@ class AoaInitSequence::AoaGetProtocolRequest : public UsbControlInTransfer { class AoaInitSequence::AoaSendIdString : public UsbControlOutTransfer { public: AoaSendIdString(uint16_t index, const char* string, uint16_t length) - : index_(index), - string_(string), - length_(length) { - } + : index_(index), string_(string), length_(length) {} private: - virtual ~AoaSendIdString() { - } + virtual ~AoaSendIdString() {} virtual RequestType Type() const { return VENDOR; } @@ -158,8 +150,7 @@ class AoaInitSequence::AoaSendIdString : public UsbControlOutTransfer { }; class AoaInitSequence::AoaTurnIntoAccessoryMode : public UsbControlOutTransfer { - virtual ~AoaTurnIntoAccessoryMode() { - } + virtual ~AoaTurnIntoAccessoryMode() {} virtual RequestType Type() const { return VENDOR; } @@ -187,8 +178,7 @@ static char version[] = "1.0"; static char uri[] = "http://www.smartdevicelink.org"; static char serial_num[] = "N000000"; -AoaInitSequence::AoaInitSequence() - : UsbControlTransferSequence() { +AoaInitSequence::AoaInitSequence() : UsbControlTransferSequence() { AddTransfer(new AoaGetProtocolRequest); AddTransfer(new AoaSendIdString(0, manufacturer, sizeof(manufacturer))); AddTransfer(new AoaSendIdString(1, model_name, sizeof(model_name))); @@ -212,13 +202,13 @@ void UsbDeviceScanner::SupportedDeviceFound(PlatformUsbDevice* device) { devices_mutex_.Acquire(); devices_.push_back(device); devices_mutex_.Release(); - LOG4CXX_DEBUG( - logger_, - "USB device (bus number " << static_cast<int>(device->bus_number()) - << ", address " << static_cast<int>(device->address()) - << ") identified as: " << device->GetManufacturer() - << ", " << device->GetProductName() - << ", serial: " << device->GetSerialNumber()); + LOG4CXX_DEBUG(logger_, + "USB device (bus number " + << static_cast<int>(device->bus_number()) << ", address " + << static_cast<int>(device->address()) + << ") identified as: " << device->GetManufacturer() << ", " + << device->GetProductName() + << ", serial: " << device->GetSerialNumber()); UpdateList(); } @@ -235,9 +225,9 @@ void UsbDeviceScanner::UpdateList() { DeviceVector device_vector; devices_mutex_.Acquire(); for (Devices::const_iterator it = devices_.begin(); it != devices_.end(); - ++it) { - const std::string device_name = (*it)->GetManufacturer() + " " - + (*it)->GetProductName(); + ++it) { + const std::string device_name = + (*it)->GetManufacturer() + " " + (*it)->GetProductName(); std::ostringstream oss; oss << (*it)->GetManufacturer() << ":" << (*it)->GetProductName() << ":" << (*it)->GetSerialNumber(); @@ -251,8 +241,7 @@ void UsbDeviceScanner::UpdateList() { controller_->SearchDeviceDone(device_vector); } -void UsbDeviceScanner::Terminate() { -} +void UsbDeviceScanner::Terminate() {} bool UsbDeviceScanner::IsInitialised() const { return true; diff --git a/src/components/transport_manager/test/raw_message_matcher.cc b/src/components/transport_manager/test/raw_message_matcher.cc index 289009d0c1..130ddc96c8 100644 --- a/src/components/transport_manager/test/raw_message_matcher.cc +++ b/src/components/transport_manager/test/raw_message_matcher.cc @@ -37,25 +37,25 @@ namespace test { namespace components { namespace transport_manager { -RawMessageMatcher::RawMessageMatcher(RawMessagePtr ptr) - : ptr_(ptr) {} +RawMessageMatcher::RawMessageMatcher(RawMessagePtr ptr) : ptr_(ptr) {} bool RawMessageMatcher::MatchAndExplain(const RawMessagePtr msg, - MatchResultListener* listener) const { + MatchResultListener* listener) const { if (msg->data_size() != ptr_->data_size()) { - return ::std::equal(msg->data(), msg->data() + msg->data_size(), ptr_->data()); + return ::std::equal( + msg->data(), msg->data() + msg->data_size(), ptr_->data()); } else return false; } void RawMessageMatcher::DescribeTo(::std::ostream* os) const { - *os << "data_ is " ; + *os << "data_ is "; ::std::ostream_iterator<unsigned char> out(*os); ::std::copy(ptr_->data(), ptr_->data() + ptr_->data_size(), out); } void RawMessageMatcher::DescribeNegationTo(::std::ostream* os) const { - *os << "data_ is not " ; + *os << "data_ is not "; ::std::ostream_iterator<unsigned char> out(*os); ::std::copy(ptr_->data(), ptr_->data() + ptr_->data_size(), out); } diff --git a/src/components/transport_manager/test/tcp_device_test.cc b/src/components/transport_manager/test/tcp_device_test.cc index 961ebe6954..55fa5ac5d3 100644 --- a/src/components/transport_manager/test/tcp_device_test.cc +++ b/src/components/transport_manager/test/tcp_device_test.cc @@ -45,7 +45,9 @@ class TestDevice : public Device { public: TestDevice(const uint32_t& in_addr, const std::string& name) : Device(name, name), in_addr_(in_addr) {} - bool IsSameAs(const Device* other_device) const { return true; } + bool IsSameAs(const Device* other_device) const { + return true; + } ApplicationList GetApplicationList() const { ApplicationList app_list; return app_list; |