Skip to content
Snippets Groups Projects
Commit 43fa081e authored by Joaquim Casals Buñuel's avatar Joaquim Casals Buñuel
Browse files

Added better suport for plugins and subscribers path input

parent 3ab2283b
No related branches found
No related tags found
No related merge requests found
Pipeline #4417 passed
#ifndef LOADER_HPP #ifndef LOADER_HPP
#define LOADER_HPP #define LOADER_HPP
#include <dlfcn.h> #include <dlfcn.h>
#include <string>
#include <stdexcept>
class Loader{ class Loader{
protected: protected:
std::string path_; std::string path_;
......
...@@ -180,7 +180,8 @@ class ParserYAML { ...@@ -180,7 +180,8 @@ class ParserYAML {
std::string _active_name; std::string _active_name;
std::vector<ParamsInitSensor> _paramsSens; std::vector<ParamsInitSensor> _paramsSens;
std::vector<ParamsInitProcessor> _paramsProc; 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::stack<std::string> _parsing_file;
std::string _file; std::string _file;
bool _relative_path; bool _relative_path;
...@@ -197,7 +198,8 @@ public: ...@@ -197,7 +198,8 @@ public:
_paramsSens = std::vector<ParamsInitSensor>(); _paramsSens = std::vector<ParamsInitSensor>();
_paramsProc = std::vector<ParamsInitProcessor>(); _paramsProc = std::vector<ParamsInitProcessor>();
_file = ""; _file = "";
_files = std::vector<std::string>(); _plugins = std::vector<std::string>();
_subscribers= std::vector<std::string>();
_parsing_file = std::stack<std::string>(); _parsing_file = std::stack<std::string>();
_path_root = ""; _path_root = "";
_relative_path = false; _relative_path = false;
...@@ -208,7 +210,8 @@ public: ...@@ -208,7 +210,8 @@ public:
_active_name = ""; _active_name = "";
_paramsSens = std::vector<ParamsInitSensor>(); _paramsSens = std::vector<ParamsInitSensor>();
_paramsProc = std::vector<ParamsInitProcessor>(); _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>(); _parsing_file = std::stack<std::string>();
_file = file; _file = file;
_path_root = ""; _path_root = "";
...@@ -220,7 +223,8 @@ public: ...@@ -220,7 +223,8 @@ public:
_active_name = ""; _active_name = "";
_paramsSens = std::vector<ParamsInitSensor>(); _paramsSens = std::vector<ParamsInitSensor>();
_paramsProc = std::vector<ParamsInitProcessor>(); _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>(); _parsing_file = std::stack<std::string>();
_file = file; _file = file;
if(path_root != ""){ if(path_root != ""){
...@@ -245,12 +249,13 @@ public: ...@@ -245,12 +249,13 @@ public:
std::string tagsToString(std::vector<std::string>& tags); std::string tagsToString(std::vector<std::string>& tags);
std::vector<std::array<std::string, 2>> sensorsSerialization(); std::vector<std::array<std::string, 2>> sensorsSerialization();
std::vector<std::array<std::string, 3>> processorsSerialization(); 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, 3>> getCallbacks();
std::vector<std::array<std::string, 2>> getProblem(); std::vector<std::array<std::string, 2>> getProblem();
std::map<std::string,std::string> getParams(); std::map<std::string,std::string> getParams();
void parse(); void parse();
void parse_freely(); void parse_freely();
}; };
std::string ParserYAML::generatePath(std::string path){ std::string ParserYAML::generatePath(std::string path){
std::regex r("^/.*"); std::regex r("^/.*");
...@@ -413,11 +418,16 @@ void ParserYAML::parseFirstLevel(std::string file){ ...@@ -413,11 +418,16 @@ void ParserYAML::parseFirstLevel(std::string file){
for(const auto& kv : n_config["callbacks"]){ 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>()}}); _callbacks.push_back({{kv[0].as<std::string>(), kv[1].as<std::string>(), kv[2].as<std::string>()}});
} }
YAML::Node n_files = n["files"]; YAML::Node n_plugins = n["plugins"];
for(const auto& kv : n_files){ for(const auto& kv : n_plugins){
_files.push_back(kv.Scalar()); _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>); // _params.insert(std::pair<std::string,std::string>);
} }
std::vector<std::array<std::string, 2>> ParserYAML::sensorsSerialization(){ std::vector<std::array<std::string, 2>> ParserYAML::sensorsSerialization(){
...@@ -432,8 +442,11 @@ std::vector<std::array<std::string, 3>> ParserYAML::processorsSerialization(){ ...@@ -432,8 +442,11 @@ std::vector<std::array<std::string, 3>> ParserYAML::processorsSerialization(){
aux.push_back({{it._type,it._name,it._name_assoc_sensor}}); aux.push_back({{it._type,it._name,it._name_assoc_sensor}});
return aux; return aux;
} }
std::vector<std::string> ParserYAML::getFiles(){ std::vector<std::string> ParserYAML::getPlugins(){
return this->_files; return this->_plugins;
}
std::vector<std::string> ParserYAML::getSubscribers() {
return this->_subscribers;
} }
std::vector<std::array<std::string, 3>> ParserYAML::getCallbacks(){ std::vector<std::array<std::string, 3>> ParserYAML::getCallbacks(){
return this->_callbacks; return this->_callbacks;
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
// C++ includes // C++ includes
#include <algorithm> #include <algorithm>
#include <map> #include <map>
#include <string>
#include <vector> #include <vector>
namespace wolf namespace wolf
...@@ -87,9 +88,19 @@ ProblemPtr Problem::autoSetup(ParamsServer &_server) ...@@ -87,9 +88,19 @@ ProblemPtr Problem::autoSetup(ParamsServer &_server)
// Load plugins // Load plugins
auto loaders = std::vector<Loader*>(); auto loaders = std::vector<Loader*>();
for(auto it : _server.getParam<std::vector<std::string>>("files")) { auto plugins_path = _server.getParam<std::string>("plugins_path");
WOLF_TRACE("Loading file " + it) for (auto it : _server.getParam<std::vector<std::string>>("plugins")) {
auto l = new LoaderRaw(it); 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(); l->load();
loaders.push_back(l); loaders.push_back(l);
} }
...@@ -121,8 +132,7 @@ ProblemPtr Problem::autoSetup(ParamsServer &_server) ...@@ -121,8 +132,7 @@ ProblemPtr Problem::autoSetup(ParamsServer &_server)
// Done // Done
return problem; return problem;
} }
Problem::~Problem() Problem::~Problem()
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment