gatelib  2.1
g.mthread.ThreadSimpleEvent.h
1 #pragma once
2 
3 #include <g_mthread_ThreadTypes.h>
4 
5 namespace g
6 {
7 namespace mthread
8 {
9 
10 
12 {
13  virtual void send () = 0;
14 };
15 
17 {
18  template <class T> struct class_method { typedef void ( T::*Pointer_t ) ( ); };
19  typedef void ( *FunctionPointer_t ) ( );
20 
23 
27 
28  struct FunctionSubscriber : public g::signal::function_subscriber_base<ThreadSimpleEvent>
29  {
30  virtual void send () { ( *functionPointer ) ( ); }
31  };
32 
33  template < class T > struct method_subscriber : public g::signal::method_subscriber_base<ThreadSimpleEvent,T>
34  {
35  virtual void send ()
36  {
37  ((this->clsInstanceP)->*(this->methodPointer))();
38  }
39  };
40 
41  struct SenderReceiver : Sender , virtual Receiver_t
42  {
43  virtual void send ()
44  {
45  for ( g::cont::ref_lst<Subscriber>::It_t it = mListSubscribers ; it.isIn ( ) ; it++ )
46  {
47  it->send ();
48  }
49  }
50  };
51 
53  {
54  public:
55  virtual void send ()
56  {
57  g::signal::QueueDataBufferAbstract::Ref_t data_buffer_ref = mGetQueueSenderP ( )->instanciateDataBufferRef ( );
58 
59  *data_buffer_ref;
60 
61  mGetQueueSenderP ( )->push ( data_buffer_ref );
62  }
63  };
64 
65  class ReceiverSerialized : private SenderReceiver , public virtual Receiver_t , public g::signal::IReceiverSerialized
66  {
67  protected:
68  void mDrainEvent ( GTimeoutSec_t aTimeOut = 0.0 )
69  {
70  g::signal::QueueDataBufferAbstract::Ref_t data_buffer_ref = mGetQueueReceiverP ( )->pop (aTimeOut);
71 
72  data_buffer_ref->reset();
73 
74 
75  *data_buffer_ref ;
76 
77  SenderReceiver::send ();
78  }
79  };
80 
82  {
83  public:
84  virtual void send () { SenderSerialized::send (); }
85  };
86 
87  template <class Q=g::signal::QueueTxRxSimple> struct sender_receiver_serialized : SenderReceiverSerializedAbstract , public Q { };
88 
89  template <class T , class Q=g::signal::QueueTxRxSimple> class thread_base :
90  public T , public virtual Receiver_t , private sender_receiver_serialized<Q>
91  {
92  public:
93  thread_base() { }
94 
95  void start ()
96  {
97  G_EXC_SET_CONTEXT ( "void ThreadSimpleEvent::thread_base<T,Q>::start ()" );
98 
99  if ( mListSubscribers.getSize() > 0 )
100  {
101  this->send ( );
102 
103  T::start ( this );
104  }
105  else
106  {
107  G_EXC_RAISE ( g::mthread::ThreadNotHavingSubscribersException );
108  }
109  }
110 
111  private:
112  virtual void mEntryPoint ( void* aPar )
113  {
114  this->mDrainEvent();
115  }
116 
117  g::signal::QueueReceiverAbstract* mGetQueueReceiverP ( ) { return this; }
118  g::signal::QueueSenderAbstract* mGetQueueSenderP ( ) { return this; }
119  };
120 
121 };
122 
123 } //namespace mthread
124 } //namespace g
125 
Definition: g.mthread.ThreadSimpleEvent.h:89
Subclass for definng queue tx side.
Definition: g_signal_queue.h:25
#define G_EXC_RAISE(aexctype)
Raises an exception using the the default message.
Definition: g_exception_macros.h:61
Definition: g.mthread.ThreadSimpleEvent.h:41
Definition: g.mthread.ThreadSimpleEvent.h:81
Definition: g.mthread.ThreadSimpleEvent.h:22
Class capable of receiving events.
Definition: g_signal_signal_receiver.h:10
Definition: g.mthread.ThreadSimpleEvent.h:65
Definition: g_cont_ref_lst.h:10
Definition: g.mthread.ThreadSimpleEvent.h:18
Definition: g.mthread.ThreadSimpleEvent.h:5
Definition: g_cont_it_ref.h:14
Subclass for defining queue rx side.
Definition: g_signal_queue.h:17
Definition: g.mthread.ThreadSimpleEvent.h:16
Definition: g_signal_subscribers.h:28
Definition: g.mthread.ThreadSimpleEvent.h:87
Definition: g.mthread.ThreadSimpleEvent.h:11
Definition: g_cont_it_ref.h:10
Definition: g.mthread.ThreadSimpleEvent.h:21
Definition: g.mthread.ThreadSimpleEvent.h:28
Interface base class for sender serializer.
Definition: g_signal.h:17
Definition: g_signal_subscribers.h:10
#define G_EXC_SET_CONTEXT(acontextstr)
Sets the method context.
Definition: g_exception_macros.h:52
Definition: g.mthread.ThreadSimpleEvent.h:33
Interface base class for receiver serializer.
Definition: g_signal.h:24
Definition: g.mthread.ThreadSimpleEvent.h:52