/* A tools bundle in C: one tool of its own and one seat verb, served over stdio. */ #include "mesh_sdk.h" #include static json_t *greet(json_t *args, char **error) { (void)error; const char *who = json_string_value(json_object_get(args, "who")); char greeting[128]; snprintf(greeting, sizeof greeting, "hello %s", who ? who : "world"); return json_pack("{s:s,s:s}", "greeting", greeting, "language", "c"); } static json_t *on(json_t *args, char **error) { (void)args; (void)error; return json_pack("{s:b,s:s}", "on", 1, "language", "c"); } int main(void) { json_t *who = json_pack("{s:{s:s,s:s}}", "who", "type", "string", "description", "whom"); const mesh_tool tools[] = { {"greet", "say hello", who, greet}, {"node-lamp.on", "the seat's verb", NULL, on}, }; int rc = mesh_serve("c-example", tools, 2); json_decref(who); return rc; }