2016-05-31 03:58:58 +00:00
|
|
|
#pragma once
|
2016-05-19 14:41:06 +00:00
|
|
|
|
|
|
|
#include "modules/base.hpp"
|
|
|
|
|
|
|
|
DefineBaseException(RegistryError);
|
|
|
|
DefineChildException(ModuleNotFound, RegistryError);
|
|
|
|
|
2016-05-31 03:58:58 +00:00
|
|
|
struct RegistryModuleEntry
|
2016-05-19 14:41:06 +00:00
|
|
|
{
|
|
|
|
concurrency::Atomic<bool> warmedup;
|
|
|
|
std::unique_ptr<modules::ModuleInterface> module;
|
|
|
|
|
2016-05-31 03:58:58 +00:00
|
|
|
RegistryModuleEntry(std::unique_ptr<modules::ModuleInterface> &&module) : warmedup(false)
|
2016-05-19 14:41:06 +00:00
|
|
|
{
|
|
|
|
this->module.swap(module);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class Registry
|
|
|
|
{
|
2016-06-20 12:01:20 +00:00
|
|
|
const int STAGE_1 = 1; // Stopped and no loaded modules
|
|
|
|
const int STAGE_2 = 2; // Modules loaded but waiting for initial broadcast
|
|
|
|
const int STAGE_3 = 3; // Running
|
|
|
|
const int STAGE_4 = 4; // Unloading modules
|
|
|
|
|
|
|
|
std::shared_ptr<Logger> logger;
|
2016-05-19 14:41:06 +00:00
|
|
|
|
|
|
|
concurrency::Atomic<int> stage;
|
|
|
|
|
2016-05-31 03:58:58 +00:00
|
|
|
std::vector<std::unique_ptr<RegistryModuleEntry>> modules;
|
2016-05-19 14:41:06 +00:00
|
|
|
|
2016-06-21 05:47:51 +00:00
|
|
|
std::mutex wait_lock;
|
|
|
|
std::condition_variable wait_handler;
|
2016-05-19 14:41:06 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
Registry();
|
|
|
|
|
|
|
|
bool ready();
|
|
|
|
void insert(std::unique_ptr<modules::ModuleInterface> &&module);
|
2016-06-29 09:06:33 +00:00
|
|
|
void load(std::function<void(std::string)> add_stdin_subscriber);
|
2016-05-19 14:41:06 +00:00
|
|
|
void unload();
|
|
|
|
bool wait();
|
2016-06-21 01:59:43 +00:00
|
|
|
void notify(std::string module_name);
|
|
|
|
std::string get(std::string module_name);
|
|
|
|
std::unique_ptr<RegistryModuleEntry>& find(std::string module_name);
|
2016-05-19 14:41:06 +00:00
|
|
|
};
|