6.2. service
— Services¶
A service is as a background task. A service is either running or stopped.
6.2.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
¶ Service start event.
-
SERVICE_CONTROL_EVENT_STOP
¶ Serviece stop event.
Typedefs
-
typedef
enum service_status_t(* service_get_status_cb_t)(struct service_t *self_p)
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.
-
struct
service_t
¶ - #include <service.h>
A service with name and control event channel.