Changeset 5952 for branches/newapi

Show
Ignore:
Timestamp:
12/11/07 06:18:18 (12 months ago)
Author:
erijo
Message:

Started working on EventManager?.

Location:
branches/newapi/licq
Files:
3 added
8 modified

Legend:

Unmodified
Added
Removed
  • branches/newapi/licq/licq/event/eventqueue.h

    r5932 r5952  
    4646 
    4747  /** 
     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  /** 
    4855   * @returns The event in the front of the queue. 
    4956   * @throws Licq::RuntimeException If the queue is empty. 
  • branches/newapi/licq/src/event/CMakeLists.txt

    r5931 r5952  
    22  descriptorset.cpp 
    33  event.cpp 
     4  eventhandler.cpp 
    45  eventloop.cpp 
     6  eventmanagerimpl.cpp 
    57  eventqueue.cpp 
    68  timerset.cpp 
  • branches/newapi/licq/src/event/eventqueue.cpp

    r5932 r5952  
    2525#include <cassert> 
    2626 
    27 LicqDaemon::EventQueue::EventQueue(const std::string& name) 
     27LicqDaemon::EventQueue::EventQueue(const std::string& name, EventManager* manager) 
    2828  : myName(name), 
     29    myEventManager(manager), 
    2930    myQueueMutex(name), 
    3031    myPipe(name) 
    3132{ 
     33  assert(myEventManager != NULL); 
     34 
    3235  myPipe.setBlockingRead(false); 
    3336  myPipe.setBlockingWrite(true); 
     
    3942  while (!myQueue.empty()) 
    4043    commitEventInternal(); 
     44} 
     45 
     46int LicqDaemon::EventQueue::getFileDescriptor() const 
     47{ 
     48  return myPipe.getReadFd(); 
     49} 
     50 
     51bool LicqDaemon::EventQueue::empty() const 
     52{ 
     53  Licq::MutexLocker locker(&myQueueMutex); 
     54  return myQueue.empty(); 
    4155} 
    4256 
     
    5468  // Notify 
    5569  myPipe.putc('E'); 
    56 } 
    57  
    58 int LicqDaemon::EventQueue::getFileDescriptor() const 
    59 { 
    60   return myPipe.getReadFd(); 
    61 } 
    62  
    63 bool LicqDaemon::EventQueue::empty() const 
    64 { 
    65   Licq::MutexLocker locker(&myQueueMutex); 
    66   return myQueue.empty(); 
    6770} 
    6871 
     
    9093  myQueue.pop(); 
    9194 
    92   // TODO: something with event 
     95  myEventManager->sendEvent(event); 
    9396} 
  • branches/newapi/licq/src/event/eventqueue.h

    r5932 r5952  
    2323#include "licq/event/eventqueue.h" 
    2424#include "licq/thread/mutex.h" 
     25#include "event/eventmanager.h" 
    2526#include "util/pipe.h" 
    2627 
     
    3334{ 
    3435public: 
    35   EventQueue(const std::string& name); 
     36  EventQueue(const std::string& name, EventManager* manager); 
    3637  ~EventQueue(); 
    37  
    38   void pushEvent(boost::shared_ptr<Licq::Event>& event); 
    3938 
    4039  // From Licq::EventQueue 
    4140  int getFileDescriptor() const; 
     41  void pushEvent(boost::shared_ptr<Licq::Event>& event); 
    4242  bool empty() const; 
    4343  boost::shared_ptr<Licq::Event> getEvent() const; 
     
    4848 
    4949  const std::string myName; 
     50  EventManager* myEventManager; 
    5051 
    5152  typedef std::queue< boost::shared_ptr<Licq::Event> > Queue; 
  • branches/newapi/licq/src/event/test/eventqueuetest.cpp

    r5931 r5952  
    1818 */ 
    1919 
     20#include "event/eventmanager.h" 
    2021#include "event/eventqueue.h" 
     22#include "test/recorder.h" 
    2123 
    2224#include <boost/test/unit_test.hpp> 
     25#include <cassert> 
    2326 
    24 BOOST_AUTO_TEST_SUITE(EventQueue) 
    25 // BOOST_FIXTURE_TEST_SUITE(EventQueue, EventQueueFixture) 
     27struct 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 
     58BOOST_FIXTURE_TEST_SUITE(EventQueue, EventQueueFixture) 
    2659 
    2760BOOST_AUTO_TEST_CASE(basic) 
    2861{ 
    29   LicqDaemon::EventQueue queue("test"); 
     62  reset(); 
     63 
     64  LicqDaemon::EventQueue queue("test", this); 
    3065  boost::shared_ptr<Licq::Event> test = Licq::Event::create("test"); 
    3166  Licq::Event* testPtr = test.get(); 
     67  Licq::Event::Id id = test->getId(); 
    3268 
    3369  queue.pushEvent(test); 
     
    4076  queue.commitEvent(); 
    4177  BOOST_CHECK_EQUAL(queue.empty(), true); 
     78 
     79  BOOST_CHECK(recorder.pop(boost::format("sendEvent(%1%)") % id)); 
     80  BOOST_CHECK(recorder.isEmpty()); 
    4281} 
    4382 
  • branches/newapi/licq/src/globals.cpp

    r5924 r5952  
    1919 
    2020#include "daemon.h" 
     21#include "event/eventmanagerimpl.h" 
    2122#include "globals.h" 
    2223#include "plugin/plugincacheimpl.h" 
     
    4849} 
    4950 
     51LicqDaemon::EventManager* LicqDaemon::Globals::getEventManager() 
     52{ 
     53  return getInstance()->myEventManager; 
     54} 
     55 
    5056LicqDaemon::Globals* LicqDaemon::Globals::getInstance() 
    5157{ 
     
    6773  myPluginCache = new PluginCacheImpl(*myPluginLoader); 
    6874  myPluginManager = new PluginManagerImpl(*myPluginCache, *myLogDistributor); 
     75 
     76  // EventManager 
     77  myEventManager = new EventManagerImpl(); 
    6978 
    7079  // Create Daemon 
     
    8897  myDaemon = NULL; 
    8998 
     99  delete static_cast<EventManagerImpl*>(myEventManager); 
     100  myEventManager = NULL; 
     101 
    90102  delete static_cast<PluginManagerImpl*>(myPluginManager); 
    91103  myPluginManager = NULL; 
  • branches/newapi/licq/src/globals.h

    r5924 r5952  
    3535 
    3636class Daemon; 
     37class EventManager; 
    3738class Log; 
    3839class LogDistributor; 
     
    6162   * to receive log messages. 
    6263   */ 
    63   static LicqDaemon::LogDistributor* getLogDistributor(); 
     64  static LogDistributor* getLogDistributor(); 
    6465 
    6566  /** 
    6667   * @returns The Daemon instance. 
    6768   */ 
    68   static LicqDaemon::Daemon* getDaemon(); 
     69  static Daemon* getDaemon(); 
    6970 
    7071  /** 
    7172   * @returns The PluginManager instance. 
    7273   */ 
    73   static LicqDaemon::PluginManager* getPluginManager(); 
     74  static PluginManager* getPluginManager(); 
     75 
     76  /** 
     77   * @returns The EventManager instance. 
     78   */ 
     79  static EventManager* getEventManager(); 
    7480 
    7581private: 
     
    95101 
    96102  Daemon* myDaemon; 
     103  EventManager* myEventManager; 
    97104  class PluginLoader* myPluginLoader; 
    98105  class PluginCache* myPluginCache; 
  • branches/newapi/licq/src/plugin/plugininstanceimpl.cpp

    r5931 r5952  
    1818 */ 
    1919 
     20#include "globals.h" 
    2021#include "licq/exception/runtimeexception.h" 
    2122#include "licq/thread/mutex.h" 
     
    9394 
    9495  // Create the plugin's event queue 
    95   mySetup.eventQueue = new EventQueue(myInformation->name); 
     96  mySetup.eventQueue = new EventQueue(myInformation->name, 
     97                                      Globals::getEventManager()); 
    9698 
    9799  // Create the plugin