Files
MuditaOS/module-services/ModuleServices.md
Adam Dobrowolski 1cb4da819d [MOS-307] Application and Service example and docs
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>
2022-03-28 08:17:39 +02:00

3.5 KiB
Raw Permalink Blame History

Module services

All Services in PurePhone are dependent to Service.hpp from module-sys

Table of Contents

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 examples sake it will be test
  • add new folder service-test in module-services
  • add folder include/service-test/ to service-test
    • this folder will contain your service public API - api you want to publish for others to use
    • add this folder as PUBLIC library include
    • please do add other elements as PRIVATE library 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> in target_link_libraries(${TARGET} ...
    • please add conditional compilation to it too in ${TARGET}Main.cpp (i.e. PurePhoneMain.cpp) - all services have ENABLE_SERVICE_{SERVICE_NAME} definition exported

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