diff options
author | Sho Amano <samano@xevo.com> | 2018-03-13 21:16:35 +0900 |
---|---|---|
committer | Sho Amano <samano@xevo.com> | 2018-03-14 12:57:26 +0900 |
commit | d7be4b4ad7d67f48ee116c4d9be54c0c0219a7df (patch) | |
tree | 712b017e45f674936495fb876e76baefaad74339 | |
parent | 3d61a8e0e3e84dbe3de72a69e35c1ef0a58eee1f (diff) | |
download | sdl_core-d7be4b4ad7d67f48ee116c4d9be54c0c0219a7df.tar.gz |
Enable NetworkInterfaceListener
-rw-r--r-- | src/components/transport_manager/include/transport_manager/tcp/tcp_client_listener.h | 2 | ||||
-rw-r--r-- | src/components/transport_manager/src/tcp/tcp_client_listener.cc | 17 |
2 files changed, 19 insertions, 0 deletions
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 6bcd41863d..c6d1002ffc 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 @@ -48,6 +48,7 @@ namespace transport_manager { namespace transport_adapter { class TransportAdapterController; +class NetworkInterfaceListener; /** * @brief Listener of device adapter that use TCP transport. @@ -132,6 +133,7 @@ class TcpClientListener : public ClientConnectionListener { threads::Thread* thread_; int socket_; bool thread_stop_requested_; + NetworkInterfaceListener* interface_listener_; std::string current_ip_address_; void Loop(); diff --git a/src/components/transport_manager/src/tcp/tcp_client_listener.cc b/src/components/transport_manager/src/tcp/tcp_client_listener.cc index 1f28fa39da..693158dba1 100644 --- a/src/components/transport_manager/src/tcp/tcp_client_listener.cc +++ b/src/components/transport_manager/src/tcp/tcp_client_listener.cc @@ -59,6 +59,7 @@ #include "utils/make_shared.h" #include "utils/threads/thread.h" #include "transport_manager/transport_adapter/transport_adapter_controller.h" +#include "transport_manager/tcp/network_interface_listener.h" #include "transport_manager/tcp/tcp_device.h" #include "transport_manager/tcp/tcp_socket_connection.h" @@ -78,6 +79,7 @@ TcpClientListener::TcpClientListener(TransportAdapterController* controller, , thread_stop_requested_(false) { thread_ = threads::CreateThread("TcpClientListener", new ListeningThreadDelegate(this)); + interface_listener_ = new NetworkInterfaceListener(this); } TransportAdapter::Error TcpClientListener::Init() { @@ -113,6 +115,12 @@ TransportAdapter::Error TcpClientListener::Init() { LOG4CXX_ERROR_WITH_ERRNO(logger_, "listen() failed"); return TransportAdapter::FAIL; } + + if (!interface_listener_->Init()) { + close(socket_); + socket_ = -1; + return TransportAdapter::FAIL; + } return TransportAdapter::OK; } @@ -129,6 +137,8 @@ void TcpClientListener::Terminate() { LOG4CXX_ERROR_WITH_ERRNO(logger_, "Failed to close socket"); } socket_ = -1; + + interface_listener_->Deinit(); } bool TcpClientListener::IsInitialised() const { @@ -300,8 +310,13 @@ TransportAdapter::Error TcpClientListener::StartListening() { return TransportAdapter::BAD_STATE; } + if (!interface_listener_->Start()) { + return TransportAdapter::FAIL; + } + if (!thread_->start()) { LOG4CXX_ERROR(logger_, "Tcp client listener thread start failed"); + interface_listener_->Stop(); return TransportAdapter::FAIL; } LOG4CXX_INFO(logger_, "Tcp client listener has started successfully"); @@ -327,6 +342,8 @@ TransportAdapter::Error TcpClientListener::StopListening() { return TransportAdapter::BAD_STATE; } + interface_listener_->Stop(); + thread_->join(); LOG4CXX_INFO(logger_, "Tcp client listener has stopped successfully"); |