Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members

listener.h

00001 //-*- C++ -*-
00002 //
00003 #ifndef __LISTENER__listener_h__
00004 #define __LISTENER__listener_h__
00005 
00006 #include "common.h"
00007 #include "event_filter.h"
00008 #include "event_filtering.h"
00009 #include <list>
00010 
00011 //
00012 // INFO: This file contains 2 classes, one concrete (Listener) and one 
00013 //       templated (ListenerForEvent)
00014 //
00015 
00016 
00017 namespace listener { 
00018 
00019   class SubscriberDeletePtr ;
00020   class Publisher ;
00021   class Event ;
00022   class Subscriber ;
00023 
00032   class IGSLISTENER Listener {
00033   public:
00034     typedef unsigned int ID ;
00035 
00036     Listener(unsigned int priority = 0) ;
00037     Listener(Publisher*, unsigned int priority = 0) ;
00038     virtual ~Listener() ;
00039 
00040     void set_publisher(Publisher*) ;
00041 
00042     ID get_id() const ;
00043 
00048     unsigned int get_priority() const ;
00049 
00056     void set_priority(unsigned int) ;
00057 
00062     void add_event_filter(EventFilter*) ;
00063 
00069     void add_permanent_event_filter(EventFilter*) ;
00070 
00074     void remove_all_event_filters() ;
00075 
00079     void block_events() ;
00080     
00084     void unblock_events() ;
00085 
00089     bool are_events_blocked() const ;
00090 
00094     template <typename LISTENER>
00095     bool inherits_from() {return dynamic_cast<LISTENER*>(this) != NULL ;}
00096 
00097     virtual void dump_listener(std::ostream&, int spaces=0) ;
00098 
00099     bool operator<(const Listener& l) const ;
00100     bool operator>(const Listener& l) const ;
00101 
00102   protected:
00106     Subscriber* subscriber() ;
00107 
00111     Publisher*  publisher() ;
00112 
00124     virtual bool process_event(Event*) = 0 ;
00125 
00126     void dump_infos(std::ostream&, int spaces=0) ;
00127 
00128   private:
00129     friend class SubscriberDeletePtr ;
00130     friend class Subscriber ;
00131     friend class Publisher ;
00132     typedef std::list<EventFilter_var> Filters ;
00133     Listener(const Listener&) ;
00134     void set_subscriber(Subscriber* subscriber) ;
00135     void unregister() ;
00136     // \return true if the event was posted
00137     bool delegate_post(Event* e) ;
00138     bool accept_event(Event* e) const ;
00139     Subscriber* subscriber_ ;
00140     Publisher* publisher_ ;
00141     Filters event_filters_ ;
00142     Filters permanent_event_filters_ ;
00143     bool to_delete_ ;
00144     ID id_ ;
00145     bool blocked_ ;
00146     static ID static_id_ ;
00147     unsigned int priority_ ;
00148 
00149   } ;
00150 
00151 
00219   template <typename EVENT>
00220   class ListenerForEvent: public Listener {
00221   public:
00222     ListenerForEvent(unsigned int priority = 0) ;
00223     ListenerForEvent(Publisher* p, unsigned int priority = 0) ;
00224     virtual ~ListenerForEvent() ;
00225 
00226   protected:
00230     virtual bool process_event(EVENT* e) = 0 ;
00234     virtual bool process_event(Event* e) ;
00235   } ;
00236 
00237 }
00238 
00239 #include "inline_src/listener.hxx"
00240 #endif

Generated on Mon Jan 30 11:57:50 2006 for EventListener by  doxygen 1.3.9.1