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 #if !defined(NO_MALLOC_DEBUG) && !defined(STANDALONE) && defined(MALLOC_DEBUG)
24 #include "asterisk/astmm.h"
27 #include "asterisk/compat.h"
29 /* Default to allowing the umask or filesystem ACLs to determine actual file
30 * creation permissions
33 #define AST_DIR_MODE 0777
36 #define AST_FILE_MODE 0666
39 #define DEFAULT_LANGUAGE "en"
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__
46 #if defined(DEBUG_FD_LEAKS) && !defined(STANDALONE) && !defined(STANDALONE_AEL)
47 /* These includes are all about ordering */
49 #include <sys/types.h>
51 #include <sys/socket.h>
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__)
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);
74 int ast_set_priority(int); /*!< Provided by asterisk.c */
75 int ast_fd_init(void); /*!< Provided by astfd.c */
78 * \brief Register a function to be executed before Asterisk exits.
79 * \param func The callback function to use.
81 * \retval 0 on success.
82 * \retval -1 on error.
84 int ast_register_atexit(void (*func)(void));
87 * \brief Unregister a function registered with ast_register_atexit().
88 * \param func The callback function to unregister.
90 void ast_unregister_atexit(void (*func)(void));
92 #if !defined(LOW_MEMORY)
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)
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.
102 void ast_register_file_version(const char *file, const char *version);
105 * \brief Unregister a source code file from the core.
106 * \param file the source file name
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.
113 void ast_unregister_file_version(const char *file);
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
119 const char *ast_file_version_find(const char *file);
121 char *ast_complete_source_filename(const char *partial, int n);
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)
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
136 * ASTERISK_FILE_VERSION(__FILE__, "\$Revision\$")
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
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) \
150 mtx_prof = ast_add_profile("mtx_lock_" file, 0); \
151 ast_register_file_version(file, version); \
153 static void __attribute__((destructor)) __unregister_file_version(void) \
155 ast_unregister_file_version(file); \
157 #else /* !MTX_PROFILE */
158 #define ASTERISK_FILE_VERSION(file, version) \
159 static void __attribute__((constructor)) __register_file_version(void) \
161 ast_register_file_version(file, version); \
163 static void __attribute__((destructor)) __unregister_file_version(void) \
165 ast_unregister_file_version(file); \
167 #endif /* !MTX_PROFILE */
168 #else /* LOW_MEMORY */
169 #define ASTERISK_FILE_VERSION(file, x)
170 #endif /* LOW_MEMORY */
172 #if !defined(LOW_MEMORY)
174 * \brief support for event profiling
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 <name>'
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.
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 */
198 * Definition of various structures that many asterisk files need,
199 * but only because they need to know that the type exists.
217 #define bzero 0x__dont_use_bzero__use_memset_instead""
218 #define bcopy 0x__dont_use_bcopy__use_memmove_instead()
220 #endif /* _ASTERISK_H */