diff options
Diffstat (limited to 'src/components/transport_manager/include/transport_manager')
31 files changed, 479 insertions, 454 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/bluetooth/bluetooth_transport_adapter.h b/src/components/transport_manager/include/transport_manager/bluetooth/bluetooth_transport_adapter.h index 69a588fd37..82e85bac70 100644 --- a/src/components/transport_manager/include/transport_manager/bluetooth/bluetooth_transport_adapter.h +++ b/src/components/transport_manager/include/transport_manager/bluetooth/bluetooth_transport_adapter.h @@ -49,14 +49,15 @@ class BluetoothTransportAdapter : public TransportAdapterImpl { /** * @brief Constructor. */ - BluetoothTransportAdapter(); + BluetoothTransportAdapter(resumption::LastState& last_state, + const TransportManagerSettings& settings); /** * @brief Destructor. */ virtual ~BluetoothTransportAdapter(); - protected: + protected: /** * @brief Return type of device. */ diff --git a/src/components/transport_manager/include/transport_manager/tcp/dnssd_service_browser.h b/src/components/transport_manager/include/transport_manager/tcp/dnssd_service_browser.h deleted file mode 100644 index 079494d035..0000000000 --- a/src/components/transport_manager/include/transport_manager/tcp/dnssd_service_browser.h +++ /dev/null @@ -1,135 +0,0 @@ -/* - * \file dnssd_service_browser.h - * \brief DnssdServiceBrowser class header file. - * - * Copyright (c) 2013, Ford Motor Company - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with the - * distribution. - * - * Neither the name of the Ford Motor Company nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef SRC_COMPONENTS_TRANSPORT_MANAGER_INCLUDE_TRANSPORT_MANAGER_TCP_DNSSD_SERVICE_BROWSER_H_ -#define SRC_COMPONENTS_TRANSPORT_MANAGER_INCLUDE_TRANSPORT_MANAGER_TCP_DNSSD_SERVICE_BROWSER_H_ - -#include <avahi-client/client.h> -#include <avahi-client/lookup.h> -#include <avahi-common/error.h> -#include <avahi-common/thread-watch.h> - -#include <string> -#include <vector> - -#include "utils/lock.h" -#include "transport_manager/transport_adapter/device_scanner.h" -#include "transport_manager/transport_adapter/transport_adapter.h" - -namespace transport_manager { - -namespace transport_adapter { - -struct DnssdServiceRecord { - AvahiIfIndex interface; - AvahiProtocol protocol; - std::string domain_name; - std::string host_name; - std::string name; - std::string type; - uint16_t port; - uint32_t addr; -}; - -#define DNSSD_DEFAULT_SERVICE_TYPE "_ford-sdlapp._tcp" - -/** - * @brief DNS service discovery class. - */ -class DnssdServiceBrowser : public DeviceScanner { - public: - /** - * @brief Constructor. - * - * @param controller Pointer to the device adapter controller. - */ - explicit DnssdServiceBrowser(class TransportAdapterController* controller); - virtual ~DnssdServiceBrowser(); - - protected: - virtual TransportAdapter::Error Init(); - virtual TransportAdapter::Error Scan(); - virtual void Terminate(); - virtual bool IsInitialised() const; - - private: - TransportAdapter::Error CreateAvahiClientAndBrowser(); - void AddService(AvahiIfIndex interface, AvahiProtocol protocol, - const char *name, const char *type, const char *domain); - void RemoveService(AvahiIfIndex interface, AvahiProtocol protocol, - const char *name, const char *type, const char *domain); - - void OnClientConnected(); - void OnClientFailure(); - - DeviceVector PrepareDeviceVector() const; - - void ServiceResolved(const DnssdServiceRecord& service_record); - void ServiceResolveFailed(const DnssdServiceRecord& service_record); - - friend void AvahiClientCallback(AvahiClient *avahi_client, - AvahiClientState avahi_client_state, - void* data); - friend void AvahiServiceBrowserCallback( - AvahiServiceBrowser *avahi_service_browser, AvahiIfIndex interface, - AvahiProtocol protocol, AvahiBrowserEvent event, const char *name, - const char *type, const char *domain, AvahiLookupResultFlags flags, - void* data); - - friend void AvahiServiceResolverCallback( - AvahiServiceResolver* avahi_service_resolver, AvahiIfIndex interface, - AvahiProtocol protocol, AvahiResolverEvent event, const char* name, - const char* type, const char* domain, const char* host_name, - const AvahiAddress* avahi_address, uint16_t port, AvahiStringList* txt, - AvahiLookupResultFlags flags, void *data); - - TransportAdapterController* controller_; - - AvahiServiceBrowser* avahi_service_browser_; - AvahiThreadedPoll* avahi_threaded_poll_; - AvahiClient* avahi_client_; - - typedef std::vector<DnssdServiceRecord> ServiceRecords; - ServiceRecords service_records_; - - sync_primitives::Lock mutex_; - - bool initialised_; -}; - -} // namespace transport_adapter -} // namespace transport_manager - -#endif // SRC_COMPONENTS_TRANSPORT_MANAGER_INCLUDE_TRANSPORT_MANAGER_TCP_DNSSD_SERVICE_BROWSER_H_ 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 d5a24f07eb..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(); @@ -99,6 +101,20 @@ class TcpClientListener : public ClientConnectionListener { */ virtual TransportAdapter::Error StopListening(); +#ifdef BUILD_TESTS + uint16_t port() const { + return port_; + } + + int get_socket() const { + return socket_; + } + + threads::Thread* thread() const { + return thread_; + } +#endif // BUILD_TESTS + private: const uint16_t port_; const bool enable_keepalive_; @@ -115,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_device.h b/src/components/transport_manager/include/transport_manager/tcp/tcp_device.h index 45bcc405d7..981ba9f6ee 100644 --- a/src/components/transport_manager/include/transport_manager/tcp/tcp_device.h +++ b/src/components/transport_manager/include/transport_manager/tcp/tcp_device.h @@ -121,7 +121,7 @@ class TcpDevice : public Device { * * @return Application's port No. */ - int GetApplicationPort(const ApplicationHandle app_handle) const; + virtual int GetApplicationPort(const ApplicationHandle app_handle) const; /** * @brief Return address. 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/tcp/tcp_transport_adapter.h b/src/components/transport_manager/include/transport_manager/tcp/tcp_transport_adapter.h index 5c1582230a..5431b4455d 100644 --- a/src/components/transport_manager/include/transport_manager/tcp/tcp_transport_adapter.h +++ b/src/components/transport_manager/include/transport_manager/tcp/tcp_transport_adapter.h @@ -49,7 +49,9 @@ class TcpTransportAdapter : public TransportAdapterImpl { /** * @brief Constructor. */ - explicit TcpTransportAdapter(uint16_t port); + explicit TcpTransportAdapter(uint16_t port, + resumption::LastState& last_state, + const TransportManagerSettings& settings); /** * @brief Destructor. diff --git a/src/components/transport_manager/include/transport_manager/time_metric_observer.h b/src/components/transport_manager/include/transport_manager/telemetry_observer.h index ce59a9b4c4..1097feaecb 100644 --- a/src/components/transport_manager/include/transport_manager/time_metric_observer.h +++ b/src/components/transport_manager/include/transport_manager/telemetry_observer.h @@ -39,7 +39,7 @@ namespace transport_manager { -class TMMetricObserver { +class TMTelemetryObserver { public: struct MessageMetric { TimevalStruct begin; @@ -49,7 +49,7 @@ class TMMetricObserver { virtual void StartRawMsg(const protocol_handler::RawMessage* ptr) = 0; virtual void StopRawMsg(const protocol_handler::RawMessage* ptr) = 0; - virtual ~TMMetricObserver(){} + 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..0b38f82637 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. @@ -119,7 +121,7 @@ class TransportAdapterController { const ConnectError& error) = 0; /** - * @brief Make state of specified connection - FINILIZING. + * @brief Make state of specified connection - FINALISING. * * @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_impl.h b/src/components/transport_manager/include/transport_manager/transport_adapter/transport_adapter_impl.h index 5306a7af5a..3dedead540 100644 --- a/src/components/transport_manager/include/transport_manager/transport_adapter/transport_adapter_impl.h +++ b/src/components/transport_manager/include/transport_manager/transport_adapter/transport_adapter_impl.h @@ -41,13 +41,16 @@ #include "utils/lock.h" #include "utils/rwlock.h" + #include "transport_manager/transport_adapter/transport_adapter.h" #include "transport_manager/transport_adapter/transport_adapter_controller.h" #include "transport_manager/transport_adapter/connection.h" +#include "transport_manager/transport_manager_settings.h" +#include "resumption/last_state.h" -#ifdef TIME_TESTER -#include "transport_manager/time_metric_observer.h" -#endif // TIME_TESTER +#ifdef TELEMETRY_MONITOR +#include "transport_manager/telemetry_observer.h" +#endif // TELEMETRY_MONITOR namespace transport_manager { @@ -75,7 +78,9 @@ class TransportAdapterImpl : public TransportAdapter, **/ TransportAdapterImpl(DeviceScanner* device_scanner, ServerConnectionFactory* server_connection_factory, - ClientConnectionListener* client_connection_listener); + ClientConnectionListener* client_connection_listener, + resumption::LastState& last_state, + const TransportManagerSettings& settings); /** * @brief Destructor. @@ -88,7 +93,7 @@ class TransportAdapterImpl : public TransportAdapter, * @return true if initialized. * @return false if not initialized. */ - virtual bool IsInitialised() const; + bool IsInitialised() const OVERRIDE; public: /** @@ -98,20 +103,20 @@ class TransportAdapterImpl : public TransportAdapter, * * @return Error information about possible reason of failure. **/ - virtual TransportAdapter::Error Init(); + TransportAdapter::Error Init() OVERRIDE; /** * @brief Stops device adapter * Called from transport manager to stop device adapter */ - virtual void Terminate(); + void Terminate() OVERRIDE; /** * @brief Add listener to the container(list) of device adapter listeners. * * @param listener Pointer to the device adapter listener. */ - virtual void AddListener(TransportAdapterListener* listener); + void AddListener(TransportAdapterListener* listener) OVERRIDE; /** * @brief Start scanning for new devices. @@ -120,7 +125,7 @@ class TransportAdapterImpl : public TransportAdapter, * * @return Error information about possible reason of search devices failure. **/ - virtual TransportAdapter::Error SearchDevices(); + TransportAdapter::Error SearchDevices() OVERRIDE; /** * @brief Connect to the specified application discovered on device. @@ -130,15 +135,16 @@ class TransportAdapterImpl : public TransportAdapter, * * @return Error information about possible reason of failure. **/ - virtual TransportAdapter::Error Connect(const DeviceUID& device_handle, - const ApplicationHandle& app_handle); + TransportAdapter::Error Connect(const DeviceUID& device_handle, + const ApplicationHandle& app_handle) OVERRIDE; /** * @brief Connect to all applications discovered on device * @param device_handle Handle of device * @return Error information about connecting applications on device */ - virtual TransportAdapter::Error ConnectDevice(const DeviceUID& device_handle); + TransportAdapter::Error ConnectDevice( + const DeviceUID& device_handle) OVERRIDE; /** * @brief Disconnect from specified session. @@ -148,8 +154,9 @@ class TransportAdapterImpl : public TransportAdapter, * * @return Error information about possible reason of disconnecting failure. **/ - virtual TransportAdapter::Error Disconnect( - const DeviceUID& device_handle, const ApplicationHandle& app_handle); + TransportAdapter::Error Disconnect( + const DeviceUID& device_handle, + const ApplicationHandle& app_handle) OVERRIDE; /** * @brief Disconnect from all sessions on specified device. @@ -159,8 +166,8 @@ class TransportAdapterImpl : public TransportAdapter, * @return Error information about possible reason of disconnecting from *specified device failure. **/ - virtual TransportAdapter::Error DisconnectDevice( - const DeviceUID& device_handle); + TransportAdapter::Error DisconnectDevice( + const DeviceUID& device_handle) OVERRIDE; /** * @brief Send frame of data. @@ -171,51 +178,52 @@ class TransportAdapterImpl : public TransportAdapter, * * @return Error information about possible reason of sending data failure **/ - virtual TransportAdapter::Error SendData(const DeviceUID& device_handle, - const ApplicationHandle& app_handle, - const ::protocol_handler::RawMessagePtr data); + TransportAdapter::Error SendData( + const DeviceUID& device_handle, + const ApplicationHandle& app_handle, + const ::protocol_handler::RawMessagePtr data) OVERRIDE; /** * @brief Start client listener. * * @return Error information about possible reason of failure. */ - virtual TransportAdapter::Error StartClientListening(); + TransportAdapter::Error StartClientListening() OVERRIDE; /** * @brief Stop client listener. * * @return Error information about possible reason of failure. */ - virtual TransportAdapter::Error StopClientListening(); + TransportAdapter::Error StopClientListening() OVERRIDE; /** * @brief Notify that device scanner is available. * * @return True - available, false - not available. */ - virtual bool IsSearchDevicesSupported() const; + bool IsSearchDevicesSupported() const OVERRIDE; /** * @brief Notify that server connection factory is available. * * @return True - available, false - not available. */ - virtual bool IsServerOriginatedConnectSupported() const; + bool IsServerOriginatedConnectSupported() const OVERRIDE; /** * @brief Notify that listener of client connection is available. * * @return True - available, false - not available. */ - virtual bool IsClientOriginatedConnectSupported() const; + bool IsClientOriginatedConnectSupported() const OVERRIDE; /** * @brief Create container(vector) of device unique identifiers. * * @return Container(vector) of device unique identifiers. */ - virtual DeviceList GetDeviceList() const; + DeviceList GetDeviceList() const OVERRIDE; /** * @brief Get container(vector) of application unique identifiers that @@ -225,8 +233,8 @@ class TransportAdapterImpl : public TransportAdapter, * * @return Container(vector) that holds application unique identifiers. */ - virtual ApplicationList GetApplicationList(const DeviceUID& device_handle) - const; + ApplicationList GetApplicationList( + const DeviceUID& device_handle) const OVERRIDE; /** * @brief Find device in the internal container(map). @@ -235,7 +243,7 @@ class TransportAdapterImpl : public TransportAdapter, * * @return Smart pointer to device. */ - virtual DeviceSptr FindDevice(const DeviceUID& device_handle) const; + DeviceSptr FindDevice(const DeviceUID& device_handle) const OVERRIDE; /** * @brief Search for device in container of devices, if it is not there - adds @@ -243,18 +251,18 @@ class TransportAdapterImpl : public TransportAdapter, * * @param devices Container(vector) of smart pointers to devices. */ - virtual void SearchDeviceDone(const DeviceVector& devices); + void SearchDeviceDone(const DeviceVector& devices) OVERRIDE; - virtual void ApplicationListUpdated(const DeviceUID& device_handle); + void ApplicationListUpdated(const DeviceUID& device_handle) OVERRIDE; - virtual void FindNewApplicationsRequest(); + void FindNewApplicationsRequest() OVERRIDE; /** * @brief Launch OnSearchDeviceFailed event in device adapter listener. * * @param error Error class that contains details of this error situation. */ - virtual void SearchDeviceFailed(const SearchDeviceError& error); + void SearchDeviceFailed(const SearchDeviceError& error) OVERRIDE; /** * @brief Add device to the container(map), if container doesn't hold it yet. @@ -263,7 +271,7 @@ class TransportAdapterImpl : public TransportAdapter, * * @return Smart pointer to the device. */ - virtual DeviceSptr AddDevice(DeviceSptr device); + DeviceSptr AddDevice(DeviceSptr device) OVERRIDE; /** * @brief Create connection and fill its parameters. @@ -272,30 +280,30 @@ class TransportAdapterImpl : public TransportAdapter, * @param device_handle Device unique identifier. * @param app_handle Handle of application. */ - virtual void ConnectionCreated(ConnectionSPtr connection, - const DeviceUID& device_handle, - const ApplicationHandle& app_handle); + void ConnectionCreated(ConnectionSPtr connection, + const DeviceUID& device_handle, + const ApplicationHandle& app_handle) OVERRIDE; /** - * @brief Set state of specified connection - FINILIZING. + * @brief Set state of specified connection - FINALISING. * * @param device_handle Device unique identifier. * @param app_handle Handle of application. */ - virtual void ConnectionFinished(const DeviceUID& device_handle, - const ApplicationHandle& app_handle); + void ConnectionFinished(const DeviceUID& device_handle, + const ApplicationHandle& app_handle) OVERRIDE; /** - * @brief Set specified connection state to FINILIZING and launch + * @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. * @param error Error class that contains details of this error situation. */ - virtual void ConnectionAborted(const DeviceUID& device_handle, - const ApplicationHandle& app_handle, - const CommunicationError& error); + void ConnectionAborted(const DeviceUID& device_handle, + const ApplicationHandle& app_handle, + const CommunicationError& error) OVERRIDE; /** * @brief Set state of specified connection - ESTABLISHED and launch @@ -304,8 +312,8 @@ class TransportAdapterImpl : public TransportAdapter, * @param devcie_handle Device unique identifier. * @param app_handle Handle of application. */ - virtual void ConnectDone(const DeviceUID& device_handle, - const ApplicationHandle& app_handle); + void ConnectDone(const DeviceUID& device_handle, + const ApplicationHandle& app_handle) OVERRIDE; /** * @brief Delete connection from the container of connections and launch @@ -314,17 +322,26 @@ class TransportAdapterImpl : public TransportAdapter, * @param device_handle Device unique identifier. * @param app_handle Handle of application. */ - virtual void ConnectFailed(const DeviceUID& device_handle, - const ApplicationHandle& app_handle, - const ConnectError& error); + void ConnectFailed(const DeviceUID& device_handle, + const ApplicationHandle& app_handle, + const ConnectError& error) OVERRIDE; + + /** + * @brief Remove marked as FINALISING connection from accounting. + * + * @param device_handle Device unique identifier. + * @param app_handle Handle of application. + */ + void RemoveFinalizedConnection(const DeviceUID& device_handle, + const ApplicationHandle& app_handle) OVERRIDE; /** * @brief Remove specified device and all its connections * @param device_handle Device unique identifier. * @param error Error class that contains details of this error situation. */ - virtual void DeviceDisconnected(const DeviceUID& device_handle, - const DisconnectDeviceError& error); + void DeviceDisconnected(const DeviceUID& device_handle, + const DisconnectDeviceError& error) OVERRIDE; /** * @brief Delete specified connection from the container(map) of connections @@ -333,8 +350,8 @@ class TransportAdapterImpl : public TransportAdapter, * @param device_handle Device unique identifier. * @param app_handle Handle of application. */ - virtual void DisconnectDone(const DeviceUID& device_handle, - const ApplicationHandle& app_handle); + void DisconnectDone(const DeviceUID& device_handle, + const ApplicationHandle& app_handle) OVERRIDE; /** * @brief Launch OnDataReceiveDone event in the device adapter listener. @@ -343,9 +360,9 @@ class TransportAdapterImpl : public TransportAdapter, * @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); + void DataReceiveDone(const DeviceUID& device_handle, + const ApplicationHandle& app_handle, + ::protocol_handler::RawMessagePtr message) OVERRIDE; /** * @brief Launch OnDataReceiveFailed event in the device adapter listener. @@ -354,9 +371,9 @@ class TransportAdapterImpl : public TransportAdapter, * @param app_handle Handle of application. * @param error Class that contains details of this error situation. */ - virtual void DataReceiveFailed(const DeviceUID& device_handle, - const ApplicationHandle& app_handle, - const DataReceiveError& error); + void DataReceiveFailed(const DeviceUID& device_handle, + const ApplicationHandle& app_handle, + const DataReceiveError& error) OVERRIDE; /** * @brief Launch OnDataSendDone event in the device adapter listener. @@ -365,9 +382,9 @@ class TransportAdapterImpl : public TransportAdapter, * @param app_handle Handle of application. * @param message Smart pointer to raw message. */ - virtual void DataSendDone(const DeviceUID& device_handle, - const ApplicationHandle& app_handle, - ::protocol_handler::RawMessagePtr message); + void DataSendDone(const DeviceUID& device_handle, + const ApplicationHandle& app_handle, + ::protocol_handler::RawMessagePtr message) OVERRIDE; /** * @brief Launch OnDataSendFailed event in the device adapter listener. @@ -377,10 +394,10 @@ class TransportAdapterImpl : public TransportAdapter, * @param message Smart pointer to raw message. * @param error Class that contains details of this error situation. */ - virtual void DataSendFailed(const DeviceUID& device_handle, - const ApplicationHandle& app_handle, - ::protocol_handler::RawMessagePtr message, - const DataSendError& error); + void DataSendFailed(const DeviceUID& device_handle, + const ApplicationHandle& app_handle, + ::protocol_handler::RawMessagePtr message, + const DataSendError& error) OVERRIDE; /** * @brief Return name of device. @@ -389,29 +406,29 @@ class TransportAdapterImpl : public TransportAdapter, * * @return String with name. */ - virtual std::string DeviceName(const DeviceUID& device_id) const; + std::string DeviceName(const DeviceUID& device_id) const OVERRIDE; /** * @brief Allows to obtain connection type used by device. * @return connection type. */ - virtual std::string GetConnectionType() const; + std::string GetConnectionType() const OVERRIDE; -#ifdef TIME_TESTER +#ifdef TELEMETRY_MONITOR /** * @brief Setup observer for time metric. * * @param observer - pointer to observer */ - void SetTimeMetricObserver(TMMetricObserver* observer); + void SetTelemetryObserver(TMTelemetryObserver* observer); /** * @brief Return Time metric observer * * @param return pointer to Time metric observer */ - virtual TMMetricObserver* GetTimeMetricObserver(); -#endif // TIME_TESTER + TMTelemetryObserver* GetTelemetryObserver() OVERRIDE; +#endif // TELEMETRY_MONITOR protected: /** @@ -431,7 +448,6 @@ class TransportAdapterImpl : public TransportAdapter, */ virtual bool ToBeAutoConnected(DeviceSptr device) const; - /** * @brief Returns true if \a device is to be disconnected automatically when * all applications will be closed @@ -446,8 +462,13 @@ class TransportAdapterImpl : public TransportAdapter, * * @return pointer to the connection. */ - ConnectionSPtr FindEstablishedConnection(const DeviceUID& device_handle, - const ApplicationHandle& app_handle) const; + virtual ConnectionSPtr FindEstablishedConnection( + const DeviceUID& device_handle, + const ApplicationHandle& app_handle) const; + + const TransportManagerSettings& get_settings() const { + return settings_; + } private: /** @@ -489,11 +510,7 @@ class TransportAdapterImpl : public TransportAdapter, ConnectionSPtr connection; DeviceUID device_id; ApplicationHandle app_handle; - enum { - NEW, - ESTABLISHED, - FINALISING - } state; + enum { NEW, ESTABLISHED, FINALISING } state; }; /** @@ -528,12 +545,16 @@ class TransportAdapterImpl : public TransportAdapter, mutable sync_primitives::RWLock connections_lock_; protected: -#ifdef TIME_TESTER +#ifdef TELEMETRY_MONITOR /** * @brief Pointer to time metric observer */ - TMMetricObserver* metric_observer_; -#endif // TIME_TESTER + TMTelemetryObserver* metric_observer_; +#endif // TELEMETRY_MONITOR + + resumption::LastState& last_state() const { + return last_state_; + } /** * @brief Pointer to the device scanner. @@ -549,9 +570,12 @@ class TransportAdapterImpl : public TransportAdapter, * @brief Pointer to the factory of connections initiated from client. */ ClientConnectionListener* client_connection_listener_; + + resumption::LastState& last_state_; + const TransportManagerSettings& settings_; }; } // namespace transport_adapter } // namespace transport_manager -#endif // SRC_COMPONENTS_TRANSPORT_MANAGER_INCLUDE_TRANSPORT_MANAGER_TRANSPORT_ADAPTER_TRANSPORT_ADAPTER_IMPL_H_ +#endif // SRC_COMPONENTS_TRANSPORT_MANAGER_INCLUDE_TRANSPORT_MANAGER_TRANSPORT_ADAPTER_TRANSPORT_ADAPTER_IMPL_H_ 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 87d71ea56f..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 @@ -36,13 +36,12 @@ #include "transport_manager/common.h" #include "transport_manager/transport_adapter/transport_adapter_listener.h" #include "transport_manager/transport_adapter/transport_adapter.h" +#include "transport_manager/transport_manager.h" namespace transport_manager { using transport_manager::transport_adapter::TransportAdapter; -class TransportManagerImpl; - /** * @brief Implementation of TransportAdapterListener class. */ @@ -72,10 +71,10 @@ class TransportAdapterListenerImpl /** * @brief Constructor. * - * @param manager Pointer to the transport manager implementation class. + * @param manager Pointer to the transport manager class. * @param adapter Pointer to the transport adapter associated with listener. */ - TransportAdapterListenerImpl(TransportManagerImpl* manager, + TransportAdapterListenerImpl(TransportManager* manager, TransportAdapter* adapter); /** @@ -100,7 +99,7 @@ class TransportAdapterListenerImpl const SearchDeviceError& error); /** - * @brief Passes notification to TransportManagerImpl + * @brief Passes notification to TransportManager * * @param adapter Transport adapter that sent notification */ @@ -223,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 @@ -254,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 @@ -284,7 +286,7 @@ class TransportAdapterListenerImpl const ApplicationHandle& app_id); private: - TransportManagerImpl* transport_manager_impl_; + TransportManager* transport_manager_; TransportAdapter* transport_adapter_; }; } // namespace transport_manager diff --git a/src/components/transport_manager/include/transport_manager/transport_manager_default.h b/src/components/transport_manager/include/transport_manager/transport_manager_default.h index 6857a5c670..e89562a28d 100644 --- a/src/components/transport_manager/include/transport_manager/transport_manager_default.h +++ b/src/components/transport_manager/include/transport_manager/transport_manager_default.h @@ -36,35 +36,34 @@ #ifndef SRC_COMPONENTS_TRANSPORT_MANAGER_INCLUDE_TRANSPORT_MANAGER_TRANSPORT_MANAGER_DEFAULT_H_ #define SRC_COMPONENTS_TRANSPORT_MANAGER_INCLUDE_TRANSPORT_MANAGER_TRANSPORT_MANAGER_DEFAULT_H_ -#include "utils/singleton.h" - #include "transport_manager/transport_manager_impl.h" +namespace resumption { +class LastState; +} + namespace transport_manager { /** * @brief Default realization of transport_manager_impl class. */ -class TransportManagerDefault : public TransportManagerImpl, - public utils::Singleton<TransportManagerDefault> { +class TransportManagerDefault : public TransportManagerImpl { + public: + explicit TransportManagerDefault(const TransportManagerSettings& settings); /** * @brief Initialize transport manager. * * @return Code error. */ - virtual int Init(); + int Init(resumption::LastState& last_state) OVERRIDE; /** * @brief Destructor. */ virtual ~TransportManagerDefault(); - TransportManagerDefault(); - DISALLOW_COPY_AND_ASSIGN(TransportManagerDefault); - - FRIEND_BASE_SINGLETON_CLASS(TransportManagerDefault); }; } diff --git a/src/components/transport_manager/include/transport_manager/transport_manager_impl.h b/src/components/transport_manager/include/transport_manager/transport_manager_impl.h index 4c38716f3f..289df3535d 100644 --- a/src/components/transport_manager/include/transport_manager/transport_manager_impl.h +++ b/src/components/transport_manager/include/transport_manager/transport_manager_impl.h @@ -36,28 +36,46 @@ #include <queue> #include <map> #include <list> +#include <vector> +#include <utility> #include <algorithm> -#include "utils/timer_thread.h" +#include "utils/timer.h" +#include "utils/timer_task_impl.h" +#include "utils/rwlock.h" #include "transport_manager/transport_manager.h" #include "transport_manager/transport_manager_listener.h" #include "transport_manager/transport_adapter/transport_adapter_listener_impl.h" #include "protocol/common.h" -#ifdef TIME_TESTER -#include "transport_manager/time_metric_observer.h" -#endif // TIME_TESTER +#ifdef TELEMETRY_MONITOR +#include "transport_manager/telemetry_observer.h" +#include "telemetry_monitor/telemetry_observable.h" +#endif // TELEMETRY_MONITOR #include "utils/threads/message_loop_thread.h" #include "transport_manager/transport_adapter/transport_adapter_event.h" +#include "transport_manager/transport_manager_settings.h" namespace transport_manager { +typedef threads::MessageLoopThread<std::queue<protocol_handler::RawMessagePtr> > + RawMessageLoopThread; +typedef threads::MessageLoopThread<std::queue<TransportAdapterEvent> > + TransportAdapterEventLoopThread; +typedef utils::SharedPtr<timer::Timer> TimerSPtr; + /** * @brief Implementation of transport manager.s */ -class TransportManagerImpl : public TransportManager, - public threads::MessageLoopThread<std::queue<protocol_handler::RawMessagePtr> >::Handler, - public threads::MessageLoopThread<std::queue<TransportAdapterEvent> >::Handler { +class TransportManagerImpl + : public TransportManager, + public RawMessageLoopThread::Handler, + public TransportAdapterEventLoopThread::Handler +#ifdef TELEMETRY_MONITOR + , + public telemetry_monitor::TelemetryObservable<TMTelemetryObserver> +#endif // TELEMETRY_MONITOR + { public: struct Connection { ConnectionUID id; @@ -69,24 +87,29 @@ class TransportManagerImpl : public TransportManager, /** * @brief Structure that contains internal connection parameters */ - struct ConnectionInternal: public Connection { + struct ConnectionInternal : public Connection { TransportManagerImpl* transport_manager; TransportAdapter* transport_adapter; - typedef timer::TimerThread<ConnectionInternal> TimerInternal; - typedef utils::SharedPtr<TimerInternal> TimerInternalSharedPointer; - TimerInternalSharedPointer timer; - bool shutDown; + TimerSPtr timer; + bool shutdown_; DeviceHandle device_handle_; int messages_count; ConnectionInternal(TransportManagerImpl* transport_manager, TransportAdapter* transport_adapter, - const ConnectionUID& id, const DeviceUID& dev_id, + const ConnectionUID id, + const DeviceUID& dev_id, const ApplicationHandle& app_id, - const DeviceHandle& device_handle); + const DeviceHandle device_handle); + void DisconnectFailedRoutine(); }; + public: + /** + * @brief Constructor. + **/ + explicit TransportManagerImpl(const TransportManagerSettings& settings); /** * @brief Destructor. @@ -98,20 +121,20 @@ class TransportManagerImpl : public TransportManager, * * @return Code error. */ - virtual int Init(); + int Init(resumption::LastState& last_state) OVERRIDE; /** * Reinitializes transport manager * @return Error code */ - virtual int Reinit(); + virtual int Reinit() OVERRIDE; /** * @brief Start scanning for new devices. * * @return Code error. **/ - virtual int SearchDevices(); + int SearchDevices() OVERRIDE; /** * @brief Connect to all applications discovered on device. @@ -120,7 +143,7 @@ class TransportManagerImpl : public TransportManager, * * @return Code error. **/ - virtual int ConnectDevice(const DeviceHandle& device_id); + int ConnectDevice(const DeviceHandle device_id) OVERRIDE; /** * @brief Disconnect from all applications connected on device. @@ -129,7 +152,7 @@ class TransportManagerImpl : public TransportManager, * * @return Code error. **/ - virtual int DisconnectDevice(const DeviceHandle& device_id); + int DisconnectDevice(const DeviceHandle device_id) OVERRIDE; /** * @brief Disconnect from applications connected on device by connection @@ -139,14 +162,14 @@ class TransportManagerImpl : public TransportManager, * * @return Code error. **/ - virtual int Disconnect(const ConnectionUID& connection_id); + int Disconnect(const ConnectionUID connection_id) OVERRIDE; /** * @brief Disconnect and clear all unreceived data. * * @param connection Connection unique identifier. */ - virtual int DisconnectForce(const ConnectionUID& connection_id); + int DisconnectForce(const ConnectionUID connection_id) OVERRIDE; /** * @brief Post new message in queue for massages destined to device. * @@ -154,7 +177,8 @@ class TransportManagerImpl : public TransportManager, * * @return Code error. **/ - virtual int SendMessageToDevice(const protocol_handler::RawMessagePtr message); + int SendMessageToDevice( + const protocol_handler::RawMessagePtr message) OVERRIDE; /** * @brief Post event in the event queue. @@ -163,7 +187,7 @@ class TransportManagerImpl : public TransportManager, * * @return Code error. **/ - virtual int ReceiveEventFromDevice(const TransportAdapterEvent& event); + int ReceiveEventFromDevice(const TransportAdapterEvent& event) OVERRIDE; /** * @brief Post listener to the container of transport manager listeners. @@ -172,9 +196,9 @@ class TransportManagerImpl : public TransportManager, * * @return Code error. **/ - virtual int AddEventListener(TransportManagerListener* listener); + int AddEventListener(TransportManagerListener* listener) OVERRIDE; - virtual int Stop(); + int Stop() OVERRIDE; /** * @brief Add device adapter to the container of device adapters. @@ -183,8 +207,8 @@ class TransportManagerImpl : public TransportManager, * * @return Code error. **/ - virtual int AddTransportAdapter( - transport_adapter::TransportAdapter* transport_adapter); + int AddTransportAdapter( + transport_adapter::TransportAdapter* transport_adapter) OVERRIDE; /** * @brief Remove device from the container that hold devices. @@ -193,7 +217,7 @@ class TransportManagerImpl : public TransportManager, * * @return Code error. **/ - virtual int RemoveDevice(const DeviceHandle& device); + int RemoveDevice(const DeviceHandle device) OVERRIDE; /** * @brief Turns on or off visibility of SDL to mobile devices @@ -202,7 +226,7 @@ class TransportManagerImpl : public TransportManager, * * @return Code error. */ - virtual int Visibility(const bool& on_off) const; + int Visibility(const bool& on_off) const OVERRIDE; /** * @brief Updates total device list with info from specific transport adapter. @@ -210,28 +234,29 @@ class TransportManagerImpl : public TransportManager, */ void UpdateDeviceList(TransportAdapter* ta); -#ifdef TIME_TESTER +#ifdef TELEMETRY_MONITOR /** * @brief Setup observer for time metric. * * @param observer - pointer to observer */ - void SetTimeMetricObserver(TMMetricObserver* observer); -#endif // TIME_TESTER - + void SetTelemetryObserver(TMTelemetryObserver* observer); +#endif // TELEMETRY_MONITOR /** * @brief Constructor. **/ TransportManagerImpl(); - protected: + const TransportManagerSettings& get_settings() const; + protected: template <class Proc, class... Args> void RaiseEvent(Proc proc, Args... args) { for (TransportManagerListenerList::iterator it = transport_manager_listener_.begin(); - it != transport_manager_listener_.end(); ++it) { + it != transport_manager_listener_.end(); + ++it) { ((*it)->*proc)(args...); } } @@ -264,9 +289,9 @@ class TransportManagerImpl : public TransportManager, */ bool is_initialized_; -#ifdef TIME_TESTER - TMMetricObserver* metric_observer_; -#endif // TIME_TESTER +#ifdef TELEMETRY_MONITOR + TMTelemetryObserver* metric_observer_; +#endif // TELEMETRY_MONITOR private: /** @@ -282,19 +307,24 @@ class TransportManagerImpl : public TransportManager, } DeviceHandle UidToHandle(const DeviceUID& dev_uid, bool& is_new) { - ConversionTable::iterator it = std::find( - conversion_table_.begin(), conversion_table_.end(), dev_uid); - if (it != conversion_table_.end()) { - is_new = false; - return std::distance(conversion_table_.begin(), it) + - 1; // handle begin since 1 (one) + { + sync_primitives::AutoReadLock lock(conversion_table_lock); + ConversionTable::iterator it = std::find( + conversion_table_.begin(), conversion_table_.end(), dev_uid); + if (it != conversion_table_.end()) { + is_new = false; + return std::distance(conversion_table_.begin(), it) + + 1; // handle begin since 1 (one) + } } is_new = true; + sync_primitives::AutoWriteLock lock(conversion_table_lock); conversion_table_.push_back(dev_uid); return conversion_table_.size(); // handle begin since 1 (one) } - DeviceUID HandleToUid(DeviceHandle handle) { + DeviceUID HandleToUid(const DeviceHandle handle) { + sync_primitives::AutoReadLock lock(conversion_table_lock); if (handle == 0 || handle > conversion_table_.size()) { return DeviceUID(); } @@ -302,6 +332,7 @@ class TransportManagerImpl : public TransportManager, } ConversionTable conversion_table_; + sync_primitives::RWLock conversion_table_lock; }; /** @@ -312,22 +343,27 @@ class TransportManagerImpl : public TransportManager, explicit TransportManagerImpl(const TransportManagerImpl&); int connection_id_counter_; + sync_primitives::RWLock connections_lock_; std::vector<ConnectionInternal> connections_; - std::map<DeviceUID, TransportAdapter*> device_to_adapter_map_; + sync_primitives::RWLock device_to_adapter_map_lock_; + typedef std::map<DeviceUID, TransportAdapter*> DeviceToAdapterMap; + DeviceToAdapterMap device_to_adapter_map_; std::vector<TransportAdapter*> transport_adapters_; /** For keep listeners which were add TMImpl */ std::map<TransportAdapter*, TransportAdapterListenerImpl*> transport_adapter_listeners_; - threads::MessageLoopThread<std::queue<protocol_handler::RawMessagePtr> > message_queue_; - threads::MessageLoopThread<std::queue<TransportAdapterEvent> > event_queue_; - + RawMessageLoopThread message_queue_; + TransportAdapterEventLoopThread event_queue_; + const TransportManagerSettings& settings_; typedef std::vector<std::pair<const TransportAdapter*, DeviceInfo> > - DeviceInfoList; + DeviceInfoList; + sync_primitives::RWLock device_list_lock_; DeviceInfoList device_list_; void AddConnection(const ConnectionInternal& c); - void RemoveConnection(uint32_t id); - ConnectionInternal* GetConnection(const ConnectionUID& id); + void RemoveConnection(const uint32_t id, + transport_adapter::TransportAdapter* transport_adapter); + ConnectionInternal* GetConnection(const ConnectionUID id); ConnectionInternal* GetConnection(const DeviceUID& device, const ApplicationHandle& application); @@ -335,12 +371,15 @@ class TransportManagerImpl : public TransportManager, ConnectionUID id, std::map<ConnectionUID, std::pair<unsigned int, unsigned char*> >& container, - unsigned char* data, unsigned int data_size); - bool GetFrameSize(unsigned char* data, unsigned int data_size, + unsigned char* data, + unsigned int data_size); + bool GetFrameSize(unsigned char* data, + unsigned int data_size, unsigned int& frame_size); bool GetFrame(std::map<ConnectionUID, std::pair<unsigned int, unsigned char*> >& container, - ConnectionUID id, unsigned int frame_size, + ConnectionUID id, + unsigned int frame_size, unsigned char** frame); void OnDeviceListUpdated(TransportAdapter* ta); @@ -348,9 +387,6 @@ class TransportManagerImpl : public TransportManager, void TerminateAllAdapters(); int InitAllAdapters(); static Connection convert(const ConnectionInternal& p); -}; -// class ; - +}; // class TransportManagerImpl } // namespace transport_manager - -#endif +#endif // SRC_COMPONENTS_TRANSPORT_MANAGER_INCLUDE_TRANSPORT_MANAGER_TRANSPORT_MANAGER_IMPL_H_ 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_aoa_adapter.h b/src/components/transport_manager/include/transport_manager/usb/usb_aoa_adapter.h index b0d8c1e453..92a813ed7c 100644 --- a/src/components/transport_manager/include/transport_manager/usb/usb_aoa_adapter.h +++ b/src/components/transport_manager/include/transport_manager/usb/usb_aoa_adapter.h @@ -44,7 +44,8 @@ namespace transport_adapter { class UsbAoaAdapter : public TransportAdapterImpl { public: - UsbAoaAdapter(); + UsbAoaAdapter(resumption::LastState& last_state, + const TransportManagerSettings& settings); virtual ~UsbAoaAdapter(); protected: 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() {} |