summaryrefslogtreecommitdiff
path: root/src/components/transport_manager/include
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/transport_manager/include')
-rw-r--r--src/components/transport_manager/include/transport_manager/cloud/cloud_device.h67
-rw-r--r--src/components/transport_manager/include/transport_manager/cloud/cloud_websocket_connection_factory.h98
-rw-r--r--src/components/transport_manager/include/transport_manager/cloud/cloud_websocket_transport_adapter.h107
-rw-r--r--src/components/transport_manager/include/transport_manager/cloud/websocket_client_connection.h205
-rw-r--r--src/components/transport_manager/include/transport_manager/transport_adapter/transport_adapter_controller.h14
-rw-r--r--src/components/transport_manager/include/transport_manager/transport_adapter/transport_adapter_impl.h68
-rw-r--r--src/components/transport_manager/include/transport_manager/transport_adapter/transport_adapter_listener.h19
-rw-r--r--src/components/transport_manager/include/transport_manager/transport_adapter/transport_adapter_listener_impl.h18
-rw-r--r--src/components/transport_manager/include/transport_manager/transport_manager_impl.h21
9 files changed, 613 insertions, 4 deletions
diff --git a/src/components/transport_manager/include/transport_manager/cloud/cloud_device.h b/src/components/transport_manager/include/transport_manager/cloud/cloud_device.h
new file mode 100644
index 0000000000..47a82e7921
--- /dev/null
+++ b/src/components/transport_manager/include/transport_manager/cloud/cloud_device.h
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2018, Livio
+ * 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.
+ */
+
+/**
+ * \file Cloud_device.h
+ * \brief CloudDevice class header file.
+ */
+
+#ifndef SRC_COMPONENTS_TRANSPORT_MANAGER_INCLUDE_TRANSPORT_MANAGER_CLOUD_CLOUD_DEVICE_H_
+#define SRC_COMPONENTS_TRANSPORT_MANAGER_INCLUDE_TRANSPORT_MANAGER_CLOUD_CLOUD_DEVICE_H_
+
+#include "transport_manager/transport_adapter/device.h"
+
+namespace transport_manager {
+namespace transport_adapter {
+
+class CloudDevice : public Device {
+ public:
+ CloudDevice(std::string& host, std::string& port, std::string& name);
+
+ virtual const std::string& GetHost() const;
+
+ virtual const std::string& GetPort() const;
+
+ protected:
+ virtual bool IsSameAs(const Device* other_device) const;
+
+ virtual ApplicationList GetApplicationList() const;
+
+ private:
+ const std::string host_;
+ const std::string port_;
+};
+
+} // namespace transport_adapter
+} // namespace transport_manager
+
+#endif // SRC_COMPONENTS_TRANSPORT_MANAGER_INCLUDE_TRANSPORT_MANAGER_CLOUD_CLOUD_DEVICE_H_
diff --git a/src/components/transport_manager/include/transport_manager/cloud/cloud_websocket_connection_factory.h b/src/components/transport_manager/include/transport_manager/cloud/cloud_websocket_connection_factory.h
new file mode 100644
index 0000000000..ef1754a6e7
--- /dev/null
+++ b/src/components/transport_manager/include/transport_manager/cloud/cloud_websocket_connection_factory.h
@@ -0,0 +1,98 @@
+/*
+ * \file cloud_websocket_connection_factory.h
+ * \brief CloudWebsocketConnectionFactory class header file.
+ *
+ * Copyright (c) 2018, Livio
+ * 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_CLOUD_CLOUD_WEBSOCKET_CONNECTION_FACTORY_H_
+#define SRC_COMPONENTS_TRANSPORT_MANAGER_INCLUDE_TRANSPORT_MANAGER_CLOUD_CLOUD_WEBSOCKET_CONNECTION_FACTORY_H_
+
+#include "transport_manager/transport_adapter/server_connection_factory.h"
+
+namespace transport_manager {
+namespace transport_adapter {
+
+class TransportAdapterController;
+
+/**
+ * @brief Create connections.
+ */
+class CloudWebsocketConnectionFactory : public ServerConnectionFactory {
+ public:
+ /**
+ * @brief Constructor.
+ *
+ * @param controller Pointer to the device adapter controller.
+ */
+ CloudWebsocketConnectionFactory(TransportAdapterController* controller);
+
+ protected:
+ /**
+ * @brief Start cloud websocket connection factory.
+ */
+ virtual TransportAdapter::Error Init();
+
+ /**
+ * @brief Create cloud boost websocket connection.
+ *
+ * @param device_uid Device unique identifier.
+ * @param ap_handle Handle of application.
+ */
+ virtual TransportAdapter::Error CreateConnection(
+ const DeviceUID& device_uid, const ApplicationHandle& app_handle);
+
+ /**
+ * @brief
+ */
+ virtual void Terminate();
+
+ /**
+ * @brief Check for initialization.
+ *
+ * @return true - initialized.
+ * false - not initialized.
+ */
+ virtual bool IsInitialised() const;
+
+ /**
+ * @brief Destructor.
+ */
+ virtual ~CloudWebsocketConnectionFactory();
+
+ private:
+ TransportAdapterController* controller_;
+};
+
+} // namespace transport_adapter
+} // namespace transport_manager
+
+#endif // SRC_COMPONENTS_TRANSPORT_MANAGER_INCLUDE_TRANSPORT_MANAGER_CLOUD_CLOUD_WEBSOCKET_CONNECTION_FACTORY_H_
diff --git a/src/components/transport_manager/include/transport_manager/cloud/cloud_websocket_transport_adapter.h b/src/components/transport_manager/include/transport_manager/cloud/cloud_websocket_transport_adapter.h
new file mode 100644
index 0000000000..138f9ca895
--- /dev/null
+++ b/src/components/transport_manager/include/transport_manager/cloud/cloud_websocket_transport_adapter.h
@@ -0,0 +1,107 @@
+/*
+ * \file cloud_websocket_transport_adapter.h
+ * \brief Cloud Websocket Transport Adapterclass header file.
+ *
+ * Copyright (c) 2018, Livio
+ * 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_CLOUD_CLOUD_WEBSOCKET_TRANSPORT_ADAPTER_H_
+#define SRC_COMPONENTS_TRANSPORT_MANAGER_INCLUDE_TRANSPORT_MANAGER_CLOUD_CLOUD_WEBSOCKET_TRANSPORT_ADAPTER_H_
+
+#include "transport_manager/transport_adapter/transport_adapter_impl.h"
+
+namespace transport_manager {
+namespace transport_adapter {
+
+/**
+ * @brief Cloud transport adapter that uses websockets.
+ */
+class CloudWebsocketTransportAdapter : public TransportAdapterImpl {
+ public:
+ /**
+ * @brief Constructor.
+ */
+ explicit CloudWebsocketTransportAdapter(
+ resumption::LastState& last_state,
+ const TransportManagerSettings& settings);
+
+ /**
+ * @brief Destructor.
+ */
+ virtual ~CloudWebsocketTransportAdapter();
+
+ /**
+ * @brief Set CloudTransportConfig for specified app_id
+ *
+ * @param app_id app ID string
+ * @param properties New cloud app properties for the app
+ */
+ void SetAppCloudTransportConfig(std::string app_id,
+ CloudAppProperties properties);
+
+ /**
+ * @brief Get CloudTransportConfig for specified app_id
+ *
+ * @param app_id app ID string
+ * @return CloudAppProperties for the app
+ */
+ const CloudAppProperties& GetAppCloudTransportConfig(std::string app_id);
+
+ protected:
+ /**
+ * @brief Return type of device.
+ *
+ * @return String with device type.
+ */
+ virtual DeviceType GetDeviceType() const;
+
+ /**
+ * @brief Store adapter state in last state singleton
+ */
+ virtual void Store() const;
+
+ /**
+ * @brief Restore adapter state from last state singleton
+ *
+ * @return True on success false otherwise
+ */
+ virtual bool Restore();
+
+ void CreateDevice(const std::string& uid) OVERRIDE;
+
+ private:
+ CloudAppTransportConfig transport_config_;
+};
+
+} // namespace transport_adapter
+} // namespace transport_manager
+
+#endif // SRC_COMPONENTS_TRANSPORT_MANAGER_INCLUDE_TRANSPORT_MANAGER_TCP_TCP_TRANSPORT_ADAPTER_H_
diff --git a/src/components/transport_manager/include/transport_manager/cloud/websocket_client_connection.h b/src/components/transport_manager/include/transport_manager/cloud/websocket_client_connection.h
new file mode 100644
index 0000000000..a726524af2
--- /dev/null
+++ b/src/components/transport_manager/include/transport_manager/cloud/websocket_client_connection.h
@@ -0,0 +1,205 @@
+/*
+ * \file websocket_client_connection.h
+ * \brief WebsocketClientConnection class header file.
+ *
+ * Copyright (c) 2018, Livio
+ * 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_CLOUD_WEBSOCKET_CLIENT_CONNECTION_H_
+#define SRC_COMPONENTS_TRANSPORT_MANAGER_INCLUDE_TRANSPORT_MANAGER_CLOUD_WEBSOCKET_CLIENT_CONNECTION_H_
+
+#include <boost/beast/core.hpp>
+#include <boost/beast/websocket.hpp>
+#include <boost/asio/connect.hpp>
+#include <boost/asio/ip/tcp.hpp>
+#include <boost/asio/thread_pool.hpp>
+#ifdef ENABLE_SECURITY
+#include <boost/asio/ssl/stream.hpp>
+#include <boost/beast/websocket/ssl.hpp>
+#endif // ENABLE_SECURITY
+#include <cstdlib>
+#include <functional>
+#include <iostream>
+#include <memory>
+#include <string>
+#include <thread>
+#include "transport_manager/transport_adapter/connection.h"
+#include "transport_manager/cloud/cloud_websocket_transport_adapter.h"
+#include "utils/threads/thread.h"
+#include "utils/threads/message_loop_thread.h"
+#include "utils/message_queue.h"
+
+namespace websocket =
+ boost::beast::websocket; // from <boost/beast/websocket.hpp>
+
+using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp>
+typedef websocket::stream<tcp::socket> WS;
+
+#ifdef ENABLE_SECURITY
+namespace ssl = boost::asio::ssl; // from <boost/asio/ssl.hpp>
+typedef websocket::stream<ssl::stream<tcp::socket> > WSS;
+#endif // ENABLE_SECURITY
+
+using ::utils::MessageQueue;
+
+typedef std::queue<protocol_handler::RawMessagePtr> AsyncQueue;
+typedef protocol_handler::RawMessagePtr Message;
+
+namespace transport_manager {
+namespace transport_adapter {
+
+class TransportAdapterController;
+
+/**
+ * @brief Class responsible for communication over bluetooth sockets.
+ */
+class WebsocketClientConnection
+ : public std::enable_shared_from_this<WebsocketClientConnection>,
+ public Connection {
+ public:
+ /**
+ * @brief Constructor.
+ *
+ * @param device_uid Device unique identifier.
+ * @param app_handle Handle of device.
+ * @param controller Pointer to the device adapter controller.
+ */
+ WebsocketClientConnection(const DeviceUID& device_uid,
+ const ApplicationHandle& app_handle,
+ TransportAdapterController* controller);
+
+ /**
+ * @brief Destructor.
+ */
+ virtual ~WebsocketClientConnection();
+
+ /**
+ * @brief Check if we can start the connection attempt and establish
+ *connection status.
+ *
+ * @param error contains information of any error that occurred during
+ *connection attempt.
+ *
+ * @return result that states whether we successfully connected or not.
+ */
+ TransportAdapter::Error Start();
+
+ /**
+ * @brief Send data frame.
+ *
+ * @param message Smart pointer to the raw message.
+ *
+ * @return Error Information about possible reason of sending data failure.
+ */
+ TransportAdapter::Error SendData(::protocol_handler::RawMessagePtr message);
+
+ /**
+ * @brief Disconnect the current connection.
+ *
+ * @return Error Information about possible reason of Disconnect failure.
+ */
+ TransportAdapter::Error Disconnect();
+
+#ifdef ENABLE_SECURITY
+ /**
+ * @brief Attempt to add provided certificate to the ssl::context
+ *
+ * @param cert Certificate string from policy table
+ */
+ void AddCertificateAuthority(std::string cert, boost::system::error_code& ec);
+#endif // ENABLE_SECURITY
+
+ void Shutdown();
+
+ void Recv(boost::system::error_code ec);
+
+ void OnRead(boost::system::error_code ec, std::size_t bytes_transferred);
+
+ private:
+ TransportAdapterController* controller_;
+ boost::asio::io_context ioc_;
+ tcp::resolver resolver_;
+ boost::beast::flat_buffer buffer_;
+ std::string host_;
+ std::string text_;
+ WS ws_;
+#ifdef ENABLE_SECURITY
+ ssl::context ctx_;
+ WSS wss_;
+#endif // ENABLE_SECURITY
+
+ std::atomic_bool shutdown_;
+
+ CloudAppProperties cloud_properties;
+ typedef std::queue<protocol_handler::RawMessagePtr> FrameQueue;
+ FrameQueue frames_to_send_;
+ mutable sync_primitives::Lock frames_to_send_mutex_;
+
+ MessageQueue<Message, AsyncQueue> message_queue_;
+
+ class LoopThreadDelegate : public threads::ThreadDelegate {
+ public:
+ LoopThreadDelegate(MessageQueue<Message, AsyncQueue>* message_queue,
+ WebsocketClientConnection* handler);
+
+ virtual void threadMain() OVERRIDE;
+ virtual void exitThreadMain() OVERRIDE;
+
+ void OnWrite();
+
+ void SetShutdown();
+
+ private:
+ void DrainQueue();
+ MessageQueue<Message, AsyncQueue>& message_queue_;
+ WebsocketClientConnection& handler_;
+ sync_primitives::Lock queue_lock_;
+ sync_primitives::ConditionalVariable queue_new_items_;
+ std::atomic_bool write_pending_;
+ std::atomic_bool shutdown_;
+
+ sync_primitives::Lock write_lock_;
+ };
+
+ LoopThreadDelegate* thread_delegate_;
+ threads::Thread* write_thread_;
+ std::thread io_service_thread_;
+
+ const DeviceUID device_uid_;
+ const ApplicationHandle app_handle_;
+
+ boost::asio::thread_pool io_pool_;
+};
+
+} // namespace transport_adapter
+} // namespace transport_manager
+
+#endif // SRC_COMPONENTS_TRANSPORT_MANAGER_INCLUDE_TRANSPORT_MANAGER_BLUETOOTH_BLUETOOTH_SOCKET_CONNECTION_H_
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 69d76b4b2b..7a0a37758c 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
@@ -88,6 +88,10 @@ class TransportAdapterController {
*/
virtual DeviceSptr FindDevice(const DeviceUID& device_handle) const = 0;
+ virtual ConnectionSPtr FindPendingConnection(
+ const DeviceUID& device_handle,
+ const ApplicationHandle& app_handle) const = 0;
+
/**
* @brief Create connection and fill its parameters.
*
@@ -100,6 +104,16 @@ class TransportAdapterController {
const ApplicationHandle& app_handle) = 0;
/**
+ * @brief Set state of specified connection - PENDING and launch
+ *OnConnectPending event in device adapter listener.
+ *
+ * @param devcie_handle Device unique identifier.
+ * @param app_handle Handle of application.
+ */
+ virtual void ConnectPending(const DeviceUID& device_handle,
+ const ApplicationHandle& app_handle) = 0;
+
+ /**
* @brief Make state of specified connection - ESTABLISHED and launch
*OnConnectDone event in device adapter listener.
*
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 078f93b32f..b30f1e35b2 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,6 +41,7 @@
#include "utils/lock.h"
#include "utils/rwlock.h"
+#include "utils/timer.h"
#include "transport_manager/transport_adapter/transport_adapter.h"
#include "transport_manager/transport_adapter/transport_adapter_controller.h"
@@ -61,6 +62,8 @@ class DeviceScanner;
class ServerConnectionFactory;
class ClientConnectionListener;
+typedef std::shared_ptr<timer::Timer> TimerSPtr;
+
/*
* @brief Implementation of device adapter class.
**/
@@ -147,6 +150,22 @@ class TransportAdapterImpl : public TransportAdapter,
const DeviceUID& device_handle) OVERRIDE;
/**
+ * @brief Retrieves the connection status of a given device
+ *
+ * @param device_handle Handle of device to query
+ *
+ * @return The connection status of the given device
+ */
+ ConnectionStatus GetConnectionStatus(
+ const DeviceUID& device_handle) const OVERRIDE;
+
+ /**
+ * @brief Notifies the application manager that a cloud connection status has
+ * updated and should trigger an UpdateAppList RPC to the HMI
+ */
+ void ConnectionStatusUpdated(DeviceSptr device, ConnectionStatus status);
+
+ /**
* @brief Disconnect from specified session.
*
* @param devcie_handle Device unique identifier.
@@ -245,6 +264,10 @@ class TransportAdapterImpl : public TransportAdapter,
*/
DeviceSptr FindDevice(const DeviceUID& device_handle) const OVERRIDE;
+ ConnectionSPtr FindPendingConnection(
+ const DeviceUID& device_handle,
+ const ApplicationHandle& app_handle) const OVERRIDE;
+
/**
* @brief Search for device in container of devices, if it is not there - adds
*it.
@@ -306,6 +329,16 @@ class TransportAdapterImpl : public TransportAdapter,
const CommunicationError& error) OVERRIDE;
/**
+ * @brief Set state of specified connection - PENDING and launch
+ *OnConnectPending event in device adapter listener.
+ *
+ * @param devcie_handle Device unique identifier.
+ * @param app_handle Handle of application.
+ */
+ void ConnectPending(const DeviceUID& device_handle,
+ const ApplicationHandle& app_handle) OVERRIDE;
+
+ /**
* @brief Set state of specified connection - ESTABLISHED and launch
*OnConnectDone event in device adapter listener.
*
@@ -434,6 +467,10 @@ class TransportAdapterImpl : public TransportAdapter,
return TransportConfig();
}
+ void CreateDevice(const std::string& uid) OVERRIDE {
+ return;
+ }
+
/**
* @brief Return name of device.
*
@@ -533,6 +570,23 @@ class TransportAdapterImpl : public TransportAdapter,
TransportAdapter::Error ConnectDevice(DeviceSptr device);
/**
+ * @brief Reattempt the last failed connection to a device
+ */
+ void RetryConnection();
+
+ /**
+ * @brief Clear any retry timers which have been completed
+ */
+ void ClearCompletedTimers();
+
+ /**
+ * @brief Retrieve the next device available for a reattempted connection
+ * @return The handle first device with an expired retry timer if present,
+ * otherwise an empty string
+ */
+ DeviceUID GetNextRetryDevice();
+
+ /**
* @brief Remove specified device
* @param device_handle Device unique identifier.
*/
@@ -564,7 +618,7 @@ class TransportAdapterImpl : public TransportAdapter,
ConnectionSPtr connection;
DeviceUID device_id;
ApplicationHandle app_handle;
- enum { NEW, ESTABLISHED, FINALISING } state;
+ enum { NEW, ESTABLISHED, FINALISING, PENDING } state;
};
/**
@@ -594,6 +648,18 @@ class TransportAdapterImpl : public TransportAdapter,
ConnectionMap connections_;
/**
+ * @brief Queue of retry timers.
+ */
+ std::queue<std::pair<TimerSPtr, DeviceUID> > retry_timer_pool_;
+ sync_primitives::Lock retry_timer_pool_lock_;
+
+ /**
+ * @brief Queue of completed retry timers.
+ */
+ std::queue<std::pair<TimerSPtr, DeviceUID> > completed_timer_pool_;
+ sync_primitives::Lock completed_timer_pool_lock_;
+
+ /**
* @brief Mutex restricting access to connections map.
**/
mutable sync_primitives::RWLock connections_lock_;
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 4606bac2d4..a0e0a51c1e 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
@@ -92,6 +92,25 @@ class TransportAdapterListener {
const TransportAdapter* adapter) = 0;
/**
+ * @brief Reaction to connection status update
+ * @param adapter Current transport adapter
+ */
+ virtual void OnConnectionStatusUpdated(const TransportAdapter* adapter) = 0;
+
+ /**
+ * @brief Search specified device adapter in the container of shared pointers
+ * to device adapters to be sure it is available,
+ * launch event ON_CONNECT_PENDING in transport manager.
+ *
+ * @param device_adater Pointer to the device adapter.
+ * @param device_handle Device unique identifier.
+ * @param app_id Handle of application.
+ */
+ virtual void OnConnectPending(const TransportAdapter* adapter,
+ const DeviceUID& device_handle,
+ const ApplicationHandle& app_id) = 0;
+
+ /**
* @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.
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 a744400279..0c9c6ef6a2 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
@@ -88,6 +88,24 @@ class TransportAdapterListenerImpl
virtual void OnFindNewApplicationsRequest(const TransportAdapter* adapter);
/**
+ * @brief Passes notification to that the cloud conection status has updated
+ */
+ virtual void OnConnectionStatusUpdated(const TransportAdapter* adapter);
+
+ /**
+ * @brief Search specified device adapter in the container of shared pointers
+ * to device adapters to be sure it is available,
+ * launch event ON_CONNECT_PENDING in transport manager.
+ *
+ * @param device_adater Pointer to the device adapter.
+ * @param device_handle Device unique identifier.
+ * @param app_id Handle of application.
+ */
+ virtual void OnConnectPending(const TransportAdapter* adapter,
+ const DeviceUID& device_handle,
+ const ApplicationHandle& app_id);
+
+ /**
* @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.
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 c1df49f91b..60303c1bca 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
@@ -43,7 +43,6 @@
#include <functional>
#include "utils/timer.h"
-#include "utils/timer_task_impl.h"
#include "utils/rwlock.h"
#include "transport_manager/transport_manager.h"
@@ -140,6 +139,12 @@ class TransportManagerImpl
**/
int SearchDevices() OVERRIDE;
+ void AddCloudDevice(
+ const transport_manager::transport_adapter::CloudAppProperties&
+ cloud_properties) OVERRIDE;
+
+ void RemoveCloudDevice(const DeviceHandle device_id) OVERRIDE;
+
/**
* @brief Connect to all applications discovered on device.
*
@@ -150,6 +155,16 @@ class TransportManagerImpl
int ConnectDevice(const DeviceHandle device_id) OVERRIDE;
/**
+ * @brief Retrieves the connection status of a given device
+ *
+ * @param device_handle Handle of device to query
+ *
+ * @return The connection status of the given device
+ */
+ ConnectionStatus GetConnectionStatus(
+ const DeviceHandle& device_handle) const OVERRIDE;
+
+ /**
* @brief Disconnect from all applications connected on device.
*
* @param device_id Handle of device to Disconnect from.
@@ -365,7 +380,7 @@ class TransportManagerImpl
* @brief Converter variable (Device ID -> Device Handle; Device Handle ->
* Device ID)
*/
- Handle2GUIDConverter converter_;
+ mutable Handle2GUIDConverter converter_;
#ifdef BUILD_TESTS
public:
@@ -380,7 +395,7 @@ class TransportManagerImpl
int connection_id_counter_;
sync_primitives::RWLock connections_lock_;
std::vector<ConnectionInternal> connections_;
- sync_primitives::RWLock device_to_adapter_map_lock_;
+ mutable sync_primitives::RWLock device_to_adapter_map_lock_;
typedef std::map<DeviceUID, TransportAdapter*> DeviceToAdapterMap;
DeviceToAdapterMap device_to_adapter_map_;
std::vector<TransportAdapter*> transport_adapters_;