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

listener::MultiplexerListener Class Reference

The MultiplexerListener allows to create Event classes, without their corresponding Listener. Its usage simplify the use of Events and the connection to the Subscriber. The Subscriber only has to create methods taking a special Event type as pointer parameter, and to connect them using this class. More...

#include <multiplexer.h>

Inheritance diagram for listener::MultiplexerListener:

listener::Listener List of all members.

Public Member Functions

 MultiplexerListener (unsigned int priority=0)
 MultiplexerListener (Publisher *p, unsigned int priority=0)
template<typename E>
void connect (const basic::function1< void, E * > &f)
 The main method to connect an basic::function1<void, E*> to the multiplexer. Using this method, it is possible to connect several isg::function1 to this Listener.
virtual void dump_listener (std::ostream &, int spaces=0)
 Dump informations about this MultiplexerListener.

Static Public Member Functions

template<typename E>
Listener::ID connect (Publisher *p, Subscriber *s, const basic::function1< void, E * > &f, unsigned int priority=0)
 The main static method to do a connection. This method will create an appropriate Listener for f and add it to the Subscriber s.
template<typename E1, typename E2>
Listener::ID connect (Publisher *p, Subscriber *s, const basic::function1< void, E1 * > &f1, const basic::function1< void, E2 * > &f2, unsigned int priority=0)
template<typename E1, typename E2, typename E3>
Listener::ID connect (Publisher *p, Subscriber *s, const basic::function1< void, E1 * > &f1, const basic::function1< void, E2 * > &f2, const basic::function1< void, E3 * > &f3, unsigned int priority=0)
template<typename E>
bool disconnect (Publisher *p, Subscriber *s, const basic::function1< void, E * > &f)
 The main static method to do a disconnection.
template<typename E>
Listenerget_listener (Publisher *p, Subscriber *s, const basic::function1< void, E * > &f)
 The main static method to retrieve a Listener.

Protected Member Functions

bool process_event (Event *e)
 This method is called when receiving an event and that the filters return true after processing.

Detailed Description

The MultiplexerListener allows to create Event classes, without their corresponding Listener. Its usage simplify the use of Events and the connection to the Subscriber. The Subscriber only has to create methods taking a special Event type as pointer parameter, and to connect them using this class.

Note:
Since the MultiplexerListener class inherits from Listener, you can add filters and block/unblock the events.
   class NullEvent: public Event {
   } ;

   class MsgEvent: public Event {
   public:
     MsgEvent(const std::string& msg): msg_(msg) {}
     const std::string& message() const {return msg_ ;}
   private:
     std::string msg_ ;
   } ;

   class Receiver: public Subscriber {
   public:
     void msg_event(MsgEvent* e) {
        std::cerr << "Receives message \"" << e->message() 
                  << "\" from " << e->get_source() << std::endl ;
     }
     void null_event(NullEvent* e) {
        std::cerr << "Receives null event from " 
                  << e->get_source() << std::endl ;
     }
   } ;

  int main() {
    Publisher* p = new Publisher ;
    Receiver * r = new Receiver ;

    igs_connect(p, r, igs_functor(r, Receiver::null_event)) ;
    // or IGS_CONNECT(p, r, Receiver::null_event) ;

    igs_connect(p, r, igs_functor(r, Receiver::msg_event)) ;
    // or IGS_CONNECT(p, r, Receiver::msg_event) ;

    p->igs_emit(NullEvent) ;
    p->igs_emit(MsgEvent("Hello World")) ;
  }

Author:
fmaerten
Date:
Wed Dec 7 09:44:10 CET 2005
Remarks:
Some remarks about Multiplexer
This revision :

Author :

Author
fmaerten
Date :
Date
2006/01/04 16:24:57
Revision :
Revision
1.13

Copyright (C) 2004, Igeoss - All Rights Reserved.


Member Function Documentation

template<typename E>
void listener::MultiplexerListener::connect const basic::function1< void, E * > &  f  )  [inline]
 

The main method to connect an basic::function1<void, E*> to the multiplexer. Using this method, it is possible to connect several isg::function1 to this Listener.

   MultiplexerListener* m = new MultiplexerListener(p) ;
   m->connect(igs_functor(s1, S::event1) ;
   m->connect(igs_functor(s1, S::event2) ;
   m->connect(igs_functor(s2, S::event1) ;
   m->connect(igs_function(event1) ;
   s->add_listener(m) ;

bool listener::MultiplexerListener::process_event Event e  )  [protected, virtual]
 

This method is called when receiving an event and that the filters return true after processing.

Returns:
true if the ecent was process, false otherwise
Usually, client code uses this method to call virtual functions (if the Listener is inherited), or basic::function (binded function type to call).

If any of the installed filters failed or if this Listener is blocked, this method is not called.

Implements listener::Listener.


The documentation for this class was generated from the following file:
Generated on Mon Jan 30 11:57:50 2006 for EventListener by  doxygen 1.3.9.1