diff options
-rw-r--r-- | CMakeLists.txt | 10 | ||||
-rw-r--r-- | cmake/Modules/FindLibavahi.cmake | 29 | ||||
-rw-r--r-- | src/appMain/CMakeLists.txt | 3 | ||||
-rw-r--r-- | src/components/time_tester/test/CMakeLists.txt | 4 | ||||
-rw-r--r-- | src/components/transport_manager/CMakeLists.txt | 10 | ||||
-rw-r--r-- | src/components/transport_manager/include/transport_manager/tcp/dnssd_service_browser.h | 144 | ||||
-rw-r--r-- | src/components/transport_manager/src/tcp/dnssd_service_browser.cc | 378 | ||||
-rw-r--r-- | src/components/transport_manager/src/tcp/tcp_transport_adapter.cc | 8 | ||||
-rw-r--r-- | src/components/transport_manager/test/CMakeLists.txt | 5 | ||||
-rw-r--r-- | src/components/transport_manager/test/dnssd_service_browser_test.cc | 147 |
10 files changed, 0 insertions, 738 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index d50c1e239c..b265c8a076 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,7 +40,6 @@ option(EXTENDED_MEDIA_MODE "Turn on and off extended Madia Manager features rela option(BUILD_SHARED_LIBS "Build all libraries as shared (if ON) or static (if OFF)" OFF) option(BUILD_BT_SUPPORT "Bluetooth support" ON) option(BUILD_USB_SUPPORT "libusb support" ON) -option(BUILD_AVAHI_SUPPORT "libavahi support" ON) option(BUILD_BACKTRACE_SUPPORT "backtrace support" ON) option(BUILD_TESTS "Possibility to build and run tests" OFF) option(TIME_TESTER "Enable profiling time test util" ON) @@ -198,7 +197,6 @@ if (CMAKE_SYSTEM_NAME STREQUAL "Linux") elseif(CMAKE_SYSTEM_NAME STREQUAL "QNX") add_definitions(-DOS_QNX) SET(BUILD_BT_SUPPORT OFF) - SET(BUILD_AVAHI_SUPPORT OFF) SET(BUILD_BACKTRACE_SUPPORT OFF) SET(EXTENDED_MEDIA_MODE OFF) endif() @@ -215,14 +213,6 @@ if (BUILD_BT_SUPPORT) message(STATUS "Bluetooth support is enabled") endif() - -if (BUILD_AVAHI_SUPPORT) - add_definitions(-DAVAHI_SUPPORT) -# --- Check libavahi-common, libavahi-client availability - find_package(Libavahi) - message(STATUS "Avahi support is enabled") -endif() - if (BUILD_BACKTRACE_SUPPORT) add_definitions(-DBACKTRACE_SUPPORT) endif() diff --git a/cmake/Modules/FindLibavahi.cmake b/cmake/Modules/FindLibavahi.cmake deleted file mode 100644 index 2bc9055059..0000000000 --- a/cmake/Modules/FindLibavahi.cmake +++ /dev/null @@ -1,29 +0,0 @@ -# --- Check libavahi-common, libavahi-client availability - -FIND_LIBRARY( - LIBAVAHI_CLIENT - NAMES libavahi-client.so - PATHS /usr/local/lib /usr/lib /opt/local/include /usr/lib/i386-linux-gnu/ - ) - -if (NOT LIBAVAHI_CLIENT) - message(STATUS " libavahi-client is not found") - message(STATUS " To install it type in the command line:") - message(STATUS " sudo apt-get install libavahi-client-dev") -endif (NOT LIBAVAHI_CLIENT) - -FIND_LIBRARY( - LIBAVAHI_COMMON - NAMES libavahi-common.so - PATHS /usr/local/lib /usr/lib /opt/local/include /usr/lib/i386-linux-gnu/ - ) - -if (NOT LIBAVAHI_COMMON) - message(STATUS " libavahi-common is not found") - message(STATUS " To install it type in the command line:") - message(STATUS " sudo apt-get install libavahi-common-dev") -endif (NOT LIBAVAHI_COMMON) - -if (NOT LIBAVAHI_COMMON OR NOT LIBAVAHI_CLIENT) - message(FATAL_ERROR "One of necesary component of libavahi is not found. Exiting!") -endif(NOT LIBAVAHI_COMMON OR NOT LIBAVAHI_CLIENT)
\ No newline at end of file diff --git a/src/appMain/CMakeLists.txt b/src/appMain/CMakeLists.txt index d347b7175f..41bc6ba281 100644 --- a/src/appMain/CMakeLists.txt +++ b/src/appMain/CMakeLists.txt @@ -88,9 +88,6 @@ endif() if (BUILD_BT_SUPPORT) list(APPEND LIBRARIES bluetooth) endif() -if (BUILD_AVAHI_SUPPORT) - list(APPEND LIBRARIES avahi-client avahi-common) -endif() if (BUILD_USB_SUPPORT) if (CMAKE_SYSTEM_NAME STREQUAL "Linux") list(APPEND LIBRARIES Libusb-1.0.16) diff --git a/src/components/time_tester/test/CMakeLists.txt b/src/components/time_tester/test/CMakeLists.txt index c278e94c90..4f83e6597a 100644 --- a/src/components/time_tester/test/CMakeLists.txt +++ b/src/components/time_tester/test/CMakeLists.txt @@ -83,10 +83,6 @@ if (BUILD_BT_SUPPORT) list(APPEND testLibraries bluetooth) endif() -if (BUILD_AVAHI_SUPPORT) - list(APPEND testLibraries avahi-client avahi-common) -endif() - file(COPY log4cxx.properties DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) create_test("time_tester_test" "${testSources}" "${testLibraries}") diff --git a/src/components/transport_manager/CMakeLists.txt b/src/components/transport_manager/CMakeLists.txt index 764f1cdafa..fbe6018d6a 100644 --- a/src/components/transport_manager/CMakeLists.txt +++ b/src/components/transport_manager/CMakeLists.txt @@ -60,11 +60,6 @@ set (SOURCES ${TM_SRC_DIR}/tcp/tcp_connection_factory.cc ) -if (BUILD_AVAHI_SUPPORT) - list (APPEND SOURCES - ${TM_SRC_DIR}/tcp/dnssd_service_browser.cc - ) -endif() if (BUILD_BT_SUPPORT) list (APPEND SOURCES ${TM_SRC_DIR}/bluetooth/bluetooth_device_scanner.cc @@ -109,11 +104,6 @@ if (BUILD_USB_SUPPORT) endif() endif(BUILD_USB_SUPPORT) - -if (BUILD_AVAHI_SUPPORT) - target_link_libraries(${target} avahi-common) -endif() - if(ENABLE_LOG) target_link_libraries(${target} log4cxx -L${LOG4CXX_LIBS_DIRECTORY}) endif() 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 23327efbf0..0000000000 --- a/src/components/transport_manager/include/transport_manager/tcp/dnssd_service_browser.h +++ /dev/null @@ -1,144 +0,0 @@ -/* - * \file dnssd_service_browser.h - * \brief DnssdServiceBrowser class header file. - * - * Copyright (c) 2015, 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(); - - virtual TransportAdapter::Error Init(); - virtual TransportAdapter::Error Scan(); - virtual void Terminate(); - virtual bool IsInitialised() const; - -#ifdef BUILD_TESTS - AvahiServiceBrowser* avahi_service_browser() const { - return avahi_service_browser_; - } - AvahiThreadedPoll* avahi_threaded_poll() const { - return avahi_threaded_poll_; - } - AvahiClient* avahi_client() const { return avahi_client_; } -#endif // BUILD_TESTS - - 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/src/tcp/dnssd_service_browser.cc b/src/components/transport_manager/src/tcp/dnssd_service_browser.cc deleted file mode 100644 index 3571ac8156..0000000000 --- a/src/components/transport_manager/src/tcp/dnssd_service_browser.cc +++ /dev/null @@ -1,378 +0,0 @@ -/* - * - * 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. - */ - -#include <algorithm> -#include <map> -#include "utils/logger.h" - -#include "transport_manager/transport_adapter/transport_adapter_impl.h" -#include "transport_manager/tcp/tcp_device.h" -#include "transport_manager/tcp/dnssd_service_browser.h" - - -namespace transport_manager { -namespace transport_adapter { - -CREATE_LOGGERPTR_GLOBAL(logger_, "TransportManager") - - -bool operator==(const DnssdServiceRecord& a, const DnssdServiceRecord& b) { - return a.name == b.name && a.type == b.type && a.interface == b.interface - && a.protocol == b.protocol && a.domain_name == b.domain_name; -} - -void DnssdServiceBrowser::Terminate() { - LOG4CXX_AUTO_TRACE(logger_); - if (0 != avahi_threaded_poll_) { - avahi_threaded_poll_stop(avahi_threaded_poll_); - } - if (0 != avahi_service_browser_) { - avahi_service_browser_free(avahi_service_browser_); - avahi_service_browser_ = NULL; - } - if (0 != avahi_client_) { - avahi_client_free(avahi_client_); - avahi_client_ = NULL; - } - if (0 != avahi_threaded_poll_) { - avahi_threaded_poll_free(avahi_threaded_poll_); - avahi_threaded_poll_ = NULL; - } -} - -bool DnssdServiceBrowser::IsInitialised() const { - return initialised_; -} - -DnssdServiceBrowser::DnssdServiceBrowser(TransportAdapterController* controller) - : controller_(controller), - avahi_service_browser_(0), - avahi_threaded_poll_(0), - avahi_client_(0), - service_records_(), - mutex_(), - initialised_(false) { -} - -DnssdServiceBrowser::~DnssdServiceBrowser() { -} - -void DnssdServiceBrowser::OnClientConnected() { - initialised_ = true; - LOG4CXX_INFO(logger_, "AvahiClient ready"); -} - -void DnssdServiceBrowser::OnClientFailure() { - LOG4CXX_AUTO_TRACE(logger_); - const int avahi_errno = avahi_client_errno(avahi_client_); - if (avahi_errno == AVAHI_ERR_DISCONNECTED) { - LOG4CXX_DEBUG(logger_, "AvahiClient disconnected"); - CreateAvahiClientAndBrowser(); - } else { - LOG4CXX_ERROR(logger_, - "AvahiClient failure: " << avahi_strerror(avahi_errno)); - } -} - -void AvahiClientCallback(AvahiClient* avahi_client, - AvahiClientState avahi_client_state, void* data) { - LOG4CXX_AUTO_TRACE(logger_); - LOG4CXX_DEBUG( - logger_, - "avahi_client " << avahi_client << ", avahi_client_state " << avahi_client_state << ", data " << data); - DnssdServiceBrowser* dnssd_service_browser = - static_cast<DnssdServiceBrowser*>(data); - - switch (avahi_client_state) { - case AVAHI_CLIENT_S_RUNNING: - dnssd_service_browser->OnClientConnected(); - LOG4CXX_DEBUG(logger_, "avahi_client_state: AVAHI_CLIENT_S_RUNNING"); - break; - case AVAHI_CLIENT_FAILURE: - dnssd_service_browser->OnClientFailure(); - LOG4CXX_DEBUG(logger_, "avahi_client_state: AVAHI_CLIENT_FAILURE"); - break; - default: { - LOG4CXX_ERROR(logger_, - "Unknown avahi_client_state: " << avahi_client_state); - } - } -} - -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) { - LOG4CXX_AUTO_TRACE(logger_); - LOG4CXX_DEBUG( - logger_, - "avahi_service_browser " << avahi_service_browser << " interface " << interface << - " protocol " << protocol << " event " << event << " name " << name << - " type " << type << " domain " << domain << " flags " << flags << " data " << data); - DnssdServiceBrowser* dnssd_service_browser = - static_cast<DnssdServiceBrowser*>(data); - - switch (event) { - case AVAHI_BROWSER_FAILURE: - LOG4CXX_ERROR( - logger_, - "AvahiServiceBrowser failure: " << avahi_strerror(avahi_client_errno( - avahi_service_browser_get_client(avahi_service_browser)))); - break; - - case AVAHI_BROWSER_NEW: - dnssd_service_browser->AddService(interface, protocol, name, type, - domain); - LOG4CXX_DEBUG(logger_, "event: AVAHI_BROWSER_NEW"); - break; - - case AVAHI_BROWSER_REMOVE: - dnssd_service_browser->RemoveService(interface, protocol, name, type, - domain); - LOG4CXX_DEBUG(logger_, "event: AVAHI_BROWSER_REMOVE"); - break; - - case AVAHI_BROWSER_ALL_FOR_NOW: - LOG4CXX_DEBUG(logger_, "event: AVAHI_BROWSER_ALL_FOR_NOW"); - break; - case AVAHI_BROWSER_CACHE_EXHAUSTED: - LOG4CXX_DEBUG(logger_, "event: AVAHI_BROWSER_CACHE_EXHAUSTED"); - break; - } - LOG4CXX_TRACE(logger_, "exit"); -} - -void DnssdServiceBrowser::ServiceResolved( - const DnssdServiceRecord& service_record) { - LOG4CXX_AUTO_TRACE(logger_); - sync_primitives::AutoLock locker(mutex_); - ServiceRecords::iterator service_record_it = std::find( - service_records_.begin(), service_records_.end(), service_record); - if (service_record_it != service_records_.end()) { - *service_record_it = service_record; - } - DeviceVector device_vector = PrepareDeviceVector(); - controller_->SearchDeviceDone(device_vector); -} - -void DnssdServiceBrowser::ServiceResolveFailed( - const DnssdServiceRecord& service_record) { - LOG4CXX_AUTO_TRACE(logger_); - LOG4CXX_DEBUG(logger_, - "AvahiServiceResolver failure for: " << service_record.name); - sync_primitives::AutoLock locker(mutex_); - ServiceRecords::iterator service_record_it = std::find( - service_records_.begin(), service_records_.end(), service_record); - if (service_record_it != service_records_.end()) { - service_records_.erase(service_record_it); - } -} - -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) { - LOG4CXX_AUTO_TRACE(logger_); - LOG4CXX_DEBUG( - logger_, - "avahi_service_resolver " << avahi_service_resolver << " interface " << interface << - " protocol " << protocol << " event " << event << " name " << name << - " type " << type << " domain " << domain << " host_name " << host_name << - " avahi_address " << avahi_address << " port " << port << - " txt " << txt << " flags " << flags << " data " << data); - DnssdServiceBrowser* dnssd_service_browser = - static_cast<DnssdServiceBrowser*>(data); - - DnssdServiceRecord service_record; - service_record.interface = interface; - service_record.protocol = protocol; - service_record.domain_name = domain; - service_record.host_name = host_name; - service_record.name = name; - service_record.type = type; - switch (event) { - case AVAHI_RESOLVER_FOUND: - service_record.addr = avahi_address->data.ipv4.address; - service_record.port = port; - dnssd_service_browser->ServiceResolved(service_record); - LOG4CXX_DEBUG(logger_, "event: AVAHI_RESOLVER_FOUND"); - break; - case AVAHI_RESOLVER_FAILURE: - dnssd_service_browser->ServiceResolveFailed(service_record); - LOG4CXX_DEBUG(logger_, "event: AVAHI_RESOLVER_FAILURE"); - break; - } - - avahi_service_resolver_free(avahi_service_resolver); -} - -TransportAdapter::Error DnssdServiceBrowser::CreateAvahiClientAndBrowser() { - LOG4CXX_AUTO_TRACE(logger_); - if (0 != avahi_service_browser_) { - avahi_service_browser_free(avahi_service_browser_); - avahi_service_browser_ = NULL; - } - if (0 != avahi_client_) { - avahi_client_free(avahi_client_); - avahi_client_ = NULL; - } - - int avahi_error; - avahi_client_ = avahi_client_new( - avahi_threaded_poll_get(avahi_threaded_poll_), AVAHI_CLIENT_NO_FAIL, - AvahiClientCallback, this, &avahi_error); - if (0 == avahi_client_) { - LOG4CXX_ERROR( - logger_, - "Failed to create AvahiClient: " << avahi_strerror(avahi_error)); - return TransportAdapter::FAIL; - } - - mutex_.Acquire(); - service_records_.clear(); - mutex_.Release(); - - avahi_service_browser_ = avahi_service_browser_new( - avahi_client_, AVAHI_IF_UNSPEC, /* TODO use only required iface */ - AVAHI_PROTO_INET, DNSSD_DEFAULT_SERVICE_TYPE, NULL, /* use default domain */ - static_cast<AvahiLookupFlags>(0), AvahiServiceBrowserCallback, this); - return TransportAdapter::OK; -} - -TransportAdapter::Error DnssdServiceBrowser::Init() { - LOG4CXX_AUTO_TRACE(logger_); - avahi_threaded_poll_ = avahi_threaded_poll_new(); - if (0 == avahi_threaded_poll_) { - LOG4CXX_ERROR(logger_, "Failed to create AvahiThreadedPoll"); - return TransportAdapter::FAIL; - } - - const TransportAdapter::Error err = CreateAvahiClientAndBrowser(); - if (err != TransportAdapter::OK) { - LOG4CXX_ERROR(logger_, "Error " << err); - return err; - } - - const int poll_start_status = avahi_threaded_poll_start(avahi_threaded_poll_); - if (0 != poll_start_status) { - LOG4CXX_ERROR(logger_, "Failed to start AvahiThreadedPoll"); - return TransportAdapter::FAIL; - } - return TransportAdapter::OK; -} - -TransportAdapter::Error DnssdServiceBrowser::Scan() { - return TransportAdapter::NOT_SUPPORTED; -} - -void DnssdServiceBrowser::AddService(AvahiIfIndex interface, - AvahiProtocol protocol, const char* name, - const char* type, const char* domain) { - LOG4CXX_AUTO_TRACE(logger_); - LOG4CXX_DEBUG( - logger_, - "interface " << interface << " protocol " << protocol << " name " << name << " type " << type << " domain " << domain); - DnssdServiceRecord record; - record.interface = interface; - record.protocol = protocol; - record.domain_name = domain; - record.name = name; - record.type = type; - - sync_primitives::AutoLock locker(mutex_); - if (service_records_.end() - == std::find(service_records_.begin(), service_records_.end(), record)) { - service_records_.push_back(record); - avahi_service_resolver_new(avahi_client_, interface, protocol, name, type, - domain, AVAHI_PROTO_INET, - static_cast<AvahiLookupFlags>(0), - AvahiServiceResolverCallback, this); - } -} - -void DnssdServiceBrowser::RemoveService(AvahiIfIndex interface, - AvahiProtocol protocol, - const char* name, const char* type, - const char* domain) { - LOG4CXX_AUTO_TRACE(logger_); - LOG4CXX_DEBUG( - logger_, - "interface " << interface << " protocol " << protocol << " name " << name << " type " << type << " domain " << domain); - DnssdServiceRecord record; - record.interface = interface; - record.protocol = protocol; - record.name = name; - record.type = type; - record.domain_name = domain; - - sync_primitives::AutoLock locker(mutex_); - service_records_.erase( - std::remove(service_records_.begin(), service_records_.end(), record), - service_records_.end()); -} - -DeviceVector DnssdServiceBrowser::PrepareDeviceVector() const { - LOG4CXX_AUTO_TRACE(logger_); - std::map<uint32_t, TcpDevice*> devices; - for (ServiceRecords::const_iterator it = service_records_.begin(); - it != service_records_.end(); ++it) { - const DnssdServiceRecord& service_record = *it; - if (service_record.host_name.empty()) { - continue; - } - if (devices[service_record.addr] == 0) { - devices[service_record.addr] = new TcpDevice(service_record.addr, - service_record.host_name); - } - if (devices[service_record.addr] != 0) { - devices[service_record.addr]->AddDiscoveredApplication( - service_record.port); - } - } - DeviceVector device_vector; - device_vector.reserve(devices.size()); - for (std::map<uint32_t, TcpDevice*>::const_iterator it = devices.begin(); - it != devices.end(); ++it) { - device_vector.push_back(DeviceSptr(it->second)); - } - return device_vector; -} - -} // namespace transport_adapter -} // namespace transport_manager diff --git a/src/components/transport_manager/src/tcp/tcp_transport_adapter.cc b/src/components/transport_manager/src/tcp/tcp_transport_adapter.cc index a0f3decec1..b7f52ff4a6 100644 --- a/src/components/transport_manager/src/tcp/tcp_transport_adapter.cc +++ b/src/components/transport_manager/src/tcp/tcp_transport_adapter.cc @@ -47,10 +47,6 @@ #include "transport_manager/tcp/tcp_connection_factory.h" #include "transport_manager/tcp/tcp_device.h" -#ifdef AVAHI_SUPPORT -#include "transport_manager/tcp/dnssd_service_browser.h" -#endif - namespace transport_manager { namespace transport_adapter { @@ -58,11 +54,7 @@ CREATE_LOGGERPTR_GLOBAL(logger_, "TransportManager") TcpTransportAdapter::TcpTransportAdapter(const uint16_t port) : TransportAdapterImpl( -#ifdef AVAHI_SUPPORT - new DnssdServiceBrowser(this), -#else NULL, -#endif new TcpConnectionFactory(this), new TcpClientListener(this, port, true)) { } diff --git a/src/components/transport_manager/test/CMakeLists.txt b/src/components/transport_manager/test/CMakeLists.txt index dc219424a7..5a149f3063 100644 --- a/src/components/transport_manager/test/CMakeLists.txt +++ b/src/components/transport_manager/test/CMakeLists.txt @@ -62,14 +62,9 @@ if (BUILD_BT_SUPPORT) list(APPEND LIBRARIES bluetooth) endif() -if (BUILD_AVAHI_SUPPORT) - list(APPEND LIBRARIES avahi-client avahi-common) -endif() - set(SOURCES ${TM_TEST_DIR}/transport_manager_default_test.cc ${TM_TEST_DIR}/transport_manager_impl_test.cc - #${TM_TEST_DIR}/dnssd_service_browser_test.cc ${TM_TEST_DIR}/transport_adapter_test.cc ${TM_TEST_DIR}/transport_adapter_listener_test.cc ${TM_TEST_DIR}/tcp_transport_adapter_test.cc diff --git a/src/components/transport_manager/test/dnssd_service_browser_test.cc b/src/components/transport_manager/test/dnssd_service_browser_test.cc deleted file mode 100644 index 6eb2ad45f6..0000000000 --- a/src/components/transport_manager/test/dnssd_service_browser_test.cc +++ /dev/null @@ -1,147 +0,0 @@ -/* - * Copyright (c) 2015, 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. - */ - -#include "gmock/gmock.h" - -#include "transport_manager/transport_adapter/transport_adapter_controller.h" -#include "transport_manager/tcp/dnssd_service_browser.h" - -namespace transport_manager { -namespace transport_adapter { - -class MockTransportAdapterController : public TransportAdapterController { - public: - MOCK_METHOD1(AddDevice, DeviceSptr(DeviceSptr device)); - MOCK_METHOD1(SearchDeviceDone, void(const DeviceVector& devices)); - MOCK_METHOD1(SearchDeviceFailed, void(const SearchDeviceError& error)); - MOCK_CONST_METHOD1(FindDevice, DeviceSptr(const DeviceUID& device_handle)); - MOCK_METHOD3(ConnectionCreated, - void(ConnectionSPtr connection, const DeviceUID& device_handle, - const ApplicationHandle& app_handle)); - MOCK_METHOD2(ConnectDone, void(const DeviceUID& device_handle, - const ApplicationHandle& app_handle)); - MOCK_METHOD3(ConnectFailed, void(const DeviceUID& device_handle, - const ApplicationHandle& app_handle, - const ConnectError& error)); - MOCK_METHOD2(ConnectionFinished, void(const DeviceUID& device_handle, - const ApplicationHandle& app_handle)); - MOCK_METHOD3(ConnectionAborted, void(const DeviceUID& device_handle, - const ApplicationHandle& app_handle, - const CommunicationError& error)); - MOCK_METHOD2(DisconnectDone, void(const DeviceUID& device_handle, - const ApplicationHandle& app_handle)); - MOCK_METHOD3(DataReceiveDone, - void(const DeviceUID& device_handle, - const ApplicationHandle& app_handle, - const ::protocol_handler::RawMessagePtr message)); - MOCK_METHOD3(DataReceiveFailed, void(const DeviceUID& device_handle, - const ApplicationHandle& app_handle, - const DataReceiveError& error)); - MOCK_METHOD3(DataSendDone, - void(const DeviceUID& device_handle, - const ApplicationHandle& app_handle, - const ::protocol_handler::RawMessagePtr message)); - MOCK_METHOD4(DataSendFailed, - void(const DeviceUID& device_handle, - const ApplicationHandle& app_handle, - const ::protocol_handler::RawMessagePtr message, - const DataSendError& error)); - MOCK_METHOD0(FindNewApplicationsRequest, void()); - MOCK_METHOD0(AckDevices, void()); - MOCK_METHOD1(ApplicationListUpdated, void(const DeviceUID& device_handle)); - MOCK_METHOD2(DeviceDisconnected, void(const DeviceUID& device_handle, - const DisconnectDeviceError& error)); -}; - -TEST(DnssdServiceBrowser, DISABLED_Init) { - // Arrange - MockTransportAdapterController controller; - DnssdServiceBrowser dnssd_service_browser(&controller); - // Check values after creation. Nothing is initialized - EXPECT_TRUE(NULL == dnssd_service_browser.avahi_service_browser()); - EXPECT_TRUE(NULL == dnssd_service_browser.avahi_threaded_poll()); - EXPECT_TRUE(NULL == dnssd_service_browser.avahi_client()); - // Act - const TransportAdapter::Error error = dnssd_service_browser.Init(); - ASSERT_EQ(TransportAdapter::OK, error); - - while (!dnssd_service_browser.IsInitialised()) { - sleep(0); - } - ASSERT_TRUE(dnssd_service_browser.IsInitialised()); - // Check values are initialized and threaded poll started - EXPECT_FALSE(NULL == dnssd_service_browser.avahi_service_browser()); - EXPECT_FALSE(NULL == dnssd_service_browser.avahi_threaded_poll()); - EXPECT_FALSE(NULL == dnssd_service_browser.avahi_client()); -} - -TEST(DnssdServiceBrowser, DISABLED_IsInitialized_ExpectFalse) { - // Arrange - MockTransportAdapterController controller; - DnssdServiceBrowser dnssd_service_browser(&controller); - // Check - EXPECT_FALSE(dnssd_service_browser.IsInitialised()); -} - -TEST(DnssdServiceBrowser, DISABLED_Terminate_ExpectTerminated) { - // Arrange - MockTransportAdapterController controller; - DnssdServiceBrowser dnssd_service_browser(&controller); - // Init service browser and client - const TransportAdapter::Error error = dnssd_service_browser.Init(); - ASSERT_EQ(TransportAdapter::OK, error); - - while (!dnssd_service_browser.IsInitialised()) { - sleep(0); - } - ASSERT_TRUE(dnssd_service_browser.IsInitialised()); - // Client & browser are initialized and successfully started - EXPECT_FALSE(NULL == dnssd_service_browser.avahi_service_browser()); - EXPECT_FALSE(NULL == dnssd_service_browser.avahi_threaded_poll()); - EXPECT_FALSE(NULL == dnssd_service_browser.avahi_client()); - dnssd_service_browser.Terminate(); - // Checks everything successfully terminated - EXPECT_TRUE(NULL == dnssd_service_browser.avahi_service_browser()); - EXPECT_TRUE(NULL == dnssd_service_browser.avahi_threaded_poll()); - EXPECT_TRUE(NULL == dnssd_service_browser.avahi_client()); -} - -TEST(DnssdServiceBrowser, DISABLED_Scan_ExpectNotSupported) { - // Arrange - MockTransportAdapterController controller; - DnssdServiceBrowser dnssd_service_browser(&controller); - // At this moment Scan() can only return NOT SUPPORTED value - EXPECT_EQ(TransportAdapter::NOT_SUPPORTED, dnssd_service_browser.Scan()); -} - -} // namespace transport_adapter -} // namespace transport_manager |