DABC (Data Acquisition Backbone Core)  2.9.9
CommandsQueue.h
Go to the documentation of this file.
1 // $Id: CommandsQueue.h 4464 2020-04-15 12:14:20Z 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_CommandsQueue
17 #define DABC_CommandsQueue
18 
19 #ifndef DABC_Command
20 #include "dabc/Command.h"
21 #endif
22 
23 #include <list>
24 
25 #include <cstdint>
26 
27 namespace dabc {
28 
29  class Worker;
30 
39  class CommandsQueue {
40 
41  public:
42 
43  enum EKind {
49  };
50 
51  protected:
52 
53  struct QueueRec {
56  uint32_t id;
57 
58  QueueRec() : cmd(), kind(kindNone), id(0) {}
59  QueueRec(const Command& _cmd, EKind _kind, uint32_t _id) : cmd(_cmd), kind(_kind), id(_id) {}
60  QueueRec(const QueueRec& src) : cmd(src.cmd), kind(src.kind), id(src.id) {}
62  {
63  cmd = src.cmd;
64  kind = src.kind;
65  id = src.id;
66  return *this;
67  }
68  };
69 
70  typedef std::list<QueueRec> QueueRecsList;
71 
74  uint32_t fIdCounter;
75 
76  public:
79  virtual ~CommandsQueue();
80 
84  uint32_t Push(Command cmd, EKind kind = kindNone);
85 
89  uint32_t ChangeKind(Command& cmd, EKind kind);
90 
91  Command Pop();
92  Command PopWithId(uint32_t id);
94  Command Front();
95  EKind FrontKind();
96 
97  unsigned Size() const { return fList.size(); }
98 
100  void ReplyAll(int res);
101 
103  void ReplyTimedout();
104 
105  void Cleanup(Mutex *m = nullptr, Worker *proc = nullptr, int res = cmd_false);
106  };
107 
108 }
109 
110 #endif
Represents command with its arguments.
Definition: Command.h:99
Queue of commands
Definition: CommandsQueue.h:39
uint32_t ChangeKind(Command &cmd, EKind kind)
Change kind of the entry for specified command.
@ kindSubmit
command submitted for execution
Definition: CommandsQueue.h:45
@ kindPostponed
command submitted but postponed to not increase execution recursion
Definition: CommandsQueue.h:48
@ kindReply
command replied to the worker
Definition: CommandsQueue.h:46
@ kindAssign
command assign with the worker, but not yet replied
Definition: CommandsQueue.h:47
void Cleanup(Mutex *m=nullptr, Worker *proc=nullptr, int res=cmd_false)
void ReplyTimedout()
Reply timed-out commands.
Command PopWithId(uint32_t id)
CommandsQueue(EKind kind=kindNone)
Normal constructor.
Command PopWithKind(EKind kind)
QueueRecsList fList
Definition: CommandsQueue.h:72
void ReplyAll(int res)
Reply all commands.
uint32_t Push(Command cmd, EKind kind=kindNone)
Add reference on the command in the queue.
std::list< QueueRec > QueueRecsList
Definition: CommandsQueue.h:70
unsigned Size() const
Definition: CommandsQueue.h:97
posix pthread mutex
Definition: threads.h:61
Active object, which is working inside dabc::Thread.
Definition: Worker.h:116
Event manipulation API.
Definition: api.h:23
@ cmd_false
Definition: Command.h:37
QueueRec(const Command &_cmd, EKind _kind, uint32_t _id)
Definition: CommandsQueue.h:59
QueueRec(const QueueRec &src)
Definition: CommandsQueue.h:60
QueueRec & operator=(const QueueRec &src)
Definition: CommandsQueue.h:61