Vanetza
 
Loading...
Searching...
No Matches
runtime.hpp
1#ifndef RUNTIME_HPP_KHDIEMRN
2#define RUNTIME_HPP_KHDIEMRN
3
4#include <vanetza/common/clock.hpp>
5#include <functional>
6
7namespace vanetza
8{
9
10/**
11 * Runtime provides current time and enables scheduling of tasks for later execution.
12 *
13 * All calls to Runtime and objects using the same Runtime have to be invoked from same thread!
14 **/
16{
17public:
18 using Callback = std::function<void(Clock::time_point)>;
19
20 /**
21 * Schedule callback for later invocation
22 * \param tp invoke callback at this time point
23 * \param cb callback
24 * \param scope associated scope pointer (used only for identification)
25 */
26 virtual void schedule(Clock::time_point tp, const Callback& cb, const void* scope = nullptr) = 0;
27
28 /**
29 * Schedule callback for later invocation
30 * \param d duration from now until callback invocation
31 * \param cb callback
32 * \param scope associated scope pointer (used only for identification)
33 */
34 virtual void schedule(Clock::duration d, const Callback& cb, const void* scope = nullptr) = 0;
35
36 /**
37 * Cancel all scheduled invocations assigned to certain scope
38 * \param scope any pointer used as scope at scheduling (nullptr has no effect)
39 */
40 virtual void cancel(const void* scope) = 0;
41
42 /**
43 * Get current time
44 * \return current time
45 */
46 virtual Clock::time_point now() const = 0;
47
48 virtual ~Runtime() = default;
49};
50
51} // namespace vanetza
52
53#endif /* RUNTIME_HPP_KHDIEMRN */
54
virtual void cancel(const void *scope)=0
virtual Clock::time_point now() const =0
virtual void schedule(Clock::time_point tp, const Callback &cb, const void *scope=nullptr)=0
virtual void schedule(Clock::duration d, const Callback &cb, const void *scope=nullptr)=0