Thu Oct 8 21:57:20 2009

Asterisk developer's documentation


asterisk.h

Go to the documentation of this file.
00001 /*
00002  * Asterisk -- A telephony toolkit for Linux.
00003  *
00004  * General Definitions for Asterisk top level program
00005  * 
00006  * Copyright (C) 1999-2006, Digium, Inc.
00007  *
00008  * Mark Spencer <markster@digium.com>
00009  *
00010  * This program is free software, distributed under the terms of
00011  * the GNU General Public License
00012  */
00013 
00014 /*! \file
00015  * \brief Asterisk main include file. File version handling, generic pbx functions.
00016  */
00017 
00018 #ifndef _ASTERISK_H
00019 #define _ASTERISK_H
00020 
00021 /* The include of 'autoconfig.h' is not necessary for any modules that
00022    are part of the Asterisk source tree, because the top-level Makefile
00023    will forcibly include that header in all compilations before all
00024    other headers (even system headers). However, leaving this here will
00025    help out-of-tree module builders, and doesn't cause any harm for the
00026    in-tree modules.
00027 */
00028 #include "asterisk/autoconfig.h"
00029 
00030 #include "asterisk/compat.h"
00031 
00032 #include "asterisk/paths.h"
00033 
00034 #define DEFAULT_LANGUAGE "en"
00035 
00036 #define DEFAULT_SAMPLE_RATE 8000
00037 #define DEFAULT_SAMPLES_PER_MS  ((DEFAULT_SAMPLE_RATE)/1000)
00038 #define  setpriority __PLEASE_USE_ast_set_priority_INSTEAD_OF_setpriority__
00039 #define  sched_setscheduler   __PLEASE_USE_ast_set_priority_INSTEAD_OF_sched_setscheduler__
00040 
00041 /* provided in asterisk.c */
00042 extern char ast_config_AST_CONFIG_DIR[PATH_MAX];
00043 extern char ast_config_AST_CONFIG_FILE[PATH_MAX];
00044 extern char ast_config_AST_MODULE_DIR[PATH_MAX];
00045 extern char ast_config_AST_SPOOL_DIR[PATH_MAX];
00046 extern char ast_config_AST_MONITOR_DIR[PATH_MAX];
00047 extern char ast_config_AST_VAR_DIR[PATH_MAX];
00048 extern char ast_config_AST_DATA_DIR[PATH_MAX];
00049 extern char ast_config_AST_LOG_DIR[PATH_MAX];
00050 extern char ast_config_AST_AGI_DIR[PATH_MAX];
00051 extern char ast_config_AST_DB[PATH_MAX];
00052 extern char ast_config_AST_KEY_DIR[PATH_MAX];
00053 extern char ast_config_AST_PID[PATH_MAX];
00054 extern char ast_config_AST_SOCKET[PATH_MAX];
00055 extern char ast_config_AST_RUN_DIR[PATH_MAX];
00056 extern char ast_config_AST_CTL_PERMISSIONS[PATH_MAX];
00057 extern char ast_config_AST_CTL_OWNER[PATH_MAX];
00058 extern char ast_config_AST_CTL_GROUP[PATH_MAX];
00059 extern char ast_config_AST_CTL[PATH_MAX];
00060 extern char ast_config_AST_SYSTEM_NAME[20];
00061 
00062 int ast_set_priority(int);       /*!< Provided by asterisk.c */
00063 int load_modules(unsigned int);        /*!< Provided by loader.c */
00064 int load_pbx(void);           /*!< Provided by pbx.c */
00065 int init_logger(void);           /*!< Provided by logger.c */
00066 void close_logger(void);         /*!< Provided by logger.c */
00067 int reload_logger(int);          /*!< Provided by logger.c */
00068 int init_framer(void);           /*!< Provided by frame.c */
00069 int ast_term_init(void);         /*!< Provided by term.c */
00070 int astdb_init(void);            /*!< Provided by db.c */
00071 void ast_channels_init(void);       /*!< Provided by channel.c */
00072 void ast_builtins_init(void);       /*!< Provided by cli.c */
00073 int dnsmgr_init(void);           /*!< Provided by dnsmgr.c */ 
00074 void dnsmgr_start_refresh(void);    /*!< Provided by dnsmgr.c */
00075 int dnsmgr_reload(void);         /*!< Provided by dnsmgr.c */
00076 void threadstorage_init(void);         /*!< Provided by threadstorage.c */
00077 int astobj2_init(void);          /*! Provided by astobj2.c */
00078 void ast_autoservice_init(void);    /*!< Provided by autoservice.c */
00079 
00080 /* Many headers need 'ast_channel' to be defined */
00081 struct ast_channel;
00082 
00083 /* Many headers need 'ast_module' to be defined */
00084 struct ast_module;
00085 
00086 /*!
00087  * \brief Reload asterisk modules.
00088  * \param name the name of the module to reload
00089  *
00090  * This function reloads the specified module, or if no modules are specified,
00091  * it will reload all loaded modules.
00092  *
00093  * \note Modules are reloaded using their reload() functions, not unloading
00094  * them and loading them again.
00095  * 
00096  * \return Zero if the specified module was not found, 1 if the module was
00097  * found but cannot be reloaded, -1 if a reload operation is already in
00098  * progress, and 2 if the specfied module was found and reloaded.
00099  */
00100 int ast_module_reload(const char *name);
00101 
00102 /*!
00103  * \brief Register a function to be executed before Asterisk exits.
00104  * \param func The callback function to use.
00105  *
00106  * \return Zero on success, -1 on error.
00107  */
00108 int ast_register_atexit(void (*func)(void));
00109 
00110 /*!   
00111  * \brief Unregister a function registered with ast_register_atexit().
00112  * \param func The callback function to unregister.   
00113  */
00114 void ast_unregister_atexit(void (*func)(void));
00115 
00116 #if !defined(LOW_MEMORY)
00117 /*!
00118  * \brief Register the version of a source code file with the core.
00119  * \param file the source file name
00120  * \param version the version string (typically a CVS revision keyword string)
00121  * \return nothing
00122  *
00123  * This function should not be called directly, but instead the
00124  * ASTERISK_FILE_VERSION macro should be used to register a file with the core.
00125  */
00126 void ast_register_file_version(const char *file, const char *version);
00127 
00128 /*!
00129  * \brief Unregister a source code file from the core.
00130  * \param file the source file name
00131  * \return nothing
00132  *
00133  * This function should not be called directly, but instead the
00134  * ASTERISK_FILE_VERSION macro should be used to automatically unregister
00135  * the file when the module is unloaded.
00136  */
00137 void ast_unregister_file_version(const char *file);
00138 
00139 /*!
00140  * \brief Register/unregister a source code file with the core.
00141  * \param file the source file name
00142  * \param version the version string (typically a CVS revision keyword string)
00143  *
00144  * This macro will place a file-scope constructor and destructor into the
00145  * source of the module using it; this will cause the version of this file
00146  * to registered with the Asterisk core (and unregistered) at the appropriate
00147  * times.
00148  *
00149  * Example:
00150  *
00151  * \code
00152  * ASTERISK_FILE_VERSION(__FILE__, "\$Revision\$")
00153  * \endcode
00154  *
00155  * \note The dollar signs above have been protected with backslashes to keep
00156  * CVS from modifying them in this file; under normal circumstances they would
00157  * not be present and CVS would expand the Revision keyword into the file's
00158  * revision number.
00159  */
00160 #ifdef MTX_PROFILE
00161 #define  HAVE_MTX_PROFILE  /* used in lock.h */
00162 #define ASTERISK_FILE_VERSION(file, version) \
00163    static int mtx_prof = -1;       /* profile mutex */   \
00164    static void __attribute__((constructor)) __register_file_version(void) \
00165    { \
00166       mtx_prof = ast_add_profile("mtx_lock_" file, 0);   \
00167       ast_register_file_version(file, version); \
00168    } \
00169    static void __attribute__((destructor)) __unregister_file_version(void) \
00170    { \
00171       ast_unregister_file_version(file); \
00172    }
00173 #else /* !MTX_PROFILE */
00174 #define ASTERISK_FILE_VERSION(file, version) \
00175    static void __attribute__((constructor)) __register_file_version(void) \
00176    { \
00177       ast_register_file_version(file, version); \
00178    } \
00179    static void __attribute__((destructor)) __unregister_file_version(void) \
00180    { \
00181       ast_unregister_file_version(file); \
00182    }
00183 #endif /* !MTX_PROFILE */
00184 #else /* LOW_MEMORY */
00185 #define ASTERISK_FILE_VERSION(file, x)
00186 #endif /* LOW_MEMORY */
00187 
00188 #if !defined(LOW_MEMORY)
00189 /*!
00190  * \brief support for event profiling
00191  *
00192  * (note, this must be documented a lot more)
00193  * ast_add_profile allocates a generic 'counter' with a given name,
00194  * which can be shown with the command 'show profile <name>'
00195  *
00196  * The counter accumulates positive or negative values supplied by
00197  * ast_add_profile(), dividing them by the 'scale' value passed in the
00198  * create call, and also counts the number of 'events'.
00199  * Values can also be taked by the TSC counter on ia32 architectures,
00200  * in which case you can mark the start of an event calling ast_mark(id, 1)
00201  * and then the end of the event with ast_mark(id, 0).
00202  * For non-i386 architectures, these two calls return 0.
00203  */
00204 int ast_add_profile(const char *, uint64_t scale);
00205 int64_t ast_profile(int, int64_t);
00206 int64_t ast_mark(int, int start1_stop0);
00207 #else /* LOW_MEMORY */
00208 #define ast_add_profile(a, b) 0
00209 #define ast_profile(a, b) do { } while (0)
00210 #define ast_mark(a, b) do { } while (0)
00211 #endif /* LOW_MEMORY */
00212 
00213 #endif /* _ASTERISK_H */

Generated on Thu Oct 8 21:57:20 2009 for Asterisk - the Open Source PBX by  doxygen 1.5.8