open62541pp 0.15.0
C++ wrapper of open62541
Loading...
Searching...
No Matches
callbackadapter.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <functional>
4
6
8
9/**
10 * Helper class to map open62541 / C-style callbacks to `std::function` objects.
11 * The the concrete adapter should:
12 * - store the `std::function` objects
13 * - implement static methods of the native open62541 callbacks
14 * - pass the pointer to itself as the callback context
15 */
17 // Optionally provide exception catcher, otherwise exceptions will be ignored
19
20 template <typename F, typename... Args>
21 void invoke(F&& callback, Args&&... args) const noexcept {
22 if (callback != nullptr) {
23 if (catcher != nullptr) {
24 catcher->invoke(std::forward<F>(callback), std::forward<Args>(args)...);
25 } else {
26 try {
27 std::invoke(std::forward<F>(callback), std::forward<Args>(args)...);
28 } catch (...) { // NOLINT(bugprone-empty-catch)
29 // ignore exceptions
30 }
31 }
32 }
33 }
34};
35
36} // namespace opcua::services::detail
Catch & store exceptions from user-defined callbacks in an exception-unaware context (open62541).
void invoke(Callback &&callback, Args &&... args) noexcept
static UA_LogCategory const char va_list args
Helper class to map open62541 / C-style callbacks to std::function objects.
void invoke(F &&callback, Args &&... args) const noexcept
opcua::detail::ExceptionCatcher * catcher