open62541pp 0.18.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 126 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 (UA_Client *native) | |
~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 | onSubscriptionInactive (SubscriptionInactivityCallback 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 > | namespaceArray () |
std::vector< std::string > | getNamespaceArray () |
Subscription< Client > | createSubscription (const SubscriptionParameters ¶meters={}) |
std::vector< Subscription< Client > > | subscriptions () |
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 |
Related Symbols | |
(Note that these are not member symbols.) | |
Client * | asWrapper (UA_Client *client) noexcept |
bool | operator== (const Client &lhs, const Client &rhs) noexcept |
bool | operator!= (const Client &lhs, const Client &rhs) 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 |
|
explicit |
Create client from native instance (move ownership to client).
opcua::Client::~Client | ( | ) |
|
delete |
|
noexcept |
|
noexcept |
Referenced by setCustomDataTypes(), 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 174 of file client.hpp.
|
inlinenoexcept |
Definition at line 179 of file client.hpp.
|
inline |
Definition at line 185 of file client.hpp.
|
inlinenoexcept |
Definition at line 190 of file client.hpp.
Definition at line 195 of file client.hpp.
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::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)
.
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::namespaceArray | ( | ) |
Get all defined namespaces.
Referenced by getNamespaceArray().
|
inline |
Definition at line 258 of file client.hpp.
Subscription< Client > opcua::Client::createSubscription | ( | const SubscriptionParameters & | parameters = {} | ) |
Create a subscription to monitor data changes and events.
std::vector< Subscription< Client > > opcua::Client::subscriptions | ( | ) |
Get all active subscriptions.
Referenced by getSubscriptions().
|
inline |
Definition at line 273 of file client.hpp.
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 |
Definition at line 321 of file client.hpp.
Definition at line 326 of file client.hpp.