← All posts

Official example 04: greeter_app — putting AMX into an existing event loop

Grow through practice

No need to finish reading — test now

One line: greeter_plugin is a plugin; greeter_app is a standalone executable. The data model is the same; what changes is “who starts it and where C functions come from”. Prerequisite: build the AMX base environment first, following “AMX / prplOS development environment”; this article only compiles/runs the example.

app vs plugin

greeter_plugingreeter_app
Startupamxrt loads the .soits own main()
ODLimport + entry-pointno import/entry-point
Symbol resolutionimport resolver (_x)ftab (amxo_resolver_ftab_add)
Good forplugins/servicesan existing app / event loop

Why ftab is required

The import resolver uses dlopen/dlsym, which only resolves symbols in shared objects. An executable (app) is not a .so, so call Greeter.say cannot find _Greeter_say — the function pointers must be registered in the function table (ftab) before parsing.

main.c key steps

amxrt_new();
amxo_parser_t* parser = amxrt_get_parser();

amxo_resolver_ftab_add(parser, "Greeter.say", AMXO_FUNC(_Greeter_say));
amxo_resolver_ftab_add(parser, "Greeter.setMaxHistory", AMXO_FUNC(_Greeter_setMaxHistory));
amxo_resolver_ftab_add(parser, "check_change", AMXO_FUNC(_State_check_change));
amxo_resolver_ftab_add(parser, "enable_greeter", AMXO_FUNC(_enable_greeter));
/* ...register every call/action that appears in the ODL... */

int rc = amxrt(argc, argv, NULL);   // CLI, backends/ODL, register DM
amxrt_delete();
  • amxrt_new / amxrt_get_parser: initialize the runtime and parser;
  • amxo_resolver_ftab_add: bind ODL names to C functions;
  • amxrt(): libamxrt takes over CLI, backends, ODL and registration;
  • by default it uses the executable name greeter to find /etc/amx/greeter/greeter.odl.

ODL differences

greeter_app/odl/greeter.odl has no:

import "${name}.so" as "${name}";
%define { entry-point greeter.greeter_main; }

Only:

%config { ... }
include "${definition_file}";
#include "${extra_file}";
?include "${save_file}":"${defaults_file}";

because libamxrt already handles startup/registration.

Compile / run on the AMX base environment

Dependencies: libamxc, libamxd, libamxo, libamxp (plus libamxrt).

make
sudo make install
greeter

On start it prints Greeter started; the ubus/RPC operations from the greeter_plugin README apply as well.

Verification status

  • ✅ source/README: app/plugin differences, ftab registration, amxrt() flow;
  • ⚠️ not run locally: build/run per README, not measured;
  • ❓ dependency detail: the README lists four libs, but main.c uses libamxrt; trust the makefile.

One sentence

Plugins use import; apps use ftab. The data model does not change; what changes is “who starts it and where symbols come from”.


Official example: greeter_app Related: 02 greeter_plugin ODL · AMXRT is a runtime Series: AMX Official Examples.

Practice

Found this useful?

I write about AI agents × embedded / edge AI. Subscribe, or email me a concrete problem.

Guestbook →Subscribe (RSS)Support

Comments 0

No comments yet — be the first!

No login required; name is optional.