27 #ifndef DABC_Parameter
31 #ifndef DABC_Hierarchy
82 virtual long Notify(
const std::string&,
int) {
return 0; }
86 virtual const char*
ClassName()
const {
return "WorkerAddon"; }
104 long
Notify(const std::
string &cmd,
int arg = 0)
193 Worker(
const ConstructorPair& pair);
216 virtual const char*
ClassName()
const {
return "Worker"; }
347 inline bool _FireEvent(uint16_t evid, uint32_t arg,
int pri = -1)
355 inline bool FireEvent(uint16_t evid, uint32_t arg,
int pri = -1)
428 virtual bool Subscribe(
const std::string &path);
476 bool Execute(
const std::string &cmd,
double tmout = -1.);
521 CmdParameterEvent(const std::
string &parname, const std::
string &parvalue,
int evid,
bool attrmodified = false) throw() :
524 SetStr(
"ParName", parname);
525 if (!parvalue.empty())
SetStr(
"ParValue", parvalue);
527 if (attrmodified)
SetBool(
"AttrMod",
true);
562 class LocalWorkerRef;
#define DABC_COMMAND(cmd_class, cmd_name)
#define DABC_REFERENCE(RefClass, ParentClass, T)
This command used to distribute parameter event to receivers.
Command definition class.
Represents command with its arguments.
bool SetStr(const std::string &name, const char *value)
bool SetBool(const std::string &name, bool v)
bool SetInt(const std::string &name, int v)
std::string GetStr(const std::string &name, const std::string &dflt="") const
bool GetBool(const std::string &name, bool dflt=false) const
int GetInt(const std::string &name, int dflt=0) const
Interface class between xml configuration and dabc objects.
Represents objects hierarchy of remote (or local) DABC process.
bool Execute(Command cmd)
bool Execute(const std::string &cmd)
LocalWorker(const std::string &name)
virtual int ExecuteCommand(Command)
Main method where commands are executed.
Lock guard for posix mutex.
Base class for most of the DABC classes.
@ flAutoDestroy
object will be automatically destroyed when no references exists, normally set in constructor,...
Container for parameter object.
std::string ParName() const
std::string ParValue() const
ParameterEvent(const Command &cmd)
bool AttrModified() const
RecordField GetField(const std::string &name) const
Reference on the arbitrary object
Object * GetObject() const
Return pointer on the object.
bool null() const
Returns true if reference contains nullptr.
Reference on the dabc::Thread class
Represent thread functionality.
@ evntDoNothing
event fired to wake-up thread and let thread or processor to perform regular checks
Reference on dabc::WorkerAddon object
long Notify(const std::string &cmd, int arg=0)
Generic addon for dabc::Worker.
virtual std::string RequiredThrdClass() const
virtual long Notify(const std::string &, int)
Light-weight command interface, which can be used from worker.
void FireWorkerEvent(unsigned evid)
void SubmitWorkerCmd(Command cmd)
void DeleteAddonItself()
This is possibility to delete addon itself, invoking worker command.
virtual void ObjectCleanup()
User method to cleanup object content before it will be destroyed Main motivation is to release any r...
virtual void ProcessEvent(const EventId &)
void DeleteWorker()
This is way to delete worker with addon inclusive.
virtual void OnThreadAssigned()
bool ActivateTimeout(double tmout_sec)
virtual double ProcessTimeout(double last_diff)
WorkerAddon(const std::string &name)
virtual const char * ClassName() const
Returns class name of the object instance.
Reference on dabc::Worker
std::string ThreadName() const
Returns thread name of worker assigned.
bool FireEvent(const EventId &ev)
RecordField Cfg(const std::string &name, Command cmd=nullptr) const
Returns configuration record of specified name.
bool FireEvent(uint16_t evid, uint32_t arg)
bool HasThread() const
Returns true when thread is assigned to the worker.
bool SyncWorker(double tmout=-1.)
Synchronize worker with caller thread.
Parameter Par(const std::string &name) const
Returns reference on parameter.
bool Execute(Command cmd, double tmout=-1.)
bool CanSubmitCommand() const
Returns true if command can be submitted to the worker.
bool MakeThreadForWorker(const std::string &thrdname="")
bool IsSameThread(const WorkerRef &ref)
Returns true if two workers share same thread.
Active object, which is working inside dabc::Thread.
virtual int PreviewCommand(Command cmd)
This method called before command will be executed.
virtual bool Subscribe(const std::string &path)
bool ActivateTimeout(double tmout_sec)
Method used to produce timeout events in the worker.
bool _IsFireEvent() const
virtual void OnThreadAssigned()
CommandDefinition CreateCmdDef(const std::string &name)
int ProcessCommand(dabc::Command cmd)
uint32_t fWorkerId
worker id in thread list, used for events submit
void AssignAddon(WorkerAddon *addon)
Assigns addon to the worker Should be called before worker assigned to the thread.
unsigned fWorkerFiredEvents
indicate current balance between fired and processed events, used to correctly halt worker
CommandsQueue fWorkerCommands
all kinds of commands, processed by the worker
static int cmd_bool(bool v)
void ProcessParameterRecording(ParameterContainer *par)
Method to process parameter recording in worker thread.
virtual void ProcessEvent(const EventId &)
virtual void BeforeHierarchyScan(Hierarchy &h)
Method called before publisher makes next snapshot of hierarchy.
Worker(const ConstructorPair &pair)
Special constructor, designed for inherited classes.
WorkerAddonRef fAddon
extension of worker for some special events
Reference fPublisher
reference on publisher, once found, remain until end of object live
int fWorkerCfgId
special ID, can be used in XML configuration in ${}# formula
bool _FireDoNothingEvent()
bool RegisterForParameterEvent(const std::string &mask, bool onlychangeevent=true)
Subscribe to parameter events from local or remote node.
void ClearThreadRef()
Method to 'forget' thread reference.
Hierarchy fWorkerHierarchy
place for publishing of worker parameters
bool Submit(Command cmd)
Submit command for execution in the processor.
bool GetCommandReply(dabc::Command &cmd, bool *exe_ready)
void WorkerParameterChanged(bool forcecall, ParameterContainer *par, const std::string &value)
Method called by parameter object which is belong to the worker.
void WorkerSleep(double tmout)
bool CanSubmitCommand() const
Returns true if command can be submitted to worker.
bool Execute(Command cmd, double tmout=-1.)
Execute command in the processor.
virtual void DoWorkerAfterMainLoop()
Internal - function executed after leaving main loop.
bool ExecuteIn(Worker *dest, Command cmd)
Executes command in specified worker.
Command Assign(Command cmd)
! Assign command with processor before command be submitted to other processor This produce ReplyComm...
void CleanupPublisher(bool sync=true)
Release reference on publisher and unsubscribe/unpublish all registered entries.
Parameter Par(const std::string &name) const
Returns reference on worker parameter object.
bool Execute(const std::string &cmd, double tmout=-1.)
bool fWorkerActive
indicates if worker can submit events to the thread
bool AssignToThread(ThreadRef thrd, bool sync=true)
Assign worker to thread, worker becomes active immediately.
void SetWorkerCfgId(int id=-1)
Set identifier which can be used in XML configuration ${}# formula It means that correspondent to the...
int fWorkerCommandsLevel
Number of process commands recursion.
RecordField Cfg(const std::string &name, Command cmd=nullptr) const
Returns configuration field of specified name Configuration value of specified name searched in follo...
void InformThreadAssigned()
Method called from the thread to inform Worker when it is assigned to thread.
virtual int ExecuteCommand(Command cmd)
Main method where commands are executed.
virtual bool PublishPars(const std::string &path)
std::string WorkerAddress(bool full=true)
Return address, which can be used to submit command to the worker If full specified,...
double ProcessAddonTimeout(double last_diff)
virtual bool DestroyByOwnThread()
Inherited method from Object, invoked at the moment when worker requested to be destroyed by its thre...
virtual std::string RequiredThrdClass() const
Method returns name of required thread class for processor.
bool UnregisterForParameterEvent(const std::string &mask)
Unsubscribe to parameter events from local or remote node.
bool DestroyPar(const std::string &name)
Method must be used if worker wants to destroy parameter.
bool HasThread() const
Indicates if pointer on thread is not zero; thread-safe.
bool _FireEvent(uint16_t evid)
virtual bool Unpublish(const Hierarchy &h, const std::string &path)
bool MakeThreadForWorker(const std::string &thrdname="")
Creates appropriate thread for worker and assign worker to the thread.
virtual double ProcessTimeout(double last_diff)
virtual void DoWorkerMainLoop()
Internal - entrance function for main loop execution.
std::string ThreadName() const
Returns name of the worker thread; thread-safe
virtual bool Unsubscribe(const std::string &path)
ThreadRef fThread
reference on the thread, once assigned remain whole time
virtual void ObjectDestroyed(Object *)
Method to clear object reference, will be called from thread context (when possible)
virtual bool Find(ConfigIO &cfg)
Method to locate object in xml file.
ThreadRef thread()
Return reference on the worker thread; thread-safe.
void SetWorkerPriority(int nq)
Reference GetPublisher()
Return reference on publisher.
bool _FireEvent(uint16_t evid, uint32_t arg, int pri=-1)
void SetParValue(const std::string &name, const RecordField &v)
Set parameter value and sync with worker hierarchy.
bool IsWorkerActive() const
Method indicates if worker is running in the thread and accepts normal events.
uint32_t WorkerId() const
int WorkerPriority() const
void ProcessCoreEvent(EventId)
virtual const char * ClassName() const
Returns class name of the object instance.
bool SingleLoop(double tmout)
bool DettachFromThread()
Detach worker from the thread, later worker can be assigned to some other thread Method especially us...
virtual bool ReplyCommand(Command cmd)
Reimplement this method to react on command reply Return true if command can be destroyed by framewor...
virtual void ObjectCleanup()
Central cleanup method for worker.
virtual Parameter CreatePar(const std::string &name, const std::string &kind="")
virtual bool Publish(const Hierarchy &h, const std::string &path)
bool IsOwnThread() const
Returns true if called from thread.
Mutex * fThreadMutex
pointer on main thread mutex
virtual void ProcessParameterEvent(const ParameterEvent &evnt)
Interface method to retrieve subscribed parameter events.
bool FireEvent(uint16_t evid)
int fWorkerPriority
priority of events, submitted by worker to the thread
bool FireEvent(uint16_t evid, uint32_t arg, int pri=-1)
@ parModified
produced when parameter value modified. Either every change or after time interval (default = 1 sec)
Event structure, exchanged between DABC threads.