asterisk.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. /*
  2. * Asterisk -- A telephony toolkit for Linux.
  3. *
  4. * General Definitions for Asterisk top level program
  5. *
  6. * Copyright (C) 1999-2006, Digium, Inc.
  7. *
  8. * Mark Spencer <markster@digium.com>
  9. *
  10. * This program is free software, distributed under the terms of
  11. * the GNU General Public License
  12. */
  13. /*! \file
  14. * \brief Asterisk main include file. File version handling, generic pbx functions.
  15. */
  16. #ifndef _ASTERISK_H
  17. #define _ASTERISK_H
  18. #include "asterisk/autoconfig.h"
  19. #if !defined(NO_MALLOC_DEBUG) && !defined(STANDALONE) && !defined(STANDALONE2) && defined(MALLOC_DEBUG)
  20. #include "asterisk/astmm.h"
  21. #endif
  22. #include "asterisk/compat.h"
  23. /* Default to allowing the umask or filesystem ACLs to determine actual file
  24. * creation permissions
  25. */
  26. #ifndef AST_DIR_MODE
  27. #define AST_DIR_MODE 0777
  28. #endif
  29. #ifndef AST_FILE_MODE
  30. #define AST_FILE_MODE 0666
  31. #endif
  32. #define DEFAULT_LANGUAGE "en"
  33. #define DEFAULT_SAMPLE_RATE 8000
  34. #define DEFAULT_SAMPLES_PER_MS ((DEFAULT_SAMPLE_RATE)/1000)
  35. #define setpriority __PLEASE_USE_ast_set_priority_INSTEAD_OF_setpriority__
  36. #define sched_setscheduler __PLEASE_USE_ast_set_priority_INSTEAD_OF_sched_setscheduler__
  37. #if defined(DEBUG_FD_LEAKS) && !defined(STANDALONE) && !defined(STANDALONE2) && !defined(STANDALONE_AEL)
  38. /* These includes are all about ordering */
  39. #include <stdio.h>
  40. #include <sys/types.h>
  41. #include <sys/stat.h>
  42. #include <sys/socket.h>
  43. #include <fcntl.h>
  44. #define open(a,...) __ast_fdleak_open(__FILE__,__LINE__,__PRETTY_FUNCTION__, a, __VA_ARGS__)
  45. #define pipe(a) __ast_fdleak_pipe(a, __FILE__,__LINE__,__PRETTY_FUNCTION__)
  46. #define socket(a,b,c) __ast_fdleak_socket(a, b, c, __FILE__,__LINE__,__PRETTY_FUNCTION__)
  47. #define close(a) __ast_fdleak_close(a)
  48. #define fopen(a,b) __ast_fdleak_fopen(a, b, __FILE__,__LINE__,__PRETTY_FUNCTION__)
  49. #define fclose(a) __ast_fdleak_fclose(a)
  50. #define dup2(a,b) __ast_fdleak_dup2(a, b, __FILE__,__LINE__,__PRETTY_FUNCTION__)
  51. #define dup(a) __ast_fdleak_dup(a, __FILE__,__LINE__,__PRETTY_FUNCTION__)
  52. #if defined(__cplusplus) || defined(c_plusplus)
  53. extern "C" {
  54. #endif
  55. int __ast_fdleak_open(const char *file, int line, const char *func, const char *path, int flags, ...);
  56. int __ast_fdleak_pipe(int *fds, const char *file, int line, const char *func);
  57. int __ast_fdleak_socket(int domain, int type, int protocol, const char *file, int line, const char *func);
  58. int __ast_fdleak_close(int fd);
  59. FILE *__ast_fdleak_fopen(const char *path, const char *mode, const char *file, int line, const char *func);
  60. int __ast_fdleak_fclose(FILE *ptr);
  61. int __ast_fdleak_dup2(int oldfd, int newfd, const char *file, int line, const char *func);
  62. int __ast_fdleak_dup(int oldfd, const char *file, int line, const char *func);
  63. #if defined(__cplusplus) || defined(c_plusplus)
  64. }
  65. #endif
  66. #endif
  67. int ast_set_priority(int); /*!< Provided by asterisk.c */
  68. int ast_fd_init(void); /*!< Provided by astfd.c */
  69. int ast_pbx_init(void); /*!< Provided by pbx.c */
  70. /*!
  71. * \brief Register a function to be executed before Asterisk exits.
  72. * \param func The callback function to use.
  73. *
  74. * \retval 0 on success.
  75. * \retval -1 on error.
  76. */
  77. int ast_register_atexit(void (*func)(void));
  78. /*!
  79. * \since 11.9
  80. * \brief Register a function to be executed before Asterisk gracefully exits.
  81. *
  82. * If Asterisk is immediately shutdown (core stop now, or sending the TERM
  83. * signal), the callback is not run. When the callbacks are run, they are run in
  84. * sequence with ast_register_atexit() callbacks, in the reverse order of
  85. * registration.
  86. *
  87. * \param func The callback function to use.
  88. *
  89. * \retval 0 on success.
  90. * \retval -1 on error.
  91. */
  92. int ast_register_cleanup(void (*func)(void));
  93. /*!
  94. * \brief Unregister a function registered with ast_register_atexit().
  95. * \param func The callback function to unregister.
  96. */
  97. void ast_unregister_atexit(void (*func)(void));
  98. #if !defined(LOW_MEMORY)
  99. /*!
  100. * \brief Register the version of a source code file with the core.
  101. * \param file the source file name
  102. * \param version the version string (typically a SVN revision keyword string)
  103. * \return nothing
  104. *
  105. * This function should not be called directly, but instead the
  106. * ASTERISK_FILE_VERSION macro should be used to register a file with the core.
  107. */
  108. void ast_register_file_version(const char *file, const char *version);
  109. /*!
  110. * \brief Unregister a source code file from the core.
  111. * \param file the source file name
  112. * \return nothing
  113. *
  114. * This function should not be called directly, but instead the
  115. * ASTERISK_FILE_VERSION macro should be used to automatically unregister
  116. * the file when the module is unloaded.
  117. */
  118. void ast_unregister_file_version(const char *file);
  119. /*! \brief Find version for given module name
  120. * \param file Module name (i.e. chan_sip.so)
  121. * \return version string or NULL if the module is not found
  122. */
  123. const char *ast_file_version_find(const char *file);
  124. char *ast_complete_source_filename(const char *partial, int n);
  125. /*!
  126. * \brief Register/unregister a source code file with the core.
  127. * \param file the source file name
  128. * \param version the version string (typically a SVN revision keyword string)
  129. *
  130. * This macro will place a file-scope constructor and destructor into the
  131. * source of the module using it; this will cause the version of this file
  132. * to registered with the Asterisk core (and unregistered) at the appropriate
  133. * times.
  134. *
  135. * Example:
  136. *
  137. * \code
  138. * ASTERISK_FILE_VERSION(__FILE__, "\$Revision\$")
  139. * \endcode
  140. *
  141. * \note The dollar signs above have been protected with backslashes to keep
  142. * SVN from modifying them in this file; under normal circumstances they would
  143. * not be present and SVN would expand the Revision keyword into the file's
  144. * revision number.
  145. */
  146. #ifdef MTX_PROFILE
  147. #define HAVE_MTX_PROFILE /* used in lock.h */
  148. #define ASTERISK_FILE_VERSION(file, version) \
  149. static int mtx_prof = -1; /* profile mutex */ \
  150. static void __attribute__((constructor)) __register_file_version(void) \
  151. { \
  152. mtx_prof = ast_add_profile("mtx_lock_" file, 0); \
  153. ast_register_file_version(file, version); \
  154. } \
  155. static void __attribute__((destructor)) __unregister_file_version(void) \
  156. { \
  157. ast_unregister_file_version(file); \
  158. }
  159. #else /* !MTX_PROFILE */
  160. #define ASTERISK_FILE_VERSION(file, version) \
  161. static void __attribute__((constructor)) __register_file_version(void) \
  162. { \
  163. ast_register_file_version(file, version); \
  164. } \
  165. static void __attribute__((destructor)) __unregister_file_version(void) \
  166. { \
  167. ast_unregister_file_version(file); \
  168. }
  169. #endif /* !MTX_PROFILE */
  170. #else /* LOW_MEMORY */
  171. #define ASTERISK_FILE_VERSION(file, x)
  172. #endif /* LOW_MEMORY */
  173. #if !defined(LOW_MEMORY)
  174. /*!
  175. * \brief support for event profiling
  176. *
  177. * (note, this must be documented a lot more)
  178. * ast_add_profile allocates a generic 'counter' with a given name,
  179. * which can be shown with the command 'core show profile &lt;name&gt;'
  180. *
  181. * The counter accumulates positive or negative values supplied by
  182. * \see ast_add_profile(), dividing them by the 'scale' value passed in the
  183. * create call, and also counts the number of 'events'.
  184. * Values can also be taked by the TSC counter on ia32 architectures,
  185. * in which case you can mark the start of an event calling ast_mark(id, 1)
  186. * and then the end of the event with ast_mark(id, 0).
  187. * For non-i386 architectures, these two calls return 0.
  188. */
  189. int ast_add_profile(const char *, uint64_t scale);
  190. int64_t ast_profile(int, int64_t);
  191. int64_t ast_mark(int, int start1_stop0);
  192. #else /* LOW_MEMORY */
  193. #define ast_add_profile(a, b) 0
  194. #define ast_profile(a, b) do { } while (0)
  195. #define ast_mark(a, b) do { } while (0)
  196. #endif /* LOW_MEMORY */
  197. /*! \brief
  198. * Definition of various structures that many asterisk files need,
  199. * but only because they need to know that the type exists.
  200. *
  201. */
  202. struct ast_channel;
  203. struct ast_frame;
  204. struct ast_module;
  205. struct ast_variable;
  206. struct ast_str;
  207. struct ast_sched_context;
  208. #ifdef bzero
  209. #undef bzero
  210. #endif
  211. #ifdef bcopy
  212. #undef bcopy
  213. #endif
  214. #define bzero 0x__dont_use_bzero__use_memset_instead""
  215. #define bcopy 0x__dont_use_bcopy__use_memmove_instead()
  216. /* Some handy macros for turning a preprocessor token into (effectively) a quoted string */
  217. #define __stringify_1(x) #x
  218. #define __stringify(x) __stringify_1(x)
  219. #endif /* _ASTERISK_H */