Asterisk - The Open Source Telephony Project  18.5.0
alertpipe.h
Go to the documentation of this file.
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 2017, Sean Bright
5  *
6  * Sean Bright <[email protected]>
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 #ifndef ASTERISK_ALERTPIPE_H
20 #define ASTERISK_ALERTPIPE_H
21 
22 #include "asterisk/utils.h"
23 
24 typedef enum {
30 
31 /*!
32  * \brief Initialize an alert pipe
33  * \since 13.16.0
34  *
35  * \param p a two-element array to hold the alert pipe's file descriptors
36  *
37  * \return non-zero if a failure occurred, zero otherwise.
38  */
39 int ast_alertpipe_init(int alert_pipe[2]);
40 
41 /*!
42  * \brief Close an alert pipe
43  * \since 13.16.0
44  *
45  * \param p a two-element containing the alert pipe's file descriptors
46  */
47 void ast_alertpipe_close(int alert_pipe[2]);
48 
49 /*!
50  * \brief Read an event from an alert pipe
51  * \since 13.16.0
52  *
53  * \param p a two-element array containing the alert pipe's file descriptors
54  *
55  * \retval AST_ALERT_READ_SUCCESS on success
56  * \retval AST_ALERT_NOT_READABLE if the alert pipe is not readable
57  * \retval AST_ALERT_READ_FATAL if the alert pipe's file descriptors are in
58  * blocking mode, or a read error occurs.
59  */
61 
62 /*!
63  * \brief Write an event to an alert pipe
64  * \since 13.16.0
65  *
66  * \param p a two-element array containing the alert pipe's file descriptors
67  *
68  * \retval 0 Success
69  * \retval 1 Failure
70  */
71 ssize_t ast_alertpipe_write(int alert_pipe[2]);
72 
73 /*!
74  * \brief Consume all alerts written to the alert pipe
75  * \since 13.16.0
76  *
77  * \param p a two-element array containing the alert pipe's file descriptors
78  *
79  * \retval AST_ALERT_READ_SUCCESS on success
80  * \retval AST_ALERT_NOT_READABLE if the alert pipe is not readable
81  * \retval AST_ALERT_READ_FATAL if the alert pipe's file descriptors are in
82  * blocking mode, or a read error occurs.
83  */
85 
86 /*!
87  * \brief Sets the alert pipe file descriptors to default values
88  * \since 13.16.0
89  *
90  * \param p a two-element array containing the alert pipe's file descriptors
91  */
93 void ast_alertpipe_clear(int alert_pipe[2]),
94 {
95  alert_pipe[0] = alert_pipe[1] = -1;
96 }
97 )
98 
99 /*!
100  * \brief Determine if the alert pipe is readable
101  * \since 13.16.0
102  *
103  * \param p a two-element array containing the alert pipe's file descriptors
104  *
105  * \return non-zero if the alert pipe is readable, zero otherwise.
106  */
108 int attribute_pure ast_alertpipe_readable(int alert_pipe[2]),
109 {
110  return alert_pipe[0] > -1;
111 }
112 )
113 
114 /*!
115  * \brief Determine if the alert pipe is writable
116  * \since 13.16.0
117  *
118  * \param p a two-element array containing the alert pipe's file descriptors
119  *
120  * \return non-zero if the alert pipe is writable, zero otherwise.
121  */
123 int attribute_pure ast_alertpipe_writable(int alert_pipe[2]),
124 {
125  return alert_pipe[1] > -1;
126 }
127 )
128 
129 /*!
130  * \brief Get the alert pipe's read file descriptor
131  * \since 13.16.0
132  *
133  * \param p a two-element array containing the alert pipe's file descriptors
134  *
135  * \return -1 if the file descriptor is not initialized, a non-negative value
136  * otherwise.
137  */
139 int attribute_pure ast_alertpipe_readfd(int alert_pipe[2]),
140 {
141  return alert_pipe[0];
142 }
143 )
144 
145 /*!
146  * \brief Swap the file descriptors from two alert pipes
147  * \since 13.16.0
148  *
149  * \param p1 a two-element array containing an alert pipe's file descriptors
150  * \param p2 a two-element array containing an alert pipe's file descriptors
151  */
153 void ast_alertpipe_swap(int alert_pipe_1[2], int alert_pipe_2[2]),
154 {
155  SWAP(alert_pipe_1[0], alert_pipe_2[0]);
156  SWAP(alert_pipe_1[1], alert_pipe_2[1]);
157 }
158 )
159 
160 #endif /* ASTERISK_ALERTPIPE_H */
#define attribute_pure
Definition: compiler.h:35
#define SWAP(a, b)
Definition: utils.h:230
int ast_alertpipe_readable(int alert_pipe[2])
Determine if the alert pipe is readable.
Definition: alertpipe.h:112
Utility functions.
void ast_alertpipe_close(int alert_pipe[2])
Close an alert pipe.
Definition: alertpipe.c:79
ssize_t ast_alertpipe_write(int alert_pipe[2])
Write an event to an alert pipe.
Definition: alertpipe.c:120
void ast_alertpipe_clear(int alert_pipe[2])
Sets the alert pipe file descriptors to default values.
Definition: alertpipe.h:97
int ast_alertpipe_writable(int alert_pipe[2])
Determine if the alert pipe is writable.
Definition: alertpipe.h:127
int ast_alertpipe_init(int alert_pipe[2])
Initialize an alert pipe.
Definition: alertpipe.c:38
ast_alert_status_t ast_alertpipe_read(int alert_pipe[2])
Read an event from an alert pipe.
Definition: alertpipe.c:102
int ast_alertpipe_readfd(int alert_pipe[2])
Get the alert pipe&#39;s read file descriptor.
Definition: alertpipe.h:143
int alert_pipe[2]
Definition: res_corosync.c:276
ast_alert_status_t ast_alertpipe_flush(int alert_pipe[2])
Consume all alerts written to the alert pipe.
Definition: alertpipe.c:134
void ast_alertpipe_swap(int alert_pipe_1[2], int alert_pipe_2[2])
Swap the file descriptors from two alert pipes.
Definition: alertpipe.h:158
ast_alert_status_t
Definition: alertpipe.h:24
#define AST_INLINE_API(hdr, body)
Definition: inline_api.h:54