open62541pp 0.17.0
C++ wrapper of open62541
Loading...
Searching...
No Matches
opcua::Subscription< Connection > Class Template Reference

#include <subscription.hpp>

Detailed Description

template<typename Connection>
class opcua::Subscription< Connection >

High-level subscription class.

The API is symmetric for both Server and Client, although servers don't use the subscription mechanism of OPC UA to transport notifications of data changes and events. Instead MonitoredItems are registered locally. Notifications are then forwarded to user-defined callbacks instead of a remote client. The subscriptionId for servers is always 0U.

Template Parameters
ConnectionServer or Client
Note
Not all methods are available and implemented for servers.

Use the free functions in the opcua::services namespace for more advanced usage:

Examples
client_subscription.cpp, and events/client_eventfilter.cpp.

Definition at line 42 of file subscription.hpp.

Public Member Functions

 Subscription (Connection &connection, const SubscriptionParameters &parameters={})
 
 Subscription (Connection &connection, IntegerId subscriptionId) noexcept
 
Connection & connection () noexcept
 
const Connection & connection () const noexcept
 
IntegerId subscriptionId () const noexcept
 
std::vector< MonitoredItem< Connection > > monitoredItems ()
 
std::vector< MonitoredItem< Connection > > getMonitoredItems ()
 
void setSubscriptionParameters (const SubscriptionParameters &parameters)
 
void setPublishingMode (bool publishing)
 
MonitoredItem< Connection > subscribeDataChange (const NodeId &id, AttributeId attribute, MonitoringMode monitoringMode, const MonitoringParametersEx &parameters, DataChangeNotificationCallback onDataChange)
 
MonitoredItem< Connection > subscribeDataChange (const NodeId &id, AttributeId attribute, DataChangeNotificationCallback onDataChange)
 
MonitoredItem< Connection > subscribeEvent (const NodeId &id, MonitoringMode monitoringMode, const MonitoringParametersEx &parameters, EventNotificationCallback onEvent)
 
MonitoredItem< Connection > subscribeEvent (const NodeId &id, const EventFilter &eventFilter, EventNotificationCallback onEvent)
 
void deleteSubscription ()
 

Related Symbols

(Note that these are not member symbols.)

template<typename T >
bool operator== (const Subscription< T > &lhs, const Subscription< T > &rhs) noexcept
 
template<typename T >
bool operator!= (const Subscription< T > &lhs, const Subscription< T > &rhs) noexcept
 

Constructor & Destructor Documentation

◆ Subscription() [1/2]

template<typename Connection >
opcua::Subscription< Connection >::Subscription ( Connection & connection,
const SubscriptionParameters & parameters = {} )
explicit

Create a new subscription.

The subscription is not automatically deleted by the destructor. You must delete it manually with deleteSubscription or services::deleteSubscription.

◆ Subscription() [2/2]

template<typename Connection >
opcua::Subscription< Connection >::Subscription ( Connection & connection,
IntegerId subscriptionId )
inlinenoexcept

Wrap an existing subscription.

The subscriptionId is ignored and set to 0U for servers.

Definition at line 51 of file subscription.hpp.

Member Function Documentation

◆ connection() [1/2]

◆ connection() [2/2]

template<typename Connection >
const Connection & opcua::Subscription< Connection >::connection ( ) const
inlinenoexcept

Get the server/client instance.

Definition at line 61 of file subscription.hpp.

◆ subscriptionId()

◆ monitoredItems()

template<typename Connection >
std::vector< MonitoredItem< Connection > > opcua::Subscription< Connection >::monitoredItems ( )

Get all local monitored items.

Referenced by opcua::Subscription< Connection >::getMonitoredItems().

◆ getMonitoredItems()

template<typename Connection >
std::vector< MonitoredItem< Connection > > opcua::Subscription< Connection >::getMonitoredItems ( )
inline
Deprecated
Use monitoredItems() instead

Definition at line 75 of file subscription.hpp.

◆ setSubscriptionParameters()

template<typename Connection >
void opcua::Subscription< Connection >::setSubscriptionParameters ( const SubscriptionParameters & parameters)
inline

Modify this subscription.

Note
Not implemented for Server.
See also
services::modifySubscription
Examples
client_subscription.cpp.

Definition at line 82 of file subscription.hpp.

◆ setPublishingMode()

template<typename Connection >
void opcua::Subscription< Connection >::setPublishingMode ( bool publishing)
inline

Enable/disable publishing of notification messages.

Note
Not implemented for Server.
See also
services::setPublishingMode
Examples
client_subscription.cpp.

Definition at line 92 of file subscription.hpp.

◆ subscribeDataChange() [1/2]

template<typename Connection >
MonitoredItem< Connection > opcua::Subscription< Connection >::subscribeDataChange ( const NodeId & id,
AttributeId attribute,
MonitoringMode monitoringMode,
const MonitoringParametersEx & parameters,
DataChangeNotificationCallback onDataChange )
inline

Create a monitored item for data change notifications.

Examples
client_subscription.cpp.

Definition at line 97 of file subscription.hpp.

Referenced by opcua::Subscription< Connection >::subscribeDataChange().

◆ subscribeDataChange() [2/2]

template<typename Connection >
MonitoredItem< Connection > opcua::Subscription< Connection >::subscribeDataChange ( const NodeId & id,
AttributeId attribute,
DataChangeNotificationCallback onDataChange )
inline

Create a monitored item for data change notifications (default settings).

The monitoring mode is set to MonitoringMode::Reporting and the default open62541 MonitoringParametersEx are used.

Definition at line 120 of file subscription.hpp.

◆ subscribeEvent() [1/2]

template<typename Connection >
MonitoredItem< Connection > opcua::Subscription< Connection >::subscribeEvent ( const NodeId & id,
MonitoringMode monitoringMode,
const MonitoringParametersEx & parameters,
EventNotificationCallback onEvent )
inline

Create a monitored item for event notifications.

Note
Not implemented for Server.

Definition at line 131 of file subscription.hpp.

Referenced by opcua::Subscription< Connection >::subscribeEvent().

◆ subscribeEvent() [2/2]

template<typename Connection >
MonitoredItem< Connection > opcua::Subscription< Connection >::subscribeEvent ( const NodeId & id,
const EventFilter & eventFilter,
EventNotificationCallback onEvent )
inline

Create a monitored item for event notifications (default settings).

The monitoring mode is set to MonitoringMode::Reporting and the default open62541 MonitoringParametersEx are used.

Note
Not implemented for Server.

Definition at line 153 of file subscription.hpp.

◆ deleteSubscription()

template<typename Connection >
void opcua::Subscription< Connection >::deleteSubscription ( )
inline

Delete this subscription.

Note
Not implemented for Server.

Definition at line 163 of file subscription.hpp.

Friends And Related Symbol Documentation

◆ operator==()

template<typename T >
bool operator== ( const Subscription< T > & lhs,
const Subscription< T > & rhs )
related

Definition at line 176 of file subscription.hpp.

◆ operator!=()

template<typename T >
bool operator!= ( const Subscription< T > & lhs,
const Subscription< T > & rhs )
related

Definition at line 182 of file subscription.hpp.