open62541pp 0.16.0
C++ wrapper of open62541
Loading...
Searching...
No Matches
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 121 of file client.hpp.

Public Member Functions

 Client ()
 
 Client (ClientConfig &&config)
 
 Client (const ByteString &certificate, const ByteString &privateKey, Span< const ByteString > trustList, Span< const ByteString > revocationList={})
 
 ~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 setLogger (LogFunction logger)
 
void setTimeout (uint32_t milliseconds) noexcept
 
template<typename Token >
void setUserIdentityToken (const Token &token)
 
void setSecurityMode (MessageSecurityMode mode) noexcept
 
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 connect (std::string_view endpointUrl)
 
void connectAsync (std::string_view endpointUrl)
 
void connect (std::string_view endpointUrl, const Login &login)
 
void disconnect ()
 
void disconnectAsync ()
 
bool isConnected () noexcept
 
std::vector< std::string > getNamespaceArray ()
 
Subscription< ClientcreateSubscription (const SubscriptionParameters &parameters={})
 
std::vector< Subscription< Client > > getSubscriptions ()
 
void runIterate (uint16_t timeoutMilliseconds=1000)
 
void run ()
 
void stop ()
 
bool isRunning () const noexcept
 
Node< ClientgetNode (NodeId id)
 
Node< ClientgetRootNode ()
 
Node< ClientgetObjectsNode ()
 
Node< ClientgetTypesNode ()
 
Node< ClientgetViewsNode ()
 
UA_Clienthandle () noexcept
 
const UA_Clienthandle () const noexcept
 

Friends

detail::ClientContextdetail::getContext (Client &client) 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 ( const ByteString & certificate,
const ByteString & privateKey,
Span< const ByteString > trustList,
Span< const ByteString > revocationList = {} )

Create client config with encryption enabled (PKI).

Security policies:

Parameters
certificateX.509 v3 certificate in DER encoded format
privateKeyPrivate key in PEM encoded format
trustListList of trusted certificates in DER encoded format
revocationListCertificate revocation lists (CRL) in DER encoded format
See also
https://reference.opcfoundation.org/Core/Part2/v105/docs/8
https://reference.opcfoundation.org/Core/Part6/v105/docs/6.2

◆ ~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

◆ operator=() [1/2]

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

◆ operator=() [2/2]

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

◆ config() [1/2]

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

◆ config() [2/2]

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

◆ 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.

◆ setLogger()

void opcua::Client::setLogger ( LogFunction logger)
inline

Definition at line 166 of file client.hpp.

◆ setTimeout()

void opcua::Client::setTimeout ( uint32_t milliseconds)
inlinenoexcept

Definition at line 171 of file client.hpp.

◆ setUserIdentityToken()

template<typename Token >
void opcua::Client::setUserIdentityToken ( const Token & token)
inline

Definition at line 177 of file client.hpp.

◆ setSecurityMode()

void opcua::Client::setSecurityMode ( MessageSecurityMode mode)
inlinenoexcept

Definition at line 182 of file client.hpp.

◆ setCustomDataTypes()

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

Set custom data types.

All data types provided are automatically considered for decoding of received messages.

Examples
custom_datatypes/client_custom_datatypes.cpp.

◆ 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.

◆ 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.

◆ 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.

◆ connect() [1/2]

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.

◆ connect() [2/2]

void opcua::Client::connect ( std::string_view endpointUrl,
const Login & login )

Connect to the selected server with the given username and password.

Parameters
endpointUrlEndpoint URL (for example opc.tcp://localhost:4840/open62541/server/)
loginLogin credentials with username and password

◆ 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.

◆ isConnected()

bool opcua::Client::isConnected ( )
noexcept

Check if client is connected (secure channel open).

◆ getNamespaceArray()

std::vector< std::string > opcua::Client::getNamespaceArray ( )

Get all defined namespaces.

◆ createSubscription()

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

Create a subscription to monitor data changes and events.

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

◆ getSubscriptions()

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

Get all active subscriptions.

◆ 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

◆ 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.

◆ stop()

void opcua::Client::stop ( )

Stop the client's main loop.

Examples
method/client_method_async.cpp.

◆ isRunning()

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

Check if the client's main loop is running.

◆ getNode()

Node< Client > opcua::Client::getNode ( NodeId id)

◆ getRootNode()

Node< Client > opcua::Client::getRootNode ( )

◆ getObjectsNode()

Node< Client > opcua::Client::getObjectsNode ( )

◆ getTypesNode()

Node< Client > opcua::Client::getTypesNode ( )

◆ getViewsNode()

Node< Client > opcua::Client::getViewsNode ( )

◆ handle() [1/2]

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

◆ handle() [2/2]

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

Friends And Related Symbol Documentation

◆ detail::getContext