annotate CSP2/CSP2_env/env-d9b9114564458d9d-741b3de822f2aaca6c6caa4325c4afce/include/verto-module.h @ 69:33d812a61356

planemo upload commit 2e9511a184a1ca667c7be0c6321a36dc4e3d116d
author jpayne
date Tue, 18 Mar 2025 17:55:14 -0400
parents
children
rev   line source
jpayne@69 1 /*
jpayne@69 2 * Copyright 2011 Red Hat, Inc.
jpayne@69 3 *
jpayne@69 4 * Permission is hereby granted, free of charge, to any person
jpayne@69 5 * obtaining a copy of this software and associated documentation files
jpayne@69 6 * (the "Software"), to deal in the Software without restriction,
jpayne@69 7 * including without limitation the rights to use, copy, modify, merge,
jpayne@69 8 * publish, distribute, sublicense, and/or sell copies of the Software,
jpayne@69 9 * and to permit persons to whom the Software is furnished to do so,
jpayne@69 10 * subject to the following conditions:
jpayne@69 11 *
jpayne@69 12 * The above copyright notice and this permission notice shall be
jpayne@69 13 * included in all copies or substantial portions of the Software.
jpayne@69 14 *
jpayne@69 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
jpayne@69 16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
jpayne@69 17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
jpayne@69 18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
jpayne@69 19 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
jpayne@69 20 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
jpayne@69 21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
jpayne@69 22 * SOFTWARE.
jpayne@69 23 */
jpayne@69 24
jpayne@69 25 /*** THE FOLLOWING ARE FOR IMPLEMENTATION MODULES ONLY ***/
jpayne@69 26
jpayne@69 27 #ifndef VERTO_MODULE_H_
jpayne@69 28 #define VERTO_MODULE_H_
jpayne@69 29
jpayne@69 30 #include <verto.h>
jpayne@69 31
jpayne@69 32 #ifndef VERTO_MODULE_TYPES
jpayne@69 33 #define VERTO_MODULE_TYPES
jpayne@69 34 typedef void verto_mod_ctx;
jpayne@69 35 typedef void verto_mod_ev;
jpayne@69 36 #endif
jpayne@69 37
jpayne@69 38 #define VERTO_MODULE_VERSION 3
jpayne@69 39 #define VERTO_MODULE_TABLE(name) verto_module_table_ ## name
jpayne@69 40 #define VERTO_MODULE(name, symb, types) \
jpayne@69 41 static verto_ctx_funcs name ## _funcs = { \
jpayne@69 42 name ## _ctx_new, \
jpayne@69 43 name ## _ctx_default, \
jpayne@69 44 name ## _ctx_free, \
jpayne@69 45 name ## _ctx_run, \
jpayne@69 46 name ## _ctx_run_once, \
jpayne@69 47 name ## _ctx_break, \
jpayne@69 48 name ## _ctx_reinitialize, \
jpayne@69 49 name ## _ctx_set_flags, \
jpayne@69 50 name ## _ctx_add, \
jpayne@69 51 name ## _ctx_del \
jpayne@69 52 }; \
jpayne@69 53 verto_module VERTO_MODULE_TABLE(name) = { \
jpayne@69 54 VERTO_MODULE_VERSION, \
jpayne@69 55 # name, \
jpayne@69 56 # symb, \
jpayne@69 57 types, \
jpayne@69 58 &name ## _funcs, \
jpayne@69 59 }; \
jpayne@69 60 verto_ctx * \
jpayne@69 61 verto_new_ ## name() \
jpayne@69 62 { \
jpayne@69 63 return verto_convert(name, 0, NULL); \
jpayne@69 64 } \
jpayne@69 65 verto_ctx * \
jpayne@69 66 verto_default_ ## name() \
jpayne@69 67 { \
jpayne@69 68 return verto_convert(name, 1, NULL); \
jpayne@69 69 }
jpayne@69 70
jpayne@69 71 typedef struct {
jpayne@69 72 /* Required */ verto_mod_ctx *(*ctx_new)();
jpayne@69 73 /* Optional */ verto_mod_ctx *(*ctx_default)();
jpayne@69 74 /* Required */ void (*ctx_free)(verto_mod_ctx *ctx);
jpayne@69 75 /* Optional */ void (*ctx_run)(verto_mod_ctx *ctx);
jpayne@69 76 /* Required */ void (*ctx_run_once)(verto_mod_ctx *ctx);
jpayne@69 77 /* Optional */ void (*ctx_break)(verto_mod_ctx *ctx);
jpayne@69 78 /* Optional */ void (*ctx_reinitialize)(verto_mod_ctx *ctx);
jpayne@69 79 /* Optional */ void (*ctx_set_flags)(verto_mod_ctx *ctx,
jpayne@69 80 const verto_ev *ev,
jpayne@69 81 verto_mod_ev *modev);
jpayne@69 82 /* Required */ verto_mod_ev *(*ctx_add)(verto_mod_ctx *ctx,
jpayne@69 83 const verto_ev *ev,
jpayne@69 84 verto_ev_flag *flags);
jpayne@69 85 /* Required */ void (*ctx_del)(verto_mod_ctx *ctx,
jpayne@69 86 const verto_ev *ev,
jpayne@69 87 verto_mod_ev *modev);
jpayne@69 88 } verto_ctx_funcs;
jpayne@69 89
jpayne@69 90 typedef struct {
jpayne@69 91 unsigned int vers;
jpayne@69 92 const char *name;
jpayne@69 93 const char *symb;
jpayne@69 94 verto_ev_type types;
jpayne@69 95 verto_ctx_funcs *funcs;
jpayne@69 96 } verto_module;
jpayne@69 97
jpayne@69 98 /**
jpayne@69 99 * Converts an existing implementation specific loop to a verto_ctx.
jpayne@69 100 *
jpayne@69 101 * This function also sets the internal default implementation so that future
jpayne@69 102 * calls to verto_new(NULL) or verto_default(NULL) will use this specific
jpayne@69 103 * implementation if it was not already set.
jpayne@69 104 *
jpayne@69 105 * @param name The name of the module (unquoted)
jpayne@69 106 * @param deflt Whether the ctx is the default context or not
jpayne@69 107 * @param ctx The context to store
jpayne@69 108 * @return A new verto_ctx, or NULL on error. Call verto_free() when done.
jpayne@69 109 */
jpayne@69 110 #define verto_convert(name, deflt, ctx) \
jpayne@69 111 verto_convert_module(&VERTO_MODULE_TABLE(name), deflt, ctx)
jpayne@69 112
jpayne@69 113 /**
jpayne@69 114 * Converts an existing implementation specific loop to a verto_ctx.
jpayne@69 115 *
jpayne@69 116 * If you are a module implementation, you probably want the macro above. This
jpayne@69 117 * function is generally used directly only when an application is attempting
jpayne@69 118 * to expose a home-grown event loop to verto.
jpayne@69 119 *
jpayne@69 120 * If deflt is non-zero and a default ctx was already defined for this module
jpayne@69 121 * and ctx is not NULL, than ctx will be free'd and the previously defined
jpayne@69 122 * default will be returned.
jpayne@69 123 *
jpayne@69 124 * If ctx is non-NULL, than the pre-existing verto_mod_ctx will be converted to
jpayne@69 125 * to a verto_ctx; if deflt is non-zero than this verto_mod_ctx will also be
jpayne@69 126 * marked as the default loop for this process. If ctx is NULL, than the
jpayne@69 127 * appropriate constructor will be called: either module->ctx_new() or
jpayne@69 128 * module->ctx_default() depending on the boolean value of deflt. If
jpayne@69 129 * module->ctx_default is NULL and deflt is non-zero, than module->ctx_new()
jpayne@69 130 * will be called and the resulting verto_mod_ctx will be utilized as the
jpayne@69 131 * default.
jpayne@69 132 *
jpayne@69 133 * This function also sets the internal default implementation so that future
jpayne@69 134 * calls to verto_new(NULL) or verto_default(NULL) will use this specific
jpayne@69 135 * implementation if it was not already set.
jpayne@69 136 *
jpayne@69 137 * @param name The name of the module (unquoted)
jpayne@69 138 * @param ctx The context private to store
jpayne@69 139 * @return A new verto_ctx, or NULL on error. Call verto_free() when done.
jpayne@69 140 */
jpayne@69 141 verto_ctx *
jpayne@69 142 verto_convert_module(const verto_module *module, int deflt, verto_mod_ctx *ctx);
jpayne@69 143
jpayne@69 144 /**
jpayne@69 145 * Calls the callback of the verto_ev and then frees it via verto_del().
jpayne@69 146 *
jpayne@69 147 * The verto_ev is not freed (verto_del() is not called) if it is a signal event.
jpayne@69 148 *
jpayne@69 149 * @see verto_add_read()
jpayne@69 150 * @see verto_add_write()
jpayne@69 151 * @see verto_add_timeout()
jpayne@69 152 * @see verto_add_idle()
jpayne@69 153 * @see verto_add_signal()
jpayne@69 154 * @see verto_add_child()
jpayne@69 155 * @see verto_del()
jpayne@69 156 * @param ev The verto_ev
jpayne@69 157 */
jpayne@69 158 void
jpayne@69 159 verto_fire(verto_ev *ev);
jpayne@69 160
jpayne@69 161 /**
jpayne@69 162 * Sets the status of the pid/handle which caused this event to fire.
jpayne@69 163 *
jpayne@69 164 * This function does nothing if the verto_ev is not a child type.
jpayne@69 165 *
jpayne@69 166 * @see verto_add_child()
jpayne@69 167 * @param ev The verto_ev to set the status in.
jpayne@69 168 * @param status The pid/handle status.
jpayne@69 169 */
jpayne@69 170 void
jpayne@69 171 verto_set_proc_status(verto_ev *ev, verto_proc_status status);
jpayne@69 172
jpayne@69 173 /**
jpayne@69 174 * Sets the state of the fd which caused this event to fire.
jpayne@69 175 *
jpayne@69 176 * This function does nothing if the verto_ev is not a io type.
jpayne@69 177 *
jpayne@69 178 * Only the flags VERTO_EV_FLAG_IO_(READ|WRITE|ERROR) are supported. All other
jpayne@69 179 * flags are unset.
jpayne@69 180 *
jpayne@69 181 * @see verto_add_io()
jpayne@69 182 * @param ev The verto_ev to set the state in.
jpayne@69 183 * @param state The fd state.
jpayne@69 184 */
jpayne@69 185 void
jpayne@69 186 verto_set_fd_state(verto_ev *ev, verto_ev_flag state);
jpayne@69 187
jpayne@69 188 #endif /* VERTO_MODULE_H_ */