open62541pp 0.15.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 <functional>
5
6#include "open62541pp/common.hpp" // TimestampsToReturn, MonitoringMode
7#include "open62541pp/config.hpp"
10#include "open62541pp/types.hpp"
12
13#ifdef UA_ENABLE_SUBSCRIPTIONS
14
15namespace opcua {
16class Client;
17} // namespace opcua
18
19namespace opcua::services {
20
21/**
22 * @defgroup MonitoredItem MonitoredItem service set
23 * Subscribe to data and events.
24 *
25 * Note the difference between Subscriptions and MonitoredItems. Subscriptions are used to report
26 * back notifications. Monitored items are used to generate notifications. Every monitored item is
27 * attached to exactly one subscription. And a subscription can contain many monitored items.
28 *
29 * Monitored items can also be registered locally (server-side). Notifications are then forwarded
30 * to a user-defined callback instead of a remote client.
31 *
32 * @see Subscription
33 * @see https://reference.opcfoundation.org/Core/Part4/v105/docs/5.12
34 * @ingroup Services
35 * @{
36 */
37
38/**
39 * Extended monitoring parameters with default values from open62541.
40 * This is an extended version of `UA_MonitoringParameters` with the `timestamps` parameter.
41 * Parameters are passed by reference because illegal parameters can be revised by the server.
42 * The updated parameters reflect the actual values that the server will use.
43 * @see https://reference.opcfoundation.org/Core/Part4/v105/docs/7.21
44 */
46 /// Timestamps to be transmitted. Won't be revised by the server.
48 /// Interval in milliseconds that defines the fastest rate at which the MonitoredItem should be
49 /// accessed and evaluated. The following values have special meaning:
50 /// - `0.0` to use the fastest practical rate
51 /// - `-1.0` to use the default sampling interval (publishing interval of the subscription)
52 double samplingInterval = 250.0;
53 /// Filter is used by the server to determine if the MonitoredItem should generate
54 /// notifications. The filter parameter type is an extensible parameter type and can be, for
55 /// example, of type DataChangeFilter, EventFilter or AggregateFilter.
56 /// @see https://reference.opcfoundation.org/Core/Part4/v105/docs/7.22
58 /// Size of the MonitoringItem queue.
59 /// The following values have special meaning:
60 /// - `0` to retrieve the server's default queue size
61 /// - `1` to retrieve the server's minimum queue size
62 /// In the case of a queue overflow, an Event of the type EventQueueOverflowEventType is
63 /// generated.
64 uint32_t queueSize = 1;
65 /// Discard policy when the queue is full.
66 /// - `true`: the oldest (first) notification in the queue is discarded
67 /// - `false`: the last notification added to the queue gets replaced with the new notification
68 bool discardOldest = true;
69};
70
71/**
72 * @defgroup CreateMonitoredItems CreateMonitoredItems service
73 * Create and add a monitored item to a subscription.
74 * @see https://reference.opcfoundation.org/Core/Part4/v105/docs/5.12.2
75 * @{
76 */
77
78/**
79 * MonitoredItem deletion callback.
80 * @param subId Subscription identifier
81 * @param monId MonitoredItem identifier
82 */
83using DeleteMonitoredItemCallback = std::function<void(uint32_t subId, uint32_t monId)>;
84
85/**
86 * Data change notification callback.
87 * @param subId Subscription identifier (`0U` for local (server-side) monitored item)
88 * @param monId MonitoredItem identifier
89 * @param value Changed value
90 */
92 std::function<void(uint32_t subId, uint32_t monId, const DataValue& value)>;
93
94/**
95 * Event notification callback.
96 * @param subId Subscription identifier (`0U` for local (server-side) monitored item)
97 * @param monId MonitoredItem identifier
98 * @param eventFields Event fields
99 */
101 std::function<void(uint32_t subId, uint32_t monId, Span<const Variant> eventFields)>;
102
103/**
104 * Create and add monitored items to a subscription for data change notifications.
105 * Don't use this function to monitor the `EventNotifier` attribute.
106 * Create monitored items with @ref createMonitoredItemsEvent instead.
107 *
108 * @param connection Instance of type Client
109 * @param request Create monitored items request
110 * @param dataChangeCallback Invoked when the monitored item is changed
111 * @param deleteCallback Invoked when the monitored item is deleted
112 */
114 Client& connection,
115 const CreateMonitoredItemsRequest& request,
116 DataChangeNotificationCallback dataChangeCallback,
117 DeleteMonitoredItemCallback deleteCallback = {}
118);
119
120/**
121 * Create and add a monitored item to a subscription for data change notifications.
122 * Don't use this function to monitor the `EventNotifier` attribute.
123 * Create a monitored item with @ref createMonitoredItemEvent instead.
124 * @copydetails MonitoringParametersEx
125 *
126 * @return Server-assigned identifier of the monitored item
127 * @param connection Instance of type Server or Client
128 * @param subscriptionId Identifier of the subscription returned by @ref createSubscription.
129 * Use `0U` for a local server-side monitored item.
130 * @param itemToMonitor Item to monitor
131 * @param monitoringMode Monitoring mode
132 * @param parameters Monitoring parameters, may be revised by server
133 * @param dataChangeCallback Invoked when the monitored item is changed
134 * @param deleteCallback Invoked when the monitored item is deleted
135 */
136template <typename T>
138 T& connection,
139 uint32_t subscriptionId,
140 const ReadValueId& itemToMonitor,
141 MonitoringMode monitoringMode,
142 MonitoringParametersEx& parameters,
143 DataChangeNotificationCallback dataChangeCallback,
144 DeleteMonitoredItemCallback deleteCallback = {}
145);
146
147/**
148 * Create and add monitored items to a subscription for event notifications.
149 * The `attributeId` of ReadValueId must be set to AttributeId::EventNotifier.
150 *
151 * @param connection Instance of type Client
152 * @param request Create monitored items request
153 * @param eventCallback Invoked when an event is published
154 * @param deleteCallback Invoked when the monitored item is deleted
155 */
157 Client& connection,
158 const CreateMonitoredItemsRequest& request,
159 EventNotificationCallback eventCallback,
160 DeleteMonitoredItemCallback deleteCallback = {}
161);
162
163/**
164 * Create and add a monitored item to a subscription for event notifications.
165 * The `attributeId` of ReadValueId must be set to AttributeId::EventNotifier.
166 * @copydetails MonitoringParametersEx
167 *
168 * @return Server-assigned identifier of the monitored item
169 * @param connection Instance of type Client
170 * @param subscriptionId Identifier of the subscription returned by @ref createSubscription
171 * @param itemToMonitor Item to monitor
172 * @param monitoringMode Monitoring mode
173 * @param parameters Monitoring parameters, may be revised by server
174 * @param eventCallback Invoked when an event is published
175 * @param deleteCallback Invoked when the monitored item is deleted
176 */
178 Client& connection,
179 uint32_t subscriptionId,
180 const ReadValueId& itemToMonitor,
181 MonitoringMode monitoringMode,
182 MonitoringParametersEx& parameters,
183 EventNotificationCallback eventCallback,
184 DeleteMonitoredItemCallback deleteCallback = {}
185);
186
187/**
188 * @}
189 * @defgroup ModifyMonitoredItems ModifyMonitoredItems service
190 * Modify a monitored items of a subscription.
191 * @see https://reference.opcfoundation.org/Core/Part4/v105/docs/5.12.3
192 * @{
193 */
194
195/**
196 * Modify monitored items of a subscription.
197 *
198 * @param connection Instance of type Client
199 * @param request Modify monitored items request
200 */
202 Client& connection, const ModifyMonitoredItemsRequest& request
203) noexcept;
204
205/**
206 * Modify a monitored item of a subscription.
207 * @copydetails MonitoringParametersEx
208 *
209 * @param connection Instance of type Client
210 * @param subscriptionId Identifier of the subscription returned by @ref createSubscription
211 * @param monitoredItemId Identifier of the monitored item
212 * @param parameters Monitoring parameters, may be revised by server
213 */
215 Client& connection,
216 uint32_t subscriptionId,
217 uint32_t monitoredItemId,
218 MonitoringParametersEx& parameters
219) noexcept;
220
221/**
222 * @}
223 * @defgroup SetMonitoringMode SetMonitoringMode service
224 * Set the monitoring mode of a monitored items.
225 * @see https://reference.opcfoundation.org/Core/Part4/v105/docs/5.12.4
226 * @{
227 */
228
229/**
230 * Set the monitoring mode of monitored items.
231 *
232 * @param connection Instance of type Client
233 * @param request Set monitoring mode request
234 */
236 Client& connection, const SetMonitoringModeRequest& request
237) noexcept;
238
239/**
240 * Set the monitoring mode of a monitored item.
241 *
242 * @param connection Instance of type Client
243 * @param subscriptionId Identifier of the subscription returned by @ref createSubscription
244 * @param monitoredItemId Identifier of the monitored item
245 * @param monitoringMode Monitoring mode
246 */
248 Client& connection,
249 uint32_t subscriptionId,
250 uint32_t monitoredItemId,
251 MonitoringMode monitoringMode
252) noexcept;
253
254/**
255 * @}
256 * @defgroup SetTriggering SetTriggering service
257 * Create and delete triggering links for a triggering item.
258 * @see https://reference.opcfoundation.org/Core/Part4/v105/docs/5.12.1.6
259 * @see https://reference.opcfoundation.org/Core/Part4/v105/docs/5.12.5
260 * @{
261 */
262
263/**
264 * Add and delete triggering links of monitored items.
265 * The triggering item and the items to report shall belong to the same subscription.
266 * @note Supported since open62541 v1.2
267 *
268 * @param connection Instance of type Client
269 * @param request Set triggering request
270 */
272 Client& connection, const SetTriggeringRequest& request
273) noexcept;
274
275/**
276 * Add and delete triggering links of a monitored item.
277 * The triggering item and the items to report shall belong to the same subscription.
278 * @note Supported since open62541 v1.2
279 *
280 * @param connection Instance of type Client
281 * @param subscriptionId Identifier of the subscription returned by @ref createSubscription
282 * @param triggeringItemId Identifier of the triggering monitored item
283 * @param linksToAdd List of monitoring item identifiers to be added as triggering links
284 * @param linksToRemove List of monitoring item identifiers to be removed as triggering links
285 */
287 Client& connection,
288 uint32_t subscriptionId,
289 uint32_t triggeringItemId,
290 Span<const uint32_t> linksToAdd,
291 Span<const uint32_t> linksToRemove
292) noexcept;
293
294/**
295 * @}
296 * @defgroup DeleteMonitoredItems DeleteMonitoredItems service
297 * Delete a monitored items from subscriptions.
298 * @see https://reference.opcfoundation.org/Core/Part4/v105/docs/5.12.6
299 * @{
300 */
301
302/**
303 * Delete monitored items from subscriptions.
304 *
305 * @param connection Instance of type Client
306 * @param request Delete monitored items request
307 */
309 Client& connection, const DeleteMonitoredItemsRequest& request
310) noexcept;
311
312/**
313 * Delete a monitored item from a subscription.
314 *
315 * @param connection Instance of type Server or Client
316 * @param subscriptionId Identifier of the subscription returned by @ref createSubscription.
317 * Use `0U` for a local server-side monitored item.
318 * @param monitoredItemId Identifier of the monitored item
319 */
320template <typename T>
321Result<void> deleteMonitoredItem(T& connection, uint32_t subscriptionId, uint32_t monitoredItemId);
322
323/**
324 * @}
325 * @}
326 */
327
328} // namespace opcua::services
329
330#endif
High-level client class.
Definition client.hpp:63
UA_CreateMonitoredItemsRequest wrapper class.
UA_CreateMonitoredItemsResponse wrapper class.
UA_DataValue wrapper class.
Definition types.hpp:1478
UA_DeleteMonitoredItemsRequest wrapper class.
UA_DeleteMonitoredItemsResponse wrapper class.
UA_ExtensionObject wrapper class.
Definition types.hpp:1664
UA_ModifyMonitoredItemsRequest wrapper class.
UA_CreateMonitoredItemsResponse wrapper class.
UA_ReadValueId wrapper class.
The template class Result encapsulates a StatusCode and optionally a value.
Definition result.hpp:53
UA_SetMonitoringModeRequest wrapper class.
UA_SetMonitoringModeResponse wrapper class.
UA_SetTriggeringRequest wrapper class.
UA_SetTriggeringResponse wrapper class.
View to a contiguous sequence of objects, similar to std::span in C++20.
Definition span.hpp:26
std::function< void(uint32_t subId, uint32_t monId)> DeleteMonitoredItemCallback
MonitoredItem deletion callback.
CreateMonitoredItemsResponse createMonitoredItemsEvent(Client &connection, const CreateMonitoredItemsRequest &request, EventNotificationCallback eventCallback, DeleteMonitoredItemCallback deleteCallback={})
Create and add monitored items to a subscription for event notifications.
std::function< void(uint32_t subId, uint32_t monId, const DataValue &value)> DataChangeNotificationCallback
Data change notification callback.
Result< uint32_t > createMonitoredItemEvent(Client &connection, uint32_t subscriptionId, const ReadValueId &itemToMonitor, MonitoringMode monitoringMode, MonitoringParametersEx &parameters, EventNotificationCallback eventCallback, DeleteMonitoredItemCallback deleteCallback={})
Create and add a monitored item to a subscription for event notifications.
std::function< void(uint32_t subId, uint32_t monId, Span< const Variant > eventFields)> EventNotificationCallback
Event notification callback.
CreateMonitoredItemsResponse createMonitoredItemsDataChange(Client &connection, const CreateMonitoredItemsRequest &request, DataChangeNotificationCallback dataChangeCallback, DeleteMonitoredItemCallback deleteCallback={})
Create and add monitored items to a subscription for data change notifications.
Result< uint32_t > createMonitoredItemDataChange(T &connection, uint32_t subscriptionId, const ReadValueId &itemToMonitor, MonitoringMode monitoringMode, MonitoringParametersEx &parameters, DataChangeNotificationCallback dataChangeCallback, DeleteMonitoredItemCallback deleteCallback={})
Create and add a monitored item to a subscription for data change notifications.
Result< void > deleteMonitoredItem(T &connection, uint32_t subscriptionId, uint32_t monitoredItemId)
Delete a monitored item from a subscription.
DeleteMonitoredItemsResponse deleteMonitoredItems(Client &connection, const DeleteMonitoredItemsRequest &request) noexcept
Delete monitored items from subscriptions.
ModifyMonitoredItemsResponse modifyMonitoredItems(Client &connection, const ModifyMonitoredItemsRequest &request) noexcept
Modify monitored items of a subscription.
Result< void > modifyMonitoredItem(Client &connection, uint32_t subscriptionId, uint32_t monitoredItemId, 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.
SetTriggeringResponse setTriggering(Client &connection, const SetTriggeringRequest &request) noexcept
Add and delete triggering links of monitored items.
OPC UA services as free functions.
Definition attribute.hpp:21
TimestampsToReturn
Timestamps to return.
Definition common.hpp:287
MonitoringMode
Monitoring mode.
Definition common.hpp:302
Extended monitoring parameters with default values from open62541.
uint32_t queueSize
Size of the MonitoringItem queue.
TimestampsToReturn timestamps
Timestamps to be transmitted. Won't be revised by the server.
ExtensionObject filter
Filter is used by the server to determine if the MonitoredItem should generate notifications.
double samplingInterval
Interval in milliseconds that defines the fastest rate at which the MonitoredItem should be accessed ...
bool discardOldest
Discard policy when the queue is full.