Changeset 4881 for branches/erijo-dev
- Timestamp:
- 04/01/07 21:44:55 (20 months ago)
- Location:
- branches/erijo-dev/licq
- Files:
-
- 3 added
- 5 modified
-
CMakeLists.txt (modified) (2 diffs)
-
licq/eventloop.h (added)
-
licq/interface/daemon.h (modified) (2 diffs)
-
licq/interface/eventhandler.h (added)
-
src/CMakeLists.txt (modified) (1 diff)
-
src/daemon.cpp (modified) (3 diffs)
-
src/daemon.h (modified) (3 diffs)
-
src/eventloop.cpp (added)
Legend:
- Unmodified
- Added
- Removed
-
branches/erijo-dev/licq/CMakeLists.txt
r4853 r4881 6 6 if (NOT CMAKE_BUILD_TYPE) 7 7 set(CMAKE_BUILD_TYPE Debug CACHE STRING 8 "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel Maintainer." 8 "Choose the type of build, options are: " 9 "None Debug Release RelWithDebInfo MinSizeRel Maintainer." 9 10 FORCE) 10 11 endif (NOT CMAKE_BUILD_TYPE) … … 55 56 56 57 # Generate config.h 57 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h) 58 configure_file( 59 ${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake 60 ${CMAKE_CURRENT_BINARY_DIR}/config.h 61 ) 58 62 59 63 add_subdirectory(src) -
branches/erijo-dev/licq/licq/interface/daemon.h
r4876 r4881 21 21 #define LICQ_IDAEMON_H 22 22 23 #include "licq/interface/event.h" 24 23 25 #include <string> 24 26 … … 35 37 36 38 virtual void* getService(const std::string& name) const = 0; 39 virtual void pushEvent(IEventPtr& event) = 0; 37 40 }; 38 41 -
branches/erijo-dev/licq/src/CMakeLists.txt
r4876 r4881 2 2 daemon.cpp 3 3 event.cpp 4 eventloop.cpp 4 5 eventqueue.cpp 5 6 logfile.cpp -
branches/erijo-dev/licq/src/daemon.cpp
r4876 r4881 20 20 #include "daemon.h" 21 21 22 void Licq::TDaemon::onEvent(IEventPtr& event) 22 #include <sys/time.h> 23 #include <time.h> 24 25 void Licq::TDaemon::onEvent(const IEventPtr& event) 23 26 { 27 Log.info("TDaemon::onEvent(%s)", event->getEventName().c_str()); 24 28 TEventHandlers::iterator handler = EventHandlers.find(event->getEventName()); 25 29 if (handler != EventHandlers.end()) … … 30 34 } 31 35 32 void Licq::TDaemon::onPluginCreate( IEventPtr& event)36 void Licq::TDaemon::onPluginCreate(const IEventPtr& event) 33 37 { 34 38 std::string name; 35 39 if (event->getProperty("name", &name)) 36 40 { 37 // something 41 Log.info("Creating plugin %s", name.c_str()); 42 } 43 } 44 45 void Licq::TDaemon::onTimeout(int timer) 46 { 47 static int count = 0; 48 timeval now; 49 ::gettimeofday(&now, NULL); 50 Log.info("Timeout at %ld:%03ld for timer %d", now.tv_sec, now.tv_usec/1000, timer); 51 if (count++ > 10) 52 EventLoop.exit(0); 53 54 if (count % 2) 55 { 56 IEventPtr event = IEvent::create(0, "plugin:create"); 57 event->setProperty("name", "testplugin"); 58 pushEvent(event); 59 60 event = IEvent::create(0, "invalid:event"); 61 pushEvent(event); 62 } 63 64 if (count == 5) 65 Pipe.write("TESTING", sizeof("TESTING") - 1); 66 } 67 68 void Licq::TDaemon::onFileDescriptor(int fd) 69 { 70 if (fd == Pipe.getFileDescriptor()) 71 { 72 char buf; 73 Pipe.read(&buf, 1); 74 Log.info("Read %c from pipe", buf); 38 75 } 39 76 } 40 77 41 78 Licq::TDaemon::TDaemon() 42 : PluginRepository(NULL) 79 : PluginRepository(NULL), EventLoop(&EventQueue, this) 43 80 { 44 81 // Setup event handlers … … 68 105 Log.debug("Done rebuilding plugin cache."); 69 106 70 return 0; 107 EventLoop.addTimer(1000, this); 108 EventLoop.addTimer(500, this); 109 110 EventLoop.addFileDescriptor(Pipe.getFileDescriptor(), 111 TEventLoop::ACTION_READ_FD, this); 112 return EventLoop.run(); 71 113 } 72 114 73 void* Licq::TDaemon::getService(const std::string& name) const115 void* Licq::TDaemon::getService(const std::string& /* name */) const 74 116 { 75 117 return NULL; 76 118 } 119 120 void Licq::TDaemon::pushEvent(IEventPtr& event) 121 { 122 EventQueue.push(event); 123 } -
branches/erijo-dev/licq/src/daemon.h
r4876 r4881 22 22 23 23 #include "licq/interface/daemon.h" 24 #include "licq/eventloop.h" 24 25 26 #include "eventqueue.h" 25 27 #include "logfile.h" 26 28 #include "plugin/pluginrepository.h" 29 #include "utils/pipe.h" 27 30 28 31 namespace Licq 29 32 { 30 33 31 class TDaemon : public IDaemon 34 class TDaemon : public IDaemon, 35 public IEventHandler, 36 public ITimeoutHandler, 37 public IFileDescriptorHandler 32 38 { 33 39 private: … … 35 41 TLogFile Log; 36 42 37 typedef void (TDaemon::*FnEventHandler)(IEventPtr& event); 43 TEventQueue EventQueue; 44 TEventLoop EventLoop; 45 TPipe Pipe; 46 47 typedef void (TDaemon::*FnEventHandler)(const IEventPtr& event); 38 48 typedef std::map<std::string, FnEventHandler> TEventHandlers; 39 49 TEventHandlers EventHandlers; 40 50 41 // Main event dispatcher42 void onEvent( IEventPtr& event);51 // From IEventHandler 52 void onEvent(const IEventPtr& event); 43 53 44 54 // Event handlers 45 void onPluginCreate(IEventPtr& event); 55 void onPluginCreate(const IEventPtr& event); 56 57 // From ITimeoutHandler 58 void onTimeout(int timer); 59 60 // From IFileDescriptorHandler 61 void onFileDescriptor(int fd); 46 62 47 63 public: … … 53 69 // From IDaemon 54 70 void* getService(const std::string& name) const; 71 void pushEvent(IEventPtr& event); 55 72 }; 56 73
