compiles and passes single test
authorMichal Voců <michal@ruk.cuni.cz>
Fri, 24 Aug 2007 21:20:15 +0000 (21:20 +0000)
committerMichal Voců <michal@ruk.cuni.cz>
Fri, 24 Aug 2007 21:20:15 +0000 (21:20 +0000)
org.glite.lb.logger/src-nt/EventManager.H
org.glite.lb.logger/src-nt/EventManager.cpp
org.glite.lb.logger/src-nt/HTTPTransport.cpp
org.glite.lb.logger/src-nt/Makefile
org.glite.lb.logger/src-nt/test/EventManagerTest.cpp
org.glite.lb.logger/src-nt/test/ThreadPoolTest.cpp

index ca37bf4..b1f16ee 100644 (file)
@@ -26,7 +26,7 @@ public:
     static const int HANDLED_FINAL = 2;
     static const int HANDLED_NEW = 3;
 
-    virtual int handleEvent(Event* &e) {}
+    virtual int handleEvent(Event* &e) { return NOT_HANDLED; }
     virtual ~EventHandler() {}
 };
 
@@ -40,12 +40,12 @@ class TypedEventHandler: public EventHandler {
 public:
     typedef int (T::*handlerType)(E* &);
     
-    TypedEventHandler(T handler, handlerType method) 
+    TypedEventHandler(T *handler, handlerType method) 
        : m_handler(handler), m_handleEvent(method) {
     }
 
     virtual int handleEvent(Event* &e) {
-       E *ne = dynamic_cast<E*>e;
+       E *ne = dynamic_cast<E*>(e);
        int result = EventHandler::NOT_HANDLED;
        if(ne) {
            result = (m_handler->*m_handleEvent)(ne);
@@ -59,8 +59,8 @@ public:
     }
     
 private:
-    handlerType m_handleEvent;
     T *m_handler;
+    handlerType m_handleEvent;
 };
 
 
@@ -71,7 +71,7 @@ public:
     
     template<class T, class E>
     EventHandler& registerHandler(T *handler, int (T::*method)(E* &)) {
-       EventHandler *h = new TypedEventHandler<T,E>(handler, method)
+       EventHandler *h = new TypedEventHandler<T,E>(handler, method);
        addHandler(h);
        return *h;
     }
@@ -89,6 +89,4 @@ private:
 };
 
 
-// implementation
-
 #endif
index 0ab0674..91efb12 100644 (file)
@@ -1,2 +1,23 @@
 #include "EventManager.H"
 
+int
+EventManager::postEvent(Event* &e)
+{
+  for(std::list<EventHandler*>::iterator i = handlers.begin();
+      i != handlers.end();
+      i++) {
+    (*i)->handleEvent(e);
+  }
+  return 0;
+}
+
+void
+EventManager::addHandler(EventHandler *handler)
+{
+  handlers.push_back(handler);
+}
+
+void
+EventManager::removeHandler(EventHandler *handler)
+{
+}
index 6908f80..9dbe316 100644 (file)
@@ -154,7 +154,7 @@ HTTPTransport::onReady()
                std::cout << request << std::endl << headers << std::endl;
                std::cout.write(body, content_length);
                std::cout.flush();
-               res = EventManager::instance()->postEvent(new NewMessageEvent(conn, headers, body));
+               // res = EventManager::instance()->postEvent(new NewMessageEvent(conn, headers, body));
        }
 
 }
index de04063..7263354 100644 (file)
@@ -10,9 +10,9 @@ LINK = libtool --mode=link g++ $(LDFLAGS)
 
 THREAD_LIB = -lpthread
 
-CPPUNIT_ROOT = /afs/ruk.cuni.cz/home/michal/egee/repository/externals/cppunit/1.10.2/slc3_ia32_gcc323
-CPPUNIT_LIB = -L$(CPPUNIT_ROOT)/lib -lcppunit -ldl
-CPPUNIT_INCLUDE = -I$(CPPUNIT_ROOT)/include
+CPPUNIT_ROOT = 
+CPPUNIT_LIB = -lcppunit -ldl
+CPPUNIT_INCLUDE = 
 
 TEST_OBJS= \
        test/ThreadPoolTest.o \
@@ -21,13 +21,23 @@ TEST_OBJS= \
        test/SingletonTest.o \
        test/test_main.o
 
-plain: PluginManager.cpp SocketInput.o Connection.o PlainConnection.o Transport.o HTTPTransport.o ThreadPool.o main.o
+OBJS = \
+       PluginManager.o \
+       SocketInput.o \
+       Connection.o \
+       PlainConnection.o \
+       Transport.o \
+       HTTPTransport.o \
+       ThreadPool.o \
+       EventManager.o
+
+plain: main.o $(OBJS)
        $(LINK) -o $@ $+ $(THREAD_LIB)
 
 utest: ThreadPool.o PluginManager.o EventManager.o $(TEST_OBJS)
        $(LINK) -o $@ $+ $(CPPUNIT_LIB) $(THREAD_LIB)
 
-stest: test/SingletonTest.o test/test_main.o
+stest: EventManager.o test/EventManagerTest.o test/test_main.o
        $(LINK) -o $@ $+ $(CPPUNIT_LIB) $(THREAD_LIB)
 
 $(TEST_OBJS): %.o: %.cpp
index bedaa03..2d55586 100644 (file)
@@ -2,17 +2,44 @@
 
 #include "EventManager.H"
 
+class EventA : public Event {
+};
+
+class EventB : public Event {
+};
+
+class EventAA : public EventA {
+};
+
+
 class EventManagerTest: public CppUnit::TestFixture {
        CPPUNIT_TEST_SUITE(EventManagerTest);
+       CPPUNIT_TEST(handleEventTest);
        CPPUNIT_TEST_SUITE_END();
 public:
        
        void setUp() {
+               handled = false;
+               manager.registerHandler(this);
        }
 
        void tearDown() {
        }
 
+       void handleEventTest() {
+               Event *e = new EventAA();
+               manager.postEvent(e);
+               CPPUNIT_ASSERT(handled);
+       }
+
+       int handleEvent(EventA* &e) {
+               handled = true;
+               return 0;
+       }
+
+private:
+       EventManager manager;
+       bool handled;
 };
 
 CPPUNIT_TEST_SUITE_REGISTRATION( EventManagerTest );
index a4be75e..4a205ec 100644 (file)
@@ -134,7 +134,7 @@ public:
 class ThreadPoolTest: public CppUnit::TestFixture
 {
        CPPUNIT_TEST_SUITE( ThreadPoolTest );
-//     CPPUNIT_TEST( testWorkQueue );
+       CPPUNIT_TEST( testWorkQueue );
        CPPUNIT_TEST( testPoll );
        CPPUNIT_TEST( testAccept );
        CPPUNIT_TEST_SUITE_END();