ZAP_TRUNK_T1,
ZAP_TRUNK_J1,
ZAP_TRUNK_BRI,
+ ZAP_TRUNK_FXO,
+ ZAP_TRUNK_FXS,
ZAP_TRUNK_NONE
} zap_trunk_type_t;
-#define TRUNK_STRINGS "E1", "T1", "J1", "BRI", "NONE"
+#define TRUNK_STRINGS "E1", "T1", "J1", "BRI", "FXO", "FXS", "NONE"
ZAP_STR2ENUM_P(zap_str2zap_trunk_type, zap_trunk_type2str, zap_trunk_type_t)
typedef enum {
zap_size_t len;
- sleep(5);
+ sleep(10);
- printf("answer call\n");
+ zap_log(ZAP_LOG_DEBUG, "answer call and start echo test\n");
zap_set_state_locked(chan, ZAP_CHANNEL_STATE_UP);
len = sizeof(frame);
if (flags & ZAP_READ) {
if (zap_channel_read(chan, frame, &len) == ZAP_SUCCESS) {
- //printf("WRITE %d\n", len);
+ //zap_log(ZAP_LOG_DEBUG, "WRITE %d\n", len);
zap_channel_write(chan, frame, &len);
} else {
break;
zap_set_state_locked(chan, ZAP_CHANNEL_STATE_BUSY);
}
- printf("call over\n");
+ zap_log(ZAP_LOG_DEBUG, "call over\n");
}
static ZIO_SIGNAL_CB_FUNCTION(on_signal)
{
- printf("got sig [%s]\n", zap_signal_event2str(sigmsg->event_id));
+ zap_log(ZAP_LOG_DEBUG, "got sig [%s]\n", zap_signal_event2str(sigmsg->event_id));
switch(sigmsg->event_id) {
case ZAP_SIGEVENT_START:
zap_set_state_locked(sigmsg->channel, ZAP_CHANNEL_STATE_RING);
- printf("launching thread and indicating ring\n");
+ zap_log(ZAP_LOG_DEBUG, "launching thread and indicating ring\n");
zap_thread_create_detached(test_call, sigmsg->channel);
break;
default:
zap_global_set_default_logger(ZAP_LOG_LEVEL_DEBUG);
if (zap_global_init() != ZAP_SUCCESS) {
- fprintf(stderr, "Error loading OpenZAP\n");
+ zap_log(ZAP_LOG_ERROR, "Error loading OpenZAP\n");
exit(-1);
}
- printf("OpenZAP loaded\n");
+ zap_log(ZAP_LOG_DEBUG, "OpenZAP loaded\n");
if (zap_span_find("wanpipe", 1, &span) != ZAP_SUCCESS) {
- fprintf(stderr, "Error finding OpenZAP span\n");
+ zap_log(ZAP_LOG_ERROR, "Error finding OpenZAP span\n");
}
-
zap_analog_configure_span(span, "us", 2000, 11, on_signal);
zap_analog_start(span);
}
zap_set_flag_locked(chan, ZAP_CHANNEL_INTHREAD);
-
-
-
teletone_init_session(&ts, 0, teletone_handler, dt_buffer);
-#if 0
- ts.debug = 1;
- ts.debug_stream = stdout;
-#endif
ts.rate = 8000;
zap_channel_command(chan, ZAP_COMMAND_GET_CODEC, &old_codec);
zap_channel_command(chan, ZAP_COMMAND_GET_INTERVAL, &interval);
-
zap_buffer_set_loops(dt_buffer, -1);
while (zap_test_flag(chan, ZAP_CHANNEL_INTHREAD)) {
elapsed += interval;
state_counter += interval;
- XX printf("WTF %s %s\n", zap_channel_state2str(chan->state), zap_channel_state2str(chan->last_state));
+
if (!zap_test_flag(chan, ZAP_CHANNEL_STATE_CHANGE)) {
switch(chan->state) {
case ZAP_CHANNEL_STATE_DIALTONE:
case ZAP_CHANNEL_STATE_UP:
case ZAP_CHANNEL_STATE_IDLE:
{
- zap_sleep(interval * 1000);
+ zap_sleep(interval);
+ continue;
}
break;
default:
zap_copy_string(new_span->tone_map[ZAP_TONEMAP_RING], "%(2000,4000,440,480)", ZAP_TONEMAP_LEN);
zap_copy_string(new_span->tone_map[ZAP_TONEMAP_BUSY], "%(500,500,480,620)", ZAP_TONEMAP_LEN);
zap_copy_string(new_span->tone_map[ZAP_TONEMAP_ATTN], "%(100,100,1400,2060,2450,2600)", ZAP_TONEMAP_LEN);
+ new_span->trunk_type = ZAP_TRUNK_NONE;
*span = new_span;
return ZAP_SUCCESS;
}
zap_status_t zap_channel_set_event_callback(zap_channel_t *zchan, zio_event_cb_t event_callback)
{
- zap_mutex_lock(zchan->span->mutex);
+ zap_mutex_lock(zchan->mutex);
zchan->event_callback = event_callback;
- zap_mutex_unlock(zchan->span->mutex);
+ zap_mutex_unlock(zchan->mutex);
return ZAP_SUCCESS;
}
zap_status_t zap_channel_open_chan(zap_channel_t *zchan)
{
zap_status_t status = ZAP_FAIL;
-
- zap_mutex_lock(zchan->span->mutex);
+
+ if ((status = zap_mutex_trylock(zchan->mutex)) != ZAP_SUCCESS) {
+ return status;
+ }
if (zap_test_flag(zchan, ZAP_CHANNEL_READY) && ! zap_test_flag(zchan, ZAP_CHANNEL_OPEN)) {
status = zchan->span->zio->open(zchan);
if (status == ZAP_SUCCESS) {
zap_set_flag(zchan, ZAP_CHANNEL_OPEN);
}
}
- zap_mutex_unlock(zchan->span->mutex);
+ zap_mutex_unlock(zchan->mutex);
return status;
}
if (span_id < ZAP_MAX_SPANS_INTERFACE && chan_id < ZAP_MAX_CHANNELS_SPAN && zio) {
zap_channel_t *check;
- zap_mutex_lock(zio->spans[span_id].mutex);
+
check = &zio->spans[span_id].channels[chan_id];
-
+ if ((status = zap_mutex_trylock(check->mutex)) != ZAP_SUCCESS) {
+ return status;
+ }
+
if (zap_test_flag(check, ZAP_CHANNEL_READY) && ! zap_test_flag(check, ZAP_CHANNEL_OPEN)) {
status = check->zio->open(check);
if (status == ZAP_SUCCESS) {
*zchan = check;
}
}
- zap_mutex_unlock(zio->spans[span_id].mutex);
+ zap_mutex_unlock(check->mutex);
}
return status;
assert(check != NULL);
*zchan = NULL;
- zap_mutex_lock(check->span->mutex);
+ zap_mutex_lock(check->mutex);
if (zap_test_flag(check, ZAP_CHANNEL_OPEN)) {
status = check->zio->close(check);
if (status == ZAP_SUCCESS) {
}
}
- zap_mutex_unlock(check->span->mutex);
+ zap_mutex_unlock(check->mutex);
return status;
}
return ZAP_FAIL;
}
- zap_mutex_lock(zchan->span->mutex);
+ zap_mutex_lock(zchan->mutex);
switch(command) {
case ZAP_COMMAND_SET_INTERVAL:
status = zchan->zio->command(zchan, command, obj);
done:
- zap_mutex_unlock(zchan->span->mutex);
+ zap_mutex_unlock(zchan->mutex);
return status;
}
span->trunk_type = zap_str2zap_trunk_type(val);
zap_log(ZAP_LOG_DEBUG, "setting trunk type to '%s'\n", zap_trunk_type2str(span->trunk_type));
} else if (!strcasecmp(var, "fxo-channel")) {
- configured += wp_configure_channel(&cfg, val, span, ZAP_CHAN_TYPE_FXO);
+ if (span->trunk_type == ZAP_TRUNK_NONE) {
+ span->trunk_type = ZAP_TRUNK_FXO;
+ zap_log(ZAP_LOG_DEBUG, "setting trunk type to '%s'\n", zap_trunk_type2str(span->trunk_type));
+ }
+ if (span->trunk_type == ZAP_TRUNK_FXO) {
+ configured += wp_configure_channel(&cfg, val, span, ZAP_CHAN_TYPE_FXO);
+ } else {
+ zap_log(ZAP_LOG_WARNING, "Cannot add FXO channels to an FXS trunk!\n");
+ }
} else if (!strcasecmp(var, "fxs-channel")) {
- configured += wp_configure_channel(&cfg, val, span, ZAP_CHAN_TYPE_FXS);
+ if (span->trunk_type == ZAP_TRUNK_NONE) {
+ span->trunk_type = ZAP_TRUNK_FXS;
+ zap_log(ZAP_LOG_DEBUG, "setting trunk type to '%s'\n", zap_trunk_type2str(span->trunk_type));
+ }
+ if (span->trunk_type == ZAP_TRUNK_FXS) {
+ configured += wp_configure_channel(&cfg, val, span, ZAP_CHAN_TYPE_FXS);
+ } else {
+ zap_log(ZAP_LOG_WARNING, "Cannot add FXS channels to an FXO trunk!\n");
+ }
} else if (!strcasecmp(var, "b-channel")) {
configured += wp_configure_channel(&cfg, val, span, ZAP_CHAN_TYPE_B);
} else if (!strcasecmp(var, "d-channel")) {