From 635b33df0f7d567626fab4f1acaa91e5609e92ca Mon Sep 17 00:00:00 2001 From: bigfoot547 Date: Fri, 14 Nov 2025 22:13:45 -0600 Subject: update some stuff --- main.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 70 insertions(+), 10 deletions(-) (limited to 'main.c') diff --git a/main.c b/main.c index e1e22ec..be91332 100644 --- a/main.c +++ b/main.c @@ -1,25 +1,61 @@ +#include +#include +#include +#include + #include "pipeline.h" #define UNUSED(_v) ((void)(_v)) -PIPELINE_STAGE int stage(struct pipeline_ctx_t *ctx, void *data, size_t len) +PIPELINE_STAGE int identity_stage_handle(const ptx_pipeline_ctx_t *ctx, void *data, size_t sz) +{ + return ptx_pipeline_ctx_next(ctx, data, sz); +} + +PIPELINE_INIT int debug_stage_init(const char *name, void **ppuser, va_list init_args) +{ + static const char *const messages[] = { "no continue :(", "continue :)" }; + + UNUSED(name); + + int config = !!va_arg(init_args, int); + *ppuser = (void *)(uintptr_t)config; + + printf("Debug stage %s (init): %s\n", name, messages[config]); + + return 0; +} + +PIPELINE_CLEANUP void debug_stage_cleanup(const char *name, void *puser) { - UNUSED(ctx); - UNUSED(data); - UNUSED(len); - return 1; + printf("Debug stage %s (cleanup): %p\n", name, puser); } -PIPELINE_STAGE int identity_stage(struct pipeline_ctx_t *ctx, void *data, size_t len) { - return pipeline_next(ctx, data, len); +PIPELINE_STAGE int debug_stage_handle(const ptx_pipeline_ctx_t *ctx, void *data, size_t sz) +{ + bool cont = !!(uintptr_t)(*ptx_pipeline_ctx_get_user(ctx)); + printf("Debug stage %s:\n Data: %p\n Size: %zu\n", ptx_pipeline_ctx_get_name(ctx), data, sz); + return cont ? ptx_pipeline_ctx_next(ctx, data, sz) : 0; } +static const struct ptx_pipeline_stage_funcs identity_stage = { + .init = NULL, + .handler = &identity_stage_handle, + .cleanup = NULL +}; + +static const struct ptx_pipeline_stage_funcs debug_stage = { + .init = &debug_stage_init, + .handler = &debug_stage_handle, + .cleanup = &debug_stage_cleanup +}; + /* mockup: * Pipeline signature: D -> D*1 * int simple_1to1_stage(struct pipeline_ctx *ctx, void *data, size_t len) { * void *out = ... transform data ...; * size_t out_len = ^^^; - * return pipeline_next(ctx, out, out_len); + * return ptx_pipeline_next(ctx, out, out_len); * } * * Pipeline signature: D -> D*(0,n) @@ -30,7 +66,7 @@ PIPELINE_STAGE int identity_stage(struct pipeline_ctx_t *ctx, void *data, size_t * return -1; ... next_data failed somehow ... * } * - * if ((err = pipeline_next(ctx, out, out_len)) < 0) { + * if ((err = ptx_pipeline_next(ctx, out, out_len)) < 0) { * return err; * } * } @@ -41,7 +77,7 @@ PIPELINE_STAGE int identity_stage(struct pipeline_ctx_t *ctx, void *data, size_t * int stateful_stage(struct pipeline_ctx *ctx, void *data, size_t len) { * my_stage_t *stg = ctx->me; * stg->stat_in += len; - * return pipeline_next(ctx, data, len); + * return ptx_pipeline_next(ctx, data, len); * } * * Pipeline signature: D -> void (i.e., never calls next) @@ -53,5 +89,29 @@ PIPELINE_STAGE int identity_stage(struct pipeline_ctx_t *ctx, void *data, size_t */ int main(void) { + ptx_pipeline_t *pl = ptx_pipeline_new(1); + if (!pl) { + fputs("Allocation failure: pipeline\n", stderr); + return 1; + } + + if (ptx_pipeline_add_before(pl, &identity_stage, "identity1", NULL) < 0) { + fputs("Failed to add identity1 to pipeline\n", stderr); + return 1; + } + + if (ptx_pipeline_add_after(pl, &debug_stage, "debug1", "identity1", true) < 0) { + fputs("Failed to add debug1 to pipeline\n", stderr); + return 1; + } + + if (ptx_pipeline_add_after(pl, &debug_stage, "debug2", "debug1", false) < 0) { + fputs("Failed to add debug2 to pipeline\n", stderr); + return 1; + } + + printf("Handle returned: %d\n", ptx_pipeline_handle(pl, "sussy", 10)); + ptx_pipeline_free(pl); + return 0; } -- cgit v1.2.3-70-g09d2