• 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.17 2011/02/17 18:25:39 rtobar 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                    const ACE_CString& type,
00087                    CharacteristicModelImpl *characteristicModel,
00088                    size_t actionThreadStackSize,
00089                    size_t monitorThreadStackSize,
00090                    const ACS::TimeInterval& actionThreadResponseTime=defaultRTResponseTime_m, 
00091                    const ACS::TimeInterval& actionThreadSleepTime=minRTSleepTime_m,
00092                    const ACS::TimeInterval& monitorThreadResponseTime=defaultMTResponseTime_m,
00093                    const ACS::TimeInterval& monitorThreadSleepTime=minMTSleepTime_m);
00094 
00095   ~BACIComponent();
00096 
00097 //  ACE_CString getName() const { return name; }
00098   const char * getName() const { return name_m.c_str(); }
00099 
00100   const char * getType() const { return type_m.c_str(); }
00101 
00109   int registerCallback(const BACIValue::Type type,
00110                        Callback_ptr callback_p, 
00111                        const CBDescIn descIn);
00112 
00123    int registerAction(const BACIValue::Type type,
00124                      Callback_ptr callback_p, 
00125                      const CBDescIn descIn,
00126                      ActionImplementator* actionImplementator_,
00127                      int actionFunction_);
00128 
00138   int registerAction(const BACIValue::Type type,
00139                      Callback_ptr callback_p, 
00140                      const CBDescIn descIn,
00141                      ActionImplementator* actionImplementator_,
00142                      int actionFunction,
00143                      const BACIValue& value);
00144 
00145   BACIThreadManager* getThreadManager() const { return threadManager_mp; }
00146 
00147   ACS::TimeInterval getMTResponseTime() const { return monitorThreadResponseTime_m; }
00148   void setMTResponseTime(const ACS::TimeInterval& _monitorThreadResponseTime);
00149 
00150   ACS::TimeInterval getMTSleepTime() const { return monitorThreadSleepTime_m; }
00151   void setMTSleepTime(const ACS::TimeInterval& _monitorThreadSleepTime);
00152   
00153   ACS::TimeInterval getRTResponseTime() const { return actionThreadResponseTime_m; }
00154   void setRTResponseTime(const ACS::TimeInterval& _actionThreadResponseTime);
00155 
00156   ACS::TimeInterval getRTSleepTime() const { return actionThreadSleepTime_m; }
00157   void setRTSleepTime(const ACS::TimeInterval& _actionThreadSleepTime);
00158 
00159     bool dispatchCallback(int callbackID, 
00160                           const BACIValue& value, 
00161                           CBDescOut& descOut,
00162                           const Completion& completion,
00163                         const BACIMonitor * archiver = 0);
00164     bool finishCallback(int callbackID, 
00165                         const BACIValue& value, 
00166                       CBDescOut& descOut, const Completion& completion);
00167 
00168 
00169   bool isInDestructionState() const { return inDestructionState_m; };
00170 
00171   
00172   int getActionCount() const { return actionQueue_m.size(); }
00173   void pushAction(BACIAction* action);
00174   BACIAction* popAction();
00175 
00176   void removeCallbackAndAction(int callbackID);
00177     BACICallback* getCallback(int callbackID);
00178     void removeCallback(int callbackID);
00179     
00180   int getPropertyCount() const { return propertyVector_m.size(); }
00181   BACIProperty* getPropertyAt(int pos) const;
00182 
00183   void stopAllThreads();
00184   bool startAllThreads();
00185 
00192   void startMonitoringThread();
00193 
00201    void startActionThread();
00202 
00207    void stopMonitoringThread();
00208 
00213     void stopActionThread();
00214 
00220     void cancelMonitoringThread();
00221 
00227     void cancelActionThread();
00228 
00229 
00234     bool isMonitoringActive();
00235 
00240     bool isActionThreadActive();
00241 
00242     CharacteristicModelImpl* getCharacteristicModel() const { return characteristicModel_mp; };
00243 
00244 protected:
00245 
00246   static const ACS::TimeInterval defaultRTResponseTime_m;                       // RT = Action Thread
00247   static const ACS::TimeInterval minRTSleepTime_m;
00248   
00249   static const ACS::TimeInterval defaultMTResponseTime_m;                       // MT = Monitor Thread
00250   static const ACS::TimeInterval minMTSleepTime_m;
00251 
00252 
00253   BACIThread* getActionThread() const { return actionThread_mp; }
00254   BACIThread* getMonitorThread() const { return monitorThread_mp; }
00255 
00256   int getThreadCount() const { return threadManager_mp->getThreadCount(); }
00257 
00258     void removeAction(int callbackID);
00259 
00260   void addProperty(BACIProperty* property);
00261   void removeProperty(BACIProperty* property);
00262 
00263 private:
00264 
00265   ACE_CString name_m;
00266   ACE_CString type_m;
00267   CharacteristicModelImpl* characteristicModel_mp;
00268 
00269   BACICallbackTable callbackTable_m;
00270   BACIActionQueue actionQueue_m;
00271   BACIPropertyVector propertyVector_m;
00272 
00273     ACS::TimeInterval actionThreadResponseTime_m;
00274     ACS::TimeInterval actionThreadSleepTime_m;
00275     ACS::TimeInterval monitorThreadResponseTime_m;
00276     ACS::TimeInterval monitorThreadSleepTime_m;
00277 
00278   BACIThread* actionThread_mp;
00279   BACIThread* monitorThread_mp;
00280   BACIThreadManager* threadManager_mp;
00281 
00282   bool inDestructionState_m;
00283 
00284   BACIMutex actionQueueMutex_m;
00285   BACIMutex propertyVectorMutex_m;
00286   BACIMutex callbackTableMutex_m;
00287 
00288   size_t actionThreadStackSize_m;
00289   size_t monitoringThreadStackSize_m;
00290 
00291   friend class BACIProperty;
00292 
00296     void operator=(const BACIComponent&);
00297     
00301     BACIComponent(const BACIComponent&);
00302 
00303 };   /* BACIComponent */
00304 
00305 /* ------------------------------------------------------------------------ */
00306 
00307 }//namespace baci
00308 
00309 
00310 #endif /* baci_H */ 
00311 
00312 

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