#define SATDUMP_DLL_EXPORT 1 #include "plugin.h" #include #include "logger.h" #include "settings.h" #include std::shared_ptr loadPlugin(std::string plugin) { logger->trace("Loading plugin " + plugin + "..."); void *dynlib = dlopen(plugin.c_str(), RTLD_LAZY); if (!dynlib) throw std::runtime_error("Error loading " + plugin + "!"); void *create = dlsym(dynlib, "loader"); const char *dlsym_error = dlerror(); if (dlsym_error != NULL) logger->warn("Possible error loading symbols from plugin!"); satdump::Plugin *pluginObject = reinterpret_cast(create)(); pluginObject->init(); logger->trace("Plugin " + pluginObject->getID() + " loaded!"); return std::shared_ptr(pluginObject); } namespace satdump { SATDUMP_DLL std::map> loaded_plugins; SATDUMP_DLL std::shared_ptr eventBus = std::make_shared(); }; void loadPlugins() { if (global_cfg.contains("plugins")) { std::vector pluginsToLoad = global_cfg["plugins"].get>(); for (std::string path : pluginsToLoad) { if (std::filesystem::exists(path) && std::filesystem::is_regular_file(path)) { std::shared_ptr pl = loadPlugin(path); satdump::loaded_plugins.insert({pl->getID(), pl}); } else { logger->error("File " + path + " is not a valid plugin!"); } } if (satdump::loaded_plugins.size() > 0) { logger->debug("Loaded plugins (" + std::to_string(satdump::loaded_plugins.size()) + ") : "); for (std::pair> &it : satdump::loaded_plugins) logger->debug(" - " + it.first); } } }