2 * Asterisk -- A telephony toolkit for Linux.
4 * General Definitions for Asterisk top level program
6 * Copyright (C) 1999-2006, Digium, Inc.
8 * Mark Spencer <markster@digium.com>
10 * This program is free software, distributed under the terms of
11 * the GNU General Public License
15 * \brief Asterisk main include file. File version handling, generic pbx functions.
21 #include "asterisk/autoconfig.h"
23 #define _POSIX_C_SOURCE 200112L
24 #define _XOPEN_SOURCE 600
28 #if _POSIX_VERSION < 200112L
29 #error System does not support POSIX version 200112.
32 /* It is not clear if we need this version check at this time.
33 #if _XOPEN_VERSION < 600
34 #error System does not support XOPEN version 600.
38 #if !defined(NO_MALLOC_DEBUG) && !defined(STANDALONE) && defined(MALLOC_DEBUG)
39 #include "asterisk/astmm.h"
42 #include "asterisk/compat.h"
44 /* Default to allowing the umask or filesystem ACLs to determine actual file
45 * creation permissions
48 #define AST_DIR_MODE 0777
51 #define AST_FILE_MODE 0666
54 #define DEFAULT_LANGUAGE "en"
56 #define DEFAULT_SAMPLE_RATE 8000
57 #define DEFAULT_SAMPLES_PER_MS ((DEFAULT_SAMPLE_RATE)/1000)
58 #define setpriority __PLEASE_USE_ast_set_priority_INSTEAD_OF_setpriority__
59 #define sched_setscheduler __PLEASE_USE_ast_set_priority_INSTEAD_OF_sched_setscheduler__
61 #if defined(DEBUG_FD_LEAKS) && !defined(STANDALONE) && !defined(STANDALONE_AEL)
62 /* These includes are all about ordering */
64 #include <sys/types.h>
66 #include <sys/socket.h>
69 #define open(a,...) __ast_fdleak_open(__FILE__,__LINE__,__PRETTY_FUNCTION__, a, __VA_ARGS__)
70 #define pipe(a) __ast_fdleak_pipe(a, __FILE__,__LINE__,__PRETTY_FUNCTION__)
71 #define socket(a,b,c) __ast_fdleak_socket(a, b, c, __FILE__,__LINE__,__PRETTY_FUNCTION__)
72 #define close(a) __ast_fdleak_close(a)
73 #define fopen(a,b) __ast_fdleak_fopen(a, b, __FILE__,__LINE__,__PRETTY_FUNCTION__)
74 #define fclose(a) __ast_fdleak_fclose(a)
75 #define dup2(a,b) __ast_fdleak_dup2(a, b, __FILE__,__LINE__,__PRETTY_FUNCTION__)
76 #define dup(a) __ast_fdleak_dup(a, __FILE__,__LINE__,__PRETTY_FUNCTION__)
78 #if defined(__cplusplus) || defined(c_plusplus)
81 int __ast_fdleak_open(const char *file, int line, const char *func, const char *path, int flags, ...);
82 int __ast_fdleak_pipe(int *fds, const char *file, int line, const char *func);
83 int __ast_fdleak_socket(int domain, int type, int protocol, const char *file, int line, const char *func);
84 int __ast_fdleak_close(int fd);
85 FILE *__ast_fdleak_fopen(const char *path, const char *mode, const char *file, int line, const char *func);
86 int __ast_fdleak_fclose(FILE *ptr);
87 int __ast_fdleak_dup2(int oldfd, int newfd, const char *file, int line, const char *func);
88 int __ast_fdleak_dup(int oldfd, const char *file, int line, const char *func);
89 #if defined(__cplusplus) || defined(c_plusplus)
94 int ast_set_priority(int); /*!< Provided by asterisk.c */
95 int ast_fd_init(void); /*!< Provided by astfd.c */
98 * \brief Register a function to be executed before Asterisk exits.
99 * \param func The callback function to use.
101 * \retval 0 on success.
102 * \retval -1 on error.
104 int ast_register_atexit(void (*func)(void));
107 * \brief Unregister a function registered with ast_register_atexit().
108 * \param func The callback function to unregister.
110 void ast_unregister_atexit(void (*func)(void));
112 #if !defined(LOW_MEMORY)
114 * \brief Register the version of a source code file with the core.
115 * \param file the source file name
116 * \param version the version string (typically a SVN revision keyword string)
119 * This function should not be called directly, but instead the
120 * ASTERISK_FILE_VERSION macro should be used to register a file with the core.
122 void ast_register_file_version(const char *file, const char *version);
125 * \brief Unregister a source code file from the core.
126 * \param file the source file name
129 * This function should not be called directly, but instead the
130 * ASTERISK_FILE_VERSION macro should be used to automatically unregister
131 * the file when the module is unloaded.
133 void ast_unregister_file_version(const char *file);
135 /*! \brief Find version for given module name
136 * \param file Module name (i.e. chan_sip.so)
137 * \return version string or NULL if the module is not found
139 const char *ast_file_version_find(const char *file);
141 char *ast_complete_source_filename(const char *partial, int n);
144 * \brief Register/unregister a source code file with the core.
145 * \param file the source file name
146 * \param version the version string (typically a SVN revision keyword string)
148 * This macro will place a file-scope constructor and destructor into the
149 * source of the module using it; this will cause the version of this file
150 * to registered with the Asterisk core (and unregistered) at the appropriate
156 * ASTERISK_FILE_VERSION(__FILE__, "\$Revision\$")
159 * \note The dollar signs above have been protected with backslashes to keep
160 * SVN from modifying them in this file; under normal circumstances they would
161 * not be present and SVN would expand the Revision keyword into the file's
165 #define HAVE_MTX_PROFILE /* used in lock.h */
166 #define ASTERISK_FILE_VERSION(file, version) \
167 static int mtx_prof = -1; /* profile mutex */ \
168 static void __attribute__((constructor)) __register_file_version(void) \
170 mtx_prof = ast_add_profile("mtx_lock_" file, 0); \
171 ast_register_file_version(file, version); \
173 static void __attribute__((destructor)) __unregister_file_version(void) \
175 ast_unregister_file_version(file); \
177 #else /* !MTX_PROFILE */
178 #define ASTERISK_FILE_VERSION(file, version) \
179 static void __attribute__((constructor)) __register_file_version(void) \
181 ast_register_file_version(file, version); \
183 static void __attribute__((destructor)) __unregister_file_version(void) \
185 ast_unregister_file_version(file); \
187 #endif /* !MTX_PROFILE */
188 #else /* LOW_MEMORY */
189 #define ASTERISK_FILE_VERSION(file, x)
190 #endif /* LOW_MEMORY */
192 #if !defined(LOW_MEMORY)
194 * \brief support for event profiling
196 * (note, this must be documented a lot more)
197 * ast_add_profile allocates a generic 'counter' with a given name,
198 * which can be shown with the command 'core show profile <name>'
200 * The counter accumulates positive or negative values supplied by
201 * \see ast_add_profile(), dividing them by the 'scale' value passed in the
202 * create call, and also counts the number of 'events'.
203 * Values can also be taked by the TSC counter on ia32 architectures,
204 * in which case you can mark the start of an event calling ast_mark(id, 1)
205 * and then the end of the event with ast_mark(id, 0).
206 * For non-i386 architectures, these two calls return 0.
208 int ast_add_profile(const char *, uint64_t scale);
209 int64_t ast_profile(int, int64_t);
210 int64_t ast_mark(int, int start1_stop0);
211 #else /* LOW_MEMORY */
212 #define ast_add_profile(a, b) 0
213 #define ast_profile(a, b) do { } while (0)
214 #define ast_mark(a, b) do { } while (0)
215 #endif /* LOW_MEMORY */
218 * Definition of various structures that many asterisk files need,
219 * but only because they need to know that the type exists.
237 #define bzero 0x__dont_use_bzero__use_memset_instead""
238 #define bcopy 0x__dont_use_bcopy__use_memmove_instead()
240 #endif /* _ASTERISK_H */