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 /* 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
28 #include "asterisk/autoconfig.h"
30 #include "asterisk/compat.h"
32 #include "asterisk/paths.h"
34 /* Default to allowing the umask or filesystem ACLs to determine actual file
35 * creation permissions
38 #define AST_DIR_MODE 0777
41 #define AST_FILE_MODE 0666
44 #define DEFAULT_LANGUAGE "en"
46 #define DEFAULT_SAMPLE_RATE 8000
47 #define DEFAULT_SAMPLES_PER_MS ((DEFAULT_SAMPLE_RATE)/1000)
48 #define setpriority __PLEASE_USE_ast_set_priority_INSTEAD_OF_setpriority__
49 #define sched_setscheduler __PLEASE_USE_ast_set_priority_INSTEAD_OF_sched_setscheduler__
51 /* provided in asterisk.c */
52 extern char ast_config_AST_CONFIG_DIR[PATH_MAX];
53 extern char ast_config_AST_CONFIG_FILE[PATH_MAX];
54 extern char ast_config_AST_MODULE_DIR[PATH_MAX];
55 extern char ast_config_AST_SPOOL_DIR[PATH_MAX];
56 extern char ast_config_AST_MONITOR_DIR[PATH_MAX];
57 extern char ast_config_AST_VAR_DIR[PATH_MAX];
58 extern char ast_config_AST_DATA_DIR[PATH_MAX];
59 extern char ast_config_AST_LOG_DIR[PATH_MAX];
60 extern char ast_config_AST_AGI_DIR[PATH_MAX];
61 extern char ast_config_AST_DB[PATH_MAX];
62 extern char ast_config_AST_KEY_DIR[PATH_MAX];
63 extern char ast_config_AST_PID[PATH_MAX];
64 extern char ast_config_AST_SOCKET[PATH_MAX];
65 extern char ast_config_AST_RUN_DIR[PATH_MAX];
66 extern char ast_config_AST_RUN_GROUP[PATH_MAX];
67 extern char ast_config_AST_RUN_USER[PATH_MAX];
68 extern char ast_config_AST_CTL_PERMISSIONS[PATH_MAX];
69 extern char ast_config_AST_CTL_OWNER[PATH_MAX];
70 extern char ast_config_AST_CTL_GROUP[PATH_MAX];
71 extern char ast_config_AST_CTL[PATH_MAX];
72 extern char ast_config_AST_SYSTEM_NAME[20];
74 int ast_set_priority(int); /*!< Provided by asterisk.c */
75 int load_modules(unsigned int); /*!< Provided by loader.c */
76 int load_pbx(void); /*!< Provided by pbx.c */
77 int init_logger(void); /*!< Provided by logger.c */
78 void close_logger(void); /*!< Provided by logger.c */
79 int reload_logger(int); /*!< Provided by logger.c */
80 int init_framer(void); /*!< Provided by frame.c */
81 int ast_term_init(void); /*!< Provided by term.c */
82 int astdb_init(void); /*!< Provided by db.c */
83 void ast_channels_init(void); /*!< Provided by channel.c */
84 void ast_builtins_init(void); /*!< Provided by cli.c */
85 int dnsmgr_init(void); /*!< Provided by dnsmgr.c */
86 void dnsmgr_start_refresh(void); /*!< Provided by dnsmgr.c */
87 int dnsmgr_reload(void); /*!< Provided by dnsmgr.c */
88 void threadstorage_init(void); /*!< Provided by threadstorage.c */
89 void ast_event_init(void); /*!< Provided by event.c */
90 int ast_device_state_engine_init(void); /*!< Provided by devicestate.c */
92 /* Many headers need 'ast_channel' to be defined */
95 /* Many headers need 'ast_module' to be defined */
99 * \brief Reload asterisk modules.
100 * \param name the name of the module to reload
102 * This function reloads the specified module, or if no modules are specified,
103 * it will reload all loaded modules.
105 * \note Modules are reloaded using their reload() functions, not unloading
106 * them and loading them again.
108 * \return 0 if the specified module was not found.
109 * \retval 1 if the module was found but cannot be reloaded.
110 * \retval -1 if a reload operation is already in progress.
111 * \retval 2 if the specfied module was found and reloaded.
113 int ast_module_reload(const char *name);
116 * \brief Register a function to be executed before Asterisk exits.
117 * \param func The callback function to use.
119 * \retval 0 on success.
120 * \retval -1 on error.
122 int ast_register_atexit(void (*func)(void));
125 * \brief Unregister a function registered with ast_register_atexit().
126 * \param func The callback function to unregister.
128 void ast_unregister_atexit(void (*func)(void));
130 #if !defined(LOW_MEMORY)
132 * \brief Register the version of a source code file with the core.
133 * \param file the source file name
134 * \param version the version string (typically a CVS revision keyword string)
137 * This function should not be called directly, but instead the
138 * ASTERISK_FILE_VERSION macro should be used to register a file with the core.
140 void ast_register_file_version(const char *file, const char *version);
143 * \brief Unregister a source code file from the core.
144 * \param file the source file name
147 * This function should not be called directly, but instead the
148 * ASTERISK_FILE_VERSION macro should be used to automatically unregister
149 * the file when the module is unloaded.
151 void ast_unregister_file_version(const char *file);
154 * \brief Register/unregister a source code file with the core.
155 * \param file the source file name
156 * \param version the version string (typically a CVS revision keyword string)
158 * This macro will place a file-scope constructor and destructor into the
159 * source of the module using it; this will cause the version of this file
160 * to registered with the Asterisk core (and unregistered) at the appropriate
166 * ASTERISK_FILE_VERSION(__FILE__, "\$Revision\$")
169 * \note The dollar signs above have been protected with backslashes to keep
170 * CVS from modifying them in this file; under normal circumstances they would
171 * not be present and CVS would expand the Revision keyword into the file's
175 #define HAVE_MTX_PROFILE /* used in lock.h */
176 #define ASTERISK_FILE_VERSION(file, version) \
177 static int mtx_prof = -1; /* profile mutex */ \
178 static void __attribute__((constructor)) __register_file_version(void) \
180 mtx_prof = ast_add_profile("mtx_lock_" file, 0); \
181 ast_register_file_version(file, version); \
183 static void __attribute__((destructor)) __unregister_file_version(void) \
185 ast_unregister_file_version(file); \
187 #else /* !MTX_PROFILE */
188 #define ASTERISK_FILE_VERSION(file, version) \
189 static void __attribute__((constructor)) __register_file_version(void) \
191 ast_register_file_version(file, version); \
193 static void __attribute__((destructor)) __unregister_file_version(void) \
195 ast_unregister_file_version(file); \
197 #endif /* !MTX_PROFILE */
198 #else /* LOW_MEMORY */
199 #define ASTERISK_FILE_VERSION(file, x)
200 #endif /* LOW_MEMORY */
202 #if !defined(LOW_MEMORY)
204 * \brief support for event profiling
206 * (note, this must be documented a lot more)
207 * ast_add_profile allocates a generic 'counter' with a given name,
208 * which can be shown with the command 'show profile <name>'
210 * The counter accumulates positive or negative values supplied by
211 * ast_add_profile(), dividing them by the 'scale' value passed in the
212 * create call, and also counts the number of 'events'.
213 * Values can also be taked by the TSC counter on ia32 architectures,
214 * in which case you can mark the start of an event calling ast_mark(id, 1)
215 * and then the end of the event with ast_mark(id, 0).
216 * For non-i386 architectures, these two calls return 0.
218 int ast_add_profile(const char *, uint64_t scale);
219 int64_t ast_profile(int, int64_t);
220 int64_t ast_mark(int, int start1_stop0);
221 #else /* LOW_MEMORY */
222 #define ast_add_profile(a, b) 0
223 #define ast_profile(a, b) do { } while (0)
224 #define ast_mark(a, b) do { } while (0)
225 #endif /* LOW_MEMORY */
227 #endif /* _ASTERISK_H */