C++ UA Server SDK  1.5.0.318
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
UaCoreServerApplication Class Referenceabstract

Base class for the main OPC Server management object. More...

#include <uacoreserverapplication.h>

Inherits UaApplication.

Inherited by UaServerApplication.

Public Member Functions

 UaCoreServerApplication ()
 Creates an instance of UaCoreServerApplication with default settings. More...
 
 UaCoreServerApplication (int argc, char *argv[], bool bRunAsService, const UaString &sApplicationName)
 Creates an instance of UaCoreServerApplication with service related settings. More...
 
virtual ~UaCoreServerApplication ()
 Destroys the UaCoreServerApplication object. More...
 
int setServerConfig (const UaString &configurationFile, const UaString &sApplicationPath)
 Sets the server configuration by passing the path of the configuration file. More...
 
int setServerConfig (const UaString &configurationFile, const UaString &sApplicationPath, const UaString &sConfigPath, const UaString &sTracePath)
 Sets the server configuration by passing the path of the configuration file. More...
 
int setServerConfig (ServerConfig *pServerConfig)
 Sets the server configuration by passing a server configuration object. More...
 
int addNodeManager (NodeManager *pNodeManager)
 Adds a node manager to the SDK. More...
 
int addModule (UaServerApplicationModule *pModule)
 Adds a Module to the SDK. More...
 
int removeNodeManager (NodeManager *pNodeManager)
 Removes and deletes the NodeManager from the SDK. More...
 
int removeModule (UaServerApplicationModule *pModule)
 Removes and deletes the Module from the SDK. More...
 
int setCallback (UaServerApplicationCallback *pUaServerApplicationCallback)
 Sets the callback interface for the server object. More...
 
void setSecondsTillShutdown (OpcUa_Int32 secondsTillShutdown)
 Set seconds till shudown sent to OPC UA client during shut down.
 
void setShutdownReason (const UaLocalizedText &shutdownReason)
 Set shudown reason sent to OPC UA client during shut down.
 
int start ()
 Starts the OPC server Initializes and starts up all NodeManagers and SDK modules. More...
 
int stop (OpcUa_Int32 secondsTillShutdown, const UaLocalizedText &shutdownReason)
 Stopps the OPC server Shutdown and deletes all SDK modules and NodeManagers. More...
 
NodeManagerConfiggetDefaultNodeManager ()
 Returns the default node manager for server specific nodes in namespace one. More...
 
ServerManagergetServerManager ()
 Returns the ServerManager object.
 
ServerConfiggetServerConfig ()
 Returns the ServerConfig object.
 
CoreModulegetCoreModule ()
 Returns the CoreModule object.
 
OpcUa_Boolean isStarted ()
 Returns the isStarted flag.
 
OpcUa_Int32 secondsTillShutdown ()
 Get seconds till shudown sent to OPC UA client during shut down.
 
UaLocalizedText shutdownReason ()
 Get shudown reason sent to OPC UA client during shut down.
 
virtual SessioncreateDefaultSession (OpcUa_Int32 sessionID, const UaNodeId &authenticationToken)=0
 Creates a session object for the OPC server. More...
 

Protected Member Functions

virtual UaStatus afterInitialize ()=0
 This method needs to be implemented by the derived class and is called to finish the initialization of the UaCoreServerApplication. More...
 
virtual UaStatus afterStartUp ()=0
 This method needs to be implemented by the derived class and is called to finish the start-up of the UaCoreServerApplication. More...
 
virtual UaStatus beforeShutdown ()
 This method needs to be implemented by the derived class and is called to start the shutdown of the UaCoreServerApplication. More...
 
virtual int main ()
 Main function for server process. More...
 

Detailed Description

Base class for the main OPC Server management object.

This class is a utility class managing all server SDK modules for common use cases in a simplified way. Enhanced users may replace this class with their own implementation to be able to use derived classes to overwrite SDK functionality.

