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