00001
00002
00003
00004
00005
00006
00007
00008 #ifndef INSTANT_H
00009 #define INSTANT_H
00010
00011 #include <transpose.h>
00012 #include <granules.h>
00013 #include <cafeEnum.h>
00014
00015
00016 template <class CTYPE> class Instant {
00017
00018 private:
00019 Transpose<dbr_string_t> renderString;
00020 Transpose<dbr_short_t> renderShort;
00021 Transpose<dbr_float_t> renderFloat;
00022 Transpose<dbr_enum_t> renderEnum;
00023 Transpose<dbr_char_t> renderChar;
00024 Transpose<dbr_long_t> renderLong;
00025 Transpose<dbr_double_t> renderDouble;
00026
00027 CAFEStatus cafeStatus;
00028 Granules cafeGranules;
00029
00030 PolicyHelper policyHelper;
00031
00032 HandleHelper helper;
00033
00034 Conduit cc;
00035 ChannelTimeoutPolicy channelTimeoutPolicyGet;
00036 ChannelRequestPolicy channelRequestPolicyGet;
00037 ChannelRequestStatus channelRequestStatusGet;
00038 ChannelRequestDataTypePolicy channelRequestDataTypePolicy;
00039
00040 ChannelRequestMetaDataClient channelRequestMetaDataClient;
00041
00042 int status;
00043
00044 int clientRequests(const unsigned int _handle, const chtype dbrType, const CTYPE * _val);
00045
00046 int clientRequests(const unsigned int _handle, const chtype dbrType, CTYPE * _val,
00047 dbr_short_t &alarmStatus, dbr_short_t &alarmSeverity, epicsTimeStamp &ts,
00048 bool isCacheRequest);
00049 public:
00050
00051 Instant (){};
00052 ~Instant (){};
00053
00054 int set(const unsigned int *handleArray, const unsigned int nelem,
00055 const chtype _dbrType, const CTYPE * val, int *statusArray);
00056
00057 int set(const unsigned int _handle, const chtype dbrType, const CTYPE * _val);
00058
00059 int get(const unsigned int _handle, const chtype dbrType, CTYPE * _val,
00060 dbr_short_t &alarmStatus, dbr_short_t &alarmSeverity, epicsTimeStamp &ts);
00061
00062 int get(const unsigned int _handle, const chtype dbrType, CTYPE * _val,
00063 dbr_short_t &alarmStatus, dbr_short_t &alarmSeverity){
00064 epicsTimeStamp ts;
00065 return get(_handle, dbrType, _val, alarmStatus, alarmSeverity, ts);
00066 };
00067
00068 int get(const unsigned int _handle, const chtype dbrType, CTYPE * _val){
00069 dbr_short_t alarmStatus; dbr_short_t alarmSeverity; epicsTimeStamp ts;
00070 return get(_handle, dbrType, _val, alarmStatus, alarmSeverity, ts);
00071 };
00072
00073 int getCache(const unsigned int _handle, const chtype dbrType, CTYPE * _val,
00074 dbr_short_t &alarmStatus, dbr_short_t &alarmSeverity, epicsTimeStamp &ts);
00075
00076 int getCache(const unsigned int _handle, const chtype dbrType, CTYPE * _val,
00077 dbr_short_t &alarmStatus, dbr_short_t &alarmSeverity){
00078 epicsTimeStamp ts;
00079 return getCache(_handle, dbrType, _val, alarmStatus, alarmSeverity, ts);
00080 };
00081
00082 int getCache(const unsigned int _handle, const chtype dbrType, CTYPE * _val){
00083 dbr_short_t alarmStatus; dbr_short_t alarmSeverity; epicsTimeStamp ts;
00084 return getCache(_handle, dbrType, _val, alarmStatus, alarmSeverity, ts);
00085 };
00086
00087 int getCache(const unsigned int *handleArray, const unsigned int nelem,
00088 const chtype _dbrType, CTYPE * val, int *statusArray,
00089 dbr_short_t *alarmStatus, dbr_short_t *alarmSeverity, epicsTimeStamp *ts);
00090
00091 int getCache(const unsigned int *handleArray, const unsigned int nelem,
00092 const chtype _dbrType, CTYPE * val, int *statusArray,
00093 dbr_short_t *alarmStatus, dbr_short_t *alarmSeverity ) {
00094 epicsTimeStamp * ts;
00095 return getCache(handleArray, nelem, _dbrType, val, statusArray,
00096 alarmStatus, alarmSeverity, ts);
00097 };
00098 int getCache(const unsigned int *handleArray, const unsigned int nelem,
00099 const chtype _dbrType, CTYPE * val, int *statusArray) {
00100 dbr_short_t * alarmStatus; dbr_short_t * alarmSeverity; epicsTimeStamp * ts;
00101 return getCache(handleArray, nelem, _dbrType, val, statusArray,
00102 alarmStatus, alarmSeverity, ts);
00103 };
00104
00105 int setAndGet(const unsigned int handleSet, const chtype dbrType, CTYPE valSet, CTYPE &valGet);
00106 int setAndMatch(const unsigned int handleSet, const chtype dbrType, CTYPE valSet, const unsigned int handleMatch,
00107 CTYPE tolerance, double timeout, bool printFlag);
00108
00109 int setAndMatchMany(std::vector<unsigned int> handleSetV, const chtype dbrType, std::vector<CTYPE> valSet, std::vector<unsigned int> handleMatch,
00110 CTYPE tolerance, double timeout, bool printFlag);
00111
00112 int setTriggerAndMatchMany(std::vector<unsigned int> handleSetV, const chtype dbrType, std::vector<CTYPE> valSet,
00113 std::vector<unsigned int> handleAction, std::vector<std::string> valAction, std::vector<unsigned int> handleMatch,
00114 CTYPE tolerance, double timeout, bool printFlag);
00115
00116 int matchMany( const chtype dbrType, std::vector<CTYPE> valSet, std::vector<unsigned int> handleMatch,
00117 CTYPE tolerance, double timeout, bool printFlag);
00118
00119 int match( const chtype dbrType, CTYPE valSet, unsigned int handleMatch,
00120 CTYPE tolerance, double timeout, bool printFlag);
00121
00122 int setMany(std::vector<unsigned int> handleSet, const chtype dbrType, std::vector<CTYPE> valSet, bool printFlag);
00123
00124
00125
00126 int compareAndMatchMany(std::vector<unsigned int> handleSet, const chtype dbrType, std::vector<CTYPE> valSet, std::vector<unsigned int> handleMatch,
00127 CTYPE tolerance, double timeout, bool printFlag);
00128
00129
00130
00131 int setManyString(std::vector<unsigned int> handleSet, std::vector<std::string> valSet, bool printFlag) {
00132
00133 #define __METHOD__ "Instant<CTYPE>::setMany(vector<unsigned int>handleSet, chtype, vector<CTYPE>valSet)"
00134
00135 CAFEStatus cstat;
00136
00137
00138 status=ICAFE_NORMAL;
00139
00140 if (handleSet.size() != valSet.size() ) {
00141 return ECAFE_HANDLE_MISMATCH_SET_AND_MATCH;
00142 }
00143
00144 for (size_t i=0; i< handleSet.size(); ++i) {
00145
00146 if (!helper.isChannelConnected(handleSet[i])) {
00147 std::cout << __FILE__ << "//" << __LINE__ << "//" << __METHOD__ << std::endl;
00148 std::cout << "NOT ALL CHANNELS CONNECTED: " << std::endl;
00149 if (!helper.isChannelConnected(handleSet[i])) {
00150 helper.printHandle(handleSet[i]);
00151 status=helper.getStatus(handleSet[i]);
00152 }
00153 }
00154
00155 }
00156
00157
00158 if (status!=ICAFE_NORMAL) {return status;}
00159
00160 if(printFlag) {
00161 std::cout << __FILE__ << "//" << __LINE__ << "//" << __METHOD__ << std::endl;
00162 }
00163
00164
00165 if (printFlag) {
00166
00167 for (size_t i=0; i< handleSet.size(); ++i) {
00168
00169 std::cout << "SETTING PV=" << helper.getPVFromHandle(handleSet[i]) << " to " << valSet[i] << std::endl;
00170
00171
00172 }
00173
00174 }
00175
00176
00177 for (size_t i=0; i< handleSet.size(); ++i) {
00178
00179
00180
00181
00182
00183 unsigned int nelemPrevious, nelemRequestedCheck=0;
00184 unsigned int nelemRequested=1;
00185
00186 nelemPrevious=helper.getNelemClient(handleSet[i]);
00187
00188 if (nelemPrevious>1) {
00189 nelemRequestedCheck = helper.setNelem(handleSet[i],nelemRequested);
00190 if (nelemRequestedCheck != nelemRequested) {
00191 std::cout << __FILE__ << "//" << __LINE__ << "//" << __METHOD__ << std::endl;
00192 std::cout << "Internal CAFE FUNNY: Wanted to set the no. elements from: "
00193 << nelemPrevious << std::endl;
00194 std::cout << "to: " << nelemRequested << " but got instead: "
00195 << nelemRequestedCheck << std::endl;
00196 }
00197 }
00198
00199
00200
00201
00202 ChannelRequestPolicy polPrevious, polNow;
00203
00204 policyHelper.getChannelRequestPolicyPut(handleSet[i], polPrevious);
00205
00206 polNow.setMethodKind(WITHOUT_CALLBACK);
00207 polNow.setWaitKind(WAIT);
00208 polNow.setWhenToFlushSendBuffer(FLUSH_AUTOMATIC);
00209
00210 policyHelper.setChannelRequestPolicyPut(handleSet[i], polNow);
00211
00212 dbr_string_t valSetA[1];
00213
00214
00215 helper.removeLeadingAndTrailingSpaces(valSet[i].c_str(), valSetA[0]);
00216
00217
00218 status=set(handleSet[i], DBR_STRING, valSetA);
00219
00220 if (status!=ICAFE_NORMAL) {
00221 std::cout << __FILE__ << "//" << __LINE__ << "//" << __METHOD__ << std::endl;
00222 cstat.report(status);
00223 }
00224
00225 policyHelper.setChannelRequestPolicyPut(handleSet[i], polPrevious);
00226
00227
00228 unsigned int nelemPreviousCheck=nelemPrevious;
00229 nelemRequested=1;
00230
00231
00232 if(helper.getNelemRequest(handleSet[i])!= nelemPrevious) {
00233 nelemPreviousCheck= helper.setNelem(handleSet[i],nelemPrevious);
00234 if (nelemPreviousCheck != nelemPrevious) {
00235 std::cout << __FILE__ << "//" << __LINE__ << "//" << __METHOD__ << std::endl;
00236 std::cout << "Internal CAFE FUNNY: Wanted to re-set the no. elements from: "
00237 << nelemRequested << std::endl;
00238 std::cout << "to the previous: " << nelemPrevious << " but got instead: "
00239 << nelemPreviousCheck << std::endl;
00240 }
00241 }
00242
00243
00244 }
00245
00246 return status;
00247 #undef __METHOD__
00248 }
00249
00257 int setAndGetString(const unsigned int handleSet, std::string valSet, std::string &valGet) {
00258 #define __METHOD__ "Instant<CTYPE>::setAndGetString(const unsigned int handleSet, std::string valSet, std::string &valGet"
00259
00260
00261 dbr_string_t valGetA[1]; dbr_string_t valSetA[1];
00262
00263 strcpy(valGetA[0],"0");
00264 valGet="0";
00265
00266 helper.removeLeadingAndTrailingSpaces(valSet.c_str(), valSetA[0]);
00267
00268 status=Instant::set(handleSet, DBR_STRING, valSetA);
00269 if (status==ICAFE_NORMAL) {
00270 status=Instant::get(handleSet, DBR_STRING, valGetA);
00271
00272 valGet=valGetA[0];
00273 }
00274 else {
00275 return status;
00276 }
00277
00278 if (strcmp(valSetA[0],valGetA[0])==0) {
00279 return ICAFE_NORMAL;
00280 }
00281
00282
00283 std::istringstream ins, ous;
00284 double oud=0;
00285 ous.clear();
00286 ous.str(valGetA[0]);
00287 ous>>oud;
00288 double ind=0;
00289 ins.clear();
00290 ins.str(valSetA[0]);
00291 ins>>ind;
00292
00293
00294 if ( !ous.fail() && !ins.fail()) {
00295 if (ind==oud) {return ICAFE_NORMAL;}
00296 }
00297
00298 else if (!ins.fail()) {
00299 short enumval=-1;
00300
00301 enumval=helper.getEnumFromString(handleSet, valGet);
00302
00303
00304
00305 std::stringstream ss;
00306 ss << enumval;
00307 valGet= ss.str();
00308 if ((short)ind==enumval) {
00309 return ICAFE_NORMAL;
00310 }
00311
00312 }
00313
00314
00315 std::cout << __FILE__ << "//" << __LINE__ << "//" << __METHOD__ << std::endl;
00316 std::cout << "Process Variable = " << helper.getPVFromHandle(handleSet) << std::endl;
00317 std::cout << "Set Value: " << valSetA[0] << " Get Value: " << valGet.c_str() << std::endl;
00318 return ICAFE_SET_AND_GET_MISMATCH;
00319 #undef __METHOD__
00320
00321 };
00322
00323
00331 int setAndGetDbrString(const unsigned int handleSet, dbr_string_t valSet, dbr_string_t &valGet) {
00332 #define __METHOD__ "Instant<CTYPE>::setAndGetDbrString(const unsigned int handleSet, dbr_string_tvalSet, dbr_string_t &valGet"
00333
00334
00335 dbr_string_t valGetA[1]; dbr_string_t valSetA[1];
00336
00337 strcpy(valGetA[0],"0");
00338 strcpy(valGet,"0");
00339
00340 helper.removeLeadingAndTrailingSpaces(valSet, valSetA[0]);
00341
00342 status=Instant::set(handleSet, DBR_STRING, valSetA);
00343 if (status==ICAFE_NORMAL) {
00344 status=Instant::get(handleSet, DBR_STRING, valGetA);
00345
00346 strcpy(valGet,valGetA[0]);
00347 }
00348 else {
00349 return status;
00350 }
00351
00352 if (strcmp(valSetA[0],valGetA[0])==0) {
00353 return ICAFE_NORMAL;
00354 }
00355
00356
00357
00358 std::istringstream ins, ous;
00359 double oud=0;
00360 ous.clear();
00361 ous.str(valGetA[0]);
00362 ous>>oud;
00363 double ind=0;
00364 ins.clear();
00365 ins.str(valSetA[0]);
00366 ins>>ind;
00367
00368 if ( !ous.fail() && !ins.fail()) {
00369 if (ind==oud) {return ICAFE_NORMAL;}
00370 }
00371
00372 else if (!ins.fail()) {
00373 short enumval=-1;
00374
00375 enumval=helper.getEnumFromString(handleSet, valGet);
00376
00377
00378 std::stringstream ss;
00379 ss << enumval;
00380 strcpy(valGet, ss.str().c_str());
00381
00382 if ((short) ind==enumval) {
00383 return ICAFE_NORMAL;
00384 }
00385
00386
00387 }
00388
00389
00390 std::cout << __FILE__ << "//" << __LINE__ << "//" << __METHOD__ << std::endl;
00391 std::cout << "Process Variable = " << helper.getPVFromHandle(handleSet) << std::endl;
00392 std::cout << "Set Value: " << valSetA[0] << " Get Value: " << valGet << std::endl;
00393 return ICAFE_SET_AND_GET_MISMATCH;
00394 #undef __METHOD__
00395
00396 };
00397
00398 };
00399
00400 #include "instant.cpp"
00401
00402 #endif // INSTANT_H
00403