summaryrefslogtreecommitdiff
path: root/src/components/transport_manager/src/tcp
diff options
context:
space:
mode:
authorAlexander <akutsan@luxoft.com>2018-06-08 11:00:26 +0300
committerAlexander <akutsan@luxoft.com>2018-06-11 13:30:58 +0300
commit7068453fe5919c8379cd0deb6fd9c077313a70e5 (patch)
treefc1c25622985a37acefa83f4d4d27736c1ea3ecb /src/components/transport_manager/src/tcp
parentb760faf707b7210765eb0defa785ee1c429b0523 (diff)
downloadsdl_core-7068453fe5919c8379cd0deb6fd9c077313a70e5.tar.gz
Use Pimple idiom for Network Interface Listener
Create `qnx` and `linux` folder with platform specific code. Moved implementation from network_interface_listener_impl to platform_specific/linux/platform_specific_network_interface_listener_impl QNX contains empty implementation Renamed source files : used cc file extension for source files
Diffstat (limited to 'src/components/transport_manager/src/tcp')
-rw-r--r--src/components/transport_manager/src/tcp/network_interface_listener_impl.cc74
-rw-r--r--src/components/transport_manager/src/tcp/platform_specific/linux/platform_specific_network_interface_listener.cc (renamed from src/components/transport_manager/src/tcp/network_interface_listener_impl.cpp)55
-rw-r--r--src/components/transport_manager/src/tcp/platform_specific/qnx/platform_specific_network_interface_listener.cc69
3 files changed, 172 insertions, 26 deletions
diff --git a/src/components/transport_manager/src/tcp/network_interface_listener_impl.cc b/src/components/transport_manager/src/tcp/network_interface_listener_impl.cc
new file mode 100644
index 0000000000..e362ee8a73
--- /dev/null
+++ b/src/components/transport_manager/src/tcp/network_interface_listener_impl.cc
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 2018 Xevo Inc.
+ * 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 names of the copyright holders 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.
+ */
+
+#include "transport_manager/tcp/network_interface_listener_impl.h"
+#include "platform_specific_network_interface_listener_impl.h"
+
+namespace transport_manager {
+namespace transport_adapter {
+
+CREATE_LOGGERPTR_GLOBAL(logger_, "TransportManager")
+
+NetworkInterfaceListenerImpl::NetworkInterfaceListenerImpl(
+ TcpClientListener* tcp_client_listener,
+ const std::string designated_interface)
+ : platform_specific_impl_(new PlatformSpecificNetworkInterfaceListener(
+ tcp_client_listener, designated_interface)) {
+ LOG4CXX_AUTO_TRACE(logger_);
+}
+
+NetworkInterfaceListenerImpl::~NetworkInterfaceListenerImpl() {
+ LOG4CXX_AUTO_TRACE(logger_);
+}
+
+bool NetworkInterfaceListenerImpl::Init() {
+ LOG4CXX_AUTO_TRACE(logger_);
+ return platform_specific_impl_->Init();
+}
+
+void NetworkInterfaceListenerImpl::Deinit() {
+ LOG4CXX_AUTO_TRACE(logger_);
+ platform_specific_impl_->Deinit();
+}
+
+bool NetworkInterfaceListenerImpl::Start() {
+ LOG4CXX_AUTO_TRACE(logger_);
+ return platform_specific_impl_->Start();
+}
+
+bool NetworkInterfaceListenerImpl::Stop() {
+ LOG4CXX_AUTO_TRACE(logger_);
+ return platform_specific_impl_->Stop();
+}
+
+} // namespace transport_adapter
+} // namespace transport_manager
diff --git a/src/components/transport_manager/src/tcp/network_interface_listener_impl.cpp b/src/components/transport_manager/src/tcp/platform_specific/linux/platform_specific_network_interface_listener.cc
index bcf5e21387..4669edd7b4 100644
--- a/src/components/transport_manager/src/tcp/network_interface_listener_impl.cpp
+++ b/src/components/transport_manager/src/tcp/platform_specific/linux/platform_specific_network_interface_listener.cc
@@ -30,7 +30,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-#include "transport_manager/tcp/network_interface_listener_impl.h"
+#include "transport_manager/tcp/platform_specific/linux/platform_specific_network_interface_listener_impl.h"
#include <arpa/inet.h>
#include <asm/types.h>
@@ -42,10 +42,9 @@
#include <sys/types.h>
#include <sys/select.h>
#include <sys/socket.h>
-#ifdef __linux__
+
#include <linux/netlink.h>
#include <linux/rtnetlink.h>
-#endif // __linux__
#include "transport_manager/tcp/tcp_client_listener.h"
#include "utils/logger.h"
@@ -106,9 +105,10 @@ void InterfaceStatus::SetIPv6Address(struct in6_addr* addr) {
}
}
-NetworkInterfaceListenerImpl::NetworkInterfaceListenerImpl(
- TcpClientListener* tcp_client_listener,
- const std::string designated_interface)
+PlatformSpecificNetworkInterfaceListener::
+ PlatformSpecificNetworkInterfaceListener(
+ TcpClientListener* tcp_client_listener,
+ const std::string designated_interface)
: tcp_client_listener_(tcp_client_listener)
, designated_interface_(designated_interface)
, selected_interface_("")
@@ -120,11 +120,12 @@ NetworkInterfaceListenerImpl::NetworkInterfaceListenerImpl(
#endif // BUILD_TESTS
{
pipe_fds_[0] = pipe_fds_[1] = -1;
- thread_ = threads::CreateThread("NetworkInterfaceListenerImpl",
+ thread_ = threads::CreateThread("PlatformSpecificNetworkInterfaceListener",
new ListenerThreadDelegate(this));
}
-NetworkInterfaceListenerImpl::~NetworkInterfaceListenerImpl() {
+PlatformSpecificNetworkInterfaceListener::
+ ~PlatformSpecificNetworkInterfaceListener() {
LOG4CXX_AUTO_TRACE(logger_);
Stop();
@@ -134,7 +135,7 @@ NetworkInterfaceListenerImpl::~NetworkInterfaceListenerImpl() {
threads::DeleteThread(thread_);
}
-bool NetworkInterfaceListenerImpl::Init() {
+bool PlatformSpecificNetworkInterfaceListener::Init() {
LOG4CXX_AUTO_TRACE(logger_);
if (socket_ >= 0) {
@@ -180,7 +181,7 @@ bool NetworkInterfaceListenerImpl::Init() {
return true;
}
-void NetworkInterfaceListenerImpl::Deinit() {
+void PlatformSpecificNetworkInterfaceListener::Deinit() {
LOG4CXX_AUTO_TRACE(logger_);
if (socket_ >= 0) {
@@ -197,7 +198,7 @@ void NetworkInterfaceListenerImpl::Deinit() {
}
}
-bool NetworkInterfaceListenerImpl::Start() {
+bool PlatformSpecificNetworkInterfaceListener::Start() {
LOG4CXX_AUTO_TRACE(logger_);
if (socket_ < 0) {
@@ -219,7 +220,7 @@ bool NetworkInterfaceListenerImpl::Start() {
return true;
}
-bool NetworkInterfaceListenerImpl::Stop() {
+bool PlatformSpecificNetworkInterfaceListener::Stop() {
LOG4CXX_AUTO_TRACE(logger_);
if (!thread_->is_running()) {
@@ -233,7 +234,7 @@ bool NetworkInterfaceListenerImpl::Stop() {
return true;
}
-void NetworkInterfaceListenerImpl::Loop() {
+void PlatformSpecificNetworkInterfaceListener::Loop() {
LOG4CXX_AUTO_TRACE(logger_);
InitializeStatus();
@@ -337,7 +338,7 @@ void NetworkInterfaceListenerImpl::Loop() {
}
}
-bool NetworkInterfaceListenerImpl::StopLoop() {
+bool PlatformSpecificNetworkInterfaceListener::StopLoop() {
LOG4CXX_AUTO_TRACE(logger_);
LOG4CXX_INFO(logger_, "Stopping network interface listener");
@@ -358,7 +359,7 @@ bool NetworkInterfaceListenerImpl::StopLoop() {
return true;
}
-bool NetworkInterfaceListenerImpl::InitializeStatus() {
+bool PlatformSpecificNetworkInterfaceListener::InitializeStatus() {
LOG4CXX_AUTO_TRACE(logger_);
#ifdef BUILD_TESTS
@@ -417,7 +418,7 @@ bool NetworkInterfaceListenerImpl::InitializeStatus() {
return true;
}
-bool NetworkInterfaceListenerImpl::UpdateStatus(
+bool PlatformSpecificNetworkInterfaceListener::UpdateStatus(
uint16_t type, std::vector<EventParam>& params) {
LOG4CXX_AUTO_TRACE(logger_);
@@ -486,7 +487,7 @@ bool NetworkInterfaceListenerImpl::UpdateStatus(
return true;
}
-void NetworkInterfaceListenerImpl::NotifyIPAddresses() {
+void PlatformSpecificNetworkInterfaceListener::NotifyIPAddresses() {
LOG4CXX_AUTO_TRACE(logger_);
std::string ipv4_addr;
@@ -519,7 +520,7 @@ void NetworkInterfaceListenerImpl::NotifyIPAddresses() {
}
}
-const std::string NetworkInterfaceListenerImpl::SelectInterface() {
+const std::string PlatformSpecificNetworkInterfaceListener::SelectInterface() {
LOG4CXX_AUTO_TRACE(logger_);
if (!designated_interface_.empty()) {
@@ -562,9 +563,9 @@ const std::string NetworkInterfaceListenerImpl::SelectInterface() {
return selected_interface_;
}
-std::vector<NetworkInterfaceListenerImpl::EventParam>
-NetworkInterfaceListenerImpl::ParseIFAddrMessage(struct ifaddrmsg* message,
- unsigned int size) {
+std::vector<PlatformSpecificNetworkInterfaceListener::EventParam>
+PlatformSpecificNetworkInterfaceListener::ParseIFAddrMessage(
+ struct ifaddrmsg* message, unsigned int size) {
LOG4CXX_AUTO_TRACE(logger_);
std::vector<EventParam> params;
@@ -619,7 +620,7 @@ NetworkInterfaceListenerImpl::ParseIFAddrMessage(struct ifaddrmsg* message,
return params;
}
-void NetworkInterfaceListenerImpl::DumpTable() const {
+void PlatformSpecificNetworkInterfaceListener::DumpTable() const {
LOG4CXX_DEBUG(logger_,
"Number of network interfaces: " << status_table_.size());
@@ -637,15 +638,17 @@ void NetworkInterfaceListenerImpl::DumpTable() const {
}
}
-NetworkInterfaceListenerImpl::ListenerThreadDelegate::ListenerThreadDelegate(
- NetworkInterfaceListenerImpl* parent)
+PlatformSpecificNetworkInterfaceListener::ListenerThreadDelegate::
+ ListenerThreadDelegate(PlatformSpecificNetworkInterfaceListener* parent)
: parent_(parent) {}
-void NetworkInterfaceListenerImpl::ListenerThreadDelegate::threadMain() {
+void PlatformSpecificNetworkInterfaceListener::ListenerThreadDelegate::
+ threadMain() {
parent_->Loop();
}
-void NetworkInterfaceListenerImpl::ListenerThreadDelegate::exitThreadMain() {
+void PlatformSpecificNetworkInterfaceListener::ListenerThreadDelegate::
+ exitThreadMain() {
parent_->StopLoop();
}
diff --git a/src/components/transport_manager/src/tcp/platform_specific/qnx/platform_specific_network_interface_listener.cc b/src/components/transport_manager/src/tcp/platform_specific/qnx/platform_specific_network_interface_listener.cc
new file mode 100644
index 0000000000..9ca7890278
--- /dev/null
+++ b/src/components/transport_manager/src/tcp/platform_specific/qnx/platform_specific_network_interface_listener.cc
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2018 Xevo Inc.
+ * 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 names of the copyright holders 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.
+ */
+#include "transport_manager/tcp/platform_specific/qnx/platform_specific_network_interface_listener_impl.h"
+
+namespace transport_manager {
+namespace transport_adapter {
+
+CREATE_LOGGERPTR_GLOBAL(logger_, "TransportManager")
+
+PlatformSpecificNetworkInterfaceListener::
+ PlatformSpecificNetworkInterfaceListener(
+ TcpClientListener* tcp_client_listener,
+ const std::string designated_interface) {}
+
+PlatformSpecificNetworkInterfaceListener::
+ ~PlatformSpecificNetworkInterfaceListener() {
+ LOG4CXX_AUTO_TRACE(logger_);
+}
+
+bool PlatformSpecificNetworkInterfaceListener::Init() {
+ LOG4CXX_AUTO_TRACE(logger_);
+ return true;
+}
+
+void PlatformSpecificNetworkInterfaceListener::Deinit() {
+ LOG4CXX_AUTO_TRACE(logger_);
+}
+
+bool PlatformSpecificNetworkInterfaceListener::Start() {
+ LOG4CXX_AUTO_TRACE(logger_);
+ return true;
+}
+
+bool PlatformSpecificNetworkInterfaceListener::Stop() {
+ LOG4CXX_AUTO_TRACE(logger_);
+ return true;
+}
+
+} // namespace transport_adapter
+} // namespace transport_manager