Service Customization

[中文]

Overview

brookesia_service_custom ships a ready-to-use CustomService so you can register custom functions and events without a separate Brookesia component.

Typical Uses

  • Lightweight features: LEDs, PWM, GPIO toggles, simple sensors—wrapped as CustomService calls.

  • Prototypes: Expose logic as functions or events for local or RPC access.

  • Extensibility: Add capabilities without changing the core service framework.

Features

  • Dynamic registration: register_function() / register_event() at runtime.

  • Fixed handler shape: FunctionParameterMap in, FunctionResult out; lambdas, std::function, free functions, functors, std::bind.

  • Events: Full publish/subscribe lifecycle.

  • ServiceManager: Local calls and remote RPC.

  • Optional worker: Task scheduler for thread-safe execution.

API Reference

Header File

Classes

class CustomService : public esp_brookesia::service::ServiceBase

Dynamic service that lets callers register functions and events at runtime.

Public Functions

bool register_function(FunctionSchema schema, FunctionHandler handler)

Register a function for custom service.

Parameters
  • schema[in] Function schema

  • handler[in] Function handler

Returns

true if registered successfully, false otherwise

bool unregister_function(const std::string &function_name)

Unregister a function.

Parameters

function_name[in] Function name

Returns

true if unregistered successfully, false otherwise

virtual std::vector<FunctionSchema> get_function_schemas() override

Get currently registered function schemas for custom service.

Returns

std::vector<FunctionSchema> Function schemas

bool register_event(EventSchema event_schema)

Register an event for custom service.

Parameters

event_schema[in] Event schema to register.

Returns

true if registered successfully, false otherwise

bool unregister_event(const std::string &event_name)

Unregister an event.

Parameters

event_name[in] Event name

Returns

true if unregistered successfully, false otherwise

bool publish_event(const std::string &event_name, EventItemMap event_items)

Publish an event for custom service.

Parameters
  • event_name[in] Event name

  • event_items[in] Event items

Returns

true if published successfully, false otherwise

virtual std::vector<EventSchema> get_event_schemas() override

Get currently registered event schemas for custom service.

Returns

std::vector<EventSchema> Event schemas

Public Static Functions

static inline CustomService &get_instance()

Get the process-wide singleton instance.

Returns

Reference to the singleton custom service.