root/src/include/ftdm_declare.h

/* [<][>][^][v][top][bottom][index][help] */

INCLUDED FROM


   1 /*
   2  * Copyright (c) 2010, Sangoma Technologies
   3  * Moises Silva <moy@sangoma.com>
   4  * All rights reserved.
   5  * 
   6  * Redistribution and use in source and binary forms, with or without
   7  * modification, are permitted provided that the following conditions
   8  * are met:
   9  * 
  10  * * Redistributions of source code must retain the above copyright
  11  * notice, this list of conditions and the following disclaimer.
  12  * 
  13  * * Redistributions in binary form must reproduce the above copyright
  14  * notice, this list of conditions and the following disclaimer in the
  15  * documentation and/or other materials provided with the distribution.
  16  * 
  17  * * Neither the name of the original author; nor the names of any contributors
  18  * may be used to endorse or promote products derived from this software
  19  * without specific prior written permission.
  20  * 
  21  * 
  22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  23  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  25  * A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER
  26  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  27  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  28  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  29  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  30  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  31  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  32  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  33  */
  34 
  35 #ifndef __FTDM_DECLARE_H__
  36 #define __FTDM_DECLARE_H__
  37 
  38 #ifdef __cplusplus
  39 extern "C" {
  40 #endif
  41 
  42 #if !defined(_XOPEN_SOURCE) && !defined(__FreeBSD__)
  43 #define _XOPEN_SOURCE 600
  44 #endif
  45 
  46 #ifndef HAVE_STRINGS_H
  47 #define HAVE_STRINGS_H 1
  48 #endif
  49 #ifndef HAVE_SYS_SOCKET_H
  50 #define HAVE_SYS_SOCKET_H 1
  51 #endif
  52 
  53 #ifndef __WINDOWS__
  54 #if defined(WIN32) || defined(WIN64) || defined(_MSC_VER) || defined(_WIN32) || defined(_WIN64)
  55 #define __WINDOWS__
  56 #endif
  57 #endif
  58 
  59 #ifdef _MSC_VER
  60 #if defined(FT_DECLARE_STATIC)
  61 #define FT_DECLARE(type)                        type __stdcall
  62 #define FT_DECLARE_NONSTD(type)         type __cdecl
  63 #define FT_DECLARE_DATA
  64 #elif defined(FREETDM_EXPORTS)
  65 #define FT_DECLARE(type)                        __declspec(dllexport) type __stdcall
  66 #define FT_DECLARE_NONSTD(type)         __declspec(dllexport) type __cdecl
  67 #define FT_DECLARE_DATA                         __declspec(dllexport)
  68 #else
  69 #define FT_DECLARE(type)                        __declspec(dllimport) type __stdcall
  70 #define FT_DECLARE_NONSTD(type)         __declspec(dllimport) type __cdecl
  71 #define FT_DECLARE_DATA                         __declspec(dllimport)
  72 #endif
  73 #define FT_DECLARE_INLINE(type)         extern __inline__ type /* why extern? see http://support.microsoft.com/kb/123768 */
  74 #define EX_DECLARE_DATA                         __declspec(dllexport)
  75 #else
  76 #if (defined(__GNUC__) || defined(__SUNPRO_CC) || defined (__SUNPRO_C)) && defined(HAVE_VISIBILITY)
  77 #define FT_DECLARE(type)                __attribute__((visibility("default"))) type
  78 #define FT_DECLARE_NONSTD(type) __attribute__((visibility("default"))) type
  79 #define FT_DECLARE_DATA         __attribute__((visibility("default")))
  80 #else
  81 #define FT_DECLARE(type)                type
  82 #define FT_DECLARE_NONSTD(type) type
  83 #define FT_DECLARE_DATA
  84 #endif
  85 #define FT_DECLARE_INLINE(type)         __inline__ type
  86 #define EX_DECLARE_DATA
  87 #endif
  88 
  89 #ifdef _MSC_VER
  90 #ifndef __inline__
  91 #define __inline__ __inline
  92 #endif
  93 #if (_MSC_VER >= 1400)                  /* VC8+ */
  94 #ifndef _CRT_SECURE_NO_DEPRECATE
  95 #define _CRT_SECURE_NO_DEPRECATE
  96 #endif
  97 #ifndef _CRT_NONSTDC_NO_DEPRECATE
  98 #define _CRT_NONSTDC_NO_DEPRECATE
  99 #endif
 100 #endif
 101 #ifndef strcasecmp
 102 #define strcasecmp(s1, s2) _stricmp(s1, s2)
 103 #endif
 104 #ifndef strncasecmp
 105 #define strncasecmp(s1, s2, n) _strnicmp(s1, s2, n)
 106 #endif
 107 #ifndef snprintf
 108 #define snprintf _snprintf
 109 #endif
 110 #ifndef S_IRUSR
 111 #define S_IRUSR _S_IREAD
 112 #endif
 113 #ifndef S_IWUSR
 114 #define S_IWUSR _S_IWRITE
 115 #endif
 116 #undef HAVE_STRINGS_H
 117 #undef HAVE_SYS_SOCKET_H
 118 /* disable warning for zero length array in a struct */
 119 /* this will cause errors on c99 and ansi compliant compilers and will need to be fixed in the wanpipe header files */
 120 #pragma warning(disable:4706)
 121 #pragma comment(lib, "Winmm")
 122 #endif
 123 
 124 #define FTDM_STR2ENUM_P(_FUNC1, _FUNC2, _TYPE) FT_DECLARE(_TYPE) _FUNC1 (const char *name); FT_DECLARE(const char *) _FUNC2 (_TYPE type);
 125 #define FTDM_STR2ENUM(_FUNC1, _FUNC2, _TYPE, _STRINGS, _MAX)    \
 126         FT_DECLARE(_TYPE) _FUNC1 (const char *name)                                                     \
 127         {                                                                                                               \
 128                 int i;                                                                                          \
 129                 _TYPE t = _MAX ;                                                                        \
 130                                                                                                                         \
 131                 for (i = 0; i < _MAX ; i++) {                                           \
 132                         if (!strcasecmp(name, _STRINGS[i])) {                   \
 133                                 t = (_TYPE) i;                                                          \
 134                                 break;                                                                          \
 135                         }                                                                                               \
 136                 }                                                                                                       \
 137                                                                                                                         \
 138                 return t;                                                                                       \
 139         }                                                                                                               \
 140         FT_DECLARE(const char *) _FUNC2 (_TYPE type)                                            \
 141         {                                                                                                               \
 142                 if (type > _MAX) {                                                                      \
 143                         type = _MAX;                                                                    \
 144                 }                                                                                                       \
 145                 return _STRINGS[(int)type];                                                     \
 146         }                                                                                                               \
 147 
 148 #ifdef __WINDOWS__
 149 #include <stdio.h>
 150 #include <windows.h>
 151 #define FTDM_INVALID_SOCKET INVALID_HANDLE_VALUE
 152 typedef HANDLE ftdm_socket_t;
 153 typedef unsigned __int64 uint64_t;
 154 typedef unsigned __int32 uint32_t;
 155 typedef unsigned __int16 uint16_t;
 156 typedef unsigned __int8 uint8_t;
 157 typedef __int64 int64_t;
 158 typedef __int32 int32_t;
 159 typedef __int16 int16_t;
 160 typedef __int8 int8_t;
 161 #define FTDM_O_BINARY O_BINARY
 162 #define FTDM_SIZE_FMT "Id"
 163 #if defined(_MSC_VER) || defined(_MSC_EXTENSIONS)
 164 #define DELTA_EPOCH_IN_MICROSECS  11644473600000000Ui64
 165 #else
 166 #define DELTA_EPOCH_IN_MICROSECS  11644473600000000ULL
 167 #endif /* _MSC_VER */
 168 #else /* __WINDOWS__ */
 169 #define FTDM_O_BINARY 0
 170 #define FTDM_SIZE_FMT "zd"
 171 #define FTDM_INVALID_SOCKET -1
 172 typedef int ftdm_socket_t;
 173 #include <stdio.h>
 174 #include <stdint.h>
 175 #include <stdarg.h>
 176 #endif
 177 
 178 /*! \brief FreeTDM APIs possible return codes */
 179 typedef enum {
 180         FTDM_SUCCESS, /*!< Success */
 181         FTDM_FAIL, /*!< Failure, generic error return code, use ftdm_channel_get_last_error or ftdm_span_get_last_error for details */
 182         FTDM_MEMERR, /*!< Memory error, most likely allocation failure */
 183         FTDM_TIMEOUT, /*!< Operation timed out (ie: polling on a device)*/
 184         FTDM_NOTIMPL, /*!< Operation not implemented */
 185         FTDM_BREAK, /*!< Request the caller to perform a break (context-dependant, ie: stop getting DNIS/ANI) */
 186 
 187         /*!< Any new return codes should try to mimc unix style error codes, no need to reinvent */
 188         /* Remapping some of the codes that were before */
 189         FTDM_ENOMEM = FTDM_MEMERR, /*!< Memory error */
 190         FTDM_ETIMEDOUT = FTDM_TIMEOUT, /*!< Operation timedout */
 191         FTDM_ENOSYS = FTDM_NOTIMPL, /*!< The function is not implemented */
 192 
 193         FTDM_EINVAL, /*!< Invalid argument */
 194         FTDM_ECANCELED, /*!< Operation cancelled */
 195         FTDM_EBUSY, /*!< Device busy */
 196 } ftdm_status_t;
 197 
 198 /*! \brief FreeTDM bool type. */
 199 typedef enum {
 200         FTDM_FALSE,
 201         FTDM_TRUE
 202 } ftdm_bool_t;
 203 
 204 /*! 
 205  * \brief FreeTDM channel.
 206  *        This is the basic data structure used to place calls and I/O operations
 207  */
 208 typedef struct ftdm_channel ftdm_channel_t;
 209 
 210 /*! 
 211  * \brief FreeTDM span.
 212  *        Channel and signaling configuration container.
 213  *        This is a logical span structure, a span may ( or may note ) contain channels
 214  *        of other physical spans, depending on configuration (freetdm.conf) or if you
 215  *        are not using configuration depends on how you call ftdm_span_add_channel
 216  */
 217 typedef struct ftdm_span ftdm_span_t;
 218 
 219 typedef struct ftdm_event ftdm_event_t;
 220 typedef struct ftdm_conf_node ftdm_conf_node_t;
 221 typedef struct ftdm_group ftdm_group_t;
 222 typedef size_t ftdm_size_t;
 223 typedef struct ftdm_sigmsg ftdm_sigmsg_t;
 224 typedef struct ftdm_io_interface ftdm_io_interface_t;
 225 typedef struct ftdm_stream_handle ftdm_stream_handle_t;
 226 typedef struct ftdm_queue ftdm_queue_t;
 227 typedef struct ftdm_memory_handler ftdm_memory_handler_t;
 228 
 229 #ifdef __cplusplus
 230 } /* extern C */
 231 #endif
 232 
 233 #endif
 234 
 235 /* For Emacs:
 236  * Local Variables:
 237  * mode:c
 238  * indent-tabs-mode:t
 239  * tab-width:4
 240  * c-basic-offset:4
 241  * End:
 242  * For VIM:
 243  * vim:set softtabstop=4 shiftwidth=4 tabstop=4:
 244  */

/* [<][>][^][v][top][bottom][index][help] */