6.3. service — Services

A service is as a background task. A service is either running or stopped.

6.3.1. Debug file system commands

Three debug file system commands is available, all located in the directory oam/service/.

Command Description
list List all registered services.
start <service> Start given service.
stop <service> Stop given service.

Example output from the shell:

$ oam/service/list
NAME                   STATUS
http_server            running
ftp_server             stopped
network_manager        running
$ oam/service/start ftp_server
$ oam/service/stop http_server
$ oam/service/list
NAME                   STATE
http_server            stopped
ftp_server             running
network_manager        running

Source code: src/oam/service.h, src/oam/service.c

Test code: tst/oam/service/main.c

Test coverage: src/oam/service.c


Defines

SERVICE_CONTROL_EVENT_START 0x1
SERVICE_CONTROL_EVENT_STOP 0x2

Serviece stop event.

Typedefs

typedef enum service_status_t (*service_get_status_cb_t)(struct service_t *self_p)

Enums

enum service_status_t

Values:

service_status_running_t = 0
service_status_stopped_t = 1

Functions

int service_module_init(void)

Initialize the service module. This function must be called before calling any other function in this module.

The module will only be initialized once even if this function is called multiple times.

Return
zero(0) or negative error code.

int service_init(struct service_t *self_p, const char *name_p, service_get_status_cb_t status_cb)

Initialize a service with given name and status callback.

Return
zero(0) or negative error code.
Parameters
  • self_p: Service to initialize.
  • name_p: Name of the service.
  • status_callback: Callback function returning the service status.

int service_start(struct service_t *self_p)

Start given service.

The event SERVICE_CONTROL_EVENT_START will be written to the control channel of given service and it’s up to the service to act on this event. All services should act on all control events.

Return
zero(0) or negative error code.
Parameters
  • self_p: Service to start.

int service_stop(struct service_t *self_p)

Stop given service.

The event SERVICE_CONTROL_EVENT_STOP will be written to the control channel of given service and it’s up to the service to act on this event. All services should act on all control events.

Return
zero(0) or negative error code.
Parameters
  • self_p: Service to stop.

int service_register(struct service_t *service_p)

Register given service to the global list of services.

Return
zero(0) or negative error code.
Parameters
  • service_p: Service to register.

int service_deregister(struct service_t *service_p)

Deregister given service from the global list of services.

Return
zero(0) or negative error code.
Parameters
  • service_p: Service to deregister.

struct service_t
#include <service.h>

A service with name and control event channel.

Public Members

const char *name_p
struct event_t control
service_get_status_cb_t status_cb
struct service_t *next_p