Ambiorix ODL parsing (1): from ODL to the data model (amx-scheduler)
Grow through practice
No need to finish reading — test nowOne line: ODL = a declarative sequence of
amxd_*calls + symbol binding. The parser islibamxo; it turns ODL into an object tree, then bindscall/entry-pointto C functions in the.so.
The parse chain
amxrt
→ amxo_parser_parse_file()
→ %config parse config
→ import dlopen the .so
→ include recursive parse
→ %define amxd_object_new / amxd_param_new
→ %populate add_instance / slot_connect
→ entry-point dlsym + invoke
amx-scheduler's ODL, section by section
%config: parser config
%config {
storage-path = "${rw_data_path}/${name}/";
definition_file = "${name}_definition.odl";
defaults_dir = "${cfg-dir}/${name}/defaults/";
}
- these keys go into
parser->config; - in C, read them with
amxo_parser_get_config(parser, "storage-path")oramxrt_get_config(); ${name}/${rw_data_path}are variable expansions;amxrtsetsnamefrom the executable name (or-o name=...).
import: load the .so
import "amx-scheduler.so" as "${name}";
libamxocallsdlopen;- later,
call xxx/entry-pointsymbols are resolved byamxo_import_resolver.c, which builds_xxx(or_<module>_xxx) and callsdlsym; - with
import-dbg = trueyou see[IMPORT-DBG] - dlopen ...andsymbol _task_added resolved ....
include: recursive parse
include "${definition_file}";
- equivalent to another
amxo_parser_parse_file; - parsed into the same DM;
entry_pointsare shared.
entry-point: the entry function
%define {
entry-point amx-scheduler.scheduler_main;
}
- the parser calls
amxo_parser_add_entry_point(parser, fn); amxrtinvokesamxo_parser_invoke_entry_points(parser, dm, AMXO_START|AMXO_STOP)at start/stop;- that calls
_scheduler_main(reason, dm, parser)in C.
%define: the object tree
%define {
%persistent object Scheduler {
%persistent object Task[] {
%persistent %unique %key string Alias;
%persistent bool Enable = false;
%persistent uint32 Duration = 0;
%read-only string Status = "";
}
}
}
Mapping:
| ODL | C |
|---|---|
object Scheduler {} | amxd_object_new(&o, amxd_object_singleton, "Scheduler") + attach to DM |
object Task[] {} | amxd_object_new(&t, amxd_object_template, "Task"); instances via amxd_object_add_instance |
string Alias | amxd_param_new(&p, "Alias", AMXC_VAR_ID_CSTRING) + amxd_object_add_param |
bool Enable | AMXC_VAR_ID_BOOL |
uint32 Duration | AMXC_VAR_ID_UINT32 |
%persistent | amxd_param_set_attr(p, amxd_pattr_persistent, true) |
%key | amxd_param_set_attr(p, amxd_pattr_key, true) |
%unique | amxd_param_set_attr(p, amxd_pattr_unique, true) |
%read-only | amxd_param_set_attr(p, amxd_pattr_read_only, true) |
%populate: instances and events
%populate {
on event "dm:instance-added" call task_added
filter 'path == "Scheduler.Task."';
on event "dm:instance-removed" call task_deleted;
on event "dm:object-changed" call task_changed
filter 'path matches "Scheduler\.Task\.[0-9]+\." &&
not contains("parameters.Status")';
}
on event ... call f→amxp_slot_connect_filtered()/amxp_slot_connect();fresolves to_f(_task_added/_task_deleted/_task_changed);- C signature:
void _task_added(const char* const event_name,
const amxc_var_t* const data,
void* const priv);
filterbecomes the slot filter expression — not anifin C.
The equivalent handwritten C
The %define above is roughly equivalent to:
amxd_dm_t* dm;
amxd_object_t *sched, *task;
amxd_param_t* p;
amxd_dm_new(&dm);
amxd_object_new(&sched, amxd_object_singleton, "Scheduler");
amxd_dm_add_root_object(dm, sched);
amxd_object_new(&task, amxd_object_template, "Task");
amxd_object_add_object(sched, task);
amxd_param_new(&p, "Alias", AMXC_VAR_ID_CSTRING);
amxd_param_set_attr(p, amxd_pattr_persistent, true);
amxd_param_set_attr(p, amxd_pattr_key, true);
amxd_param_set_attr(p, amxd_pattr_unique, true);
amxd_object_add_param(task, p);
ODL is just that code written declaratively. For the manual version, see libamxd in code.
Where the parser source is
libamxo/src/amxo_parser_dm_utils.c: objects / instances / events;libamxo/src/amxo_parser_dm_param_utils.c: parameters and attributes;libamxo/src/amxo_import_resolver.c:dlopen+_<symbol>resolution;libamxrt/src/amxrt.c:amxo_parser_invoke_entry_points(START/STOP).
Read these four files and every ODL keyword maps to a C call.
Debugging
import-dbg = true: seedlopen/ symbol resolution;amxrt -dconfig: see the parsed config;ubus call Scheduler _describe: see the object tree/parameters/attributes;- symbol not found: check the C function is
_xxx, and that the.sowasimported.
Three resolvers
call xxx / entry-point are not direct calls — they are resolved to function pointers first:
| Resolver | What it does |
|---|---|
| auto (default) | finds by naming rules |
| ftab | function table; registered with amxo_resolver_ftab_add() (e.g. check_enum) |
| import | dlopened .so, dlsym for _<symbol> |
Default order (visible in -dconfig):
auto-resolver-order = ["ftab", "import", "*"]
What ODL can / cannot do
Can:
- declare objects, parameters, functions, events, instances;
- bind C functions (
on action/call/entry-point); - set initial values, add instances, subscribe to events with
%populate.
Cannot:
- implement behavior (functions/actions must be in C);
- act as a general-purpose language (it has expressions/filters, but not complex computation/loops);
- replace business code.
ODL is “declare + bind”; C is “implement”.
Syntax cheat sheet
| Syntax | Purpose |
|---|---|
%config { ... } | parser/runtime config |
import "x.so" | load a plugin |
include "x.odl" | recursive parse |
?include "a":"b" | optional include / fallback |
%define { object ... } | object tree |
%populate { ... } | defaults/instances/events |
on action read call f | read callback |
on event "..." call f | event subscription |
entry-point x.y | startup entry |
FAQ
What is ODL?
Ambiorix's object definition language: declares the object tree and binds C functions; not a plain config file.
How do ODL and C relate?
ODL declares, C implements; on action/call/entry-point bind them.
How is ODL parsed?
amxo_parser_parse_file: %config → import → include → %define (amxd_object_new) → %populate (instances/events) → entry-point.
How does ODL relate to prplOS?
prplOS uses AMX for the data model/management plane; ODL is how that model is declared.
Why is ${name} equal to amxrt?
amxrt uses the executable name as name; use -o name=xxx or an install symlink.
Next
A bigger ODL: greeter (4 ODL files with instances/templates/async/resolver).
One sentence
ODL is not “configuration”; it is declarative source that builds the object tree and binds functions. Once you read ODL, you can see the
amxd_*andamxp_*calls it generates.
Next: Ambiorix ODL parsing (2): greeter Reference: ODL handbook Examples: 02 amx-scheduler · 03 cpu-info Deep dive: How %config is parsed Series: AMX Official Examples.
Comments 0
No comments yet — be the first!