NAP
Service Class Reference

#include <nap/service.h>

Public Member Functions

 Service (ServiceConfiguration *configuration)
 
virtual ~Service ()
 
CoregetCore ()
 
const std::string getTypeName () const
 

Protected Member Functions

virtual void registerObjectCreators (rtti::Factory &factory)
 
virtual void getDependentServices (std::vector< rtti::TypeInfo > &dependencies)
 
virtual void created ()
 
virtual bool init (utility::ErrorState &error)
 
virtual void preUpdate (double deltaTime)
 
virtual void update (double deltaTime)
 
virtual void postUpdate (double deltaTime)
 
virtual void shutdown ()
 
virtual void resourcesLoaded ()
 
template<typename SERVICE_CONFIG >
SERVICE_CONFIG * getConfiguration ()
 
template<typename SERVICE_CONFIG >
const SERVICE_CONFIG * getConfiguration () const
 

Detailed Description

A Service is a process within core that cooperates with certain components in the system, this is the base class for all services. Often services are used to load a driver, set up a connection or manage global module specific state. All services are automatically loaded and managed by Core. This ensures the right service order of initialization, runtime state and closing. When designing a module using a service make sure to export the service using the 'NAP_SERVICE_MODULE' #define in a source file exactly once, for example:

NAP_SERVICE_MODULE("mod_naposc", "0.2.0", "nap::OSCService")

This code snippet ensures that core automatically loads, creates and initializes the service when loading the modules.

Inheritance diagram for Service:
[legend]

Constructor & Destructor Documentation

◆ Service()

Service ( ServiceConfiguration configuration)

◆ ~Service()

virtual ~Service ( )
virtual

Member Function Documentation

◆ created()

virtual void created ( )
protectedvirtual

Invoked when the service has been constructed and Core is available. This occurs before service initialization

Reimplemented in APIWebSocketService.

◆ getConfiguration() [1/2]

SERVICE_CONFIG* getConfiguration ( )
protected

Retrieve the ServiceConfiguration for this service. Will be null if this service does not support configuration

Returns
The ServiceConfiguration

◆ getConfiguration() [2/2]

const SERVICE_CONFIG* getConfiguration ( ) const
protected

Retrieve the ServiceConfiguration for this service. Will be null if this service does not support configuration

Returns
The ServiceConfiguration

◆ getCore()

Core& getCore ( )
Returns
the nap core this service belongs to

◆ getDependentServices()

virtual void getDependentServices ( std::vector< rtti::TypeInfo > &  dependencies)
protectedvirtual

Override this function to register service dependencies A service that depends on another service is initialized after all it's associated dependencies This will ensure correct order of initialization, update calls and shutdown of all services

Parameters
dependenciesrtti information of the services this service depends on

Reimplemented in RenderService, IMGuiService, SDLInputService, APIWebSocketService, EtherDreamService, AdvancedAudioService, and VideoService.

◆ getTypeName()

const std::string getTypeName ( ) const
Returns
the type name of the service

◆ init()

virtual bool init ( utility::ErrorState error)
protectedvirtual

Invoked by core after initializing the core engine. When called all modules this service depends on have been initialized Override this method to initialize your service.

Parameters
errorshould contain the error message when initialization fails

Reimplemented in APIService, RenderService, AudioService, IMGuiService, SDLInputService, EtherDreamService, OSCService, MidiService, VideoService, FontService, AdvancedAudioService, YoctoService, SerialService, WebSocketService, and APIWebSocketService.

◆ postUpdate()

virtual void postUpdate ( double  deltaTime)
protectedvirtual

Invoked by core in the app loop. Update order depends on service dependency This call is invoked after the application update call

Parameters
deltaTimethe time in seconds between calls

Reimplemented in InputService, and SceneService.

◆ preUpdate()

virtual void preUpdate ( double  deltaTime)
protectedvirtual

Invoked by core in the app loop. Update order depends on service dependency. This call is invoked before the resource manager checks for file changes and the app update call If service B depends on A, A::update() is called before B::update()

Parameters
deltaTimethe time in seconds between calls

Reimplemented in RenderService.

◆ registerObjectCreators()

virtual void registerObjectCreators ( rtti::Factory factory)
protectedvirtual

Override this function to register specific object creators for classes associated with this module

Parameters
factorythe factory used by the resource manager to instantiate objects

Reimplemented in RenderService, AudioService, MidiService, APIWebSocketService, ArtNetService, VideoService, FontService, OSCService, EtherDreamService, WebSocketService, SceneService, AdvancedAudioService, and PythonScriptService.

◆ resourcesLoaded()

virtual void resourcesLoaded ( )
protectedvirtual

Invoked after the resource manager successfully loaded a resource file

Reimplemented in RenderService, and ParameterService.

◆ shutdown()

virtual void shutdown ( )
protectedvirtual

Invoked when exiting the main loop, after app shutdown is called Use this function to close service specific handles, drivers or devices When service B depends on A, Service B is shutdown before A

Reimplemented in APIService, RenderService, AudioService, IMGuiService, SDLInputService, EtherDreamService, FontService, YoctoService, and SerialService.

◆ update()

virtual void update ( double  deltaTime)
protectedvirtual

Invoked by core in the app loop. Update order depends on service dependency This call is invoked after the resource manager has loaded any file changes but before the app update call. If service B depends on A, A:s:update() is called before B::update()

Parameters
deltaTimethe time in seconds between calls

Reimplemented in APIService, RenderService, IMGuiService, MidiService, OSCService, ArtNetService, WebSocketService, VideoService, and SceneService.