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

acssampObjImpl.h

Go to the documentation of this file.
00001 #ifndef _ACSAMP_OBJ_IMPL_H
00002 #define _ACSAMP_OBJ_IMPL_H 
00003 /*******************************************************************************
00004  *    ALMA - Atacama Large Millimiter Array
00005  *    (c) European Southern Observatory, 2002
00006  *    Copyright by ESO (in the framework of the ALMA collaboration)
00007  *    and Cosylab 2002, All rights reserved
00008  *
00009  *    This library is free software; you can redistribute it and/or
00010  *    modify it under the terms of the GNU Lesser General Public
00011  *    License as published by the Free Software Foundation; either
00012  *    version 2.1 of the License, or (at your option) any later version.
00013  *
00014  *    This library is distributed in the hope that it will be useful,
00015  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017  *    Lesser General Public License for more details.
00018  *
00019  *    You should have received a copy of the GNU Lesser General Public
00020  *    License along with this library; if not, write to the Free Software
00021  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
00022  *
00023  *
00024  * "@(#) $Id: acssampObjImpl.h,v 1.30 2008/10/07 06:41:54 cparedes Exp $"
00025  *
00026  * who       when      what
00027  * --------  --------  ----------------------------------------------
00028  * oat       07/04/03  created 
00029  */
00030 
00031 /************************************************************************
00032  *
00033  *----------------------------------------------------------------------
00034  */
00035 
00036 #ifndef __cplusplus
00037 #error This is a C++ include file and cannot be used from plain C
00038 #endif
00039 
00040 #include "acssampImpl.h"
00041 #include "acssampS.h"
00042 #include <acsncSimpleSupplier.h>
00043 #include <ace/Message_Queue.h>
00044 
00045 #include <sstream>
00046 
00047 
00048 #define ACS_SAMP_C class T, class T_var, class Tval
00049 #define ACS_SAMP_TL T, T_var, Tval
00050 
00051 
00059 //forward declaration
00060 template<ACS_SAMP_C>
00061 class ACSSampObjImpl;
00062 
00063 template<ACS_SAMP_C>
00064 class SamplingThread : public ACS::Thread
00065 {
00066   public:
00067     SamplingThread(const ACE_CString& name,
00068                    ACSSampObjImpl<ACS_SAMP_TL> *sampObj,
00069                    const ACS::TimeInterval& responseTime=ThreadBase::defaultResponseTime, 
00070                    const ACS::TimeInterval& sleepTime=ThreadBase::defaultSleepTime) :
00071         ACS::Thread(name, responseTime, sleepTime),
00072         sampObj_p(sampObj) {}
00073 
00074     ~SamplingThread() {}
00075 
00076     virtual void runLoop()
00077         {
00078             if ( sampObj_p->isInDestructState() ) exit();
00079 //          ACS_DEBUG("acssamp::ACSSampObjImpl::sampThreadWorker","sampling ...");                  
00080             // perform the sampling
00081             sampObj_p->doSamp();
00082         }
00083                 
00084   private:
00085 
00086     ACSSampObjImpl<ACS_SAMP_TL> *sampObj_p;   
00087 };
00088 
00089 
00090 template<ACS_SAMP_C>
00091 class SamplingThreadFlush : public ACS::Thread
00092 {
00093   public:
00094     SamplingThreadFlush(const ACE_CString& name, 
00095                         ACSSampObjImpl<ACS_SAMP_TL> *sampObj,
00096                         const ACS::TimeInterval& responseTime=ThreadBase::defaultResponseTime, 
00097                         const ACS::TimeInterval& sleepTime=ThreadBase::defaultSleepTime) :
00098         ACS::Thread(name, responseTime, sleepTime),
00099         sampObj_p(sampObj) {}
00100 
00101     ~SamplingThreadFlush() {}
00102 
00103     virtual void runLoop()
00104         {
00105             ACS_DEBUG_PARAM("acssamp::ACSSampObjImpl::sampThreadFlush","Starting thread %s",getName().c_str());  
00106       
00107             if (sampObj_p->isInDestructState()) exit();
00108             //  ACS_DEBUG("acssamp::ACSSampObjImpl::sampThreadWorker","flushing on the NC ...");
00109             sampObj_p->flushSamp();
00110         }
00111                 
00112   private:
00113 
00114     ACSSampObjImpl<ACS_SAMP_TL> *sampObj_p;   
00115 };
00116 
00117 
00118 
00119 
00136 template <ACS_SAMP_C>
00137 class ACSSampObjImpl: public virtual POA_acssamp::SampObj,
00138                       public virtual PortableServer::RefCountServantBase
00139 {
00140   
00141   public:
00168     ACSSampObjImpl(const ACE_CString& _cobName, const ACE_CString& _propertyName, 
00169                    ACS::TimeInterval _sampFrequency, ACS::TimeInterval _sampReportRate, baci::BACIComponent *_m_cob, ACS::Property_var _genProperty, ACSSampImpl * _sampPtr);
00170 
00174     virtual ~ACSSampObjImpl();
00175 
00176 
00186     virtual void start ();
00187 
00197     virtual void stop ();
00198     
00208     virtual void destroy();
00209 
00219     virtual void suspend();
00220 
00230     virtual void resume();
00231 
00232 
00247     virtual void setFrequency (ACS::TimeInterval sFrequency);
00248   
00249 
00263     virtual void getFrequency (ACS::TimeInterval_out sFrequency);
00264 
00265 
00266 
00280     virtual void setRate (ACS::TimeInterval rRate);
00281   
00282 
00283 
00296     virtual void getRate (ACS::TimeInterval_out rRate);
00297 
00298 
00299 
00313     virtual void initialize( );
00314 
00324     virtual void doSamp();
00325 
00326 
00335     virtual void flushSamp();
00336 
00337 
00346     ACS::TimeInterval getSampFrequency() const { return sampFrequency; }
00347 
00357     void setSampFrequency(const ACS::TimeInterval& _sampFrequency);
00358 
00367     ACS::TimeInterval getReportRate() const { return sampReportRate; }
00368 
00378     void setReportRate(const ACS::TimeInterval& _sampReportRate);
00379 
00389     CORBA::Object_ptr getCORBAReference() const { return reference_p; }
00390 
00391 
00406     virtual char * getChannelName();
00407     
00408 
00414     struct SampData {
00415         ACS::Time timeStamp; 
00416         Tval val;
00417     };
00418 
00419 
00429     bool isInDestructState() const { return inDestructState; };
00430 
00431   private:
00432   
00433   
00434     //ACE_CString name;  
00435     ACE_CString cobName; 
00436     ACE_CString propertyName;
00437     ACE_CString sampObjName;
00438     ACE_CString sampChannelName;
00439 
00440     ACS::TimeInterval sampFrequency;
00441     ACS::TimeInterval sampReportRate;
00442 
00443     bool inDestructState;
00444 
00448     baci::BACIComponent *cob_p;
00449 
00455     SamplingThread<ACS_SAMP_TL> *controlLoop_p;
00456 
00463     SamplingThreadFlush<ACS_SAMP_TL> *flush_p;
00464  
00465     //ACS::ThreadManager *threadManager_p;
00466 
00467     ACS::Property_var genProperty_p;
00468 
00469     T_var propToSamp_p;
00470 
00475     ACE_Message_Queue<ACE_SYNCH> *mq_p;
00476 
00477 //  nc::SimpleSupplier<acssamp::SampObj::SampDataBlock> *sampSupplier_p;
00478 
00479     nc::SimpleSupplier *sampSupplier_p;
00480 
00481     CORBA::Object_ptr reference_p;
00482 
00483     ACSSampImpl *samp_p;
00484 };
00485 
00486 
00487 
00491 #include "acssampObjImpl.i"
00492 
00493 
00494 #endif 

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