From 2e9a23aa32c2fc3f5c517405b0ac6292cd09abdf Mon Sep 17 00:00:00 2001 From: hernando Date: Wed, 11 Oct 2017 13:49:35 +0200 Subject: [PATCH] Failsafe when Servus implementation can't created and fallback to dummy (#80) --- CMake/common | 2 +- CMakeLists.txt | 5 ++++- doc/Changelog.md | 2 ++ servus/servus.cpp | 15 ++++++++++++--- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/CMake/common b/CMake/common index bff2a12..c295fb2 160000 --- a/CMake/common +++ b/CMake/common @@ -1 +1 @@ -Subproject commit bff2a126f7f2f3e947c1674918465d42154bfe33 +Subproject commit c295fb24d765a6d9479e4d7e4c0885e3ff0df6b0 diff --git a/CMakeLists.txt b/CMakeLists.txt index 63aafff..e62667a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -56,7 +56,10 @@ add_subdirectory(apps) add_subdirectory(tests) set(CPACK_PACKAGE_DESCRIPTION_FILE "${PROJECT_SOURCE_DIR}/README.md") -set(CPACK_DEBIAN_PACKAGE_DEPENDS "libavahi-client3, avahi-daemon") +set(SERVUS_PACKAGE_DEB_DEPENDS) +if (avahi-client_FOUND) + list(APPEND SERVUS_PACKAGE_DEB_DEPENDS libavahi-client3 avahi-daemon) +endif() include(CommonCPack) set(COMMON_PROJECT_DOMAIN eu.humanbrainproject) diff --git a/doc/Changelog.md b/doc/Changelog.md index 8c49ad7..621b7f1 100644 --- a/doc/Changelog.md +++ b/doc/Changelog.md @@ -3,6 +3,8 @@ # git master +* [80](https://github.com/HBPVis/Servus/pull/80): + Failsafe when Servus implementation can't be created and fallback to dummy. * [77](https://github.com/HBPVis/Servus/pull/77): Add test driver implementation for Servus * [76](https://github.com/HBPVis/Servus/pull/76): diff --git a/servus/servus.cpp b/servus/servus.cpp index 20bc672..a96acd3 100644 --- a/servus/servus.cpp +++ b/servus/servus.cpp @@ -193,12 +193,21 @@ std::unique_ptr _chooseImplementation(const std::string& name) { if (name == TEST_DRIVER) return std::unique_ptr(new test::Servus); + try + { #ifdef SERVUS_USE_DNSSD - return std::unique_ptr(new dnssd::Servus(name)); + return std::unique_ptr(new dnssd::Servus(name)); #elif defined(SERVUS_USE_AVAHI_CLIENT) - return std::unique_ptr(new avahi::Servus(name)); + return std::unique_ptr(new avahi::Servus(name)); #endif - return std::unique_ptr(new none::Servus(name)); + return std::unique_ptr(new none::Servus(name)); + } + catch (const std::runtime_error& error) + { + std::cerr << "Error starting Servus client: " << error.what() + << std::endl; + return std::unique_ptr(new servus::none::Servus(name)); + } } }