open62541pp 0.16.0
C++ wrapper of open62541
Loading...
Searching...
No Matches
opcua::Server Class Reference

#include <server.hpp>

Detailed Description

High-level server class.

A server is usually created in two steps:

  1. Create and modify a server configuration (ServerConfig)
  2. Create a Server with a ServerConfig (move ownership to the Server instance)

The server expects that the configuration is not modified during runtime.

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

Don't overwrite the UA_ServerConfig::context pointer! The context pointer is used to store a pointer to the Server instance (for asWrapper(UA_Server*)) and to get access to the underlying server context.

Examples
custom_datatypes/server_custom_datatypes.cpp, events/server_events.cpp, method/server_method.cpp, server.cpp, server_accesscontrol.cpp, server_datasource.cpp, server_instantiation.cpp, server_logger.cpp, server_minimal.cpp, and server_valuecallback.cpp.

Definition at line 132 of file server.hpp.

Public Member Functions

 Server ()
 
 Server (ServerConfig &&config)
 
 Server (uint16_t port, const ByteString &certificate={})
 
 Server (uint16_t port, const ByteString &certificate, const ByteString &privateKey, Span< const ByteString > trustList, Span< const ByteString > issuerList, Span< const ByteString > revocationList={})
 
 ~Server ()
 
 Server (const Server &)=delete
 
 Server (Server &&other) noexcept
 
Serveroperator= (const Server &)=delete
 
Serveroperator= (Server &&other) noexcept
 
ServerConfigconfig () noexcept
 
const ServerConfigconfig () const noexcept
 
void setLogger (LogFunction logger)
 
void setApplicationUri (std::string_view uri)
 
void setProductUri (std::string_view uri)
 
void setApplicationName (std::string_view name)
 
void setCustomHostname (std::string_view hostname)
 
void setAccessControl (AccessControlBase &accessControl)
 
void setAccessControl (std::unique_ptr< AccessControlBase > &&accessControl)
 
void setCustomDataTypes (Span< const DataType > dataTypes)
 
std::vector< SessiongetSessions ()
 
std::vector< std::string > getNamespaceArray ()
 
NamespaceIndex registerNamespace (std::string_view uri)
 
void setVariableNodeValueCallback (const NodeId &id, ValueCallback callback)
 
void setVariableNodeValueBackend (const NodeId &id, ValueBackendDataSource backend)
 
Subscription< ServercreateSubscription () noexcept
 
Event createEvent (const NodeId &eventType=ObjectTypeId::BaseEventType)
 
uint16_t runIterate ()
 
void run ()
 
void stop ()
 
bool isRunning () const noexcept
 
Node< ServergetNode (NodeId id)
 
Node< ServergetRootNode ()
 
Node< ServergetObjectsNode ()
 
Node< ServergetTypesNode ()
 
Node< ServergetViewsNode ()
 
UA_Serverhandle () noexcept
 
const UA_Serverhandle () const noexcept
 

Friends

detail::ServerContextdetail::getContext (Server &server) noexcept
 

Constructor & Destructor Documentation

◆ Server() [1/6]

opcua::Server::Server ( )

Create server with default configuration.

◆ Server() [2/6]

opcua::Server::Server ( ServerConfig && config)
explicit

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

◆ Server() [3/6]

opcua::Server::Server ( uint16_t port,
const ByteString & certificate = {} )
inlineexplicit

Create server config with minimal configuration.

Security policies:

Parameters
portPort number
certificateOptional X.509 v3 certificate in DER encoded format

Definition at line 142 of file server.hpp.

◆ Server() [4/6]

opcua::Server::Server ( uint16_t port,
const ByteString & certificate,
const ByteString & privateKey,
Span< const ByteString > trustList,
Span< const ByteString > issuerList,
Span< const ByteString > revocationList = {} )
inline

Create server config with encryption enabled (PKI).

Security policies:

Parameters
portPort number
certificateX.509 v3 certificate in DER encoded format
privateKeyPrivate key in PEM encoded format
trustListList of trusted certificates in DER encoded format
issuerListList of issuer certificates (i.e. CAs) 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/Part4/v105/docs/6.1
https://reference.opcfoundation.org/Core/Part6/v105/docs/6.2

Definition at line 155 of file server.hpp.

◆ ~Server()

opcua::Server::~Server ( )

◆ Server() [5/6]

opcua::Server::Server ( const Server & )
delete

◆ Server() [6/6]

opcua::Server::Server ( Server && other)
noexcept

Member Function Documentation

◆ operator=() [1/2]

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

◆ operator=() [2/2]

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

◆ config() [1/2]

◆ config() [2/2]

const ServerConfig & opcua::Server::config ( ) const
noexcept

◆ setLogger()

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

Definition at line 178 of file server.hpp.

◆ setApplicationUri()

void opcua::Server::setApplicationUri ( std::string_view uri)
inline

Definition at line 183 of file server.hpp.

◆ setProductUri()

void opcua::Server::setProductUri ( std::string_view uri)
inline

Definition at line 188 of file server.hpp.

◆ setApplicationName()

void opcua::Server::setApplicationName ( std::string_view name)
inline

Definition at line 193 of file server.hpp.

◆ setCustomHostname()

void opcua::Server::setCustomHostname ( std::string_view hostname)

Set custom hostname, default: system's host name.

◆ setAccessControl() [1/2]

void opcua::Server::setAccessControl ( AccessControlBase & accessControl)
inline

Definition at line 202 of file server.hpp.

◆ setAccessControl() [2/2]

void opcua::Server::setAccessControl ( std::unique_ptr< AccessControlBase > && accessControl)
inline

Definition at line 207 of file server.hpp.

◆ setCustomDataTypes()

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

Set custom data types.

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

Examples
custom_datatypes/server_custom_datatypes.cpp.

◆ getSessions()

std::vector< Session > opcua::Server::getSessions ( )

Get active server session.

◆ getNamespaceArray()

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

Get all defined namespaces.

◆ registerNamespace()

NamespaceIndex opcua::Server::registerNamespace ( std::string_view uri)
nodiscard

Register namespace. The new namespace index will be returned.

◆ setVariableNodeValueCallback()

void opcua::Server::setVariableNodeValueCallback ( const NodeId & id,
ValueCallback callback )

Set value callbacks to execute before every read and after every write operation.

Examples
server_valuecallback.cpp.

◆ setVariableNodeValueBackend()

void opcua::Server::setVariableNodeValueBackend ( const NodeId & id,
ValueBackendDataSource backend )

Set data source backend for variable node.

Examples
server_datasource.cpp.

◆ createSubscription()

Subscription< Server > opcua::Server::createSubscription ( )
noexcept

Create a (pseudo) subscription to monitor local data changes and events.

◆ createEvent()

Event opcua::Server::createEvent ( const NodeId & eventType = ObjectTypeId::BaseEventType)

Create an event object to generate and trigger events.

◆ runIterate()

uint16_t opcua::Server::runIterate ( )

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

Returns
Maximum wait period until next Server::runIterate call (in ms)

◆ run()

◆ stop()

void opcua::Server::stop ( )

Stop the server's main loop.

◆ isRunning()

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

Check if the server is running.

◆ getNode()

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

◆ getRootNode()

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

◆ getObjectsNode()

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

◆ getTypesNode()

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

◆ getViewsNode()

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

◆ handle() [1/2]

UA_Server * opcua::Server::handle ( )
noexcept

◆ handle() [2/2]

const UA_Server * opcua::Server::handle ( ) const
noexcept

Friends And Related Symbol Documentation

◆ detail::getContext