Official example 02: amx-scheduler — the smallest data model (2 C + 2 ODL)
Grow through practice
No need to finish reading — test nowOne line: 2 C files + 2 ODL files are enough to see AMX objects, instances and events. It is smaller than cpu-info — the first step from “runtime” into “data model”. Prerequisite: build the AMX base environment first, following “AMX / prplOS development environment”; this article only compiles/runs the example.
Files
odl/amx-scheduler.odl
odl/amx-scheduler_definition.odl
src/scheduler_main.c
src/scheduler_event.c
ODL: objects and instances
amx-scheduler.odl:
%config {
storage-path = "${rw_data_path}/${name}/";
definition_file = "${name}_definition.odl";
defaults_dir = "${cfg-dir}/${name}/defaults/";
}
import "amx-scheduler.so" as "${name}";
include "${definition_file}";
%define {
entry-point amx-scheduler.scheduler_main;
}
amx-scheduler_definition.odl:
%define {
%persistent object Scheduler {
%persistent object Task[] {
%persistent %unique %key string Alias;
%persistent bool Enable = false;
%persistent string Second = "*";
%persistent string Minute = "*";
%persistent string Hour = "*";
%persistent string Month = "*";
%persistent string DayOfMonth = "*";
%persistent string DayOfWeek = "*";
%persistent uint32 Duration = 0;
%read-only string Status = "";
}
}
}
%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")';
}
Scheduler.Task[]is multi-instance;Aliasis the key;- cron fields (
Second/Minute/...) are passed tolibamxpcron; - instance add/remove/change trigger C functions.
C: entry and events
scheduler_main.c: entryscheduler_main(reason, dm, parser), stores dm/parser/scheduler;scheduler_event.c: implementstask_added/task_deleted/task_changed.
ODL declares; C implements — same as other data-model examples.
Compile/test on the AMX base environment
0. Environment
Dependencies: libamxc/libamxd/libamxo/libamxp + amxrt + a ubus backend. Prerequisite: AMX base environment.
1. Build
git clone https://gitlab.com/prpl-foundation/components/ambiorix/examples/datamodel/amx-scheduler.git
cd amx-scheduler
make
2. Start the bus
sudo ubusd -s /var/run/ubus/ubus.sock &
3. Run
sudo amxrt -N \
-o name=amx-scheduler \
-o rw_data_path=/tmp/amx-scheduler-data \
-I odl \
-L output/x86_64-linux-gnu/object \
-u ubus:/var/run/ubus/ubus.sock \
-B /usr/bin/mods/amxb/mod-amxb-ubus.so \
odl/amx-scheduler.odl
-o name=amx-scheduleris required: the ODL uses${name}to findamx-scheduler_definition.odl; without it,${name}becomesamxrtand the definition is not found.
4. Verify
ubus list
# Scheduler
# Scheduler.Task
ubus call Scheduler _get
Measured: Scheduler. is an empty object (no Task instances yet), with amxd-error-code: 0. The log may show:
INFO -- Load - Failed to load .../odl or directory is empty
That is expected: there is no persisted data yet.
5. Cleanup
sudo pkill -x amxrt
sudo pkill -x ubusd
What you learn
- multi-instance objects
Task[]and keys (Alias); - instance add/remove/change → events → C functions;
- persistence and
${name}paths; - cron is just fields; scheduling happens in
libamxp.
Limits
No default Task instances; to see cron in action, add one (ubus call Scheduler.Task _add or an ODL defaults file).
Next
cpu-info: read-only/volatile, CPU[] instances, read/list/describe actions.
Official example: amx-scheduler Deep dive: How ODL is parsed Series: AMX Official Examples.
Comments 0
No comments yet — be the first!