Fix some bad locking stemming from trying to forward a call to a non-existent
[asterisk/asterisk.git] / include / asterisk.h
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(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(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 <unistd.h>
53 #include <fcntl.h>
54
55 #define open(a,...)     __ast_fdleak_open(__FILE__,__LINE__,__PRETTY_FUNCTION__, a, __VA_ARGS__)
56 #define pipe(a) __ast_fdleak_pipe(a, __FILE__,__LINE__,__PRETTY_FUNCTION__)
57 #define socket(a,b,c)   __ast_fdleak_socket(a, b, c, __FILE__,__LINE__,__PRETTY_FUNCTION__)
58 #define close(a)        __ast_fdleak_close(a)
59 #define fopen(a,b)      __ast_fdleak_fopen(a, b, __FILE__,__LINE__,__PRETTY_FUNCTION__)
60 #define fclose(a)       __ast_fdleak_fclose(a)
61 #define dup2(a,b)       __ast_fdleak_dup2(a, b, __FILE__,__LINE__,__PRETTY_FUNCTION__)
62 #define dup(a)  __ast_fdleak_dup(a, __FILE__,__LINE__,__PRETTY_FUNCTION__)
63
64 int __ast_fdleak_open(const char *file, int line, const char *func, const char *path, int flags, ...);
65 int __ast_fdleak_pipe(int *fds, const char *file, int line, const char *func);
66 int __ast_fdleak_socket(int domain, int type, int protocol, const char *file, int line, const char *func);
67 int __ast_fdleak_close(int fd);
68 FILE *__ast_fdleak_fopen(const char *path, const char *mode, const char *file, int line, const char *func);
69 int __ast_fdleak_fclose(FILE *ptr);
70 int __ast_fdleak_dup2(int oldfd, int newfd, const char *file, int line, const char *func);
71 int __ast_fdleak_dup(int oldfd, const char *file, int line, const char *func);
72 #endif
73
74 int ast_set_priority(int);                      /*!< Provided by asterisk.c */
75 int ast_fd_init(void);                          /*!< Provided by astfd.c */
76
77 /*!
78  * \brief Register a function to be executed before Asterisk exits.
79  * \param func The callback function to use.
80  *
81  * \retval 0 on success.
82  * \retval -1 on error.
83  */
84 int ast_register_atexit(void (*func)(void));
85
86 /*!
87  * \brief Unregister a function registered with ast_register_atexit().
88  * \param func The callback function to unregister.
89  */
90 void ast_unregister_atexit(void (*func)(void));
91
92 #if !defined(LOW_MEMORY)
93 /*!
94  * \brief Register the version of a source code file with the core.
95  * \param file the source file name
96  * \param version the version string (typically a SVN revision keyword string)
97  * \return nothing
98  *
99  * This function should not be called directly, but instead the
100  * ASTERISK_FILE_VERSION macro should be used to register a file with the core.
101  */
102 void ast_register_file_version(const char *file, const char *version);
103
104 /*!
105  * \brief Unregister a source code file from the core.
106  * \param file the source file name
107  * \return nothing
108  *
109  * This function should not be called directly, but instead the
110  * ASTERISK_FILE_VERSION macro should be used to automatically unregister
111  * the file when the module is unloaded.
112  */
113 void ast_unregister_file_version(const char *file);
114
115 /*! \brief Find version for given module name
116  * \param file Module name (i.e. chan_sip.so)
117  * \return version string or NULL if the module is not found
118  */
119 const char *ast_file_version_find(const char *file);
120
121 char *ast_complete_source_filename(const char *partial, int n);
122
123 /*!
124  * \brief Register/unregister a source code file with the core.
125  * \param file the source file name
126  * \param version the version string (typically a SVN revision keyword string)
127  *
128  * This macro will place a file-scope constructor and destructor into the
129  * source of the module using it; this will cause the version of this file
130  * to registered with the Asterisk core (and unregistered) at the appropriate
131  * times.
132  *
133  * Example:
134  *
135  * \code
136  * ASTERISK_FILE_VERSION(__FILE__, "\$Revision\$")
137  * \endcode
138  *
139  * \note The dollar signs above have been protected with backslashes to keep
140  * SVN from modifying them in this file; under normal circumstances they would
141  * not be present and SVN would expand the Revision keyword into the file's
142  * revision number.
143  */
144 #ifdef MTX_PROFILE
145 #define HAVE_MTX_PROFILE        /* used in lock.h */
146 #define ASTERISK_FILE_VERSION(file, version) \
147         static int mtx_prof = -1;       /* profile mutex */     \
148         static void __attribute__((constructor)) __register_file_version(void) \
149         { \
150                 mtx_prof = ast_add_profile("mtx_lock_" file, 0);        \
151                 ast_register_file_version(file, version); \
152         } \
153         static void __attribute__((destructor)) __unregister_file_version(void) \
154         { \
155                 ast_unregister_file_version(file); \
156         }
157 #else /* !MTX_PROFILE */
158 #define ASTERISK_FILE_VERSION(file, version) \
159         static void __attribute__((constructor)) __register_file_version(void) \
160         { \
161                 ast_register_file_version(file, version); \
162         } \
163         static void __attribute__((destructor)) __unregister_file_version(void) \
164         { \
165                 ast_unregister_file_version(file); \
166         }
167 #endif /* !MTX_PROFILE */
168 #else /* LOW_MEMORY */
169 #define ASTERISK_FILE_VERSION(file, x)
170 #endif /* LOW_MEMORY */
171
172 #if !defined(LOW_MEMORY)
173 /*!
174  * \brief support for event profiling
175  *
176  * (note, this must be documented a lot more)
177  * ast_add_profile allocates a generic 'counter' with a given name,
178  * which can be shown with the command 'core show profile &lt;name&gt;'
179  *
180  * The counter accumulates positive or negative values supplied by
181  * \see ast_add_profile(), dividing them by the 'scale' value passed in the
182  * create call, and also counts the number of 'events'.
183  * Values can also be taked by the TSC counter on ia32 architectures,
184  * in which case you can mark the start of an event calling ast_mark(id, 1)
185  * and then the end of the event with ast_mark(id, 0).
186  * For non-i386 architectures, these two calls return 0.
187  */
188 int ast_add_profile(const char *, uint64_t scale);
189 int64_t ast_profile(int, int64_t);
190 int64_t ast_mark(int, int start1_stop0);
191 #else /* LOW_MEMORY */
192 #define ast_add_profile(a, b) 0
193 #define ast_profile(a, b) do { } while (0)
194 #define ast_mark(a, b) do { } while (0)
195 #endif /* LOW_MEMORY */
196
197 /*! \brief
198  * Definition of various structures that many asterisk files need,
199  * but only because they need to know that the type exists.
200  *
201  */
202
203 struct ast_channel;
204 struct ast_frame;
205 struct ast_module;
206 struct ast_variable;
207 struct ast_str;
208
209 #ifdef bzero
210 #undef bzero
211 #endif
212
213 #ifdef bcopy
214 #undef bcopy
215 #endif
216
217 #define bzero  0x__dont_use_bzero__use_memset_instead""
218 #define bcopy  0x__dont_use_bcopy__use_memmove_instead()
219
220 #endif /* _ASTERISK_H */