Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed poco dependency #139

Merged
merged 26 commits into from
Apr 8, 2020
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ install:
- mkdir ros2
- cd ros2
- git clone https://github.com/ros2/console_bridge_vendor.git
- git clone https://github.com/ros2/poco_vendor.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"
Expand Down
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 uncrustify
brew unlink python@2
brew outdated python3 || brew upgrade python3 || brew install python3
fi
Expand All @@ -43,7 +43,6 @@ script:
- git clone https://github.com/ament/uncrustify_vendor.git
- cd $AMENT_WS_SRC/ros2
- git clone https://github.com/ros2/console_bridge_vendor.git
- git clone https://github.com/ros2/poco_vendor.git
- cd $AMENT_WS
# Link source into workspace's source space
- ln -s $TRAVIS_BUILD_DIR ./src
Expand Down
13 changes: 6 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions class_loader-extras.cmake
Original file line number Diff line number Diff line change
@@ -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})
13 changes: 4 additions & 9 deletions include/class_loader/class_loader_core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include <cstddef>
#include <cstdio>
#include <map>
#include <memory>
#include <mutex>
#include <string>
#include <typeinfo>
Expand All @@ -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
Expand All @@ -82,7 +77,7 @@ typedef std::string ClassName;
typedef std::string BaseClassName;
typedef std::map<ClassName, impl::AbstractMetaObjectBase *> FactoryMap;
typedef std::map<BaseClassName, FactoryMap> BaseToFactoryMapMap;
typedef std::pair<LibraryPath, Poco::SharedLibrary *> LibraryPair;
typedef std::pair<LibraryPath, std::shared_ptr<rcpputils::SharedLibrary>> LibraryPair;
typedef std::vector<LibraryPair> LibraryVector;
typedef std::vector<AbstractMetaObjectBase *> MetaObjectVector;

Expand All @@ -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
Expand Down
3 changes: 1 addition & 2 deletions include/class_loader/meta_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_
Expand Down
10 changes: 4 additions & 6 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,15 @@
<author>Mirza Shah</author>
<author>Dirk Thomas</author>

<buildtool_depend>ament_cmake</buildtool_depend>

<build_depend>console_bridge_vendor</build_depend>
<build_depend>libconsole-bridge-dev</build_depend>
<build_depend>libpoco-dev</build_depend>
<build_depend>poco_vendor</build_depend>

<buildtool_depend>ament_cmake</buildtool_depend>

<exec_depend>console_bridge_vendor</exec_depend>
<exec_depend>libconsole-bridge-dev</exec_depend>
<exec_depend>libpoco-dev</exec_depend>
<exec_depend>poco_vendor</exec_depend>

<depend>rcpputils</depend>

<test_depend>ament_cmake_gtest</test_depend>
<test_depend>ament_lint_auto</test_depend>
Expand Down
28 changes: 1 addition & 27 deletions src/class_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@

#include "class_loader/class_loader.hpp"

#include <Poco/SharedLibrary.h>

#include <string>

namespace class_loader
Expand All @@ -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)
Expand Down
84 changes: 35 additions & 49 deletions src/class_loader_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,9 @@
#include "class_loader/class_loader_core.hpp"
#include "class_loader/class_loader.hpp"

#include <Poco/SharedLibrary.h>

#include <cassert>
#include <cstddef>
#include <memory>
#include <string>
#include <vector>

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -445,31 +444,25 @@ void loadLibrary(const std::string & library_path, ClassLoader * loader)
return;
}

Poco::SharedLibrary * library_handle = nullptr;
std::shared_ptr<rcpputils::SharedLibrary> library_handle;

static std::recursive_mutex loader_mutex;

{
std::lock_guard<std::recursive_mutex> 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) {
setCurrentlyLoadingLibraryName("");
setCurrentlyActiveClassLoader(nullptr);
throw class_loader::LibraryLoadException(
"Could not load library (Poco exception = " + std::string(e.message()) + ")");
} catch (const Poco::LibraryAlreadyLoadedException & e) {
library_handle = std::make_shared<rcpputils::SharedLibrary>(library_path.c_str());
} catch (const std::runtime_error & e) {
setCurrentlyLoadingLibraryName("");
setCurrentlyActiveClassLoader(nullptr);
throw class_loader::LibraryLoadException(
"Library already loaded (Poco exception = " + std::string(e.message()) + ")");
} catch (const Poco::NotFoundException & 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 not found (Poco exception = " + std::string(e.message()) + ")");
throw class_loader::LibraryLoadException("Bad alloc " + std::string(e.what()));
}

setCurrentlyLoadingLibraryName("");
Expand All @@ -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<void *>(library_handle));
"Successfully loaded library %s into memory (handle = %p).",
library_path.c_str(), reinterpret_cast<void *>(library_handle.get()));

// Graveyard scenario
size_t num_lib_objs = allMetaObjectsForLibrary(library_path).size();
Expand Down Expand Up @@ -530,35 +523,28 @@ 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);

// Remove from loaded library list as well if no more factories associated with said library
if (!areThereAnyExistingMetaObjectsForLibrary(library_path)) {
CONSOLE_BRIDGE_logDebug(
"class_loader.impl: "
"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);
itr = open_libraries.erase(itr);
} else {
CONSOLE_BRIDGE_logDebug(
"class_loader.impl: "
"MetaObjects still remain in memory meaning other ClassLoaders are still using library"
", keeping library %s open.",
library_path.c_str());
}
return;
} catch (const Poco::RuntimeException & e) {
delete (library);
throw class_loader::LibraryUnloadException(
"Could not unload library (Poco exception = " + std::string(e.message()) + ")");
ahcorde marked this conversation as resolved.
Show resolved Hide resolved
destroyMetaObjectsForLibrary(library_path, loader);

// Remove from loaded library list as well if no more factories associated with said library
if (!areThereAnyExistingMetaObjectsForLibrary(library_path)) {
CONSOLE_BRIDGE_logDebug(
"class_loader.impl: "
"There are no more MetaObjects left for %s so unloading library and "
"removing from loaded library vector.\n",
library_path.c_str());

library.reset();
itr = open_libraries.erase(itr);
} else {
CONSOLE_BRIDGE_logDebug(
"class_loader.impl: "
"MetaObjects still remain in memory meaning other ClassLoaders are still using library"
", keeping library %s open.",
library_path.c_str());
}
return;
}
throw class_loader::LibraryUnloadException(
"Attempt to unload library that class_loader is unaware of.");
Expand All @@ -580,8 +566,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<void *>((libs.at(c)).second));
"Open library %zu = %s (handle = %p)\n",
c, (libs.at(c)).first.c_str(), reinterpret_cast<void *>((libs.at(c)).second.get()));
}

printf("METAOBJECTS (i.e. FACTORIES) IN MEMORY:\n");
Expand Down
20 changes: 10 additions & 10 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
Loading