Sat Aug 6 00:39:29 2011

Asterisk developer's documentation


io.h

Go to the documentation of this file.
00001 /*
00002  * Asterisk -- An open source telephony toolkit.
00003  *
00004  * Copyright (C) 1999 - 2005, Digium, Inc.
00005  *
00006  * Mark Spencer <markster@digium.com>
00007  *
00008  * See http://www.asterisk.org for more information about
00009  * the Asterisk project. Please do not directly contact
00010  * any of the maintainers of this project for assistance;
00011  * the project provides a web site, mailing lists and IRC
00012  * channels for your use.
00013  *
00014  * This program is free software, distributed under the terms of
00015  * the GNU General Public License Version 2. See the LICENSE file
00016  * at the top of the source tree.
00017  */
00018 
00019 /*! \file
00020  * \brief I/O Management (derived from Cheops-NG)
00021  */
00022 
00023 #ifndef _ASTERISK_IO_H
00024 #define _ASTERISK_IO_H
00025 
00026 #include "asterisk/poll-compat.h"
00027 
00028 #if defined(__cplusplus) || defined(c_plusplus)
00029 extern "C" {
00030 #endif
00031 
00032 /*! Input ready */
00033 #define AST_IO_IN    POLLIN
00034 /*! Output ready */
00035 #define AST_IO_OUT   POLLOUT
00036 /*! Priority input ready */
00037 #define AST_IO_PRI   POLLPRI
00038 
00039 /* Implicitly polled for */
00040 /*! Error condition (errno or getsockopt) */
00041 #define AST_IO_ERR   POLLERR
00042 /*! Hangup */
00043 #define AST_IO_HUP   POLLHUP
00044 /*! Invalid fd */
00045 #define AST_IO_NVAL  POLLNVAL
00046 
00047 /*
00048  * An Asterisk IO callback takes its id, a file descriptor, list of events, and
00049  * callback data as arguments and returns 0 if it should not be
00050  * run again, or non-zero if it should be run again.
00051  */
00052 
00053 struct io_context;
00054 
00055 /*! Creates a context */
00056 /*!
00057  * Create a context for I/O operations
00058  * Basically mallocs an IO structure and sets up some default values.
00059  * Returns an allocated io_context structure
00060  */
00061 struct io_context *io_context_create(void);
00062 
00063 /*! Destroys a context */
00064 /*
00065  * \param ioc structure to destroy
00066  * Destroy a context for I/O operations
00067  * Frees all memory associated with the given io_context structure along with the structure itself
00068  */
00069 void io_context_destroy(struct io_context *ioc);
00070 
00071 typedef int (*ast_io_cb)(int *id, int fd, short events, void *cbdata);
00072 #define AST_IO_CB(a) ((ast_io_cb)(a))
00073 
00074 /*! Adds an IO context */
00075 /*!
00076  * \param ioc which context to use
00077  * \param fd which fd to monitor
00078  * \param callback callback function to run
00079  * \param events event mask of events to wait for
00080  * \param data data to pass to the callback
00081  * Watch for any of revents activites on fd, calling callback with data as
00082  * callback data.  Returns a pointer to ID of the IO event, or NULL on failure.
00083  */
00084 int *ast_io_add(struct io_context *ioc, int fd, ast_io_cb callback, short events, void *data);
00085 
00086 /*! Changes an IO handler */
00087 /*!
00088  * \param ioc which context to use
00089  * \param id
00090  * \param fd the fd you wish it to contain now
00091  * \param callback new callback function
00092  * \param events event mask to wait for
00093  * \param data data to pass to the callback function
00094  * Change an i/o handler, updating fd if > -1, callback if non-null, and revents
00095  * if >-1, and data if non-null.  Returns a pointero to the ID of the IO event,
00096  * or NULL on failure.
00097  */
00098 int *ast_io_change(struct io_context *ioc, int *id, int fd, ast_io_cb callback, short events, void *data);
00099 
00100 /*! Removes an IO context */
00101 /*!
00102  * \param ioc which io_context to remove it from
00103  * \param id which ID to remove
00104  * Remove an I/O id from consideration  Returns 0 on success or -1 on failure.
00105  */
00106 int ast_io_remove(struct io_context *ioc, int *id);
00107 
00108 /*! Waits for IO */
00109 /*!
00110  * \param ioc which context to act upon
00111  * \param howlong how many milliseconds to wait
00112  * Wait for I/O to happen, returning after
00113  * howlong milliseconds, and after processing
00114  * any necessary I/O.  Returns the number of
00115  * I/O events which took place.
00116  */
00117 int ast_io_wait(struct io_context *ioc, int howlong);
00118 
00119 /*! Dumps the IO array */
00120 /*
00121  * Debugging: Dump everything in the I/O array
00122  */
00123 void ast_io_dump(struct io_context *ioc);
00124 
00125 /*! Set fd into non-echoing mode (if fd is a tty) */
00126 
00127 int ast_hide_password(int fd);
00128 
00129 /*! Restores TTY mode */
00130 /*
00131  * Call with result from previous ast_hide_password
00132  */
00133 int ast_restore_tty(int fd, int oldstatus);
00134 
00135 int ast_get_termcols(int fd);
00136 
00137 #if defined(__cplusplus) || defined(c_plusplus)
00138 }
00139 #endif
00140 
00141 #endif /* _ASTERISK_IO_H */

Generated on Sat Aug 6 00:39:29 2011 for Asterisk - the Open Source PBX by  doxygen 1.4.7