BeeeOn Gateway  v2020.3.1-2-g6f737dc
Platform to interconnect the IoT world
AnswerQueue.h
1 #pragma once
2 
3 #include <list>
4 
5 #include <Poco/Event.h>
6 #include <Poco/Timespan.h>
7 
8 #include "core/Answer.h"
9 #include "util/Loggable.h"
10 
11 namespace BeeeOn {
12 
13 /*
14  * The responses are added to the queue during the Answer creation. After
15  * the status is changed in the Result, the Answer is set to dirty and the
16  * Answer notifies the queue about this change.
17  *
18  * It is possible to wait for Answer from queue for a given time using
19  * wait(Timespan, dirtyList). After a given time Answers with the set dirty
20  * (the status Response was set to the Answers) are stored to the dirtyList.
21  */
22 class AnswerQueue : public Loggable {
23  friend Answer;
24 public:
25  AnswerQueue();
26 
27  /*
28  * Blocking waiting for the list of the Answers in which
29  * change Results were. Returns true if the event became
30  * signalled within the specified time interval, false otherwise.
31  */
32  bool wait(const Poco::Timespan &timeout,
33  std::list<Answer::Ptr> &dirtyList);
34 
35  Answer::Ptr newAnswer();
36 
37  void remove(const Answer::Ptr answer);
38 
39  std::list<Answer::Ptr> finishedAnswers();
40 
41  Poco::Event &event();
42 
43  unsigned long size() const;
44 
49  void dispose();
50 
51  void notifyUpdated();
52 
53 protected:
54  void add(Answer *answer);
55 
56  bool isDisposed() const;
57 
58  bool block(const Poco::Timespan &timeout);
59 
60  /*
61  * List of Answer, which were set as dirty.
62  */
63  void listDirty(std::list<Answer::Ptr> &dirtyList) const;
64 
65 protected:
66  std::list<Answer::Ptr> m_answerList;
67  Poco::Event m_event;
68  mutable Poco::FastMutex m_mutex;
69  Poco::AtomicCounter m_disposed;
70 };
71 
72 }
Definition: Answer.h:30
Definition: AnswerQueue.h:22
Definition: Loggable.h:19
void dispose()
Definition: AnswerQueue.cpp:117