open62541++ 0.13.0
C++ wrapper of open62541
Loading...
Searching...
No Matches
Public Member Functions | Friends | List of all members
opcua::Client Class Reference

#include <Client.h>

Detailed Description

High-level client class.

Exposes the most common functionality. Use the handle() method to get access the underlying UA_Client instance and use the full power of open6254.

Examples
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 60 of file Client.h.

Public Member Functions

 Client (Logger logger=nullptr)
 
 Client (const ByteString &certificate, const ByteString &privateKey, Span< const ByteString > trustList, Span< const ByteString > revocationList={})
 
 ~Client ()
 
 Client (const Client &)=delete
 
 Client (Client &&) noexcept=default
 
Clientoperator= (const Client &)=delete
 
Clientoperator= (Client &&) noexcept=default
 
std::vector< ApplicationDescriptionfindServers (std::string_view serverUrl)
 
std::vector< EndpointDescriptiongetEndpoints (std::string_view serverUrl)
 
void setLogger (Logger logger)
 
void setTimeout (uint32_t milliseconds)
 
void setSecurityMode (MessageSecurityMode mode)
 
void setCustomDataTypes (std::vector< DataType > dataTypes)
 
void onConnected (StateCallback callback)
 
void onDisconnected (StateCallback callback)
 
void onSessionActivated (StateCallback callback)
 
void onSessionClosed (StateCallback callback)
 
void connect (std::string_view endpointUrl)
 
void connect (std::string_view endpointUrl, const Login &login)
 
void disconnect () noexcept
 
bool isConnected () noexcept
 
std::vector< std::string > getNamespaceArray ()
 
Subscription< ClientcreateSubscription ()
 
Subscription< ClientcreateSubscription (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::ClientConnection & detail::getConnection (Client &client) noexcept
 

Constructor & Destructor Documentation

◆ Client() [1/4]

opcua::Client::Client ( Logger logger = nullptr)
explicit

Create client with default configuration (no encryption).

Security policies:

  • None
    Parameters
    loggerCustom log function. If the passed function is empty, the default logger is used.

◆ Client() [2/4]

opcua::Client::Client ( const ByteString & certificate,
const ByteString & privateKey,
Span< const ByteString > trustList,
Span< const ByteString > revocationList = {} )

Create client 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() [3/4]

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

◆ Client() [4/4]

opcua::Client::Client ( Client && )
defaultnoexcept

Member Function Documentation

◆ operator=() [1/2]

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

◆ operator=() [2/2]

Client & opcua::Client::operator= ( Client && )
defaultnoexcept

◆ 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 ( Logger logger)

Set custom logging function.

Does nothing if the passed function is empty or a nullptr.

Examples
client_find_servers.cpp.

◆ setTimeout()

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

Set response timeout in milliseconds.

◆ setSecurityMode()

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

Set message security mode.

◆ setCustomDataTypes()

void opcua::Client::setCustomDataTypes ( std::vector< 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.

◆ onDisconnected()

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

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

◆ onSessionActivated()

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

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

Examples
client_subscription.cpp.

◆ onSessionClosed()

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

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

◆ connect() [1/2]

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

Connect to the selected server.

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.

◆ 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 ( )
noexcept

Disconnect and close a connection to the server (async, without blocking).

Examples
client_connect.cpp, and client_subscription.cpp.

◆ 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() [1/2]

Subscription< Client > opcua::Client::createSubscription ( )

Create a subscription to monitor data changes and events (default subscription parameters).

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

◆ createSubscription() [2/2]

Subscription< Client > opcua::Client::createSubscription ( SubscriptionParameters & parameters)

Create a subscription to monitor data changes and events.

◆ 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_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::getConnection

detail::ClientConnection & detail::getConnection ( Client & client)
friend