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 #include "asterisk/compat.h"
27 #define DEFAULT_LANGUAGE "en"
29 #define DEFAULT_SAMPLE_RATE 8000
30 #define DEFAULT_SAMPLES_PER_MS ((DEFAULT_SAMPLE_RATE)/1000)
32 /* provided in asterisk.c */
33 extern char ast_config_AST_CONFIG_DIR[PATH_MAX];
34 extern char ast_config_AST_CONFIG_FILE[PATH_MAX];
35 extern char ast_config_AST_MODULE_DIR[PATH_MAX];
36 extern char ast_config_AST_SPOOL_DIR[PATH_MAX];
37 extern char ast_config_AST_MONITOR_DIR[PATH_MAX];
38 extern char ast_config_AST_VAR_DIR[PATH_MAX];
39 extern char ast_config_AST_DATA_DIR[PATH_MAX];
40 extern char ast_config_AST_LOG_DIR[PATH_MAX];
41 extern char ast_config_AST_AGI_DIR[PATH_MAX];
42 extern char ast_config_AST_DB[PATH_MAX];
43 extern char ast_config_AST_KEY_DIR[PATH_MAX];
44 extern char ast_config_AST_PID[PATH_MAX];
45 extern char ast_config_AST_SOCKET[PATH_MAX];
46 extern char ast_config_AST_RUN_DIR[PATH_MAX];
47 extern char ast_config_AST_CTL_PERMISSIONS[PATH_MAX];
48 extern char ast_config_AST_CTL_OWNER[PATH_MAX];
49 extern char ast_config_AST_CTL_GROUP[PATH_MAX];
50 extern char ast_config_AST_CTL[PATH_MAX];
51 extern char ast_config_AST_SYSTEM_NAME[20];
53 int ast_set_priority(int); /*!< Provided by asterisk.c */
54 int load_modules(void); /*!< Provided by loader.c */
55 int load_pbx(void); /*!< Provided by pbx.c */
56 int init_logger(void); /*!< Provided by logger.c */
57 void close_logger(void); /*!< Provided by logger.c */
58 int reload_logger(int); /*!< Provided by logger.c */
59 int init_framer(void); /*!< Provided by frame.c */
60 int term_init(void); /*!< Provided by term.c */
61 int astdb_init(void); /*!< Provided by db.c */
62 void ast_channels_init(void); /*!< Provided by channel.c */
63 void ast_builtins_init(void); /*!< Provided by cli.c */
64 int dnsmgr_init(void); /*!< Provided by dnsmgr.c */
65 void dnsmgr_start_refresh(void); /*!< Provided by dnsmgr.c */
66 int dnsmgr_reload(void); /*!< Provided by dnsmgr.c */
68 /* Many headers need 'ast_channel' to be defined */
71 /* Many headers need 'ast_module' to be defined */
75 * \brief Reload asterisk modules.
76 * \param name the name of the module to reload
78 * This function reloads the specified module, or if no modules are specified,
79 * it will reload all loaded modules.
81 * \note Modules are reloaded using their reload() functions, not unloading
82 * them and loading them again.
84 * \return Zero if the specified module was not found, 1 if the module was
85 * found but cannot be reloaded, -1 if a reload operation is already in
86 * progress, and 2 if the specfied module was found and reloaded.
88 int ast_module_reload(const char *name);
91 * \brief Register a function to be executed before Asterisk exits.
92 * \param func The callback function to use.
94 * \return Zero on success, -1 on error.
96 int ast_register_atexit(void (*func)(void));
99 * \brief Unregister a function registered with ast_register_atexit().
100 * \param func The callback function to unregister.
102 void ast_unregister_atexit(void (*func)(void));
105 * \brief Register the version of a source code file with the core.
106 * \param file the source file name
107 * \param version the version string (typically a CVS revision keyword string)
110 * This function should not be called directly, but instead the
111 * ASTERISK_FILE_VERSION macro should be used to register a file with the core.
113 void ast_register_file_version(const char *file, const char *version);
116 * \brief Unregister a source code file from the core.
117 * \param file the source file name
120 * This function should not be called directly, but instead the
121 * ASTERISK_FILE_VERSION macro should be used to automatically unregister
122 * the file when the module is unloaded.
124 void ast_unregister_file_version(const char *file);
127 * \brief support for event profiling
129 * (note, this must be documented a lot more)
130 * ast_add_profile allocates a generic 'counter' with a given name,
131 * which can be shown with the command 'show profile <name>'
133 * The counter accumulates positive or negative values supplied by
134 * ast_add_profile(), dividing them by the 'scale' value passed in the
135 * create call, and also counts the number of 'events'.
136 * Values can also be taked by the TSC counter on ia32 architectures,
137 * in which case you can mark the start of an event calling ast_mark(id, 1)
138 * and then the end of the event with ast_mark(id, 0).
139 * For non-i386 architectures, these two calls return 0.
141 int ast_add_profile(const char *, uint64_t scale);
142 int64_t ast_profile(int, int64_t);
143 int64_t ast_mark(int, int start1_stop0);
146 * \brief Register/unregister a source code file with the core.
147 * \param file the source file name
148 * \param version the version string (typically a CVS revision keyword string)
150 * This macro will place a file-scope constructor and destructor into the
151 * source of the module using it; this will cause the version of this file
152 * to registered with the Asterisk core (and unregistered) at the appropriate
158 * ASTERISK_FILE_VERSION(__FILE__, "\$Revision\$")
161 * \note The dollar signs above have been protected with backslashes to keep
162 * CVS from modifying them in this file; under normal circumstances they would
163 * not be present and CVS would expand the Revision keyword into the file's
166 #if defined(__GNUC__) && !defined(LOW_MEMORY)
168 #define HAVE_MTX_PROFILE /* used in lock.h */
169 #define ASTERISK_FILE_VERSION(file, version) \
170 static int mtx_prof = -1; /* profile mutex */ \
171 static void __attribute__((constructor)) __register_file_version(void) \
173 mtx_prof = ast_add_profile("mtx_lock_" file, 0); \
174 ast_register_file_version(file, version); \
176 static void __attribute__((destructor)) __unregister_file_version(void) \
178 ast_unregister_file_version(file); \
181 #define ASTERISK_FILE_VERSION(file, version) \
182 static void __attribute__((constructor)) __register_file_version(void) \
184 ast_register_file_version(file, version); \
186 static void __attribute__((destructor)) __unregister_file_version(void) \
188 ast_unregister_file_version(file); \
191 #elif !defined(LOW_MEMORY) /* ! __GNUC__ && ! LOW_MEMORY*/
192 #define ASTERISK_FILE_VERSION(file, x) static const char __file_version[] = x;
193 #else /* LOW_MEMORY */
194 #define ASTERISK_FILE_VERSION(file, x)
195 #endif /* __GNUC__ */
197 #endif /* _ASTERISK_H */