A derived class must implement the methods afterInitialize(), afterStartUp() and beforeShutdown(). In addition the derived class must add the following code to the destructor to make sure beforeShutdown() is called before the object is deleted.

if ( isStarted() != OpcUa_False )
{
UaLocalizedText reason("en","Application shut down");
stop(0, reason);
}

Constructor & Destructor Documentation

UaCoreServerApplication::UaCoreServerApplication ( )

Creates an instance of UaCoreServerApplication with default settings.

UaCoreServerApplication::UaCoreServerApplication ( int  argc,
char *  argv[],
bool  bRunAsService,
const UaString sApplicationName 
)

Creates an instance of UaCoreServerApplication with service related settings.

UaCoreServerApplication::~UaCoreServerApplication ( )
virtual

Destroys the UaCoreServerApplication object.

Member Function Documentation

int UaCoreServerApplication::addModule ( UaServerApplicationModule pModule)

Adds a Module to the SDK.

The module will be managed by this class including starting, stopping and deletion of the module. The method can be called several times for a list of modules. If the method is called before start, all modules will be started during the call of the start method. If this method is called if the server is already started the module will be started by this method.

Returns
Success code for the operation. Return 0 if adding the module succedded and -1 if adding the module failed.
int UaCoreServerApplication::addNodeManager ( NodeManager pNodeManager)

Adds a node manager to the SDK.

The node manager will be managed by this class including starting, stopping and deletion of the node manager. The method can be called several times for a list of node managers. If the method is called before start, all node managers will be started during the call of the start method. If this method is called if the server is already started the node manager will be started by this method.

Returns
Success code for the operation. Return 0 if adding the node manager succedded and -1 if adding the node manager failed.
virtual UaStatus UaCoreServerApplication::afterInitialize ( )
protectedpure virtual

This method needs to be implemented by the derived class and is called to finish the initialization of the UaCoreServerApplication.

This method is typically used to initialize the communication modules like the UaModule.

Returns
Result code

Implemented in UaServerApplication.

virtual UaStatus UaCoreServerApplication::afterStartUp ( )
protectedpure virtual

This method needs to be implemented by the derived class and is called to finish the start-up of the UaCoreServerApplication.

This method is typically used to start up the communication modules like the UaModule.

Returns
Result code

Implemented in UaServerApplication, and OpcServer.

UaStatus UaCoreServerApplication::beforeShutdown ( )
protectedvirtual

This method needs to be implemented by the derived class and is called to start the shutdown of the UaCoreServerApplication.

This method is typically used to stop the communication modules like the UaModule.

Returns
Result code

Reimplemented in UaServerApplication.

virtual Session* UaCoreServerApplication::createDefaultSession ( OpcUa_Int32  sessionID,
const UaNodeId authenticationToken 
)
pure virtual

Creates a session object for the OPC server.

This is the default implementation. It can be overwritten by implementing the UaServerApplicationCallback.

Parameters
sessionIDSession Id created by the server application.
authenticationTokenSecret session Id created by the server application.
Returns
A pointer to the created session.

Implemented in UaServerApplication.

NodeManagerConfig * UaCoreServerApplication::getDefaultNodeManager ( )

Returns the default node manager for server specific nodes in namespace one.

This node manager can be used to create objects and variables for data access. It can not be used for enhanced OPC UA features. Usind features like events, methods and historical access requires the implementation of a specific node manager.

Returns
NodeManagerConfig interface used to add and delete UaNode objects in the node manager. Returns NULL if the server is not started.
int UaCoreServerApplication::main ( )
protectedvirtual

Main function for server process.

This default implementation calls start() on the server object, waits for the shutdown flag to be set and calls stop() on the server object if the shutdown flag is set through a user command in a console application or through the service shutdown.

int UaCoreServerApplication::removeModule ( UaServerApplicationModule pModule)

Removes and deletes the Module from the SDK.

Parameters
pModuleModule to remove.
Returns
Success code for the operation. Return 0 if removing the module succedded and -1 if removing the module failed.
int UaCoreServerApplication::removeNodeManager ( NodeManager pNodeManager)

