mirror of
https://github.com/mudita/MuditaOS.git
synced 2025-12-31 18:08:21 -05:00
Working example of application and service ready to copy from with minimum documentation Apply suggestions from code review Co-authored-by: * Paweł Olejniczak <58421550+pawel-mudita@users.noreply.github.com> * Paweł Joński <79840715+paweljonskim@users.noreply.github.com> * Bartosz Cichocki <sp2fet@gmail.com>
3.5 KiB
3.5 KiB
Module services
All Services in PurePhone are dependent to Service.hpp from module-sys
Table of Contents
- Module services
- General services documentation
- How to add new service
- More on services configuration
- Minimalistic service example
General services documentation
Services documentation is available in module-sys here.
How to add new service
- we do not have strict naming conventions, but please follow others
- name your service - for example’s sake it will be
test - add new folder
service-testinmodule-services - add folder
include/service-test/toservice-test- this folder will contain your service public API - api you want to publish for others to use
- add this folder as
PUBLIClibrary include - please do add other elements as
PRIVATElibrary includes and libraries
- create
include/service-test/ServiceTest.hpp- this file will be your service declaration - create
ServiceTest.cpp- this file will be your service entry point and definition - add your service to SERVICES list in
module-services/CMakeLists.txt - add your service to list of services to include in product main in which you want to have it
- add your service
$<$<BOOL:${ENABLE_SERVICE_TEST}>:service-test>intarget_link_libraries(${TARGET} ... - please add conditional compilation to it too in
${TARGET}Main.cpp(i.e.PurePhoneMain.cpp) - all services haveENABLE_SERVICE_{SERVICE_NAME}definition exported
- add your service
NOTE: There are no other rules of thumb in terms of folders
- add cmake, the very basic cmake here:
project(service-test)
message("${PROJECT_NAME} ${CMAKE_CURRENT_LIST_DIR}" )
set(SOURCES ServiceTest.cpp)
add_library(${PROJECT_NAME} STATIC ${SOURCES})
target_include_directories(${PROJECT_NAME}
PRIVATE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
)
target_link_libraries(${PROJECT_NAME}
PRIVATE
PUBLIC
)
if (${ENABLE_TESTS})
add_subdirectory(test)
endif ()
- to disable your service by default please add:
option(ENABLE_SERVICE_TEST "Enable service test" OFF)
To change service startup order
Please see the SystemManager services synchronization documentation
To use settings::Settings
Documentation: settings::Settings
To add timer
Documentation timers
To add 3rd party library
Documentation: third party libraries
To add tests
Documentation: unit tests gathering cmake
To change service order, failure timeout or name
Documentation service manifest
More on services configuration
While we can enable and disable services, we do not have proper separation for services and API definition. This means that whole system compilation will depend on:
- include paths exported in services
- APIs from services
Example
See service-test example for ready to copy service example