22 #include <cmw-rda/RDAService.h>
23 #include <cmw-rda/Config.h>
24 #include <cmw-rda/DeviceHandle.h>
25 #include <cmw-rda/ReplyHandler.h>
28 class rdaDabcHandler :
public rdaReplyHandler
45 bool subscribe(rdaDeviceHandle* device,
const std::string &cycle)
48 fRequest = device->monitorOn(fService.c_str(), cycle.c_str(),
false,
this, fContext);
50 }
catch (
const rdaException& ex) {
52 EOUT(
"Exception caught in subscribe: %s %s", ex.getType(), ex.getMessage());
55 EOUT(
"Unknown exception caught in subscribe");
61 bool unsubscribe(rdaDeviceHandle* device)
64 if (fRequest) device->monitorOff(fRequest);
67 }
catch (
const rdaException& ex) {
69 EOUT(
"Exception caught in subscribe: %s %s", ex.getType(), ex.getMessage());
72 EOUT(
"Unknown exception caught in unsubscribe");
78 virtual void handleReply(
const rdaRequest& rq,
const rdaData& value)
84 catch (
const rdaException& ex)
87 EOUT(
"Exception caught in GSIVoltageHandler: %s %s", ex.getType(), ex.getMessage());
92 EOUT(
"Unknown exception caught in handleReply");
100 mbs::MonitorSlowControl(name,
"Fesa", cmd),
107 fHierarchy.Create(
"fesa-monitor",
true);
109 fServerName = Cfg(
"Server", cmd).AsStr();
110 fDeviceName = Cfg(
"Device", cmd).AsStr();
111 fCycle = Cfg(
"Cycle", cmd).AsStr();
113 std::vector<std::string> services = Cfg(
"Services", cmd).AsStrVect();
116 if (!fServerName.empty() && !fDeviceName.empty() && (services.size()>0)) {
117 fRDAService = rdaRDAService::init();
120 fDevice = fRDAService->getDeviceHandle(fDeviceName.c_str(), fServerName.c_str());
122 EOUT(
"Device %s on server %s not found", fDeviceName.c_str(), fServerName.c_str());
127 for (
unsigned n=0;n<services.size();n++) {
133 rdaDabcHandler* handler =
new rdaDabcHandler(
this, services[n]);
134 if (handler->subscribe(fDevice, fCycle))
135 fHandlers.push_back(handler);
142 Publish(fHierarchy,
"FESA/Monitor");
149 for (
unsigned n=0;n<
fHandlers.size();n++) {
164 if (item.
null())
return;
179 if (item.
null())
return;
192 if ((fname.find(
"_") == 0) || value->contains(fname.c_str()))
continue;
197 rdaDataIterator iter(*value);
199 while (iter.hasNext()) {
200 rdaDataEntry* entry = iter.next();
202 const char* tag = entry->tag();
203 if ((tag==0) || (*tag==0)) {
204 EOUT(
"There is no tag specified in field of service %s", name.c_str());
210 switch (entry->getValueType()) {
212 case rdaDataEntry::TYPE_NULL:
break;
214 case rdaDataEntry::TYPE_BOOLEAN: {
215 item.
SetField(tag, entry->extractBoolean());
216 if (fDoRec && !fBlockRec) fRec.AddLong(tag, entry->extractBoolean(),
true);
220 case rdaDataEntry::TYPE_BOOLEAN_ARRAY: {
221 unsigned long size(0);
222 const bool* arr = entry->getBooleanArray(size);
223 std::vector<int64_t> vect;
224 for (
unsigned n=0;n<size;n++) vect.push_back(arr[n] ? 1 : 0);
229 case rdaDataEntry::TYPE_BYTE: {
230 item.
SetField(tag, (int64_t)entry->extractByte());
231 if (fDoRec && !fBlockRec) fRec.AddLong(tag, (int64_t)entry->extractByte(),
true);
235 case rdaDataEntry::TYPE_BYTE_ARRAY: {
236 unsigned long size(0);
237 const signed char* arr = entry->getByteArray(size);
238 std::vector<int64_t> vect;
239 for (
unsigned n=0;n<size;n++) vect.push_back((int64_t)arr[n]);
244 case rdaDataEntry::TYPE_SHORT: {
245 item.
SetField(tag, (int64_t)entry->extractShort());
246 if (fDoRec && !fBlockRec) fRec.AddLong(tag, (int64_t)entry->extractShort(),
true);
250 case rdaDataEntry::TYPE_SHORT_ARRAY: {
251 unsigned long size(0);
252 const short* arr = entry->getShortArray(size);
253 std::vector<int64_t> vect;
254 for (
unsigned n=0;n<size;n++) vect.push_back((int64_t)arr[n]);
259 case rdaDataEntry::TYPE_INT: {
260 item.
SetField(tag, entry->extractInt());
261 if (fDoRec && !fBlockRec) fRec.AddLong(tag, entry->extractInt(),
true);
265 case rdaDataEntry::TYPE_INT_ARRAY: {
266 unsigned long size(0);
267 const int* arr = entry->getIntArray(size);
269 std::vector<int64_t> vect;
270 for (
unsigned n=0;n<size;n++) vect.push_back(arr[n]);
275 case rdaDataEntry::TYPE_LONG: {
276 item.
SetField(tag, (int64_t)entry->extractLong());
277 if (fDoRec && !fBlockRec) fRec.AddLong(tag, entry->extractLong(),
true);
281 case rdaDataEntry::TYPE_LONG_ARRAY: {
282 unsigned long size(0);
283 const long long* arr = entry->getLongArray(size);
284 std::vector<int64_t> vect;
285 for (
unsigned n=0;n<size;n++) vect.push_back((int64_t)arr[n]);
290 case rdaDataEntry::TYPE_FLOAT: {
291 item.
SetField(tag, entry->extractFloat());
292 if (fDoRec && !fBlockRec) fRec.AddDouble(tag, entry->extractFloat(),
true);
296 case rdaDataEntry::TYPE_FLOAT_ARRAY: {
297 unsigned long size(0);
298 const float* arr = entry->getFloatArray(size);
299 std::vector<double> vect;
300 for (
unsigned n=0;n<size;n++) vect.push_back(arr[n]);
305 case rdaDataEntry::TYPE_DOUBLE: {
306 item.
SetField(tag, entry->extractDouble());
307 if (fDoRec && !fBlockRec) fRec.AddDouble(tag, entry->extractDouble(),
true);
311 case rdaDataEntry::TYPE_DOUBLE_ARRAY: {
312 unsigned long size(0);
313 const double* arr = entry->getDoubleArray(size);
314 std::vector<double> vect;
315 for (
unsigned n=0;n<size;n++) vect.push_back(arr[n]);
320 case rdaDataEntry::TYPE_STRING: {
321 item.
SetField(tag, entry->getString());
325 case rdaDataEntry::TYPE_STRING_ARRAY: {
326 unsigned long size(0);
327 const char** arr = entry->getStringArray(size);
328 std::vector<std::string> vect;
329 for (
unsigned n=0;n<size;n++) vect.push_back(arr[n]);
347 return fRec.GetRawSize();
353 unsigned len = fRec.Write(ptr, maxsize);
Represents command with its arguments.
Represents objects hierarchy of remote (or local) DABC process.
void MarkChangedItems(uint64_t tm=0)
If any field was modified, item will be marked with new version.
Hierarchy CreateHChild(const std::string &name, bool allowslahes=false, bool sortorder=false)
Create child item in hierarchy with specified name If allowslahes enabled, instead of subfolders item...
Hierarchy GetHChild(const std::string &name, bool allowslahes=false, bool force=false, bool sortorder=false)
Return child, if necessary creates with full subfolder If force specified, missing childs and folders...
void EnableHistory(unsigned length=100, bool withchilds=false)
Activate history production for selected element and its childs.
Lock guard for posix mutex.
unsigned NumFields() const
bool HasField(const std::string &name) const
bool SetField(const std::string &name, const RecordField &v)
bool RemoveField(const std::string &name)
std::string FieldName(unsigned cnt) const
bool null() const
Returns true if reference contains nullptr.
Monitor for of FESA data.
virtual unsigned WriteRecRawData(void *ptr, unsigned maxsize)
Monitor(const std::string &name, dabc::Command cmd=nullptr)
virtual unsigned GetRecRawSize()
std::vector< rdaDabcHandler * > fHandlers
void ReportServiceError(const std::string &name, const std::string &err)
rdaDeviceHandle * fDevice
void ReportServiceChanged(const std::string &name, const rdaData *v)
std::string format(const char *fmt,...)
Support for MBS - standard GSI DAQ.