Wed Jan 8 2020 09:49:48

Asterisk developer's documentation


io.h
Go to the documentation of this file.
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 1999 - 2005, Digium, Inc.
5  *
6  * Mark Spencer <markster@digium.com>
7  *
8  * See http://www.asterisk.org for more information about
9  * the Asterisk project. Please do not directly contact
10  * any of the maintainers of this project for assistance;
11  * the project provides a web site, mailing lists and IRC
12  * channels for your use.
13  *
14  * This program is free software, distributed under the terms of
15  * the GNU General Public License Version 2. See the LICENSE file
16  * at the top of the source tree.
17  */
18 
19 /*! \file
20  * \brief I/O Management (derived from Cheops-NG)
21  */
22 
23 #ifndef _ASTERISK_IO_H
24 #define _ASTERISK_IO_H
25 
26 #include "asterisk/poll-compat.h"
27 
28 #if defined(__cplusplus) || defined(c_plusplus)
29 extern "C" {
30 #endif
31 
32 /*! Input ready */
33 #define AST_IO_IN POLLIN
34 /*! Output ready */
35 #define AST_IO_OUT POLLOUT
36 /*! Priority input ready */
37 #define AST_IO_PRI POLLPRI
38 
39 /* Implicitly polled for */
40 /*! Error condition (errno or getsockopt) */
41 #define AST_IO_ERR POLLERR
42 /*! Hangup */
43 #define AST_IO_HUP POLLHUP
44 /*! Invalid fd */
45 #define AST_IO_NVAL POLLNVAL
46 
47 /*! \brief
48  * An Asterisk IO callback takes its id, a file descriptor, list of events, and
49  * callback data as arguments and returns 0 if it should not be
50  * run again, or non-zero if it should be run again.
51  */
52 
53 struct io_context;
54 
55 /*!
56  * \brief Creates a context
57  * Create a context for I/O operations
58  * Basically mallocs an IO structure and sets up some default values.
59  * \return an allocated io_context structure
60  */
61 struct io_context *io_context_create(void);
62 
63 /*!
64  * \brief Destroys a context
65  * \param ioc structure to destroy
66  * Destroy a context for I/O operations
67  * Frees all memory associated with the given io_context structure along with the structure itself
68  */
69 void io_context_destroy(struct io_context *ioc);
70 
71 typedef int (*ast_io_cb)(int *id, int fd, short events, void *cbdata);
72 #define AST_IO_CB(a) ((ast_io_cb)(a))
73 
74 /*!
75  * \brief Adds an IO context
76  * \param ioc which context to use
77  * \param fd which fd to monitor
78  * \param callback callback function to run
79  * \param events event mask of events to wait for
80  * \param data data to pass to the callback
81  * Watch for any of revents activites on fd, calling callback with data as
82  * callback data.
83  * \retval a pointer to ID of the IO event
84  * \retval NULL on failure
85  */
86 int *ast_io_add(struct io_context *ioc, int fd, ast_io_cb callback, short events, void *data);
87 
88 /*!
89  * \brief Changes an IO handler
90  * \param ioc which context to use
91  * \param id
92  * \param fd the fd you wish it to contain now
93  * \param callback new callback function
94  * \param events event mask to wait for
95  * \param data data to pass to the callback function
96  * Change an I/O handler, updating fd if > -1, callback if non-null,
97  * and revents if >-1, and data if non-null.
98  * \retval a pointer to the ID of the IO event
99  * \retval NULL on failure
100  */
101 int *ast_io_change(struct io_context *ioc, int *id, int fd, ast_io_cb callback, short events, void *data);
102 
103 /*!
104  * \brief Removes an IO context
105  * \param ioc which io_context to remove it from
106  * \param id which ID to remove
107  * Remove an I/O id from consideration
108  * \retval 0 on success
109  * \retval -1 on failure
110  */
111 int ast_io_remove(struct io_context *ioc, int *id);
112 
113 /*!
114  * \brief Waits for IO
115  * \param ioc which context to act upon
116  * \param howlong how many milliseconds to wait
117  * Wait for I/O to happen, returning after
118  * howlong milliseconds, and after processing
119  * any necessary I/O.
120  * \return he number of I/O events which took place.
121  */
122 int ast_io_wait(struct io_context *ioc, int howlong);
123 
124 /*!
125  * \brief Dumps the IO array.
126  * Debugging: Dump everything in the I/O array
127  */
128 void ast_io_dump(struct io_context *ioc);
129 
130 /*! Set fd into non-echoing mode (if fd is a tty) */
131 
132 int ast_hide_password(int fd);
133 
134 /*!
135  * \brief Restores TTY mode.
136  * Call with result from previous ast_hide_password
137  */
138 int ast_restore_tty(int fd, int oldstatus);
139 
140 int ast_get_termcols(int fd);
141 
142 #if defined(__cplusplus) || defined(c_plusplus)
143 }
144 #endif
145 
146 #endif /* _ASTERISK_IO_H */
int ast_io_wait(struct io_context *ioc, int howlong)
Waits for IO.
Definition: io.c:273
int ast_hide_password(int fd)
Definition: io.c:332
void ast_io_dump(struct io_context *ioc)
Dumps the IO array. Debugging: Dump everything in the I/O array.
Definition: io.c:307
int * ast_io_add(struct io_context *ioc, int fd, ast_io_cb callback, short events, void *data)
Adds an IO context.
Definition: io.c:157
int ast_get_termcols(int fd)
Definition: io.c:368
int ast_restore_tty(int fd, int oldstatus)
Restores TTY mode. Call with result from previous ast_hide_password.
Definition: io.c:351
void io_context_destroy(struct io_context *ioc)
Destroys a context.
Definition: io.c:102
Global IO variables are now in a struct in order to be made threadsafe.
Definition: io.c:66
int ast_io_remove(struct io_context *ioc, int *id)
Removes an IO context.
Definition: io.c:240
int(* ast_io_cb)(int *id, int fd, short events, void *cbdata)
Definition: io.h:71
int * ast_io_change(struct io_context *ioc, int *id, int fd, ast_io_cb callback, short events, void *data)
Changes an IO handler.
Definition: io.c:195
enum queue_result id
Definition: app_queue.c:1090
static struct adsi_event events[]
Definition: app_adsiprog.c:78
struct io_context * io_context_create(void)
Creates a context Create a context for I/O operations Basically mallocs an IO structure and sets up s...
Definition: io.c:76