open62541pp 0.18.0
C++ wrapper of open62541
Loading...
Searching...
No Matches
Classes | Public Member Functions | Friends | Related Symbols | List of all members
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 136 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 (UA_Server *native)
 
 ~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< Sessionsessions ()
 
std::vector< SessiongetSessions ()
 
std::vector< std::string > namespaceArray ()
 
std::vector< std::string > getNamespaceArray ()
 
NamespaceIndex registerNamespace (std::string_view uri)
 
void setVariableNodeValueCallback (const NodeId &id, ValueCallbackBase &callback)
 
void setVariableNodeValueCallback (const NodeId &id, std::unique_ptr< ValueCallbackBase > &&callback)
 
void setVariableNodeDataSource (const NodeId &id, DataSourceBase &source)
 
void setVariableNodeDataSource (const NodeId &id, std::unique_ptr< DataSourceBase > &&source)
 
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::ServerContext & detail::getContext (Server &server) noexcept
 

Related Symbols

(Note that these are not member symbols.)

ServerasWrapper (UA_Server *server) noexcept
 
bool operator== (const Server &lhs, const Server &rhs) noexcept
 
bool operator!= (const Server &lhs, const Server &rhs) noexcept
 

Constructor & Destructor Documentation

◆ Server() [1/7]

opcua::Server::Server ( )

Create server with default configuration.

◆ Server() [2/7]

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

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

◆ Server() [3/7]

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 146 of file server.hpp.

◆ Server() [4/7]

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/9
https://reference.opcfoundation.org/Core/Part4/v105/docs/6.1
https://reference.opcfoundation.org/Core/Part6/v105/docs/6.2

Definition at line 159 of file server.hpp.

◆ Server() [5/7]

opcua::Server::Server ( UA_Server native)
explicit

Create server from native instance (move ownership to server).

◆ ~Server()

opcua::Server::~Server ( )

◆ Server() [6/7]

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

◆ Server() [7/7]

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]

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

◆ config() [2/2]

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

◆ setLogger()

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

Definition at line 185 of file server.hpp.

◆ setApplicationUri()

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

Definition at line 190 of file server.hpp.

◆ setProductUri()

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

Definition at line 195 of file server.hpp.

◆ setApplicationName()

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

Definition at line 200 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 209 of file server.hpp.

◆ setAccessControl() [2/2]

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

Definition at line 214 of file server.hpp.

◆ setCustomDataTypes()

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

Definition at line 219 of file server.hpp.

◆ sessions()

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

Get active sessions.

Referenced by getSessions().

◆ getSessions()

std::vector< Session > opcua::Server::getSessions ( )
inline
Deprecated:
Use sessions() instead

Definition at line 228 of file server.hpp.

◆ namespaceArray()

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

Get all defined namespaces.

Referenced by getNamespaceArray().

◆ getNamespaceArray()

std::vector< std::string > opcua::Server::getNamespaceArray ( )
inline
Deprecated:
Use namespaceArray() instead

Definition at line 237 of file server.hpp.

◆ registerNamespace()

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

Register namespace. The new namespace index will be returned.

◆ setVariableNodeValueCallback() [1/2]

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

Set value callback for variable node.

Examples
server_valuecallback.cpp.

◆ setVariableNodeValueCallback() [2/2]

void opcua::Server::setVariableNodeValueCallback ( const NodeId id,
std::unique_ptr< ValueCallbackBase > &&  callback 
)

Set value callback for variable node (move ownership to server).

◆ setVariableNodeDataSource() [1/2]

void opcua::Server::setVariableNodeDataSource ( const NodeId id,
DataSourceBase source 
)

Set data source for variable node.

Examples
server_datasource.cpp.

◆ setVariableNodeDataSource() [2/2]

void opcua::Server::setVariableNodeDataSource ( const NodeId id,
std::unique_ptr< DataSourceBase > &&  source 
)

Set data source for variable node (move ownership to server).

◆ createSubscription()

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

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

Deprecated:
Use Subscription constructor

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

void opcua::Server::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

detail::ServerContext & detail::getContext ( Server server)
friend

◆ asWrapper()

Server * asWrapper ( UA_Server server)
related

Convert native UA_Server pointer to its wrapper instance.

The native server must be owned by a Server instance.

◆ operator==()

bool operator== ( const Server lhs,
const Server rhs 
)
related

Definition at line 305 of file server.hpp.

◆ operator!=()

bool operator!= ( const Server lhs,
const Server rhs 
)
related

Definition at line 310 of file server.hpp.