open62541pp 0.19.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 /// 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 IntegerId subscriptionId_{0U};
95 IntegerId monitoredItemId_{0U};
96};
97
98/* ---------------------------------------------------------------------------------------------- */
99
100/// @relates MonitoredItem
101template <typename T>
102inline bool operator==(const MonitoredItem<T>& lhs, const MonitoredItem<T>& rhs) noexcept {
103 return (lhs.connection() == rhs.connection()) &&
104 (lhs.subscriptionId() == rhs.subscriptionId()) &&
105 (lhs.monitoredItemId() == rhs.monitoredItemId());
106}
107
108/// @relates MonitoredItem
109template <typename T>
110inline bool operator!=(const MonitoredItem<T>& lhs, const MonitoredItem<T>& rhs) noexcept {
111 return !(lhs == rhs);
112}
113
114} // namespace opcua
115
116#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.
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.
UA_NodeId wrapper class.
Definition types.hpp:641
constexpr void throwIfBad() const
Throw a BadStatus exception if the status code is bad.
Definition types.hpp:82
const StatusCode & statusCode() const noexcept
Definition types.hpp:2075
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:1623
uint32_t IntegerId
IntegerId.
Definition types.hpp:84
AttributeId
Attribute identifiers.
Definition common.hpp:28
Extended monitoring parameters with default values from open62541.