Service - lms-org/lms GitHub Wiki
Services are in between modules and libraries: They expose a set of methods to modules just like libraries and are initialized during framework startup just like modules. Services have access to configs and must be defined in an XML config.
Service names should be lowercase with underscore and end with _service
.
Each service should be contained in its own git repository and its folder structure is defined as:
-
src - folder containing *.cpp files
- my_service.cpp - Service implementation
- interface.cpp - Interface for the framework
-
include - folder containing *.h files
- my_service.h - Service declaration
- CMakeLists.txt - Compile commands for CMake
- README.md - Service description and information in
You should use the lms-create-service
script from
lms_tools to create an
empty service.
A service class must extend lms::Service
.
class MyService : public lms::Service {
bool init() override;
void destroy() override;
void configsChanged();
}
Services must be defined in XML configs to be loaded into the framework.
<framework>
<service>
<name>my_service</name>
</service>
</framework>
Modules can either get a thread-safe handle on a service or an unsafe direct access. Currently there is no way a service can directly access another service.
MyService* service = getUnsafeService<MyService>("my_service");
{
lms::ServiceHandle<MyService> hnd = getService<MyService>("my_service");
// service is now locked and cannot be used in any other module or runtime
hnd->calculate42();
// unlocks automatically
}