diff options
Diffstat (limited to 'engine/include/core/signal.hpp')
-rw-r--r-- | engine/include/core/signal.hpp | 50 |
1 files changed, 45 insertions, 5 deletions
diff --git a/engine/include/core/signal.hpp b/engine/include/core/signal.hpp index e21b73e..8496f1e 100644 --- a/engine/include/core/signal.hpp +++ b/engine/include/core/signal.hpp @@ -101,16 +101,29 @@ namespace flat static std::map<std::string, std::weak_ptr<channel>> channels; bool mapped; + + bool map(); public: using ptr = std::shared_ptr<channel>; - + + /* + * Constructs a new channel and try to bind it the specified job + * If no job is specified, then flat::main_job will be taken + * + * Note: Remember to check for channel legacy with legit() member function + * A channel is legit if and only if there's no other channel + * corresponding to the same label name + * In general, a channel must be UNIQUE with its label + */ channel(const std::string& id = ""); ~channel(); - void start(priority_t task_priority = priority_t::none); - bool map(); + // do not allow to copy a channel + // it does not have any sense to create a channel with the same name + channel(const channel&) = delete; + channel& operator=(const channel&) = delete; void emit(const signal&); @@ -120,6 +133,21 @@ namespace flat bool connect(listener* l); void disconnect(listener* l); + /* + * Check for legacy + * + * Note: Channels are mapped by their label. + * A channel is legit if and only if there's no other channel + * corresponding to the same label name. + */ + bool legit() const; + + /* + * It tries binding the channel task and make the channel legit + * In case of success, true is returned, otherwise false + */ + bool start(priority_t task_priority = priority_t::none, job * _job = NULL); + listener::ptr connect(listener::callback f, const std::initializer_list<std::string>& filters = {}); @@ -130,10 +158,22 @@ namespace flat using namespace std::placeholders; return connect(std::bind(mf, obj, _1, _2), filters); } - + + /* + * Find channel by its name + */ static ptr find(const std::string&); - static ptr create(const std::string& id, priority_t prior = priority_t::none); + /* + * Safer than constructor + * It constructs a new channel checking whether it is legit or not. + * It returns a nullptr if the legacy is not verified. + * + * Note: Channels are mapped by their label. + * A channel is legit if and only if there's no other channel + * corresponding to the same label name. + */ + static ptr create(const std::string& id, priority_t prior = priority_t::none, job * _job = NULL); void check_and_call(); }; |