Changeset 5952 for branches/newapi
- Timestamp:
- 12/11/07 06:18:18 (12 months ago)
- Location:
- branches/newapi/licq
- Files:
-
- 3 added
- 8 modified
-
licq/event/eventqueue.h (modified) (1 diff)
-
src/event/CMakeLists.txt (modified) (1 diff)
-
src/event/eventmanager.h (added)
-
src/event/eventmanagerimpl.cpp (added)
-
src/event/eventmanagerimpl.h (added)
-
src/event/eventqueue.cpp (modified) (4 diffs)
-
src/event/eventqueue.h (modified) (3 diffs)
-
src/event/test/eventqueuetest.cpp (modified) (2 diffs)
-
src/globals.cpp (modified) (4 diffs)
-
src/globals.h (modified) (3 diffs)
-
src/plugin/plugininstanceimpl.cpp (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/newapi/licq/licq/event/eventqueue.h
r5932 r5952 46 46 47 47 /** 48 * Pushes an event to the end of the queue. The queue takes 49 * ownership of the event and @a event is reset before the function 50 * returns. 51 */ 52 virtual void pushEvent(boost::shared_ptr<Event>& event) = 0; 53 54 /** 48 55 * @returns The event in the front of the queue. 49 56 * @throws Licq::RuntimeException If the queue is empty. -
branches/newapi/licq/src/event/CMakeLists.txt
r5931 r5952 2 2 descriptorset.cpp 3 3 event.cpp 4 eventhandler.cpp 4 5 eventloop.cpp 6 eventmanagerimpl.cpp 5 7 eventqueue.cpp 6 8 timerset.cpp -
branches/newapi/licq/src/event/eventqueue.cpp
r5932 r5952 25 25 #include <cassert> 26 26 27 LicqDaemon::EventQueue::EventQueue(const std::string& name )27 LicqDaemon::EventQueue::EventQueue(const std::string& name, EventManager* manager) 28 28 : myName(name), 29 myEventManager(manager), 29 30 myQueueMutex(name), 30 31 myPipe(name) 31 32 { 33 assert(myEventManager != NULL); 34 32 35 myPipe.setBlockingRead(false); 33 36 myPipe.setBlockingWrite(true); … … 39 42 while (!myQueue.empty()) 40 43 commitEventInternal(); 44 } 45 46 int LicqDaemon::EventQueue::getFileDescriptor() const 47 { 48 return myPipe.getReadFd(); 49 } 50 51 bool LicqDaemon::EventQueue::empty() const 52 { 53 Licq::MutexLocker locker(&myQueueMutex); 54 return myQueue.empty(); 41 55 } 42 56 … … 54 68 // Notify 55 69 myPipe.putc('E'); 56 }57 58 int LicqDaemon::EventQueue::getFileDescriptor() const59 {60 return myPipe.getReadFd();61 }62 63 bool LicqDaemon::EventQueue::empty() const64 {65 Licq::MutexLocker locker(&myQueueMutex);66 return myQueue.empty();67 70 } 68 71 … … 90 93 myQueue.pop(); 91 94 92 // TODO: something with event95 myEventManager->sendEvent(event); 93 96 } -
branches/newapi/licq/src/event/eventqueue.h
r5932 r5952 23 23 #include "licq/event/eventqueue.h" 24 24 #include "licq/thread/mutex.h" 25 #include "event/eventmanager.h" 25 26 #include "util/pipe.h" 26 27 … … 33 34 { 34 35 public: 35 EventQueue(const std::string& name );36 EventQueue(const std::string& name, EventManager* manager); 36 37 ~EventQueue(); 37 38 void pushEvent(boost::shared_ptr<Licq::Event>& event);39 38 40 39 // From Licq::EventQueue 41 40 int getFileDescriptor() const; 41 void pushEvent(boost::shared_ptr<Licq::Event>& event); 42 42 bool empty() const; 43 43 boost::shared_ptr<Licq::Event> getEvent() const; … … 48 48 49 49 const std::string myName; 50 EventManager* myEventManager; 50 51 51 52 typedef std::queue< boost::shared_ptr<Licq::Event> > Queue; -
branches/newapi/licq/src/event/test/eventqueuetest.cpp
r5931 r5952 18 18 */ 19 19 20 #include "event/eventmanager.h" 20 21 #include "event/eventqueue.h" 22 #include "test/recorder.h" 21 23 22 24 #include <boost/test/unit_test.hpp> 25 #include <cassert> 23 26 24 BOOST_AUTO_TEST_SUITE(EventQueue) 25 // BOOST_FIXTURE_TEST_SUITE(EventQueue, EventQueueFixture) 27 struct EventQueueFixture : public LicqDaemon::EventManager 28 { 29 void reset() 30 { 31 BOOST_REQUIRE(recorder.isEmpty()); 32 } 33 34 // EventManager 35 void registerQueue(const std::string&, Licq::EventQueue*, int) 36 { 37 assert(false); 38 } 39 40 void unregisterQueue(const std::string&, Licq::EventQueue*) 41 { 42 assert(false); 43 } 44 45 void unregisterQueue(Licq::EventQueue*) 46 { 47 assert(false); 48 } 49 50 void sendEvent(boost::shared_ptr<Licq::Event>& event) 51 { 52 recorder.push(boost::format("sendEvent(%1%)") % event->getId()); 53 } 54 55 LicqTest::Recorder recorder; 56 }; 57 58 BOOST_FIXTURE_TEST_SUITE(EventQueue, EventQueueFixture) 26 59 27 60 BOOST_AUTO_TEST_CASE(basic) 28 61 { 29 LicqDaemon::EventQueue queue("test"); 62 reset(); 63 64 LicqDaemon::EventQueue queue("test", this); 30 65 boost::shared_ptr<Licq::Event> test = Licq::Event::create("test"); 31 66 Licq::Event* testPtr = test.get(); 67 Licq::Event::Id id = test->getId(); 32 68 33 69 queue.pushEvent(test); … … 40 76 queue.commitEvent(); 41 77 BOOST_CHECK_EQUAL(queue.empty(), true); 78 79 BOOST_CHECK(recorder.pop(boost::format("sendEvent(%1%)") % id)); 80 BOOST_CHECK(recorder.isEmpty()); 42 81 } 43 82 -
branches/newapi/licq/src/globals.cpp
r5924 r5952 19 19 20 20 #include "daemon.h" 21 #include "event/eventmanagerimpl.h" 21 22 #include "globals.h" 22 23 #include "plugin/plugincacheimpl.h" … … 48 49 } 49 50 51 LicqDaemon::EventManager* LicqDaemon::Globals::getEventManager() 52 { 53 return getInstance()->myEventManager; 54 } 55 50 56 LicqDaemon::Globals* LicqDaemon::Globals::getInstance() 51 57 { … … 67 73 myPluginCache = new PluginCacheImpl(*myPluginLoader); 68 74 myPluginManager = new PluginManagerImpl(*myPluginCache, *myLogDistributor); 75 76 // EventManager 77 myEventManager = new EventManagerImpl(); 69 78 70 79 // Create Daemon … … 88 97 myDaemon = NULL; 89 98 99 delete static_cast<EventManagerImpl*>(myEventManager); 100 myEventManager = NULL; 101 90 102 delete static_cast<PluginManagerImpl*>(myPluginManager); 91 103 myPluginManager = NULL; -
branches/newapi/licq/src/globals.h
r5924 r5952 35 35 36 36 class Daemon; 37 class EventManager; 37 38 class Log; 38 39 class LogDistributor; … … 61 62 * to receive log messages. 62 63 */ 63 static L icqDaemon::LogDistributor* getLogDistributor();64 static LogDistributor* getLogDistributor(); 64 65 65 66 /** 66 67 * @returns The Daemon instance. 67 68 */ 68 static LicqDaemon::Daemon* getDaemon();69 static Daemon* getDaemon(); 69 70 70 71 /** 71 72 * @returns The PluginManager instance. 72 73 */ 73 static LicqDaemon::PluginManager* getPluginManager(); 74 static PluginManager* getPluginManager(); 75 76 /** 77 * @returns The EventManager instance. 78 */ 79 static EventManager* getEventManager(); 74 80 75 81 private: … … 95 101 96 102 Daemon* myDaemon; 103 EventManager* myEventManager; 97 104 class PluginLoader* myPluginLoader; 98 105 class PluginCache* myPluginCache; -
branches/newapi/licq/src/plugin/plugininstanceimpl.cpp
r5931 r5952 18 18 */ 19 19 20 #include "globals.h" 20 21 #include "licq/exception/runtimeexception.h" 21 22 #include "licq/thread/mutex.h" … … 93 94 94 95 // Create the plugin's event queue 95 mySetup.eventQueue = new EventQueue(myInformation->name); 96 mySetup.eventQueue = new EventQueue(myInformation->name, 97 Globals::getEventManager()); 96 98 97 99 // Create the plugin
