open62541pp 0.16.0
C++ wrapper of open62541
|
#include <client.hpp>
High-level client class.
A client is usually created in two steps:
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.
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 | |
Client & | operator= (const Client &)=delete |
Client & | operator= (Client &&other) noexcept |
ClientConfig & | config () noexcept |
const ClientConfig & | config () const noexcept |
std::vector< ApplicationDescription > | findServers (std::string_view serverUrl) |
std::vector< EndpointDescription > | getEndpoints (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< Client > | createSubscription (const SubscriptionParameters ¶meters={}) |
std::vector< Subscription< Client > > | getSubscriptions () |
void | runIterate (uint16_t timeoutMilliseconds=1000) |
void | run () |
void | stop () |
bool | isRunning () const noexcept |
Node< Client > | getNode (NodeId id) |
Node< Client > | getRootNode () |
Node< Client > | getObjectsNode () |
Node< Client > | getTypesNode () |
Node< Client > | getViewsNode () |
UA_Client * | handle () noexcept |
const UA_Client * | handle () const noexcept |
Friends | |
detail::ClientContext & | detail::getContext (Client &client) noexcept |
opcua::Client::Client | ( | ) |
Create client with default configuration.
|
explicit |
Create client with given configuration (move ownership to client).
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:
certificate | X.509 v3 certificate in DER encoded format |
privateKey | Private key in PEM encoded format |
trustList | List of trusted certificates in DER encoded format |
revocationList | Certificate revocation lists (CRL) in DER encoded format |
opcua::Client::~Client | ( | ) |
|
delete |
|
noexcept |
|
noexcept |
Referenced by setLogger(), setSecurityMode(), setTimeout(), and setUserIdentityToken().
|
noexcept |
std::vector< ApplicationDescription > opcua::Client::findServers | ( | std::string_view | serverUrl | ) |
Gets a list of all registered servers at the given server.
serverUrl | Server URL (for example opc.tcp://localhost:4840 ) |
std::vector< EndpointDescription > opcua::Client::getEndpoints | ( | std::string_view | serverUrl | ) |
|
inline |
Definition at line 166 of file client.hpp.
|
inlinenoexcept |
Definition at line 171 of file client.hpp.
|
inline |
Definition at line 177 of file client.hpp.
|
inlinenoexcept |
Definition at line 182 of file client.hpp.
Set custom data types.
All data types provided are automatically considered for decoding of received messages.
void opcua::Client::onConnected | ( | StateCallback | callback | ) |
Set a state callback that will be called after the client is connected.
void opcua::Client::onDisconnected | ( | StateCallback | callback | ) |
Set a state callback that will be called after the client is disconnected.
void opcua::Client::onSessionActivated | ( | StateCallback | callback | ) |
Set a state callback that will be called after the session is activated.
void opcua::Client::onSessionClosed | ( | StateCallback | callback | ) |
Set a state callback that will be called after the session is closed.
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.
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.
endpointUrl | Endpoint URL (for example opc.tcp://localhost:4840/open62541/server/ ) |
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.
endpointUrl | Endpoint URL (for example opc.tcp://localhost:4840/open62541/server/ ) |
void opcua::Client::connect | ( | std::string_view | endpointUrl, |
const Login & | login ) |
Connect to the selected server with the given username and password.
endpointUrl | Endpoint URL (for example opc.tcp://localhost:4840/open62541/server/ ) |
login | Login credentials with username and password |
void opcua::Client::disconnect | ( | ) |
Disconnect and close the connection to the server.
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.
|
noexcept |
Check if client is connected (secure channel open).
std::vector< std::string > opcua::Client::getNamespaceArray | ( | ) |
Get all defined namespaces.
Subscription< Client > opcua::Client::createSubscription | ( | const SubscriptionParameters & | parameters = {} | ) |
Create a subscription to monitor data changes and events.
std::vector< Subscription< Client > > opcua::Client::getSubscriptions | ( | ) |
Get all active subscriptions.
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.
timeoutMilliseconds | Timeout in milliseconds |
void opcua::Client::run | ( | ) |
Run the client's main loop by. This method will block until Client::stop is called.
void opcua::Client::stop | ( | ) |
Stop the client's main loop.
|
noexcept |
Check if the client's main loop is running.
|
noexcept |
|
noexcept |
|
friend |