open62541pp 0.19.0
C++ wrapper of open62541
Loading...
Searching...
No Matches
Classes | Public Member Functions | Friends | Related Symbols | List of all members
opcua::Client Class Reference

#include <client.hpp>

Detailed Description

High-level client class.

A client is usually created in two steps:

  1. Create and modify a client configuration (ClientConfig)
  2. Create a Client with a ClientConfig (move ownership to the Client instance)

Once a client is connected to an endpointUrl, it is not possible to switch to another server. A new client has to be created for that.

Use the handle() method to get access the underlying UA_Server instance and use the full power of open62541.

Don't overwrite the UA_ClientConfig::clientContext pointer! The context pointer is used to store a pointer to the Client instance (for asWrapper(UA_Client*)) and to get access to the underlying client context.

Examples
client_async.cpp, client_browse.cpp, client_connect.cpp, client_find_servers.cpp, client_minimal.cpp, client_subscription.cpp, custom_datatypes/client_custom_datatypes.cpp, events/client_eventfilter.cpp, method/client_method.cpp, and method/client_method_async.cpp.

Definition at line 130 of file client.hpp.

Public Member Functions

 Client ()
 
 Client (ClientConfig &&config)
 
 Client (UA_Client *native)
 
 ~Client ()
 
 Client (const Client &)=delete
 
 Client (Client &&other) noexcept
 
Clientoperator= (const Client &)=delete
 
Clientoperator= (Client &&other) noexcept
 
ClientConfigconfig () noexcept
 
const ClientConfigconfig () const noexcept
 
std::vector< ApplicationDescriptionfindServers (std::string_view serverUrl)
 
std::vector< EndpointDescriptiongetEndpoints (std::string_view serverUrl)
 
void setCustomDataTypes (Span< const DataType > dataTypes)
 
void onConnected (StateCallback callback)
 
void onDisconnected (StateCallback callback)
 
void onSessionActivated (StateCallback callback)
 
void onSessionClosed (StateCallback callback)
 
void onInactive (InactivityCallback callback)
 
void onSubscriptionInactive (SubscriptionInactivityCallback callback)
 
void connect (std::string_view endpointUrl)
 
void connectAsync (std::string_view endpointUrl)
 
void disconnect ()
 
void disconnectAsync ()
 
bool isConnected () noexcept
 
std::vector< StringnamespaceArray ()
 
Subscription< ClientcreateSubscription (const SubscriptionParameters &parameters={})
 
std::vector< Subscription< Client > > subscriptions ()
 
void runIterate (uint16_t timeoutMilliseconds=1000)
 
void run ()
 
void stop ()
 
bool isRunning () const noexcept
 
UA_Clienthandle () noexcept
 
const UA_Clienthandle () const noexcept
 

Friends

detail::ClientContext & detail::getContext (Client &client) noexcept
 

Related Symbols

(Note that these are not member symbols.)

ClientasWrapper (UA_Client *client) noexcept
 
bool operator== (const Client &lhs, const Client &rhs) noexcept
 
bool operator!= (const Client &lhs, const Client &rhs) noexcept
 

Constructor & Destructor Documentation

◆ Client() [1/5]

opcua::Client::Client ( )

Create client with default configuration.

◆ Client() [2/5]

opcua::Client::Client ( ClientConfig &&  config)
explicit

Create client with given configuration (move ownership to client).

◆ Client() [3/5]

opcua::Client::Client ( UA_Client native)
explicit

Create client from native instance (move ownership to client).

◆ ~Client()

opcua::Client::~Client ( )

◆ Client() [4/5]

opcua::Client::Client ( const Client )
delete

◆ Client() [5/5]

opcua::Client::Client ( Client &&  other)
noexcept

Member Function Documentation

◆ config() [1/2]

const ClientConfig & opcua::Client::config ( ) const
noexcept

◆ config() [2/2]

ClientConfig & opcua::Client::config ( )
noexcept

◆ connect()

void opcua::Client::connect ( std::string_view  endpointUrl)

Connect to the selected server.

The session authentification method is defined by the UserIdentityToken and is set with Client::setUserIdentityToken.

