-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcall_every_handler.h
43 lines (33 loc) · 1.14 KB
/
call_every_handler.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#pragma once
#include <mutex>
#include <memory>
#include <functional>
#include <unordered_map>
#include "global_include.h"
namespace mavsdk {
class CallEveryHandler {
public:
CallEveryHandler(Time& time);
~CallEveryHandler();
// delete copy and move constructors and assign operators
CallEveryHandler(CallEveryHandler const&) = delete; // Copy construct
CallEveryHandler(CallEveryHandler&&) = delete; // Move construct
CallEveryHandler& operator=(CallEveryHandler const&) = delete; // Copy assign
CallEveryHandler& operator=(CallEveryHandler&&) = delete; // Move assign
void add(std::function<void()> callback, double interval_s, void** cookie);
void change(double interval_s, const void* cookie);
void reset(const void* cookie);
void remove(const void* cookie);
void run_once();
private:
struct Entry {
std::function<void()> callback{nullptr};
dl_time_t last_time{};
double interval_s{0.0f};
};
std::unordered_map<void*, std::shared_ptr<Entry>> _entries{};
std::mutex _entries_mutex{};
bool _iterator_invalidated{false};
Time& _time;
};
} // namespace mavsdk