start API cleanup by moving private headers and data structures into private/ include directory
This commit is contained in:
parent
041a8f0d00
commit
73a80ba939
|
@ -36,7 +36,7 @@ moddir = @modinstdir@
|
|||
libdir = @libdir@
|
||||
library_includedir = $(PREFIX)/include
|
||||
|
||||
INCS = -I$(FT_SRCDIR)/$(SRC)/include -I$(FT_SRCDIR)/$(SRC)/isdn/include
|
||||
INCS = -I$(FT_SRCDIR)/$(SRC)/include -I$(FT_SRCDIR)/$(SRC)/isdn/include -I$(FT_SRCDIR)/$(SRC)/include/private
|
||||
if HAVE_SCTP
|
||||
INCS += -I$(FT_SRCDIR)/$(SRC)/ftmod/ftmod_sangoma_boost
|
||||
endif
|
||||
|
@ -76,23 +76,9 @@ $(SRC)/ftdm_dso.c \
|
|||
$(SRC)/ftdm_cpu_monitor.c
|
||||
|
||||
library_include_HEADERS = \
|
||||
$(SRC)/include/fsk.h \
|
||||
$(SRC)/include/g711.h \
|
||||
$(SRC)/include/hashtable.h \
|
||||
$(SRC)/include/hashtable_itr.h \
|
||||
$(SRC)/include/hashtable_private.h \
|
||||
$(SRC)/include/libteletone_detect.h \
|
||||
$(SRC)/include/libteletone_generate.h \
|
||||
$(SRC)/include/libteletone.h \
|
||||
$(SRC)/include/freetdm.h \
|
||||
$(SRC)/include/sangoma_tdm_api.h \
|
||||
$(SRC)/include/uart.h \
|
||||
$(SRC)/include/ftdm_buffer.h \
|
||||
$(SRC)/include/ftdm_config.h \
|
||||
$(SRC)/include/ftdm_threadmutex.h \
|
||||
$(SRC)/include/ftdm_dso.h \
|
||||
$(SRC)/include/ftdm_types.h \
|
||||
$(SRC)/include/ftdm_cpu_monitor.h
|
||||
$(SRC)/include/ftdm_os.h
|
||||
|
||||
lib_LTLIBRARIES = libfreetdm.la
|
||||
libfreetdm_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS)
|
||||
|
@ -275,4 +261,4 @@ install-data-local:
|
|||
$(mkinstalldirs) $(DESTDIR)$(PREFIX)
|
||||
$(mkinstalldirs) $(DESTDIR)@confdir@
|
||||
@[ -f "$(DESTDIR)@confdir@/freetdm.conf" ] || ( cp conf/*.conf $(DESTDIR)@confdir@)
|
||||
@echo OpenFTDM Installed
|
||||
@echo FreeTDM Installed
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
*
|
||||
* 2005 03 20 R. Krten created
|
||||
*/
|
||||
#include <freetdm.h>
|
||||
#include <private/ftdm_core.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "freetdm.h"
|
||||
#include "private/ftdm_core.h"
|
||||
#include "ftdm_buffer.h"
|
||||
|
||||
static unsigned buffer_id = 0;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#include "freetdm.h"
|
||||
#include "private/ftdm_core.h"
|
||||
#include "fsk.h"
|
||||
#include "uart.h"
|
||||
|
||||
|
|
|
@ -35,8 +35,7 @@
|
|||
* Moises Silva <moy@sangoma.com>
|
||||
*/
|
||||
|
||||
#include "freetdm.h"
|
||||
#include "ftdm_config.h"
|
||||
#include "private/ftdm_core.h"
|
||||
|
||||
int ftdm_config_open_file(ftdm_config_t *cfg, const char *file_path)
|
||||
{
|
||||
|
|
|
@ -50,7 +50,7 @@
|
|||
#include <errno.h>
|
||||
#endif
|
||||
|
||||
#include "freetdm.h"
|
||||
#include "private/ftdm_core.h"
|
||||
#include "ftdm_cpu_monitor.h"
|
||||
struct ftdm_cpu_monitor_stats
|
||||
{
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include "freetdm.h"
|
||||
#include "private/ftdm_core.h"
|
||||
#include "ftdm_dso.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
|
|
@ -40,7 +40,7 @@
|
|||
#define _GNU_SOURCE
|
||||
#ifndef WIN32
|
||||
#endif
|
||||
#include "freetdm.h"
|
||||
#include "private/ftdm_core.h"
|
||||
#include <stdarg.h>
|
||||
#ifdef WIN32
|
||||
#include <io.h>
|
||||
|
@ -1592,11 +1592,72 @@ FT_DECLARE(ftdm_status_t) ftdm_channel_open(uint32_t span_id, uint32_t chan_id,
|
|||
return status;
|
||||
}
|
||||
|
||||
FT_DECLARE(ftdm_status_t) ftdm_channel_outgoing_call(ftdm_channel_t *ftdmchan)
|
||||
FT_DECLARE(uint32_t) ftdm_channel_get_id(const ftdm_channel_t *ftdmchan)
|
||||
{
|
||||
return ftdmchan->chan_id;
|
||||
}
|
||||
|
||||
FT_DECLARE(uint32_t) ftdm_channel_get_ph_id(const ftdm_channel_t *ftdmchan)
|
||||
{
|
||||
return ftdmchan->physical_chan_id;
|
||||
}
|
||||
|
||||
FT_DECLARE(uint32_t) ftdm_channel_get_span_id(const ftdm_channel_t *ftdmchan)
|
||||
{
|
||||
return ftdmchan->span_id;
|
||||
}
|
||||
|
||||
FT_DECLARE(uint32_t) ftdm_span_get_id(const ftdm_span_t *span)
|
||||
{
|
||||
return span->span_id;
|
||||
}
|
||||
|
||||
FT_DECLARE(const char *) ftdm_span_get_name(const ftdm_span_t *span)
|
||||
{
|
||||
return span->name;
|
||||
}
|
||||
|
||||
FT_DECLARE(ftdm_bool_t) ftdm_channel_call_active(const ftdm_channel_t *ftdmchan)
|
||||
{
|
||||
return (ftdmchan->state == FTDM_CHANNEL_STATE_UP) ? FTDM_TRUE : FTDM_FALSE;
|
||||
}
|
||||
|
||||
FT_DECLARE(ftdm_status_t) ftdm_channel_call_answer(ftdm_channel_t *ftdmchan)
|
||||
{
|
||||
ftdm_set_state_locked_wait(ftdmchan, FTDM_CHANNEL_STATE_UP);
|
||||
return FTDM_SUCCESS;
|
||||
}
|
||||
|
||||
FT_DECLARE(ftdm_status_t) ftdm_channel_call_hangup(ftdm_channel_t *ftdmchan)
|
||||
{
|
||||
ftdm_set_state_locked_wait(ftdmchan, FTDM_CHANNEL_STATE_HANGUP);
|
||||
return FTDM_SUCCESS;
|
||||
}
|
||||
|
||||
FT_DECLARE(const char *) ftdm_channel_get_last_error(const ftdm_channel_t *ftdmchan)
|
||||
{
|
||||
return ftdmchan->last_error;
|
||||
}
|
||||
|
||||
FT_DECLARE(ftdm_status_t) ftdm_channel_call_indicate(ftdm_channel_t *ftdmchan, ftdm_channel_indication_t indication)
|
||||
{
|
||||
switch (indication) {
|
||||
case FTDM_CHANNEL_INDICATE_RING:
|
||||
ftdm_set_state_locked_wait(ftdmchan, FTDM_CHANNEL_STATE_RING);
|
||||
case FTDM_CHANNEL_INDICATE_PROGRESS:
|
||||
ftdm_set_state_locked_wait(ftdmchan, FTDM_CHANNEL_STATE_PROGRESS_MEDIA);
|
||||
default:
|
||||
ftdm_log(FTDM_LOG_DEBUG, "Do not know how to indicate %d\n", indication);
|
||||
return FTDM_FAIL;
|
||||
}
|
||||
return FTDM_SUCCESS;
|
||||
}
|
||||
|
||||
FT_DECLARE(ftdm_status_t) ftdm_channel_call_place(ftdm_channel_t *ftdmchan)
|
||||
{
|
||||
ftdm_status_t status;
|
||||
|
||||
assert(ftdmchan != NULL);
|
||||
ftdm_assert(ftdmchan != NULL, "null channel");
|
||||
|
||||
if (ftdmchan->span->outgoing_call) {
|
||||
if ((status = ftdmchan->span->outgoing_call(ftdmchan)) == FTDM_SUCCESS) {
|
||||
|
@ -1604,9 +1665,8 @@ FT_DECLARE(ftdm_status_t) ftdm_channel_outgoing_call(ftdm_channel_t *ftdmchan)
|
|||
}
|
||||
return status;
|
||||
} else {
|
||||
ftdm_log(FTDM_LOG_ERROR, "outgoing_call method not implemented!\n");
|
||||
ftdm_log(FTDM_LOG_ERROR, "outgoing_call method not implemented in this span!\n");
|
||||
}
|
||||
|
||||
return FTDM_FAIL;
|
||||
}
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "freetdm.h"
|
||||
#include "private/ftdm_core.h"
|
||||
|
||||
static ftdm_status_t ftdm_std_queue_create(ftdm_queue_t **outqueue, ftdm_size_t capacity);
|
||||
static ftdm_status_t ftdm_std_queue_enqueue(ftdm_queue_t *queue, void *obj);
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
#define _WIN32_WINNT 0x0400
|
||||
#endif
|
||||
|
||||
#include "freetdm.h"
|
||||
#include "private/ftdm_core.h"
|
||||
#include "ftdm_threadmutex.h"
|
||||
|
||||
#ifdef WIN32
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "freetdm.h"
|
||||
#include "private/ftdm_core.h"
|
||||
#include "ftdm_analog.h"
|
||||
|
||||
#ifndef localtime_r
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include "freetdm.h"
|
||||
#include "private/ftdm_core.h"
|
||||
#include "ftdm_analog_em.h"
|
||||
|
||||
#ifndef localtime_r
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <openr2.h>
|
||||
#include "freetdm.h"
|
||||
#include "private/ftdm_core.h"
|
||||
|
||||
/* debug thread count for r2 legs */
|
||||
static ftdm_mutex_t* g_thread_count_mutex;
|
||||
|
|
|
@ -43,7 +43,7 @@ On __WINDOWS__ platform this code works with sigmod ONLY, don't try to make sens
|
|||
I basically ifdef out everything that the compiler complained about
|
||||
*/
|
||||
|
||||
#include "freetdm.h"
|
||||
#include "private/ftdm_core.h"
|
||||
#include "sangoma_boost_client.h"
|
||||
#include "ftdm_sangoma_boost.h"
|
||||
#ifdef HAVE_SYS_SELECT_H
|
||||
|
|
|
@ -35,7 +35,7 @@
|
|||
#ifndef SANGOMA_BOOST_INTERFACE_H
|
||||
#define SANGOMA_BOOST_INTERFACE_H
|
||||
|
||||
#include "freetdm.h"
|
||||
#include "private/ftdm_core.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
*/
|
||||
|
||||
|
||||
#include "freetdm.h"
|
||||
#include "private/ftdm_core.h"
|
||||
//#include "ftdm_skel.h"
|
||||
|
||||
static FIO_CONFIGURE_FUNCTION(skel_configure)
|
||||
|
|
|
@ -42,7 +42,7 @@
|
|||
#include <unistd.h>
|
||||
#include <stropts.h>
|
||||
#endif
|
||||
#include "freetdm.h"
|
||||
#include "private/ftdm_core.h"
|
||||
#ifndef __WINDOWS__
|
||||
#include <poll.h>
|
||||
#include <sys/socket.h>
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
*/
|
||||
|
||||
|
||||
#include "freetdm.h"
|
||||
#include "private/ftdm_core.h"
|
||||
#include "ftmod_zt.h"
|
||||
|
||||
/**
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "freetdm.h"
|
||||
#include "private/ftdm_core.h"
|
||||
#include "hashtable.h"
|
||||
#include "hashtable_private.h"
|
||||
#include <stdlib.h>
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "freetdm.h"
|
||||
#include "private/ftdm_core.h"
|
||||
#include "hashtable.h"
|
||||
#include "hashtable_private.h"
|
||||
#include "hashtable_itr.h"
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,148 @@
|
|||
/*
|
||||
* Copyright (c) 2010, Sangoma Technologies
|
||||
* Moises Silva <moy@sangoma.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the original author; nor the names of any contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
|
||||
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef __FTDM_DECLARE_H__
|
||||
#define __FTDM_DECLARE_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* ######## start utility macros not to be used by customers, but needed in this header, may be move to another header ############ */
|
||||
|
||||
#ifndef __WINDOWS__
|
||||
#if defined(WIN32) || defined(WIN64) || defined(_MSC_VER) || defined(_WIN32) || defined(_WIN64)
|
||||
#define __WINDOWS__
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#if defined(FT_DECLARE_STATIC)
|
||||
#define FT_DECLARE(type) type __stdcall
|
||||
#define FT_DECLARE_NONSTD(type) type __cdecl
|
||||
#define FT_DECLARE_DATA
|
||||
#elif defined(FREETDM_EXPORTS)
|
||||
#define FT_DECLARE(type) __declspec(dllexport) type __stdcall
|
||||
#define FT_DECLARE_NONSTD(type) __declspec(dllexport) type __cdecl
|
||||
#define FT_DECLARE_DATA __declspec(dllexport)
|
||||
#else
|
||||
#define FT_DECLARE(type) __declspec(dllimport) type __stdcall
|
||||
#define FT_DECLARE_NONSTD(type) __declspec(dllimport) type __cdecl
|
||||
#define FT_DECLARE_DATA __declspec(dllimport)
|
||||
#endif
|
||||
#define EX_DECLARE_DATA __declspec(dllexport)
|
||||
#else
|
||||
#if (defined(__GNUC__) || defined(__SUNPRO_CC) || defined (__SUNPRO_C)) && defined(HAVE_VISIBILITY)
|
||||
#define FT_DECLARE(type) __attribute__((visibility("default"))) type
|
||||
#define FT_DECLARE_NONSTD(type) __attribute__((visibility("default"))) type
|
||||
#define FT_DECLARE_DATA __attribute__((visibility("default")))
|
||||
#else
|
||||
#define FT_DECLARE(type) type
|
||||
#define FT_DECLARE_NONSTD(type) type
|
||||
#define FT_DECLARE_DATA
|
||||
#endif
|
||||
#define EX_DECLARE_DATA
|
||||
#endif
|
||||
|
||||
#define FTDM_STR2ENUM_P(_FUNC1, _FUNC2, _TYPE) FT_DECLARE(_TYPE) _FUNC1 (const char *name); FT_DECLARE(const char *) _FUNC2 (_TYPE type);
|
||||
#define FTDM_STR2ENUM(_FUNC1, _FUNC2, _TYPE, _STRINGS, _MAX) \
|
||||
FT_DECLARE(_TYPE) _FUNC1 (const char *name) \
|
||||
{ \
|
||||
int i; \
|
||||
_TYPE t = _MAX ; \
|
||||
\
|
||||
for (i = 0; i < _MAX ; i++) { \
|
||||
if (!strcasecmp(name, _STRINGS[i])) { \
|
||||
t = (_TYPE) i; \
|
||||
break; \
|
||||
} \
|
||||
} \
|
||||
\
|
||||
return t; \
|
||||
} \
|
||||
FT_DECLARE(const char *) _FUNC2 (_TYPE type) \
|
||||
{ \
|
||||
if (type > _MAX) { \
|
||||
type = _MAX; \
|
||||
} \
|
||||
return _STRINGS[(int)type]; \
|
||||
} \
|
||||
|
||||
#ifdef WIN32
|
||||
#include <windows.h>
|
||||
#define FTDM_INVALID_SOCKET INVALID_HANDLE_VALUE
|
||||
typedef HANDLE ftdm_socket_t;
|
||||
typedef unsigned __int64 uint64_t;
|
||||
typedef unsigned __int32 uint32_t;
|
||||
typedef unsigned __int16 uint16_t;
|
||||
typedef unsigned __int8 uint8_t;
|
||||
typedef __int64 int64_t;
|
||||
typedef __int32 int32_t;
|
||||
typedef __int16 int16_t;
|
||||
typedef __int8 int8_t;
|
||||
#else
|
||||
#define FTDM_INVALID_SOCKET -1
|
||||
typedef int ftdm_socket_t;
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <stdarg.h>
|
||||
#endif
|
||||
|
||||
typedef struct ftdm_channel ftdm_channel_t;
|
||||
typedef struct ftdm_span ftdm_span_t;
|
||||
typedef struct ftdm_event ftdm_event_t;
|
||||
typedef struct ftdm_conf_node ftdm_conf_node_t;
|
||||
typedef struct ftdm_group ftdm_group_t;
|
||||
typedef size_t ftdm_size_t;
|
||||
typedef struct ftdm_sigmsg ftdm_sigmsg_t;
|
||||
typedef struct ftdm_io_interface ftdm_io_interface_t;
|
||||
typedef struct ftdm_stream_handle ftdm_stream_handle_t;
|
||||
typedef struct ftdm_queue ftdm_queue_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern C */
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/* For Emacs:
|
||||
* Local Variables:
|
||||
* mode:c
|
||||
* indent-tabs-mode:t
|
||||
* tab-width:4
|
||||
* c-basic-offset:4
|
||||
* End:
|
||||
* For VIM:
|
||||
* vim:set softtabstop=4 shiftwidth=4 tabstop=4:
|
||||
*/
|
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
* Copyright (c) 2010, Sangoma Technologies
|
||||
* Moises Silva <moy@sangoma.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the original author; nor the names of any contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
|
||||
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef __FTDM_OS_H__
|
||||
#define __FTDM_OS_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "ftdm_declare.h"
|
||||
#include "ftdm_threadmutex.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#ifndef __WINDOWS__
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#ifdef __WINDOWS__
|
||||
#define ftdm_sleep(x) Sleep(x)
|
||||
#else
|
||||
#define ftdm_sleep(x) usleep(x * 1000)
|
||||
#endif
|
||||
|
||||
#define ftdm_copy_string(x,y,z) strncpy(x, y, z - 1)
|
||||
#define ftdm_set_string(x,y) strncpy(x, y, sizeof(x)-1)
|
||||
#define ftdm_strlen_zero(s) (!s || *s == '\0')
|
||||
#define ftdm_strlen_zero_buf(s) (*s == '\0')
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern C */
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/* For Emacs:
|
||||
* Local Variables:
|
||||
* mode:c
|
||||
* indent-tabs-mode:t
|
||||
* tab-width:4
|
||||
* c-basic-offset:4
|
||||
* End:
|
||||
* For VIM:
|
||||
* vim:set softtabstop=4 shiftwidth=4 tabstop=4:
|
||||
*/
|
|
@ -30,6 +30,7 @@
|
|||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct ftdm_mutex ftdm_mutex_t;
|
||||
typedef struct ftdm_thread ftdm_thread_t;
|
||||
typedef struct ftdm_interrupt ftdm_interrupt_t;
|
||||
|
@ -38,11 +39,20 @@ typedef void *(*ftdm_thread_function_t) (ftdm_thread_t *, void *);
|
|||
FT_DECLARE(ftdm_status_t) ftdm_thread_create_detached(ftdm_thread_function_t func, void *data);
|
||||
FT_DECLARE(ftdm_status_t) ftdm_thread_create_detached_ex(ftdm_thread_function_t func, void *data, ftdm_size_t stack_size);
|
||||
FT_DECLARE(void) ftdm_thread_override_default_stacksize(ftdm_size_t size);
|
||||
|
||||
|
||||
FT_DECLARE(ftdm_status_t) ftdm_mutex_create(ftdm_mutex_t **mutex);
|
||||
FT_DECLARE(ftdm_status_t) ftdm_mutex_destroy(ftdm_mutex_t **mutex);
|
||||
|
||||
#define ftdm_mutex_lock(_x) _ftdm_mutex_lock(_x)
|
||||
FT_DECLARE(ftdm_status_t) _ftdm_mutex_lock(ftdm_mutex_t *mutex);
|
||||
|
||||
#define ftdm_mutex_trylock(_x) _ftdm_mutex_trylock(_x)
|
||||
FT_DECLARE(ftdm_status_t) _ftdm_mutex_trylock(ftdm_mutex_t *mutex);
|
||||
|
||||
#define ftdm_mutex_unlock(_x) _ftdm_mutex_unlock(_x)
|
||||
FT_DECLARE(ftdm_status_t) _ftdm_mutex_unlock(ftdm_mutex_t *mutex);
|
||||
|
||||
FT_DECLARE(ftdm_status_t) ftdm_interrupt_create(ftdm_interrupt_t **cond, ftdm_socket_t device);
|
||||
FT_DECLARE(ftdm_status_t) ftdm_interrupt_destroy(ftdm_interrupt_t **cond);
|
||||
FT_DECLARE(ftdm_status_t) ftdm_interrupt_signal(ftdm_interrupt_t *cond);
|
||||
|
|
|
@ -0,0 +1,697 @@
|
|||
/*
|
||||
* Copyright (c) 2010, Sangoma Technologies
|
||||
* Moises Silva <moy@sangoma.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the original author; nor the names of any contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
|
||||
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef __PRIVATE_FTDM_CORE__
|
||||
#define __PRIVATE_FTDM_CORE__
|
||||
|
||||
#if !defined(_XOPEN_SOURCE) && !defined(__FreeBSD__)
|
||||
#define _XOPEN_SOURCE 600
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_STRINGS_H
|
||||
#define HAVE_STRINGS_H 1
|
||||
#endif
|
||||
#ifndef HAVE_SYS_SOCKET_H
|
||||
#define HAVE_SYS_SOCKET_H 1
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#ifndef __inline__
|
||||
#define __inline__ __inline
|
||||
#endif
|
||||
#if (_MSC_VER >= 1400) /* VC8+ */
|
||||
#ifndef _CRT_SECURE_NO_DEPRECATE
|
||||
#define _CRT_SECURE_NO_DEPRECATE
|
||||
#endif
|
||||
#ifndef _CRT_NONSTDC_NO_DEPRECATE
|
||||
#define _CRT_NONSTDC_NO_DEPRECATE
|
||||
#endif
|
||||
#endif
|
||||
#ifndef strcasecmp
|
||||
#define strcasecmp(s1, s2) _stricmp(s1, s2)
|
||||
#endif
|
||||
#ifndef strncasecmp
|
||||
#define strncasecmp(s1, s2, n) _strnicmp(s1, s2, n)
|
||||
#endif
|
||||
#ifndef snprintf
|
||||
#define snprintf _snprintf
|
||||
#endif
|
||||
#ifndef S_IRUSR
|
||||
#define S_IRUSR _S_IREAD
|
||||
#endif
|
||||
#ifndef S_IWUSR
|
||||
#define S_IWUSR _S_IWRITE
|
||||
#endif
|
||||
#undef HAVE_STRINGS_H
|
||||
#undef HAVE_SYS_SOCKET_H
|
||||
/* disable warning for zero length array in a struct */
|
||||
/* this will cause errors on c99 and ansi compliant compilers and will need to be fixed in the wanpipe header files */
|
||||
#pragma warning(disable:4706)
|
||||
#pragma comment(lib, "Winmm")
|
||||
#endif
|
||||
|
||||
#define FTDM_THREAD_STACKSIZE 240 * 1024
|
||||
#define FTDM_ENUM_NAMES(_NAME, _STRINGS) static const char * _NAME [] = { _STRINGS , NULL };
|
||||
|
||||
#define ftdm_true(expr) \
|
||||
(expr && ( !strcasecmp(expr, "yes") || \
|
||||
!strcasecmp(expr, "on") || \
|
||||
!strcasecmp(expr, "true") || \
|
||||
!strcasecmp(expr, "enabled") || \
|
||||
!strcasecmp(expr, "active") || \
|
||||
atoi(expr))) ? 1 : 0
|
||||
|
||||
|
||||
|
||||
#include <time.h>
|
||||
#ifndef __WINDOWS__
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#ifdef HAVE_STRINGS_H
|
||||
#include <strings.h>
|
||||
#endif
|
||||
#include <assert.h>
|
||||
|
||||
#include "freetdm.h"
|
||||
#include "ftdm_types.h"
|
||||
#include "hashtable.h"
|
||||
#include "ftdm_config.h"
|
||||
#include "g711.h"
|
||||
#include "libteletone.h"
|
||||
#include "ftdm_buffer.h"
|
||||
#include "ftdm_threadmutex.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define FTDM_MAX_CHANNELS_PHYSICAL_SPAN 32
|
||||
#define FTDM_MAX_PHYSICAL_SPANS_PER_LOGICAL_SPAN 32
|
||||
#define FTDM_MAX_CHANNELS_SPAN FTDM_MAX_CHANNELS_PHYSICAL_SPAN * FTDM_MAX_PHYSICAL_SPANS_PER_LOGICAL_SPAN
|
||||
#define FTDM_MAX_SPANS_INTERFACE 128
|
||||
|
||||
#define FTDM_MAX_CHANNELS_GROUP 1024
|
||||
#define FTDM_MAX_GROUPS_INTERFACE FTDM_MAX_SPANS_INTERFACE
|
||||
|
||||
#define GOTO_STATUS(label,st) status = st; goto label ;
|
||||
|
||||
#define ftdm_copy_string(x,y,z) strncpy(x, y, z - 1)
|
||||
#define ftdm_set_string(x,y) strncpy(x, y, sizeof(x)-1)
|
||||
#define ftdm_strlen_zero(s) (!s || *s == '\0')
|
||||
#define ftdm_strlen_zero_buf(s) (*s == '\0')
|
||||
|
||||
|
||||
#define ftdm_channel_test_feature(obj, flag) ((obj)->features & flag)
|
||||
#define ftdm_channel_set_feature(obj, flag) (obj)->features |= (flag)
|
||||
#define ftdm_channel_clear_feature(obj, flag) (obj)->features &= ~(flag)
|
||||
#define ftdm_channel_set_member_locked(obj, _m, _v) ftdm_mutex_lock(obj->mutex); obj->_m = _v; ftdm_mutex_unlock(obj->mutex)
|
||||
|
||||
/*!
|
||||
\brief Test for the existance of a flag on an arbitary object
|
||||
\command obj the object to test
|
||||
\command flag the or'd list of flags to test
|
||||
\return true value if the object has the flags defined
|
||||
*/
|
||||
#define ftdm_test_flag(obj, flag) ((obj)->flags & flag)
|
||||
#define ftdm_test_pflag(obj, flag) ((obj)->pflags & flag)
|
||||
#define ftdm_test_sflag(obj, flag) ((obj)->sflags & flag)
|
||||
|
||||
#define ftdm_set_alarm_flag(obj, flag) (obj)->alarm_flags |= (flag)
|
||||
#define ftdm_clear_alarm_flag(obj, flag) (obj)->alarm_flags &= ~(flag)
|
||||
#define ftdm_test_alarm_flag(obj, flag) ((obj)->alarm_flags & flag)
|
||||
|
||||
/*!
|
||||
\brief Set a flag on an arbitrary object
|
||||
\command obj the object to set the flags on
|
||||
\command flag the or'd list of flags to set
|
||||
*/
|
||||
#define ftdm_set_flag(obj, flag) (obj)->flags |= (flag)
|
||||
#define ftdm_set_flag_locked(obj, flag) assert(obj->mutex != NULL); \
|
||||
ftdm_mutex_lock(obj->mutex); \
|
||||
(obj)->flags |= (flag); \
|
||||
ftdm_mutex_unlock(obj->mutex);
|
||||
|
||||
#define ftdm_set_pflag(obj, flag) (obj)->pflags |= (flag)
|
||||
#define ftdm_set_pflag_locked(obj, flag) assert(obj->mutex != NULL); \
|
||||
ftdm_mutex_lock(obj->mutex); \
|
||||
(obj)->pflags |= (flag); \
|
||||
ftdm_mutex_unlock(obj->mutex);
|
||||
|
||||
#define ftdm_set_sflag(obj, flag) (obj)->sflags |= (flag)
|
||||
#define ftdm_set_sflag_locked(obj, flag) assert(obj->mutex != NULL); \
|
||||
ftdm_mutex_lock(obj->mutex); \
|
||||
(obj)->sflags |= (flag); \
|
||||
ftdm_mutex_unlock(obj->mutex);
|
||||
|
||||
/*!
|
||||
\brief Clear a flag on an arbitrary object while locked
|
||||
\command obj the object to test
|
||||
\command flag the or'd list of flags to clear
|
||||
*/
|
||||
#define ftdm_clear_flag(obj, flag) (obj)->flags &= ~(flag)
|
||||
|
||||
#define ftdm_clear_flag_locked(obj, flag) assert(obj->mutex != NULL); ftdm_mutex_lock(obj->mutex); (obj)->flags &= ~(flag); ftdm_mutex_unlock(obj->mutex);
|
||||
|
||||
#define ftdm_clear_pflag(obj, flag) (obj)->pflags &= ~(flag)
|
||||
|
||||
#define ftdm_clear_pflag_locked(obj, flag) assert(obj->mutex != NULL); ftdm_mutex_lock(obj->mutex); (obj)->pflags &= ~(flag); ftdm_mutex_unlock(obj->mutex);
|
||||
|
||||
#define ftdm_clear_sflag(obj, flag) (obj)->sflags &= ~(flag)
|
||||
|
||||
#define ftdm_clear_sflag_locked(obj, flag) assert(obj->mutex != NULL); ftdm_mutex_lock(obj->mutex); (obj)->sflags &= ~(flag); ftdm_mutex_unlock(obj->mutex);
|
||||
|
||||
|
||||
#define ftdm_set_state_locked(obj, s) if ( obj->state == s ) { \
|
||||
ftdm_log(FTDM_LOG_WARNING, "Why bother changing state on %d:%d from %s to %s\n", obj->span_id, obj->chan_id, ftdm_channel_state2str(obj->state), ftdm_channel_state2str(s)); \
|
||||
} else if (ftdm_test_flag(obj, FTDM_CHANNEL_READY)) { \
|
||||
ftdm_channel_state_t st = obj->state; \
|
||||
ftdm_channel_set_state(obj, s, 1); \
|
||||
if (obj->state == s) ftdm_log(FTDM_LOG_DEBUG, "Changing state on %d:%d from %s to %s\n", obj->span_id, obj->chan_id, ftdm_channel_state2str(st), ftdm_channel_state2str(s)); \
|
||||
else ftdm_log(FTDM_LOG_WARNING, "VETO Changing state on %d:%d from %s to %s\n", obj->span_id, obj->chan_id, ftdm_channel_state2str(st), ftdm_channel_state2str(s)); \
|
||||
}
|
||||
|
||||
#define ftdm_set_state(obj, s) if ( obj->state == s ) { \
|
||||
ftdm_log(FTDM_LOG_WARNING, "Why bother changing state on %d:%d from %s to %s\n", obj->span_id, obj->chan_id, ftdm_channel_state2str(obj->state), ftdm_channel_state2str(s)); \
|
||||
} else if (ftdm_test_flag(obj, FTDM_CHANNEL_READY)) { \
|
||||
ftdm_channel_state_t st = obj->state; \
|
||||
ftdm_channel_set_state(obj, s, 0); \
|
||||
if (obj->state == s) ftdm_log(FTDM_LOG_DEBUG, "Changing state on %d:%d from %s to %s\n", obj->span_id, obj->chan_id, ftdm_channel_state2str(st), ftdm_channel_state2str(s)); \
|
||||
else ftdm_log(FTDM_LOG_WARNING, "VETO Changing state on %d:%d from %s to %s\n", obj->span_id, obj->chan_id, ftdm_channel_state2str(st), ftdm_channel_state2str(s)); \
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
/* The while(0) below throws a conditional expression is constant warning */
|
||||
#pragma warning(disable:4127)
|
||||
#endif
|
||||
|
||||
#define ftdm_set_state_locked_wait(obj, s) \
|
||||
do { \
|
||||
int __safety = 100; \
|
||||
ftdm_set_state_locked(obj, s); \
|
||||
while(__safety-- && ftdm_test_flag(obj, FTDM_CHANNEL_STATE_CHANGE)) { \
|
||||
ftdm_sleep(10); \
|
||||
} \
|
||||
if(!__safety) { \
|
||||
ftdm_log(FTDM_LOG_CRIT, "State change not completed\n"); \
|
||||
} \
|
||||
} while(0);
|
||||
|
||||
#define ftdm_wait_for_flag_cleared(obj, flag, time) \
|
||||
do { \
|
||||
int __safety = time; \
|
||||
while(__safety-- && ftdm_test_flag(obj, flag)) { \
|
||||
ftdm_mutex_unlock(obj->mutex); \
|
||||
ftdm_sleep(10); \
|
||||
ftdm_mutex_lock(obj->mutex); \
|
||||
} \
|
||||
if(!__safety) { \
|
||||
ftdm_log(FTDM_LOG_CRIT, "flag %d was never cleared\n", flag); \
|
||||
} \
|
||||
} while(0);
|
||||
|
||||
#define ftdm_set_state_wait(obj, s) \
|
||||
do { \
|
||||
ftdm_channel_set_state(obj, s, 0); \
|
||||
ftdm_wait_for_flag_cleared(obj, FTDM_CHANNEL_STATE_CHANGE, 100); \
|
||||
} while(0);
|
||||
|
||||
|
||||
#define ftdm_set_state_r(obj, s, l, r) if ( obj->state == s ) { \
|
||||
if (s != FTDM_CHANNEL_STATE_HANGUP) ftdm_log(FTDM_LOG_WARNING, "Why bother changing state on %d:%d from %s to %s\n", obj->span_id, obj->chan_id, ftdm_channel_state2str(obj->state), ftdm_channel_state2str(s)); r = FTDM_STATE_CHANGE_SAME; \
|
||||
} else if (ftdm_test_flag(obj, FTDM_CHANNEL_READY)) { \
|
||||
int st = obj->state; \
|
||||
r = (ftdm_channel_set_state(obj, s, l) == FTDM_SUCCESS) ? FTDM_STATE_CHANGE_SUCCESS : FTDM_STATE_CHANGE_FAIL; \
|
||||
if (obj->state == s) {ftdm_log(FTDM_LOG_DEBUG, "Changing state on %d:%d from %s to %s\n", obj->span_id, obj->chan_id, ftdm_channel_state2str(st), ftdm_channel_state2str(s));} \
|
||||
else ftdm_log(FTDM_LOG_WARNING, "VETO Changing state on %d:%d from %s to %s\n", obj->span_id, obj->chan_id, ftdm_channel_state2str(st), ftdm_channel_state2str(s)); \
|
||||
}
|
||||
|
||||
|
||||
#define ftdm_is_dtmf(key) ((key > 47 && key < 58) || (key > 64 && key < 69) || (key > 96 && key < 101) || key == 35 || key == 42 || key == 87 || key == 119)
|
||||
|
||||
/*!
|
||||
\brief Copy flags from one arbitrary object to another
|
||||
\command dest the object to copy the flags to
|
||||
\command src the object to copy the flags from
|
||||
\command flags the flags to copy
|
||||
*/
|
||||
#define ftdm_copy_flags(dest, src, flags) (dest)->flags &= ~(flags); (dest)->flags |= ((src)->flags & (flags))
|
||||
|
||||
struct ftdm_stream_handle {
|
||||
ftdm_stream_handle_write_function_t write_function;
|
||||
ftdm_stream_handle_raw_write_function_t raw_write_function;
|
||||
void *data;
|
||||
void *end;
|
||||
ftdm_size_t data_size;
|
||||
ftdm_size_t data_len;
|
||||
ftdm_size_t alloc_len;
|
||||
ftdm_size_t alloc_chunk;
|
||||
};
|
||||
|
||||
FT_DECLARE_NONSTD(ftdm_status_t) ftdm_console_stream_raw_write(ftdm_stream_handle_t *handle, uint8_t *data, ftdm_size_t datalen);
|
||||
FT_DECLARE_NONSTD(ftdm_status_t) ftdm_console_stream_write(ftdm_stream_handle_t *handle, const char *fmt, ...);
|
||||
|
||||
#define FTDM_CMD_CHUNK_LEN 1024
|
||||
#define FTDM_STANDARD_STREAM(s) memset(&s, 0, sizeof(s)); s.data = ftdm_malloc(FTDM_CMD_CHUNK_LEN); \
|
||||
assert(s.data); \
|
||||
memset(s.data, 0, FTDM_CMD_CHUNK_LEN); \
|
||||
s.end = s.data; \
|
||||
s.data_size = FTDM_CMD_CHUNK_LEN; \
|
||||
s.write_function = ftdm_console_stream_write; \
|
||||
s.raw_write_function = ftdm_console_stream_raw_write; \
|
||||
s.alloc_len = FTDM_CMD_CHUNK_LEN; \
|
||||
s.alloc_chunk = FTDM_CMD_CHUNK_LEN
|
||||
|
||||
/*! brief create a new queue */
|
||||
#define ftdm_queue_create(queue, capacity) g_ftdm_queue_handler.create(queue, capacity)
|
||||
|
||||
/*! Enqueue an object */
|
||||
#define ftdm_queue_enqueue(queue, obj) g_ftdm_queue_handler.enqueue(queue, obj)
|
||||
|
||||
/*! dequeue an object from the queue */
|
||||
#define ftdm_queue_dequeue(queue) g_ftdm_queue_handler.dequeue(queue)
|
||||
|
||||
/*! wait ms milliseconds for a queue to have available objects, -1 to wait forever */
|
||||
#define ftdm_queue_wait(queue, ms) g_ftdm_queue_handler.wait(queue, ms)
|
||||
|
||||
/*! get the internal interrupt object (to wait for elements to be added from the outside bypassing ftdm_queue_wait) */
|
||||
#define ftdm_queue_get_interrupt(queue, ms) g_ftdm_queue_handler.get_interrupt(queue, ms)
|
||||
|
||||
/*! destroy the queue */
|
||||
#define ftdm_queue_destroy(queue) g_ftdm_queue_handler.destroy(queue)
|
||||
|
||||
FT_DECLARE_DATA extern ftdm_queue_handler_t g_ftdm_queue_handler;
|
||||
|
||||
#define FTDM_TOKEN_STRLEN 128
|
||||
#define FTDM_MAX_TOKENS 10
|
||||
|
||||
static __inline__ char *ftdm_clean_string(char *s)
|
||||
{
|
||||
char *p;
|
||||
|
||||
for (p = s; p && *p; p++) {
|
||||
uint8_t x = (uint8_t) *p;
|
||||
if (x < 32 || x > 127) {
|
||||
*p = ' ';
|
||||
}
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
struct ftdm_bitstream {
|
||||
uint8_t *data;
|
||||
uint32_t datalen;
|
||||
uint32_t byte_index;
|
||||
uint8_t bit_index;
|
||||
int8_t endian;
|
||||
uint8_t top;
|
||||
uint8_t bot;
|
||||
uint8_t ss;
|
||||
uint8_t ssv;
|
||||
};
|
||||
|
||||
struct ftdm_fsk_data_state {
|
||||
dsp_fsk_handle_t *fsk1200_handle;
|
||||
uint8_t init;
|
||||
uint8_t *buf;
|
||||
size_t bufsize;
|
||||
ftdm_size_t blen;
|
||||
ftdm_size_t bpos;
|
||||
ftdm_size_t dlen;
|
||||
ftdm_size_t ppos;
|
||||
int checksum;
|
||||
};
|
||||
|
||||
struct ftdm_fsk_modulator {
|
||||
teletone_dds_state_t dds;
|
||||
ftdm_bitstream_t bs;
|
||||
uint32_t carrier_bits_start;
|
||||
uint32_t carrier_bits_stop;
|
||||
uint32_t chan_sieze_bits;
|
||||
uint32_t bit_factor;
|
||||
uint32_t bit_accum;
|
||||
uint32_t sample_counter;
|
||||
int32_t samples_per_bit;
|
||||
int32_t est_bytes;
|
||||
fsk_modem_types_t modem_type;
|
||||
ftdm_fsk_data_state_t *fsk_data;
|
||||
ftdm_fsk_write_sample_t write_sample_callback;
|
||||
void *user_data;
|
||||
int16_t sample_buffer[64];
|
||||
};
|
||||
|
||||
|
||||
typedef enum {
|
||||
FTDM_TYPE_NONE,
|
||||
FTDM_TYPE_SPAN = 0xFF,
|
||||
FTDM_TYPE_CHANNEL
|
||||
} ftdm_data_type_t;
|
||||
|
||||
/* 2^8 table size, one for each byte (sample) value */
|
||||
#define FTDM_GAINS_TABLE_SIZE 256
|
||||
struct ftdm_channel {
|
||||
ftdm_data_type_t data_type;
|
||||
uint32_t span_id;
|
||||
uint32_t chan_id;
|
||||
uint32_t physical_span_id;
|
||||
uint32_t physical_chan_id;
|
||||
uint32_t rate;
|
||||
uint32_t extra_id;
|
||||
ftdm_chan_type_t type;
|
||||
ftdm_socket_t sockfd;
|
||||
uint32_t flags;
|
||||
uint32_t pflags;
|
||||
uint32_t sflags;
|
||||
ftdm_alarm_flag_t alarm_flags;
|
||||
ftdm_channel_feature_t features;
|
||||
ftdm_codec_t effective_codec;
|
||||
ftdm_codec_t native_codec;
|
||||
uint32_t effective_interval;
|
||||
uint32_t native_interval;
|
||||
uint32_t packet_len;
|
||||
ftdm_channel_state_t state;
|
||||
ftdm_channel_state_t last_state;
|
||||
ftdm_channel_state_t init_state;
|
||||
ftdm_mutex_t *mutex;
|
||||
teletone_dtmf_detect_state_t dtmf_detect;
|
||||
uint32_t buffer_delay;
|
||||
ftdm_event_t event_header;
|
||||
char last_error[256];
|
||||
fio_event_cb_t event_callback;
|
||||
uint32_t skip_read_frames;
|
||||
ftdm_buffer_t *dtmf_buffer;
|
||||
ftdm_buffer_t *gen_dtmf_buffer;
|
||||
ftdm_buffer_t *pre_buffer;
|
||||
ftdm_buffer_t *digit_buffer;
|
||||
ftdm_buffer_t *fsk_buffer;
|
||||
ftdm_mutex_t *pre_buffer_mutex;
|
||||
uint32_t dtmf_on;
|
||||
uint32_t dtmf_off;
|
||||
char *dtmf_hangup_buf;
|
||||
teletone_generation_session_t tone_session;
|
||||
ftdm_time_t last_event_time;
|
||||
ftdm_time_t ring_time;
|
||||
char tokens[FTDM_MAX_TOKENS+1][FTDM_TOKEN_STRLEN];
|
||||
uint8_t needed_tones[FTDM_TONEMAP_INVALID];
|
||||
uint8_t detected_tones[FTDM_TONEMAP_INVALID];
|
||||
ftdm_tonemap_t last_detected_tone;
|
||||
uint32_t token_count;
|
||||
char chan_name[128];
|
||||
char chan_number[32];
|
||||
ftdm_filehandle_t fds[2];
|
||||
ftdm_fsk_data_state_t fsk;
|
||||
uint8_t fsk_buf[80];
|
||||
uint32_t ring_count;
|
||||
void *mod_data;
|
||||
void *call_data;
|
||||
struct ftdm_caller_data caller_data;
|
||||
struct ftdm_span *span;
|
||||
struct ftdm_io_interface *fio;
|
||||
ftdm_hash_t *variable_hash;
|
||||
unsigned char rx_cas_bits;
|
||||
uint32_t pre_buffer_size;
|
||||
uint8_t rxgain_table[FTDM_GAINS_TABLE_SIZE];
|
||||
uint8_t txgain_table[FTDM_GAINS_TABLE_SIZE];
|
||||
float rxgain;
|
||||
float txgain;
|
||||
};
|
||||
|
||||
struct ftdm_span {
|
||||
ftdm_data_type_t data_type;
|
||||
char *name;
|
||||
uint32_t span_id;
|
||||
uint32_t chan_count;
|
||||
ftdm_span_flag_t flags;
|
||||
struct ftdm_io_interface *fio;
|
||||
fio_event_cb_t event_callback;
|
||||
ftdm_mutex_t *mutex;
|
||||
ftdm_trunk_type_t trunk_type;
|
||||
ftdm_analog_start_type_t start_type;
|
||||
ftdm_signal_type_t signal_type;
|
||||
void *signal_data;
|
||||
fio_signal_cb_t signal_cb;
|
||||
ftdm_event_t event_header;
|
||||
char last_error[256];
|
||||
char tone_map[FTDM_TONEMAP_INVALID+1][FTDM_TONEMAP_LEN];
|
||||
teletone_tone_map_t tone_detect_map[FTDM_TONEMAP_INVALID+1];
|
||||
teletone_multi_tone_t tone_finder[FTDM_TONEMAP_INVALID+1];
|
||||
ftdm_channel_t *channels[FTDM_MAX_CHANNELS_SPAN+1];
|
||||
fio_channel_outgoing_call_t outgoing_call;
|
||||
fio_channel_set_sig_status_t set_channel_sig_status;
|
||||
fio_channel_get_sig_status_t get_channel_sig_status;
|
||||
fio_span_set_sig_status_t set_span_sig_status;
|
||||
fio_span_get_sig_status_t get_span_sig_status;
|
||||
fio_channel_request_t channel_request;
|
||||
ftdm_span_start_t start;
|
||||
ftdm_span_stop_t stop;
|
||||
void *mod_data;
|
||||
char *type;
|
||||
char *dtmf_hangup;
|
||||
size_t dtmf_hangup_len;
|
||||
ftdm_state_map_t *state_map;
|
||||
ftdm_caller_data_t default_caller_data;
|
||||
ftdm_queue_t *pendingchans;
|
||||
struct ftdm_span *next;
|
||||
};
|
||||
|
||||
struct ftdm_group {
|
||||
char *name;
|
||||
uint32_t group_id;
|
||||
uint32_t chan_count;
|
||||
ftdm_channel_t *channels[FTDM_MAX_CHANNELS_GROUP];
|
||||
uint32_t last_used_index;
|
||||
ftdm_mutex_t *mutex;
|
||||
struct ftdm_group *next;
|
||||
};
|
||||
|
||||
FT_DECLARE_DATA extern ftdm_crash_policy_t g_ftdm_crash_policy;
|
||||
|
||||
FT_DECLARE_DATA extern ftdm_memory_handler_t g_ftdm_mem_handler;
|
||||
|
||||
/*! \brief Duplicate string */
|
||||
FT_DECLARE(char *) ftdm_strdup(const char *str);
|
||||
FT_DECLARE(char *) ftdm_strndup(const char *str, ftdm_size_t inlen);
|
||||
|
||||
FT_DECLARE(ftdm_size_t) ftdm_fsk_modulator_generate_bit(ftdm_fsk_modulator_t *fsk_trans, int8_t bit, int16_t *buf, ftdm_size_t buflen);
|
||||
FT_DECLARE(int32_t) ftdm_fsk_modulator_generate_carrier_bits(ftdm_fsk_modulator_t *fsk_trans, uint32_t bits);
|
||||
FT_DECLARE(void) ftdm_fsk_modulator_generate_chan_sieze(ftdm_fsk_modulator_t *fsk_trans);
|
||||
FT_DECLARE(void) ftdm_fsk_modulator_send_data(ftdm_fsk_modulator_t *fsk_trans);
|
||||
#define ftdm_fsk_modulator_send_all(_it) ftdm_fsk_modulator_generate_chan_sieze(_it); \
|
||||
ftdm_fsk_modulator_generate_carrier_bits(_it, _it->carrier_bits_start); \
|
||||
ftdm_fsk_modulator_send_data(_it); \
|
||||
ftdm_fsk_modulator_generate_carrier_bits(_it, _it->carrier_bits_stop)
|
||||
|
||||
FT_DECLARE(ftdm_status_t) ftdm_fsk_modulator_init(ftdm_fsk_modulator_t *fsk_trans,
|
||||
fsk_modem_types_t modem_type,
|
||||
uint32_t sample_rate,
|
||||
ftdm_fsk_data_state_t *fsk_data,
|
||||
float db_level,
|
||||
uint32_t carrier_bits_start,
|
||||
uint32_t carrier_bits_stop,
|
||||
uint32_t chan_sieze_bits,
|
||||
ftdm_fsk_write_sample_t write_sample_callback,
|
||||
void *user_data);
|
||||
FT_DECLARE(int8_t) ftdm_bitstream_get_bit(ftdm_bitstream_t *bsp);
|
||||
FT_DECLARE(void) ftdm_bitstream_init(ftdm_bitstream_t *bsp, uint8_t *data, uint32_t datalen, ftdm_endian_t endian, uint8_t ss);
|
||||
FT_DECLARE(ftdm_status_t) ftdm_fsk_data_parse(ftdm_fsk_data_state_t *state, ftdm_size_t *type, char **data, ftdm_size_t *len);
|
||||
FT_DECLARE(ftdm_status_t) ftdm_fsk_demod_feed(ftdm_fsk_data_state_t *state, int16_t *data, size_t samples);
|
||||
FT_DECLARE(ftdm_status_t) ftdm_fsk_demod_destroy(ftdm_fsk_data_state_t *state);
|
||||
FT_DECLARE(int) ftdm_fsk_demod_init(ftdm_fsk_data_state_t *state, int rate, uint8_t *buf, size_t bufsize);
|
||||
FT_DECLARE(ftdm_status_t) ftdm_fsk_data_init(ftdm_fsk_data_state_t *state, uint8_t *data, uint32_t datalen);
|
||||
FT_DECLARE(ftdm_status_t) ftdm_fsk_data_add_mdmf(ftdm_fsk_data_state_t *state, ftdm_mdmf_type_t type, const uint8_t *data, uint32_t datalen);
|
||||
FT_DECLARE(ftdm_status_t) ftdm_fsk_data_add_checksum(ftdm_fsk_data_state_t *state);
|
||||
FT_DECLARE(ftdm_status_t) ftdm_fsk_data_add_sdmf(ftdm_fsk_data_state_t *state, const char *date, char *number);
|
||||
FT_DECLARE(ftdm_status_t) ftdm_channel_send_fsk_data(ftdm_channel_t *ftdmchan, ftdm_fsk_data_state_t *fsk_data, float db_level);
|
||||
|
||||
FT_DECLARE(ftdm_status_t) ftdm_channel_set_state(ftdm_channel_t *ftdmchan, ftdm_channel_state_t state, int lock);
|
||||
|
||||
FT_DECLARE(ftdm_status_t) ftdm_span_load_tones(ftdm_span_t *span, const char *mapname);
|
||||
FT_DECLARE(ftdm_time_t) ftdm_current_time_in_ms(void);
|
||||
FT_DECLARE(ftdm_status_t) ftdm_channel_done(ftdm_channel_t *ftdmchan);
|
||||
|
||||
FT_DECLARE(ftdm_status_t) ftdm_channel_use(ftdm_channel_t *ftdmchan);
|
||||
|
||||
FT_DECLARE(void) ftdm_generate_sln_silence(int16_t *data, uint32_t samples, uint32_t divisor);
|
||||
|
||||
FT_DECLARE(uint32_t) ftdm_separate_string(char *buf, char delim, char **array, int arraylen);
|
||||
FT_DECLARE(void) print_bits(uint8_t *b, int bl, char *buf, int blen, int e, uint8_t ss);
|
||||
FT_DECLARE(void) print_hex_bytes(uint8_t *data, ftdm_size_t dlen, char *buf, ftdm_size_t blen);
|
||||
|
||||
FT_DECLARE_NONSTD(int) ftdm_hash_equalkeys(void *k1, void *k2);
|
||||
FT_DECLARE_NONSTD(uint32_t) ftdm_hash_hashfromstring(void *ky);
|
||||
|
||||
FT_DECLARE(ftdm_status_t) ftdm_channel_complete_state(ftdm_channel_t *ftdmchan);
|
||||
|
||||
FT_DECLARE(int) ftdm_load_modules(void);
|
||||
|
||||
FT_DECLARE(ftdm_status_t) ftdm_unload_modules(void);
|
||||
|
||||
FT_DECLARE(ftdm_status_t) ftdm_span_send_signal(ftdm_span_t *span, ftdm_sigmsg_t *sigmsg);
|
||||
|
||||
FT_DECLARE(char *) ftdm_build_dso_path(const char *name, char *path, ftdm_size_t len);
|
||||
|
||||
FT_DECLARE(int) ftdm_load_module(const char *name);
|
||||
FT_DECLARE(int) ftdm_load_module_assume(const char *name);
|
||||
FT_DECLARE(int) ftdm_vasprintf(char **ret, const char *fmt, va_list ap);
|
||||
|
||||
FIO_CODEC_FUNCTION(fio_slin2ulaw);
|
||||
FIO_CODEC_FUNCTION(fio_ulaw2slin);
|
||||
FIO_CODEC_FUNCTION(fio_slin2alaw);
|
||||
FIO_CODEC_FUNCTION(fio_alaw2slin);
|
||||
FIO_CODEC_FUNCTION(fio_ulaw2alaw);
|
||||
FIO_CODEC_FUNCTION(fio_alaw2ulaw);
|
||||
|
||||
/*!
|
||||
\brief Assert condition
|
||||
*/
|
||||
#define ftdm_assert(assertion, msg) \
|
||||
if (!(assertion)) { \
|
||||
ftdm_log(FTDM_LOG_CRIT, msg); \
|
||||
if (g_ftdm_crash_policy & FTDM_CRASH_ON_ASSERT) { \
|
||||
ftdm_abort(); \
|
||||
} \
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Assert condition and return
|
||||
*/
|
||||
#define ftdm_assert_return(assertion, retval, msg) \
|
||||
if (!(assertion)) { \
|
||||
ftdm_log(FTDM_LOG_CRIT, msg); \
|
||||
if (g_ftdm_crash_policy & FTDM_CRASH_ON_ASSERT) { \
|
||||
ftdm_abort(); \
|
||||
} else { \
|
||||
return retval; \
|
||||
} \
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Allocate uninitialized memory
|
||||
\command chunksize the chunk size
|
||||
*/
|
||||
#define ftdm_malloc(chunksize) g_ftdm_mem_handler.malloc(g_ftdm_mem_handler.pool, chunksize)
|
||||
|
||||
/*!
|
||||
\brief Reallocates memory
|
||||
\command buff the buffer
|
||||
\command chunksize the chunk size
|
||||
*/
|
||||
#define ftdm_realloc(buff, chunksize) g_ftdm_mem_handler.realloc(g_ftdm_mem_handler.pool, buff, chunksize)
|
||||
|
||||
/*!
|
||||
\brief Allocate initialized memory
|
||||
\command chunksize the chunk size
|
||||
*/
|
||||
#define ftdm_calloc(elements, chunksize) g_ftdm_mem_handler.calloc(g_ftdm_mem_handler.pool, elements, chunksize)
|
||||
|
||||
/*!
|
||||
\brief Free chunk of memory
|
||||
\command chunksize the chunk size
|
||||
*/
|
||||
#define ftdm_free(chunk) g_ftdm_mem_handler.free(g_ftdm_mem_handler.pool, chunk)
|
||||
|
||||
/*!
|
||||
\brief Free a pointer and set it to NULL unless it already is NULL
|
||||
\command it the pointer
|
||||
*/
|
||||
#define ftdm_safe_free(it) if (it) { ftdm_free(it); it = NULL; }
|
||||
|
||||
/*!
|
||||
\brief Socket the given socket
|
||||
\command it the socket
|
||||
*/
|
||||
#define ftdm_socket_close(it) if (it > -1) { close(it); it = -1;}
|
||||
|
||||
#define ftdm_array_len(array) sizeof(array)/sizeof(array[0])
|
||||
|
||||
static __inline__ void ftdm_abort(void)
|
||||
{
|
||||
#ifdef __cplusplus
|
||||
::abort();
|
||||
#else
|
||||
abort();
|
||||
#endif
|
||||
}
|
||||
|
||||
static __inline__ void ftdm_set_state_all(ftdm_span_t *span, ftdm_channel_state_t state)
|
||||
{
|
||||
uint32_t j;
|
||||
ftdm_mutex_lock(span->mutex);
|
||||
for(j = 1; j <= span->chan_count; j++) {
|
||||
ftdm_set_state_locked((span->channels[j]), state);
|
||||
}
|
||||
ftdm_mutex_unlock(span->mutex);
|
||||
}
|
||||
|
||||
static __inline__ int ftdm_check_state_all(ftdm_span_t *span, ftdm_channel_state_t state)
|
||||
{
|
||||
uint32_t j;
|
||||
for(j = 1; j <= span->chan_count; j++) {
|
||||
if (span->channels[j]->state != state || ftdm_test_flag(span->channels[j], FTDM_CHANNEL_STATE_CHANGE)) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static __inline__ void ftdm_set_flag_all(ftdm_span_t *span, uint32_t flag)
|
||||
{
|
||||
uint32_t j;
|
||||
ftdm_mutex_lock(span->mutex);
|
||||
for(j = 1; j <= span->chan_count; j++) {
|
||||
ftdm_set_flag_locked((span->channels[j]), flag);
|
||||
}
|
||||
ftdm_mutex_unlock(span->mutex);
|
||||
}
|
||||
|
||||
static __inline__ void ftdm_clear_flag_all(ftdm_span_t *span, uint32_t flag)
|
||||
{
|
||||
uint32_t j;
|
||||
ftdm_mutex_lock(span->mutex);
|
||||
for(j = 1; j <= span->chan_count; j++) {
|
||||
ftdm_clear_flag_locked((span->channels[j]), flag);
|
||||
}
|
||||
ftdm_mutex_unlock(span->mutex);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* endif __PRIVATE_FTDM_CORE__ */
|
|
@ -0,0 +1,451 @@
|
|||
/*
|
||||
* Copyright (c) 2007, Anthony Minessale II
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the original author; nor the names of any contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
|
||||
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* Contributors:
|
||||
*
|
||||
* Moises Silva <moy@sangoma.com>
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef FTDM_TYPES_H
|
||||
#define FTDM_TYPES_H
|
||||
|
||||
#include "freetdm.h"
|
||||
|
||||
#include "fsk.h"
|
||||
|
||||
#ifdef WIN32
|
||||
typedef intptr_t ftdm_ssize_t;
|
||||
typedef int ftdm_filehandle_t;
|
||||
#else
|
||||
#include <sys/types.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <stdarg.h>
|
||||
typedef ssize_t ftdm_ssize_t;
|
||||
typedef int ftdm_filehandle_t;
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define FTDM_COMMAND_OBJ_INT *((int *)obj)
|
||||
#define FTDM_COMMAND_OBJ_CHAR_P (char *)obj
|
||||
#define FTDM_COMMAND_OBJ_FLOAT *(float *)obj
|
||||
#define FTDM_FSK_MOD_FACTOR 0x10000
|
||||
#define FTDM_DEFAULT_DTMF_ON 250
|
||||
#define FTDM_DEFAULT_DTMF_OFF 50
|
||||
|
||||
#define FTDM_END -1
|
||||
#define FTDM_ANY_STATE -1
|
||||
|
||||
typedef uint64_t ftdm_time_t;
|
||||
|
||||
typedef enum {
|
||||
FTDM_ENDIAN_BIG = 1,
|
||||
FTDM_ENDIAN_LITTLE = -1
|
||||
} ftdm_endian_t;
|
||||
|
||||
typedef enum {
|
||||
FTDM_CID_TYPE_SDMF = 0x04,
|
||||
FTDM_CID_TYPE_MDMF = 0x80
|
||||
} ftdm_cid_type_t;
|
||||
|
||||
typedef enum {
|
||||
MDMF_DATETIME = 1,
|
||||
MDMF_PHONE_NUM = 2,
|
||||
MDMF_DDN = 3,
|
||||
MDMF_NO_NUM = 4,
|
||||
MDMF_PHONE_NAME = 7,
|
||||
MDMF_NO_NAME = 8,
|
||||
MDMF_ALT_ROUTE = 9,
|
||||
MDMF_INVALID = 10
|
||||
} ftdm_mdmf_type_t;
|
||||
#define MDMF_STRINGS "X", "DATETIME", "PHONE_NUM", "DDN", "NO_NUM", "X", "X", "PHONE_NAME", "NO_NAME", "ALT_ROUTE", "INVALID"
|
||||
FTDM_STR2ENUM_P(ftdm_str2ftdm_mdmf_type, ftdm_mdmf_type2str, ftdm_mdmf_type_t)
|
||||
|
||||
#define FTDM_TONEMAP_LEN 128
|
||||
typedef enum {
|
||||
FTDM_TONEMAP_NONE,
|
||||
FTDM_TONEMAP_DIAL,
|
||||
FTDM_TONEMAP_RING,
|
||||
FTDM_TONEMAP_BUSY,
|
||||
FTDM_TONEMAP_FAIL1,
|
||||
FTDM_TONEMAP_FAIL2,
|
||||
FTDM_TONEMAP_FAIL3,
|
||||
FTDM_TONEMAP_ATTN,
|
||||
FTDM_TONEMAP_CALLWAITING_CAS,
|
||||
FTDM_TONEMAP_CALLWAITING_SAS,
|
||||
FTDM_TONEMAP_CALLWAITING_ACK,
|
||||
FTDM_TONEMAP_INVALID
|
||||
} ftdm_tonemap_t;
|
||||
#define TONEMAP_STRINGS "NONE", "DIAL", "RING", "BUSY", "FAIL1", "FAIL2", "FAIL3", "ATTN", "CALLWAITING-CAS", "CALLWAITING-SAS", "CALLWAITING-ACK", "INVALID"
|
||||
FTDM_STR2ENUM_P(ftdm_str2ftdm_tonemap, ftdm_tonemap2str, ftdm_tonemap_t)
|
||||
|
||||
typedef enum {
|
||||
FTDM_TRUNK_E1,
|
||||
FTDM_TRUNK_T1,
|
||||
FTDM_TRUNK_J1,
|
||||
FTDM_TRUNK_BRI,
|
||||
FTDM_TRUNK_BRI_PTMP,
|
||||
FTDM_TRUNK_FXO,
|
||||
FTDM_TRUNK_FXS,
|
||||
FTDM_TRUNK_EM,
|
||||
FTDM_TRUNK_NONE
|
||||
} ftdm_trunk_type_t;
|
||||
#define TRUNK_STRINGS "E1", "T1", "J1", "BRI", "BRI_PTMP", "FXO", "FXS", "EM", "NONE"
|
||||
FTDM_STR2ENUM_P(ftdm_str2ftdm_trunk_type, ftdm_trunk_type2str, ftdm_trunk_type_t)
|
||||
|
||||
typedef enum {
|
||||
FTDM_ANALOG_START_KEWL,
|
||||
FTDM_ANALOG_START_LOOP,
|
||||
FTDM_ANALOG_START_GROUND,
|
||||
FTDM_ANALOG_START_WINK,
|
||||
FTDM_ANALOG_START_NA
|
||||
} ftdm_analog_start_type_t;
|
||||
#define START_TYPE_STRINGS "KEWL", "LOOP", "GROUND", "WINK", "NA"
|
||||
FTDM_STR2ENUM_P(ftdm_str2ftdm_analog_start_type, ftdm_analog_start_type2str, ftdm_analog_start_type_t)
|
||||
|
||||
typedef enum {
|
||||
FTDM_OOB_ONHOOK,
|
||||
FTDM_OOB_OFFHOOK,
|
||||
FTDM_OOB_WINK,
|
||||
FTDM_OOB_FLASH,
|
||||
FTDM_OOB_RING_START,
|
||||
FTDM_OOB_RING_STOP,
|
||||
FTDM_OOB_ALARM_TRAP,
|
||||
FTDM_OOB_ALARM_CLEAR,
|
||||
FTDM_OOB_NOOP,
|
||||
FTDM_OOB_CAS_BITS_CHANGE,
|
||||
FTDM_OOB_INVALID
|
||||
} ftdm_oob_event_t;
|
||||
#define OOB_STRINGS "DTMF", "ONHOOK", "OFFHOOK", "WINK", "FLASH", "RING_START", "RING_STOP", "ALARM_TRAP", "ALARM_CLEAR", "NOOP", "CAS_BITS_CHANGE", "INVALID"
|
||||
FTDM_STR2ENUM_P(ftdm_str2ftdm_oob_event, ftdm_oob_event2str, ftdm_oob_event_t)
|
||||
|
||||
typedef enum {
|
||||
FTDM_ALARM_NONE = 0,
|
||||
FTDM_ALARM_RECOVER = (1 << 0),
|
||||
FTDM_ALARM_LOOPBACK = (1 << 2),
|
||||
FTDM_ALARM_YELLOW = (1 << 3),
|
||||
FTDM_ALARM_RED = (1 << 4),
|
||||
FTDM_ALARM_BLUE = (1 << 5),
|
||||
FTDM_ALARM_NOTOPEN = ( 1 << 6),
|
||||
FTDM_ALARM_AIS = ( 1 << 7),
|
||||
FTDM_ALARM_RAI = ( 1 << 8),
|
||||
FTDM_ALARM_GENERAL = ( 1 << 30)
|
||||
} ftdm_alarm_flag_t;
|
||||
|
||||
typedef enum {
|
||||
FTDM_SIGTYPE_NONE,
|
||||
FTDM_SIGTYPE_ISDN,
|
||||
FTDM_SIGTYPE_RBS,
|
||||
FTDM_SIGTYPE_ANALOG,
|
||||
FTDM_SIGTYPE_SANGOMABOOST,
|
||||
FTDM_SIGTYPE_M3UA,
|
||||
FTDM_SIGTYPE_R2
|
||||
} ftdm_signal_type_t;
|
||||
|
||||
typedef enum {
|
||||
FTDM_TONE_DTMF = (1 << 0)
|
||||
} ftdm_tone_type_t;
|
||||
|
||||
typedef enum {
|
||||
FTDM_SPAN_CONFIGURED = (1 << 0),
|
||||
FTDM_SPAN_READY = (1 << 1),
|
||||
FTDM_SPAN_STATE_CHANGE = (1 << 2),
|
||||
FTDM_SPAN_SUSPENDED = (1 << 3),
|
||||
FTDM_SPAN_IN_THREAD = (1 << 4),
|
||||
FTDM_SPAN_STOP_THREAD = (1 << 5),
|
||||
FTDM_SPAN_USE_CHAN_QUEUE = (1 << 6),
|
||||
FTDM_SPAN_SUGGEST_CHAN_ID = (1 << 7),
|
||||
} ftdm_span_flag_t;
|
||||
|
||||
typedef enum {
|
||||
FTDM_CHANNEL_FEATURE_DTMF_DETECT = (1 << 0),
|
||||
FTDM_CHANNEL_FEATURE_DTMF_GENERATE = (1 << 1),
|
||||
FTDM_CHANNEL_FEATURE_CODECS = (1 << 2),
|
||||
FTDM_CHANNEL_FEATURE_INTERVAL = (1 << 3),
|
||||
FTDM_CHANNEL_FEATURE_CALLERID = (1 << 4),
|
||||
FTDM_CHANNEL_FEATURE_PROGRESS = (1 << 5)
|
||||
} ftdm_channel_feature_t;
|
||||
|
||||
typedef enum {
|
||||
FTDM_CHANNEL_STATE_DOWN,
|
||||
FTDM_CHANNEL_STATE_HOLD,
|
||||
FTDM_CHANNEL_STATE_SUSPENDED,
|
||||
FTDM_CHANNEL_STATE_DIALTONE,
|
||||
FTDM_CHANNEL_STATE_COLLECT,
|
||||
FTDM_CHANNEL_STATE_RING,
|
||||
FTDM_CHANNEL_STATE_BUSY,
|
||||
FTDM_CHANNEL_STATE_ATTN,
|
||||
FTDM_CHANNEL_STATE_GENRING,
|
||||
FTDM_CHANNEL_STATE_DIALING,
|
||||
FTDM_CHANNEL_STATE_GET_CALLERID,
|
||||
FTDM_CHANNEL_STATE_CALLWAITING,
|
||||
FTDM_CHANNEL_STATE_RESTART,
|
||||
FTDM_CHANNEL_STATE_PROGRESS,
|
||||
FTDM_CHANNEL_STATE_PROGRESS_MEDIA,
|
||||
FTDM_CHANNEL_STATE_UP,
|
||||
FTDM_CHANNEL_STATE_IDLE,
|
||||
FTDM_CHANNEL_STATE_TERMINATING,
|
||||
FTDM_CHANNEL_STATE_CANCEL,
|
||||
FTDM_CHANNEL_STATE_HANGUP,
|
||||
FTDM_CHANNEL_STATE_HANGUP_COMPLETE,
|
||||
FTDM_CHANNEL_STATE_IN_LOOP,
|
||||
FTDM_CHANNEL_STATE_INVALID
|
||||
} ftdm_channel_state_t;
|
||||
#define CHANNEL_STATE_STRINGS "DOWN", "HOLD", "SUSPENDED", "DIALTONE", "COLLECT", \
|
||||
"RING", "BUSY", "ATTN", "GENRING", "DIALING", "GET_CALLERID", "CALLWAITING", \
|
||||
"RESTART", "PROGRESS", "PROGRESS_MEDIA", "UP", "IDLE", "TERMINATING", "CANCEL", \
|
||||
"HANGUP", "HANGUP_COMPLETE", "IN_LOOP", "INVALID"
|
||||
FTDM_STR2ENUM_P(ftdm_str2ftdm_channel_state, ftdm_channel_state2str, ftdm_channel_state_t)
|
||||
|
||||
typedef enum {
|
||||
FTDM_CHANNEL_CONFIGURED = (1 << 0),
|
||||
FTDM_CHANNEL_READY = (1 << 1),
|
||||
FTDM_CHANNEL_OPEN = (1 << 2),
|
||||
FTDM_CHANNEL_DTMF_DETECT = (1 << 3),
|
||||
FTDM_CHANNEL_SUPRESS_DTMF = (1 << 4),
|
||||
FTDM_CHANNEL_TRANSCODE = (1 << 5),
|
||||
FTDM_CHANNEL_BUFFER = (1 << 6),
|
||||
FTDM_CHANNEL_EVENT = (1 << 7),
|
||||
FTDM_CHANNEL_INTHREAD = (1 << 8),
|
||||
FTDM_CHANNEL_WINK = (1 << 9),
|
||||
FTDM_CHANNEL_FLASH = (1 << 10),
|
||||
FTDM_CHANNEL_STATE_CHANGE = (1 << 11),
|
||||
FTDM_CHANNEL_HOLD = (1 << 12),
|
||||
FTDM_CHANNEL_INUSE = (1 << 13),
|
||||
FTDM_CHANNEL_OFFHOOK = (1 << 14),
|
||||
FTDM_CHANNEL_RINGING = (1 << 15),
|
||||
FTDM_CHANNEL_PROGRESS_DETECT = (1 << 16),
|
||||
FTDM_CHANNEL_CALLERID_DETECT = (1 << 17),
|
||||
FTDM_CHANNEL_OUTBOUND = (1 << 18),
|
||||
FTDM_CHANNEL_SUSPENDED = (1 << 19),
|
||||
FTDM_CHANNEL_3WAY = (1 << 20),
|
||||
FTDM_CHANNEL_PROGRESS = (1 << 21),
|
||||
FTDM_CHANNEL_MEDIA = (1 << 22),
|
||||
FTDM_CHANNEL_ANSWERED = (1 << 23),
|
||||
FTDM_CHANNEL_MUTE = (1 << 24),
|
||||
FTDM_CHANNEL_USE_RX_GAIN = (1 << 25),
|
||||
FTDM_CHANNEL_USE_TX_GAIN = (1 << 26),
|
||||
FTDM_CHANNEL_IN_ALARM = (1 << 27),
|
||||
} ftdm_channel_flag_t;
|
||||
#if defined(__cplusplus) && defined(WIN32)
|
||||
// fix C2676
|
||||
__inline__ ftdm_channel_flag_t operator|=(ftdm_channel_flag_t a, int32_t b) {
|
||||
a = (ftdm_channel_flag_t)(a | b);
|
||||
return a;
|
||||
}
|
||||
__inline__ ftdm_channel_flag_t operator&=(ftdm_channel_flag_t a, int32_t b) {
|
||||
a = (ftdm_channel_flag_t)(a & b);
|
||||
return a;
|
||||
}
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
ZSM_NONE,
|
||||
ZSM_UNACCEPTABLE,
|
||||
ZSM_ACCEPTABLE
|
||||
} ftdm_state_map_type_t;
|
||||
|
||||
typedef enum {
|
||||
ZSD_INBOUND,
|
||||
ZSD_OUTBOUND,
|
||||
} ftdm_state_direction_t;
|
||||
|
||||
#define FTDM_MAP_NODE_SIZE 512
|
||||
#define FTDM_MAP_MAX FTDM_CHANNEL_STATE_INVALID+2
|
||||
|
||||
struct ftdm_state_map_node {
|
||||
ftdm_state_direction_t direction;
|
||||
ftdm_state_map_type_t type;
|
||||
ftdm_channel_state_t check_states[FTDM_MAP_MAX];
|
||||
ftdm_channel_state_t states[FTDM_MAP_MAX];
|
||||
};
|
||||
typedef struct ftdm_state_map_node ftdm_state_map_node_t;
|
||||
|
||||
struct ftdm_state_map {
|
||||
ftdm_state_map_node_t nodes[FTDM_MAP_NODE_SIZE];
|
||||
};
|
||||
typedef struct ftdm_state_map ftdm_state_map_t;
|
||||
|
||||
typedef enum ftdm_channel_hw_link_status {
|
||||
FTDM_HW_LINK_DISCONNECTED = 0,
|
||||
FTDM_HW_LINK_CONNECTED
|
||||
} ftdm_channel_hw_link_status_t;
|
||||
|
||||
typedef ftdm_status_t (*ftdm_stream_handle_raw_write_function_t) (ftdm_stream_handle_t *handle, uint8_t *data, ftdm_size_t datalen);
|
||||
typedef ftdm_status_t (*ftdm_stream_handle_write_function_t) (ftdm_stream_handle_t *handle, const char *fmt, ...);
|
||||
|
||||
#include "ftdm_dso.h"
|
||||
|
||||
#define FTDM_NODE_NAME_SIZE 50
|
||||
struct ftdm_conf_node {
|
||||
/* node name */
|
||||
char name[FTDM_NODE_NAME_SIZE];
|
||||
|
||||
/* total slots for parameters */
|
||||
unsigned int t_parameters;
|
||||
|
||||
/* current number of parameters */
|
||||
unsigned int n_parameters;
|
||||
|
||||
/* array of parameters */
|
||||
ftdm_conf_parameter_t *parameters;
|
||||
|
||||
/* first node child */
|
||||
struct ftdm_conf_node *child;
|
||||
|
||||
/* next node sibling */
|
||||
struct ftdm_conf_node *next;
|
||||
|
||||
/* my parent if any */
|
||||
struct ftdm_conf_node *parent;
|
||||
};
|
||||
|
||||
typedef struct ftdm_module {
|
||||
char name[256];
|
||||
fio_io_load_t io_load;
|
||||
fio_io_unload_t io_unload;
|
||||
fio_sig_load_t sig_load;
|
||||
fio_sig_configure_t sig_configure;
|
||||
fio_sig_unload_t sig_unload;
|
||||
/*!
|
||||
\brief configure a given span signaling
|
||||
\see sig_configure
|
||||
This is just like sig_configure but receives
|
||||
an an ftdm_conf_node_t instead
|
||||
I'd like to deprecate sig_configure and move
|
||||
all modules to use configure_span_signaling
|
||||
*/
|
||||
fio_configure_span_signaling_t configure_span_signaling;
|
||||
ftdm_dso_lib_t lib;
|
||||
char path[256];
|
||||
} ftdm_module_t;
|
||||
|
||||
#ifndef __FUNCTION__
|
||||
#define __FUNCTION__ (const char *)__func__
|
||||
#endif
|
||||
|
||||
typedef struct ftdm_fsk_data_state ftdm_fsk_data_state_t;
|
||||
typedef int (*ftdm_fsk_data_decoder_t)(ftdm_fsk_data_state_t *state);
|
||||
typedef ftdm_status_t (*ftdm_fsk_write_sample_t)(int16_t *buf, ftdm_size_t buflen, void *user_data);
|
||||
typedef struct hashtable ftdm_hash_t;
|
||||
typedef struct hashtable_iterator ftdm_hash_iterator_t;
|
||||
typedef struct key ftdm_hash_key_t;
|
||||
typedef struct value ftdm_hash_val_t;
|
||||
typedef struct ftdm_bitstream ftdm_bitstream_t;
|
||||
typedef struct ftdm_fsk_modulator ftdm_fsk_modulator_t;
|
||||
typedef ftdm_status_t (*ftdm_span_start_t)(ftdm_span_t *span);
|
||||
typedef ftdm_status_t (*ftdm_span_stop_t)(ftdm_span_t *span);
|
||||
|
||||
typedef enum {
|
||||
FTDM_CAUSE_NONE = 0,
|
||||
FTDM_CAUSE_UNALLOCATED = 1,
|
||||
FTDM_CAUSE_NO_ROUTE_TRANSIT_NET = 2,
|
||||
FTDM_CAUSE_NO_ROUTE_DESTINATION = 3,
|
||||
FTDM_CAUSE_CHANNEL_UNACCEPTABLE = 6,
|
||||
FTDM_CAUSE_CALL_AWARDED_DELIVERED = 7,
|
||||
FTDM_CAUSE_NORMAL_CLEARING = 16,
|
||||
FTDM_CAUSE_USER_BUSY = 17,
|
||||
FTDM_CAUSE_NO_USER_RESPONSE = 18,
|
||||
FTDM_CAUSE_NO_ANSWER = 19,
|
||||
FTDM_CAUSE_SUBSCRIBER_ABSENT = 20,
|
||||
FTDM_CAUSE_CALL_REJECTED = 21,
|
||||
FTDM_CAUSE_NUMBER_CHANGED = 22,
|
||||
FTDM_CAUSE_REDIRECTION_TO_NEW_DESTINATION = 23,
|
||||
FTDM_CAUSE_EXCHANGE_ROUTING_ERROR = 25,
|
||||
FTDM_CAUSE_DESTINATION_OUT_OF_ORDER = 27,
|
||||
FTDM_CAUSE_INVALID_NUMBER_FORMAT = 28,
|
||||
FTDM_CAUSE_FACILITY_REJECTED = 29,
|
||||
FTDM_CAUSE_RESPONSE_TO_STATUS_ENQUIRY = 30,
|
||||
FTDM_CAUSE_NORMAL_UNSPECIFIED = 31,
|
||||
FTDM_CAUSE_NORMAL_CIRCUIT_CONGESTION = 34,
|
||||
FTDM_CAUSE_NETWORK_OUT_OF_ORDER = 38,
|
||||
FTDM_CAUSE_NORMAL_TEMPORARY_FAILURE = 41,
|
||||
FTDM_CAUSE_SWITCH_CONGESTION = 42,
|
||||
FTDM_CAUSE_ACCESS_INFO_DISCARDED = 43,
|
||||
FTDM_CAUSE_REQUESTED_CHAN_UNAVAIL = 44,
|
||||
FTDM_CAUSE_PRE_EMPTED = 45,
|
||||
FTDM_CAUSE_FACILITY_NOT_SUBSCRIBED = 50,
|
||||
FTDM_CAUSE_OUTGOING_CALL_BARRED = 52,
|
||||
FTDM_CAUSE_INCOMING_CALL_BARRED = 54,
|
||||
FTDM_CAUSE_BEARERCAPABILITY_NOTAUTH = 57,
|
||||
FTDM_CAUSE_BEARERCAPABILITY_NOTAVAIL = 58,
|
||||
FTDM_CAUSE_SERVICE_UNAVAILABLE = 63,
|
||||
FTDM_CAUSE_BEARERCAPABILITY_NOTIMPL = 65,
|
||||
FTDM_CAUSE_CHAN_NOT_IMPLEMENTED = 66,
|
||||
FTDM_CAUSE_FACILITY_NOT_IMPLEMENTED = 69,
|
||||
FTDM_CAUSE_SERVICE_NOT_IMPLEMENTED = 79,
|
||||
FTDM_CAUSE_INVALID_CALL_REFERENCE = 81,
|
||||
FTDM_CAUSE_INCOMPATIBLE_DESTINATION = 88,
|
||||
FTDM_CAUSE_INVALID_MSG_UNSPECIFIED = 95,
|
||||
FTDM_CAUSE_MANDATORY_IE_MISSING = 96,
|
||||
FTDM_CAUSE_MESSAGE_TYPE_NONEXIST = 97,
|
||||
FTDM_CAUSE_WRONG_MESSAGE = 98,
|
||||
FTDM_CAUSE_IE_NONEXIST = 99,
|
||||
FTDM_CAUSE_INVALID_IE_CONTENTS = 100,
|
||||
FTDM_CAUSE_WRONG_CALL_STATE = 101,
|
||||
FTDM_CAUSE_RECOVERY_ON_TIMER_EXPIRE = 102,
|
||||
FTDM_CAUSE_MANDATORY_IE_LENGTH_ERROR = 103,
|
||||
FTDM_CAUSE_PROTOCOL_ERROR = 111,
|
||||
FTDM_CAUSE_INTERWORKING = 127,
|
||||
FTDM_CAUSE_SUCCESS = 142,
|
||||
FTDM_CAUSE_ORIGINATOR_CANCEL = 487,
|
||||
FTDM_CAUSE_CRASH = 500,
|
||||
FTDM_CAUSE_SYSTEM_SHUTDOWN = 501,
|
||||
FTDM_CAUSE_LOSE_RACE = 502,
|
||||
FTDM_CAUSE_MANAGER_REQUEST = 503,
|
||||
FTDM_CAUSE_BLIND_TRANSFER = 600,
|
||||
FTDM_CAUSE_ATTENDED_TRANSFER = 601,
|
||||
FTDM_CAUSE_ALLOTTED_TIMEOUT = 602,
|
||||
FTDM_CAUSE_USER_CHALLENGE = 603,
|
||||
FTDM_CAUSE_MEDIA_TIMEOUT = 604
|
||||
} ftdm_call_cause_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/* For Emacs:
|
||||
* Local Variables:
|
||||
* mode:c
|
||||
* indent-tabs-mode:t
|
||||
* tab-width:4
|
||||
* c-basic-offset:4
|
||||
* End:
|
||||
* For VIM:
|
||||
* vim:set softtabstop=4 shiftwidth=4 tabstop=4:
|
||||
*/
|
||||
|
|
@ -34,7 +34,7 @@
|
|||
*/
|
||||
|
||||
#include <libteletone.h>
|
||||
#include "freetdm.h"
|
||||
#include "private/ftdm_core.h"
|
||||
|
||||
#define SMAX 32767
|
||||
#define SMIN -32768
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "freetdm.h"
|
||||
|
||||
|
||||
|
@ -12,10 +15,10 @@ static void *test_call(ftdm_thread_t *me, void *obj)
|
|||
|
||||
ftdm_log(FTDM_LOG_DEBUG, "answer call and start echo test\n");
|
||||
|
||||
ftdm_set_state_locked(chan, FTDM_CHANNEL_STATE_UP);
|
||||
ftdm_channel_call_answer(chan);
|
||||
ftdm_channel_command(chan, FTDM_COMMAND_SEND_DTMF, number);
|
||||
|
||||
while (chan->state == FTDM_CHANNEL_STATE_UP) {
|
||||
while (ftdm_channel_call_active(chan)) {
|
||||
ftdm_wait_flag_t flags = FTDM_READ;
|
||||
|
||||
if (ftdm_channel_wait(chan, &flags, -1) == FTDM_FAIL) {
|
||||
|
@ -32,8 +35,8 @@ static void *test_call(ftdm_thread_t *me, void *obj)
|
|||
}
|
||||
}
|
||||
|
||||
if (chan->state == FTDM_CHANNEL_STATE_UP) {
|
||||
ftdm_set_state_locked(chan, FTDM_CHANNEL_STATE_BUSY);
|
||||
if (ftdm_channel_call_active(chan)) {
|
||||
ftdm_channel_call_indicate(chan, FTDM_CHANNEL_INDICATE_BUSY);
|
||||
}
|
||||
|
||||
ftdm_log(FTDM_LOG_DEBUG, "call over\n");
|
||||
|
@ -47,7 +50,7 @@ static FIO_SIGNAL_CB_FUNCTION(on_signal)
|
|||
|
||||
switch(sigmsg->event_id) {
|
||||
case FTDM_SIGEVENT_START:
|
||||
ftdm_set_state_locked(sigmsg->channel, FTDM_CHANNEL_STATE_RING);
|
||||
ftdm_channel_call_indicate(sigmsg->channel, FTDM_CHANNEL_INDICATE_RING);
|
||||
ftdm_log(FTDM_LOG_DEBUG, "launching thread and indicating ring\n");
|
||||
ftdm_thread_create_detached(test_call, sigmsg->channel);
|
||||
break;
|
||||
|
@ -101,7 +104,7 @@ int main(int argc, char *argv[])
|
|||
"tonemap", "us",
|
||||
"digit_timeout", &digit_timeout,
|
||||
"max_dialstr", &max_dialstr,
|
||||
TAG_END
|
||||
FTDM_TAG_END
|
||||
) != FTDM_SUCCESS) {
|
||||
ftdm_log(FTDM_LOG_ERROR, "Error configuring FreeTDM span\n");
|
||||
goto done;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "freetdm.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
@ -7,6 +8,7 @@ int main(int argc, char *argv[])
|
|||
unsigned ms = 20;
|
||||
ftdm_codec_t codec = FTDM_CODEC_SLIN;
|
||||
unsigned runs = 1;
|
||||
int spanid, chanid;
|
||||
|
||||
|
||||
if (ftdm_global_init() != FTDM_SUCCESS) {
|
||||
|
@ -20,7 +22,9 @@ int main(int argc, char *argv[])
|
|||
//if (ftdm_channel_open_any("wanpipe", 0, FTDM_TOP_DOWN, &chan) == FTDM_SUCCESS) {
|
||||
if (ftdm_channel_open(1, 1, &chan) == FTDM_SUCCESS) {
|
||||
int x = 0;
|
||||
printf("opened channel %d:%d\n", chan->span_id, chan->chan_id);
|
||||
spanid = ftdm_channel_get_span_id(chan);
|
||||
chanid = ftdm_channel_get_id(chan);
|
||||
printf("opened channel %d:%d\n", spanid, chanid);
|
||||
|
||||
#if 1
|
||||
if (ftdm_channel_command(chan, FTDM_COMMAND_SET_INTERVAL, &ms) == FTDM_SUCCESS) {
|
||||
|
@ -28,7 +32,7 @@ int main(int argc, char *argv[])
|
|||
ftdm_channel_command(chan, FTDM_COMMAND_GET_INTERVAL, &ms);
|
||||
printf("interval set to %u\n", ms);
|
||||
} else {
|
||||
printf("set interval failed [%s]\n", chan->last_error);
|
||||
printf("set interval failed [%s]\n", ftdm_channel_get_last_error(chan));
|
||||
}
|
||||
#endif
|
||||
if (ftdm_channel_command(chan, FTDM_COMMAND_SET_CODEC, &codec) == FTDM_SUCCESS) {
|
||||
|
@ -36,7 +40,7 @@ int main(int argc, char *argv[])
|
|||
ftdm_channel_command(chan, FTDM_COMMAND_GET_CODEC, &codec);
|
||||
printf("codec set to %u\n", codec);
|
||||
} else {
|
||||
printf("set codec failed [%s]\n", chan->last_error);
|
||||
printf("set codec failed [%s]\n", ftdm_channel_get_last_error(chan));
|
||||
}
|
||||
|
||||
for(x = 0; x < 25; x++) {
|
||||
|
@ -45,22 +49,22 @@ int main(int argc, char *argv[])
|
|||
ftdm_wait_flag_t flags = FTDM_READ;
|
||||
|
||||
if (ftdm_channel_wait(chan, &flags, -1) == FTDM_FAIL) {
|
||||
printf("wait FAIL! %u [%s]\n", (unsigned)len, chan->last_error);
|
||||
printf("wait FAIL! %u [%s]\n", (unsigned)len, ftdm_channel_get_last_error(chan));
|
||||
}
|
||||
if (flags & FTDM_READ) {
|
||||
if (ftdm_channel_read(chan, buf, &len) == FTDM_SUCCESS) {
|
||||
printf("READ: %u\n", (unsigned)len);
|
||||
} else {
|
||||
printf("READ FAIL! %u [%s]\n", (unsigned)len, chan->last_error);
|
||||
printf("READ FAIL! %u [%s]\n", (unsigned)len, ftdm_channel_get_last_error(chan));
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
printf("wait fail [%s]\n", chan->last_error);
|
||||
printf("wait fail [%s]\n", ftdm_channel_get_last_error(chan));
|
||||
}
|
||||
}
|
||||
ftdm_channel_close(&chan);
|
||||
} else {
|
||||
printf("open fail [%s]\n", chan->last_error);
|
||||
printf("open fail [%s]\n", ftdm_channel_get_last_error(chan));
|
||||
}
|
||||
|
||||
if(--runs) {
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "freetdm.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
static FIO_SIGNAL_CB_FUNCTION(on_signal)
|
||||
{
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "freetdm.h"
|
||||
#include "private/ftdm_core.h"
|
||||
|
||||
ftdm_status_t my_write_sample(int16_t *buf, ftdm_size_t buflen, void *user_data);
|
||||
|
||||
struct helper {
|
||||
|
|
|
@ -1,5 +1,11 @@
|
|||
#include "freetdm.h"
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
static int THREADS[4][31] = { {0} };
|
||||
static int R = 0;
|
||||
|
@ -12,18 +18,20 @@ static void *channel_run(ftdm_thread_t *me, void *obj)
|
|||
ftdm_channel_t *ftdmchan = obj;
|
||||
int fd = -1;
|
||||
short buf[160];
|
||||
int spanid = ftdm_channel_get_span_id(ftdmchan);
|
||||
int chanid = ftdm_channel_get_id(ftdmchan);
|
||||
|
||||
ftdm_mutex_lock(mutex);
|
||||
T++;
|
||||
ftdm_mutex_unlock(mutex);
|
||||
|
||||
ftdm_set_state_locked_wait(ftdmchan, FTDM_CHANNEL_STATE_UP);
|
||||
ftdm_channel_call_answer(ftdmchan);
|
||||
|
||||
if ((fd = open("test.raw", O_RDONLY, 0)) < 0) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
while(R == 1 && THREADS[ftdmchan->span_id][ftdmchan->chan_id] == 1) {
|
||||
while(R == 1 && THREADS[spanid][chanid] == 1) {
|
||||
ssize_t bytes = read(fd, buf, sizeof(buf));
|
||||
size_t bbytes;
|
||||
|
||||
|
@ -44,9 +52,9 @@ static void *channel_run(ftdm_thread_t *me, void *obj)
|
|||
|
||||
end:
|
||||
|
||||
ftdm_set_state_locked_wait(ftdmchan, FTDM_CHANNEL_STATE_HANGUP);
|
||||
ftdm_channel_call_hangup(ftdmchan);
|
||||
|
||||
THREADS[ftdmchan->span_id][ftdmchan->chan_id] = 0;
|
||||
THREADS[spanid][chanid] = 0;
|
||||
|
||||
ftdm_mutex_lock(mutex);
|
||||
T = 0;
|
||||
|
@ -57,17 +65,19 @@ static void *channel_run(ftdm_thread_t *me, void *obj)
|
|||
|
||||
static FIO_SIGNAL_CB_FUNCTION(on_signal)
|
||||
{
|
||||
ftdm_log(FTDM_LOG_DEBUG, "got sig %d:%d [%s]\n", sigmsg->channel->span_id, sigmsg->channel->chan_id, ftdm_signal_event2str(sigmsg->event_id));
|
||||
int spanid = ftdm_channel_get_span_id(sigmsg->channel);
|
||||
int chanid = ftdm_channel_get_id(sigmsg->channel);
|
||||
ftdm_log(FTDM_LOG_DEBUG, "got sig %d:%d [%s]\n", spanid, chanid, ftdm_signal_event2str(sigmsg->event_id));
|
||||
|
||||
switch(sigmsg->event_id) {
|
||||
|
||||
case FTDM_SIGEVENT_STOP:
|
||||
THREADS[sigmsg->channel->span_id][sigmsg->channel->chan_id] = -1;
|
||||
THREADS[spanid][chanid] = -1;
|
||||
break;
|
||||
|
||||
case FTDM_SIGEVENT_START:
|
||||
if (!THREADS[sigmsg->channel->span_id][sigmsg->channel->chan_id]) {
|
||||
THREADS[sigmsg->channel->span_id][sigmsg->channel->chan_id] = 1;
|
||||
if (!THREADS[spanid][chanid]) {
|
||||
THREADS[spanid][chanid] = 1;
|
||||
ftdm_thread_create_detached(channel_run, sigmsg->channel);
|
||||
}
|
||||
|
||||
|
@ -125,7 +135,7 @@ int main(int argc, char *argv[])
|
|||
"l1", "alaw",
|
||||
"debug", NULL,
|
||||
"opts", 0,
|
||||
TAG_END) == FTDM_SUCCESS) {
|
||||
FTDM_TAG_END) == FTDM_SUCCESS) {
|
||||
|
||||
|
||||
ftdm_span_start(span);
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
#include "freetdm.h"
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
static int R = 0;
|
||||
static ftdm_mutex_t *mutex = NULL;
|
||||
|
||||
static FIO_SIGNAL_CB_FUNCTION(on_r2_signal)
|
||||
{
|
||||
ftdm_log(FTDM_LOG_DEBUG, "Got R2 channel sig [%s] in channel\n", ftdm_signal_event2str(sigmsg->event_id), sigmsg->channel->physical_chan_id);
|
||||
int chanid = ftdm_channel_get_ph_id(sigmsg->channel);
|
||||
ftdm_log(FTDM_LOG_DEBUG, "Got R2 channel sig [%s] in channel\n", ftdm_signal_event2str(sigmsg->event_id), chanid);
|
||||
return FTDM_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -49,7 +51,7 @@ int main(int argc, char *argv[])
|
|||
"max_ani", 10,
|
||||
"max_dnis", 4,
|
||||
"logging", "all",
|
||||
TAG_END) == FTDM_SUCCESS) {
|
||||
FTDM_TAG_END) == FTDM_SUCCESS) {
|
||||
|
||||
|
||||
ftdm_span_start(span);
|
||||
|
|
|
@ -46,6 +46,9 @@
|
|||
#include <signal.h>
|
||||
|
||||
#include "freetdm.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
|
||||
/* arbitrary limit for max calls in this sample program */
|
||||
|
@ -137,16 +140,20 @@ static void release_timers(ftdm_channel_t *channel)
|
|||
/* hangup the call */
|
||||
static void send_hangup(ftdm_channel_t *channel)
|
||||
{
|
||||
ftdm_log(FTDM_LOG_NOTICE, "-- Requesting hangup in channel %d:%d\n", channel->span_id, channel->chan_id);
|
||||
ftdm_set_state_locked(channel, FTDM_CHANNEL_STATE_HANGUP);
|
||||
int spanid = ftdm_channel_get_span_id(channel);
|
||||
int chanid = ftdm_channel_get_id(channel);
|
||||
ftdm_log(FTDM_LOG_NOTICE, "-- Requesting hangup in channel %d:%d\n", spanid, chanid);
|
||||
ftdm_channel_call_hangup(channel);
|
||||
}
|
||||
|
||||
/* send answer for an incoming call */
|
||||
static void send_answer(ftdm_channel_t *channel)
|
||||
{
|
||||
/* we move the channel signaling state machine to UP (answered) */
|
||||
ftdm_log(FTDM_LOG_NOTICE, "-- Requesting answer in channel %d:%d\n", channel->span_id, channel->chan_id);
|
||||
ftdm_set_state_locked(channel, FTDM_CHANNEL_STATE_UP);
|
||||
int spanid = ftdm_channel_get_span_id(channel);
|
||||
int chanid = ftdm_channel_get_id(channel);
|
||||
ftdm_log(FTDM_LOG_NOTICE, "-- Requesting answer in channel %d:%d\n", spanid, chanid);
|
||||
ftdm_channel_call_answer(channel);
|
||||
schedule_timer(channel, HANGUP_TIMER, send_hangup);
|
||||
}
|
||||
|
||||
|
@ -154,8 +161,10 @@ static void send_answer(ftdm_channel_t *channel)
|
|||
static void send_progress(ftdm_channel_t *channel)
|
||||
{
|
||||
/* we move the channel signaling state machine to UP (answered) */
|
||||
ftdm_log(FTDM_LOG_NOTICE, "-- Requesting progress\n", channel->span_id, channel->chan_id);
|
||||
ftdm_set_state_locked(channel, FTDM_CHANNEL_STATE_PROGRESS);
|
||||
int spanid = ftdm_channel_get_span_id(channel);
|
||||
int chanid = ftdm_channel_get_id(channel);
|
||||
ftdm_log(FTDM_LOG_NOTICE, "-- Requesting progress\n", spanid, chanid);
|
||||
ftdm_channel_call_indicate(channel, FTDM_CHANNEL_INDICATE_PROGRESS);
|
||||
schedule_timer(channel, ANSWER_TIMER, send_answer);
|
||||
}
|
||||
|
||||
|
@ -196,7 +205,7 @@ static FIO_SIGNAL_CB_FUNCTION(on_signaling_event)
|
|||
/* release any timer for this channel */
|
||||
release_timers(sigmsg->channel);
|
||||
/* acknowledge the hangup */
|
||||
ftdm_set_state_locked(sigmsg->channel, FTDM_CHANNEL_STATE_HANGUP);
|
||||
ftdm_channel_call_hangup(sigmsg->channel);
|
||||
break;
|
||||
default:
|
||||
ftdm_log(FTDM_LOG_WARNING, "Unhandled event %s in channel %d:%d\n", ftdm_signal_event2str(sigmsg->event_id),
|
||||
|
@ -223,7 +232,7 @@ static void place_call(const ftdm_span_t *span, const char *number)
|
|||
* it is also an option to use ftdm_channel_open_by_group to let freetdm hunt
|
||||
* an available channel in a given group instead of per span
|
||||
* */
|
||||
status = ftdm_channel_open_by_span(span->span_id, FTDM_TOP_DOWN, &caller_data, &ftdmchan);
|
||||
status = ftdm_channel_open_by_span(ftdm_span_get_id(span), FTDM_TOP_DOWN, &caller_data, &ftdmchan);
|
||||
if (status != FTDM_SUCCESS) {
|
||||
ftdm_log(FTDM_LOG_ERROR, "Failed to originate call\n");
|
||||
return;
|
||||
|
@ -232,9 +241,9 @@ static void place_call(const ftdm_span_t *span, const char *number)
|
|||
g_outgoing_channel = ftdmchan;
|
||||
|
||||
/* set the caller data for the outgoing channel */
|
||||
memcpy(&ftdmchan->caller_data, &caller_data, sizeof(caller_data));
|
||||
ftdm_channel_set_caller_data(ftdmchan, &caller_data);
|
||||
|
||||
status = ftdm_channel_outgoing_call(ftdmchan);
|
||||
status = ftdm_channel_call_place(ftdmchan);
|
||||
if (status != FTDM_SUCCESS) {
|
||||
ftdm_log(FTDM_LOG_ERROR, "Failed to originate call\n");
|
||||
return;
|
||||
|
@ -331,7 +340,7 @@ int main(int argc, char *argv[])
|
|||
|
||||
/* send the configuration values down to the stack */
|
||||
if (ftdm_configure_span_signaling("sangoma_boost", span, on_signaling_event, parameters) != FTDM_SUCCESS) {
|
||||
fprintf(stderr, "Error configuring sangoma_boost signaling abstraction in span %s\n", span->name);
|
||||
fprintf(stderr, "Error configuring sangoma_boost signaling abstraction in span %s\n", ftdm_span_get_name(span));
|
||||
goto done;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#include "freetdm.h"
|
||||
#include "private/ftdm_core.h"
|
||||
|
||||
struct ttmp {
|
||||
int fd;
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
* 2005 06 11 R. Krten created
|
||||
*/
|
||||
|
||||
#include <freetdm.h>
|
||||
#include <private/ftdm_core.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
|
Loading…
Reference in New Issue