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
CharacteristicModelImpl *characteristicModel,
00087
const ACS::TimeInterval& actionThreadResponseTime=defaultRTResponseTime_m,
00088
const ACS::TimeInterval& actionThreadSleepTime=minRTSleepTime_m,
00089
const ACS::TimeInterval& monitorThreadResponseTime=defaultMTResponseTime_m,
00090
const ACS::TimeInterval& monitorThreadSleepTime=minMTSleepTime_m);
00091
00092 ~BACIComponent();
00093
00094
00095 const char * getName()
const {
return name_m.c_str(); }
00096
00104
int registerCallback(
const BACIValue::Type type,
00105
Callback_ptr callback_p,
00106
const CBDescIn descIn);
00107
00118
int registerAction(
const BACIValue::Type type,
00119
Callback_ptr callback_p,
00120
const CBDescIn descIn,
00121
ActionImplementator* actionImplementator_,
00122
int actionFunction_);
00123
00133
int registerAction(
const BACIValue::Type type,
00134
Callback_ptr callback_p,
00135
const CBDescIn descIn,
00136
ActionImplementator* actionImplementator_,
00137
int actionFunction,
00138
const BACIValue& value);
00139
00140 BACIThreadManager* getThreadManager()
const {
return threadManager_mp; }
00141
00142 ACS::TimeInterval getMTResponseTime()
const {
return monitorThreadResponseTime_m; }
00143
void setMTResponseTime(
const ACS::TimeInterval& _monitorThreadResponseTime);
00144
00145 ACS::TimeInterval getMTSleepTime()
const {
return monitorThreadSleepTime_m; }
00146
void setMTSleepTime(
const ACS::TimeInterval& _monitorThreadSleepTime);
00147
00148 ACS::TimeInterval getRTResponseTime()
const {
return actionThreadResponseTime_m; }
00149
void setRTResponseTime(
const ACS::TimeInterval& _actionThreadResponseTime);
00150
00151 ACS::TimeInterval getRTSleepTime()
const {
return actionThreadSleepTime_m; }
00152
void setRTSleepTime(
const ACS::TimeInterval& _actionThreadSleepTime);
00153
00154
bool dispatchCallback(
int callbackID,
00155
const BACIValue& value,
00156
CBDescOut& descOut,
00157
const Completion& completion,
00158
const BACIMonitor * archiver = 0);
00159
bool finishCallback(
int callbackID,
00160
const BACIValue& value,
00161
CBDescOut& descOut,
const Completion& completion);
00162
00163
00164 bool isInDestructionState()
const {
return inDestructionState_m; };
00165
00166
00167 int getActionCount()
const {
return actionQueue_m.size(); }
00168
void pushAction(
BACIAction* action);
00169
BACIAction* popAction();
00170
00171
void removeCallbackAndAction(
int callbackID);
00172
BACICallback* getCallback(
int callbackID);
00173
void removeCallback(
int callbackID);
00174
00175 int getPropertyCount()
const {
return propertyVector_m.size(); }
00176
BACIProperty* getPropertyAt(
int pos)
const;
00177
00178
void stopAllThreads();
00179
bool startAllThreads();
00180
00187
void startMonitoringThread();
00188
00196
void startActionThread();
00197
00202
void stopMonitoringThread();
00203
00208
void stopActionThread();
00209
00214
bool isMonitoringActive();
00215
00220
bool isActionThreadActive();
00221
00222 CharacteristicModelImpl* getCharacteristicModel()
const {
return characteristicModel_mp; };
00223
00224
protected:
00225
00226 static const ACS::TimeInterval defaultRTResponseTime_m;
00227 static const ACS::TimeInterval minRTSleepTime_m;
00228
00229 static const ACS::TimeInterval defaultMTResponseTime_m;
00230 static const ACS::TimeInterval minMTSleepTime_m;
00231
00232
00233 BACIThread* getActionThread()
const {
return actionThread_mp; }
00234 BACIThread* getMonitorThread()
const {
return monitorThread_mp; }
00235
00236 int getThreadCount()
const {
return threadManager_mp->getThreadCount(); }
00237
00238
void removeAction(
int callbackID);
00239
00240
void addProperty(
BACIProperty* property);
00241
void removeProperty(
BACIProperty* property);
00242
00243
private:
00244
00245 ACE_CString name_m;
00246 CharacteristicModelImpl* characteristicModel_mp;
00247
00248 BACICallbackTable callbackTable_m;
00249 BACIActionQueue actionQueue_m;
00250 BACIPropertyVector propertyVector_m;
00251
00252 ACS::TimeInterval actionThreadResponseTime_m;
00253 ACS::TimeInterval actionThreadSleepTime_m;
00254 ACS::TimeInterval monitorThreadResponseTime_m;
00255 ACS::TimeInterval monitorThreadSleepTime_m;
00256
00257 BACIThread* actionThread_mp;
00258 BACIThread* monitorThread_mp;
00259 BACIThreadManager* threadManager_mp;
00260
00261 bool inDestructionState_m;
00262
00263 BACIMutex actionQueueMutex_m;
00264 BACIMutex propertyVectorMutex_m;
00265 BACIMutex callbackTableMutex_m;
00266
00267
00268
friend class BACIProperty;
00269
00273
void operator=(
const BACIComponent&);
00274
00278 BACIComponent(
const BACIComponent&);
00279
00280 };
00281
00282
00283
00284 }
00285
00286
00287
#endif
00288
00289