• Classes
  • Modules
  • Namespaces
  • Files
  • Related Pages
  • File List
  • File Members

acsncSimpleConsumer.h

Go to the documentation of this file.
00001 #ifndef SIMPLE_CONSUMER_H
00002 #define SIMPLE_CONSUMER_H
00003 /*    @(#) $Id: acsncSimpleConsumer.h,v 1.13.2.1 2012/01/03 22:35:31 javarias Exp $
00004  *    ALMA - Atacama Large Millimiter Array
00005  *    (c) Associated Universities Inc., 2002 
00006  *    (c) European Southern Observatory, 2002
00007  *    Copyright by ESO (in the framework of the ALMA collaboration)
00008  *    and Cosylab 2002, All rights reserved
00009  *
00010  *    This library is free software; you can redistribute it and/or
00011  *    modify it under the terms of the GNU Lesser General Public
00012  *    License as published by the Free Software Foundation; either
00013  *    version 2.1 of the License, or (at your option) any later version.
00014  *
00015  *    This library is distributed in the hope that it will be useful,
00016  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  *    Lesser General Public License for more details.
00019  *
00020  *    You should have received a copy of the GNU Lesser General Public
00021  *    License along with this library; if not, write to the Free Software
00022  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
00023  */
00024 
00030 #include "acsncConsumer.h"
00031 #include <acsutilAnyAide.h>
00032 #include "acsncErrType.h"
00033 namespace nc {
00034 
00050 template <class T> class SimpleConsumer : public Consumer
00051 {
00052   public:
00061     typedef void (*eventHandlerFunction)(T eventData, void *handlerParam);
00063 
00067     SimpleConsumer(const char* channelName);
00069 
00088     template <class J> void
00089     addSubscription(eventHandlerFunction templateFunction, void *handlerParam=0)
00090         {
00091             ACS_TRACE("SimpleConsumer::addSubscription");
00092             
00093             //yikes...the developer is trying to subscribe to multiple event
00094             //types from a singly templated class.
00095             if (templateFunction_mp!=0)
00096                 {
00097                 ACS_SHORT_LOG((LM_ERROR,
00098                                "SimpleConsumer::addSubscription unable to subscribe to multiple event types from this class!"));
00099                 ACSErrTypeCommon::CouldntPerformActionExImpl err = ACSErrTypeCommon::CouldntPerformActionExImpl(__FILE__,
00100                                                                             __LINE__,
00101                                                                             "nc::SimpleConsumer::addSubscription");
00102                 throw err.getCouldntPerformActionEx();
00103                 }
00104             
00105             //save a reference to the eventHandlerFunction
00106             templateFunction_mp = templateFunction;
00107             
00108             //save the parameter to handler
00109             handlerParam_mp = handlerParam;
00110             
00111             //just call superclass implementation
00112             Consumer::addSubscription<J>();
00113         }
00114     
00127     virtual void 
00128     push_structured_event(const CosNotification::StructuredEvent &notification);
00130   protected:
00134     virtual ~SimpleConsumer();
00135 
00139     eventHandlerFunction templateFunction_mp;
00144     void *handlerParam_mp;
00145 
00146   private:
00150     void operator=(const SimpleConsumer&);
00151 
00155     SimpleConsumer(const SimpleConsumer&);
00156 
00158 
00175     void
00176     addSubscription(const char* type_name, eventHandlerFunction templateFunction, void *handlerParam=0);
00177 };
00178  }; 
00179 
00180 #include "acsncSimpleConsumer.i"
00181 
00193 #define ACS_NEW_SIMPLE_CONSUMER(simpConsumer_p, idlStruct, channelName, handlerFunction, handlerParam) \
00194 { \
00195   simpConsumer_p = new nc::SimpleConsumer<idlStruct>(channelName); \
00196   simpConsumer_p->addSubscription<idlStruct>(handlerFunction, handlerParam);\
00197 }
00198 
00199 #endif

Generated on Thu Jan 12 2012 23:13:50 for ACS-10.0 C++ API by  doxygen 1.7.0