|
Packit |
fd8b60 |
/*
|
|
Packit |
fd8b60 |
* Copyright 2011 Red Hat, Inc.
|
|
Packit |
fd8b60 |
*
|
|
Packit |
fd8b60 |
* Permission is hereby granted, free of charge, to any person
|
|
Packit |
fd8b60 |
* obtaining a copy of this software and associated documentation files
|
|
Packit |
fd8b60 |
* (the "Software"), to deal in the Software without restriction,
|
|
Packit |
fd8b60 |
* including without limitation the rights to use, copy, modify, merge,
|
|
Packit |
fd8b60 |
* publish, distribute, sublicense, and/or sell copies of the Software,
|
|
Packit |
fd8b60 |
* and to permit persons to whom the Software is furnished to do so,
|
|
Packit |
fd8b60 |
* subject to the following conditions:
|
|
Packit |
fd8b60 |
*
|
|
Packit |
fd8b60 |
* The above copyright notice and this permission notice shall be
|
|
Packit |
fd8b60 |
* included in all copies or substantial portions of the Software.
|
|
Packit |
fd8b60 |
*
|
|
Packit |
fd8b60 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
Packit |
fd8b60 |
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
Packit |
fd8b60 |
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
Packit |
fd8b60 |
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
Packit |
fd8b60 |
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
Packit |
fd8b60 |
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
Packit |
fd8b60 |
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
Packit |
fd8b60 |
* SOFTWARE.
|
|
Packit |
fd8b60 |
*/
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
/*** THE FOLLOWING ARE FOR IMPLEMENTATION MODULES ONLY ***/
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
#ifndef VERTO_MODULE_H_
|
|
Packit |
fd8b60 |
#define VERTO_MODULE_H_
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
#include <verto.h>
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
#ifndef VERTO_MODULE_TYPES
|
|
Packit |
fd8b60 |
#define VERTO_MODULE_TYPES
|
|
Packit |
fd8b60 |
typedef void verto_mod_ctx;
|
|
Packit |
fd8b60 |
typedef void verto_mod_ev;
|
|
Packit |
fd8b60 |
#endif
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
#define VERTO_MODULE_VERSION 3
|
|
Packit |
fd8b60 |
#define VERTO_MODULE_TABLE(name) verto_module_table_ ## name
|
|
Packit |
fd8b60 |
#define VERTO_MODULE(name, symb, types) \
|
|
Packit |
fd8b60 |
static verto_ctx_funcs name ## _funcs = { \
|
|
Packit |
fd8b60 |
name ## _ctx_new, \
|
|
Packit |
fd8b60 |
name ## _ctx_default, \
|
|
Packit |
fd8b60 |
name ## _ctx_free, \
|
|
Packit |
fd8b60 |
name ## _ctx_run, \
|
|
Packit |
fd8b60 |
name ## _ctx_run_once, \
|
|
Packit |
fd8b60 |
name ## _ctx_break, \
|
|
Packit |
fd8b60 |
name ## _ctx_reinitialize, \
|
|
Packit |
fd8b60 |
name ## _ctx_set_flags, \
|
|
Packit |
fd8b60 |
name ## _ctx_add, \
|
|
Packit |
fd8b60 |
name ## _ctx_del \
|
|
Packit |
fd8b60 |
}; \
|
|
Packit |
fd8b60 |
verto_module VERTO_MODULE_TABLE(name) = { \
|
|
Packit |
fd8b60 |
VERTO_MODULE_VERSION, \
|
|
Packit |
fd8b60 |
# name, \
|
|
Packit |
fd8b60 |
# symb, \
|
|
Packit |
fd8b60 |
types, \
|
|
Packit |
fd8b60 |
&name ## _funcs, \
|
|
Packit |
fd8b60 |
}; \
|
|
Packit |
fd8b60 |
verto_ctx * \
|
|
Packit |
fd8b60 |
verto_new_ ## name() \
|
|
Packit |
fd8b60 |
{ \
|
|
Packit |
fd8b60 |
return verto_convert(name, 0, NULL); \
|
|
Packit |
fd8b60 |
} \
|
|
Packit |
fd8b60 |
verto_ctx * \
|
|
Packit |
fd8b60 |
verto_default_ ## name() \
|
|
Packit |
fd8b60 |
{ \
|
|
Packit |
fd8b60 |
return verto_convert(name, 1, NULL); \
|
|
Packit |
fd8b60 |
}
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
typedef struct {
|
|
Packit |
fd8b60 |
/* Required */ verto_mod_ctx *(*ctx_new)();
|
|
Packit |
fd8b60 |
/* Optional */ verto_mod_ctx *(*ctx_default)();
|
|
Packit |
fd8b60 |
/* Required */ void (*ctx_free)(verto_mod_ctx *ctx);
|
|
Packit |
fd8b60 |
/* Optional */ void (*ctx_run)(verto_mod_ctx *ctx);
|
|
Packit |
fd8b60 |
/* Required */ void (*ctx_run_once)(verto_mod_ctx *ctx);
|
|
Packit |
fd8b60 |
/* Optional */ void (*ctx_break)(verto_mod_ctx *ctx);
|
|
Packit |
fd8b60 |
/* Optional */ void (*ctx_reinitialize)(verto_mod_ctx *ctx);
|
|
Packit |
fd8b60 |
/* Optional */ void (*ctx_set_flags)(verto_mod_ctx *ctx,
|
|
Packit |
fd8b60 |
const verto_ev *ev,
|
|
Packit |
fd8b60 |
verto_mod_ev *modev);
|
|
Packit |
fd8b60 |
/* Required */ verto_mod_ev *(*ctx_add)(verto_mod_ctx *ctx,
|
|
Packit |
fd8b60 |
const verto_ev *ev,
|
|
Packit |
fd8b60 |
verto_ev_flag *flags);
|
|
Packit |
fd8b60 |
/* Required */ void (*ctx_del)(verto_mod_ctx *ctx,
|
|
Packit |
fd8b60 |
const verto_ev *ev,
|
|
Packit |
fd8b60 |
verto_mod_ev *modev);
|
|
Packit |
fd8b60 |
} verto_ctx_funcs;
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
typedef struct {
|
|
Packit |
fd8b60 |
unsigned int vers;
|
|
Packit |
fd8b60 |
const char *name;
|
|
Packit |
fd8b60 |
const char *symb;
|
|
Packit |
fd8b60 |
verto_ev_type types;
|
|
Packit |
fd8b60 |
verto_ctx_funcs *funcs;
|
|
Packit |
fd8b60 |
} verto_module;
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
/**
|
|
Packit |
fd8b60 |
* Converts an existing implementation specific loop to a verto_ctx.
|
|
Packit |
fd8b60 |
*
|
|
Packit |
fd8b60 |
* This function also sets the internal default implementation so that future
|
|
Packit |
fd8b60 |
* calls to verto_new(NULL) or verto_default(NULL) will use this specific
|
|
Packit |
fd8b60 |
* implementation if it was not already set.
|
|
Packit |
fd8b60 |
*
|
|
Packit |
fd8b60 |
* @param name The name of the module (unquoted)
|
|
Packit |
fd8b60 |
* @param deflt Whether the ctx is the default context or not
|
|
Packit |
fd8b60 |
* @param ctx The context to store
|
|
Packit |
fd8b60 |
* @return A new verto_ctx, or NULL on error. Call verto_free() when done.
|
|
Packit |
fd8b60 |
*/
|
|
Packit |
fd8b60 |
#define verto_convert(name, deflt, ctx) \
|
|
Packit |
fd8b60 |
verto_convert_module(&VERTO_MODULE_TABLE(name), deflt, ctx)
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
/**
|
|
Packit |
fd8b60 |
* Converts an existing implementation specific loop to a verto_ctx.
|
|
Packit |
fd8b60 |
*
|
|
Packit |
fd8b60 |
* If you are a module implementation, you probably want the macro above. This
|
|
Packit |
fd8b60 |
* function is generally used directly only when an application is attempting
|
|
Packit |
fd8b60 |
* to expose a home-grown event loop to verto.
|
|
Packit |
fd8b60 |
*
|
|
Packit |
fd8b60 |
* If deflt is non-zero and a default ctx was already defined for this module
|
|
Packit |
fd8b60 |
* and ctx is not NULL, than ctx will be free'd and the previously defined
|
|
Packit |
fd8b60 |
* default will be returned.
|
|
Packit |
fd8b60 |
*
|
|
Packit |
fd8b60 |
* If ctx is non-NULL, than the pre-existing verto_mod_ctx will be converted to
|
|
Packit |
fd8b60 |
* to a verto_ctx; if deflt is non-zero than this verto_mod_ctx will also be
|
|
Packit |
fd8b60 |
* marked as the default loop for this process. If ctx is NULL, than the
|
|
Packit |
fd8b60 |
* appropriate constructor will be called: either module->ctx_new() or
|
|
Packit |
fd8b60 |
* module->ctx_default() depending on the boolean value of deflt. If
|
|
Packit |
fd8b60 |
* module->ctx_default is NULL and deflt is non-zero, than module->ctx_new()
|
|
Packit |
fd8b60 |
* will be called and the resulting verto_mod_ctx will be utilized as the
|
|
Packit |
fd8b60 |
* default.
|
|
Packit |
fd8b60 |
*
|
|
Packit |
fd8b60 |
* This function also sets the internal default implementation so that future
|
|
Packit |
fd8b60 |
* calls to verto_new(NULL) or verto_default(NULL) will use this specific
|
|
Packit |
fd8b60 |
* implementation if it was not already set.
|
|
Packit |
fd8b60 |
*
|
|
Packit |
fd8b60 |
* @param name The name of the module (unquoted)
|
|
Packit |
fd8b60 |
* @param ctx The context private to store
|
|
Packit |
fd8b60 |
* @return A new verto_ctx, or NULL on error. Call verto_free() when done.
|
|
Packit |
fd8b60 |
*/
|
|
Packit |
fd8b60 |
verto_ctx *
|
|
Packit |
fd8b60 |
verto_convert_module(const verto_module *module, int deflt, verto_mod_ctx *ctx);
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
/**
|
|
Packit |
fd8b60 |
* Calls the callback of the verto_ev and then frees it via verto_del().
|
|
Packit |
fd8b60 |
*
|
|
Packit |
fd8b60 |
* The verto_ev is not freed (verto_del() is not called) if it is a signal event.
|
|
Packit |
fd8b60 |
*
|
|
Packit |
fd8b60 |
* @see verto_add_read()
|
|
Packit |
fd8b60 |
* @see verto_add_write()
|
|
Packit |
fd8b60 |
* @see verto_add_timeout()
|
|
Packit |
fd8b60 |
* @see verto_add_idle()
|
|
Packit |
fd8b60 |
* @see verto_add_signal()
|
|
Packit |
fd8b60 |
* @see verto_add_child()
|
|
Packit |
fd8b60 |
* @see verto_del()
|
|
Packit |
fd8b60 |
* @param ev The verto_ev
|
|
Packit |
fd8b60 |
*/
|
|
Packit |
fd8b60 |
void
|
|
Packit |
fd8b60 |
verto_fire(verto_ev *ev);
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
/**
|
|
Packit |
fd8b60 |
* Sets the status of the pid/handle which caused this event to fire.
|
|
Packit |
fd8b60 |
*
|
|
Packit |
fd8b60 |
* This function does nothing if the verto_ev is not a child type.
|
|
Packit |
fd8b60 |
*
|
|
Packit |
fd8b60 |
* @see verto_add_child()
|
|
Packit |
fd8b60 |
* @param ev The verto_ev to set the status in.
|
|
Packit |
fd8b60 |
* @param status The pid/handle status.
|
|
Packit |
fd8b60 |
*/
|
|
Packit |
fd8b60 |
void
|
|
Packit |
fd8b60 |
verto_set_proc_status(verto_ev *ev, verto_proc_status status);
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
/**
|
|
Packit |
fd8b60 |
* Sets the state of the fd which caused this event to fire.
|
|
Packit |
fd8b60 |
*
|
|
Packit |
fd8b60 |
* This function does nothing if the verto_ev is not a io type.
|
|
Packit |
fd8b60 |
*
|
|
Packit |
fd8b60 |
* Only the flags VERTO_EV_FLAG_IO_(READ|WRITE|ERROR) are supported. All other
|
|
Packit |
fd8b60 |
* flags are unset.
|
|
Packit |
fd8b60 |
*
|
|
Packit |
fd8b60 |
* @see verto_add_io()
|
|
Packit |
fd8b60 |
* @param ev The verto_ev to set the state in.
|
|
Packit |
fd8b60 |
* @param state The fd state.
|
|
Packit |
fd8b60 |
*/
|
|
Packit |
fd8b60 |
void
|
|
Packit |
fd8b60 |
verto_set_fd_state(verto_ev *ev, verto_ev_flag state);
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
#endif /* VERTO_MODULE_H_ */
|