LoRa Basics MAC
The Services Framework provides a convenient way for independent modules to provide static, compile-time hooks that can be used by other modules. For example, a module might provide a hook that gets called whenever an certain event occurs.
Modules that make use of a provided hook can specify a call to a function they provide, to be executed whenever the hook is called.
This framework enables independent modules to make use of each other’s functionality without the need of dynamic, run-time registration of callbacks, event listeners, or similar mechanisms.
Service descriptions are contained in a
YAML-file with the name SVCID.svc, where SVCID is a short, unique service identifier for the module.
The service description contains the source files of the module, the hooks the module provides, as well as code snippets for any hooks that the module makes use of.
src: - ui/uisvc.c hooks: - void button (int) hook.exti_irq: button_exti
The service in this example provides a hook called button with the signature
void (*) (int), while making use of the exti_irq hook which must be provided by another module. The function
button_exti(...) will be executed whenever the exti_irq hook is called.
To make use of a service module, add the corresponding service identifier to the
SVCS list in the project Makefile.
The build environment will search the
services directory, as well as the project directory for service description files.
The information gathered from the service descriptions is then used by the service tool to generate the
svcdefs.h header file. This header file is populated with macros that contain the code that is executed when the hook is called.
Further, all source files specified in the service descriptions will be added to the build.
Some modules may provide APIs to be used by other modules or applications. For this purpose, the
services directory is added to the include-path during the build process, so that API header files can be easily included.
See the test-service project for an example on how an application might make use of services.