37 fDeliverAllEvents(false),
41 #ifdef DABC_EXTRA_CHECKS
42 DebugObject(
"Parameter",
this, 10);
48 #ifdef DABC_EXTRA_CHECKS
49 DebugObject(
"Parameter",
this, -10);
56 std::string units = GetField(
"units").AsStr();
59 if (fStatistic==kindRate) {
60 if (units.empty()) units =
"1/s";
70 return fDeliverAllEvents;
84 std::string n = name.empty() ? DefaultFiledName() : name;
86 if (Fields().HasField(n))
return Fields().Field(n);
94 bool res(
false), fire(
false), doworker(
false);
98 std::string name = _name.empty() ? DefaultFiledName() : _name;
99 bool is_dflt_name = (name == DefaultFiledName());
101 DOUT4(
"ParameterContainer::SetField %s dflt %s", name.c_str(),
DBOOL(is_dflt_name));
106 if (!_CanChangeField(name))
return false;
108 doworker = fMonitored || fRecorded;
112 if ((fStatistic!=kindNone) && is_dflt_name && !value.
null()) {
118 if (fAsynchron)
return true;
122 if (fLastChangeTm.null()) fLastChangeTm = tm;
124 fRateTimeSum = tm - fLastChangeTm;
126 fire = _CalcRate(ratevalue, svalue);
130 res = Fields().Field(name).SetDouble(ratevalue);
135 res = Fields().Field(name).SetValue(value);
141 if (fLastChangeTm.null() || (fInterval<=0.) || (tm > fLastChangeTm+fInterval)) {
143 svalue = Fields().Field(name).AsStr();
146 if (fire) fLastChangeTm = tm;
150 if (res && !is_dflt_name) {
152 fAttrModified =
true;
156 if ((fMonitored || fRecorded) && res && fire && !fWaitWorker) {
171 if (fire && res) FireModified(svalue);
173 DOUT4(
"ParameterContainer::SetField %s = %s res %s fire %s",
186 if (fRecorded) res = res | 1;
187 if (fMonitored) res = res | 2;
195 int doout = GetDebugLevel();
205 dabc::mgr()->ProduceParameterEvent(
this,
id);
218 bool fire(
false), res(
false), doworker(
false);
227 if ((fStatistic!=kindNone) && fAsynchron) {
228 fRateTimeSum += last_dif;
229 fire = _CalcRate(value, svalue);
232 res = Fields().Field(DefaultFiledName()).SetDouble(value);
237 fRateTimeSum += last_dif;
239 if (!fLastChangeTm.null() && (fRateTimeSum>fInterval)) {
241 fLastChangeTm.Reset();
243 svalue = Fields().Field(DefaultFiledName()).AsStr();
247 if ((fMonitored || fRecorded) && res && fire && !fWaitWorker) {
256 else ConfirmFromWorker();
260 FireModified(svalue);
265 if ((fRateTimeSum < fInterval) || (fRateTimeSum<1e-6))
return false;
267 if (fStatistic==kindRate)
268 value = fRateValueSum / fRateTimeSum;
270 if ((fStatistic==kindAverage) && (fRateNumSum>0))
271 value = fRateValueSum / fRateNumSum;
277 dabc::formats(svalue,
"%*.*f", fRateWidth, fRatePrec, value);
289 fInterval = interval > 0 ? interval : 0.;
291 fDeliverAllEvents = everyevnt;
315 bool force_value_modified =
false;
320 force_value_modified =
true;
321 }
else if (fKind ==
"cmddef") {
324 }
else if (fKind ==
"info") {
326 }
else if (Fields().HasField(
"#record")) {
327 force_value_modified =
true;
333 if (force_value_modified && cont->
HasField(
"value"))
343 return GetObject() ? GetObject()->fAsynchron :
false;
353 res = GetObject()->fAttrModified;
354 GetObject()->fAttrModified =
false;
362 return GetObject() ? GetObject()->GetDebugLevel() : -1;
368 if (GetObject()==0)
return *
this;
370 GetObject()->fRateWidth = GetField(
"width").AsInt(GetObject()->fRateWidth);
371 GetObject()->fRatePrec = GetField(
"prec").AsInt(GetObject()->fRatePrec);
378 GetObject()->fInterval = interval;
380 GetObject()->fAsynchron = !synchron;
382 DOUT3(
"Asynchron = %s",
DBOOL(GetObject()->fAsynchron));
384 GetObject()->fRateValueSum = 0.;
385 GetObject()->fRateTimeSum = 0.;
386 GetObject()->fRateNumSum = 0.;
396 if (GetObject()==0)
return *
this;
403 GetObject()->fAsynchron =
false;
413 if (GetObject()==0)
return false;
422 SetField(
"width", width);
423 SetField(
"prec", prec);
427 GetObject()->fRateWidth = width;
428 GetObject()->fRatePrec = prec;
436 if (GetObject()==0)
return *
this;
438 GetObject()->fRateWidth = GetField(
"width").AsInt(GetObject()->fRateWidth);
439 GetObject()->fRatePrec = GetField(
"prec").AsInt(GetObject()->fRatePrec);
446 GetObject()->fInterval = interval;
448 GetObject()->fAsynchron = !synchron;
450 DOUT3(
"Asynchron = %s",
DBOOL(GetObject()->fAsynchron));
452 GetObject()->fRateValueSum = 0.;
453 GetObject()->fRateTimeSum = 0.;
454 GetObject()->fRateNumSum = 0.;
464 if (GetObject()==0)
return *
this;
471 GetObject()->fAsynchron =
false;
483 if (GetObject()==0)
return false;
504 return GetObject() ? GetObject()->GetWorker() : 0;
517 if (GetObject()==0)
return false;
521 return GetObject()->fMonitored;
526 if (GetObject()!=0) {
530 GetObject()->fMonitored = on;
538 if (GetObject()==0)
return std::string();
540 return GetObject()->Kind();
545 if (GetObject()==0)
return std::string();
547 return GetObject()->GetActualUnits();
558 GetObject()->FireModified(Value().AsStr());
564 if (w.
null())
return SetValue(v);
576 return GetField(
"numargs").AsInt(0);
588 for (
int n=0;n<num;n++)
589 if (ArgName(n)==name)
return n;
595 if (name.empty() ||
null())
return *
this;
597 int id = FindArg(name);
601 SetField(
"numargs",
id+1);
605 SetField(prefix, name);
608 SetField(prefix+
"_dflt", dflt);
610 SetField(prefix+
"_kind", kind);
613 SetField(prefix+
"_req", required);
620 int id = FindArg(name);
621 if (
id<0)
return *
this;
625 SetField(prefix+
"_min", min);
626 SetField(prefix+
"_max", max);
635 if ((n<0) || (n>=NumArgs()))
return false;
639 name = GetField(prefix).AsStr();
641 kind = GetField(prefix+
"_kind").AsStr();
643 if (HasField(prefix+
"_dflt"))
644 dflt = GetField(prefix+
"_dflt").AsStr();
648 if (HasField(prefix+
"_req"))
649 required = GetField(prefix+
"_req").AsBool();
662 for (
int n=0;n<num;n++) {
663 std::string name, kind, dflt;
664 bool required(
false);
665 if (GetArg(n,name,kind,required, dflt))
666 if (required || !dflt.empty()) cmd.
SetStr(name, dflt);
static const char * ParValue()
Command definition class.
int FindArg(const std::string &name) const
CommandDefinition & SetArgMinMax(const std::string &name, const RecordField &min, const RecordField &max)
std::string ArgName(int n) const
Command MakeCommand() const
Create command according command definition, all default and required parameters will be specified.
bool GetArg(int n, std::string &name, std::string &kind, bool &required, std::string &dflt) const
CommandDefinition & AddArg(const std::string &name, const std::string &kind="string", bool required=true, const RecordField &dflt=RecordField())
Represents command with its arguments.
bool SetStr(const std::string &name, const char *value)
Lock guard for posix mutex.
static void Debug(int level, const char *filename, unsigned linenumber, const char *funcname, const char *message)
Base class for most of the DABC classes.
Object * GetParent() const
Returns pointer on parent object, thread safe
virtual void ObjectCleanup()
User method to cleanup object content before it will be destroyed Main motivation is to release any r...
void SetSynchron(bool on, double interval=1., bool everyevnt=false)
Specifies that parameter produce 'modified' events synchronous with changes of parameter.
virtual void ObjectCleanup()
User method to cleanup object content before it will be destroyed Main motivation is to release any r...
unsigned ConfirmFromWorker()
Get confirmation from worker, which monitor parameters changes.
const std::string GetActualUnits() const
virtual void BuildFieldsMap(RecordFieldsMap *cont)
Save parameter attributes into container.
void ProcessTimeout(double last_dif)
Method called from manager thread when parameter configured as asynchronous.
virtual ~ParameterContainer()
ParameterContainer(Reference worker, const std::string &name, const std::string &parkind="", bool hidden=false)
Worker * GetWorker() const
bool IsDeliverAllEvents() const
If true, all events must be delivered to the consumer.
void FireModified(const std::string &svalue)
Internal method, used to inform system that parameter is modified If configured, also debug output wi...
virtual std::string DefaultFiledName() const
const std::string & Kind() const
virtual RecordField GetField(const std::string &name) const
void FireParEvent(int id)
virtual bool SetField(const std::string &name, const RecordField &v)
bool _CalcRate(double &value, std::string &svalue)
bool TakeAttrModified()
Returns true if any parameter attribute was modified since last call to this method.
Parameter & SetMonitored(bool on=true)
Specify if parameter event should be delivered to the worker.
Parameter & DisableRatemeter()
Disable ratemeter functionality.
void FireConfigured()
Fire parConfigured event for parameter.
Parameter & SetWidthPrecision(unsigned width, unsigned prec)
Set parameter to convert double values to the string - used for ratemeter.
Parameter & SetAverage(bool synchron=false, double interval=1.0)
Converts parameter in statistic variable.
int ExecuteChange(Command cmd)
Specifies that parameter produce 'modified' events synchronous with changes of parameter.
bool SubmitSetValue(const RecordField &v)
bool IsAverage() const
Returns true if average calculation is active.
bool IsMonitored()
Returns true when parameter event should be delivered to the worker.
const std::string GetActualUnits() const
Return actual units of parameter value, taking into account rate (1/s) unit when enabled.
bool IsRatemeter() const
Returns true if rate measurement is activated.
bool NeedTimeout()
Returns true if parameter object requires timeout processing.
int GetDebugLevel() const
Parameter & SetRatemeter(bool synchron=false, double interval=1.0)
Converts parameter in ratemeter - all values will be summed up and divided on specified interval.
Parameter & DisableAverage()
Disables averaging functionality.
Reference GetWorker() const
Returns reference on the worker.
const std::string Kind() const
Parameter & SetSynchron(bool on, double interval=1., bool everyevnt=false)
Indicate if parameter is should generate events synchron with code which modified it.
void FireModified()
Can be called by user to signal framework that parameter was modified.
Container for records fields.
bool SetStr(const std::string &v)
std::string AsStr(const std::string &dflt="") const
double AsDouble(double dflt=0.) const
void SetModified(bool on=true)
void CopyFrom(const RecordFieldsMap &src, bool overwrite=true)
Copy fields from source map.
bool HasField(const std::string &name) const
RecordField & Field(const std::string &name)
Direct access to the fields.
RecordField GetField(const std::string &name) const
Reference on the arbitrary object
bool null() const
Returns true if reference contains nullptr.
Reference on dabc::Worker
Active object, which is working inside dabc::Thread.
void WorkerParameterChanged(bool forcecall, ParameterContainer *par, const std::string &value)
Method called by parameter object which is belong to the worker.
XMLNodePointer_t GetParent(XMLNodePointer_t xmlnode)
const char * xmlValueAttr
void formats(std::string &sbuf, const char *fmt,...)
std::string format(const char *fmt,...)
@ parConfigured
event only for manager, used to react on reconfiguration of parameter
@ parModified
produced when parameter value modified. Either every change or after time interval (default = 1 sec)
@ parDestroy
produced once when parameter is destroyed
Class for acquiring and holding timestamps.