asterisk.h

Go to the documentation of this file.
00001 /*
00002  * Asterisk -- An open source telephony toolkit.
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 #include "asterisk/autoconfig.h"
00022 
00023 #if !defined(NO_MALLOC_DEBUG) && !defined(STANDALONE) && !defined(STANDALONE2) && defined(MALLOC_DEBUG)
00024 #include "asterisk/astmm.h"
00025 #endif
00026 
00027 #include "asterisk/compat.h"
00028 
00029 /* Default to allowing the umask or filesystem ACLs to determine actual file
00030  * creation permissions
00031  */
00032 #ifndef AST_DIR_MODE
00033 #define AST_DIR_MODE 0777
00034 #endif
00035 #ifndef AST_FILE_MODE
00036 #define AST_FILE_MODE 0666
00037 #endif
00038 
00039 #define DEFAULT_LANGUAGE "en"
00040 
00041 #define DEFAULT_SAMPLE_RATE 8000
00042 #define DEFAULT_SAMPLES_PER_MS  ((DEFAULT_SAMPLE_RATE)/1000)
00043 #define  setpriority __PLEASE_USE_ast_set_priority_INSTEAD_OF_setpriority__
00044 #define  sched_setscheduler   __PLEASE_USE_ast_set_priority_INSTEAD_OF_sched_setscheduler__
00045 
00046 #if defined(DEBUG_FD_LEAKS) && !defined(STANDALONE) && !defined(STANDALONE2) && !defined(STANDALONE_AEL)
00047 /* These includes are all about ordering */
00048 #include <stdio.h>
00049 #include <sys/types.h>
00050 #include <sys/stat.h>
00051 #include <sys/socket.h>
00052 #include <fcntl.h>
00053 
00054 #define  open(a,...) __ast_fdleak_open(__FILE__,__LINE__,__PRETTY_FUNCTION__, a, __VA_ARGS__)
00055 #define pipe(a)      __ast_fdleak_pipe(a, __FILE__,__LINE__,__PRETTY_FUNCTION__)
00056 #define socket(a,b,c)   __ast_fdleak_socket(a, b, c, __FILE__,__LINE__,__PRETTY_FUNCTION__)
00057 #define close(a)  __ast_fdleak_close(a)
00058 #define  fopen(a,b)  __ast_fdleak_fopen(a, b, __FILE__,__LINE__,__PRETTY_FUNCTION__)
00059 #define  fclose(a)   __ast_fdleak_fclose(a)
00060 #define  dup2(a,b)   __ast_fdleak_dup2(a, b, __FILE__,__LINE__,__PRETTY_FUNCTION__)
00061 #define dup(a)    __ast_fdleak_dup(a, __FILE__,__LINE__,__PRETTY_FUNCTION__)
00062 
00063 #if defined(__cplusplus) || defined(c_plusplus)
00064 extern "C" {
00065 #endif
00066 int __ast_fdleak_open(const char *file, int line, const char *func, const char *path, int flags, ...);
00067 int __ast_fdleak_pipe(int *fds, const char *file, int line, const char *func);
00068 int __ast_fdleak_socket(int domain, int type, int protocol, const char *file, int line, const char *func);
00069 int __ast_fdleak_close(int fd);
00070 FILE *__ast_fdleak_fopen(const char *path, const char *mode, const char *file, int line, const char *func);
00071 int __ast_fdleak_fclose(FILE *ptr);
00072 int __ast_fdleak_dup2(int oldfd, int newfd, const char *file, int line, const char *func);
00073 int __ast_fdleak_dup(int oldfd, const char *file, int line, const char *func);
00074 #if defined(__cplusplus) || defined(c_plusplus)
00075 }
00076 #endif
00077 #endif
00078 
00079 int ast_set_priority(int);       /*!< Provided by asterisk.c */
00080 int ast_fd_init(void);           /*!< Provided by astfd.c */
00081 int ast_pbx_init(void);          /*!< Provided by pbx.c */
00082 
00083 /*!
00084  * \brief Register a function to be executed before Asterisk exits.
00085  * \param func The callback function to use.
00086  *
00087  * \retval 0 on success.
00088  * \retval -1 on error.
00089  *
00090  * \note This function should be rarely used in situations where
00091  * something must be shutdown to avoid corruption, excessive data
00092  * loss, or when external programs must be stopped.  All other
00093  * cleanup in the core should use ast_register_cleanup.
00094  */
00095 int ast_register_atexit(void (*func)(void));
00096 
00097 /*!
00098  * \since 11.9
00099  * \brief Register a function to be executed before Asterisk gracefully exits.
00100  *
00101  * If Asterisk is immediately shutdown (core stop now, or sending the TERM
00102  * signal), the callback is not run. When the callbacks are run, they are run in
00103  * sequence with ast_register_atexit() callbacks, in the reverse order of
00104  * registration.
00105  *
00106  * \param func The callback function to use.
00107  *
00108  * \retval 0 on success.
00109  * \retval -1 on error.
00110  */
00111 int ast_register_cleanup(void (*func)(void));
00112 
00113 /*!
00114  * \brief Unregister a function registered with ast_register_atexit().
00115  * \param func The callback function to unregister.
00116  */
00117 void ast_unregister_atexit(void (*func)(void));
00118 
00119 /*!
00120  * \brief Cancel an existing shutdown and return to normal operation.
00121  *
00122  * \note Shutdown can be cancelled while the server is waiting for
00123  * any existing channels to be destroyed before shutdown becomes
00124  * irreversible.
00125  *
00126  * \return non-zero if shutdown cancelled.
00127  */
00128 int ast_cancel_shutdown(void);
00129 
00130 /*!
00131  * \details
00132  * The server is preventing new channel creation in preparation for
00133  * shutdown and may actively be releasing resources.  The shutdown
00134  * process may be canceled by ast_cancel_shutdown() if it is not too
00135  * late.
00136  *
00137  * \note The preparation to shutdown phase can be quite lengthy
00138  * if we are gracefully shutting down.  How long existing calls will
00139  * last is not up to us.
00140  *
00141  * \return non-zero if the server is preparing to or actively shutting down.
00142  */
00143 int ast_shutting_down(void);
00144 
00145 /*!
00146  * \return non-zero if the server is actively shutting down.
00147  * \since 13.3.0
00148  *
00149  * \details
00150  * The server is releasing resources and unloading modules.
00151  * It won't be long now.
00152  */
00153 int ast_shutdown_final(void);
00154 
00155 #if !defined(LOW_MEMORY)
00156 /*!
00157  * \brief Register the version of a source code file with the core.
00158  * \param file the source file name
00159  * \param version the version string (typically a SVN revision keyword string)
00160  * \return nothing
00161  *
00162  * This function should not be called directly, but instead the
00163  * ASTERISK_FILE_VERSION macro should be used to register a file with the core.
00164  */
00165 void ast_register_file_version(const char *file, const char *version);
00166 
00167 /*!
00168  * \brief Unregister a source code file from the core.
00169  * \param file the source file name
00170  * \return nothing
00171  *
00172  * This function should not be called directly, but instead the
00173  * ASTERISK_FILE_VERSION macro should be used to automatically unregister
00174  * the file when the module is unloaded.
00175  */
00176 void ast_unregister_file_version(const char *file);
00177 
00178 /*! \brief Find version for given module name
00179  * \param file Module name (i.e. chan_sip.so)
00180  * \return version string or NULL if the module is not found
00181  */
00182 const char *ast_file_version_find(const char *file);
00183 
00184 char *ast_complete_source_filename(const char *partial, int n);
00185 
00186 /*!
00187  * \brief Register/unregister a source code file with the core.
00188  * \param file the source file name
00189  * \param version the version string (typically a SVN revision keyword string)
00190  *
00191  * This macro will place a file-scope constructor and destructor into the
00192  * source of the module using it; this will cause the version of this file
00193  * to registered with the Asterisk core (and unregistered) at the appropriate
00194  * times.
00195  *
00196  * Example:
00197  *
00198  * \code
00199  * ASTERISK_FILE_VERSION(__FILE__, "\$Revision\$")
00200  * \endcode
00201  *
00202  * \note The dollar signs above have been protected with backslashes to keep
00203  * SVN from modifying them in this file; under normal circumstances they would
00204  * not be present and SVN would expand the Revision keyword into the file's
00205  * revision number.
00206  */
00207 #ifdef MTX_PROFILE
00208 #define  HAVE_MTX_PROFILE  /* used in lock.h */
00209 #define ASTERISK_FILE_VERSION(file, version) \
00210    static int mtx_prof = -1;       /* profile mutex */   \
00211    static void __attribute__((constructor)) __register_file_version(void) \
00212    { \
00213       mtx_prof = ast_add_profile("mtx_lock_" file, 0);   \
00214       ast_register_file_version(file, version); \
00215    } \
00216    static void __attribute__((destructor)) __unregister_file_version(void) \
00217    { \
00218       ast_unregister_file_version(file); \
00219    }
00220 #else /* !MTX_PROFILE */
00221 #define ASTERISK_FILE_VERSION(file, version) \
00222    static void __attribute__((constructor)) __register_file_version(void) \
00223    { \
00224       ast_register_file_version(file, version); \
00225    } \
00226    static void __attribute__((destructor)) __unregister_file_version(void) \
00227    { \
00228       ast_unregister_file_version(file); \
00229    }
00230 #endif /* !MTX_PROFILE */
00231 #else /* LOW_MEMORY */
00232 #define ASTERISK_FILE_VERSION(file, x)
00233 #endif /* LOW_MEMORY */
00234 
00235 #if !defined(LOW_MEMORY)
00236 /*!
00237  * \brief support for event profiling
00238  *
00239  * (note, this must be documented a lot more)
00240  * ast_add_profile allocates a generic 'counter' with a given name,
00241  * which can be shown with the command 'core show profile &lt;name&gt;'
00242  *
00243  * The counter accumulates positive or negative values supplied by
00244  * \see ast_add_profile(), dividing them by the 'scale' value passed in the
00245  * create call, and also counts the number of 'events'.
00246  * Values can also be taked by the TSC counter on ia32 architectures,
00247  * in which case you can mark the start of an event calling ast_mark(id, 1)
00248  * and then the end of the event with ast_mark(id, 0).
00249  * For non-i386 architectures, these two calls return 0.
00250  */
00251 int ast_add_profile(const char *, uint64_t scale);
00252 int64_t ast_profile(int, int64_t);
00253 int64_t ast_mark(int, int start1_stop0);
00254 #else /* LOW_MEMORY */
00255 #define ast_add_profile(a, b) 0
00256 #define ast_profile(a, b) do { } while (0)
00257 #define ast_mark(a, b) do { } while (0)
00258 #endif /* LOW_MEMORY */
00259 
00260 /*! \brief
00261  * Definition of various structures that many asterisk files need,
00262  * but only because they need to know that the type exists.
00263  *
00264  */
00265 
00266 struct ast_channel;
00267 struct ast_frame;
00268 struct ast_module;
00269 struct ast_variable;
00270 struct ast_str;
00271 struct ast_sched_context;
00272 
00273 /* Some handy macros for turning a preprocessor token into (effectively) a quoted string */
00274 #define __stringify_1(x)   #x
00275 #define __stringify(x)     __stringify_1(x)
00276 
00277 #endif /* _ASTERISK_H */

Generated on Thu Apr 16 06:27:14 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6