Wed Jan 8 2020 09:49:42

Asterisk developer's documentation


asterisk.h
Go to the documentation of this file.
1 /*
2  * Asterisk -- A telephony toolkit for Linux.
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 
23 #if !defined(NO_MALLOC_DEBUG) && !defined(STANDALONE) && !defined(STANDALONE2) && defined(MALLOC_DEBUG)
24 #include "asterisk/astmm.h"
25 #endif
26 
27 #include "asterisk/compat.h"
28 
29 /* Default to allowing the umask or filesystem ACLs to determine actual file
30  * creation permissions
31  */
32 #ifndef AST_DIR_MODE
33 #define AST_DIR_MODE 0777
34 #endif
35 #ifndef AST_FILE_MODE
36 #define AST_FILE_MODE 0666
37 #endif
38 
39 #define DEFAULT_LANGUAGE "en"
40 
41 #define DEFAULT_SAMPLE_RATE 8000
42 #define DEFAULT_SAMPLES_PER_MS ((DEFAULT_SAMPLE_RATE)/1000)
43 #define setpriority __PLEASE_USE_ast_set_priority_INSTEAD_OF_setpriority__
44 #define sched_setscheduler __PLEASE_USE_ast_set_priority_INSTEAD_OF_sched_setscheduler__
45 
46 #if defined(DEBUG_FD_LEAKS) && !defined(STANDALONE) && !defined(STANDALONE2) && !defined(STANDALONE_AEL)
47 /* These includes are all about ordering */
48 #include <stdio.h>
49 #include <sys/types.h>
50 #include <sys/stat.h>
51 #include <sys/socket.h>
52 #include <fcntl.h>
53 
54 #define open(a,...) __ast_fdleak_open(__FILE__,__LINE__,__PRETTY_FUNCTION__, a, __VA_ARGS__)
55 #define pipe(a) __ast_fdleak_pipe(a, __FILE__,__LINE__,__PRETTY_FUNCTION__)
56 #define socket(a,b,c) __ast_fdleak_socket(a, b, c, __FILE__,__LINE__,__PRETTY_FUNCTION__)
57 #define close(a) __ast_fdleak_close(a)
58 #define fopen(a,b) __ast_fdleak_fopen(a, b, __FILE__,__LINE__,__PRETTY_FUNCTION__)
59 #define fclose(a) __ast_fdleak_fclose(a)
60 #define dup2(a,b) __ast_fdleak_dup2(a, b, __FILE__,__LINE__,__PRETTY_FUNCTION__)
61 #define dup(a) __ast_fdleak_dup(a, __FILE__,__LINE__,__PRETTY_FUNCTION__)
62 
63 #if defined(__cplusplus) || defined(c_plusplus)
64 extern "C" {
65 #endif
66 int __ast_fdleak_open(const char *file, int line, const char *func, const char *path, int flags, ...);
67 int __ast_fdleak_pipe(int *fds, const char *file, int line, const char *func);
68 int __ast_fdleak_socket(int domain, int type, int protocol, const char *file, int line, const char *func);
69 int __ast_fdleak_close(int fd);
70 FILE *__ast_fdleak_fopen(const char *path, const char *mode, const char *file, int line, const char *func);
71 int __ast_fdleak_fclose(FILE *ptr);
72 int __ast_fdleak_dup2(int oldfd, int newfd, const char *file, int line, const char *func);
73 int __ast_fdleak_dup(int oldfd, const char *file, int line, const char *func);
74 #if defined(__cplusplus) || defined(c_plusplus)
75 }
76 #endif
77 #endif
78 
79 int ast_set_priority(int); /*!< Provided by asterisk.c */
80 int ast_fd_init(void); /*!< Provided by astfd.c */
81 int ast_pbx_init(void); /*!< Provided by pbx.c */
82 
83 /*!
84  * \brief Register a function to be executed before Asterisk exits.
85  * \param func The callback function to use.
86  *
87  * \retval 0 on success.
88  * \retval -1 on error.
89  */
90 int ast_register_atexit(void (*func)(void));
91 
92 /*!
93  * \since 1.8.29
94  * \brief Register a function to be executed before Asterisk gracefully exits.
95  *
96  * If Asterisk is immediately shutdown (core stop now, or sending the TERM
97  * signal), the callback is not run. When the callbacks are run, they are run in
98  * sequence with ast_register_atexit() callbacks, in the reverse order of
99  * registration.
100  *
101  * \param func The callback function to use.
102  *
103  * \retval 0 on success.
104  * \retval -1 on error.
105  */
106 int ast_register_cleanup(void (*func)(void));
107 
108 /*!
109  * \brief Unregister a function registered with ast_register_atexit().
110  * \param func The callback function to unregister.
111  */
112 void ast_unregister_atexit(void (*func)(void));
113 
114 #if !defined(LOW_MEMORY)
115 /*!
116  * \brief Register the version of a source code file with the core.
117  * \param file the source file name
118  * \param version the version string (typically a SVN revision keyword string)
119  * \return nothing
120  *
121  * This function should not be called directly, but instead the
122  * ASTERISK_FILE_VERSION macro should be used to register a file with the core.
123  */
124 void ast_register_file_version(const char *file, const char *version);
125 
126 /*!
127  * \brief Unregister a source code file from the core.
128  * \param file the source file name
129  * \return nothing
130  *
131  * This function should not be called directly, but instead the
132  * ASTERISK_FILE_VERSION macro should be used to automatically unregister
133  * the file when the module is unloaded.
134  */
135 void ast_unregister_file_version(const char *file);
136 
137 /*! \brief Find version for given module name
138  * \param file Module name (i.e. chan_sip.so)
139  * \return version string or NULL if the module is not found
140  */
141 const char *ast_file_version_find(const char *file);
142 
143 char *ast_complete_source_filename(const char *partial, int n);
144 
145 /*!
146  * \brief Register/unregister a source code file with the core.
147  * \param file the source file name
148  * \param version the version string (typically a SVN revision keyword string)
149  *
150  * This macro will place a file-scope constructor and destructor into the
151  * source of the module using it; this will cause the version of this file
152  * to registered with the Asterisk core (and unregistered) at the appropriate
153  * times.
154  *
155  * Example:
156  *
157  * \code
158  * ASTERISK_FILE_VERSION(__FILE__, "\$Revision\$")
159  * \endcode
160  *
161  * \note The dollar signs above have been protected with backslashes to keep
162  * SVN from modifying them in this file; under normal circumstances they would
163  * not be present and SVN would expand the Revision keyword into the file's
164  * revision number.
165  */
166 #ifdef MTX_PROFILE
167 #define HAVE_MTX_PROFILE /* used in lock.h */
168 #define ASTERISK_FILE_VERSION(file, version) \
169  static int mtx_prof = -1; /* profile mutex */ \
170  static void __attribute__((constructor)) __register_file_version(void) \
171  { \
172  mtx_prof = ast_add_profile("mtx_lock_" file, 0); \
173  ast_register_file_version(file, version); \
174  } \
175  static void __attribute__((destructor)) __unregister_file_version(void) \
176  { \
177  ast_unregister_file_version(file); \
178  }
179 #else /* !MTX_PROFILE */
180 #define ASTERISK_FILE_VERSION(file, version) \
181  static void __attribute__((constructor)) __register_file_version(void) \
182  { \
183  ast_register_file_version(file, version); \
184  } \
185  static void __attribute__((destructor)) __unregister_file_version(void) \
186  { \
187  ast_unregister_file_version(file); \
188  }
189 #endif /* !MTX_PROFILE */
190 #else /* LOW_MEMORY */
191 #define ASTERISK_FILE_VERSION(file, x)
192 #endif /* LOW_MEMORY */
193 
194 #if !defined(LOW_MEMORY)
195 /*!
196  * \brief support for event profiling
197  *
198  * (note, this must be documented a lot more)
199  * ast_add_profile allocates a generic 'counter' with a given name,
200  * which can be shown with the command 'core show profile &lt;name&gt;'
201  *
202  * The counter accumulates positive or negative values supplied by
203  * \see ast_add_profile(), dividing them by the 'scale' value passed in the
204  * create call, and also counts the number of 'events'.
205  * Values can also be taked by the TSC counter on ia32 architectures,
206  * in which case you can mark the start of an event calling ast_mark(id, 1)
207  * and then the end of the event with ast_mark(id, 0).
208  * For non-i386 architectures, these two calls return 0.
209  */
210 int ast_add_profile(const char *, uint64_t scale);
211 int64_t ast_profile(int, int64_t);
212 int64_t ast_mark(int, int start1_stop0);
213 #else /* LOW_MEMORY */
214 #define ast_add_profile(a, b) 0
215 #define ast_profile(a, b) do { } while (0)
216 #define ast_mark(a, b) do { } while (0)
217 #endif /* LOW_MEMORY */
218 
219 /*! \brief
220  * Definition of various structures that many asterisk files need,
221  * but only because they need to know that the type exists.
222  *
223  */
224 
225 struct ast_channel;
226 struct ast_frame;
227 struct ast_module;
228 struct ast_variable;
229 struct ast_str;
230 
231 #ifdef bzero
232 #undef bzero
233 #endif
234 
235 #ifdef bcopy
236 #undef bcopy
237 #endif
238 
239 #define bzero 0x__dont_use_bzero__use_memset_instead""
240 #define bcopy 0x__dont_use_bcopy__use_memmove_instead()
241 
242 #endif /* _ASTERISK_H */
Asterisk memory usage debugging This file provides headers for MALLOC_DEBUG, a define used for tracki...
int64_t ast_mark(int, int start1_stop0)
Definition: asterisk.c:775
Main Channel structure associated with a channel.
Definition: channel.h:742
uint32_t version
int64_t ast_profile(int, int64_t)
Definition: asterisk.c:740
void ast_register_file_version(const char *file, const char *version)
Register the version of a source code file with the core.
Definition: asterisk.c:318
char * ast_complete_source_filename(const char *partial, int n)
Definition: asterisk.c:357
Structure for variables, used for configurations and for channel variables.
Definition: config.h:75
int ast_register_cleanup(void(*func)(void))
Register a function to be executed before Asterisk gracefully exits.
Definition: asterisk.c:1003
void ast_unregister_atexit(void(*func)(void))
Unregister a function registered with ast_register_atexit().
Definition: asterisk.c:1008
int ast_register_atexit(void(*func)(void))
Register a function to be executed before Asterisk exits.
Definition: asterisk.c:998
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:1650
int ast_add_profile(const char *, uint64_t scale)
support for event profiling
Definition: asterisk.c:710
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:364
General Definitions for Asterisk top level program Included by asterisk.h to handle platform-specific...
static const char type[]
Definition: chan_nbs.c:57
int ast_pbx_init(void)
Definition: pbx.c:11407
Data structure associated with a single frame of data.
Definition: frame.h:142
const char * ast_file_version_find(const char *file)
Find version for given module name.
Definition: asterisk.c:376
int ast_fd_init(void)
Definition: astfd.c:289
void ast_unregister_file_version(const char *file)
Unregister a source code file from the core.
Definition: asterisk.c:339