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