Files
spark/src/lib/plugin/plugin.cpp
T
2019-11-12 10:56:29 -05:00

65 lines
1.9 KiB
C++

#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 <algorithm>
#include <boost/dll.hpp>
#include <boost/filesystem.hpp>
void init_spark_plugin(bts::SparkServices &serv);
namespace bts {
namespace plugin {
using namespace bts::orderman;
void init_plugins(SparkServices &services) {
static std::vector<decltype(boost::dll::import<void(SparkServices &)>(
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<config::DeploymentType>().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<void(SparkServices &)>(
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