]> Dogcows Code - chaz/yoink/blobdiff - src/Moof/Dispatcher.hh
dispatcher alias methods
[chaz/yoink] / src / Moof / Dispatcher.hh
index ec143b46fdce105a7021f79cc4a2ecb1027144f4..da82f3824256b70bf50ee283f446133594a1c009 100644 (file)
 
 #include <string>
 
-#include <boost/shared_ptr.hpp>
 #include <boost/function.hpp>
-
-#include <Moof/Singleton.hh>
+#include <boost/shared_ptr.hpp>
 
 
 namespace Mf {
@@ -55,13 +53,21 @@ public:
  * Dispatcher of notifications to interested parties.
  */
 
-class Dispatcher : public Singleton<Dispatcher>
+class Dispatcher
 {
+       class Impl;
+       boost::shared_ptr<Impl> impl_;
+
 public:
+
        typedef void* Handler;
-       typedef boost::function<void(const Notification&)> Function;
+       typedef boost::function<void(const Notification*)> 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,
@@ -69,15 +75,36 @@ public:
 
        void removeHandler(Handler id);
 
-       void dispatch(const std::string& message);
-       void dispatch(const std::string& message, const Notification& param);
-
-private:
-       class DispatcherImpl;
-       boost::shared_ptr<DispatcherImpl> impl_;
+       void dispatch(const std::string& message, const Notification* param = 0);
 };
 
 
+namespace dispatcher {
+
+inline Dispatcher::Handler addHandler(const std::string& message,
+               const Dispatcher::Function& callback)
+{
+       Dispatcher::getInstance().addHandler(message, callback);
+}
+
+inline Dispatcher::Handler addHandler(const std::string& message,
+               const Dispatcher::Function& callback, Dispatcher::Handler id)
+{
+       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_
This page took 0.020097 seconds and 4 git commands to generate.