libhomegear-base  0.7
Base library for Homegear and Homegear family modules.
ITimedQueue.h
Go to the documentation of this file.
1 /* Copyright 2013-2019 Homegear GmbH
2  *
3  * libhomegear-base is free software: you can redistribute it and/or
4  * modify it under the terms of the GNU Lesser General Public License as
5  * published by the Free Software Foundation, either version 3 of the
6  * License, or (at your option) any later version.
7  *
8  * libhomegear-base is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public
14  * License along with libhomegear-base. If not, see
15  * <http://www.gnu.org/licenses/>.
16  *
17  * In addition, as a special exception, the copyright holders give
18  * permission to link the code of portions of this program with the
19  * OpenSSL library under certain conditions as described in each
20  * individual source file, and distribute linked combinations
21  * including the two.
22  * You must obey the GNU Lesser General Public License in all respects
23  * for all of the code used other than OpenSSL. If you modify
24  * file(s) with this exception, you may extend this exception to your
25  * version of the file(s), but you are not obligated to do so. If you
26  * do not wish to do so, delete this exception statement from your
27  * version. If you delete this exception statement from all source
28  * files in the program, then also delete it here.
29 */
30 
31 #ifndef ITIMEDQUEUE_H_
32 #define ITIMEDQUEUE_H_
33 
34 #include "IQueueBase.h"
35 
36 #include <map>
37 
38 namespace BaseLib {
39 class SharedObjects;
40 
42  public:
44  ITimedQueueEntry(int64_t time) { _time = time; };
45  virtual ~ITimedQueueEntry() {};
46 
47  int64_t getTime() { return _time; }
48  void setTime(int64_t value) { _time = value; }
49  private:
50  int64_t _time = 0;
51 };
52 
53 class ITimedQueue : public IQueueBase {
54  public:
55  ITimedQueue(SharedObjects *baseLib, uint32_t queueCount);
56  virtual ~ITimedQueue();
57 
58  void startQueue(int32_t index, int32_t threadPriority, int32_t threadPolicy);
59  void stopQueue(int32_t index);
60  bool enqueue(int32_t index, std::shared_ptr<ITimedQueueEntry> &entry, int64_t &id);
61  void removeQueueEntry(int32_t index, int64_t id);
62  virtual void processQueueEntry(int32_t index, int64_t id, std::shared_ptr<ITimedQueueEntry> &entry) = 0;
63  private:
64  static const int32_t _bufferSize = 1000;
65  std::vector<bool> _firstPositionChanged;
66  std::unique_ptr<std::mutex[]> _bufferMutex = nullptr;
67  std::vector<std::map<int64_t, std::shared_ptr<ITimedQueueEntry>>> _buffer;
68  std::unique_ptr<std::mutex[]> _processingThreadMutex = nullptr;
69  std::vector<std::thread> _processingThread;
70  std::unique_ptr<std::condition_variable[]> _processingConditionVariable = nullptr;
71 
72  void process(int32_t index);
73 };
74 
75 }
76 #endif
This is the base library main class.
Definition: BaseLib.h:95
Definition: IQueueBase.h:45
Definition: BaseLib.cpp:34
Definition: ITimedQueue.h:41
PVariable value
Definition: UiElements.h:217
int64_t getTime()
Definition: ITimedQueue.h:47
ITimedQueueEntry(int64_t time)
Definition: ITimedQueue.h:44
void setTime(int64_t value)
Definition: ITimedQueue.h:48
ITimedQueueEntry()
Definition: ITimedQueue.h:43
Definition: ITimedQueue.h:53
virtual ~ITimedQueueEntry()
Definition: ITimedQueue.h:45