AsyncFw 1.2
Async Framework is c++ runtime with timers, poll notifiers, sockets, coroutines, etc.
 
Loading...
Searching...
No Matches
Rrd.h
1/*
2Copyright (c) 2026 Alexandr Kuzmuk
3
4This file is part of the AsyncFw project. Licensed under the MIT License.
5See {Link: LICENSE file https://mit-license.org} in the project root for full license information.
6*/
7
8#pragma once
9
10#include "../core/FunctionConnector.h"
11#include "../core/DataArray.h"
12
13namespace AsyncFw {
14class Thread;
16class Rrd {
17public:
18 using Item = DataArray;
19 using ItemList = DataArrayList;
20 template <typename T>
21 void setAverage(int _interval, T f, int _offset = 0) {
22 average = new FunctionArgs<const ItemList &>::Function(f);
23 aInterval = _interval / interval;
24 aOffset = _offset;
25 }
26 Rrd(int size, int interval, int fillInterval, const std::string &name);
27 Rrd(int size, int interval, int fillInterval);
28 Rrd(int size, const std::string &name);
29 Rrd(int size);
30 ~Rrd();
31 uint64_t read(DataArrayList *list, uint64_t from = 0, uint32_t size = 0, uint64_t *lastIndex = nullptr);
32 void setFillInterval(int interval);
33 uint32_t size() { return dbSize; }
34 uint32_t count();
35
36 //Must lock the thread before calling this method
37 Item readFromArray(uint32_t);
38 //Must lock the thread before calling this method
39 void writeToArray(uint32_t, const Item &);
40
41 void append(const Item &data, uint64_t index = 0);
42 void save(const std::string &fn = {});
43 void clear();
44 uint64_t lastIndex();
45
46 FunctionConnectorProtected<Rrd>::Connector<> updated;
47
48 Thread *thread() { return thread_; }
49
50protected:
51 Thread *thread_;
52 uint64_t last_;
53 uint32_t dbSize;
54 ItemList dataBase;
55 uint32_t count_v;
56 bool readOnly = false;
57
58private:
59 AbstractFunction<const ItemList &> *average = nullptr;
60 int aInterval = 0;
61 int aOffset = 0;
62 int interval;
63 uint32_t fill;
64 std::string file;
65 bool createFile();
66 bool readFromFile();
67 bool saveToFile(const std::string &fn = {});
68};
69} // namespace AsyncFw
The DataArrayList class.
Definition DataArray.h:48
The DataArray class.
Definition DataArray.h:20
AsyncFw::Thread thread with sockets.
Definition Thread.h:16