open62541pp 0.16.0
C++ wrapper of open62541
Loading...
Searching...
No Matches
monitoreditem.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4#include <type_traits>
5
6#include "open62541pp/common.hpp" // AttributeId
7#include "open62541pp/config.hpp"
10
11#ifdef UA_ENABLE_SUBSCRIPTIONS
12
13namespace opcua {
14
15class Server;
16
18
19/**
20 * High-level monitored item class.
21 *
22 * @tparam Connection Server or Client
23 * @note Not all methods are available and implemented for servers.
24 *
25 * Use the free functions in the opcua::services namespace for more advanced usage:
26 * - @ref MonitoredItem
27 */
28template <typename Connection>
30public:
31 /// Wrap an existing monitored item.
32 /// The `subscriptionId` is ignored and set to `0U` for servers.
34 Connection& connection, uint32_t subscriptionId, uint32_t monitoredItemId
35 ) noexcept
36 : connection_(&connection),
37 subscriptionId_(std::is_same_v<Connection, Server> ? 0U : subscriptionId),
38 monitoredItemId_(monitoredItemId) {}
39
40 /// Get the server/client instance.
41 Connection& connection() noexcept {
42 return *connection_;
43 }
44
45 /// Get the server/client instance.
46 const Connection& connection() const noexcept {
47 return *connection_;
48 }
49
50 /// Get the server-assigned identifier of the underlying subscription.
51 uint32_t subscriptionId() const noexcept {
52 return subscriptionId_;
53 }
54
55 /// Get the server-assigned identifier of this monitored item.
56 uint32_t monitoredItemId() const noexcept {
57 return monitoredItemId_;
58 }
59
60 /// Get the monitored NodeId.
61 const NodeId& getNodeId();
62
63 /// Get the monitored AttributeId.
65
66 /// Modify this monitored item.
67 /// @note Not implemented for Server.
68 /// @see services::modifyMonitoredItem
74
75 /// Set the monitoring mode of this monitored item.
76 /// @note Not implemented for Server.
77 /// @see services::setMonitoringMode
78 void setMonitoringMode(MonitoringMode monitoringMode) {
80 connection(), subscriptionId(), monitoredItemId(), monitoringMode
81 )
82 .throwIfBad();
83 }
84
85 /// Delete this monitored item.
86 /// @see services::deleteMonitoredItem
91
92private:
93 Connection* connection_;
94 uint32_t subscriptionId_{0U};
95 uint32_t monitoredItemId_{0U};
96};
97
98/* ---------------------------------------------------------------------------------------------- */
99
100template <typename T>
101inline bool operator==(const MonitoredItem<T>& lhs, const MonitoredItem<T>& rhs) noexcept {
102 return (lhs.connection() == rhs.connection()) &&
103 (lhs.subscriptionId() == rhs.subscriptionId()) &&
104 (lhs.monitoredItemId() == rhs.monitoredItemId());
105}
106
107template <typename T>
108inline bool operator!=(const MonitoredItem<T>& lhs, const MonitoredItem<T>& rhs) noexcept {
109 return !(lhs == rhs);
110}
111
112} // namespace opcua
113
114#endif
const StatusCode & getStatusCode() const noexcept
High-level monitored item class.
const Connection & connection() const noexcept
Get the server/client instance.
void deleteMonitoredItem()
Delete this monitored item.
void setMonitoringMode(MonitoringMode monitoringMode)
Set the monitoring mode of this monitored item.
uint32_t subscriptionId() const noexcept
Get the server-assigned identifier of the underlying subscription.
Connection & connection() noexcept
Get the server/client instance.
uint32_t monitoredItemId() const noexcept
Get the server-assigned identifier of this monitored item.
const NodeId & getNodeId()
Get the monitored NodeId.
void setMonitoringParameters(const MonitoringParametersEx &parameters)
Modify this monitored item.
MonitoredItem(Connection &connection, uint32_t subscriptionId, uint32_t monitoredItemId) noexcept
Wrap an existing monitored item.
AttributeId getAttributeId()
Get the monitored AttributeId.
UA_NodeId wrapper class.
Definition types.hpp:590
constexpr void throwIfBad() const
Throw a BadStatus exception if the status code is bad.
Definition types.hpp:82
StatusCode deleteMonitoredItem(T &connection, uint32_t subscriptionId, uint32_t monitoredItemId)
Delete a monitored item from a subscription.
MonitoredItemModifyResult modifyMonitoredItem(Client &connection, uint32_t subscriptionId, uint32_t monitoredItemId, const MonitoringParametersEx &parameters) noexcept
Modify a monitored item of a subscription.
SetMonitoringModeResponse setMonitoringMode(Client &connection, const SetMonitoringModeRequest &request) noexcept
Set the monitoring mode of monitored items.
MonitoringMode
Monitoring mode.
Definition common.hpp:302
bool operator!=(const Client &lhs, const Client &rhs) noexcept
Definition client.hpp:295
AttributeId
Attribute identifiers.
Definition common.hpp:28
bool operator==(const Client &lhs, const Client &rhs) noexcept
Definition client.hpp:291
Extended monitoring parameters with default values from open62541.