thrum (C)
the thrum client for a bee written in C
A C bee reaches humd through hum’s own client. A thrum_bee runs
hum bee link, which enters the bee, signs its hello, reads humd’s
verdict, reconnects when humd restarts, and checks every tone against the
thrum. Every language gets that same client, so a C bee behaves exactly
as a Rust, TS, Python or Go one. It links only cJSON:
brew install pkgconf cjson # macOSsudo apt-get install pkg-config libcjson-dev # Debian, Ubuntustatic void on_prompt(thrum_bee *bee, const cJSON *tone, void *user) { /* build an unfurl and a wilt for the tone's sid, then thrum_bee_send each */}
thrum_options opts = {.hive = "my-hive", .as = "main", .role = THRUM_ROLE_NURSE, .hello = hello};thrum_bee *bee = thrum_bee_new(&opts);thrum_bee_on(bee, THRUM_CHI_PROMPT, on_prompt, NULL);if (thrum_bee_start(bee) != 0) fprintf(stderr, "%s\n", thrum_bee_error(bee));int how = thrum_bee_wait(bee);thrum_bee_free(bee);thrum_bee_new(&opts) | a bee’s client; nothing runs until thrum_bee_start |
thrum_bee_on, thrum_bee_on_sid, thrum_bee_off_sid, thrum_bee_on_any | a tone goes to its sid’s handler, else its chi’s, else the any handler |
thrum_bee_on_nestled, thrum_bee_on_astray, thrum_bee_on_advisory | humd admitted the bee; humd went away; something to fix |
thrum_bee_start | returns once humd admits the bee (0), or THRUM_LINK_REFUSED, or THRUM_LINK_FAILED |
thrum_bee_send, thrum_bee_hello | send a tone, given a rid if it has none; change the hello |
thrum_bee_close, thrum_bee_wait | close the link; how the link ended |
hum is found at $HUM_CLI, else on PATH, else ~/.local/bin/hum. A
bee’s Makefile includes thrum.mk for the flags and $(THRUM_LIB).
Every source under thrum/ is generated by cargo run -p codegen:
chi.h and protocol.h from thrum-core, link.h, link.c and
thrum.h from codegen/templates/c with the link’s constants from
hum-thrum. make test checks the views against thrum-core’s golden
tones, and examples/echo_bee.c is the bee the conformance run
(cargo test -p hum --test conform) drives in every language.