open62541pp 0.20.0
C++ wrapper of open62541
Loading...
Searching...
No Matches
callback.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4#include <functional>
5
6#include "open62541pp/types.hpp" // DateTime
7
8namespace opcua {
9
10class Client;
11class Server;
12
13using CallbackId = uint64_t;
14using TimedCallback = std::function<void()>;
15using RepeatedCallback = std::function<void()>;
16
17/**
18 * Add a callback for execution at a specified time.
19 * If the indicated time lies in the past, then the callback is executed at the next iteration of
20 * the event loop.
21 * @param connection Instance of type Client or Server
22 * @param callback Callback to be executed
23 * @param date Execution time for the callback
24 * @return Callback identifier
25 */
26template <typename T>
27[[nodiscard]] CallbackId addTimedCallback(T& connection, TimedCallback callback, DateTime date);
28
29/**
30 * Add a callback for repeated execution.
31 * @param connection Instance of type Client or Server
32 * @param callback Callback to be executed
33 * @param intervalMilliseconds Execution interval in milliseconds (must be > 0).
34 * The first execution occurs at now() + interval at the latest.
35 * @return Callback identifier
36 */
37template <typename T>
39 T& connection, RepeatedCallback callback, double intervalMilliseconds
40);
41
42/**
43 * Change the execution interval of an existing repeated callback.
44 * @param connection Instance of type Client or Server
45 * @param callbackId Callback identifier
46 * @param intervalMilliseconds New interval in milliseconds (must be > 0)
47 */
48template <typename T>
50 T& connection, CallbackId callbackId, double intervalMilliseconds
51);
52
53/**
54 * Remove a previously registered callback.
55 * @param connection Instance of type Client or Server
56 * @param callbackId Callback identifier
57 */
58template <typename T>
59void removeCallback(T& connection, CallbackId callbackId);
60
61} // namespace opcua
UA_DateTime wrapper class.
Definition types.hpp:359
std::function< void()> RepeatedCallback
Definition callback.hpp:15
uint64_t CallbackId
Definition callback.hpp:13
void changeRepeatedCallbackInterval(T &connection, CallbackId callbackId, double intervalMilliseconds)
Change the execution interval of an existing repeated callback.
std::function< void()> TimedCallback
Definition callback.hpp:14
CallbackId addTimedCallback(T &connection, TimedCallback callback, DateTime date)
Add a callback for execution at a specified time.
void removeCallback(T &connection, CallbackId callbackId)
Remove a previously registered callback.
CallbackId addRepeatedCallback(T &connection, RepeatedCallback callback, double intervalMilliseconds)
Add a callback for repeated execution.