Asterisk - The Open Source Telephony Project  GIT-master-a24979a
asterisk.h
Go to the documentation of this file.
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * General Definitions for Asterisk top level program
5  *
6  * Copyright (C) 1999-2006, Digium, Inc.
7  *
8  * Mark Spencer <markster@digium.com>
9  *
10  * This program is free software, distributed under the terms of
11  * the GNU General Public License
12  */
13 
14 /*! \file
15  * \brief Asterisk main include file. File version handling, generic pbx functions.
16  */
17 
18 #ifndef _ASTERISK_H
19 #define _ASTERISK_H
20 
21 #include "asterisk/autoconfig.h"
22 #include "asterisk/compat.h"
23 #include "asterisk/astmm.h"
24 
25 /* Default to allowing the umask or filesystem ACLs to determine actual file
26  * creation permissions
27  */
28 #ifndef AST_DIR_MODE
29 #define AST_DIR_MODE 0777
30 #endif
31 #ifndef AST_FILE_MODE
32 #define AST_FILE_MODE 0666
33 #endif
34 
35 /* Make sure PATH_MAX is defined on platforms (HURD) that don't define it.
36  * Also be sure to handle the case of a path larger than PATH_MAX
37  * (err safely) in the code.
38  */
39 #ifndef PATH_MAX
40 #define PATH_MAX 4096
41 #endif
42 
43 
44 #define AST_CURL_USER_AGENT "asterisk-libcurl-agent/1.0"
45 
46 #define DEFAULT_LANGUAGE "en"
47 
48 #define DEFAULT_SAMPLE_RATE 8000
49 #define DEFAULT_SAMPLES_PER_MS ((DEFAULT_SAMPLE_RATE)/1000)
50 #define setpriority __PLEASE_USE_ast_set_priority_INSTEAD_OF_setpriority__
51 #define sched_setscheduler __PLEASE_USE_ast_set_priority_INSTEAD_OF_sched_setscheduler__
52 #define strtok __PLEASE_USE_strtok_r_INSTEAD_OF_strtok__
53 
54 #if defined(DEBUG_FD_LEAKS) && !defined(STANDALONE) && !defined(STANDALONE2) && !defined(STANDALONE_AEL)
55 /* These includes are all about ordering */
56 #include <sys/stat.h>
57 #include <sys/socket.h>
58 #include <fcntl.h>
59 
60 #define open(a,...) __ast_fdleak_open(__FILE__,__LINE__,__PRETTY_FUNCTION__, a, __VA_ARGS__)
61 #define pipe(a) __ast_fdleak_pipe(a, __FILE__,__LINE__,__PRETTY_FUNCTION__)
62 #define socketpair(a,b,c,d) __ast_fdleak_socketpair(a, b, c, d, __FILE__,__LINE__,__PRETTY_FUNCTION__)
63 #define socket(a,b,c) __ast_fdleak_socket(a, b, c, __FILE__,__LINE__,__PRETTY_FUNCTION__)
64 #define accept(a,b,c) __ast_fdleak_accept(a, b, c, __FILE__,__LINE__,__PRETTY_FUNCTION__)
65 #define close(a) __ast_fdleak_close(a)
66 #define fopen(a,b) __ast_fdleak_fopen(a, b, __FILE__,__LINE__,__PRETTY_FUNCTION__)
67 #define fclose(a) __ast_fdleak_fclose(a)
68 #define dup2(a,b) __ast_fdleak_dup2(a, b, __FILE__,__LINE__,__PRETTY_FUNCTION__)
69 #define dup(a) __ast_fdleak_dup(a, __FILE__,__LINE__,__PRETTY_FUNCTION__)
70 
71 #if defined(__cplusplus) || defined(c_plusplus)
72 extern "C" {
73 #endif
74 int __ast_fdleak_open(const char *file, int line, const char *func, const char *path, int flags, ...);
75 int __ast_fdleak_pipe(int *fds, const char *file, int line, const char *func);
76 int __ast_fdleak_socketpair(int domain, int type, int protocol, int sv[2],
77  const char *file, int line, const char *func);
78 int __ast_fdleak_socket(int domain, int type, int protocol, const char *file, int line, const char *func);
79 int __ast_fdleak_accept(int socket, struct sockaddr *address, socklen_t *address_len,
80  const char *file, int line, const char *func);
81 #if defined(HAVE_EVENTFD)
82 #include <sys/eventfd.h>
83 #define eventfd(a,b) __ast_fdleak_eventfd(a,b, __FILE__,__LINE__,__PRETTY_FUNCTION__)
84 int __ast_fdleak_eventfd(unsigned int initval, int flags, const char *file, int line, const char *func);
85 #endif
86 #if defined(HAVE_TIMERFD)
87 #include <sys/timerfd.h>
88 #define timerfd_create(a,b) __ast_fdleak_timerfd_create(a,b, __FILE__,__LINE__,__PRETTY_FUNCTION__)
89 int __ast_fdleak_timerfd_create(int clockid, int flags, const char *file, int line, const char *func);
90 #endif
91 int __ast_fdleak_close(int fd);
92 FILE *__ast_fdleak_fopen(const char *path, const char *mode, const char *file, int line, const char *func);
93 int __ast_fdleak_fclose(FILE *ptr);
94 int __ast_fdleak_dup2(int oldfd, int newfd, const char *file, int line, const char *func);
95 int __ast_fdleak_dup(int oldfd, const char *file, int line, const char *func);
96 #if defined(__cplusplus) || defined(c_plusplus)
97 }
98 #endif
99 #endif
100 
101 int ast_set_priority(int); /*!< Provided by asterisk.c */
102 int ast_fd_init(void); /*!< Provided by astfd.c */
103 int ast_pbx_init(void); /*!< Provided by pbx.c */
104 
105 /*!
106  * \brief Register a function to be executed before Asterisk exits.
107  * \param func The callback function to use.
108  *
109  * \retval 0 on success.
110  * \retval -1 on error.
111  *
112  * \note This function should be rarely used in situations where
113  * something must be shutdown to avoid corruption, excessive data
114  * loss, or when external programs must be stopped. All other
115  * cleanup in the core should use ast_register_cleanup.
116  */
117 int ast_register_atexit(void (*func)(void));
118 
119 /*!
120  * \since 11.9
121  * \brief Register a function to be executed before Asterisk gracefully exits.
122  *
123  * If Asterisk is immediately shutdown (core stop now, or sending the TERM
124  * signal), the callback is not run. When the callbacks are run, they are run in
125  * sequence with ast_register_atexit() callbacks, in the reverse order of
126  * registration.
127  *
128  * \param func The callback function to use.
129  *
130  * \retval 0 on success.
131  * \retval -1 on error.
132  */
133 int ast_register_cleanup(void (*func)(void));
134 
135 /*!
136  * \brief Unregister a function registered with ast_register_atexit().
137  * \param func The callback function to unregister.
138  */
139 void ast_unregister_atexit(void (*func)(void));
140 
141 /*!
142  * \brief Cancel an existing shutdown and return to normal operation.
143  *
144  * \note Shutdown can be cancelled while the server is waiting for
145  * any existing channels to be destroyed before shutdown becomes
146  * irreversible.
147  *
148  * \return non-zero if shutdown cancelled.
149  */
150 int ast_cancel_shutdown(void);
151 
152 /*!
153  * \details
154  * The server is preventing new channel creation in preparation for
155  * shutdown and may actively be releasing resources. The shutdown
156  * process may be canceled by ast_cancel_shutdown() if it is not too
157  * late.
158  *
159  * \note The preparation to shutdown phase can be quite lengthy
160  * if we are gracefully shutting down. How long existing calls will
161  * last is not up to us.
162  *
163  * \return non-zero if the server is preparing to or actively shutting down.
164  */
165 int ast_shutting_down(void);
166 
167 /*!
168  * \return non-zero if the server is actively shutting down.
169  * \since 13.3.0
170  *
171  * \details
172  * The server is releasing resources and unloading modules.
173  * It won't be long now.
174  */
175 int ast_shutdown_final(void);
176 
177 #ifdef MTX_PROFILE
178 #define HAVE_MTX_PROFILE /* used in lock.h */
179 #endif /* MTX_PROFILE */
180 
181 /*!
182  * \brief support for event profiling
183  *
184  * (note, this must be documented a lot more)
185  * ast_add_profile allocates a generic 'counter' with a given name,
186  * which can be shown with the command 'core show profile &lt;name&gt;'
187  *
188  * The counter accumulates positive or negative values supplied by
189  * \see ast_add_profile(), dividing them by the 'scale' value passed in the
190  * create call, and also counts the number of 'events'.
191  * Values can also be taked by the TSC counter on ia32 architectures,
192  * in which case you can mark the start of an event calling ast_mark(id, 1)
193  * and then the end of the event with ast_mark(id, 0).
194  * For non-i386 architectures, these two calls return 0.
195  */
196 int ast_add_profile(const char *, uint64_t scale);
197 int64_t ast_profile(int, int64_t);
198 int64_t ast_mark(int, int start1_stop0);
199 
200 /*! \brief
201  * Definition of various structures that many asterisk files need,
202  * but only because they need to know that the type exists.
203  *
204  */
205 
206 struct ast_channel;
207 struct ast_frame;
208 struct ast_module;
209 struct ast_variable;
210 struct ast_str;
211 struct ast_sched_context;
212 struct ast_json;
213 
214 /* Some handy macros for turning a preprocessor token into (effectively) a quoted string */
215 #define __stringify_1(x) #x
216 #define __stringify(x) __stringify_1(x)
217 
218 #if defined(AST_IN_CORE) \
219  || (!defined(AST_MODULE_SELF_SYM) \
220  && (defined(STANDALONE) || defined(STANDALONE2) || defined(AST_NOT_MODULE)))
221 
222 #define AST_MODULE_SELF NULL
223 
224 #elif defined(AST_MODULE_SELF_SYM)
225 
226 /*! Retrieve the 'struct ast_module *' for the current module. */
227 #define AST_MODULE_SELF AST_MODULE_SELF_SYM()
228 
229 struct ast_module;
230 /* Internal/forward declaration, AST_MODULE_SELF should be used instead. */
231 struct ast_module *AST_MODULE_SELF_SYM(void);
232 
233 #else
234 
235 #error "Externally compiled modules must declare AST_MODULE_SELF_SYM."
236 
237 #endif
238 
239 /*!
240  * \brief Retrieve the PBX UUID
241  * \param pbx_uuid A buffer of at least AST_UUID_STR_LEN (36 + 1) size to receive the UUID
242  * \param length The buffer length
243  */
244 int ast_pbx_uuid_get(char *pbx_uuid, int length);
245 
246 #endif /* _ASTERISK_H */
int ast_add_profile(const char *, uint64_t scale)
support for event profiling
Definition: astman.c:92
int ast_shutdown_final(void)
Definition: asterisk.c:1865
int ast_register_cleanup(void(*func)(void))
Register a function to be executed before Asterisk gracefully exits.
Definition: clicompat.c:19
int ast_shutting_down(void)
Definition: asterisk.c:1870
int ast_pbx_uuid_get(char *pbx_uuid, int length)
Retrieve the PBX UUID.
Definition: asterisk.c:970
int ast_cancel_shutdown(void)
Cancel an existing shutdown and return to normal operation.
Definition: asterisk.c:1875
void ast_unregister_atexit(void(*func)(void))
Unregister a function registered with ast_register_atexit().
Definition: asterisk.c:1058
int64_t ast_mark(int, int start1_stop0)
Definition: astman.c:103
int ast_pbx_init(void)
int64_t ast_profile(int, int64_t)
Definition: astman.c:98
int ast_register_atexit(void(*func)(void))
Register a function to be executed before Asterisk exits.
Definition: clicompat.c:13
int ast_set_priority(int)
We set ourselves to a high priority, that we might pre-empt everything else. If your PBX has heavy ac...
Definition: asterisk.c:1835
int ast_fd_init(void)
Definition: astfd.c:370
Asterisk memory management routines.
static const char type[]
Definition: chan_ooh323.c:109
char * address
Definition: f2c.h:59
General Definitions for Asterisk top level program Included by asterisk.h to handle platform-specific...
#define AST_MODULE_SELF_SYM
Main Channel structure associated with a channel.
Data structure associated with a single frame of data.
Abstract JSON element (object, array, string, int, ...).
Support for dynamic strings.
Definition: strings.h:604
Structure for variables, used for configurations and for channel variables.
Domain data structure.
Definition: sip.h:887