DABC (Data Acquisition Backbone Core)  2.9.9
Worker.h
Go to the documentation of this file.
1 // $Id: Worker.h 4475 2020-04-15 13:55:30Z linev $
2 
3 /************************************************************
4  * The Data Acquisition Backbone Core (DABC) *
5  ************************************************************
6  * Copyright (C) 2009 - *
7  * GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
8  * Planckstr. 1, 64291 Darmstadt, Germany *
9  * Contact: http://dabc.gsi.de *
10  ************************************************************
11  * This software can be used under the GPL license *
12  * agreements as stated in LICENSE.txt file *
13  * which is part of the distribution. *
14  ************************************************************/
15 
16 #ifndef DABC_Worker
17 #define DABC_Worker
18 
19 #ifndef DABC_Object
20 #include "dabc/Object.h"
21 #endif
22 
23 #ifndef DABC_Thread
24 #include "dabc/Thread.h"
25 #endif
26 
27 #ifndef DABC_Parameter
28 #include "dabc/Parameter.h"
29 #endif
30 
31 #ifndef DABC_Hierarchy
32 #include "dabc/Hierarchy.h"
33 #endif
34 
35 namespace dabc {
36 
37  class ParameterEvent;
38 
39  class WorkerRef;
40  class Worker;
41  class WorkerAddonRef;
42 
49  class WorkerAddon : public Object {
50 
51  friend class Thread;
52  friend class Worker;
53  friend class WorkerAddonRef;
54 
55  protected:
57 
58  virtual void ObjectCleanup();
59 
60  virtual void ProcessEvent(const EventId&) {}
61 
63  void DeleteWorker();
64 
66  void DeleteAddonItself();
67 
68  void SubmitWorkerCmd(Command cmd);
69 
70  void FireWorkerEvent(unsigned evid);
71 
72  // method will be called by worker when thread was assigned
73  virtual void OnThreadAssigned() {}
74 
75  // analog to Worker::ActiavteTimeout
76  bool ActivateTimeout(double tmout_sec);
77 
78  // analog to Worker::ProcessTimeout
79  virtual double ProcessTimeout(double last_diff) { return -1.; }
80 
82  virtual long Notify(const std::string&, int) { return 0; }
83 
84  public:
85 
86  virtual const char* ClassName() const { return "WorkerAddon"; }
87 
88  virtual std::string RequiredThrdClass() const { return std::string(); }
89 
90  WorkerAddon(const std::string &name);
91  virtual ~WorkerAddon();
92  };
93 
94  // ________________________________________________________________
95 
101  class WorkerAddonRef : public Reference {
103 
104  long Notify(const std::string &cmd, int arg = 0)
105  { return GetObject() ? GetObject()->Notify(cmd,arg) : 0; }
106  };
107 
108  // _________________________________________________________________
109 
116  class Worker : public Object {
117 
118  enum EParsMasks {
120  parsFixedMask = 0x100,
122  parsValidMask = 0x400
123  };
124 
125  friend class Thread;
126  friend class Parameter;
127  friend class ParameterContainer;
128  friend class Command;
129  friend class Object;
130  friend class WorkerRef;
131  friend class WorkerAddon;
132 
133  private:
134 
136  void ClearThreadRef();
137 
140  {
142  if (!fAddon.null()) fAddon()->OnThreadAssigned();
143  }
144 
145  double ProcessAddonTimeout(double last_diff)
146  {
147  return fAddon.null() ? -1 : fAddon()->ProcessTimeout(last_diff);
148  }
149 
150  protected:
154 
155  uint32_t fWorkerId;
157 
159 
160  // FIXME: most workers should analyze FireEvent to recognize moment when worker is going into halt mode
163 
165 
167 
169 
171 
172 
174  virtual bool DestroyByOwnThread();
175 
177  virtual void ObjectCleanup();
178 
180  virtual void ObjectDestroyed(Object*) {}
181 
186  inline bool IsWorkerActive() const { return fWorkerActive; }
187 
190  void SetWorkerCfgId(int id = -1) { fWorkerCfgId = id; }
191 
193  Worker(const ConstructorPair& pair);
194 
195  public:
196 
197  static int cmd_bool(bool v) { return v ? cmd_true : cmd_false; }
198 
200  evntFirstCore = 1, // events 1 .. 99 used only by Worker itself
201  evntFirstAddOn = 100, // events 100 .. 199 are dedicated for specific add-ons
202  evntFirstSystem = 200, // events 200 .. 999 used only inside DABC class
203  evntFirstUser = 1000 // event from 1000 are available for users
204  };
205 
207  priorityMaximum = 0, // event queue with number 0 always has highest priority
208  priorityMinimum = -1, // this event will be submitted to queue with maximum number
209  priorityDefault = -7, // this code will be replaced with default priority for specified operation
210  priorityMagic = -77 // this priority allows to submit commands even when processor is stopped
211  };
212 
213  Worker(Reference parent, const std::string &name);
214  virtual ~Worker();
215 
216  virtual const char* ClassName() const { return "Worker"; }
217 
220  virtual std::string RequiredThrdClass() const
221  { return fAddon.null() ? std::string() : fAddon()->RequiredThrdClass(); }
222 
224  bool HasThread() const;
225 
227  bool IsOwnThread() const;
228 
230  bool AssignToThread(ThreadRef thrd, bool sync = true);
231 
233  bool MakeThreadForWorker(const std::string &thrdname = "");
234 
240  bool DettachFromThread();
241 
243  ThreadRef thread();
244 
246  std::string ThreadName() const;
247 
257  bool ActivateTimeout(double tmout_sec);
258 
259  void SetWorkerPriority(int nq) { fWorkerPriority = nq; }
260  inline int WorkerPriority() const { return fWorkerPriority; }
261 
262  uint32_t WorkerId() const { return fWorkerId; }
263 
264  // this all about parameters list, which can be managed for any working processor
265 
267  Parameter Par(const std::string &name) const;
268 
276  RecordField Cfg(const std::string &name, Command cmd = nullptr) const;
277 
281  Command Assign(Command cmd);
282 
284  bool CanSubmitCommand() const;
285 
287  bool Submit(Command cmd);
288 
290  bool Execute(Command cmd, double tmout = -1.);
291 
292  bool Execute(const std::string &cmd, double tmout = -1.) { return Execute(Command(cmd), tmout); }
293 
296  std::string WorkerAddress(bool full = true);
297 
300  void AssignAddon(WorkerAddon* addon);
301 
302  protected:
303 
310  virtual int PreviewCommand(Command cmd);
311 
313  virtual int ExecuteCommand(Command cmd);
314 
317  virtual bool ReplyCommand(Command cmd);
318 
319  // Method is called when requested time point is reached
320  // Rewrite method in derived class to react on this event
321  // return value specifies time interval to the next timeout
322  // Argument last_diff identifies time distance to previous timeout
323  // Return value: <0 - no new timeout is required
324  // =0 - provide timeout as soon as possible
325  // >0 - activate timeout after this interval
326  virtual double ProcessTimeout(double last_diff) { return -1.; }
327 
328  inline bool _IsFireEvent() const
329  {
330  return fThread() && fWorkerActive;
331  }
332 
333  inline bool _FireEvent(uint16_t evid)
334  {
335  if (!_IsFireEvent()) return false;
336  fThread()->_Fire(EventId(evid, fWorkerId), fWorkerPriority);
338  return true;
339  }
340 
341  inline bool FireEvent(uint16_t evid)
342  {
343  LockGuard lock(fThreadMutex);
344  return _FireEvent(evid);
345  }
346 
347  inline bool _FireEvent(uint16_t evid, uint32_t arg, int pri = -1)
348  {
349  if (!_IsFireEvent()) return false;
350  fThread()->_Fire(EventId(evid, fWorkerId, arg), pri < 0 ? fWorkerPriority : pri);
352  return true;
353  }
354 
355  inline bool FireEvent(uint16_t evid, uint32_t arg, int pri = -1)
356  {
357  LockGuard lock(fThreadMutex);
358  return _FireEvent(evid, arg, pri);
359  }
360 
361 
362  inline bool _FireDoNothingEvent()
363  {
364  if (!_IsFireEvent()) return false;
365  fThread()->_Fire(EventId(Thread::evntDoNothing), -1);
366  return true;
367  }
368 
369  virtual void ProcessEvent(const EventId&);
370 
371  bool ActivateMainLoop();
372 
373  bool SingleLoop(double tmout) { return fThread()->SingleLoop(fWorkerId, tmout); }
374 
375  void WorkerSleep(double tmout);
376 
380  bool ExecuteIn(Worker* dest, Command cmd);
381 
382  void CancelCommands();
383 
385  virtual void DoWorkerMainLoop() {}
386 
388  virtual void DoWorkerAfterMainLoop() {}
389 
390  // method called immediately after processor was assigned to thread
391  // called comes from the thread context
392  virtual void OnThreadAssigned() {}
393 
394  virtual bool Find(ConfigIO &cfg);
395 
396  virtual Parameter CreatePar(const std::string &name, const std::string &kind = "");
397 
399  void SetParValue(const std::string &name, const RecordField &v);
400 
401  CommandDefinition CreateCmdDef(const std::string &name);
402 
404  bool DestroyPar(const std::string &name);
405 
407  bool RegisterForParameterEvent(const std::string &mask, bool onlychangeevent = true);
408 
410  bool UnregisterForParameterEvent(const std::string &mask);
411 
413  virtual void ProcessParameterEvent(const ParameterEvent &evnt) {}
414 
421 
422  virtual bool Publish(const Hierarchy &h, const std::string &path);
423 
424  virtual bool PublishPars(const std::string &path);
425 
426  virtual bool Unpublish(const Hierarchy& h, const std::string &path);
427 
428  virtual bool Subscribe(const std::string &path);
429 
430  virtual bool Unsubscribe(const std::string &path);
431 
433  void CleanupPublisher(bool sync = true);
434 
437  virtual void BeforeHierarchyScan(Hierarchy& h) {}
438 
439  private:
440 
443 
445 
446  int ProcessCommand(dabc::Command cmd);
447  bool GetCommandReply(dabc::Command& cmd, bool* exe_ready);
448 
453  void WorkerParameterChanged(bool forcecall, ParameterContainer *par, const std::string &value);
454 
457  };
458 
459  // __________________________________________________________________________
460 
466  class WorkerRef : public Reference {
467 
469 
470  public:
471 
472  bool Submit(Command cmd);
473 
474  bool Execute(Command cmd, double tmout = -1.);
475 
476  bool Execute(const std::string &cmd, double tmout = -1.);
477 
479  Parameter Par(const std::string &name) const;
480 
482  RecordField Cfg(const std::string &name, Command cmd = nullptr) const
483  { return GetObject() ? GetObject()->Cfg(name, cmd) : cmd.GetField(name); }
484 
486  bool HasThread() const;
487 
489  std::string ThreadName() const
490  { return GetObject() ? GetObject()->ThreadName() : std::string(); }
491 
493  { return GetObject() ? GetObject()->thread() : ThreadRef(); }
494 
496  bool IsSameThread(const WorkerRef& ref);
497 
498  bool MakeThreadForWorker(const std::string &thrdname = "")
499  { return GetObject() ? GetObject()->MakeThreadForWorker(thrdname) : false; }
500 
502  bool CanSubmitCommand() const;
503 
506  bool SyncWorker(double tmout = -1.);
507 
508  bool FireEvent(uint16_t evid, uint32_t arg) { return GetObject() ? GetObject()->FireEvent(evid, arg) : false; }
509 
510  bool FireEvent(const EventId& ev) { return GetObject() ? GetObject()->FireEvent(ev.GetCode(), ev.GetArg()) : false; }
511  };
512 
513  // _____________________________________________________________________________
514 
515 
517  class CmdParameterEvent : public Command {
518 
519  DABC_COMMAND(CmdParameterEvent, "CmdParameterEvent")
520 
521  CmdParameterEvent(const std::string &parname, const std::string &parvalue, int evid, bool attrmodified = false) throw() :
522  dabc::Command(CmdName())
523  {
524  SetStr("ParName", parname);
525  if (!parvalue.empty()) SetStr("ParValue", parvalue);
526  if (evid!=parModified) SetInt("Event", evid);
527  if (attrmodified) SetBool("AttrMod", true);
528  }
529  };
530 
531  // _____________________________________________________________________
532 
533  class ParameterEvent : protected CmdParameterEvent {
534  friend class Worker;
535 
536  protected:
538 
540 
541  public:
542 
543  std::string ParName() const { return GetStr("ParName"); }
544  std::string ParValue() const { return GetStr("ParValue"); }
545  int EventId() const { return GetInt("Event", parModified); }
546  bool AttrModified() const { return GetBool("AttrMod", false); }
547  };
548 
549 
550  // --------------------------------------------------------------------------
551 
562  class LocalWorkerRef;
563 
564  class LocalWorker : public Object {
565  protected:
566 
567  friend class LocalWorkerRef;
568 
570  virtual int ExecuteCommand(Command) { return cmd_false; }
571 
572  public:
573 
574  LocalWorker(const std::string &name) : Object(name, flAutoDestroy) {}
575  virtual ~LocalWorker() {}
576 
577  };
578 
579  class LocalWorkerRef : public Reference {
580 
582 
583  public:
584 
585  bool Execute(Command cmd)
586  {
587  if (GetObject())
588  return GetObject()->ExecuteCommand(cmd) == cmd_true;
589  return false;
590  }
591 
592  bool Execute(const std::string &cmd)
593  {
594  return Execute(Command(cmd));
595  }
596  };
597 
598 }
599 
600 #endif
#define DABC_COMMAND(cmd_class, cmd_name)
Definition: Command.h:282
#define DABC_REFERENCE(RefClass, ParentClass, T)
Definition: Reference.h:222
This command used to distribute parameter event to receivers.
Definition: Worker.h:517
Command definition class.
Definition: Parameter.h:333
Represents command with its arguments.
Definition: Command.h:99
bool SetStr(const std::string &name, const char *value)
Definition: Command.h:134
bool SetBool(const std::string &name, bool v)
Definition: Command.h:141
bool SetInt(const std::string &name, int v)
Definition: Command.h:138
std::string GetStr(const std::string &name, const std::string &dflt="") const
Definition: Command.h:136
bool GetBool(const std::string &name, bool dflt=false) const
Definition: Command.h:142
int GetInt(const std::string &name, int dflt=0) const
Definition: Command.h:139
Queue of commands
Definition: CommandsQueue.h:39
Interface class between xml configuration and dabc objects.
Definition: ConfigIO.h:38
Represents objects hierarchy of remote (or local) DABC process.
Definition: Hierarchy.h:285
bool Execute(Command cmd)
Definition: Worker.h:585
bool Execute(const std::string &cmd)
Definition: Worker.h:592
LocalWorker(const std::string &name)
Definition: Worker.h:574
virtual int ExecuteCommand(Command)
Main method where commands are executed.
Definition: Worker.h:570
virtual ~LocalWorker()
Definition: Worker.h:575
Lock guard for posix mutex.
Definition: threads.h:127
posix pthread mutex
Definition: threads.h:61
Base class for most of the DABC classes.
Definition: Object.h:116
@ flAutoDestroy
object will be automatically destroyed when no references exists, normally set in constructor,...
Definition: Object.h:167
Container for parameter object.
Definition: Parameter.h:52
std::string ParName() const
Definition: Worker.h:543
int EventId() const
Definition: Worker.h:545
std::string ParValue() const
Definition: Worker.h:544
ParameterEvent(const Command &cmd)
Definition: Worker.h:539
bool AttrModified() const
Definition: Worker.h:546
Parameter class
Definition: Parameter.h:163
RecordField GetField(const std::string &name) const
Definition: Record.h:510
Reference on the arbitrary object
Definition: Reference.h:73
Object * GetObject() const
Return pointer on the object.
Definition: Reference.h:129
friend class Command
Definition: Reference.h:76
bool null() const
Returns true if reference contains nullptr.
Definition: Reference.h:151
Reference on the dabc::Thread class
Definition: Thread.h:482
Represent thread functionality.
Definition: Thread.h:109
@ evntDoNothing
event fired to wake-up thread and let thread or processor to perform regular checks
Definition: Thread.h:322
Reference on dabc::WorkerAddon object
Definition: Worker.h:101
long Notify(const std::string &cmd, int arg=0)
Definition: Worker.h:104
Generic addon for dabc::Worker.
Definition: Worker.h:49
virtual std::string RequiredThrdClass() const
Definition: Worker.h:88
virtual long Notify(const std::string &, int)
Light-weight command interface, which can be used from worker.
Definition: Worker.h:82
void FireWorkerEvent(unsigned evid)
Definition: Worker.cxx:56
void SubmitWorkerCmd(Command cmd)
Definition: Worker.cxx:73
void DeleteAddonItself()
This is possibility to delete addon itself, invoking worker command.
Definition: Worker.cxx:50
virtual void ObjectCleanup()
User method to cleanup object content before it will be destroyed Main motivation is to release any r...
Definition: Worker.cxx:39
virtual void ProcessEvent(const EventId &)
Definition: Worker.h:60
void DeleteWorker()
This is way to delete worker with addon inclusive.
Definition: Worker.cxx:44
virtual void OnThreadAssigned()
Definition: Worker.h:73
virtual ~WorkerAddon()
Definition: Worker.cxx:34
bool ActivateTimeout(double tmout_sec)
Definition: Worker.cxx:62
virtual double ProcessTimeout(double last_diff)
Definition: Worker.h:79
Reference fWorker
Definition: Worker.h:56
WorkerAddon(const std::string &name)
Definition: Worker.cxx:27
virtual const char * ClassName() const
Returns class name of the object instance.
Definition: Worker.h:86
Reference on dabc::Worker
Definition: Worker.h:466
std::string ThreadName() const
Returns thread name of worker assigned.
Definition: Worker.h:489
bool FireEvent(const EventId &ev)
Definition: Worker.h:510
RecordField Cfg(const std::string &name, Command cmd=nullptr) const
Returns configuration record of specified name.
Definition: Worker.h:482
bool FireEvent(uint16_t evid, uint32_t arg)
Definition: Worker.h:508
bool HasThread() const
Returns true when thread is assigned to the worker.
Definition: Worker.cxx:1165
ThreadRef thread()
Definition: Worker.h:492
bool SyncWorker(double tmout=-1.)
Synchronize worker with caller thread.
Definition: Worker.cxx:1184
Parameter Par(const std::string &name) const
Returns reference on parameter.
Definition: Worker.cxx:1159
bool Execute(Command cmd, double tmout=-1.)
Definition: Worker.cxx:1147
bool CanSubmitCommand() const
Returns true if command can be submitted to the worker.
Definition: Worker.cxx:1179
bool MakeThreadForWorker(const std::string &thrdname="")
Definition: Worker.h:498
bool IsSameThread(const WorkerRef &ref)
Returns true if two workers share same thread.
Definition: Worker.cxx:1170
bool Submit(Command cmd)
Definition: Worker.cxx:1139
Active object, which is working inside dabc::Thread.
Definition: Worker.h:116
virtual int PreviewCommand(Command cmd)
This method called before command will be executed.
Definition: Worker.cxx:650
virtual bool Subscribe(const std::string &path)
Definition: Worker.cxx:1116
bool ActivateTimeout(double tmout_sec)
Method used to produce timeout events in the worker.
Definition: Worker.cxx:385
bool _IsFireEvent() const
Definition: Worker.h:328
@ priorityMaximum
Definition: Worker.h:207
@ priorityDefault
Definition: Worker.h:209
@ priorityMagic
Definition: Worker.h:210
@ priorityMinimum
Definition: Worker.h:208
virtual void OnThreadAssigned()
Definition: Worker.h:392
CommandDefinition CreateCmdDef(const std::string &name)
Definition: Worker.cxx:603
int ProcessCommand(dabc::Command cmd)
Definition: Worker.cxx:449
uint32_t fWorkerId
worker id in thread list, used for events submit
Definition: Worker.h:155
void AssignAddon(WorkerAddon *addon)
Assigns addon to the worker Should be called before worker assigned to the thread.
Definition: Worker.cxx:277
unsigned fWorkerFiredEvents
indicate current balance between fired and processed events, used to correctly halt worker
Definition: Worker.h:162
CommandsQueue fWorkerCommands
all kinds of commands, processed by the worker
Definition: Worker.h:164
static int cmd_bool(bool v)
Definition: Worker.h:197
void ProcessParameterRecording(ParameterContainer *par)
Method to process parameter recording in worker thread.
Definition: Worker.cxx:638
virtual void ProcessEvent(const EventId &)
Definition: Worker.cxx:499
virtual void BeforeHierarchyScan(Hierarchy &h)
Method called before publisher makes next snapshot of hierarchy.
Definition: Worker.h:437
Worker(const ConstructorPair &pair)
Special constructor, designed for inherited classes.
Definition: Worker.cxx:109
WorkerAddonRef fAddon
extension of worker for some special events
Definition: Worker.h:152
Reference fPublisher
reference on publisher, once found, remain until end of object live
Definition: Worker.h:153
int fWorkerCfgId
special ID, can be used in XML configuration in ${}# formula
Definition: Worker.h:170
bool _FireDoNothingEvent()
Definition: Worker.h:362
bool RegisterForParameterEvent(const std::string &mask, bool onlychangeevent=true)
Subscribe to parameter events from local or remote node.
Definition: Worker.cxx:1050
void ClearThreadRef()
Method to 'forget' thread reference.
Definition: Worker.cxx:213
Hierarchy fWorkerHierarchy
place for publishing of worker parameters
Definition: Worker.h:168
bool Submit(Command cmd)
Submit command for execution in the processor.
Definition: Worker.cxx:960
bool GetCommandReply(dabc::Command &cmd, bool *exe_ready)
Definition: Worker.cxx:996
void WorkerParameterChanged(bool forcecall, ParameterContainer *par, const std::string &value)
Method called by parameter object which is belong to the worker.
Definition: Worker.cxx:620
void WorkerSleep(double tmout)
Definition: Worker.cxx:1031
bool CanSubmitCommand() const
Returns true if command can be submitted to worker.
Definition: Worker.cxx:953
bool Execute(Command cmd, double tmout=-1.)
Execute command in the processor.
Definition: Worker.cxx:877
@ evntReplyCommand
Definition: Worker.h:442
@ evntSubmitCommand
Definition: Worker.h:441
virtual void DoWorkerAfterMainLoop()
Internal - function executed after leaving main loop.
Definition: Worker.h:388
bool ExecuteIn(Worker *dest, Command cmd)
Executes command in specified worker.
Definition: Worker.cxx:866
Command Assign(Command cmd)
! Assign command with processor before command be submitted to other processor This produce ReplyComm...
Definition: Worker.cxx:933
void CleanupPublisher(bool sync=true)
Release reference on publisher and unsubscribe/unpublish all registered entries.
Definition: Worker.cxx:1126
Parameter Par(const std::string &name) const
Returns reference on worker parameter object.
Definition: Worker.cxx:516
bool Execute(const std::string &cmd, double tmout=-1.)
Definition: Worker.h:292
bool fWorkerActive
indicates if worker can submit events to the thread
Definition: Worker.h:161
bool AssignToThread(ThreadRef thrd, bool sync=true)
Assign worker to thread, worker becomes active immediately.
Definition: Worker.cxx:326
void SetWorkerCfgId(int id=-1)
Set identifier which can be used in XML configuration ${}# formula It means that correspondent to the...
Definition: Worker.h:190
friend class Command
Definition: Worker.h:128
int fWorkerCommandsLevel
Number of process commands recursion.
Definition: Worker.h:166
RecordField Cfg(const std::string &name, Command cmd=nullptr) const
Returns configuration field of specified name Configuration value of specified name searched in follo...
Definition: Worker.cxx:521
void InformThreadAssigned()
Method called from the thread to inform Worker when it is assigned to thread.
Definition: Worker.h:139
virtual int ExecuteCommand(Command cmd)
Main method where commands are executed.
Definition: Worker.cxx:851
virtual bool PublishPars(const std::string &path)
Definition: Worker.cxx:1081
std::string WorkerAddress(bool full=true)
Return address, which can be used to submit command to the worker If full specified,...
Definition: Worker.cxx:1062
double ProcessAddonTimeout(double last_diff)
Definition: Worker.h:145
virtual bool DestroyByOwnThread()
Inherited method from Object, invoked at the moment when worker requested to be destroyed by its thre...
Definition: Worker.cxx:194
virtual std::string RequiredThrdClass() const
Method returns name of required thread class for processor.
Definition: Worker.h:220
bool UnregisterForParameterEvent(const std::string &mask)
Unsubscribe to parameter events from local or remote node.
Definition: Worker.cxx:1056
bool DestroyPar(const std::string &name)
Method must be used if worker wants to destroy parameter.
Definition: Worker.cxx:592
EWorkerEventsCodes
Definition: Worker.h:199
@ evntFirstSystem
Definition: Worker.h:202
@ evntFirstCore
Definition: Worker.h:200
@ evntFirstAddOn
Definition: Worker.h:201
@ evntFirstUser
Definition: Worker.h:203
bool HasThread() const
Indicates if pointer on thread is not zero; thread-safe.
Definition: Worker.cxx:151
bool _FireEvent(uint16_t evid)
Definition: Worker.h:333
virtual bool Unpublish(const Hierarchy &h, const std::string &path)
Definition: Worker.cxx:1111
void CancelCommands()
Definition: Worker.cxx:1026
bool ActivateMainLoop()
Definition: Worker.cxx:505
bool MakeThreadForWorker(const std::string &thrdname="")
Creates appropriate thread for worker and assign worker to the thread.
Definition: Worker.cxx:302
virtual double ProcessTimeout(double last_diff)
Definition: Worker.h:326
virtual void DoWorkerMainLoop()
Internal - entrance function for main loop execution.
Definition: Worker.h:385
std::string ThreadName() const
Returns name of the worker thread; thread-safe
Definition: Worker.cxx:186
virtual bool Unsubscribe(const std::string &path)
Definition: Worker.cxx:1121
ThreadRef fThread
reference on the thread, once assigned remain whole time
Definition: Worker.h:151
virtual void ObjectDestroyed(Object *)
Method to clear object reference, will be called from thread context (when possible)
Definition: Worker.h:180
virtual bool Find(ConfigIO &cfg)
Method to locate object in xml file.
Definition: Worker.cxx:608
ThreadRef thread()
Return reference on the worker thread; thread-safe.
Definition: Worker.cxx:158
void SetWorkerPriority(int nq)
Definition: Worker.h:259
Reference GetPublisher()
Return reference on publisher.
Definition: Worker.cxx:1068
bool _FireEvent(uint16_t evid, uint32_t arg, int pri=-1)
Definition: Worker.h:347
@ parsChangableMask
Definition: Worker.h:121
@ parsVisibilityMask
Definition: Worker.h:119
@ parsValidMask
Definition: Worker.h:122
@ parsFixedMask
Definition: Worker.h:120
void SetParValue(const std::string &name, const RecordField &v)
Set parameter value and sync with worker hierarchy.
Definition: Worker.cxx:578
bool IsWorkerActive() const
Method indicates if worker is running in the thread and accepts normal events.
Definition: Worker.h:186
uint32_t WorkerId() const
Definition: Worker.h:262
int WorkerPriority() const
Definition: Worker.h:260
void ProcessCoreEvent(EventId)
Definition: Worker.cxx:392
virtual const char * ClassName() const
Returns class name of the object instance.
Definition: Worker.h:216
bool SingleLoop(double tmout)
Definition: Worker.h:373
bool DettachFromThread()
Detach worker from the thread, later worker can be assigned to some other thread Method especially us...
Definition: Worker.cxx:372
virtual bool ReplyCommand(Command cmd)
Reimplement this method to react on command reply Return true if command can be destroyed by framewor...
Definition: Worker.cxx:856
virtual void ObjectCleanup()
Central cleanup method for worker.
Definition: Worker.cxx:238
virtual Parameter CreatePar(const std::string &name, const std::string &kind="")
Definition: Worker.cxx:558
virtual bool Publish(const Hierarchy &h, const std::string &path)
Definition: Worker.cxx:1075
bool IsOwnThread() const
Returns true if called from thread.
Definition: Worker.cxx:176
Mutex * fThreadMutex
pointer on main thread mutex
Definition: Worker.h:158
virtual void ProcessParameterEvent(const ParameterEvent &evnt)
Interface method to retrieve subscribed parameter events.
Definition: Worker.h:413
bool FireEvent(uint16_t evid)
Definition: Worker.h:341
int fWorkerPriority
priority of events, submitted by worker to the thread
Definition: Worker.h:156
virtual ~Worker()
Definition: Worker.cxx:133
bool FireEvent(uint16_t evid, uint32_t arg, int pri=-1)
Definition: Worker.h:355
Event manipulation API.
Definition: api.h:23
@ parModified
produced when parameter value modified. Either every change or after time interval (default = 1 sec)
Definition: Parameter.h:43
@ cmd_false
Definition: Command.h:37
@ cmd_true
Definition: Command.h:38
Event structure, exchanged between DABC threads.
Definition: Thread.h:70
uint32_t GetArg() const
Definition: Thread.h:94
uint16_t GetCode() const
Definition: Thread.h:92