open62541pp 0.17.0
C++ wrapper of open62541
Loading...
Searching...
No Matches
monitoreditem.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <type_traits>
4
5#include "open62541pp/common.hpp" // AttributeId
6#include "open62541pp/config.hpp"
9#include "open62541pp/ua/types.hpp" // IntegerId
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.
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 IntegerId subscriptionId() const noexcept {
52 return subscriptionId_;
53 }
54
55 /// Get the server-assigned identifier of this monitored item.
56 IntegerId monitoredItemId() const noexcept {
57 return monitoredItemId_;
58 }
59
60 /// Get the monitored NodeId.
61 const NodeId& nodeId();
62
63 /// @deprecated Use nodeId() instead
64 [[deprecated("use nodeId() instead")]]
65 const NodeId& getNodeId() {
66 return nodeId();
67 }
68
69 /// Get the monitored AttributeId.
71
72 /// @deprecated Use attributeId() instead
73 [[deprecated("use attributeId() instead")]]
75 return attributeId();
76 }
77
78 /// Modify this monitored item.
79 /// @note Not implemented for Server.
80 /// @see services::modifyMonitoredItem
86
87 /// Set the monitoring mode of this monitored item.
88 /// @note Not implemented for Server.
89 /// @see services::setMonitoringMode
90 void setMonitoringMode(MonitoringMode monitoringMode) {
92 connection(), subscriptionId(), monitoredItemId(), monitoringMode
93 )
94 .throwIfBad();
95 }
96
97 /// Delete this monitored item.
98 /// @see services::deleteMonitoredItem
103
104private:
105 Connection* connection_;
106 IntegerId subscriptionId_{0U};
107 IntegerId monitoredItemId_{0U};
108};
109
110/* ---------------------------------------------------------------------------------------------- */
111
112/// @relates MonitoredItem
113template <typename T>
114inline bool operator==(const MonitoredItem<T>& lhs, const MonitoredItem<T>& rhs) noexcept {
115 return (lhs.connection() == rhs.connection()) &&
116 (lhs.subscriptionId() == rhs.subscriptionId()) &&
117 (lhs.monitoredItemId() == rhs.monitoredItemId());
118}
119
120/// @relates MonitoredItem
121template <typename T>
122inline bool operator!=(const MonitoredItem<T>& lhs, const MonitoredItem<T>& rhs) noexcept {
123 return !(lhs == rhs);
124}
125
126} // namespace opcua
127
128#endif
High-level monitored item class.
IntegerId subscriptionId() const noexcept
Get the server-assigned identifier of the underlying subscription.
const Connection & connection() const noexcept
Get the server/client instance.
MonitoredItem(Connection &connection, IntegerId subscriptionId, IntegerId monitoredItemId) noexcept
Wrap an existing monitored item.
void deleteMonitoredItem()
Delete this monitored item.
void setMonitoringMode(MonitoringMode monitoringMode)
Set the monitoring mode of this monitored item.
bool operator==(const MonitoredItem< T > &lhs, const MonitoredItem< T > &rhs) noexcept
Connection & connection() noexcept
Get the server/client instance.
const NodeId & getNodeId()
void setMonitoringParameters(const MonitoringParametersEx &parameters)
Modify this monitored item.
const NodeId & nodeId()
Get the monitored NodeId.
bool operator!=(const MonitoredItem< T > &lhs, const MonitoredItem< T > &rhs) noexcept
IntegerId monitoredItemId() const noexcept
Get the server-assigned identifier of this monitored item.
AttributeId attributeId()
Get the monitored AttributeId.
AttributeId getAttributeId()
UA_NodeId wrapper class.
Definition types.hpp:666
constexpr void throwIfBad() const
Throw a BadStatus exception if the status code is bad.
Definition types.hpp:84
const StatusCode & statusCode() const noexcept
Definition types.hpp:2122
StatusCode deleteMonitoredItem(T &connection, IntegerId subscriptionId, IntegerId monitoredItemId)
Delete a monitored item from a subscription.
MonitoredItemModifyResult modifyMonitoredItem(Client &connection, IntegerId subscriptionId, IntegerId 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 types.hpp:1664
uint32_t IntegerId
IntegerId.
Definition types.hpp:123
AttributeId
Attribute identifiers.
Definition common.hpp:28
Extended monitoring parameters with default values from open62541.