14namespace opcua::services::detail {
16inline Result<Variant> getVariant(DataValue&& dv)
noexcept {
17 if (dv.status().isBad()) {
18 return BadResult(dv.status());
21 return BadResult(UA_STATUSCODE_BADUNEXPECTEDERROR);
23 return std::move(dv).value();
30template <AttributeId Attribute>
31struct AttributeHandler;
33struct AttributeHandlerVariant {
36 static Result<Variant> fromDataValue(DataValue&& dv)
noexcept {
37 return getVariant(std::move(dv));
40 static DataValue toDataValue(
const Variant& value)
noexcept {
49template <
typename T,
typename Enable =
void>
50struct AttributeHandlerScalar {
53 static Result<Type> fromDataValue(DataValue&& dv)
noexcept {
54 return getVariant(std::move(dv)).transform([](Variant&& var) {
55 assert(var.isType<T>());
56 assert(var.isScalar());
57 return std::move(var).scalar<T>();
63 return DataValue(Variant(std::forward<U>(value)));
68struct AttributeHandlerScalar<T, std::enable_if_t<std::is_enum_v<T>>> {
70 using UnderlyingType = std::underlying_type_t<Type>;
71 using UnderlyingHandler = AttributeHandlerScalar<UnderlyingType>;
73 static Result<Type> fromDataValue(DataValue&& dv)
noexcept {
74 return UnderlyingHandler::fromDataValue(std::move(dv)).transform([](
auto value) {
75 return static_cast<Type
>(value);
79 static DataValue toDataValue(Type value) {
80 return UnderlyingHandler::toDataValue(
static_cast<UnderlyingType
>(value));
85struct AttributeHandlerScalar<Bitmask<T>> {
86 using Type = Bitmask<T>;
88 using UnderlyingHandler = AttributeHandlerScalar<UnderlyingType>;
90 static Result<Type> fromDataValue(DataValue&& dv)
noexcept {
91 return UnderlyingHandler::fromDataValue(std::move(dv)).transform([](
auto value) {
92 return Bitmask<T>(value);
96 static DataValue toDataValue(Type value) {
97 return UnderlyingHandler::toDataValue(value.get());
108 static Result<Type> fromDataValue(DataValue&& dv)
noexcept {
109 return getVariant(std::move(dv)).transform([](
const Variant& var) {
111 return *
static_cast<const NodeClass*
>(var.data());
145 : AttributeHandlerScalar<Bitmask<EventNotifier>> {};
158 using Type = std::vector<uint32_t>;
160 static Result<Type> fromDataValue(DataValue&& dv)
noexcept {
161 return getVariant(std::move(dv)).transform([](Variant&& var) {
162 assert(var.isType<uint32_t>());
163 assert(var.isArray());
164 return std::move(var).to<Type>();
178 : AttributeHandlerScalar<Bitmask<AccessLevel>> {};
std::underlying_type_t< T > Underlying
Span(Container &) -> Span< typename Container::value_type >
EventNotifier
Event notifier.
AttributeId
Attribute identifiers.
@ UserExecutable
Indicates if the method is currently executable taking user access rights into account.
@ Historizing
Indicates whether the server is actively collecting data for the history of the variable.
@ Executable
Indicates if the method is currently executable.
@ DisplayName
The localized name of the node.
@ NodeId
Unambiguous identifier of a node.
@ BrowseName
A non-localised human-readable name used to browse the address space.
@ Value
The most recent value of the variable that the server has.
@ MinimumSamplingInterval
Specifies (in milliseconds) how fast the server can reasonably sample the value for changes.
@ IsAbstract
If a reference is abstract, no reference of this type shall exist, only of its subtypes.
@ InverseName
The inverse name describes the reference type as seen from the target node.
@ DataType
The NodeId of the data type definition for the Value attribute.
@ Description
Explains the meaning of the node in a localized text.
@ UserWriteMask
Exposes the possibilities of a client to write the attributes of the node.
@ ArrayDimensions
Specifies the maximum supported length of each dimension of the Value attribute.
@ ContainsNoLoops
Indicates that by following the references in the context of the view there are no loops.
@ UserAccessLevel
Indicates how the value of a variable can be accessed (read/write) and if it contains current and/or ...
@ DataTypeDefinition
Provides the meta data and encoding information for custom data types.
@ Symmetric
If a reference is symmetric, it can seen from both the source and target node.