NAP
Public Member Functions | Protected Member Functions | List of all members
Service Class Reference

#include </opt/build/repo/nap/cmake/module_creator/template/src/templateservice.h>

Public Member Functions

UNPREFIXED_MODULE_NAME_INPUTCASE Service (ServiceConfiguration *configuration)
 
virtual void getDependentServices (std::vector< rtti::TypeInfo > &dependencies) override
 
virtual bool init (nap::utility::ErrorState &errorState) override
 
virtual void update (double deltaTime) override
 
virtual void shutdown () override
 
 Service (ServiceConfiguration *configuration)
 
virtual ~Service ()
 
CoregetCore ()
 
const CoregetCore () const
 
std::string getTypeName () const
 
const ModulegetModule () const
 
 Service (Service &)=delete
 
Serviceoperator= (const Service &)=delete
 
 Service (Service &&)=delete
 
Serviceoperator= (Service &&)=delete
 

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 preShutdown ()
 
virtual void shutdown ()
 
virtual void preResourcesLoaded ()
 
virtual void postResourcesLoaded ()
 
template<typename SERVICE_CONFIG >
SERVICE_CONFIG * getConfiguration ()
 
template<typename SERVICE_CONFIG >
const SERVICE_CONFIG * getConfiguration () const
 
std::string getIniFilePath () const
 
std::string getIniFilePath (const std::string &appendix) const
 

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() [1/4]

UNPREFIXED_MODULE_NAME_INPUTCASE Service ( ServiceConfiguration configuration)

◆ Service() [2/4]

Service ( ServiceConfiguration configuration)

◆ ~Service()

virtual ~Service ( )
virtual

◆ Service() [3/4]

Service ( Service )
delete

Copy is not allowed

◆ Service() [4/4]

Service ( Service &&  )
delete

Move is not allowed

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 PortalService, and 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() [1/2]

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

◆ getCore() [2/2]

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

◆ getDependentServices() [1/2]

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, RenderAdvancedService, ParameterGUIService, SDLInputService, APIWebSocketService, PortalService, SequenceServiceAudio, VideoService, SequenceGUIService, and SequenceAudioGUIService.

◆ getDependentServices() [2/2]

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

Use this call 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, RenderAdvancedService, ParameterGUIService, SDLInputService, APIWebSocketService, PortalService, SequenceServiceAudio, VideoService, SequenceGUIService, and SequenceAudioGUIService.

◆ getIniFilePath() [1/2]

std::string getIniFilePath ( ) const
protected

Returns the (absolute) path to the .ini file associated with this service. Note that this call does not create the .ini directory if it does not exist. The .ini file is used to (re)-store settings in between sessions

Returns
absolute path to .ini file on disk

◆ getIniFilePath() [2/2]

std::string getIniFilePath ( const std::string &  appendix) const
protected

Returns the (absolute) path to the .ini file associated with this service. Note that this call does not create the .ini directory if it does not exist. The .ini file is used to (re)-store settings in between sessions

Parameters
appendixadditional name, attached to the end of the file-name
Returns
absolute path to the .ini file on disk

◆ getModule()

const Module& getModule ( ) const
Returns
The module associated with this service

◆ getTypeName()

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

◆ init() [1/2]

virtual bool init ( nap::utility::ErrorState errorState)
overridevirtual

◆ init() [2/2]

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 IMGuiService, APIService, LicenseService, SDLInputService, UDPService, FontService, SerialService, RenderService, SequenceGUIService, RenderAdvancedService, SequenceService, PortAudioService, ParameterGUIService, SequenceAudioGUIService, OSCService, SequenceServiceAudio, AudioService, MidiService, VideoService, WebSocketService, and APIWebSocketService.

◆ operator=() [1/2]

Service& operator= ( const Service )
delete

Copy assignment is not allowed

◆ operator=() [2/2]

Service& operator= ( Service &&  )
delete

Move assignment is not allowed

◆ postResourcesLoaded()

virtual void postResourcesLoaded ( )
protectedvirtual

Invoked after the resource manager successfully loaded resources

Reimplemented in RenderService, RenderAdvancedService, and ParameterService.

◆ 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 IMGuiService, SceneService, RenderAdvancedService, and InputService.

◆ preResourcesLoaded()

virtual void preResourcesLoaded ( )
protectedvirtual

Invoked when the resource manager is about to load resources

Reimplemented in RenderService, and RenderAdvancedService.

◆ preShutdown()

virtual void preShutdown ( )
protectedvirtual

Invoked when exiting the main loop, after app shutdown is called This is called before shutdown() and before the resources are destroyed. Use this function if your service needs to reset its state before resources are destroyed When service B depends on A, Service B is shutdown before A

Reimplemented in RenderService, IMGuiService, RenderAdvancedService, and PortAudioService.

◆ 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

◆ 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 IMGuiService, SequenceGUIService, SequenceService, PortAudioService, SequenceAudioGUIService, ArtNetService, APIWebSocketService, PortalService, FontService, VideoService, OSCService, WebSocketService, SceneService, SequenceServiceAudio, UDPService, and PythonScriptService.

◆ shutdown() [1/2]

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 RenderService, IMGuiService, APIService, RenderAdvancedService, PortAudioService, SDLInputService, UDPService, AudioService, FontService, and SerialService.

◆ shutdown() [2/2]

virtual void shutdown ( )
overridevirtual

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 RenderService, IMGuiService, APIService, RenderAdvancedService, PortAudioService, SDLInputService, UDPService, AudioService, FontService, and SerialService.

◆ update() [1/2]

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 RenderService, IMGuiService, APIService, SequenceService, PortalService, ArtNetService, OSCService, UDPService, SequenceServiceAudio, WebSocketService, MidiService, SceneService, and VideoService.

◆ update() [2/2]

virtual void update ( double  deltaTime)
overridevirtual

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 RenderService, IMGuiService, APIService, SequenceService, PortalService, ArtNetService, OSCService, UDPService, SequenceServiceAudio, WebSocketService, MidiService, SceneService, and VideoService.