git-svn-id: http://svn.openzap.org/svn/openzap/trunk@90 a93c3328-9c30-0410-af19-c9cd2b2d52af
This commit is contained in:
Anthony Minessale 2007-05-22 02:27:50 +00:00
parent b8635f17e7
commit 62eea6fd81
6 changed files with 165 additions and 144 deletions

View File

@ -32,7 +32,9 @@
OBJS=hashtable.o \
hashtable_itr.o \
openzap.o \
zap_io.o \
zap_isdn.o \
zap_analog.o \
zap_config.o \
g711.o \
libteletone_detect.o \
@ -77,7 +79,7 @@ sangoma_pri.o: sangoma_pri.c
priserver: $(MYLIB) priserver.o sangoma_pri.o
$(CC) sangoma_pri.o priserver.o -L. -o priserver -lopenzap -lm -lpthread ../../libpri-1.2.4/libpri.a
openzap.o: openzap.c
zap_io.o: zap_io.c
$(CC) $(MOD_CFLAGS) $(CC_CFLAGS) $(CFLAGS) -c $< -o $@
zap_wanpipe.o: zap_wanpipe.c

View File

@ -173,7 +173,7 @@ struct zap_channel {
teletone_dtmf_detect_state_t dtmf_detect;
zap_event_t event_header;
char last_error[256];
zint_event_cb_t event_callback;
zio_event_cb_t event_callback;
void *mod_data;
uint32_t skip_read_frames;
zap_buffer_t *dtmf_buffer;
@ -181,7 +181,7 @@ struct zap_channel {
uint32_t dtmf_off;
teletone_generation_session_t tone_session;
struct zap_span *span;
struct zap_software_interface *zint;
struct zap_io_interface *zio;
};
@ -189,34 +189,35 @@ struct zap_span {
uint32_t span_id;
uint32_t chan_count;
zap_span_flag_t flags;
struct zap_software_interface *zint;
zint_event_cb_t event_callback;
struct zap_io_interface *zio;
zio_event_cb_t event_callback;
zap_mutex_t *mutex;
zap_signal_type_t signal_type;
zap_channel_t channels[ZAP_MAX_CHANNELS_SPAN];
};
extern zap_logger_t zap_log;
struct zap_software_interface {
struct zap_io_interface {
const char *name;
zint_configure_t configure;
zint_open_t open;
zint_close_t close;
zint_command_t command;
zint_wait_t wait;
zint_read_t read;
zint_write_t write;
zio_configure_t configure;
zio_open_t open;
zio_close_t close;
zio_command_t command;
zio_wait_t wait;
zio_read_t read;
zio_write_t write;
uint32_t span_index;
struct zap_span spans[ZAP_MAX_SPANS_INTERFACE];
};
zap_status_t zap_span_find(const char *name, uint32_t id, zap_span_t **span);
zap_status_t zap_span_create(zap_software_interface_t *zint, zap_span_t **span);
zap_status_t zap_span_close_all(zap_software_interface_t *zint);
zap_status_t zap_span_create(zap_io_interface_t *zio, zap_span_t **span);
zap_status_t zap_span_close_all(zap_io_interface_t *zio);
zap_status_t zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_chan_type_t type, zap_channel_t **chan);
zap_status_t zap_span_set_event_callback(zap_span_t *span, zint_event_cb_t event_callback);
zap_status_t zap_channel_set_event_callback(zap_channel_t *zchan, zint_event_cb_t event_callback);
zap_status_t zap_span_set_event_callback(zap_span_t *span, zio_event_cb_t event_callback);
zap_status_t zap_channel_set_event_callback(zap_channel_t *zchan, zio_event_cb_t event_callback);
zap_status_t zap_channel_open(const char *name, uint32_t span_id, uint32_t chan_id, zap_channel_t **zchan);
zap_status_t zap_channel_open_any(const char *name, uint32_t span_id, zap_direction_t direction, zap_channel_t **zchan);
zap_status_t zap_channel_close(zap_channel_t **zchan);

View File

@ -45,11 +45,36 @@ typedef int zap_socket_t;
#endif
typedef size_t zap_size_t;
struct zap_software_interface;
struct zap_io_interface;
#define ZAP_COMMAND_OBJ_INT *((int *)obj)
#define ZAP_COMMAND_OBJ_CHAR_P (char *)obj
typedef enum {
ZAP_SIGTYPE_NONE,
ZAP_SIGTYPE_ISDN,
ZAP_SIGTYPE_RBS,
ZAP_SIGTYPE_ANALOG
} zap_signal_type_t;
typedef enum {
ZAP_SIGEVENT_CALL_START,
ZAP_SIGEVENT_CALL_STOP,
ZAP_SIGEVENT_CALL_TRANSFER,
ZAP_SIGEVENT_ANSWER,
ZAP_SIGEVENT_PROGRESS,
ZAP_SIGEVENT_PROGRESS_MEDIA,
ZAP_SIGEVENT_NOTIFY,
ZAP_SIGEVENT_MISC
} zap_signal_event_t;
typedef enum {
ZAP_EVENT_NONE,
ZAP_EVENT_DTMF,
ZAP_EVENT_COUNT
} zap_event_type_t;
typedef enum {
ZAP_TOP_DOWN,
ZAP_BOTTOM_UP
@ -134,43 +159,43 @@ typedef enum {
typedef struct zap_channel zap_channel_t;
typedef struct zap_event zap_event_t;
#define ZINT_EVENT_CB_ARGS (zap_channel_t *zchan, zap_event_t *event)
#define ZINT_CODEC_ARGS (void *data, zap_size_t max, zap_size_t *datalen)
#define ZINT_CONFIGURE_ARGS (struct zap_software_interface *zint)
#define ZINT_OPEN_ARGS (zap_channel_t *zchan)
#define ZINT_CLOSE_ARGS (zap_channel_t *zchan)
#define ZINT_COMMAND_ARGS (zap_channel_t *zchan, zap_command_t command, void *obj)
#define ZINT_WAIT_ARGS (zap_channel_t *zchan, zap_wait_flag_t *flags, int32_t to)
#define ZINT_READ_ARGS (zap_channel_t *zchan, void *data, zap_size_t *datalen)
#define ZINT_WRITE_ARGS (zap_channel_t *zchan, void *data, zap_size_t *datalen)
#define ZIO_EVENT_CB_ARGS (zap_channel_t *zchan, zap_event_t *event)
#define ZIO_CODEC_ARGS (void *data, zap_size_t max, zap_size_t *datalen)
#define ZIO_CONFIGURE_ARGS (struct zap_io_interface *zio)
#define ZIO_OPEN_ARGS (zap_channel_t *zchan)
#define ZIO_CLOSE_ARGS (zap_channel_t *zchan)
#define ZIO_COMMAND_ARGS (zap_channel_t *zchan, zap_command_t command, void *obj)
#define ZIO_WAIT_ARGS (zap_channel_t *zchan, zap_wait_flag_t *flags, int32_t to)
#define ZIO_READ_ARGS (zap_channel_t *zchan, void *data, zap_size_t *datalen)
#define ZIO_WRITE_ARGS (zap_channel_t *zchan, void *data, zap_size_t *datalen)
typedef zap_status_t (*zint_event_cb_t) ZINT_EVENT_CB_ARGS ;
typedef zap_status_t (*zint_codec_t) ZINT_CODEC_ARGS ;
typedef zap_status_t (*zint_configure_t) ZINT_CONFIGURE_ARGS ;
typedef zap_status_t (*zint_open_t) ZINT_OPEN_ARGS ;
typedef zap_status_t (*zint_close_t) ZINT_CLOSE_ARGS ;
typedef zap_status_t (*zint_command_t) ZINT_COMMAND_ARGS ;
typedef zap_status_t (*zint_wait_t) ZINT_WAIT_ARGS ;
typedef zap_status_t (*zint_read_t) ZINT_READ_ARGS ;
typedef zap_status_t (*zint_write_t) ZINT_WRITE_ARGS ;
typedef zap_status_t (*zio_event_cb_t) ZIO_EVENT_CB_ARGS ;
typedef zap_status_t (*zio_codec_t) ZIO_CODEC_ARGS ;
typedef zap_status_t (*zio_configure_t) ZIO_CONFIGURE_ARGS ;
typedef zap_status_t (*zio_open_t) ZIO_OPEN_ARGS ;
typedef zap_status_t (*zio_close_t) ZIO_CLOSE_ARGS ;
typedef zap_status_t (*zio_command_t) ZIO_COMMAND_ARGS ;
typedef zap_status_t (*zio_wait_t) ZIO_WAIT_ARGS ;
typedef zap_status_t (*zio_read_t) ZIO_READ_ARGS ;
typedef zap_status_t (*zio_write_t) ZIO_WRITE_ARGS ;
#define ZINT_EVENT_CB_FUNCTION(name) zap_status_t name ZINT_EVENT_CB_ARGS
#define ZINT_CODEC_FUNCTION(name) zap_status_t name ZINT_CODEC_ARGS
#define ZINT_CONFIGURE_FUNCTION(name) zap_status_t name ZINT_CONFIGURE_ARGS
#define ZINT_OPEN_FUNCTION(name) zap_status_t name ZINT_OPEN_ARGS
#define ZINT_CLOSE_FUNCTION(name) zap_status_t name ZINT_CLOSE_ARGS
#define ZINT_COMMAND_FUNCTION(name) zap_status_t name ZINT_COMMAND_ARGS
#define ZINT_WAIT_FUNCTION(name) zap_status_t name ZINT_WAIT_ARGS
#define ZINT_READ_FUNCTION(name) zap_status_t name ZINT_READ_ARGS
#define ZINT_WRITE_FUNCTION(name) zap_status_t name ZINT_WRITE_ARGS
#define ZIO_EVENT_CB_FUNCTION(name) zap_status_t name ZIO_EVENT_CB_ARGS
#define ZIO_CODEC_FUNCTION(name) zap_status_t name ZIO_CODEC_ARGS
#define ZIO_CONFIGURE_FUNCTION(name) zap_status_t name ZIO_CONFIGURE_ARGS
#define ZIO_OPEN_FUNCTION(name) zap_status_t name ZIO_OPEN_ARGS
#define ZIO_CLOSE_FUNCTION(name) zap_status_t name ZIO_CLOSE_ARGS
#define ZIO_COMMAND_FUNCTION(name) zap_status_t name ZIO_COMMAND_ARGS
#define ZIO_WAIT_FUNCTION(name) zap_status_t name ZIO_WAIT_ARGS
#define ZIO_READ_FUNCTION(name) zap_status_t name ZIO_READ_ARGS
#define ZIO_WRITE_FUNCTION(name) zap_status_t name ZIO_WRITE_ARGS
#define ZINT_CONFIGURE_MUZZLE assert(zint != NULL)
#define ZINT_OPEN_MUZZLE assert(zchan != NULL)
#define ZINT_CLOSE_MUZZLE assert(zchan != NULL)
#define ZINT_COMMAND_MUZZLE assert(zchan != NULL); assert(command != 0); assert(obj != NULL)
#define ZINT_WAIT_MUZZLE assert(zchan != NULL); assert(flags != 0); assert(to != 0)
#define ZINT_READ_MUZZLE assert(zchan != NULL); assert(data != NULL); assert(datalen != NULL)
#define ZINT_WRITE_MUZZLE assert(zchan != NULL); assert(data != NULL); assert(datalen != NULL)
#define ZIO_CONFIGURE_MUZZLE assert(zio != NULL)
#define ZIO_OPEN_MUZZLE assert(zchan != NULL)
#define ZIO_CLOSE_MUZZLE assert(zchan != NULL)
#define ZIO_COMMAND_MUZZLE assert(zchan != NULL); assert(command != 0); assert(obj != NULL)
#define ZIO_WAIT_MUZZLE assert(zchan != NULL); assert(flags != 0); assert(to != 0)
#define ZIO_READ_MUZZLE assert(zchan != NULL); assert(data != NULL); assert(datalen != NULL)
#define ZIO_WRITE_MUZZLE assert(zchan != NULL); assert(data != NULL); assert(datalen != NULL)
#define ZAP_PRE __FILE__, __FUNCTION__, __LINE__
@ -192,16 +217,9 @@ typedef zap_status_t (*zint_write_t) ZINT_WRITE_ARGS ;
#define ZAP_LOG_ALERT ZAP_PRE, ZAP_LOG_LEVEL_ALERT
#define ZAP_LOG_EMERG ZAP_PRE, ZAP_LOG_LEVEL_EMERG
typedef enum {
ZAP_EVENT_NONE,
ZAP_EVENT_DTMF,
ZAP_EVENT_COUNT
} zap_event_type_t;
typedef struct zap_span zap_span_t;
typedef void (*zap_logger_t)(char *file, const char *func, int line, int level, char *fmt, ...);
typedef struct zap_software_interface zap_software_interface_t;
typedef struct zap_io_interface zap_io_interface_t;
typedef struct hashtable zap_hash_t;
typedef struct hashtable_itr zap_hash_itr_t;
typedef struct key zap_hash_key_t;

View File

@ -35,7 +35,7 @@
#define ZAP_WANPIPE_H
#include "openzap.h"
zap_status_t wanpipe_init(zap_software_interface_t **zint);
zap_status_t wanpipe_init(zap_io_interface_t **zint);
zap_status_t wanpipe_destroy(void);
#endif

View File

@ -147,18 +147,18 @@ static uint32_t hashfromstring(void *ky)
return hash;
}
zap_status_t zap_span_create(zap_software_interface_t *zint, zap_span_t **span)
zap_status_t zap_span_create(zap_io_interface_t *zio, zap_span_t **span)
{
zap_span_t *new_span = NULL;
assert(zint != NULL);
assert(zio != NULL);
if (zint->span_index < ZAP_MAX_SPANS_INTERFACE) {
new_span = &zint->spans[++zint->span_index];
if (zio->span_index < ZAP_MAX_SPANS_INTERFACE) {
new_span = &zio->spans[++zio->span_index];
memset(new_span, 0, sizeof(*new_span));
zap_set_flag(new_span, ZAP_SPAN_CONFIGURED);
new_span->span_id = zint->span_index;
new_span->zint = zint;
new_span->span_id = zio->span_index;
new_span->zio = zio;
zap_mutex_create(&new_span->mutex);
*span = new_span;
return ZAP_SUCCESS;
@ -167,13 +167,13 @@ zap_status_t zap_span_create(zap_software_interface_t *zint, zap_span_t **span)
return ZAP_FAIL;
}
zap_status_t zap_span_close_all(zap_software_interface_t *zint)
zap_status_t zap_span_close_all(zap_io_interface_t *zio)
{
zap_span_t *span;
uint32_t i;
for(i = 0; i < zint->span_index; i++) {
span = &zint->spans[i];
for(i = 0; i < zio->span_index; i++) {
span = &zio->spans[i];
if (span->mutex) {
zap_mutex_destroy(&span->mutex);
}
@ -189,7 +189,7 @@ zap_status_t zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_cha
new_chan = &span->channels[++span->chan_count];
new_chan->type = type;
new_chan->sockfd = sockfd;
new_chan->zint = span->zint;
new_chan->zio = span->zio;
new_chan->span_id = span->span_id;
new_chan->chan_id = span->chan_count;
new_chan->span = span;
@ -203,14 +203,14 @@ zap_status_t zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_cha
zap_status_t zap_span_find(const char *name, uint32_t id, zap_span_t **span)
{
zap_software_interface_t *zint;
zap_io_interface_t *zio;
zap_span_t *fspan;
zap_mutex_lock(globals.mutex);
zint = (zap_software_interface_t *) hashtable_search(globals.interface_hash, (char *)name);
zio = (zap_io_interface_t *) hashtable_search(globals.interface_hash, (char *)name);
zap_mutex_unlock(globals.mutex);
if (!zint) {
if (!zio) {
return ZAP_FAIL;
}
@ -218,7 +218,7 @@ zap_status_t zap_span_find(const char *name, uint32_t id, zap_span_t **span)
return ZAP_FAIL;
}
fspan = &zint->spans[id];
fspan = &zio->spans[id];
if (!zap_test_flag(fspan, ZAP_SPAN_CONFIGURED)) {
return ZAP_FAIL;
@ -230,7 +230,7 @@ zap_status_t zap_span_find(const char *name, uint32_t id, zap_span_t **span)
}
zap_status_t zap_span_set_event_callback(zap_span_t *span, zint_event_cb_t event_callback)
zap_status_t zap_span_set_event_callback(zap_span_t *span, zio_event_cb_t event_callback)
{
zap_mutex_lock(span->mutex);
span->event_callback = event_callback;
@ -238,7 +238,7 @@ zap_status_t zap_span_set_event_callback(zap_span_t *span, zint_event_cb_t event
return ZAP_SUCCESS;
}
zap_status_t zap_channel_set_event_callback(zap_channel_t *zchan, zint_event_cb_t event_callback)
zap_status_t zap_channel_set_event_callback(zap_channel_t *zchan, zio_event_cb_t event_callback)
{
zap_mutex_lock(zchan->span->mutex);
zchan->event_callback = event_callback;
@ -248,7 +248,7 @@ zap_status_t zap_channel_set_event_callback(zap_channel_t *zchan, zint_event_cb_
zap_status_t zap_channel_open_any(const char *name, uint32_t span_id, zap_direction_t direction, zap_channel_t **zchan)
{
zap_software_interface_t *zint;
zap_io_interface_t *zio;
zap_status_t status = ZAP_FAIL;
zap_channel_t *check;
uint32_t i,j;
@ -256,10 +256,10 @@ zap_status_t zap_channel_open_any(const char *name, uint32_t span_id, zap_direct
uint32_t span_max;
zap_mutex_lock(globals.mutex);
zint = (zap_software_interface_t *) hashtable_search(globals.interface_hash, (char *)name);
zio = (zap_io_interface_t *) hashtable_search(globals.interface_hash, (char *)name);
zap_mutex_unlock(globals.mutex);
if (!zint) {
if (!zio) {
zap_log(ZAP_LOG_ERROR, "Invalid interface name!\n");
return ZAP_FAIL;
}
@ -267,7 +267,7 @@ zap_status_t zap_channel_open_any(const char *name, uint32_t span_id, zap_direct
if (span_id) {
span_max = span_id;
} else {
span_max = zint->span_index;
span_max = zio->span_index;
}
if (direction == ZAP_TOP_DOWN) {
@ -279,7 +279,7 @@ zap_status_t zap_channel_open_any(const char *name, uint32_t span_id, zap_direct
zap_mutex_lock(globals.mutex);
for(;;) {
span = &zint->spans[j];
span = &zio->spans[j];
if (!zap_test_flag(span, ZAP_SPAN_CONFIGURED)) {
goto next_loop;
@ -317,7 +317,7 @@ zap_status_t zap_channel_open_any(const char *name, uint32_t span_id, zap_direct
if (zap_test_flag(check, ZAP_CHANNEL_READY) && !zap_test_flag(check, ZAP_CHANNEL_OPEN)) {
status = check->zint->open(check);
status = check->zio->open(check);
if (status == ZAP_SUCCESS) {
zap_set_flag(check, ZAP_CHANNEL_OPEN);
@ -376,27 +376,27 @@ static zap_status_t zap_channel_reset(zap_channel_t *zchan)
zap_status_t zap_channel_open(const char *name, uint32_t span_id, uint32_t chan_id, zap_channel_t **zchan)
{
zap_software_interface_t *zint;
zap_io_interface_t *zio;
zap_status_t status = ZAP_FAIL;
zap_mutex_lock(globals.mutex);
zint = (zap_software_interface_t *) hashtable_search(globals.interface_hash, (char *)name);
zio = (zap_io_interface_t *) hashtable_search(globals.interface_hash, (char *)name);
zap_mutex_unlock(globals.mutex);
if (span_id < ZAP_MAX_SPANS_INTERFACE && chan_id < ZAP_MAX_CHANNELS_SPAN && zint) {
if (span_id < ZAP_MAX_SPANS_INTERFACE && chan_id < ZAP_MAX_CHANNELS_SPAN && zio) {
zap_channel_t *check;
zap_mutex_lock(zint->spans[span_id].mutex);
check = &zint->spans[span_id].channels[chan_id];
zap_mutex_lock(zio->spans[span_id].mutex);
check = &zio->spans[span_id].channels[chan_id];
if (zap_test_flag(check, ZAP_CHANNEL_READY) && ! zap_test_flag(check, ZAP_CHANNEL_OPEN)) {
status = check->zint->open(check);
status = check->zio->open(check);
if (status == ZAP_SUCCESS) {
zap_set_flag(check, ZAP_CHANNEL_OPEN);
*zchan = check;
}
}
zap_mutex_unlock(zint->spans[span_id].mutex);
zap_mutex_unlock(zio->spans[span_id].mutex);
}
return status;
@ -414,7 +414,7 @@ zap_status_t zap_channel_close(zap_channel_t **zchan)
zap_mutex_lock(check->span->mutex);
if (zap_test_flag(check, ZAP_CHANNEL_OPEN)) {
status = check->zint->close(check);
status = check->zio->close(check);
if (status == ZAP_SUCCESS) {
zap_channel_reset(check);
*zchan = NULL;
@ -464,7 +464,7 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo
zap_status_t status = ZAP_FAIL;
assert(zchan != NULL);
assert(zchan->zint != NULL);
assert(zchan->zio != NULL);
if (!zap_test_flag(zchan, ZAP_CHANNEL_OPEN)) {
snprintf(zchan->last_error, sizeof(zchan->last_error), "channel not open");
@ -623,12 +623,12 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo
break;
}
if (!zchan->zint->command) {
if (!zchan->zio->command) {
snprintf(zchan->last_error, sizeof(zchan->last_error), "method not implemented");
GOTO_STATUS(done, ZAP_FAIL);
}
status = zchan->zint->command(zchan, command, obj);
status = zchan->zio->command(zchan, command, obj);
done:
zap_mutex_unlock(zchan->span->mutex);
@ -639,24 +639,24 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo
zap_status_t zap_channel_wait(zap_channel_t *zchan, zap_wait_flag_t *flags, int32_t to)
{
assert(zchan != NULL);
assert(zchan->zint != NULL);
assert(zchan->zio != NULL);
if (!zap_test_flag(zchan, ZAP_CHANNEL_OPEN)) {
snprintf(zchan->last_error, sizeof(zchan->last_error), "channel not open");
return ZAP_FAIL;
}
if (!zchan->zint->wait) {
if (!zchan->zio->wait) {
snprintf(zchan->last_error, sizeof(zchan->last_error), "method not implemented");
return ZAP_FAIL;
}
return zchan->zint->wait(zchan, flags, to);
return zchan->zio->wait(zchan, flags, to);
}
/*******************************/
ZINT_CODEC_FUNCTION(zint_slin2ulaw)
ZIO_CODEC_FUNCTION(zio_slin2ulaw)
{
int16_t sln_buf[512] = {0}, *sln = sln_buf;
uint8_t *lp = data;
@ -680,7 +680,7 @@ ZINT_CODEC_FUNCTION(zint_slin2ulaw)
}
ZINT_CODEC_FUNCTION(zint_ulaw2slin)
ZIO_CODEC_FUNCTION(zio_ulaw2slin)
{
int16_t *sln = data;
uint8_t law[1024] = {0}, *lp = law;
@ -702,7 +702,7 @@ ZINT_CODEC_FUNCTION(zint_ulaw2slin)
return ZAP_SUCCESS;
}
ZINT_CODEC_FUNCTION(zint_slin2alaw)
ZIO_CODEC_FUNCTION(zio_slin2alaw)
{
int16_t sln_buf[512] = {0}, *sln = sln_buf;
uint8_t *lp = data;
@ -726,7 +726,7 @@ ZINT_CODEC_FUNCTION(zint_slin2alaw)
}
ZINT_CODEC_FUNCTION(zint_alaw2slin)
ZIO_CODEC_FUNCTION(zio_alaw2slin)
{
int16_t *sln = data;
uint8_t law[1024] = {0}, *lp = law;
@ -748,7 +748,7 @@ ZINT_CODEC_FUNCTION(zint_alaw2slin)
return ZAP_SUCCESS;
}
ZINT_CODEC_FUNCTION(zint_ulaw2alaw)
ZIO_CODEC_FUNCTION(zio_ulaw2alaw)
{
zap_size_t len = *datalen;
uint32_t i;
@ -766,7 +766,7 @@ ZINT_CODEC_FUNCTION(zint_ulaw2alaw)
return ZAP_SUCCESS;
}
ZINT_CODEC_FUNCTION(zint_alaw2ulaw)
ZIO_CODEC_FUNCTION(zio_alaw2ulaw)
{
zap_size_t len = *datalen;
uint32_t i;
@ -789,34 +789,34 @@ ZINT_CODEC_FUNCTION(zint_alaw2ulaw)
zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *datalen)
{
zap_status_t status = ZAP_FAIL;
zint_codec_t codec_func = NULL;
zio_codec_t codec_func = NULL;
zap_size_t max = *datalen;
assert(zchan != NULL);
assert(zchan->zint != NULL);
assert(zchan->zint != NULL);
assert(zchan->zio != NULL);
assert(zchan->zio != NULL);
if (!zap_test_flag(zchan, ZAP_CHANNEL_OPEN)) {
snprintf(zchan->last_error, sizeof(zchan->last_error), "channel not open");
return ZAP_FAIL;
}
if (!zchan->zint->read) {
if (!zchan->zio->read) {
snprintf(zchan->last_error, sizeof(zchan->last_error), "method not implemented");
return ZAP_FAIL;
}
status = zchan->zint->read(zchan, data, datalen);
status = zchan->zio->read(zchan, data, datalen);
if (status == ZAP_SUCCESS && zap_test_flag(zchan, ZAP_CHANNEL_TRANSCODE) && zchan->effective_codec != zchan->native_codec) {
if (zchan->native_codec == ZAP_CODEC_ULAW && zchan->effective_codec == ZAP_CODEC_SLIN) {
codec_func = zint_ulaw2slin;
codec_func = zio_ulaw2slin;
} else if (zchan->native_codec == ZAP_CODEC_ULAW && zchan->effective_codec == ZAP_CODEC_ALAW) {
codec_func = zint_ulaw2alaw;
codec_func = zio_ulaw2alaw;
} else if (zchan->native_codec == ZAP_CODEC_ALAW && zchan->effective_codec == ZAP_CODEC_SLIN) {
codec_func = zint_alaw2slin;
codec_func = zio_alaw2slin;
} else if (zchan->native_codec == ZAP_CODEC_ALAW && zchan->effective_codec == ZAP_CODEC_ULAW) {
codec_func = zint_alaw2ulaw;
codec_func = zio_alaw2ulaw;
}
if (codec_func) {
@ -861,7 +861,7 @@ zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *data
teletone_dtmf_detect(&zchan->dtmf_detect, sln, (int)slen);
teletone_dtmf_get(&zchan->dtmf_detect, digit_str, sizeof(digit_str));
if(digit_str[0]) {
zint_event_cb_t event_callback = NULL;
zio_event_cb_t event_callback = NULL;
if (zchan->span->event_callback) {
event_callback = zchan->span->event_callback;
} else if (zchan->event_callback) {
@ -892,31 +892,31 @@ zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *data
zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t *datalen)
{
zap_status_t status = ZAP_FAIL;
zint_codec_t codec_func = NULL;
zio_codec_t codec_func = NULL;
zap_size_t dtmf_blen, max = *datalen;
assert(zchan != NULL);
assert(zchan->zint != NULL);
assert(zchan->zio != NULL);
if (!zap_test_flag(zchan, ZAP_CHANNEL_OPEN)) {
snprintf(zchan->last_error, sizeof(zchan->last_error), "channel not open");
return ZAP_FAIL;
}
if (!zchan->zint->write) {
if (!zchan->zio->write) {
snprintf(zchan->last_error, sizeof(zchan->last_error), "method not implemented");
return ZAP_FAIL;
}
if (zap_test_flag(zchan, ZAP_CHANNEL_TRANSCODE) && zchan->effective_codec != zchan->native_codec) {
if (zchan->native_codec == ZAP_CODEC_ULAW && zchan->effective_codec == ZAP_CODEC_SLIN) {
codec_func = zint_slin2ulaw;
codec_func = zio_slin2ulaw;
} else if (zchan->native_codec == ZAP_CODEC_ULAW && zchan->effective_codec == ZAP_CODEC_ALAW) {
codec_func = zint_alaw2ulaw;
codec_func = zio_alaw2ulaw;
} else if (zchan->native_codec == ZAP_CODEC_ALAW && zchan->effective_codec == ZAP_CODEC_SLIN) {
codec_func = zint_slin2alaw;
codec_func = zio_slin2alaw;
} else if (zchan->native_codec == ZAP_CODEC_ALAW && zchan->effective_codec == ZAP_CODEC_ULAW) {
codec_func = zint_ulaw2alaw;
codec_func = zio_ulaw2alaw;
}
if (codec_func) {
@ -949,22 +949,22 @@ zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t *dat
if (zchan->native_codec != ZAP_CODEC_SLIN) {
if (zchan->native_codec == ZAP_CODEC_ULAW) {
*datalen = dlen;
zint_slin2ulaw(data, max, datalen);
zio_slin2ulaw(data, max, datalen);
} else if (zchan->native_codec == ZAP_CODEC_ALAW) {
*datalen = dlen;
zint_slin2alaw(data, max, datalen);
zio_slin2alaw(data, max, datalen);
}
}
}
status = zchan->zint->write(zchan, data, datalen);
status = zchan->zio->write(zchan, data, datalen);
return status;
}
static struct {
zap_software_interface_t *wanpipe_interface;
zap_software_interface_t *zt_interface;
zap_io_interface_t *wanpipe_interface;
zap_io_interface_t *zt_interface;
} interfaces;
zap_status_t zap_global_init(void)
@ -1013,14 +1013,14 @@ zap_status_t zap_global_init(void)
while (zap_config_next_pair(&cfg, &var, &val)) {
if (!strcasecmp(cfg.category, "openzap")) {
if (!strcmp(var, "load")) {
zap_software_interface_t *zint;
zap_io_interface_t *zio;
zap_mutex_lock(globals.mutex);
zint = (zap_software_interface_t *) hashtable_search(globals.interface_hash, val);
zio = (zap_io_interface_t *) hashtable_search(globals.interface_hash, val);
zap_mutex_unlock(globals.mutex);
if (zint) {
if (zint->configure(zint) == ZAP_SUCCESS) {
if (zio) {
if (zio->configure(zio) == ZAP_SUCCESS) {
configured++;
}
} else {

View File

@ -42,7 +42,7 @@ static struct {
unsigned codec_ms;
} wp_globals;
static zap_software_interface_t wanpipe_interface;
static zap_io_interface_t wanpipe_interface;
static zap_status_t wp_tdm_cmd_exec(zap_channel_t *zchan, wanpipe_tdm_api_t *tdm_api)
{
@ -146,7 +146,7 @@ static unsigned wp_configure_channel(zap_config_t *cfg, const char *str, zap_spa
return configured;
}
static ZINT_CONFIGURE_FUNCTION(wanpipe_configure)
static ZIO_CONFIGURE_FUNCTION(wanpipe_configure)
{
zap_config_t cfg;
char *var, *val;
@ -155,7 +155,7 @@ static ZINT_CONFIGURE_FUNCTION(wanpipe_configure)
int new_span = 0;
unsigned configured = 0, d = 0;
ZINT_CONFIGURE_MUZZLE;
ZIO_CONFIGURE_MUZZLE;
zap_log(ZAP_LOG_DEBUG, "configuring wanpipe\n");
if (!zap_config_open_file(&cfg, "wanpipe.conf")) {
@ -229,7 +229,7 @@ static ZINT_CONFIGURE_FUNCTION(wanpipe_configure)
return configured ? ZAP_SUCCESS : ZAP_FAIL;
}
static ZINT_OPEN_FUNCTION(wanpipe_open)
static ZIO_OPEN_FUNCTION(wanpipe_open)
{
wanpipe_tdm_api_t tdm_api;
@ -259,18 +259,18 @@ static ZINT_OPEN_FUNCTION(wanpipe_open)
return ZAP_SUCCESS;
}
static ZINT_CLOSE_FUNCTION(wanpipe_close)
static ZIO_CLOSE_FUNCTION(wanpipe_close)
{
ZINT_CLOSE_MUZZLE;
ZIO_CLOSE_MUZZLE;
return ZAP_SUCCESS;
}
static ZINT_COMMAND_FUNCTION(wanpipe_command)
static ZIO_COMMAND_FUNCTION(wanpipe_command)
{
wanpipe_tdm_api_t tdm_api;
int err = 0;
ZINT_COMMAND_MUZZLE;
ZIO_COMMAND_MUZZLE;
memset(&tdm_api, 0, sizeof(tdm_api));
@ -306,7 +306,7 @@ static ZINT_COMMAND_FUNCTION(wanpipe_command)
return ZAP_SUCCESS;
}
static ZINT_READ_FUNCTION(wanpipe_read)
static ZIO_READ_FUNCTION(wanpipe_read)
{
int rx_len = 0;
wp_tdm_api_rx_hdr_t hdrframe;
@ -325,7 +325,7 @@ static ZINT_READ_FUNCTION(wanpipe_read)
return ZAP_SUCCESS;
}
static ZINT_WRITE_FUNCTION(wanpipe_write)
static ZIO_WRITE_FUNCTION(wanpipe_write)
{
int bsent;
wp_tdm_api_tx_hdr_t hdrframe;
@ -344,7 +344,7 @@ static ZINT_WRITE_FUNCTION(wanpipe_write)
}
static ZINT_WAIT_FUNCTION(wanpipe_wait)
static ZIO_WAIT_FUNCTION(wanpipe_wait)
{
int32_t inflags = 0;
int result;
@ -389,9 +389,9 @@ static ZINT_WAIT_FUNCTION(wanpipe_wait)
return ZAP_SUCCESS;
}
zap_status_t wanpipe_init(zap_software_interface_t **zint)
zap_status_t wanpipe_init(zap_io_interface_t **zio)
{
assert(zint != NULL);
assert(zio != NULL);
memset(&wanpipe_interface, 0, sizeof(wanpipe_interface));
wp_globals.codec_ms = 20;
@ -403,7 +403,7 @@ zap_status_t wanpipe_init(zap_software_interface_t **zint)
wanpipe_interface.wait = wanpipe_wait;
wanpipe_interface.read = wanpipe_read;
wanpipe_interface.write = wanpipe_write;
*zint = &wanpipe_interface;
*zio = &wanpipe_interface;
return ZAP_SUCCESS;
}