From 88751e9e5ee3726b8a6987aeaae04e956c2234f5 Mon Sep 17 00:00:00 2001 From: midipix Date: Mon, 27 Jan 2020 08:36:51 -0500 Subject: created lib-app skeleton (foss21.org lib-app model). --- src/internal/tpax_driver_impl.h | 112 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 src/internal/tpax_driver_impl.h (limited to 'src/internal/tpax_driver_impl.h') diff --git a/src/internal/tpax_driver_impl.h b/src/internal/tpax_driver_impl.h new file mode 100644 index 0000000..49dea15 --- /dev/null +++ b/src/internal/tpax_driver_impl.h @@ -0,0 +1,112 @@ +/******************************************************/ +/* tpax: a topological pax implementation */ +/* Copyright (C) 2020 Z. Gilboa */ +/* Released under GPLv2 and GPLv3; see COPYING.TPAX. */ +/******************************************************/ + +#ifndef TPAX_DRIVER_IMPL_H +#define TPAX_DRIVER_IMPL_H + +#include +#include +#include + +#include +#include "tpax_dprintf_impl.h" +#include "argv/argv.h" + +#define TPAX_OPTV_ELEMENTS 64 + +extern const struct argv_option tpax_default_options[]; + +enum app_tags { + TAG_HELP, + TAG_VERSION, +}; + +struct tpax_driver_ctx_impl { + struct tpax_common_ctx cctx; + struct tpax_driver_ctx ctx; + struct tpax_fd_ctx fdctx; + const struct tpax_unit_ctx * euctx; + const char * eunit; + struct tpax_error_info ** errinfp; + struct tpax_error_info ** erricap; + struct tpax_error_info * erriptr[64]; + struct tpax_error_info erribuf[64]; +}; + +struct tpax_unit_ctx_impl { + const char * path; + struct tpax_unit_ctx uctx; +}; + + +static inline struct tpax_driver_ctx_impl * tpax_get_driver_ictx( + const struct tpax_driver_ctx * dctx) +{ + uintptr_t addr; + + if (dctx) { + addr = (uintptr_t)dctx - offsetof(struct tpax_driver_ctx_impl,ctx); + return (struct tpax_driver_ctx_impl *)addr; + } + + return 0; +} + +static inline void tpax_driver_set_ectx( + const struct tpax_driver_ctx * dctx, + const struct tpax_unit_ctx * uctx, + const char * unit) +{ + struct tpax_driver_ctx_impl * ictx; + + ictx = tpax_get_driver_ictx(dctx); + ictx->euctx = uctx; + ictx->eunit = unit; +} + +static inline int tpax_driver_fdin(const struct tpax_driver_ctx * dctx) +{ + struct tpax_fd_ctx fdctx; + tpax_get_driver_fdctx(dctx,&fdctx); + return fdctx.fdin; +} + +static inline int tpax_driver_fdout(const struct tpax_driver_ctx * dctx) +{ + struct tpax_fd_ctx fdctx; + tpax_get_driver_fdctx(dctx,&fdctx); + return fdctx.fdout; +} + +static inline int tpax_driver_fderr(const struct tpax_driver_ctx * dctx) +{ + struct tpax_fd_ctx fdctx; + tpax_get_driver_fdctx(dctx,&fdctx); + return fdctx.fderr; +} + +static inline int tpax_driver_fdlog(const struct tpax_driver_ctx * dctx) +{ + struct tpax_fd_ctx fdctx; + tpax_get_driver_fdctx(dctx,&fdctx); + return fdctx.fdlog; +} + +static inline int tpax_driver_fdcwd(const struct tpax_driver_ctx * dctx) +{ + struct tpax_fd_ctx fdctx; + tpax_get_driver_fdctx(dctx,&fdctx); + return fdctx.fdcwd; +} + +static inline int tpax_driver_fddst(const struct tpax_driver_ctx * dctx) +{ + struct tpax_fd_ctx fdctx; + tpax_get_driver_fdctx(dctx,&fdctx); + return fdctx.fddst; +} + +#endif -- cgit v1.2.3