asterisk.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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. * \brief Unregister a function registered with ast_register_atexit().
  80. * \param func The callback function to unregister.
  81. */
  82. void ast_unregister_atexit(void (*func)(void));
  83. #if !defined(LOW_MEMORY)
  84. /*!
  85. * \brief Register the version of a source code file with the core.
  86. * \param file the source file name
  87. * \param version the version string (typically a SVN revision keyword string)
  88. * \return nothing
  89. *
  90. * This function should not be called directly, but instead the
  91. * ASTERISK_FILE_VERSION macro should be used to register a file with the core.
  92. */
  93. void ast_register_file_version(const char *file, const char *version);
  94. /*!
  95. * \brief Unregister a source code file from the core.
  96. * \param file the source file name
  97. * \return nothing
  98. *
  99. * This function should not be called directly, but instead the
  100. * ASTERISK_FILE_VERSION macro should be used to automatically unregister
  101. * the file when the module is unloaded.
  102. */
  103. void ast_unregister_file_version(const char *file);
  104. /*! \brief Find version for given module name
  105. * \param file Module name (i.e. chan_sip.so)
  106. * \return version string or NULL if the module is not found
  107. */
  108. const char *ast_file_version_find(const char *file);
  109. char *ast_complete_source_filename(const char *partial, int n);
  110. /*!
  111. * \brief Register/unregister a source code file with the core.
  112. * \param file the source file name
  113. * \param version the version string (typically a SVN revision keyword string)
  114. *
  115. * This macro will place a file-scope constructor and destructor into the
  116. * source of the module using it; this will cause the version of this file
  117. * to registered with the Asterisk core (and unregistered) at the appropriate
  118. * times.
  119. *
  120. * Example:
  121. *
  122. * \code
  123. * ASTERISK_FILE_VERSION(__FILE__, "\$Revision\$")
  124. * \endcode
  125. *
  126. * \note The dollar signs above have been protected with backslashes to keep
  127. * SVN from modifying them in this file; under normal circumstances they would
  128. * not be present and SVN would expand the Revision keyword into the file's
  129. * revision number.
  130. */
  131. #ifdef MTX_PROFILE
  132. #define HAVE_MTX_PROFILE /* used in lock.h */
  133. #define ASTERISK_FILE_VERSION(file, version) \
  134. static int mtx_prof = -1; /* profile mutex */ \
  135. static void __attribute__((constructor)) __register_file_version(void) \
  136. { \
  137. mtx_prof = ast_add_profile("mtx_lock_" file, 0); \
  138. ast_register_file_version(file, version); \
  139. } \
  140. static void __attribute__((destructor)) __unregister_file_version(void) \
  141. { \
  142. ast_unregister_file_version(file); \
  143. }
  144. #else /* !MTX_PROFILE */
  145. #define ASTERISK_FILE_VERSION(file, version) \
  146. static void __attribute__((constructor)) __register_file_version(void) \
  147. { \
  148. ast_register_file_version(file, version); \
  149. } \
  150. static void __attribute__((destructor)) __unregister_file_version(void) \
  151. { \
  152. ast_unregister_file_version(file); \
  153. }
  154. #endif /* !MTX_PROFILE */
  155. #else /* LOW_MEMORY */
  156. #define ASTERISK_FILE_VERSION(file, x)
  157. #endif /* LOW_MEMORY */
  158. #if !defined(LOW_MEMORY)
  159. /*!
  160. * \brief support for event profiling
  161. *
  162. * (note, this must be documented a lot more)
  163. * ast_add_profile allocates a generic 'counter' with a given name,
  164. * which can be shown with the command 'core show profile &lt;name&gt;'
  165. *
  166. * The counter accumulates positive or negative values supplied by
  167. * \see ast_add_profile(), dividing them by the 'scale' value passed in the
  168. * create call, and also counts the number of 'events'.
  169. * Values can also be taked by the TSC counter on ia32 architectures,
  170. * in which case you can mark the start of an event calling ast_mark(id, 1)
  171. * and then the end of the event with ast_mark(id, 0).
  172. * For non-i386 architectures, these two calls return 0.
  173. */
  174. int ast_add_profile(const char *, uint64_t scale);
  175. int64_t ast_profile(int, int64_t);
  176. int64_t ast_mark(int, int start1_stop0);
  177. #else /* LOW_MEMORY */
  178. #define ast_add_profile(a, b) 0
  179. #define ast_profile(a, b) do { } while (0)
  180. #define ast_mark(a, b) do { } while (0)
  181. #endif /* LOW_MEMORY */
  182. /*! \brief
  183. * Definition of various structures that many asterisk files need,
  184. * but only because they need to know that the type exists.
  185. *
  186. */
  187. struct ast_channel;
  188. struct ast_frame;
  189. struct ast_module;
  190. struct ast_variable;
  191. struct ast_str;
  192. #ifdef bzero
  193. #undef bzero
  194. #endif
  195. #ifdef bcopy
  196. #undef bcopy
  197. #endif
  198. #define bzero 0x__dont_use_bzero__use_memset_instead""
  199. #define bcopy 0x__dont_use_bcopy__use_memmove_instead()
  200. #endif /* _ASTERISK_H */