X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2FMoof%2FDispatcher.hh;h=bbce87872e67e1afdcf0b0c21b19f9ff56a83fd3;hp=5747f8581ddbc3622eed9be8ce5c3f0eebd03293;hb=542e50a284c7f5b144a5c97c17f6d89b2af0175c;hpb=4701bf580b75a7d77a460c6f14f9fc31fb109bbb diff --git a/src/Moof/Dispatcher.hh b/src/Moof/Dispatcher.hh index 5747f85..bbce878 100644 --- a/src/Moof/Dispatcher.hh +++ b/src/Moof/Dispatcher.hh @@ -31,10 +31,9 @@ #include -#include +#include #include - -#include +#include namespace Mf { @@ -47,7 +46,7 @@ namespace Mf { class Notification { public: - virtual ~Notification(); + virtual ~Notification() {}; }; @@ -55,13 +54,24 @@ public: * Dispatcher of notifications to interested parties. */ -class Dispatcher : public Singleton +class Dispatcher { + class Impl; + boost::shared_ptr impl_; + public: + + // TODO - the Handler would be even better as an object which automagically + // removes itself from the dispatcher on destruction, so users don't have to + // worry about forgetting typedef void* Handler; typedef boost::function Function; Dispatcher(); + ~Dispatcher(); + + // get global instance + static Dispatcher& getInstance(); Handler addHandler(const std::string& message, const Function& callback); Handler addHandler(const std::string& message, const Function& callback, @@ -70,13 +80,36 @@ public: void removeHandler(Handler id); void dispatch(const std::string& message, const Notification* param = 0); - -private: - class Impl; - boost::shared_ptr impl_; }; +namespace dispatcher { + +inline Dispatcher::Handler addHandler(const std::string& message, + const Dispatcher::Function& callback) +{ + return Dispatcher::getInstance().addHandler(message, callback); +} + +inline Dispatcher::Handler addHandler(const std::string& message, + const Dispatcher::Function& callback, Dispatcher::Handler id) +{ + return Dispatcher::getInstance().addHandler(message, callback, id); +} + +inline void removeHandler(Dispatcher::Handler id) +{ + Dispatcher::getInstance().removeHandler(id); +} + +inline void dispatch(const std::string& message, const Notification* param = 0) +{ + Dispatcher::getInstance().dispatch(message, param); +} + +} // namespace dispatch + + } // namespace Mf #endif // _MOOF_DISPATCHER_HH_