From 635b33df0f7d567626fab4f1acaa91e5609e92ca Mon Sep 17 00:00:00 2001 From: bigfoot547 Date: Fri, 14 Nov 2025 22:13:45 -0600 Subject: update some stuff --- pipeline.h | 65 ++++++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 40 insertions(+), 25 deletions(-) (limited to 'pipeline.h') diff --git a/pipeline.h b/pipeline.h index e164c58..562f1df 100644 --- a/pipeline.h +++ b/pipeline.h @@ -3,39 +3,54 @@ #include #include +#include + #include "config.h" -#define PIPELINE_STAGE ATTR_WUR +#define PIPELINE_STAGE ATTR_WUR ATTR_ACCESS((read_only, 1)) +#define PIPELINE_INIT ATTR_ACCESS((read_only, 1)) +#define PIPELINE_CLEANUP ATTR_ACCESS((read_only, 1)) -struct pipeline_ctx_t; -typedef int (pipeline_stage_proc)(struct pipeline_ctx_t * /*ctx*/, void * /*data*/, size_t /*len*/) PIPELINE_STAGE; +typedef struct ptx__pipeline_ctx_tag ptx_pipeline_ctx_t; +typedef struct ptx__pipeline_tag ptx_pipeline_t; -struct pipeline_stage_t -{ - const char *name; - pipeline_stage_proc *proc; - struct pipeline_stage_t *next; - void *user; -}; +typedef int (ptx_pipeline_proc_t)(const ptx_pipeline_ctx_t * /*ctx*/, void * /*data*/, size_t /*len*/) PIPELINE_STAGE; +typedef int (ptx_pipeline_init_proc_t)(const char * /*name*/, void ** /*ppuser*/, va_list /*init_args*/) PIPELINE_INIT; +typedef void (ptx_pipeline_cleanup_proc_t)(const char * /*name*/, void * /*puser*/) PIPELINE_CLEANUP; -struct pipeline_t -{ - struct pipeline_stage_t *first; +struct ptx_pipeline_stage_funcs { + ptx_pipeline_proc_t *handler; + ptx_pipeline_init_proc_t *init; + ptx_pipeline_cleanup_proc_t *cleanup; }; -struct pipeline_ctx_t -{ - struct pipeline_stage_t *stage; -}; +/* allocates a new pipeline, with space for `initial_size' new stages. */ +ptx_pipeline_t *ptx_pipeline_new(size_t initial_size) ATTR_WUR ATTR_MALLOC() ATTR_MALLOC((ptx_pipeline_free, 1)); + +/* frees an existing pipeline stage. note that this will call the cleanup function in the stages as well. */ +void ptx_pipeline_free(ptx_pipeline_t *pl); + +/* adds `stage' with `name' to `pipeline' after `after' * + * returns: number of stages added to pipeline (0 or 1), or -1 if there was an allocation or initialization error. */ +int ptx_pipeline_add_after(ptx_pipeline_t *pipeline, const struct ptx_pipeline_stage_funcs *stage, const char *name, const char *after, ...); +/* adds `stage' with `name' to `pipeline' before `before' + * returns: number of stages added to pipeline (0 or 1), or -1 if there was an allocation or initialization error. */ +int ptx_pipeline_add_before(ptx_pipeline_t *pipeline, const struct ptx_pipeline_stage_funcs *stage, const char *name, const char *before, ...); + +/* TODO: could theoretically have versions of the above functions that don't defensively copy `name' */ + +/* returns: number of stages removed from pipeline */ +int ptx_pipeline_remove_stage(ptx_pipeline_t *pipeline, const char *name); + +/* this pointer is guaranteed to be valid as long as the pipeline context is active (i.e., within this handler function) + * If you need to access user data of a stage from outside of a handler function, TODO */ +void **ptx_pipeline_ctx_get_user(const ptx_pipeline_ctx_t *ctx); +const char *ptx_pipeline_ctx_get_name(const ptx_pipeline_ctx_t *ctx); + +int ptx_pipeline_ctx_next(const ptx_pipeline_ctx_t *ctx, void *nextdata, size_t nextsize); -int pipeline_add_stage_before(struct pipeline_t *pl, struct pipeline_stage_t *stage, const char *name); -int pipeline_add_stage_after(struct pipeline_t *pl, struct pipeline_stage_t *stage, const char *name); +void ptx_pipeline_ctx_diag(const ptx_pipeline_ctx_t *ctx, int lvl, const char *fmt, ...) ATTR_FORMAT((printf, 3, 4)); /* TODO: pipeline stages should be able to send diagnostic messages */ -ATTR_ALWAYS_INLINE inline int pipeline_next(struct pipeline_ctx_t *ctx, void *data, size_t len) -{ - assert(ctx->stage->next); - ctx->stage = ctx->stage->next; - return (ctx->stage->proc)(ctx, data, len); -} +int ptx_pipeline_handle(ptx_pipeline_t *pipeline, void *data, size_t sz); /* TODO: diagnostic */ #endif /* include guard */ -- cgit v1.2.3-70-g09d2