2016-05-30 23:58:58 -04:00
|
|
|
#pragma once
|
2016-05-19 10:41:06 -04:00
|
|
|
|
|
|
|
#include "modules/base.hpp"
|
|
|
|
|
|
|
|
DefineBaseException(RegistryError);
|
|
|
|
DefineChildException(ModuleNotFound, RegistryError);
|
|
|
|
|
2016-05-30 23:58:58 -04:00
|
|
|
struct RegistryModuleEntry
|
2016-05-19 10:41:06 -04:00
|
|
|
{
|
|
|
|
concurrency::Atomic<bool> warmedup;
|
|
|
|
std::unique_ptr<modules::ModuleInterface> module;
|
|
|
|
|
2016-05-30 23:58:58 -04:00
|
|
|
RegistryModuleEntry(std::unique_ptr<modules::ModuleInterface> &&module) : warmedup(false)
|
2016-05-19 10:41:06 -04:00
|
|
|
{
|
|
|
|
this->module.swap(module);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class Registry
|
|
|
|
{
|
|
|
|
// Stopped and no loaded modules
|
|
|
|
const int STAGE_1 = 1;
|
|
|
|
// Modules loaded but waiting for initial broadcast
|
|
|
|
const int STAGE_2 = 2;
|
|
|
|
// Running
|
|
|
|
const int STAGE_3 = 3;
|
|
|
|
// Unloading modules
|
|
|
|
const int STAGE_4 = 4;
|
|
|
|
|
|
|
|
concurrency::Atomic<int> stage;
|
|
|
|
|
2016-05-30 23:58:58 -04:00
|
|
|
std::vector<std::unique_ptr<RegistryModuleEntry>> modules;
|
2016-05-19 10:41:06 -04:00
|
|
|
|
|
|
|
std::mutex wait_mtx;
|
|
|
|
std::condition_variable wait_cv;
|
|
|
|
|
|
|
|
public:
|
|
|
|
Registry();
|
|
|
|
|
|
|
|
bool ready();
|
|
|
|
void insert(std::unique_ptr<modules::ModuleInterface> &&module);
|
|
|
|
void load();
|
|
|
|
void unload();
|
|
|
|
bool wait();
|
|
|
|
void notify(const std::string& module_name);
|
|
|
|
std::string get(const std::string& module_name);
|
2016-05-30 23:58:58 -04:00
|
|
|
std::unique_ptr<RegistryModuleEntry>& find(const std::string& module_name);
|
2016-05-19 10:41:06 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
std::shared_ptr<Registry> &get_registry();
|