diff --git a/include/core/utils/loader.hpp b/include/core/utils/loader.hpp index 4f36eeecb9cda277e16bb495349ea047b546b6ce..4e45d198c2ca9663d407d5e22289af010a227b41 100644 --- a/include/core/utils/loader.hpp +++ b/include/core/utils/loader.hpp @@ -1,6 +1,8 @@ #ifndef LOADER_HPP #define LOADER_HPP #include <dlfcn.h> +#include <string> +#include <stdexcept> class Loader{ protected: std::string path_; diff --git a/include/core/yaml/parser_yaml.hpp b/include/core/yaml/parser_yaml.hpp index c661e078a8306acf63b98425f642460ec522dc77..11101cc9872e18ac410803961eef3c6748c9ef85 100644 --- a/include/core/yaml/parser_yaml.hpp +++ b/include/core/yaml/parser_yaml.hpp @@ -180,7 +180,8 @@ class ParserYAML { std::string _active_name; std::vector<ParamsInitSensor> _paramsSens; std::vector<ParamsInitProcessor> _paramsProc; - std::vector<std::string> _files; + std::vector<std::string> _plugins; + std::vector<std::string> _subscribers; std::stack<std::string> _parsing_file; std::string _file; bool _relative_path; @@ -197,7 +198,8 @@ public: _paramsSens = std::vector<ParamsInitSensor>(); _paramsProc = std::vector<ParamsInitProcessor>(); _file = ""; - _files = std::vector<std::string>(); + _plugins = std::vector<std::string>(); + _subscribers= std::vector<std::string>(); _parsing_file = std::stack<std::string>(); _path_root = ""; _relative_path = false; @@ -208,7 +210,8 @@ public: _active_name = ""; _paramsSens = std::vector<ParamsInitSensor>(); _paramsProc = std::vector<ParamsInitProcessor>(); - _files = std::vector<std::string>(); + _plugins = std::vector<std::string>(); + _subscribers = std::vector<std::string>(); _parsing_file = std::stack<std::string>(); _file = file; _path_root = ""; @@ -220,7 +223,8 @@ public: _active_name = ""; _paramsSens = std::vector<ParamsInitSensor>(); _paramsProc = std::vector<ParamsInitProcessor>(); - _files = std::vector<std::string>(); + _plugins = std::vector<std::string>(); + _subscribers = std::vector<std::string>(); _parsing_file = std::stack<std::string>(); _file = file; if(path_root != ""){ @@ -245,12 +249,13 @@ public: std::string tagsToString(std::vector<std::string>& tags); std::vector<std::array<std::string, 2>> sensorsSerialization(); std::vector<std::array<std::string, 3>> processorsSerialization(); - std::vector<std::string> getFiles(); + std::vector<std::string> getPlugins(); + std::vector<std::string> getSubscribers(); std::vector<std::array<std::string, 3>> getCallbacks(); std::vector<std::array<std::string, 2>> getProblem(); std::map<std::string,std::string> getParams(); void parse(); - void parse_freely(); + void parse_freely(); }; std::string ParserYAML::generatePath(std::string path){ std::regex r("^/.*"); @@ -413,11 +418,16 @@ void ParserYAML::parseFirstLevel(std::string file){ for(const auto& kv : n_config["callbacks"]){ _callbacks.push_back({{kv[0].as<std::string>(), kv[1].as<std::string>(), kv[2].as<std::string>()}}); } - YAML::Node n_files = n["files"]; - for(const auto& kv : n_files){ - _files.push_back(kv.Scalar()); + YAML::Node n_plugins = n["plugins"]; + for(const auto& kv : n_plugins){ + _plugins.push_back(kv.Scalar()); } - insert_register("files", wolf::converter<std::string>::convert(_files)); + insert_register("plugins", wolf::converter<std::string>::convert(_plugins)); + YAML::Node n_subscribers= n["subscribers"]; + for (const auto &kv : n_subscribers) { + _subscribers.push_back(kv.Scalar()); + } + insert_register("subscribers", wolf::converter<std::string>::convert(_subscribers)); // _params.insert(std::pair<std::string,std::string>); } std::vector<std::array<std::string, 2>> ParserYAML::sensorsSerialization(){ @@ -432,8 +442,11 @@ std::vector<std::array<std::string, 3>> ParserYAML::processorsSerialization(){ aux.push_back({{it._type,it._name,it._name_assoc_sensor}}); return aux; } -std::vector<std::string> ParserYAML::getFiles(){ - return this->_files; +std::vector<std::string> ParserYAML::getPlugins(){ + return this->_plugins; +} +std::vector<std::string> ParserYAML::getSubscribers() { + return this->_subscribers; } std::vector<std::array<std::string, 3>> ParserYAML::getCallbacks(){ return this->_callbacks; diff --git a/src/problem/problem.cpp b/src/problem/problem.cpp index bcb8945b98bd536a6eb40cd917876f28cf38565d..aab29c55cee08b86b3687ec845953950027ba523 100644 --- a/src/problem/problem.cpp +++ b/src/problem/problem.cpp @@ -20,6 +20,7 @@ // C++ includes #include <algorithm> #include <map> +#include <string> #include <vector> namespace wolf @@ -87,9 +88,19 @@ ProblemPtr Problem::autoSetup(ParamsServer &_server) // Load plugins auto loaders = std::vector<Loader*>(); - for(auto it : _server.getParam<std::vector<std::string>>("files")) { - WOLF_TRACE("Loading file " + it) - auto l = new LoaderRaw(it); + auto plugins_path = _server.getParam<std::string>("plugins_path"); + for (auto it : _server.getParam<std::vector<std::string>>("plugins")) { + std::string plugin = plugins_path + "libwolf" + it + ".so"; + WOLF_TRACE("Loading plugin " + plugin); + auto l = new LoaderRaw(plugin); + l->load(); + loaders.push_back(l); + } + auto subscribers_path = _server.getParam<std::string>("subscribers_path"); + for (auto it : _server.getParam<std::vector<std::string>>("subscribers")) { + std::string subscriber = subscribers_path + "libwolf_subscriber_" + it + ".so"; + WOLF_TRACE("Loading subscriber " + subscriber); + auto l = new LoaderRaw(subscriber); l->load(); loaders.push_back(l); } @@ -121,8 +132,7 @@ ProblemPtr Problem::autoSetup(ParamsServer &_server) // Done return problem; -} - + } Problem::~Problem() {