(closes issue #12846)
[asterisk-bristuff.git] / include / asterisk.h
blob4fcb5f8edd4eeed1a0510aa923ffc0137af3011f
1 /*
2 * Asterisk -- A telephony toolkit for Linux.
4 * General Definitions for Asterisk top level program
5 *
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
14 /*! \file
15 * \brief Asterisk main include file. File version handling, generic pbx functions.
18 #ifndef _ASTERISK_H
19 #define _ASTERISK_H
21 /* The include of 'autoconfig.h' is not necessary for any modules that
22 are part of the Asterisk source tree, because the top-level Makefile
23 will forcibly include that header in all compilations before all
24 other headers (even system headers). However, leaving this here will
25 help out-of-tree module builders, and doesn't cause any harm for the
26 in-tree modules.
28 #include "asterisk/autoconfig.h"
30 #include "asterisk/compat.h"
32 #include "asterisk/paths.h"
34 #define DEFAULT_LANGUAGE "en"
36 #define DEFAULT_SAMPLE_RATE 8000
37 #define DEFAULT_SAMPLES_PER_MS ((DEFAULT_SAMPLE_RATE)/1000)
38 #define setpriority __PLEASE_USE_ast_set_priority_INSTEAD_OF_setpriority__
39 #define sched_setscheduler __PLEASE_USE_ast_set_priority_INSTEAD_OF_sched_setscheduler__
41 /* provided in asterisk.c */
42 extern char ast_config_AST_CONFIG_DIR[PATH_MAX];
43 extern char ast_config_AST_CONFIG_FILE[PATH_MAX];
44 extern char ast_config_AST_MODULE_DIR[PATH_MAX];
45 extern char ast_config_AST_SPOOL_DIR[PATH_MAX];
46 extern char ast_config_AST_MONITOR_DIR[PATH_MAX];
47 extern char ast_config_AST_VAR_DIR[PATH_MAX];
48 extern char ast_config_AST_DATA_DIR[PATH_MAX];
49 extern char ast_config_AST_LOG_DIR[PATH_MAX];
50 extern char ast_config_AST_AGI_DIR[PATH_MAX];
51 extern char ast_config_AST_DB[PATH_MAX];
52 extern char ast_config_AST_KEY_DIR[PATH_MAX];
53 extern char ast_config_AST_PID[PATH_MAX];
54 extern char ast_config_AST_SOCKET[PATH_MAX];
55 extern char ast_config_AST_RUN_DIR[PATH_MAX];
56 extern char ast_config_AST_CTL_PERMISSIONS[PATH_MAX];
57 extern char ast_config_AST_CTL_OWNER[PATH_MAX];
58 extern char ast_config_AST_CTL_GROUP[PATH_MAX];
59 extern char ast_config_AST_CTL[PATH_MAX];
60 extern char ast_config_AST_SYSTEM_NAME[20];
62 int ast_set_priority(int); /*!< Provided by asterisk.c */
63 int load_modules(unsigned int); /*!< Provided by loader.c */
64 int load_pbx(void); /*!< Provided by pbx.c */
65 int init_logger(void); /*!< Provided by logger.c */
66 void close_logger(void); /*!< Provided by logger.c */
67 int reload_logger(int); /*!< Provided by logger.c */
68 int init_framer(void); /*!< Provided by frame.c */
69 int ast_term_init(void); /*!< Provided by term.c */
70 int astdb_init(void); /*!< Provided by db.c */
71 void ast_channels_init(void); /*!< Provided by channel.c */
72 void ast_builtins_init(void); /*!< Provided by cli.c */
73 int dnsmgr_init(void); /*!< Provided by dnsmgr.c */
74 void dnsmgr_start_refresh(void); /*!< Provided by dnsmgr.c */
75 int dnsmgr_reload(void); /*!< Provided by dnsmgr.c */
76 void threadstorage_init(void); /*!< Provided by threadstorage.c */
77 int astobj2_init(void); /*! Provided by astobj2.c */
78 void ast_autoservice_init(void); /*!< Provided by autoservice.c */
80 /* Many headers need 'ast_channel' to be defined */
81 struct ast_channel;
83 /* Many headers need 'ast_module' to be defined */
84 struct ast_module;
86 /*!
87 * \brief Reload asterisk modules.
88 * \param name the name of the module to reload
90 * This function reloads the specified module, or if no modules are specified,
91 * it will reload all loaded modules.
93 * \note Modules are reloaded using their reload() functions, not unloading
94 * them and loading them again.
96 * \return Zero if the specified module was not found, 1 if the module was
97 * found but cannot be reloaded, -1 if a reload operation is already in
98 * progress, and 2 if the specfied module was found and reloaded.
100 int ast_module_reload(const char *name);
103 * \brief Register a function to be executed before Asterisk exits.
104 * \param func The callback function to use.
106 * \return Zero on success, -1 on error.
108 int ast_register_atexit(void (*func)(void));
110 /*!
111 * \brief Unregister a function registered with ast_register_atexit().
112 * \param func The callback function to unregister.
114 void ast_unregister_atexit(void (*func)(void));
116 #if !defined(LOW_MEMORY)
118 * \brief Register the version of a source code file with the core.
119 * \param file the source file name
120 * \param version the version string (typically a CVS revision keyword string)
121 * \return nothing
123 * This function should not be called directly, but instead the
124 * ASTERISK_FILE_VERSION macro should be used to register a file with the core.
126 void ast_register_file_version(const char *file, const char *version);
129 * \brief Unregister a source code file from the core.
130 * \param file the source file name
131 * \return nothing
133 * This function should not be called directly, but instead the
134 * ASTERISK_FILE_VERSION macro should be used to automatically unregister
135 * the file when the module is unloaded.
137 void ast_unregister_file_version(const char *file);
140 * \brief Register/unregister a source code file with the core.
141 * \param file the source file name
142 * \param version the version string (typically a CVS revision keyword string)
144 * This macro will place a file-scope constructor and destructor into the
145 * source of the module using it; this will cause the version of this file
146 * to registered with the Asterisk core (and unregistered) at the appropriate
147 * times.
149 * Example:
151 * \code
152 * ASTERISK_FILE_VERSION(__FILE__, "\$Revision\$")
153 * \endcode
155 * \note The dollar signs above have been protected with backslashes to keep
156 * CVS from modifying them in this file; under normal circumstances they would
157 * not be present and CVS would expand the Revision keyword into the file's
158 * revision number.
160 #ifdef MTX_PROFILE
161 #define HAVE_MTX_PROFILE /* used in lock.h */
162 #define ASTERISK_FILE_VERSION(file, version) \
163 static int mtx_prof = -1; /* profile mutex */ \
164 static void __attribute__((constructor)) __register_file_version(void) \
166 mtx_prof = ast_add_profile("mtx_lock_" file, 0); \
167 ast_register_file_version(file, version); \
169 static void __attribute__((destructor)) __unregister_file_version(void) \
171 ast_unregister_file_version(file); \
173 #else /* !MTX_PROFILE */
174 #define ASTERISK_FILE_VERSION(file, version) \
175 static void __attribute__((constructor)) __register_file_version(void) \
177 ast_register_file_version(file, version); \
179 static void __attribute__((destructor)) __unregister_file_version(void) \
181 ast_unregister_file_version(file); \
183 #endif /* !MTX_PROFILE */
184 #else /* LOW_MEMORY */
185 #define ASTERISK_FILE_VERSION(file, x)
186 #endif /* LOW_MEMORY */
188 #if !defined(LOW_MEMORY)
190 * \brief support for event profiling
192 * (note, this must be documented a lot more)
193 * ast_add_profile allocates a generic 'counter' with a given name,
194 * which can be shown with the command 'show profile <name>'
196 * The counter accumulates positive or negative values supplied by
197 * ast_add_profile(), dividing them by the 'scale' value passed in the
198 * create call, and also counts the number of 'events'.
199 * Values can also be taked by the TSC counter on ia32 architectures,
200 * in which case you can mark the start of an event calling ast_mark(id, 1)
201 * and then the end of the event with ast_mark(id, 0).
202 * For non-i386 architectures, these two calls return 0.
204 int ast_add_profile(const char *, uint64_t scale);
205 int64_t ast_profile(int, int64_t);
206 int64_t ast_mark(int, int start1_stop0);
207 #else /* LOW_MEMORY */
208 #define ast_add_profile(a, b) 0
209 #define ast_profile(a, b) do { } while (0)
210 #define ast_mark(a, b) do { } while (0)
211 #endif /* LOW_MEMORY */
213 #endif /* _ASTERISK_H */