Don't include logger.h in asterisk.h by default as it is causing problems building
[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 int ast_set_priority(int);                      /*!< Provided by asterisk.c */
47
48 /*!
49  * \brief Register a function to be executed before Asterisk exits.
50  * \param func The callback function to use.
51  *
52  * \retval 0 on success.
53  * \retval -1 on error.
54  */
55 int ast_register_atexit(void (*func)(void));
56
57 /*!   
58  * \brief Unregister a function registered with ast_register_atexit().
59  * \param func The callback function to unregister.   
60  */
61 void ast_unregister_atexit(void (*func)(void));
62
63 #if !defined(LOW_MEMORY)
64 /*!
65  * \brief Register the version of a source code file with the core.
66  * \param file the source file name
67  * \param version the version string (typically a CVS revision keyword string)
68  * \return nothing
69  *
70  * This function should not be called directly, but instead the
71  * ASTERISK_FILE_VERSION macro should be used to register a file with the core.
72  */
73 void ast_register_file_version(const char *file, const char *version);
74
75 /*!
76  * \brief Unregister a source code file from the core.
77  * \param file the source file name
78  * \return nothing
79  *
80  * This function should not be called directly, but instead the
81  * ASTERISK_FILE_VERSION macro should be used to automatically unregister
82  * the file when the module is unloaded.
83  */
84 void ast_unregister_file_version(const char *file);
85
86 /*! \brief Find version for given module name
87  * \param file Module name (i.e. chan_sip.so)
88  * \return version string or NULL if the module is not found
89  */
90 const char *ast_file_version_find(const char *file);
91
92
93 /*!
94  * \brief Register/unregister a source code file with the core.
95  * \param file the source file name
96  * \param version the version string (typically a CVS revision keyword string)
97  *
98  * This macro will place a file-scope constructor and destructor into the
99  * source of the module using it; this will cause the version of this file
100  * to registered with the Asterisk core (and unregistered) at the appropriate
101  * times.
102  *
103  * Example:
104  *
105  * \code
106  * ASTERISK_FILE_VERSION(__FILE__, "\$Revision\$")
107  * \endcode
108  *
109  * \note The dollar signs above have been protected with backslashes to keep
110  * CVS from modifying them in this file; under normal circumstances they would
111  * not be present and CVS would expand the Revision keyword into the file's
112  * revision number.
113  */
114 #ifdef MTX_PROFILE
115 #define HAVE_MTX_PROFILE        /* used in lock.h */
116 #define ASTERISK_FILE_VERSION(file, version) \
117         static int mtx_prof = -1;       /* profile mutex */     \
118         static void __attribute__((constructor)) __register_file_version(void) \
119         { \
120                 mtx_prof = ast_add_profile("mtx_lock_" file, 0);        \
121                 ast_register_file_version(file, version); \
122         } \
123         static void __attribute__((destructor)) __unregister_file_version(void) \
124         { \
125                 ast_unregister_file_version(file); \
126         }
127 #else /* !MTX_PROFILE */
128 #define ASTERISK_FILE_VERSION(file, version) \
129         static void __attribute__((constructor)) __register_file_version(void) \
130         { \
131                 ast_register_file_version(file, version); \
132         } \
133         static void __attribute__((destructor)) __unregister_file_version(void) \
134         { \
135                 ast_unregister_file_version(file); \
136         }
137 #endif /* !MTX_PROFILE */
138 #else /* LOW_MEMORY */
139 #define ASTERISK_FILE_VERSION(file, x)
140 #endif /* LOW_MEMORY */
141
142 #if !defined(LOW_MEMORY)
143 /*!
144  * \brief support for event profiling
145  *
146  * (note, this must be documented a lot more)
147  * ast_add_profile allocates a generic 'counter' with a given name,
148  * which can be shown with the command 'show profile <name>'
149  *
150  * The counter accumulates positive or negative values supplied by
151  * ast_add_profile(), dividing them by the 'scale' value passed in the
152  * create call, and also counts the number of 'events'.
153  * Values can also be taked by the TSC counter on ia32 architectures,
154  * in which case you can mark the start of an event calling ast_mark(id, 1)
155  * and then the end of the event with ast_mark(id, 0).
156  * For non-i386 architectures, these two calls return 0.
157  */
158 int ast_add_profile(const char *, uint64_t scale);
159 int64_t ast_profile(int, int64_t);
160 int64_t ast_mark(int, int start1_stop0);
161 #else /* LOW_MEMORY */
162 #define ast_add_profile(a, b) 0
163 #define ast_profile(a, b) do { } while (0)
164 #define ast_mark(a, b) do { } while (0)
165 #endif /* LOW_MEMORY */
166
167 /*! \brief
168  * Definition of various structures that many asterisk files need,
169  * but only because they need to know that the type exists.
170  *
171  */
172
173 struct ast_channel;
174 struct ast_frame;
175 struct ast_module;
176 struct ast_variable;
177 struct ast_str;
178
179 #define bzero  0x__dont_use_bzero__use_memset_instead""
180 #define bcopy  0x__dont_use_bcopy__use_memmove_instead()
181
182 #endif /* _ASTERISK_H */