11 #include <mc_rtc/config.h>
33 template<
typename... Args>
34 static std::shared_ptr<mc_observers::Observer>
get_observer(
const std::string & name,
const Args &... args)
36 std::lock_guard<std::mutex> guard{mtx};
38 return observer_loader->create_object(name, args...);
50 std::lock_guard<std::mutex> guard{mtx};
52 return observer_loader->get_object_runtime_directory(name);
55 template<
typename RetT,
typename... Args>
56 static void register_object(
const std::string & name, std::function<RetT *(
const Args &...)> callback)
58 std::unique_lock<std::mutex> guard{mtx};
60 observer_loader->register_object(name, callback);
68 std::lock_guard<std::mutex> guard{mtx};
70 observer_loader->load_libraries(paths);
76 std::lock_guard<std::mutex> guard{mtx};
78 observer_loader->clear();
86 std::lock_guard<std::mutex> guard{mtx};
88 return observer_loader->has_object(name);
93 std::lock_guard<std::mutex> guard{mtx};
95 if(observer_loader) { observer_loader->set_verbosity(verbose); }
101 std::lock_guard<std::mutex> guard{mtx};
103 return observer_loader->objects();
107 static inline void init(
bool skip_default_path =
false)
113 std::vector<std::string> default_path = {};
114 if(!skip_default_path) { default_path.push_back(mc_rtc::MC_OBSERVERS_INSTALL_PREFIX); }
115 observer_loader.reset(
125 static std::unique_ptr<mc_rtc::ObjectLoader<mc_observers::Observer>> observer_loader;
126 static bool verbose_;
127 static std::mutex mtx;
#define MC_OBSERVERS_DLLAPI
Definition: api.h:47
ltdl wrapper for mc_rtc purpose
Definition: BodySensorObserver.h:14
void error(Args &&... args)
Definition: logging.h:63
Load Observer instances from shared libraries.
Definition: ObserverLoader.h:24
static void register_object(const std::string &name, std::function< RetT *(const Args &...)> callback)
Definition: ObserverLoader.h:56
static std::shared_ptr< mc_observers::Observer > get_observer(const std::string &name, const Args &... args)
Definition: ObserverLoader.h:34
static void update_module_path(const std::vector< std::string > &paths)
Definition: ObserverLoader.h:66
static std::string get_observer_runtime_directory(const std::string &name) noexcept
Definition: ObserverLoader.h:48
static void clear()
Definition: ObserverLoader.h:74
static bool has_observer(const std::string &name)
Definition: ObserverLoader.h:84
static std::vector< std::string > available_observers()
Definition: ObserverLoader.h:99
static void set_verbosity(bool verbose)
Definition: ObserverLoader.h:91
Exception thrown by loader interface.
Definition: loader.h:43
virtual const char * what() const noexcept override
Definition: loader.h:47
ltdl wrapper for factory-like classes
Definition: loader.h:187