open62541pp
0.15.0
C++ wrapper of open62541
Loading...
Searching...
No Matches
include
open62541pp
services
detail
callbackadapter.hpp
Go to the documentation of this file.
1
#pragma once
2
3
#include <functional>
4
5
#include "
open62541pp/detail/exceptioncatcher.hpp
"
6
7
namespace
opcua::services::detail
{
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
*/
16
struct
CallbackAdapter
{
17
// Optionally provide exception catcher, otherwise exceptions will be ignored
18
opcua::detail::ExceptionCatcher
*
catcher
=
nullptr
;
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
opcua::detail::ExceptionCatcher
Catch & store exceptions from user-defined callbacks in an exception-unaware context (open62541).
Definition
exceptioncatcher.hpp:13
opcua::detail::ExceptionCatcher::invoke
void invoke(Callback &&callback, Args &&... args) noexcept
Definition
exceptioncatcher.hpp:30
exceptioncatcher.hpp
args
static UA_LogCategory const char va_list args
opcua::services::detail
Definition
attribute.hpp:239
opcua::services::detail::CallbackAdapter
Helper class to map open62541 / C-style callbacks to std::function objects.
Definition
callbackadapter.hpp:16
opcua::services::detail::CallbackAdapter::invoke
void invoke(F &&callback, Args &&... args) const noexcept
Definition
callbackadapter.hpp:21
opcua::services::detail::CallbackAdapter::catcher
opcua::detail::ExceptionCatcher * catcher
Definition
callbackadapter.hpp:18
Generated by
1.11.0