Parameters
endpointUrlEndpoint URL (for example opc.tcp://localhost:4840/open62541/server/)
Examples
client_browse.cpp, client_connect.cpp, client_minimal.cpp, client_subscription.cpp, custom_datatypes/client_custom_datatypes.cpp, events/client_eventfilter.cpp, method/client_method.cpp, and method/client_method_async.cpp.

◆ connectAsync()

void opcua::Client::connectAsync ( std::string_view  endpointUrl)

Asynchronously connect to the selected server.

Set a state callback, e.g. onConnected, to be notified when the connection status changes.

The session authentification method is defined by the UserIdentityToken and is set with Client::setUserIdentityToken.

Parameters
endpointUrlEndpoint URL (for example opc.tcp://localhost:4840/open62541/server/)
Examples
client_async.cpp.

◆ createSubscription()

Subscription< Client > opcua::Client::createSubscription ( const SubscriptionParameters parameters = {})

Create a subscription to monitor data changes and events.

Deprecated:
Use Subscription constructor

◆ disconnect()

void opcua::Client::disconnect ( )

Disconnect and close the connection to the server.

Examples
client_connect.cpp, and client_subscription.cpp.

◆ disconnectAsync()

void opcua::Client::disconnectAsync ( )

Asynchronously disconnect and close the connection to the server.

Set a state callback, e.g. onDisconnected, to be notified when the connection status changes.

◆ findServers()

std::vector< ApplicationDescription > opcua::Client::findServers ( std::string_view  serverUrl)

Gets a list of all registered servers at the given server.

Parameters
serverUrlServer URL (for example opc.tcp://localhost:4840)
Note
Client must be disconnected.
Examples
client_find_servers.cpp.

◆ getEndpoints()

std::vector< EndpointDescription > opcua::Client::getEndpoints ( std::string_view  serverUrl)

Gets a list of endpoints of a server.

Parameters
serverUrlServer URL (for example opc.tcp://localhost:4840)
Note
Client must be disconnected.

◆ handle() [1/2]

const UA_Client * opcua::Client::handle ( ) const
noexcept

◆ handle() [2/2]

UA_Client * opcua::Client::handle ( )
noexcept

◆ isConnected()

bool opcua::Client::isConnected ( )
noexcept

Check if client is connected (secure channel open).

◆ isRunning()

bool opcua::Client::isRunning ( ) const
noexcept

Check if the client's main loop is running.

◆ namespaceArray()

std::vector< String > opcua::Client::namespaceArray ( )

Get all defined namespaces.

◆ onConnected()

void opcua::Client::onConnected ( StateCallback  callback)

Set a state callback that will be called after the client is connected.

Examples
client_async.cpp.

◆ onDisconnected()

void opcua::Client::onDisconnected ( StateCallback  callback)

Set a state callback that will be called after the client is disconnected.

Examples
client_async.cpp.

◆ onInactive()

void opcua::Client::onInactive ( InactivityCallback  callback)

Set an inactivity callback.

Every UA_ClientConfig::connectivityCheckInterval (in ms), an async read request is performed on the server. The callback is called when the client receives no response for this request.

◆ onSessionActivated()

void opcua::Client::onSessionActivated ( StateCallback  callback)

Set a state callback that will be called after the session is activated.

Examples
client_async.cpp, and client_subscription.cpp.

◆ onSessionClosed()

void opcua::Client::onSessionClosed ( StateCallback  callback)

Set a state callback that will be called after the session is closed.

Examples
client_async.cpp.

◆ onSubscriptionInactive()

void opcua::Client::onSubscriptionInactive ( SubscriptionInactivityCallback  callback)

Set a subscription inactivity callback.

The callback is called when the client does not receive a publish response after the defined delay of (publishingInterval * maxKeepAliveCount) + UA_ClientConfig::timeout).

◆ operator=() [1/2]

Client & opcua::Client::operator= ( Client &&  other)
noexcept

◆ operator=() [2/2]

Client & opcua::Client::operator= ( const Client )
delete

◆ run()

void opcua::Client::run ( )

Run the client's main loop by. This method will block until Client::stop is called.

Examples
client_async.cpp, client_subscription.cpp, events/client_eventfilter.cpp, and method/client_method_async.cpp.

◆ runIterate()

void opcua::Client::runIterate ( uint16_t  timeoutMilliseconds = 1000)

Run a single iteration of the client's main loop.

Listen on the network and process arriving asynchronous responses in the background. Internal housekeeping, renewal of SecureChannels and subscription management is done as well.

Parameters
timeoutMillisecondsTimeout in milliseconds

◆ setCustomDataTypes()

void opcua::Client::setCustomDataTypes ( Span< const DataType dataTypes)
inline

Definition at line 165 of file client.hpp.

◆ stop()

void opcua::Client::stop ( )

Stop the client's main loop.

◆ subscriptions()

std::vector< Subscription< Client > > opcua::Client::subscriptions ( )

Get all active subscriptions.

Friends And Related Symbol Documentation

◆ asWrapper()

Client * asWrapper ( UA_Client client)
related

Convert native UA_Client pointer to its wrapper instance.

The native client must be owned by a Client instance.

◆ detail::getContext

detail::ClientContext & detail::getContext ( Client client)
friend

◆ operator!=()

bool operator!= ( const Client lhs,
const Client rhs 
)
related

Definition at line 270 of file client.hpp.

◆ operator==()

bool operator== ( const Client lhs,
const Client rhs 
)
related

Definition at line 265 of file client.hpp.