dispatcher alias methods
authorCharles McGarvey <chazmcgarvey@brokenzipper.com>
Tue, 8 Sep 2009 16:09:04 +0000 (10:09 -0600)
committerCharles McGarvey <chazmcgarvey@brokenzipper.com>
Tue, 8 Sep 2009 16:09:04 +0000 (10:09 -0600)
src/Moof/Dispatcher.hh
src/YoinkApp.cc

index a152691a8184d170d62890df2fb72dbc51959dc2..da82f3824256b70bf50ee283f446133594a1c009 100644 (file)
@@ -55,7 +55,11 @@ public:
 
 class Dispatcher
 {
+       class Impl;
+       boost::shared_ptr<Impl> impl_;
+
 public:
+
        typedef void* Handler;
        typedef boost::function<void(const Notification*)> Function;
 
@@ -72,13 +76,35 @@ public:
        void removeHandler(Handler id);
 
        void dispatch(const std::string& message, const Notification* param = 0);
-
-private:
-       class Impl;
-       boost::shared_ptr<Impl> impl_;
 };
 
 
+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_
index 7ec807bdb22de89f4c3a7d461e12b38063afec8d..86816e5295a61d78e6dbb0ae02df255d06b6acc1 100644 (file)
@@ -109,7 +109,7 @@ YoinkApp::YoinkApp(int argc, char* argv[]) :
        music("NightFusion"),
        punchSound("RobotPunch")
 {
-       Mf::Dispatcher::getInstance().addHandler("video.context_recreated",
+       Mf::dispatcher::addHandler("video.context_recreated",
                        boost::bind(&YoinkApp::contextRecreated, this, _1), this);
        setupGL();
 
@@ -144,7 +144,7 @@ YoinkApp::~YoinkApp()
        delete font;
        delete testScene;
 
-       Mf::Dispatcher::getInstance().removeHandler(this);
+       Mf::dispatcher::removeHandler(this);
 }
 
 
@@ -419,7 +419,7 @@ void YoinkApp::handleEvent(const Mf::Event& event)
                        }
                        else if (event.key.keysym.sym == SDLK_t)
                        {
-                               Mf::Dispatcher::getInstance().dispatch("video.context_recreated");
+                               Mf::dispatcher::dispatch("video.context_recreated");
                                break;
                        }
                        else if (event.key.keysym.sym == SDLK_p)
This page took 0.021254 seconds and 4 git commands to generate.