Changeset 6027 for branches/newapi
- Timestamp:
- 01/11/08 07:59:37 (11 months ago)
- Location:
- branches/newapi/simple/src
- Files:
-
- 3 modified
-
plugin.cpp (modified) (1 diff)
-
simpleplugin.cpp (modified) (3 diffs)
-
simpleplugin.h (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/newapi/simple/src/plugin.cpp
r5922 r6027 48 48 Licq::Plugin* licqCreatePlugin(const Licq::Plugin::Setup& setup) 49 49 { 50 return new SimplePlugin( *setup.log);50 return new SimplePlugin(setup); 51 51 } 52 52 -
branches/newapi/simple/src/simpleplugin.cpp
r5788 r6027 18 18 */ 19 19 20 #include "licq/interface/daemon.h" 20 21 #include "simpleplugin.h" 21 22 22 SimplePlugin::SimplePlugin(Licq::Log& log) 23 : myLog(log) 23 SimplePlugin::SimplePlugin(const Licq::Plugin::Setup& setup) 24 : myLog(*setup.log), 25 mySetup(setup), 26 myEventDispatcher(myEventLoop, *mySetup.eventQueue, Licq::Daemon::getInstance()) 24 27 { 25 28 myLog.debug("Constructing SimplePlugin"); … … 34 37 { 35 38 myLog.debug(boost::format("onTimer(%1%)") % timer); 39 static int counter = 0; 40 if (++counter == 10) 41 { 42 Licq::Event::Ptr exit = Licq::Event::create("daemon.exit"); 43 Licq::Daemon::getInstance()->sendEventToDaemon(exit); 44 } 36 45 } 37 46 … … 41 50 } 42 51 52 bool SimplePlugin::onEvent(Licq::Event::Ptr event) 53 { 54 myLog.debug(boost::format("onEvent(%1%)") % event->getName()); 55 if (event->getName() == "plugin.stop") 56 { 57 myEventLoop.exit(0); 58 Licq::Event::Ptr stopped = Licq::Event::create("plugin.stopped"); 59 stopped->setProperty("id", mySetup.id); 60 Licq::Daemon::getInstance()->sendEventToDaemon(stopped); 61 return false; 62 } 63 return true; 64 } 65 43 66 int SimplePlugin::run() 44 67 { 45 Licq::EventLoop eventLoop;46 eventLoop.addTimer(20, this);68 myEventDispatcher.setDefaultCallback(&SimplePlugin::onEvent, this); 69 myEventLoop.addTimer(500, this); 47 70 48 71 myLog.debug("Starting SimplePlugin"); 49 return eventLoop.run();72 return myEventLoop.run(); 50 73 } -
branches/newapi/simple/src/simpleplugin.h
r5914 r6027 21 21 #define SIMPLEPLUGIN_H 22 22 23 #include "licq/event/eventdispatcher.h" 23 24 #include "licq/event/eventloop.h" 24 25 #include "licq/interface/plugin.h" … … 30 31 { 31 32 public: 32 SimplePlugin( Licq::Log& log);33 SimplePlugin(const Licq::Plugin::Setup& setup); 33 34 ~SimplePlugin(); 34 35 36 bool onEvent(Licq::Event::Ptr event); 37 38 // From Licq::EventLoop::Handler 35 39 void onTimer(int timer); 36 40 void onDescriptor(int fd, Licq::EventLoop::NotifierType type); … … 42 46 private: 43 47 Licq::Log& myLog; 48 const Licq::Plugin::Setup& mySetup; 49 50 Licq::EventLoop myEventLoop; 51 Licq::EventDispatcher myEventDispatcher; 44 52 }; 45 53
