NAP
Public Member Functions | List of all members
ServiceRunner< APP, HANDLER > Class Template Reference

#include <servicerunner.h>

Public Member Functions

 ServiceRunner (nap::Core &core)
 
virtual ~ServiceRunner ()
 
 ServiceRunner (ServiceRunner &)=delete
 
ServiceRunneroperator= (const ServiceRunner &)=delete
 
 ServiceRunner (ServiceRunner &&)=delete
 
ServiceRunneroperator= (ServiceRunner &&)=delete
 
bool init (utility::ErrorState &error)
 
void update ()
 
int shutdown ()
 
int exitCode () const
 
APP & getApp ()
 
CoregetCore ()
 
const CoregetCore () const
 
HANDLER & getHandler ()
 

Description

template<typename APP, typename HANDLER>
class nap::ServiceRunner< APP, HANDLER >

Utility class that runs a nap::BaseApp as a service. This is useful when a different environment embeds a NAP application as a service that is run in the background. When running an app as a service the app is initialized, updated and stopped from that external environment. Call init() to initialize core, all the services and the app. Call update() to update all services and the app. Call shutdown() on exit to make sure all processes are stopped correctly.

The APP template argument should be derived from nap::BaseApp. The HANDLER template argument should be of type nap::AppEventHandler()

When creating a ServiceRunner with those two template arguments the app is created and invoked at the right time based on core and it's associated services. Note that this object owns the app and handler.

Constructor & Destructor Documentation

◆ ServiceRunner() [1/3]

ServiceRunner ( nap::Core core)

Constructor

Parameters
corethe nap core this runner uses in conjunction with the app and handler

◆ ~ServiceRunner()

~ServiceRunner
virtual

Destructor

◆ ServiceRunner() [2/3]

ServiceRunner ( ServiceRunner< APP, HANDLER > &  )
delete

Copy is not allowed

◆ ServiceRunner() [3/3]

ServiceRunner ( ServiceRunner< APP, HANDLER > &&  )
delete

Move is not allowed

Member Function Documentation

◆ exitCode()

int exitCode ( ) const

Returns the application exit code, available after shutdown().

Returns
the application exit code.

◆ getApp()

APP & getApp
Returns
the app

◆ getCore() [1/2]

Core& getCore ( )
Returns
core

◆ getCore() [2/2]

const Core& getCore ( ) const
Returns
core

◆ getHandler()

HANDLER & getHandler
Returns
the app handler

◆ init()

bool init ( utility::ErrorState error)

This call will initialize core and the application

Parameters
errorthe error message if the initialization failed
Returns
if the initialization was successful

◆ operator=() [1/2]

ServiceRunner& operator= ( const ServiceRunner< APP, HANDLER > &  )
delete

◆ operator=() [2/2]

ServiceRunner& operator= ( ServiceRunner< APP, HANDLER > &&  )
delete

◆ shutdown()

int shutdown

Call this before exiting your application. Ensures the app is exited and running services are stopped appropiately.

◆ update()

void update

Call this from an external environment. On update all events are processed, after that update on core is called.