Jazz 1.25.+
Loading...
Searching...
No Matches
Public Member Functions | Data Fields
jazz_elements::Service Class Reference

A Jazz Service is a globally instanced configurable object that may allocate RAM. More...

#include <utils.h>

Inheritance diagram for jazz_elements::Service:
jazz_bebop::Bop jazz_bebop::DataSpaces jazz_bebop::Fields jazz_bebop::OpCodes jazz_bebop::Space jazz_elements::Container jazz_main::HttpServer jazz_models::SemSpaces jazz_bebop::BaseAPI jazz_elements::Channels jazz_elements::Persisted jazz_elements::Volatile jazz_models::Model jazz_bebop::Core jazz_main::API jazz_models::ModelsAPI

Public Member Functions

 Service (pLogger a_logger, pConfigFile a_config)
 
virtual StatusCode start ()
 A simple start()/shut_down() interface (Restart is: shut_down(TRUE):start())
 
virtual StatusCode shut_down ()
 
virtual pChar const id ()
 
void log (int loglevel, const char *message)
 
void log_printf (int loglevel, const char *fmt,...)
 
bool get_conf_key (const char *key, int &value)
 
bool get_conf_key (const char *key, double &value)
 
bool get_conf_key (const char *key, std::string &value)
 

Data Fields

pLogger p_log
 The logger.
 
pConfigFile p_conf
 The configuration file.
 

Detailed Description

A Jazz Service is a globally instanced configurable object that may allocate RAM.

A service is anything that requires configuration and a logger. Only a service can own (alloc from the system) RAM, anything else allocates RAM from a service. Only Services (and some callback functions) are instantiated in Jazz instances and there is only one of each. The abstract class just defines the API.

A Service should NOT read the configuration before its .start() method is called as it may change between construction (at loading) and .start() (at running).

Constructor & Destructor Documentation

◆ Service()

jazz_elements::Service::Service ( pLogger  a_logger,
pConfigFile  a_config 
)

Initialize the Service without starting it.

Parameters
a_loggerA Logger.
a_configPossibly a configuration file as a ConfigFile object. NULL is okay if the object does not expect any configuration.

Rather than using the private p_log and p_conf pointers, it is recommended to use the inline methods log() and log_printf() for logging and get_conf_key() for accessing the configuration.

Member Function Documentation

◆ start()

StatusCode jazz_elements::Service::start ( )
virtual

A simple start()/shut_down() interface (Restart is: shut_down(TRUE):start())

Start (or restart) the Service

Returns
SERVICE_NO_ERROR if successful, some error if not.

This method should be overriden by something that actually starts the service, possibly using the configuration file in pConf.

Reimplemented in jazz_bebop::BaseAPI, jazz_bebop::Core, jazz_bebop::DataSpaces, jazz_bebop::Fields, jazz_bebop::OpCodes, jazz_bebop::Space, jazz_elements::Channels, jazz_elements::Container, jazz_elements::Persisted, jazz_elements::Volatile, jazz_main::API, jazz_models::Model, jazz_models::ModelsAPI, and jazz_models::SemSpaces.

◆ shut_down()

StatusCode jazz_elements::Service::shut_down ( )
virtual

Stop the Service

Returns
SERVICE_NO_ERROR if successful, some error if not.

This method should be overriden by something that actually stops the service, possibly using the configuration file in pConf.

Reimplemented in jazz_bebop::BaseAPI, jazz_bebop::Core, jazz_bebop::OpCodes, jazz_bebop::Space, jazz_elements::Channels, jazz_elements::Container, jazz_elements::Persisted, jazz_elements::Volatile, jazz_main::API, jazz_main::HttpServer, jazz_models::Model, and jazz_models::ModelsAPI.

◆ id()

pChar const jazz_elements::Service::id ( )
virtual

Return object ID.

Returns
A string identifying the object that is especially useful to track uplifts and versions.

Reimplemented in jazz_bebop::BaseAPI, jazz_bebop::Core, jazz_bebop::DataSpaces, jazz_bebop::Fields, jazz_elements::Channels, jazz_elements::Persisted, jazz_elements::Volatile, jazz_main::API, jazz_main::HttpServer, jazz_models::ModelsAPI, and jazz_models::SemSpaces.

◆ log()

void jazz_elements::Service::log ( int  loglevel,
const char *  message 
)
inline

Wrapper method logging events through a Logger when the logger was passed to the constructor of this class.

Parameters
loglevelThe trace level.
messageA message.

See Logger for details.

◆ log_printf()

void jazz_elements::Service::log_printf ( int  loglevel,
const char *  fmt,
  ... 
)
inline

Wrapper method logging events through a Logger when the logger was passed to the constructor of this class.

Parameters
loglevelThe trace level.
fmtThe printf-style format string.
...The list of parameters as a variadic list of parameters.

See Logger for details.

◆ get_conf_key() [1/3]

bool jazz_elements::Service::get_conf_key ( const char *  key,
int &  value 
)
inline

Wrapper method to get configuration values when the ConfigFile was passed to the constructor of this class.

Parameters
keyThe configuration key to be searched.
valueValue to be returned only when the function returns true.
Returns
True when the key exists and can be returned with the specific (overloaded) type.

See ConfigFile for details.

◆ get_conf_key() [2/3]

bool jazz_elements::Service::get_conf_key ( const char *  key,
double &  value 
)
inline

Wrapper method to get configuration values when the ConfigFile was passed to the constructor of this class.

Parameters
keyThe configuration key to be searched.
valueValue to be returned only when the function returns true.
Returns
True when the key exists and can be returned with the specific (overloaded) type.

See ConfigFile for details.

◆ get_conf_key() [3/3]

bool jazz_elements::Service::get_conf_key ( const char *  key,
std::string &  value 
)
inline

Wrapper method to get configuration values when the ConfigFile was passed to the constructor of this class.

Parameters
keyThe configuration key to be searched.
valueValue to be returned only when the function returns true.
Returns
True when the key exists and can be returned with the specific (overloaded) type.

See ConfigFile for details.


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