Go to the documentation of this file.00001 #ifndef baciBACIComponent_H
00002 #define baciBACIComponent_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
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
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;
00247 static const ACS::TimeInterval minRTSleepTime_m;
00248
00249 static const ACS::TimeInterval defaultMTResponseTime_m;
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 };
00304
00305
00306
00307 }
00308
00309
00310 #endif
00311
00312