open62541pp 0.19.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, method/server_method_async.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 142 of file server.hpp.

Public Member Functions

 Server ()
 
 Server (ServerConfig &&config)
 
 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 setCustomDataTypes (Span< const DataType > dataTypes)
 
std::vector< Sessionsessions ()
 
std::vector< StringnamespaceArray ()
 
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
 
uint16_t runIterate ()
 
void run ()
 
void stop ()
 
bool isRunning () const noexcept
 
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
 
void useAsyncOperation (Server &server, const NodeId &id, bool enabled)
 
std::optional< AsyncOperationgetAsyncOperation (Server &server) noexcept
 
void runAsyncOperation (Server &server, const AsyncOperation &operation)
 

Constructor & Destructor Documentation

◆ Server() [1/5]

opcua::Server::Server ( )

Create server with default configuration.

◆ Server() [2/5]

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

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

◆ Server() [3/5]

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

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

◆ ~Server()

opcua::Server::~Server ( )

◆ Server() [4/5]

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

◆ Server() [5/5]

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

Member Function Documentation

◆ config() [1/2]

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

◆ config() [2/2]

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

◆ createSubscription()

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

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

Deprecated:
Use Subscription constructor

◆ handle() [1/2]

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

◆ handle() [2/2]

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

◆ isRunning()

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

Check if the server is running.

◆ namespaceArray()

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

Get all defined namespaces.

◆ operator=() [1/2]

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

◆ operator=() [2/2]

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

◆ registerNamespace()

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

Register namespace. The new namespace index will be returned.

◆ run()

void opcua::Server::run ( )

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

◆ sessions()

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

Get active sessions.

◆ setCustomDataTypes()

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

Definition at line 164 of file server.hpp.

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

◆ setVariableNodeValueCallback() [1/2]

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

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

◆ setVariableNodeValueCallback() [2/2]

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

Set value callback for variable node.

Examples
server_valuecallback.cpp.

◆ stop()

void opcua::Server::stop ( )

Stop the server's main loop.

Friends And Related Symbol Documentation

◆ 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.

◆ detail::getContext

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

◆ getAsyncOperation()

std::optional< AsyncOperation > getAsyncOperation ( Server server)
related

Get the next queued async operation if available.

Async operations are queued by nodes with async operations enabled (see useAsyncOperation).

◆ operator!=()

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

Definition at line 233 of file server.hpp.

◆ operator==()

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

Definition at line 228 of file server.hpp.

◆ runAsyncOperation()

void runAsyncOperation ( Server server,
const AsyncOperation operation 
)
related

Run the provided async operation.

◆ useAsyncOperation()

void useAsyncOperation ( Server server,
const NodeId id,
bool  enabled 
)
related

Enable or disable async operations for the specified node.

When enabled, operations on the node are queued and must processed by a worker thread using runAsyncOperation.

Note
Only supported for method nodes.