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

baciBACIComponent.h

Go to the documentation of this file.
00001 #ifndef baciBACIComponent_H
00002 #define baciBACIComponent_H
00003 
00004 /*******************************************************************
00005 * ALMA - Atacama Large Millimiter Array
00006 * (c) European Southern Observatory, 2003 
00007 *
00008 *This library is free software; you can redistribute it and/or
00009 *modify it under the terms of the GNU Lesser General Public
00010 *License as published by the Free Software Foundation; either
00011 *version 2.1 of the License, or (at your option) any later version.
00012 *
00013 *This library is distributed in the hope that it will be useful,
00014 *but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016 *Lesser General Public License for more details.
00017 *
00018 *You should have received a copy of the GNU Lesser General Public
00019 *License along with this library; if not, write to the Free Software
00020 *Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
00021 *
00022 * "@(#) $Id: baciBACIComponent.h,v 1.15 2009/10/08 09:05:13 bjeram Exp $"
00023 *
00024 * who       when      what
00025 * --------  --------  ----------------------------------------------
00026 * bgustafs 2001-07-12 changed name of parameter in setCompletion
00027 * msekoran  2001/03/04 modified
00028 */
00029 
00035 #ifndef __cplusplus
00036 #error This is a C++ include file and cannot be used from plain C
00037 #endif
00038 
00039 #include "baciExport.h"
00040 #include "baciThread.h"
00041 #include "baciValue.h"
00042 #include "logging.h"
00043 
00044 #include "baciBACIAction.h"
00045 #include "baciBACICallback.h"
00046 #include "baciBACIMonitor.h"
00047 #include "baciBACIProperty.h"
00048 #include <acsThreadManager.h>
00049 #include "baciCharacteristicModelImpl.h"
00050 #include <baciErrTypeProperty.h>
00051 #include <ACSErrTypeCommon.h>
00052 
00053 namespace baci
00054 {
00055 
00056 
00057 /* ------------------------------------------------------------------------ */
00058 
00059 
00060 
00068 class baci_EXPORT BACIComponent
00069 {
00070 
00071 public:
00072 
00084     BACIComponent( ACS::ThreadManager *thrMgr,
00085                    const ACE_CString& name,
00086                    CharacteristicModelImpl *characteristicModel,
00087                    size_t actionThreadStackSize,
00088                    size_t monitorThreadStackSize,
00089                    const ACS::TimeInterval& actionThreadResponseTime=defaultRTResponseTime_m, 
00090                    const ACS::TimeInterval& actionThreadSleepTime=minRTSleepTime_m,
00091                    const ACS::TimeInterval& monitorThreadResponseTime=defaultMTResponseTime_m,
00092                    const ACS::TimeInterval& monitorThreadSleepTime=minMTSleepTime_m);
00093 
00094   ~BACIComponent();
00095 
00096 //  ACE_CString getName() const { return name; }
00097   const char * getName() const { return name_m.c_str(); }
00098 
00106   int registerCallback(const BACIValue::Type type,
00107                        Callback_ptr callback_p, 
00108                        const CBDescIn descIn);
00109 
00120    int registerAction(const BACIValue::Type type,
00121                      Callback_ptr callback_p, 
00122                      const CBDescIn descIn,
00123                      ActionImplementator* actionImplementator_,
00124                      int actionFunction_);
00125 
00135   int registerAction(const BACIValue::Type type,
00136                      Callback_ptr callback_p, 
00137                      const CBDescIn descIn,
00138                      ActionImplementator* actionImplementator_,
00139                      int actionFunction,
00140                      const BACIValue& value);
00141 
00142   BACIThreadManager* getThreadManager() const { return threadManager_mp; }
00143 
00144   ACS::TimeInterval getMTResponseTime() const { return monitorThreadResponseTime_m; }
00145   void setMTResponseTime(const ACS::TimeInterval& _monitorThreadResponseTime);
00146 
00147   ACS::TimeInterval getMTSleepTime() const { return monitorThreadSleepTime_m; }
00148   void setMTSleepTime(const ACS::TimeInterval& _monitorThreadSleepTime);
00149   
00150   ACS::TimeInterval getRTResponseTime() const { return actionThreadResponseTime_m; }
00151   void setRTResponseTime(const ACS::TimeInterval& _actionThreadResponseTime);
00152 
00153   ACS::TimeInterval getRTSleepTime() const { return actionThreadSleepTime_m; }
00154   void setRTSleepTime(const ACS::TimeInterval& _actionThreadSleepTime);
00155 
00156     bool dispatchCallback(int callbackID, 
00157                           const BACIValue& value, 
00158                           CBDescOut& descOut,
00159                           const Completion& completion,
00160                         const BACIMonitor * archiver = 0);
00161     bool finishCallback(int callbackID, 
00162                         const BACIValue& value, 
00163                       CBDescOut& descOut, const Completion& completion);
00164 
00165 
00166   bool isInDestructionState() const { return inDestructionState_m; };
00167 
00168   
00169   int getActionCount() const { return actionQueue_m.size(); }
00170   void pushAction(BACIAction* action);
00171   BACIAction* popAction();
00172 
00173   void removeCallbackAndAction(int callbackID);
00174     BACICallback* getCallback(int callbackID);
00175     void removeCallback(int callbackID);
00176     
00177   int getPropertyCount() const { return propertyVector_m.size(); }
00178   BACIProperty* getPropertyAt(int pos) const;
00179 
00180   void stopAllThreads();
00181   bool startAllThreads();
00182 
00189   void startMonitoringThread();
00190 
00198    void startActionThread();
00199 
00204    void stopMonitoringThread();
00205 
00210     void stopActionThread();
00211 
00216     bool isMonitoringActive();
00217 
00222     bool isActionThreadActive();
00223 
00224     CharacteristicModelImpl* getCharacteristicModel() const { return characteristicModel_mp; };
00225 
00226 protected:
00227 
00228   static const ACS::TimeInterval defaultRTResponseTime_m;                       // RT = Action Thread
00229   static const ACS::TimeInterval minRTSleepTime_m;
00230   
00231   static const ACS::TimeInterval defaultMTResponseTime_m;                       // MT = Monitor Thread
00232   static const ACS::TimeInterval minMTSleepTime_m;
00233 
00234 
00235   BACIThread* getActionThread() const { return actionThread_mp; }
00236   BACIThread* getMonitorThread() const { return monitorThread_mp; }
00237 
00238   int getThreadCount() const { return threadManager_mp->getThreadCount(); }
00239 
00240     void removeAction(int callbackID);
00241 
00242   void addProperty(BACIProperty* property);
00243   void removeProperty(BACIProperty* property);
00244 
00245 private:
00246 
00247   ACE_CString name_m;
00248   CharacteristicModelImpl* characteristicModel_mp;
00249 
00250   BACICallbackTable callbackTable_m;
00251   BACIActionQueue actionQueue_m;
00252   BACIPropertyVector propertyVector_m;
00253 
00254     ACS::TimeInterval actionThreadResponseTime_m;
00255     ACS::TimeInterval actionThreadSleepTime_m;
00256     ACS::TimeInterval monitorThreadResponseTime_m;
00257     ACS::TimeInterval monitorThreadSleepTime_m;
00258 
00259   BACIThread* actionThread_mp;
00260   BACIThread* monitorThread_mp;
00261   BACIThreadManager* threadManager_mp;
00262 
00263   bool inDestructionState_m;
00264 
00265   BACIMutex actionQueueMutex_m;
00266   BACIMutex propertyVectorMutex_m;
00267   BACIMutex callbackTableMutex_m;
00268 
00269   size_t actionThreadStackSize_m;
00270   size_t monitoringThreadStackSize_m;
00271 
00272   friend class BACIProperty;
00273 
00277     void operator=(const BACIComponent&);
00278     
00282     BACIComponent(const BACIComponent&);
00283 
00284 };   /* BACIComponent */
00285 
00286 /* ------------------------------------------------------------------------ */
00287 
00288 }//namespace baci
00289 
00290 
00291 #endif /* baci_H */ 
00292 
00293 

Generated on Thu Jul 8 2010 19:47:46 for ACS-9.0 C++ API by  doxygen 1.7.0