27 mbs::MonitorSlowControl(name,
"Dim", cmd),
37 strncpy(fNoLink,
"no_link",
sizeof(fNoLink));
39 fDimDns = Cfg(
"DimDns", cmd).AsStr();
40 fDimMask = Cfg(
"DimMask", cmd).AsStr(
"*");
41 if (fDimMask.empty()) fDimMask =
"*";
43 fWorkerHierarchy.Create(
"DIMC",
true);
46 fDimPeriod = Cfg(
"DimPeriod", cmd).AsDouble(1);
48 CreateTimer(
"DimTimer", (fDimPeriod>0.01) ? fDimPeriod : 0.01);
51 Publish(fWorkerHierarchy,
"DIMC");
56 for (DimServicesMap::iterator iter =
fDimInfos.begin(); iter!=
fDimInfos.end();iter++) {
57 delete iter->second.info;
58 iter->second.info = 0;
70 if (!fDimDns.empty()) {
74 ::DimClient::setDnsNode(url.GetHostName().c_str(), url.GetPort());
76 ::DimClient::setDnsNode(url.GetHostName().c_str());
80 fDimBr = new ::DimBrowser();
85 char *service_name, *service_descr;
93 for (DimServicesMap::iterator iter = fDimInfos.begin(); iter!=fDimInfos.end();iter++) {
94 iter->second.flag = 0;
98 int nservices = fDimBr->getServices(fDimMask.c_str());
99 DOUT3(
"found %d DIM services", nservices);
101 while((type = fDimBr->getNextService(service_name, service_descr))!= 0)
107 DOUT3(
"DIM type %d name %s descr %s", type, service_name, service_descr);
109 if ((service_descr==0) || ((type!=1) && (type!=2)))
continue;
111 DimServicesMap::iterator iter = fDimInfos.find(service_name);
112 if (iter!=fDimInfos.end()) {
113 iter->second.flag = type;
122 entry.info =
new DimInfo(service_name, (
void*) fNoLink, (
int)
sizeof(fNoLink), (DimInfoHandler*)
this);
124 fDimInfos[service_name] = entry;
126 DOUT3(
"Create entry %p type %d name %s descr %s", entry.info, type, service_name, service_descr);
135 item.
SetField(
"dimcmd", service_name);
139 item.
SetField(
"arg0_kind",
"string");
146 DimServicesMap::iterator iter = fDimInfos.begin();
147 while (iter!=fDimInfos.end()) {
148 if (iter->second.flag != 0) { iter++;
continue; }
150 delete iter->second.info;
151 iter->second.info = 0;
153 DOUT3(
"Destroy entry %s", iter->first.c_str());
155 fWorkerHierarchy.RemoveHChild(iter->first);
157 fDimInfos.erase(iter++);
162 fNeedDnsUpdate =
false;
167 if (fDimBr==0)
return;
169 if (TimerName(timer) ==
"DimTimer")
170 if (fLastScan.Expired(10.) || (fDimInfos.size()==0) || fNeedDnsUpdate)
178 if (cmd.
IsName(dabc::CmdHierarchyExec::CmdName())) {
179 std::string path = cmd.
GetStr(
"Item");
180 std::string arg = cmd.
GetStr(
"PAR");
187 EOUT(
"Did not found command item %s in DIM hierarchy", path.c_str());
195 DOUT2(
"Execute DIM command %s arg %s", dimcmd.c_str(), arg.c_str());
197 DimClient::sendCommand(dimcmd.c_str(), arg.c_str());
209 DimInfo *info = getInfo();
212 if (info->getData() == fNoLink) {
213 DOUT3(
"Get nolink for %s", info->getName());
217 if (info->getFormat() == 0) {
218 EOUT(
"Get null format for %s", info->getName());
226 EOUT(
"Fail to find item for %s", info->getName());
230 DimServicesMap::iterator iter = fDimInfos.find(info->getName());
231 if ((iter==fDimInfos.end()) || (iter->second.info!=info)) {
232 EOUT(
"Did not found service %s in infos map", info->getName());
236 if (strcmp(info->getName(),
"DIS_DNS/SERVER_LIST")==0) {
237 DOUT3(
"Get DIS_DNS/SERVER_LIST");
238 fNeedDnsUpdate =
true;
244 iter->second.fKind = 0;
245 if (strcmp(info->getFormat(),
"I")==0) {
246 item.
SetField(
"value", info->getInt());
248 iter->second.fKind = 1;
249 iter->second.fLong = info->getInt();
251 if (strcmp(info->getFormat(),
"F")==0) {
252 item.
SetField(
"value", info->getFloat());
254 iter->second.fKind = 2;
255 iter->second.fDouble = info->getFloat();
257 if (strcmp(info->getFormat(),
"D")==0) {
258 item.
SetField(
"value", info->getDouble());
260 iter->second.fKind = 2;
261 iter->second.fDouble = info->getDouble();
263 if (strcmp(info->getFormat(),
"C")==0) {
264 item.
SetField(
"value", info->getString());
267 if ((strcmp(info->getFormat(),
"F:1;I:1;F:1;F:1;F:1;F:1;C:16;C:16;C:16")==0) && (strncmp(info->getName(),
"DABC/",5)==0)) {
269 item.
SetField(
"value", info->getFloat());
271 iter->second.fKind = 2;
272 iter->second.fDouble = info->getFloat();
274 if ((strcmp(info->getFormat(),
"I:1;C:16;C:128")==0) && (strncmp(info->getName(),
"DABC/",5)==0)) {
276 item.
SetField(
"value", (
const char*) info->getData() +
sizeof(
int) + 16);
279 if (strlen(info->getFormat()) > 2) {
280 const char* fmt = info->getFormat();
284 char* ptr = (
char*) info->getData();
287 if (*fmt++!=
':')
break;
289 while ((*fmt>=
'0') && (*fmt<=
'9')) {
290 size = size*10 + (*fmt -
'0');
293 if (*fmt==
';') fmt++;
305 std::vector<int64_t> vect;
306 for (
int n=0;n<size;n++) vect.push_back(((
int*)ptr)[n]);
309 ptr +=
sizeof(int) * size;
315 std::vector<double> vect;
316 for (
int n=0;n<size;n++) vect.push_back(((
float*)ptr)[n]);
319 ptr +=
sizeof(float) * size;
325 std::vector<double> vect;
326 for (
int n=0;n<size;n++) vect.push_back(((
double*)ptr)[n]);
329 ptr +=
sizeof(double) * size;
333 while ((slen<size) && (ptr[slen]!=0)) slen++;
337 fld.
SetStr(std::string(ptr,size));
342 EOUT(
"Unknown data format %c", kind);
346 if (fld.
null())
break;
351 if (strlen(info->getFormat())>0)
352 EOUT(
"Not processed DIM format %s for record %s", info->getFormat(), info->getName());
367 for (DimServicesMap::iterator iter = fDimInfos.begin(); iter!=fDimInfos.end(); iter++) {
368 switch (iter->second.fKind) {
369 case 1: fRec.AddLong(iter->first, iter->second.fLong);
break;
370 case 2: fRec.AddDouble(iter->first, iter->second.fDouble);
break;
376 return fRec.GetRawSize();
Represents command with its arguments.
std::string GetStr(const std::string &name, const std::string &dflt="") const
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 FindChild(const char *name)
Return child element from hierarchy.
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.
virtual void OnThreadAssigned()
virtual int ExecuteCommand(Command cmd)
Main method where commands are executed.
bool SetVectInt(const std::vector< int64_t > &v)
bool SetStr(const std::string &v)
std::string AsStr(const std::string &dflt="") const
bool SetVectDouble(const std::vector< double > &v)
RecordField GetField(const std::string &name) const
bool SetField(const std::string &name, const RecordField &v)
bool IsName(const char *name) const
Returns true if object name is the same as specified one.
bool null() const
Returns true if reference contains nullptr.
Uniform Resource Locator interpreter.
virtual int ExecuteCommand(dabc::Command cmd)
Main method where commands are executed.
virtual void ProcessTimerEvent(unsigned timer)
Method called by framework when timer event is produced.
virtual void infoHandler()
Monitor(const std::string &name, dabc::Command cmd=nullptr)
virtual unsigned GetRecRawSize()
virtual void OnThreadAssigned()
::DimBrowser * fDimBr
dim browser
DimServicesMap fDimInfos
all subscribed DIM services
virtual void ProcessTimerEvent(unsigned timer)
Method called by framework when timer event is produced.
std::string format(const char *fmt,...)
Support for MBS - standard GSI DAQ.