IT++ Logo Newcom Logo

itpp::Signal< DataType > Class Template Reference

Signals and slots. More...

#include <itpp/protocol/signals_slots.h>

List of all members.

Public Member Functions

 Signal (const std::string signal_name="Unamed Signal", const bool single_shot=false, const bool enable_debug=false)
 ~Signal ()
void connect (Base_Slot< DataType > *slot)
 Connect a slot to the signal.
void disconnect (Base_Slot< DataType > *slot=NULL)
 Disconnect the slot from the signal.
Base_Eventoperator() (DataType signal, const Ttype delta_time=0)
 Issue a signal.
void cancel ()
 cancel signal
void set_name (const std::string &signal_name)
 set name of signal
void set_debug (const bool enable_debug=true)
 Set debug mode. If true all signals are printed to stdout.
void trigger (DataType u)

Protected Types

typedef std::list< Base_Slot<
DataType > *, std::allocator<
Base_Slot< DataType
> * > >::iterator 
Base_Slot_Iterator

Protected Member Functions

void _disconnect (Base_Slot< DataType > *slot)

Protected Attributes

std::list< Base_Slot< DataType > *,
std::allocator< Base_Slot<
DataType > * > > 
connected_slots
std::string name

Friends

class Base_Slot< DataType >


Detailed Description

template<class DataType>
class itpp::Signal< DataType >

Signals and slots.

A simple example where to objects A and B are communicating through signals and slots. Each object has one signal and one slot. The A_signal is used to send a signal to the B_slot and vice versa. When a signal is received by the B_slot it is forwarded to the function forward(). The class definition includes the definition of the signals, slots and forward functions including a name and the type of data to transmit.

  #include "signals_slots.h"
  class A;
  class B;

  class A {
  public:
    A(){
      A_slot.forward(this, &A::member);
      A_signal.set_name("A_signal");
      A_signal.set_debug(true);
      A_slot.set_name("A_slot");
      N = 10;
    }
    Signal<int> A_signal;
    Slot<A, double> A_slot;
  private:
    int N;
    void member(const double x) {
      if(N)
        A_signal.arm(3.4, N--);
    }
  };

  class B {
  public:
    B(){
      B_slot.forward(this, &B::member);
      B_signal.set_name("B_signal");
      B_signal.set_debug();
      B_slot.set_name("B_slot");
    }
    Signal<double> B_signal;
    Slot<B, int> B_slot;
  private:
    void member(const int k){ B_signal.arm(23.2, M_PI); }  
  };

  int main(){
    A a; // class A does not know anything about class B.
    B b; // class B does not know anything about class A.
  
    a.A_signal.connect(&b.B_slot); // Connect a to b.
    b.B_signal.connect(&a.A_slot); // Connect b to a.

    a.A_signal.arm(56.2, 3); // First event in 56.2 seconds carrying data = 3
  
    Event_Queue::start(); // start the event-based simulation
  }

Definition at line 113 of file signals_slots.h.


Member Function Documentation

template<class DataType>
void itpp::Signal< DataType >::connect ( Base_Slot< DataType > *  slot  ) 

Connect a slot to the signal.

Definition at line 396 of file signals_slots.h.

References itpp::Signal< DataType >::connected_slots, itpp::Base_Slot< DataType >::name, and itpp::Signal< DataType >::name.

Referenced by itpp::TTimer< itpp::TCP_Receiver >::TTimer().

template<class DataType>
void itpp::Signal< DataType >::disconnect ( Base_Slot< DataType > *  slot = NULL  ) 

Disconnect the slot from the signal.

Definition at line 418 of file signals_slots.h.

References itpp::Signal< DataType >::connected_slots.

template<class DataType>
Base_Event * itpp::Signal< DataType >::operator() ( DataType  signal,
const Ttype  delta_time = 0 
)

Issue a signal.

Definition at line 434 of file signals_slots.h.

References itpp::Event_Queue::add(), itpp::Signal< DataType >::cancel(), and itpp::Signal< DataType >::name.

template<class DataType>
void itpp::Signal< DataType >::cancel (  ) 

cancel signal

Definition at line 457 of file signals_slots.h.

Referenced by itpp::TTimer< itpp::TCP_Receiver >::HandleCancelEvent(), itpp::Signal< DataType >::operator()(), itpp::TTimer< itpp::TCP_Receiver >::Reset(), itpp::TTimer< itpp::TCP_Receiver >::Set(), and itpp::TTimer< itpp::TCP_Receiver >::~TTimer().

template<class DataType>
void itpp::Signal< DataType >::set_name ( const std::string &  signal_name  ) 

set name of signal

Definition at line 384 of file signals_slots.h.

References itpp::Signal< DataType >::name.

Referenced by itpp::Signal< DataType >::Signal(), itpp::TCP_Sender::TCP_Sender(), and itpp::TCP_Server_Application::TCP_Server_Application().

template<class DataType>
void itpp::Signal< DataType >::set_debug ( const bool  enable_debug = true  ) 

Set debug mode. If true all signals are printed to stdout.

Definition at line 390 of file signals_slots.h.

Referenced by itpp::TCP_Sender::set_debug(), itpp::Signal< DataType >::Signal(), itpp::TCP_Server_Application::TCP_Server_Application(), and itpp::TTimer< itpp::TCP_Receiver >::TTimer().


The documentation for this class was generated from the following file:
SourceForge Logo

Generated on Thu Apr 19 14:43:50 2007 for IT++ by Doxygen 1.5.1