#include "lib/logging/logging.h" #include "lib/orderman/actors/order_manager/OrderBuilder.h" #include "lib/plugin/SparkServices.h" #include "lib/utils/PBUtils.h" #include "lib/config/config.h" #include "lib/config/protos/system.pb.h" #include #include #include namespace bts { namespace plugin { using namespace bts::orderman; void init_plugins(SparkServices &services) { static std::vector( boost::filesystem::path(), ""))> keep_alive; auto plugin_path = os::sparkd_wd() + "/plugins/"; if (!boost::filesystem::is_directory(plugin_path)) { LOG(Plugin, Info, "No plugin directory found at {}. Skipping plugin loading", plugin_path); return; } boost::filesystem::directory_iterator end; for (auto iter = boost::filesystem::directory_iterator(plugin_path); iter != end; ++iter) { auto &f = *iter; auto pl = f.path().string(); if (pl == "order_plugin_example.so" && config::get().type() != "dev") { LOG(Plugin, Info, "Skipping order_plugin_example.so because we are not running in dev mode", plugin_path); continue; } LOG(Plugin, Info, "Attempting to initialize plugin {}", pl); try { auto init_plugin = boost::dll::import( f.path(), "init_spark_plugin"); init_plugin(services); keep_alive.push_back(init_plugin); LOG(Plugin, Info, "Successfully initialized plugin {}", pl); } catch (boost::system::system_error const &e) { LOG(Plugin, Error, "Failed to initialize plugin {}. Error: {} (OS error code: {})", pl, std::string(e.what()), e.code()); } } } } // namespace plugin } // namespace bts