diff --git a/hello_plugin/CMakeLists.txt b/hello_plugin/CMakeLists.txt index 4582cc4090cd73d4e19f2a66cb9140df2c4d47b7..ff20e63759550f5690f84ae02140361386eeb33f 100644 --- a/hello_plugin/CMakeLists.txt +++ b/hello_plugin/CMakeLists.txt @@ -5,8 +5,10 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) # ADD_EXECUTABLE(hello_plugin hello_plugin.cpp sensor_odom_2D.cpp processor_odom_2D.cpp) ADD_EXECUTABLE(hello_plugin hello_plugin.cpp) ADD_EXECUTABLE(params_autoconf params_autoconf.cpp) -target_link_libraries(hello_plugin class_loader boost_system console_bridge wolf yaml-cpp ${CERES_LIBRARIES}) -target_link_libraries(params_autoconf class_loader boost_system console_bridge wolf yaml-cpp ) +# target_link_libraries(hello_plugin class_loader boost_system console_bridge wolf yaml-cpp ${CERES_LIBRARIES}) +# target_link_libraries(params_autoconf class_loader boost_system console_bridge wolf yaml-cpp ) +target_link_libraries(hello_plugin boost_system wolf yaml-cpp ${CERES_LIBRARIES} dl) +target_link_libraries(params_autoconf boost_system wolf yaml-cpp dl) # These lines always at the end SET(HDRS_PLUGIN ${HDRS_PLUGIN} PARENT_SCOPE ) SET(SRCS_PLUGIN ${SRCS_PLUGIN} PARENT_SCOPE ) diff --git a/hello_plugin/hello_plugin.cpp b/hello_plugin/hello_plugin.cpp index 8091a6f1fe10fe12ea51474a9ac2099956bded6f..0f73b2ffe48ba95d3fbcc9838427ae2fd20ec71c 100644 --- a/hello_plugin/hello_plugin.cpp +++ b/hello_plugin/hello_plugin.cpp @@ -4,7 +4,6 @@ * Created on: Nov 12, 2018 * Author: jcasals */ -#include <class_loader/class_loader.hpp> #include "base/sensor/sensor_base.h" #include "base/wolf.h" // #include "sensor_odom_2D.cpp" @@ -16,13 +15,13 @@ #include "../hello_wolf/feature_range_bearing.h" #include "../hello_wolf/constraint_range_bearing.h" #include "../hello_wolf/landmark_point_2D.h" +#include "loader.hpp" #include "base/processor/processor_odom_2D.h" #include "base/solver/solver_factory.h" #include "base/ceres_wrapper/ceres_manager.h" using namespace std; -using namespace class_loader; using namespace wolf; using namespace Eigen; @@ -40,10 +39,15 @@ int main(int argc, char** argv) { a segmentation fault. Likewise, it seems that these ClassLoaders must be allocated at the heap, because the constructor refuses to build an object if I try to do local (stack) allocation, i.e `ClassLoader(it)` is not allowed but `new ClassLoader(it)` is. **/ - vector<ClassLoader*> class_loaders = vector<ClassLoader*>(); + // vector<ClassLoader*> class_loaders = vector<ClassLoader*>(); + // for(auto it : parser.getFiles()) { + // auto c = new ClassLoader(it); + // class_loaders.push_back(c); + // } + auto loaders = vector<Loader*>(); for(auto it : parser.getFiles()) { - auto c = new ClassLoader(it); - class_loaders.push_back(c); + auto l = new LoaderRaw(it); + loaders.push_back(l); } ProblemPtr problem = Problem::create("PO 2D"); auto sensorMap = map<string, SensorBasePtr>(); diff --git a/hello_plugin/loader.hpp b/hello_plugin/loader.hpp new file mode 100644 index 0000000000000000000000000000000000000000..4f36eeecb9cda277e16bb495349ea047b546b6ce --- /dev/null +++ b/hello_plugin/loader.hpp @@ -0,0 +1,43 @@ +#ifndef LOADER_HPP +#define LOADER_HPP +#include <dlfcn.h> +class Loader{ +protected: + std::string path_; +public: + Loader(std::string _file){ + this->path_ = _file; + } + virtual void load() = 0; + virtual void close() = 0; +}; +class LoaderRaw: public Loader{ + void* resource_; +public: + LoaderRaw(std::string _file): + Loader(_file) + { + // + } + ~LoaderRaw(){ + this->close(); + } + void load(){ + this->resource_ = dlopen(this->path_.c_str(), RTLD_LAZY); + if(not this->resource_) + throw std::runtime_error("Couldn't load resource with path " + this->path_); + } + void close(){ + if(this->resource_) dlclose(this->resource_); + } +}; +// class LoaderPlugin: public Loader{ +// ClassLoader* resource_; +// void load(){ +// this->resource_ = new ClassLoader(this->path_); +// } +// void close(){ +// delete this->resource_; +// } +// }; +#endif \ No newline at end of file diff --git a/hello_plugin/params_autoconf.cpp b/hello_plugin/params_autoconf.cpp index ead3ae34a615486cdda6368fe78360b57ec9a101..e987769c16d943771665420f3816784bc7d49b5b 100644 --- a/hello_plugin/params_autoconf.cpp +++ b/hello_plugin/params_autoconf.cpp @@ -4,7 +4,6 @@ * Created on: Feb 15, 2019 * Author: jcasals */ -#include <class_loader/class_loader.hpp> #include "base/sensor/sensor_base.h" #include "base/wolf.h" // #include "sensor_odom_2D.cpp" @@ -16,13 +15,13 @@ #include "../hello_wolf/feature_range_bearing.h" #include "../hello_wolf/constraint_range_bearing.h" #include "../hello_wolf/landmark_point_2D.h" +#include "loader.hpp" #include "base/processor/processor_odom_2D.h" #include "base/solver/solver_factory.h" #include "base/ceres_wrapper/ceres_manager.h" using namespace std; -using namespace class_loader; using namespace wolf; using namespace Eigen; @@ -40,10 +39,10 @@ int main(int argc, char** argv) { a segmentation fault. Likewise, it seems that these ClassLoaders must be allocated at the heap, because the constructor refuses to build an object if I try to do local (stack) allocation, i.e `ClassLoader(it)` is not allowed but `new ClassLoader(it)` is. **/ - vector<ClassLoader*> class_loaders = vector<ClassLoader*>(); + auto loaders = vector<Loader*>(); for(auto it : parser.getFiles()) { - auto c = new ClassLoader(it); - class_loaders.push_back(c); + auto l = new LoaderRaw(it); + loaders.push_back(l); } ProblemPtr problem = Problem::create("PO 2D"); auto sensorMap = map<string, SensorBasePtr>();