Go to the documentation of this file.00001 #ifndef SIMPLE_CONSUMER_H
00002 #define SIMPLE_CONSUMER_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00030 #include "acsncConsumer.h"
00031 #include <acsutilAnyAide.h>
00032 #include <RepeatGuard.h>
00033 #include "acsncErrType.h"
00034 #include "acsncBlockingQueue.h"
00035
00036 namespace nc {
00037
00053 template <class T> class SimpleConsumer : public Consumer
00054 {
00055 public:
00064 typedef void (*eventHandlerFunction)(T eventData, void *handlerParam);
00066
00072 SimpleConsumer(const char* channelName, const char* acsNCDomainName = 0);
00074
00093 template <class J> void
00094 addSubscription(eventHandlerFunction templateFunction, void *handlerParam=0)
00095 {
00096 ACS_TRACE("SimpleConsumer::addSubscription");
00097
00098
00099
00100 if (templateFunction_mp!=0)
00101 {
00102 ACS_SHORT_LOG((LM_ERROR,
00103 "SimpleConsumer::addSubscription unable to subscribe to multiple event types from this class!"));
00104 ACSErrTypeCommon::CouldntPerformActionExImpl err = ACSErrTypeCommon::CouldntPerformActionExImpl(__FILE__,
00105 __LINE__,
00106 "nc::SimpleConsumer::addSubscription");
00107 throw err.getCouldntPerformActionEx();
00108 }
00109
00110
00111 templateFunction_mp = templateFunction;
00112
00113
00114 handlerParam_mp = handlerParam;
00115
00116
00117 Consumer::addSubscription<J>();
00118 }
00119
00132 virtual void
00133 push_structured_event(const CosNotification::StructuredEvent ¬ification);
00135
00136 bool stopConsumerThread();
00137
00138 virtual void disconnect();
00139
00144 void processEvent();
00145
00146 protected:
00150 virtual ~SimpleConsumer();
00151
00155 eventHandlerFunction templateFunction_mp;
00160 void *handlerParam_mp;
00161
00162 private:
00166 void operator=(const SimpleConsumer&);
00167
00171 SimpleConsumer(const SimpleConsumer&);
00172
00174
00191 void
00192 addSubscription(const char* type_name, eventHandlerFunction templateFunction, void *handlerParam=0);
00193
00197 static void * dispatchEvent(void *args);
00198
00199 blocking_queue<T> buffer;
00200 bool stop_thread;
00201 pthread_t dispatching_thread;
00202
00203 RepeatGuard receiverTooSlowLogRepeatGuard;
00204 unsigned int numEventsDiscarded;
00205
00206 };
00207 };
00208
00209 #include "acsncSimpleConsumer.i"
00210
00222 #define ACS_NEW_SIMPLE_CONSUMER(simpConsumer_p, idlStruct, channelName, handlerFunction, handlerParam) \
00223 { \
00224 simpConsumer_p = new nc::SimpleConsumer<idlStruct>(channelName); \
00225 simpConsumer_p->addSubscription<idlStruct>(handlerFunction, handlerParam);\
00226 }
00227
00240 #define ACS_NEW_SIMPLE_CONSUMER_WITH_DOMAIN(simpConsumer_p, idlStruct, channelName, domainname, handlerFunction, handlerParam) \
00241 { \
00242 simpConsumer_p = new nc::SimpleConsumer<idlStruct>(channelName,domainname); \
00243 simpConsumer_p->addSubscription<idlStruct>(handlerFunction, handlerParam);\
00244 }
00245
00246 #endif