Invoker
Invoker API
The Invoker API provides a command invocation mechanism using caller provided runtime and (command) hooks.
Component Diagram
@startuml invoker-api
skinparam nodesep 55
skinparam ranksep 40
title Invoker API
component "Caller" as caller
component "InvokerDesc" as inv
component "Vector<InvokerHook>" as hooks
component "InvokerHook" as hook
component "Loader" as loader
component "Runtime" as runtime
interface "InvokerLoaderFunc" as loaderFunc
interface "InvokerRuntimeFunc" as runtimeFunc
caller --> inv : create / push / invoke / destroy
inv ---> hooks : owns
hooks ---> hook : [0..m]
inv --( loaderFunc
loaderFunc -- loader
loader --> inv : populate via invoker_push()
inv --( runtimeFunc
runtimeFunc -- runtime
inv --> runtime : invoke(command) / shutdown(NULL)
center footer Dynamic Simulation Environment
@enduml

Example
The following example demonstrates how to use the Invoker API.
// Copyright 2026 Robert Bosch GmbH
#include <stdio.h>
#include <stdlib.h>
#include <dse/clib/invoker/invoker.h>
enum { HOOK_INIT = 1, HOOK_RUN, HOOK_STOP };
typedef struct SysCmdCtx {
int count;
} SysCmdCtx;
static int loader(InvokerDesc* inv)
{
const InvokerHook hooks[] = {
{ .id = HOOK_INIT, .command = "echo '[init] starting'" },
{ .id = HOOK_RUN, .command = "echo '[run] working'" },
{ .id = HOOK_STOP, .command = "echo '[stop] done'" },
{ 0 },
};
return invoker_push(inv, hooks);
}
static int runtime(InvokerDesc* inv, const InvokerHook* hook)
{
SysCmdCtx* ctx = inv->runtime_ctx;
if (hook == NULL) {
if (ctx != NULL) {
printf("Total commands executed: %d\n", ctx->count);
free(ctx);
inv->runtime_ctx = NULL;
}
return 0;
}
if (ctx == NULL) {
ctx = inv->runtime_ctx = calloc(1, sizeof(*ctx));
if (ctx == NULL) return -ENOMEM;
}
ctx->count++;
return system(hook->command);
}
int main(void)
{
InvokerDesc inv = invoker_create(runtime, loader);
if (inv.runtime_func == NULL) return 1;
invoker_invoke(&inv, HOOK_INIT);
invoker_invoke(&inv, HOOK_RUN);
invoker_invoke(&inv, HOOK_STOP);
invoker_destroy(&inv);
return 0;
}
Typedefs
InvokerDesc
typedef struct InvokerDesc {
InvokerRuntimeFunc runtime_func;
void* runtime_ctx;
int hooks;
}
InvokerHook
typedef struct InvokerHook {
InvokerHookId id;
const char* name;
const char* command;
}
pthread_attr_t
typedef struct pthread_attr_t {
char[56] __size;
long __align;
}
Functions
invoker_create
Create an invoker with a runtime function and optionally load its hooks.
Parameters
- runtime_func (InvokerRuntimeFunc)
- Runtime function used to execute hooks. Must not be NULL.
- loader_func (InvokerLoaderFunc)
- Optional function used to populate the invoker's hooks. Pass NULL to skip loading.
Returns
- InvokerDesc
- Initialized invoker. If
runtime_funcis NULL,errnois set toEINVAL. Ifloader_funcreturns a nonzero value, the invoker is destroyed anderrnois set toECANCELED.
invoker_destroy
Destroy an invoker and release its registered hooks. If a runtime function is configured, it is called with a NULL hook before the hooks are released.
Parameters
- inv (InvokerDesc*)
- Pointer to the InvokerDesc, or NULL.
Returns
- void
- The invoker was destroyed, or the pointer was NULL.
invoker_invoke
Invoke the command for a hook ID using the configured runtime function. If no matching hook exists, or its command is NULL or empty, no runtime call is made.
Parameters
- inv (InvokerDesc*)
- Pointer to the InvokerDesc.
- id (InvokerHookId)
- ID of the hook to invoke.
Returns
- N (int)
- Return value from the runtime function, or zero if no command was invoked.
- -EINVAL (-22)
invis NULL or has no runtime function.
invoker_push
Copy hooks into an invoker and sort them by hook ID. The input array must end
with an entry whose name and command are both NULL. Hook strings are copied
and owned by the invoker.
Parameters
- inv (InvokerDesc*)
- Pointer to the InvokerDesc.
- hooks (const InvokerHook*)
- Sentinel-terminated array of hooks to copy into the invoker.
Returns
- 0 (int)
- Hooks were copied successfully.
- -EINVAL (-22)
invorhooksis NULL.