19 #include <momemta/Logging.h> 20 #include <momemta/ModuleRegistry.h> 24 ModuleRegistryInterface::~ModuleRegistryInterface() {}
31 ModuleRegistry::ModuleRegistry() { }
33 void ModuleRegistry::registerModule(RegisterOp registration_op) {
34 std::unique_lock<std::mutex> lock(mutex_);
36 deferred_.emplace_back(registration_op);
38 registerModuleWithLock(registration_op);
43 std::unique_lock<std::mutex> lock(mutex_);
46 registry_.erase(module_name);
54 std::unique_lock<std::mutex> lock(mutex_);
57 auto it = registry_.find(module_name);
58 if (it != registry_.end())
63 throw module_not_found_error(
"Module '" + module_name +
"' is not present in the registry");
72 std::unique_lock<std::mutex> lock(mutex_);
75 for (
const auto& it: registry_) {
76 if (ignore_internal && it.second.module_def.internal)
79 list.emplace_back(it.second.module_def);
84 std::unique_lock<std::mutex> lock(mutex_);
88 void ModuleRegistry::callDeferred()
const {
94 for (
auto& fn: deferred_) {
95 registerModuleWithLock(fn);
101 void ModuleRegistry::registerModuleWithLock(RegisterOp registration_op)
const {
102 auto registration_data = registration_op();
105 auto it = registry_.find(registration_data.module_def.name);
106 if (it != registry_.end())
107 throw module_already_exists_error(
"The module '" + registration_data.module_def.name +
"' already exists.");
109 registry_.emplace(registration_data.module_def.name, registration_data);
112 namespace registration {
115 ModuleDefBuilderReceiver::ModuleDefBuilderReceiver(
const ModuleDefBuilder& builder) {
116 name_ = builder.name();
118 return builder.Build();
122 ModuleDefBuilderReceiver::~ModuleDefBuilderReceiver() {
void deregisterModule(const std::string &module_name)
void processRegistrations()
static ModuleRegistry & get()
A singleton available at startup.
const ModuleRegistrationData & find(const std::string &module_name) const override
void exportList(bool ignore_internal, ModuleList &list) const