Removes and deletes the NodeManager from the SDK.

Parameters
pNodeManagerNodeManager to remove.
Returns
Success code for the operation. Return 0 if removing the module succedded and -1 if removing the module failed.
int UaCoreServerApplication::setCallback ( UaServerApplicationCallback pUaServerApplicationCallback)

Sets the callback interface for the server object.

This callback interface needs to be implemented if the application wants to implement user authentication.

Parameters
pUaServerApplicationCallbackInterface pointer of the callback interface.
Returns
Success code for the operation. Return 0 if the call succedded and -1 if the call failed. This call fails if it is called after starting the server with the method start.
int UaCoreServerApplication::setServerConfig ( const UaString configurationFile,
const UaString sApplicationPath 
)

Sets the server configuration by passing the path of the configuration file.

One of the overloaded methods needs to be called to give the server a valid configuration.
This version forces the server to use the default implementation for the ServerConfig object and allows to specify the configuraiton file and the path to the application or the directory containing the configuration and the PKI store.

Parameters
configurationFilePath and file name of the configuration file. The file can be one of the two file formats supported by the SDK, a XML file format and an INI file format. The XML file format requires linking of the XML parser module and needs to be activated by compiling this class with the compiler switch SUPPORT_XML_PARSER set to 1
sApplicationPathThe path of the application folder used to replace the [ApplicationPath] placeholders in the configuration file
Returns
Success code for the operation. Return 0 if the call succedded and -1 if the call failed. This call fails if it is called after starting the server with the method start.
int UaCoreServerApplication::setServerConfig ( const UaString configurationFile,
const UaString sApplicationPath,
const UaString sConfigPath,
const UaString sTracePath 
)

Sets the server configuration by passing the path of the configuration file.

One of the overloaded methods needs to be called to give the server a valid configuration.
This version forces the server to use the default implementation for the ServerConfig object and allows to specify the configuraiton file and the path to the application or the directory containing the configuration and the PKI store.

Parameters
configurationFilePath and file name of the configuration file. The file can be one of the two file formats supported by the SDK, a XML file format and an INI file format. The XML file format requires linking of the XML parser module and needs to be activated by compiling this class with the compiler switch SUPPORT_XML_PARSER set to 1
sApplicationPathThe path of the application folder used to replace the [ApplicationPath] placeholders in the configuration file
sConfigPathThe path of the configuration files and PKI store used to replace the [ConfigPath] placeholders in the configuration file
sTracePathThe path of the trace file folder used to replace the [TracePath] placeholders in the configuration file
Returns
Success code for the operation. Return 0 if the call succedded and -1 if the call failed. This call fails if it is called after starting the server with the method start.
int UaCoreServerApplication::setServerConfig ( ServerConfig pServerConfig)

Sets the server configuration by passing a server configuration object.

One of the overloaded methods needs to be called to give the server a valid configuration.
This version allows to pass in a ServerConfig object with a user specific implementation.

Parameters
pServerConfigInterface pointer of the object implementing the ServerConfig interface.
Returns
Success code for the operation. Return 0 if the call succedded and -1 if the call failed. This call fails if it is called after starting the server with the method start.
int UaCoreServerApplication::start ( )

Starts the OPC server Initializes and starts up all NodeManagers and SDK modules.

It is possible to add more NodeManagers after the server is started.

Returns
Success code for the operation. Return 0 if the server start succedded and -1 if the server start failed.
int UaCoreServerApplication::stop ( OpcUa_Int32  secondsTillShutdown,
const UaLocalizedText shutdownReason 
)

Stopps the OPC server Shutdown and deletes all SDK modules and NodeManagers.

Parameters
secondsTillShutdownSeconds till shutdown of the server if clients are connected.
shutdownReasonReason for the shutdown.
Returns
Success code for the operation. Return 0 if the server stop succedded and -1 if the server stop failed.

The documentation for this class was generated from the following files: