diff --git a/.appveyor.yml b/.appveyor.yml index 1980a76b..1def8914 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -30,10 +30,18 @@ install: - git clone https://github.com/ament/googletest.git - git clone https://github.com/ament/uncrustify_vendor.git - cd .. + - mkdir osrf + - cd osrf + - git clone https://github.com/osrf/osrf_testing_tools_cpp.git + - cd .. - mkdir ros2 - cd ros2 + - git clone https://github.com/ros2/ament_cmake_ros.git - git clone https://github.com/ros2/console_bridge_vendor.git - - git clone https://github.com/ros2/poco_vendor.git + - git clone https://github.com/ros2/launch.git + - git clone https://github.com/ros2/python_cmake_module.git + - git clone https://github.com/ros2/rcutils.git + - git clone https://github.com/ros2/rcpputils.git - cd ..\..\.. - call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat" x86_amd64 - set "PATH=%PATH%;C:\Python37;C:\Python37\Scripts" diff --git a/.travis.yml b/.travis.yml index 7d1b0084..7b9a9ffc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,7 @@ language: generic os: - linux - osx -dist: xenial +dist: bionic env: global: - AMENT_WS=~/ament_ws @@ -18,11 +18,11 @@ install: - | if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get update -qq - sudo apt-get install cmake cppcheck libxml2-utils libpoco-dev python3 python3-pip python3-empy python3-pyparsing python3-setuptools wget + sudo apt-get install cmake cppcheck libxml2-utils python3 python3-pip python3-empy python3-pyparsing python3-setuptools wget else brew update brew outdated cmake || brew upgrade cmake || brew install cmake - brew install cppcheck console_bridge poco uncrustify + brew install cppcheck console_bridge brew unlink python@2 brew outdated python3 || brew upgrade python3 || brew install python3 fi @@ -33,6 +33,7 @@ install: - sudo -H python3 -m pip install -U flake8 flake8-blind-except flake8-builtins flake8-class-newline flake8-comprehensions flake8-deprecated flake8-docstrings flake8-import-order flake8-quotes pytest pytest-repeat pytest-rerunfailures pytest-cov pytest-runner setuptools script: - mkdir -p $AMENT_WS_SRC/ament + - mkdir -p $AMENT_WS_SRC/osrf - mkdir -p $AMENT_WS_SRC/ros2 # Fetch dependencies into the workspace - cd $AMENT_WS_SRC/ament @@ -41,9 +42,15 @@ script: - git clone https://github.com/ament/ament_package.git - git clone https://github.com/ament/googletest.git - git clone https://github.com/ament/uncrustify_vendor.git + - cd $AMENT_WS_SRC/osrf + - git clone https://github.com/osrf/osrf_testing_tools_cpp.git - cd $AMENT_WS_SRC/ros2 + - git clone https://github.com/ros2/ament_cmake_ros.git - git clone https://github.com/ros2/console_bridge_vendor.git - - git clone https://github.com/ros2/poco_vendor.git + - git clone https://github.com/ros2/launch.git + - git clone https://github.com/ros2/python_cmake_module.git + - git clone https://github.com/ros2/rcutils.git + - git clone https://github.com/ros2/rcpputils.git - cd $AMENT_WS # Link source into workspace's source space - ln -s $TRAVIS_BUILD_DIR ./src diff --git a/CMakeLists.txt b/CMakeLists.txt index e731007e..864d952c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,12 +18,12 @@ endif() find_package(console_bridge_vendor REQUIRED) # Provides console_bridge 0.4.0 on platforms without it. find_package(console_bridge REQUIRED) -find_package(poco_vendor REQUIRED) # Provides FindPoco.cmake and Poco on platforms without it. -find_package(Poco REQUIRED COMPONENTS Foundation) -link_directories(${Poco_LIBRARY_DIR}) + +find_package(rcpputils REQUIRED) if(ament_cmake_FOUND) ament_export_dependencies(console_bridge) + ament_export_dependencies(rcpputils) ament_export_include_directories(include) endif() @@ -37,12 +37,12 @@ add_library(${PROJECT_NAME} SHARED ${${PROJECT_NAME}_SRCS}) if(ament_cmake_FOUND) target_include_directories(${PROJECT_NAME} PUBLIC include) - ament_target_dependencies(${PROJECT_NAME} "console_bridge" "Poco") + ament_target_dependencies(${PROJECT_NAME} "console_bridge" "rcpputils") ament_export_libraries(${PROJECT_NAME}) else() target_include_directories(${PROJECT_NAME} - PUBLIC include ${console_bridge_INCLUDE_DIRS} ${Poco_INCLUDE_DIRS}) - target_link_libraries(${PROJECT_NAME} ${console_bridge_LIBRARIES} ${Poco_LIBRARIES}) + PUBLIC include ${console_bridge_INCLUDE_DIRS}) + target_link_libraries(${PROJECT_NAME} ${console_bridge_LIBRARIES}) endif() if(WIN32) # Causes the visibility macros to use dllexport rather than dllimport @@ -77,7 +77,6 @@ else() set(TARGET_NAME ${PROJECT_NAME}) set(PKGCONFIG_LIBS ${console_bridge_LIBRARIES} - ${Poco_LIBRARIES} ) # Prepare and install necessary files to support finding of the library diff --git a/class_loader-extras.cmake b/class_loader-extras.cmake index 4567b32b..2777110d 100644 --- a/class_loader-extras.cmake +++ b/class_loader-extras.cmake @@ -1,5 +1 @@ include("${class_loader_DIR}/class_loader_hide_library_symbols.cmake") - -find_package(poco_vendor REQUIRED) -find_package(Poco REQUIRED COMPONENTS Foundation) -list(APPEND class_loader_LIBRARIES ${Poco_LIBRARIES}) diff --git a/include/class_loader/class_loader_core.hpp b/include/class_loader/class_loader_core.hpp index d0d5b622..3d0e9600 100644 --- a/include/class_loader/class_loader_core.hpp +++ b/include/class_loader/class_loader_core.hpp @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -56,13 +57,7 @@ #include "class_loader/meta_object.hpp" #include "class_loader/visibility_control.hpp" -// Forward declaration to avoid including poco headers directly. -namespace Poco -{ - -class SharedLibrary; - -} +#include "rcpputils/shared_library.hpp" /** * @note This header file is the internal implementation of the plugin system which is exposed via the ClassLoader class @@ -82,7 +77,7 @@ typedef std::string ClassName; typedef std::string BaseClassName; typedef std::map FactoryMap; typedef std::map BaseToFactoryMapMap; -typedef std::pair LibraryPair; +typedef std::pair> LibraryPair; typedef std::vector LibraryVector; typedef std::vector MetaObjectVector; @@ -99,7 +94,7 @@ CLASS_LOADER_PUBLIC BaseToFactoryMapMap & getGlobalPluginBaseToFactoryMapMap(); /** - * @brief Gets a handle to a list of open libraries in the form of LibraryPairs which encode the library path+name and the handle to the underlying Poco::SharedLibrary + * @brief Gets a handle to a list of open libraries in the form of LibraryPairs which encode the library path+name and the handle to the underlying shared library * @return A reference to the global vector that tracks loaded libraries */ CLASS_LOADER_PUBLIC diff --git a/include/class_loader/meta_object.hpp b/include/class_loader/meta_object.hpp index ecea7efb..f0e27aa8 100644 --- a/include/class_loader/meta_object.hpp +++ b/include/class_loader/meta_object.hpp @@ -29,8 +29,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ -// Note: This header defines a simplication of Poco::MetaObject -// that allows us to tag MetaObjects with an associated library name. +// Note: This header defines a simplication of a shared library #ifndef CLASS_LOADER__META_OBJECT_HPP_ #define CLASS_LOADER__META_OBJECT_HPP_ diff --git a/package.xml b/package.xml index 2248c0b1..ee0118b9 100644 --- a/package.xml +++ b/package.xml @@ -13,17 +13,15 @@ Mirza Shah Dirk Thomas - ament_cmake - console_bridge_vendor libconsole-bridge-dev - libpoco-dev - poco_vendor + + ament_cmake console_bridge_vendor libconsole-bridge-dev - libpoco-dev - poco_vendor + + rcpputils ament_cmake_gtest ament_lint_auto diff --git a/src/class_loader.cpp b/src/class_loader.cpp index 50cf4e23..a9df86b9 100644 --- a/src/class_loader.cpp +++ b/src/class_loader.cpp @@ -29,8 +29,6 @@ #include "class_loader/class_loader.hpp" -#include - #include namespace class_loader @@ -48,33 +46,9 @@ void ClassLoader::setUnmanagedInstanceBeenCreated(bool state) ClassLoader::has_unmananged_instance_been_created_ = state; } -std::string systemLibraryPrefix() -{ -#ifndef _WIN32 - return "lib"; -#endif - return ""; -} - -std::string systemLibrarySuffix() -{ -// Poco should be compiled with `#define POCO_NO_SHARED_LIBRARY_DEBUG_SUFFIX` -// to automatically remove the trailing `d` from the shared library suffix -// return Poco::SharedLibrary::suffix(); -#ifdef __linux__ - return ".so"; -#elif __APPLE__ - return ".dylib"; -#elif _WIN32 - return ".dll"; -#else - return Poco::SharedLibrary::suffix(); -#endif -} - std::string systemLibraryFormat(const std::string & library_name) { - return systemLibraryPrefix() + library_name + systemLibrarySuffix(); + return rcpputils::get_platform_library_name(library_name); } ClassLoader::ClassLoader(const std::string & library_path, bool ondemand_load_unload) diff --git a/src/class_loader_core.cpp b/src/class_loader_core.cpp index 2c7407f2..43e47756 100644 --- a/src/class_loader_core.cpp +++ b/src/class_loader_core.cpp @@ -30,10 +30,9 @@ #include "class_loader/class_loader_core.hpp" #include "class_loader/class_loader.hpp" -#include - #include #include +#include #include #include @@ -296,7 +295,7 @@ bool isLibraryLoadedByAnybody(const std::string & library_path) LibraryVector::iterator itr = findLoadedLibrary(library_path); if (itr != open_libraries.end()) { - assert(itr->second->isLoaded() == true); // Ensure Poco actually thinks the library is loaded + assert(itr->second != nullptr); // Ensure that the library is loaded return true; } else { return false; @@ -445,31 +444,25 @@ void loadLibrary(const std::string & library_path, ClassLoader * loader) return; } - Poco::SharedLibrary * library_handle = nullptr; + std::shared_ptr library_handle; + static std::recursive_mutex loader_mutex; { std::lock_guard loader_lock(loader_mutex); + setCurrentlyActiveClassLoader(loader); + setCurrentlyLoadingLibraryName(library_path); try { - setCurrentlyActiveClassLoader(loader); - setCurrentlyLoadingLibraryName(library_path); - library_handle = new Poco::SharedLibrary(library_path); - } catch (const Poco::LibraryLoadException & e) { + library_handle = std::make_shared(library_path.c_str()); + } catch (const std::runtime_error & e) { setCurrentlyLoadingLibraryName(""); setCurrentlyActiveClassLoader(nullptr); - throw class_loader::LibraryLoadException( - "Could not load library (Poco exception = " + std::string(e.message()) + ")"); - } catch (const Poco::LibraryAlreadyLoadedException & e) { + throw class_loader::LibraryLoadException("Could not load library " + std::string(e.what())); + } catch (const std::bad_alloc & e) { setCurrentlyLoadingLibraryName(""); setCurrentlyActiveClassLoader(nullptr); - throw class_loader::LibraryLoadException( - "Library already loaded (Poco exception = " + std::string(e.message()) + ")"); - } catch (const Poco::NotFoundException & e) { - setCurrentlyLoadingLibraryName(""); - setCurrentlyActiveClassLoader(nullptr); - throw class_loader::LibraryLoadException( - "Library not found (Poco exception = " + std::string(e.message()) + ")"); + throw class_loader::LibraryLoadException("Bad alloc " + std::string(e.what())); } setCurrentlyLoadingLibraryName(""); @@ -479,8 +472,8 @@ void loadLibrary(const std::string & library_path, ClassLoader * loader) assert(library_handle != nullptr); CONSOLE_BRIDGE_logDebug( "class_loader.impl: " - "Successfully loaded library %s into memory (Poco::SharedLibrary handle = %p).", - library_path.c_str(), reinterpret_cast(library_handle)); + "Successfully loaded library %s into memory (handle = %p).", + library_path.c_str(), reinterpret_cast(library_handle.get())); // Graveyard scenario size_t num_lib_objs = allMetaObjectsForLibrary(library_path).size(); @@ -530,7 +523,7 @@ void unloadLibrary(const std::string & library_path, ClassLoader * loader) LibraryVector & open_libraries = getLoadedLibraryVector(); LibraryVector::iterator itr = findLoadedLibrary(library_path); if (itr != open_libraries.end()) { - Poco::SharedLibrary * library = itr->second; + auto library = itr->second; std::string library_path = itr->first; try { destroyMetaObjectsForLibrary(library_path, loader); @@ -542,9 +535,8 @@ void unloadLibrary(const std::string & library_path, ClassLoader * loader) "There are no more MetaObjects left for %s so unloading library and " "removing from loaded library vector.\n", library_path.c_str()); - library->unload(); - assert(library->isLoaded() == false); - delete (library); + + library->unload_library(); itr = open_libraries.erase(itr); } else { CONSOLE_BRIDGE_logDebug( @@ -554,10 +546,9 @@ void unloadLibrary(const std::string & library_path, ClassLoader * loader) library_path.c_str()); } return; - } catch (const Poco::RuntimeException & e) { - delete (library); + } catch (const std::runtime_error & e) { throw class_loader::LibraryUnloadException( - "Could not unload library (Poco exception = " + std::string(e.message()) + ")"); + "Could not unload library (Poco exception = " + std::string(e.what()) + ")"); } } throw class_loader::LibraryUnloadException( @@ -580,8 +571,8 @@ void printDebugInfoToScreen() LibraryVector libs = getLoadedLibraryVector(); for (size_t c = 0; c < libs.size(); c++) { printf( - "Open library %zu = %s (Poco SharedLibrary handle = %p)\n", - c, (libs.at(c)).first.c_str(), reinterpret_cast((libs.at(c)).second)); + "Open library %zu = %s (handle = %p)\n", + c, (libs.at(c)).first.c_str(), reinterpret_cast((libs.at(c)).second.get())); } printf("METAOBJECTS (i.e. FACTORIES) IN MEMORY:\n"); diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 926524c1..2f989fc7 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -6,10 +6,10 @@ add_library(${PROJECT_NAME}_TestPlugins1 EXCLUDE_FROM_ALL SHARED plugins1.cpp) if(ament_cmake_FOUND) target_include_directories(${PROJECT_NAME}_TestPlugins1 PUBLIC "../include") - ament_target_dependencies(${PROJECT_NAME}_TestPlugins1 "console_bridge" "Poco") + ament_target_dependencies(${PROJECT_NAME}_TestPlugins1 "console_bridge") else() target_include_directories(${PROJECT_NAME}_TestPlugins1 - PUBLIC "../include" ${console_bridge_INCLUDE_DIRS} ${Poco_INCLUDE_DIRS}) + PUBLIC "../include" ${console_bridge_INCLUDE_DIRS}) endif() target_link_libraries(${PROJECT_NAME}_TestPlugins1 ${PROJECT_NAME}) class_loader_hide_library_symbols(${PROJECT_NAME}_TestPlugins1) @@ -18,10 +18,10 @@ add_library(${PROJECT_NAME}_TestPlugins2 EXCLUDE_FROM_ALL SHARED plugins2.cpp) if(ament_cmake_FOUND) target_include_directories(${PROJECT_NAME}_TestPlugins2 PUBLIC "../include") - ament_target_dependencies(${PROJECT_NAME}_TestPlugins2 "console_bridge" "Poco") + ament_target_dependencies(${PROJECT_NAME}_TestPlugins2 "console_bridge") else() target_include_directories(${PROJECT_NAME}_TestPlugins2 - PUBLIC "../include" ${console_bridge_INCLUDE_DIRS} ${Poco_INCLUDE_DIRS}) + PUBLIC "../include" ${console_bridge_INCLUDE_DIRS}) endif() target_link_libraries(${PROJECT_NAME}_TestPlugins2 ${PROJECT_NAME}) class_loader_hide_library_symbols(${PROJECT_NAME}_TestPlugins2) @@ -40,11 +40,11 @@ if(TARGET ${PROJECT_NAME}_utest) if(ament_cmake_FOUND) target_include_directories(${PROJECT_NAME}_utest PUBLIC "../include") - ament_target_dependencies(${PROJECT_NAME}_utest "console_bridge" "Poco") + ament_target_dependencies(${PROJECT_NAME}_utest "console_bridge") else() target_include_directories(${PROJECT_NAME}_utest - PUBLIC "../include" ${console_bridge_INCLUDE_DIRS} ${Poco_INCLUDE_DIRS}) - target_link_libraries(${PROJECT_NAME}_utest ${Poco_LIBRARIES}) + PUBLIC "../include" ${console_bridge_INCLUDE_DIRS}) + target_link_libraries(${PROJECT_NAME}_utest) endif() target_link_libraries(${PROJECT_NAME}_utest ${PROJECT_NAME}) if(NOT WIN32) @@ -62,11 +62,11 @@ if(TARGET ${PROJECT_NAME}_unique_ptr_test) if(ament_cmake_FOUND) target_include_directories(${PROJECT_NAME}_unique_ptr_test PUBLIC "../include") - ament_target_dependencies(${PROJECT_NAME}_unique_ptr_test "Poco") + ament_target_dependencies(${PROJECT_NAME}_unique_ptr_test) else() target_include_directories(${PROJECT_NAME}_unique_ptr_test - PUBLIC "../include" ${Poco_INCLUDE_DIRS}) - target_link_libraries(${PROJECT_NAME}_unique_ptr_test ${Poco_LIBRARIES}) + PUBLIC "../include") + target_link_libraries(${PROJECT_NAME}_unique_ptr_test) endif() target_link_libraries(${PROJECT_NAME}_unique_ptr_test ${PROJECT_NAME}) if(NOT WIN32) diff --git a/test/fviz_case_study/CMakeLists.txt b/test/fviz_case_study/CMakeLists.txt index f03d34ee..191aeb2a 100644 --- a/test/fviz_case_study/CMakeLists.txt +++ b/test/fviz_case_study/CMakeLists.txt @@ -10,10 +10,10 @@ add_executable(${PROJECT_NAME}_Test_Fviz_Main EXCLUDE_FROM_ALL fviz_main.cpp) if(ament_cmake_FOUND) target_include_directories(${PROJECT_NAME}_Test_Fviz_Main PUBLIC "../include") - ament_target_dependencies(${PROJECT_NAME}_Test_Fviz_Main "console_bridge" "Poco") + ament_target_dependencies(${PROJECT_NAME}_Test_Fviz_Main "console_bridge") else() target_include_directories(${PROJECT_NAME}_Test_Fviz_Main - PUBLIC "../include" ${console_bridge_INCLUDE_DIRS} ${Poco_INCLUDE_DIRS}) + PUBLIC "../include" ${console_bridge_INCLUDE_DIRS}) endif() target_link_libraries(${PROJECT_NAME}_Test_Fviz_Main ${PROJECT_NAME} ${PROJECT_NAME}_Test_Fviz) @@ -21,7 +21,7 @@ target_link_libraries(${PROJECT_NAME}_Test_Fviz_Main add_library(${PROJECT_NAME}_Test_FvizDefaultPlugin EXCLUDE_FROM_ALL SHARED fviz_default_plugin.cpp) target_include_directories(${PROJECT_NAME}_Test_FvizDefaultPlugin - PUBLIC "../include" ${console_bridge_INCLUDE_DIRS} ${Poco_INCLUDE_DIRS}) + PUBLIC "../include" ${console_bridge_INCLUDE_DIRS}) target_link_libraries(${PROJECT_NAME}_Test_FvizDefaultPlugin ${PROJECT_NAME} ${PROJECT_NAME}_Test_Fviz) class_loader_hide_library_symbols(${PROJECT_NAME}_Test_FvizDefaultPlugin) @@ -39,11 +39,11 @@ if(TARGET ${PROJECT_NAME}_fviz_test) if(ament_cmake_FOUND) target_include_directories(${PROJECT_NAME}_fviz_test PUBLIC "../include") - ament_target_dependencies(${PROJECT_NAME}_fviz_test "console_bridge" "Poco") + ament_target_dependencies(${PROJECT_NAME}_fviz_test "console_bridge") else() target_include_directories(${PROJECT_NAME}_fviz_test - PUBLIC "../include" ${console_bridge_INCLUDE_DIRS} ${Poco_INCLUDE_DIRS}) - target_link_libraries(${PROJECT_NAME}_fviz_test ${Poco_LIBRARIES}) + PUBLIC "../include" ${console_bridge_INCLUDE_DIRS}) + target_link_libraries(${PROJECT_NAME}_fviz_test) endif() target_link_libraries(${PROJECT_NAME}_fviz_test ${PROJECT_NAME} ${PROJECT_NAME}_Test_Fviz)