diff options
Diffstat (limited to 'src/components/transport_manager/include/transport_manager')
5 files changed, 140 insertions, 44 deletions
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 3f524dac0f..bd8aaad571 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 @@ -2,7 +2,7 @@ * \file bluetooth_socket_connection.h * \brief BluetoothSocketConnection class header file. * - * Copyright (c) 2013, Ford Motor Company + * Copyright (c) 2017, Ford Motor Company * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -66,12 +66,13 @@ class BluetoothSocketConnection : public ThreadedSocketConnection { protected: /** - * @brief Establish connection. + * @brief Check if we can start the connection attempt and establish + *connection status. * - * @param error Connection error. + * @param error contains information of any error that occurred during + *connection attempt. * - * @return True - connection established. - * false - connection not established. + * @return result that states whether we successfully connected or not. */ virtual bool Establish(ConnectError** error); }; diff --git a/src/components/transport_manager/include/transport_manager/tcp/tcp_connection_factory.h b/src/components/transport_manager/include/transport_manager/tcp/tcp_connection_factory.h index 7f238e91ec..da24a4d65d 100644 --- a/src/components/transport_manager/include/transport_manager/tcp/tcp_connection_factory.h +++ b/src/components/transport_manager/include/transport_manager/tcp/tcp_connection_factory.h @@ -2,7 +2,7 @@ * \file tcp_connection_factory.h * \brief TcpConnectionFactory class header file. * - * Copyright (c) 2013, Ford Motor Company + * Copyright (c) 2017, Ford Motor Company * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -37,11 +37,12 @@ #define SRC_COMPONENTS_TRANSPORT_MANAGER_INCLUDE_TRANSPORT_MANAGER_TCP_TCP_CONNECTION_FACTORY_H_ #include "transport_manager/transport_adapter/server_connection_factory.h" -#include "transport_manager/transport_adapter/transport_adapter_controller.h" namespace transport_manager { namespace transport_adapter { +class TransportAdapterController; + /** * @brief Create connections. */ diff --git a/src/components/transport_manager/include/transport_manager/tcp/tcp_server_originated_socket_connection.h b/src/components/transport_manager/include/transport_manager/tcp/tcp_server_originated_socket_connection.h new file mode 100644 index 0000000000..bf38fae37e --- /dev/null +++ b/src/components/transport_manager/include/transport_manager/tcp/tcp_server_originated_socket_connection.h @@ -0,0 +1,84 @@ +/* + * \file tcp_server_originated_socket_connection.h + * \brief TcpServerOriginatedSocketConnection class header file. + * + * Copyright (c) 2017, 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_TCP_SERVER_ORIGINATED_SOCKET_CONNECTION_H_ +#define SRC_COMPONENTS_TRANSPORT_MANAGER_INCLUDE_TRANSPORT_MANAGER_TCP_TCP_SERVER_ORIGINATED_SOCKET_CONNECTION_H_ + +#include "transport_manager/transport_adapter/threaded_socket_connection.h" + +namespace transport_manager { +namespace transport_adapter { + +class TransportAdapterController; + +/** + * @brief Class responsible for communication over sockets that originated by + * server. + */ +class TcpServerOriginatedSocketConnection : public ThreadedSocketConnection { + public: + /** + * @brief Constructor. + * + * @param device_uid Device unique identifier. + * @param app_handle Handle of application. + * @param controller Pointer to the device adapter controller. + */ + TcpServerOriginatedSocketConnection(const DeviceUID& device_uid, + const ApplicationHandle& app_handle, + TransportAdapterController* controller); + + /** + * @brief Destructor. + */ + virtual ~TcpServerOriginatedSocketConnection(); + + protected: + /** + * @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. + */ + virtual bool Establish(ConnectError** error); +}; + +} // namespace transport_adapter +} // namespace transport_manager + +#endif // SRC_COMPONENTS_TRANSPORT_MANAGER_INCLUDE_TRANSPORT_MANAGER_TCP_TCP_SERVER_ORIGINATED_SOCKET_CONNECTION_H_ 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 4d7901f4f0..a3e081e238 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 @@ -2,7 +2,7 @@ * \file tcp_socket_connection.h * \brief TcpSocketConnection class header file. * - * Copyright (c) 2013, Ford Motor Company + * Copyright (c) 2017, Ford Motor Company * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -36,11 +36,6 @@ #ifndef SRC_COMPONENTS_TRANSPORT_MANAGER_INCLUDE_TRANSPORT_MANAGER_TCP_TCP_SOCKET_CONNECTION_H_ #define SRC_COMPONENTS_TRANSPORT_MANAGER_INCLUDE_TRANSPORT_MANAGER_TCP_TCP_SOCKET_CONNECTION_H_ -#include <arpa/inet.h> -#include <netinet/in.h> -#include <sys/types.h> -#include <sys/socket.h> - #include "transport_manager/transport_adapter/threaded_socket_connection.h" namespace transport_manager { @@ -71,36 +66,13 @@ class TcpSocketConnection : public ThreadedSocketConnection { protected: /** - * @brief - */ - virtual bool Establish(ConnectError** error); -}; - -/** - * @brief Class responsible for communication over sockets that originated by - * server. - */ -class TcpServerOiginatedSocketConnection : public ThreadedSocketConnection { - public: - /** - * @brief Constructor. + * @brief Check if we can start the connection attempt and establish + *connection status. * - * @param device_uid Device unique identifier. - * @param app_handle Handle of application. - * @param controller Pointer to the device adapter controller. - */ - TcpServerOiginatedSocketConnection(const DeviceUID& device_uid, - const ApplicationHandle& app_handle, - TransportAdapterController* controller); - - /** - * @brief Destructor. - */ - virtual ~TcpServerOiginatedSocketConnection(); - - protected: - /** - * @brief + * @param error contains information of any error that occurred during + *connection attempt. + * + * @return result that states whether we successfully connected or not. */ virtual bool Establish(ConnectError** error); }; 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 ab0c5cbf85..3792b94d7c 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 @@ -1,7 +1,7 @@ /* * \file threaded_socket_connection.h * \brief Header for classes responsible for communication over sockets. - * Copyright (c) 2013, Ford Motor Company + * Copyright (c) 2017, Ford Motor Company * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -40,6 +40,7 @@ #include "transport_manager/transport_adapter/connection.h" #include "protocol/common.h" +#include "utils/atomic_object.h" #include "utils/threads/thread_delegate.h" #include "utils/lock.h" @@ -88,6 +89,15 @@ class ThreadedSocketConnection : public Connection { bool IsFramesToSendQueueEmpty() const; /** + * @brief Check if connection has been terminated. + * + * @return Information which states that connection was marked as terminated. + */ + bool IsConnectionTerminated() const { + return terminate_flag_; + } + + /** * @brief Set variable that hold socket No. */ void set_socket(int socket) { @@ -111,6 +121,15 @@ class ThreadedSocketConnection : public Connection { */ virtual ~ThreadedSocketConnection(); + /** + * @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. + */ virtual bool Establish(ConnectError** error) = 0; /** @@ -134,6 +153,25 @@ class ThreadedSocketConnection : public Connection { return app_handle_; } + /** + * @brief Get variable that hold socket No. + */ + int get_socket() const { + return socket_; + } + + /** + * @brief Checks current socket value, sends shutdown and close commands for + * this socket and clear current socket value. + */ + void ShutdownAndCloseSocket(); + + /** + * @brief This method will ensure that thread has finished running and then it + * will delete this thread. + */ + void StopAndJoinThread(); + private: class SocketConnectionDelegate : public threads::ThreadDelegate { public: @@ -163,7 +201,7 @@ class ThreadedSocketConnection : public Connection { FrameQueue frames_to_send_; mutable sync_primitives::Lock frames_to_send_mutex_; - int socket_; + sync_primitives::atomic_int socket_; bool terminate_flag_; bool unexpected_disconnect_; const DeviceUID device_uid_; |