1999-10-24 16:47:59 +00:00
|
|
|
/*
|
2012-10-18 14:17:40 +00:00
|
|
|
* Asterisk -- An open source telephony toolkit.
|
1999-10-24 16:47:59 +00:00
|
|
|
*
|
|
|
|
* General Definitions for Asterisk top level program
|
2008-12-31 23:07:14 +00:00
|
|
|
*
|
2006-04-24 17:11:45 +00:00
|
|
|
* Copyright (C) 1999-2006, Digium, Inc.
|
1999-10-24 16:47:59 +00:00
|
|
|
*
|
2005-06-06 20:27:51 +00:00
|
|
|
* Mark Spencer <markster@digium.com>
|
1999-10-24 16:47:59 +00:00
|
|
|
*
|
|
|
|
* This program is free software, distributed under the terms of
|
|
|
|
* the GNU General Public License
|
|
|
|
*/
|
|
|
|
|
2005-10-26 13:03:17 +00:00
|
|
|
/*! \file
|
|
|
|
* \brief Asterisk main include file. File version handling, generic pbx functions.
|
|
|
|
*/
|
|
|
|
|
1999-10-24 16:47:59 +00:00
|
|
|
#ifndef _ASTERISK_H
|
|
|
|
#define _ASTERISK_H
|
|
|
|
|
2006-06-07 19:05:35 +00:00
|
|
|
#include "asterisk/autoconfig.h"
|
2006-06-07 18:54:56 +00:00
|
|
|
|
2010-11-27 10:00:35 +00:00
|
|
|
#if !defined(NO_MALLOC_DEBUG) && !defined(STANDALONE) && !defined(STANDALONE2) && defined(MALLOC_DEBUG)
|
2008-09-27 15:52:56 +00:00
|
|
|
#include "asterisk/astmm.h"
|
|
|
|
#endif
|
|
|
|
|
2006-04-24 17:11:45 +00:00
|
|
|
#include "asterisk/compat.h"
|
|
|
|
|
2006-12-21 19:44:20 +00:00
|
|
|
/* Default to allowing the umask or filesystem ACLs to determine actual file
|
|
|
|
* creation permissions
|
|
|
|
*/
|
|
|
|
#ifndef AST_DIR_MODE
|
|
|
|
#define AST_DIR_MODE 0777
|
|
|
|
#endif
|
|
|
|
#ifndef AST_FILE_MODE
|
|
|
|
#define AST_FILE_MODE 0666
|
|
|
|
#endif
|
|
|
|
|
2000-01-09 19:58:18 +00:00
|
|
|
#define DEFAULT_LANGUAGE "en"
|
|
|
|
|
2006-03-29 02:12:31 +00:00
|
|
|
#define DEFAULT_SAMPLE_RATE 8000
|
|
|
|
#define DEFAULT_SAMPLES_PER_MS ((DEFAULT_SAMPLE_RATE)/1000)
|
2007-04-09 03:04:07 +00:00
|
|
|
#define setpriority __PLEASE_USE_ast_set_priority_INSTEAD_OF_setpriority__
|
|
|
|
#define sched_setscheduler __PLEASE_USE_ast_set_priority_INSTEAD_OF_sched_setscheduler__
|
2006-03-29 02:12:31 +00:00
|
|
|
|
2010-11-27 10:00:35 +00:00
|
|
|
#if defined(DEBUG_FD_LEAKS) && !defined(STANDALONE) && !defined(STANDALONE2) && !defined(STANDALONE_AEL)
|
2009-04-09 04:59:05 +00:00
|
|
|
/* These includes are all about ordering */
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
|
|
|
#define open(a,...) __ast_fdleak_open(__FILE__,__LINE__,__PRETTY_FUNCTION__, a, __VA_ARGS__)
|
2009-08-17 16:25:10 +00:00
|
|
|
#define pipe(a) __ast_fdleak_pipe(a, __FILE__,__LINE__,__PRETTY_FUNCTION__)
|
2009-04-09 04:59:05 +00:00
|
|
|
#define socket(a,b,c) __ast_fdleak_socket(a, b, c, __FILE__,__LINE__,__PRETTY_FUNCTION__)
|
|
|
|
#define close(a) __ast_fdleak_close(a)
|
|
|
|
#define fopen(a,b) __ast_fdleak_fopen(a, b, __FILE__,__LINE__,__PRETTY_FUNCTION__)
|
|
|
|
#define fclose(a) __ast_fdleak_fclose(a)
|
|
|
|
#define dup2(a,b) __ast_fdleak_dup2(a, b, __FILE__,__LINE__,__PRETTY_FUNCTION__)
|
2009-08-17 16:25:10 +00:00
|
|
|
#define dup(a) __ast_fdleak_dup(a, __FILE__,__LINE__,__PRETTY_FUNCTION__)
|
2009-04-09 04:59:05 +00:00
|
|
|
|
2009-08-21 16:53:52 +00:00
|
|
|
#if defined(__cplusplus) || defined(c_plusplus)
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
2009-04-09 04:59:05 +00:00
|
|
|
int __ast_fdleak_open(const char *file, int line, const char *func, const char *path, int flags, ...);
|
|
|
|
int __ast_fdleak_pipe(int *fds, const char *file, int line, const char *func);
|
|
|
|
int __ast_fdleak_socket(int domain, int type, int protocol, const char *file, int line, const char *func);
|
|
|
|
int __ast_fdleak_close(int fd);
|
|
|
|
FILE *__ast_fdleak_fopen(const char *path, const char *mode, const char *file, int line, const char *func);
|
|
|
|
int __ast_fdleak_fclose(FILE *ptr);
|
|
|
|
int __ast_fdleak_dup2(int oldfd, int newfd, const char *file, int line, const char *func);
|
|
|
|
int __ast_fdleak_dup(int oldfd, const char *file, int line, const char *func);
|
2009-08-21 16:53:52 +00:00
|
|
|
#if defined(__cplusplus) || defined(c_plusplus)
|
|
|
|
}
|
|
|
|
#endif
|
2009-04-09 04:59:05 +00:00
|
|
|
#endif
|
|
|
|
|
2006-06-08 07:29:46 +00:00
|
|
|
int ast_set_priority(int); /*!< Provided by asterisk.c */
|
2009-04-09 04:59:05 +00:00
|
|
|
int ast_fd_init(void); /*!< Provided by astfd.c */
|
2010-11-30 09:49:25 +00:00
|
|
|
int ast_pbx_init(void); /*!< Provided by pbx.c */
|
2006-04-14 14:08:19 +00:00
|
|
|
|
2006-04-11 15:55:56 +00:00
|
|
|
/*!
|
|
|
|
* \brief Register a function to be executed before Asterisk exits.
|
|
|
|
* \param func The callback function to use.
|
2006-04-14 14:08:19 +00:00
|
|
|
*
|
2007-07-23 14:32:04 +00:00
|
|
|
* \retval 0 on success.
|
|
|
|
* \retval -1 on error.
|
2006-04-11 15:55:56 +00:00
|
|
|
*/
|
|
|
|
int ast_register_atexit(void (*func)(void));
|
2006-04-14 14:08:19 +00:00
|
|
|
|
Avoid unnecessary cleanups during immediate shutdown
This patch addresses issues during immediate shutdowns, where modules
are not unloaded, but Asterisk atexit handlers are run.
In the typical case, this usually isn't a big deal. But the
introduction of the Stasis message bus makes it much more likely for
asynchronous activity to be happening off in some thread during
shutdown.
During an immediate shutdown, Asterisk skips unloading modules. But
while it is processing the atexit handlers, there is a window of time
where some of the core message types have been cleaned up, but the
message bus is still running. Specifically, it's still running
module subscriptions that might be using the core message types. If a
message is received by that subscription in that window, it will
attempt to use a message type that has been cleaned up.
To solve this problem, this patch introduces ast_register_cleanup().
This function operates identically to ast_register_atexit(), except
that cleanup calls are not invoked on an immediate shutdown. All of
the core message type and topic cleanup was moved from atexit handlers
to cleanup handlers.
This ensures that core type and topic cleanup only happens if the
modules that used them are first unloaded.
This patch also changes the ast_assert() when accessing a cleaned up
or uninitialized message type to an error log message. Message type
functions are actually NULL safe across the board, so the assert was a
bit heavy handed. Especially for anyone with DO_CRASH enabled.
Review: https://reviewboard.asterisk.org/r/2562/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@390122 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-05-30 17:05:53 +00:00
|
|
|
/*!
|
|
|
|
* \since 12
|
|
|
|
* \brief Register a function to be executed before Asterisk gracefully exits.
|
|
|
|
*
|
|
|
|
* If Asterisk is immediately shutdown (core stop now, or sending the TERM
|
|
|
|
* signal), the callback is not run. When the callbacks are run, they are run in
|
|
|
|
* sequence with ast_register_atexit() callbacks, in the reverse order of
|
|
|
|
* registration.
|
|
|
|
*
|
|
|
|
* \param func The callback function to use.
|
|
|
|
*
|
|
|
|
* \retval 0 on success.
|
|
|
|
* \retval -1 on error.
|
|
|
|
*/
|
|
|
|
int ast_register_cleanup(void (*func)(void));
|
|
|
|
|
2008-12-31 23:07:14 +00:00
|
|
|
/*!
|
2006-04-11 15:55:56 +00:00
|
|
|
* \brief Unregister a function registered with ast_register_atexit().
|
2008-12-31 23:07:14 +00:00
|
|
|
* \param func The callback function to unregister.
|
2006-04-11 15:55:56 +00:00
|
|
|
*/
|
|
|
|
void ast_unregister_atexit(void (*func)(void));
|
|
|
|
|
2006-10-04 21:10:36 +00:00
|
|
|
#if !defined(LOW_MEMORY)
|
2005-06-07 01:13:23 +00:00
|
|
|
/*!
|
|
|
|
* \brief Register the version of a source code file with the core.
|
|
|
|
* \param file the source file name
|
2008-12-31 23:07:14 +00:00
|
|
|
* \param version the version string (typically a SVN revision keyword string)
|
2005-06-07 01:13:23 +00:00
|
|
|
* \return nothing
|
|
|
|
*
|
|
|
|
* This function should not be called directly, but instead the
|
|
|
|
* ASTERISK_FILE_VERSION macro should be used to register a file with the core.
|
|
|
|
*/
|
2005-06-06 20:27:51 +00:00
|
|
|
void ast_register_file_version(const char *file, const char *version);
|
2005-06-07 01:13:23 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Unregister a source code file from the core.
|
|
|
|
* \param file the source file name
|
|
|
|
* \return nothing
|
|
|
|
*
|
|
|
|
* This function should not be called directly, but instead the
|
|
|
|
* ASTERISK_FILE_VERSION macro should be used to automatically unregister
|
|
|
|
* the file when the module is unloaded.
|
|
|
|
*/
|
2005-06-06 20:27:51 +00:00
|
|
|
void ast_unregister_file_version(const char *file);
|
|
|
|
|
2007-11-27 21:04:29 +00:00
|
|
|
/*! \brief Find version for given module name
|
|
|
|
* \param file Module name (i.e. chan_sip.so)
|
|
|
|
* \return version string or NULL if the module is not found
|
|
|
|
*/
|
|
|
|
const char *ast_file_version_find(const char *file);
|
|
|
|
|
2008-12-10 17:09:15 +00:00
|
|
|
char *ast_complete_source_filename(const char *partial, int n);
|
2007-11-27 21:04:29 +00:00
|
|
|
|
2005-06-07 01:13:23 +00:00
|
|
|
/*!
|
|
|
|
* \brief Register/unregister a source code file with the core.
|
|
|
|
* \param file the source file name
|
2008-12-31 23:07:14 +00:00
|
|
|
* \param version the version string (typically a SVN revision keyword string)
|
2005-06-07 01:13:23 +00:00
|
|
|
*
|
|
|
|
* This macro will place a file-scope constructor and destructor into the
|
|
|
|
* source of the module using it; this will cause the version of this file
|
|
|
|
* to registered with the Asterisk core (and unregistered) at the appropriate
|
|
|
|
* times.
|
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
*
|
|
|
|
* \code
|
|
|
|
* ASTERISK_FILE_VERSION(__FILE__, "\$Revision\$")
|
|
|
|
* \endcode
|
2005-06-07 01:17:07 +00:00
|
|
|
*
|
|
|
|
* \note The dollar signs above have been protected with backslashes to keep
|
2008-12-31 23:07:14 +00:00
|
|
|
* SVN from modifying them in this file; under normal circumstances they would
|
|
|
|
* not be present and SVN would expand the Revision keyword into the file's
|
2005-06-07 01:17:07 +00:00
|
|
|
* revision number.
|
2005-06-07 01:13:23 +00:00
|
|
|
*/
|
2006-04-12 20:40:46 +00:00
|
|
|
#ifdef MTX_PROFILE
|
|
|
|
#define HAVE_MTX_PROFILE /* used in lock.h */
|
|
|
|
#define ASTERISK_FILE_VERSION(file, version) \
|
|
|
|
static int mtx_prof = -1; /* profile mutex */ \
|
|
|
|
static void __attribute__((constructor)) __register_file_version(void) \
|
|
|
|
{ \
|
|
|
|
mtx_prof = ast_add_profile("mtx_lock_" file, 0); \
|
|
|
|
ast_register_file_version(file, version); \
|
|
|
|
} \
|
|
|
|
static void __attribute__((destructor)) __unregister_file_version(void) \
|
|
|
|
{ \
|
|
|
|
ast_unregister_file_version(file); \
|
|
|
|
}
|
2006-10-04 21:10:36 +00:00
|
|
|
#else /* !MTX_PROFILE */
|
2005-06-06 22:12:19 +00:00
|
|
|
#define ASTERISK_FILE_VERSION(file, version) \
|
2005-06-06 20:27:51 +00:00
|
|
|
static void __attribute__((constructor)) __register_file_version(void) \
|
|
|
|
{ \
|
2005-06-06 22:12:19 +00:00
|
|
|
ast_register_file_version(file, version); \
|
2005-06-06 20:27:51 +00:00
|
|
|
} \
|
|
|
|
static void __attribute__((destructor)) __unregister_file_version(void) \
|
|
|
|
{ \
|
2005-06-06 22:12:19 +00:00
|
|
|
ast_unregister_file_version(file); \
|
2005-06-06 20:27:51 +00:00
|
|
|
}
|
2006-10-04 21:10:36 +00:00
|
|
|
#endif /* !MTX_PROFILE */
|
2005-06-07 16:07:06 +00:00
|
|
|
#else /* LOW_MEMORY */
|
|
|
|
#define ASTERISK_FILE_VERSION(file, x)
|
2006-10-04 21:10:36 +00:00
|
|
|
#endif /* LOW_MEMORY */
|
|
|
|
|
|
|
|
#if !defined(LOW_MEMORY)
|
|
|
|
/*!
|
|
|
|
* \brief support for event profiling
|
|
|
|
*
|
|
|
|
* (note, this must be documented a lot more)
|
|
|
|
* ast_add_profile allocates a generic 'counter' with a given name,
|
2009-04-01 20:13:28 +00:00
|
|
|
* which can be shown with the command 'core show profile <name>'
|
2006-10-04 21:10:36 +00:00
|
|
|
*
|
|
|
|
* The counter accumulates positive or negative values supplied by
|
2009-04-01 20:13:28 +00:00
|
|
|
* \see ast_add_profile(), dividing them by the 'scale' value passed in the
|
2006-10-04 21:10:36 +00:00
|
|
|
* create call, and also counts the number of 'events'.
|
|
|
|
* Values can also be taked by the TSC counter on ia32 architectures,
|
|
|
|
* in which case you can mark the start of an event calling ast_mark(id, 1)
|
|
|
|
* and then the end of the event with ast_mark(id, 0).
|
|
|
|
* For non-i386 architectures, these two calls return 0.
|
|
|
|
*/
|
|
|
|
int ast_add_profile(const char *, uint64_t scale);
|
|
|
|
int64_t ast_profile(int, int64_t);
|
|
|
|
int64_t ast_mark(int, int start1_stop0);
|
|
|
|
#else /* LOW_MEMORY */
|
|
|
|
#define ast_add_profile(a, b) 0
|
|
|
|
#define ast_profile(a, b) do { } while (0)
|
|
|
|
#define ast_mark(a, b) do { } while (0)
|
|
|
|
#endif /* LOW_MEMORY */
|
2005-06-06 20:27:51 +00:00
|
|
|
|
2007-11-21 16:07:11 +00:00
|
|
|
/*! \brief
|
|
|
|
* Definition of various structures that many asterisk files need,
|
|
|
|
* but only because they need to know that the type exists.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct ast_channel;
|
|
|
|
struct ast_frame;
|
|
|
|
struct ast_module;
|
2007-11-22 03:50:04 +00:00
|
|
|
struct ast_variable;
|
|
|
|
struct ast_str;
|
2010-12-20 17:15:54 +00:00
|
|
|
struct ast_sched_context;
|
2007-11-21 16:07:11 +00:00
|
|
|
|
2012-01-30 21:21:16 +00:00
|
|
|
/* Some handy macros for turning a preprocessor token into (effectively) a quoted string */
|
|
|
|
#define __stringify_1(x) #x
|
|
|
|
#define __stringify(x) __stringify_1(x)
|
|
|
|
|
2005-06-06 20:27:51 +00:00
|
|
|
#endif /* _ASTERISK_H */
|