asterisk.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  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. /*!
  99. * \brief Cancel an existing shutdown and return to normal operation.
  100. *
  101. * \note Shutdown can be cancelled while the server is waiting for
  102. * any existing channels to be destroyed before shutdown becomes
  103. * irreversible.
  104. *
  105. * \return non-zero if shutdown cancelled.
  106. */
  107. int ast_cancel_shutdown(void);
  108. /*!
  109. * \details
  110. * The server is preventing new channel creation in preparation for
  111. * shutdown and may actively be releasing resources. The shutdown
  112. * process may be canceled by ast_cancel_shutdown() if it is not too
  113. * late.
  114. *
  115. * \note The preparation to shutdown phase can be quite lengthy
  116. * if we are gracefully shutting down. How long existing calls will
  117. * last is not up to us.
  118. *
  119. * \return non-zero if the server is preparing to or actively shutting down.
  120. */
  121. int ast_shutting_down(void);
  122. /*!
  123. * \return non-zero if the server is actively shutting down.
  124. * \since 13.3.0
  125. *
  126. * \details
  127. * The server is releasing resources and unloading modules.
  128. * It won't be long now.
  129. */
  130. int ast_shutdown_final(void);
  131. #if !defined(LOW_MEMORY)
  132. /*!
  133. * \brief Register the version of a source code file with the core.
  134. * \param file the source file name
  135. * \param version the version string (typically a SVN revision keyword string)
  136. * \return nothing
  137. *
  138. * This function should not be called directly, but instead the
  139. * ASTERISK_FILE_VERSION macro should be used to register a file with the core.
  140. */
  141. void ast_register_file_version(const char *file, const char *version);
  142. /*!
  143. * \brief Unregister a source code file from the core.
  144. * \param file the source file name
  145. * \return nothing
  146. *
  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.
  150. */
  151. void ast_unregister_file_version(const char *file);
  152. /*! \brief Find version for given module name
  153. * \param file Module name (i.e. chan_sip.so)
  154. * \return version string or NULL if the module is not found
  155. */
  156. const char *ast_file_version_find(const char *file);
  157. char *ast_complete_source_filename(const char *partial, int n);
  158. /*!
  159. * \brief Register/unregister a source code file with the core.
  160. * \param file the source file name
  161. * \param version the version string (typically a SVN revision keyword string)
  162. *
  163. * This macro will place a file-scope constructor and destructor into the
  164. * source of the module using it; this will cause the version of this file
  165. * to registered with the Asterisk core (and unregistered) at the appropriate
  166. * times.
  167. *
  168. * Example:
  169. *
  170. * \code
  171. * ASTERISK_FILE_VERSION(__FILE__, "\$Revision\$")
  172. * \endcode
  173. *
  174. * \note The dollar signs above have been protected with backslashes to keep
  175. * SVN from modifying them in this file; under normal circumstances they would
  176. * not be present and SVN would expand the Revision keyword into the file's
  177. * revision number.
  178. */
  179. #ifdef MTX_PROFILE
  180. #define HAVE_MTX_PROFILE /* used in lock.h */
  181. #define ASTERISK_FILE_VERSION(file, version) \
  182. static int mtx_prof = -1; /* profile mutex */ \
  183. static void __attribute__((constructor)) __register_file_version(void) \
  184. { \
  185. mtx_prof = ast_add_profile("mtx_lock_" file, 0); \
  186. ast_register_file_version(file, version); \
  187. } \
  188. static void __attribute__((destructor)) __unregister_file_version(void) \
  189. { \
  190. ast_unregister_file_version(file); \
  191. }
  192. #else /* !MTX_PROFILE */
  193. #define ASTERISK_FILE_VERSION(file, version) \
  194. static void __attribute__((constructor)) __register_file_version(void) \
  195. { \
  196. ast_register_file_version(file, version); \
  197. } \
  198. static void __attribute__((destructor)) __unregister_file_version(void) \
  199. { \
  200. ast_unregister_file_version(file); \
  201. }
  202. #endif /* !MTX_PROFILE */
  203. #else /* LOW_MEMORY */
  204. #define ASTERISK_FILE_VERSION(file, x)
  205. #endif /* LOW_MEMORY */
  206. #if !defined(LOW_MEMORY)
  207. /*!
  208. * \brief support for event profiling
  209. *
  210. * (note, this must be documented a lot more)
  211. * ast_add_profile allocates a generic 'counter' with a given name,
  212. * which can be shown with the command 'core show profile &lt;name&gt;'
  213. *
  214. * The counter accumulates positive or negative values supplied by
  215. * \see ast_add_profile(), dividing them by the 'scale' value passed in the
  216. * create call, and also counts the number of 'events'.
  217. * Values can also be taked by the TSC counter on ia32 architectures,
  218. * in which case you can mark the start of an event calling ast_mark(id, 1)
  219. * and then the end of the event with ast_mark(id, 0).
  220. * For non-i386 architectures, these two calls return 0.
  221. */
  222. int ast_add_profile(const char *, uint64_t scale);
  223. int64_t ast_profile(int, int64_t);
  224. int64_t ast_mark(int, int start1_stop0);
  225. #else /* LOW_MEMORY */
  226. #define ast_add_profile(a, b) 0
  227. #define ast_profile(a, b) do { } while (0)
  228. #define ast_mark(a, b) do { } while (0)
  229. #endif /* LOW_MEMORY */
  230. /*! \brief
  231. * Definition of various structures that many asterisk files need,
  232. * but only because they need to know that the type exists.
  233. *
  234. */
  235. struct ast_channel;
  236. struct ast_frame;
  237. struct ast_module;
  238. struct ast_variable;
  239. struct ast_str;
  240. struct ast_sched_context;
  241. /* Some handy macros for turning a preprocessor token into (effectively) a quoted string */
  242. #define __stringify_1(x) #x
  243. #define __stringify(x) __stringify_1(x)
  244. #endif /* _ASTERISK_H */