/* * A plugin for tests/test_lifecycle: registers a tool and a ticking widget, * then fails its init when SP_TEST_INIT_FAIL is set. Its shutdown() writes * SP_TEST_SHUTDOWN_FILE, so the test can see that it ran. */ #include #include #include "splinter.h" #include "splinter_plugin.h" static int lc_tool(const char *args, struct sp_buf *out, void *ctx) { (void)args; (void)ctx; return sp_buf_puts(out, "lifecycle"); } static int lc_tick(struct sp_host *h, const char *name, void *ctx) { (void)ctx; return sp_host_widget_text(h, name, "tick"); } static const struct sp_tool tool = { "lifecycle_tool", "test", "{\"type\":\"object\"}", SP_AUTH_READ, lc_tool, NULL }; static const struct sp_widget widget = { "lifecycle", lc_tick, NULL, NULL, 50 }; static int lc_init(struct sp_host *h) { if (sp_host_add_tool(h, &tool) != 0 || sp_host_add_widget(h, &widget) != 0) return -1; return getenv("SP_TEST_INIT_FAIL") != NULL ? -1 : 0; } static void lc_shutdown(struct sp_host *h) { const char *path = getenv("SP_TEST_SHUTDOWN_FILE"); FILE *f; (void)h; if (path != NULL && (f = fopen(path, "w")) != NULL) { fputs("shut down\n", f); fclose(f); } } static const struct sp_plugin plugin = { SP_PLUGIN_ABI, "lifecycle", "1.0.0", lc_init, NULL, lc_shutdown }; const struct sp_plugin * sp_plugin_describe(void) { return &plugin; }