forked from open62541pp/open62541pp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevent.cpp
69 lines (54 loc) · 1.88 KB
/
event.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include "open62541pp/event.hpp"
#include "open62541pp/config.hpp" // UA_ENABLE_SUBSCRIPTIONS_EVENTS
#include "open62541pp/detail/open62541/server.h"
#include "open62541pp/exception.hpp"
#include "open62541pp/server.hpp"
#include "open62541pp/types.hpp"
namespace opcua {
#ifdef UA_ENABLE_SUBSCRIPTIONS_EVENTS
Event::Event(Server& connection, const NodeId& eventType)
: connection_(&connection) {
throwIfBad(UA_Server_createEvent(connection.handle(), eventType, id_.handle()));
}
Event::~Event() {
UA_Server_deleteNode(connection().handle(), id(), true /* deleteReferences */);
}
Event& Event::writeSourceName(std::string_view sourceName) {
return writeProperty({0, "SourceName"}, Variant(sourceName));
}
Event& Event::writeTime(DateTime time) { // NOLINT(performance-unnecessary-value-param)
return writeProperty({0, "Time"}, Variant(time));
}
Event& Event::writeSeverity(uint16_t severity) {
return writeProperty({0, "Severity"}, Variant(severity));
}
Event& Event::writeMessage(const LocalizedText& message) {
return writeProperty({0, "Message"}, Variant(message));
}
Event& Event::writeProperty(const QualifiedName& propertyName, const Variant& value) {
const auto status = UA_Server_writeObjectProperty(
connection().handle(), id(), propertyName, value
);
throwIfBad(status);
return *this;
}
ByteString Event::trigger(const NodeId& originId) {
ByteString eventId;
const auto status = UA_Server_triggerEvent(
connection().handle(),
id(),
originId,
eventId.handle(),
false // deleteEventNode
);
throwIfBad(status);
return eventId;
}
#endif
bool operator==(const Event& lhs, const Event& rhs) noexcept {
return (lhs.connection() == rhs.connection()) && (lhs.id() == rhs.id());
}
bool operator!=(const Event& lhs, const Event& rhs) noexcept {
return !(lhs == rhs);
}
} // namespace opcua