Path: blob/main/crypto/krb5/src/util/verto/verto-module.h
34907 views
/*1* Copyright 2011 Red Hat, Inc.2*3* Permission is hereby granted, free of charge, to any person4* obtaining a copy of this software and associated documentation files5* (the "Software"), to deal in the Software without restriction,6* including without limitation the rights to use, copy, modify, merge,7* publish, distribute, sublicense, and/or sell copies of the Software,8* and to permit persons to whom the Software is furnished to do so,9* subject to the following conditions:10*11* The above copyright notice and this permission notice shall be12* included in all copies or substantial portions of the Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,15* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF16* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND17* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS18* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN19* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN20* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE21* SOFTWARE.22*/2324/*** THE FOLLOWING ARE FOR IMPLEMENTATION MODULES ONLY ***/2526#ifndef VERTO_MODULE_H_27#define VERTO_MODULE_H_2829#include <verto.h>3031#ifndef VERTO_MODULE_TYPES32#define VERTO_MODULE_TYPES33typedef void verto_mod_ctx;34typedef void verto_mod_ev;35#endif3637#define VERTO_MODULE_VERSION 338#define VERTO_MODULE_TABLE(name) verto_module_table_ ## name39#define VERTO_MODULE(name, symb, types) \40static verto_ctx_funcs name ## _funcs = { \41name ## _ctx_new, \42name ## _ctx_default, \43name ## _ctx_free, \44name ## _ctx_run, \45name ## _ctx_run_once, \46name ## _ctx_break, \47name ## _ctx_reinitialize, \48name ## _ctx_set_flags, \49name ## _ctx_add, \50name ## _ctx_del \51}; \52verto_module VERTO_MODULE_TABLE(name) = { \53VERTO_MODULE_VERSION, \54# name, \55# symb, \56types, \57&name ## _funcs, \58}; \59verto_ctx * \60verto_new_ ## name() \61{ \62return verto_convert(name, 0, NULL); \63} \64verto_ctx * \65verto_default_ ## name() \66{ \67return verto_convert(name, 1, NULL); \68}6970typedef struct {71/* Required */ verto_mod_ctx *(*ctx_new)();72/* Optional */ verto_mod_ctx *(*ctx_default)();73/* Required */ void (*ctx_free)(verto_mod_ctx *ctx);74/* Optional */ void (*ctx_run)(verto_mod_ctx *ctx);75/* Required */ void (*ctx_run_once)(verto_mod_ctx *ctx);76/* Optional */ void (*ctx_break)(verto_mod_ctx *ctx);77/* Optional */ void (*ctx_reinitialize)(verto_mod_ctx *ctx);78/* Optional */ void (*ctx_set_flags)(verto_mod_ctx *ctx,79const verto_ev *ev,80verto_mod_ev *modev);81/* Required */ verto_mod_ev *(*ctx_add)(verto_mod_ctx *ctx,82const verto_ev *ev,83verto_ev_flag *flags);84/* Required */ void (*ctx_del)(verto_mod_ctx *ctx,85const verto_ev *ev,86verto_mod_ev *modev);87} verto_ctx_funcs;8889typedef struct {90unsigned int vers;91const char *name;92const char *symb;93verto_ev_type types;94verto_ctx_funcs *funcs;95} verto_module;9697/**98* Converts an existing implementation specific loop to a verto_ctx.99*100* This function also sets the internal default implementation so that future101* calls to verto_new(NULL) or verto_default(NULL) will use this specific102* implementation if it was not already set.103*104* @param name The name of the module (unquoted)105* @param deflt Whether the ctx is the default context or not106* @param ctx The context to store107* @return A new verto_ctx, or NULL on error. Call verto_free() when done.108*/109#define verto_convert(name, deflt, ctx) \110verto_convert_module(&VERTO_MODULE_TABLE(name), deflt, ctx)111112/**113* Converts an existing implementation specific loop to a verto_ctx.114*115* If you are a module implementation, you probably want the macro above. This116* function is generally used directly only when an application is attempting117* to expose a home-grown event loop to verto.118*119* If deflt is non-zero and a default ctx was already defined for this module120* and ctx is not NULL, than ctx will be free'd and the previously defined121* default will be returned.122*123* If ctx is non-NULL, than the pre-existing verto_mod_ctx will be converted to124* to a verto_ctx; if deflt is non-zero than this verto_mod_ctx will also be125* marked as the default loop for this process. If ctx is NULL, than the126* appropriate constructor will be called: either module->ctx_new() or127* module->ctx_default() depending on the boolean value of deflt. If128* module->ctx_default is NULL and deflt is non-zero, than module->ctx_new()129* will be called and the resulting verto_mod_ctx will be utilized as the130* default.131*132* This function also sets the internal default implementation so that future133* calls to verto_new(NULL) or verto_default(NULL) will use this specific134* implementation if it was not already set.135*136* @param name The name of the module (unquoted)137* @param ctx The context private to store138* @return A new verto_ctx, or NULL on error. Call verto_free() when done.139*/140verto_ctx *141verto_convert_module(const verto_module *module, int deflt, verto_mod_ctx *ctx);142143/**144* Calls the callback of the verto_ev and then frees it via verto_del().145*146* The verto_ev is not freed (verto_del() is not called) if it is a signal event.147*148* @see verto_add_read()149* @see verto_add_write()150* @see verto_add_timeout()151* @see verto_add_idle()152* @see verto_add_signal()153* @see verto_add_child()154* @see verto_del()155* @param ev The verto_ev156*/157void158verto_fire(verto_ev *ev);159160/**161* Sets the status of the pid/handle which caused this event to fire.162*163* This function does nothing if the verto_ev is not a child type.164*165* @see verto_add_child()166* @param ev The verto_ev to set the status in.167* @param status The pid/handle status.168*/169void170verto_set_proc_status(verto_ev *ev, verto_proc_status status);171172/**173* Sets the state of the fd which caused this event to fire.174*175* This function does nothing if the verto_ev is not a io type.176*177* Only the flags VERTO_EV_FLAG_IO_(READ|WRITE|ERROR) are supported. All other178* flags are unset.179*180* @see verto_add_io()181* @param ev The verto_ev to set the state in.182* @param state The fd state.183*/184void185verto_set_fd_state(verto_ev *ev, verto_ev_flag state);186187#endif /* VERTO_MODULE_H_ */188189190