git-svn-id: http://svn.openzap.org/svn/openzap/trunk@187 a93c3328-9c30-0410-af19-c9cd2b2d52af
This commit is contained in:
Anthony Minessale 2007-05-31 03:04:26 +00:00
parent a2dea73797
commit 65228c6815
4 changed files with 78 additions and 24 deletions

View File

@ -49,11 +49,10 @@ static struct span_config SPAN_CONFIG[ZAP_MAX_SPANS_INTERFACE] = {0};
typedef enum { typedef enum {
TFLAG_IO = (1 << 0), TFLAG_IO = (1 << 0),
TFLAG_OUTBOUND = (1 << 1), TFLAG_DTMF = (1 << 1),
TFLAG_DTMF = (1 << 2), TFLAG_CODEC = (1 << 2),
TFLAG_CODEC = (1 << 3), TFLAG_BREAK = (1 << 3),
TFLAG_BREAK = (1 << 4), TFLAG_HOLD = (1 << 4)
TFLAG_HOLD = (1 << 5)
} TFLAGS; } TFLAGS;
static struct { static struct {
@ -540,6 +539,33 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi
switch_caller_profile_t *outbound_profile, switch_caller_profile_t *outbound_profile,
switch_core_session_t **new_session, switch_memory_pool_t **pool) switch_core_session_t **new_session, switch_memory_pool_t **pool)
{ {
char *dest;
int span_id = 0;
zap_channel_t *zchan = NULL;
switch_call_cause_t cause = SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
char name[128];
if (!outbound_profile) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing caller profile\n");
return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
}
if ((dest = strchr('/', outbound_profile->destination_number))) {
dest++;
span_id = atoi(outbound_profile->destination_number);
}
if (!span_id) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing span\n");
return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
}
if (zap_channel_open_any(span_id, ZAP_TOP_DOWN, &zchan) != ZAP_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No channels available\n");
return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
}
if ((*new_session = switch_core_session_request(&channel_endpoint_interface, pool)) != 0) { if ((*new_session = switch_core_session_request(&channel_endpoint_interface, pool)) != 0) {
private_t *tech_pvt; private_t *tech_pvt;
switch_channel_t *channel; switch_channel_t *channel;
@ -548,36 +574,33 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi
switch_core_session_add_stream(*new_session, NULL); switch_core_session_add_stream(*new_session, NULL);
if ((tech_pvt = (private_t *) switch_core_session_alloc(*new_session, sizeof(private_t))) != 0) { if ((tech_pvt = (private_t *) switch_core_session_alloc(*new_session, sizeof(private_t))) != 0) {
channel = switch_core_session_get_channel(*new_session); channel = switch_core_session_get_channel(*new_session);
tech_init(tech_pvt, *new_session, NULL); tech_init(tech_pvt, *new_session, zchan);
} else { } else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Hey where is my memory pool?\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Hey where is my memory pool?\n");
switch_core_session_destroy(new_session); switch_core_session_destroy(new_session);
return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; cause = SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
} goto fail;
if (outbound_profile) {
char name[128];
snprintf(name, sizeof(name), "OPENZAP/%s-%04x", outbound_profile->destination_number, rand() & 0xffff);
switch_channel_set_name(channel, name);
caller_profile = switch_caller_profile_clone(*new_session, outbound_profile);
switch_channel_set_caller_profile(channel, caller_profile);
tech_pvt->caller_profile = caller_profile;
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Doh! no caller profile\n");
switch_core_session_destroy(new_session);
return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
} }
snprintf(name, sizeof(name), "OPENZAP/%s", outbound_profile->destination_number);
switch_channel_set_name(channel, name);
caller_profile = switch_caller_profile_clone(*new_session, outbound_profile);
switch_channel_set_caller_profile(channel, caller_profile);
tech_pvt->caller_profile = caller_profile;
switch_channel_set_flag(channel, CF_OUTBOUND); switch_channel_set_flag(channel, CF_OUTBOUND);
switch_set_flag_locked(tech_pvt, TFLAG_OUTBOUND);
switch_channel_set_state(channel, CS_INIT); switch_channel_set_state(channel, CS_INIT);
return SWITCH_CAUSE_SUCCESS; return SWITCH_CAUSE_SUCCESS;
} }
return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
fail:
if (zchan) {
zap_channel_done(zchan);
}
return cause;
} }

View File

@ -346,6 +346,8 @@ zap_status_t zap_channel_open(uint32_t span_id, uint32_t chan_id, zap_channel_t
zap_status_t zap_channel_open_chan(zap_channel_t *zchan); zap_status_t zap_channel_open_chan(zap_channel_t *zchan);
zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, zap_channel_t **zchan); zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, zap_channel_t **zchan);
zap_status_t zap_channel_close(zap_channel_t **zchan); zap_status_t zap_channel_close(zap_channel_t **zchan);
zap_status_t zap_channel_done(zap_channel_t *zchan);
zap_status_t zap_channel_use(zap_channel_t *zchan);
zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, void *obj); zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, void *obj);
zap_status_t zap_channel_wait(zap_channel_t *zchan, zap_wait_flag_t *flags, int32_t to); zap_status_t zap_channel_wait(zap_channel_t *zchan, zap_wait_flag_t *flags, int32_t to);
zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *datalen); zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *datalen);

View File

@ -167,6 +167,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj)
break; break;
case ZAP_CHANNEL_STATE_DOWN: case ZAP_CHANNEL_STATE_DOWN:
{ {
zap_channel_done(chan);
goto done; goto done;
} }
break; break;
@ -180,6 +181,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj)
switch(chan->state) { switch(chan->state) {
case ZAP_CHANNEL_STATE_UP: case ZAP_CHANNEL_STATE_UP:
{ {
zap_channel_use(chan);
if (zap_test_flag(chan, ZAP_CHANNEL_HOLD)) { if (zap_test_flag(chan, ZAP_CHANNEL_HOLD)) {
zap_clear_flag(chan, ZAP_CHANNEL_HOLD); zap_clear_flag(chan, ZAP_CHANNEL_HOLD);
sig.event_id = ZAP_SIGEVENT_FLASH; sig.event_id = ZAP_SIGEVENT_FLASH;
@ -193,6 +195,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj)
break; break;
case ZAP_CHANNEL_STATE_IDLE: case ZAP_CHANNEL_STATE_IDLE:
{ {
zap_channel_use(chan);
sig.event_id = ZAP_SIGEVENT_START; sig.event_id = ZAP_SIGEVENT_START;
zap_copy_string(sig.dnis, dtmf, sizeof(sig.dnis)); zap_copy_string(sig.dnis, dtmf, sizeof(sig.dnis));
data->sig_cb(&sig); data->sig_cb(&sig);
@ -201,6 +204,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj)
break; break;
case ZAP_CHANNEL_STATE_DOWN: case ZAP_CHANNEL_STATE_DOWN:
{ {
zap_channel_done(chan);
sig.event_id = ZAP_SIGEVENT_STOP; sig.event_id = ZAP_SIGEVENT_STOP;
data->sig_cb(&sig); data->sig_cb(&sig);
goto done; goto done;
@ -208,6 +212,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj)
break; break;
case ZAP_CHANNEL_STATE_DIALTONE: case ZAP_CHANNEL_STATE_DIALTONE:
{ {
zap_channel_done(chan);
*dtmf = '\0'; *dtmf = '\0';
dtmf_offset = 0; dtmf_offset = 0;
zap_buffer_zero(dt_buffer); zap_buffer_zero(dt_buffer);
@ -217,6 +222,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj)
break; break;
case ZAP_CHANNEL_STATE_RING: case ZAP_CHANNEL_STATE_RING:
{ {
zap_channel_done(chan);
zap_buffer_zero(dt_buffer); zap_buffer_zero(dt_buffer);
teletone_run(&ts, chan->span->tone_map[ZAP_TONEMAP_RING]); teletone_run(&ts, chan->span->tone_map[ZAP_TONEMAP_RING]);
indicate = 1; indicate = 1;
@ -224,6 +230,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj)
break; break;
case ZAP_CHANNEL_STATE_BUSY: case ZAP_CHANNEL_STATE_BUSY:
{ {
zap_channel_done(chan);
zap_buffer_zero(dt_buffer); zap_buffer_zero(dt_buffer);
teletone_run(&ts, chan->span->tone_map[ZAP_TONEMAP_BUSY]); teletone_run(&ts, chan->span->tone_map[ZAP_TONEMAP_BUSY]);
indicate = 1; indicate = 1;
@ -231,12 +238,14 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj)
break; break;
case ZAP_CHANNEL_STATE_ATTN: case ZAP_CHANNEL_STATE_ATTN:
{ {
zap_channel_done(chan);
zap_buffer_zero(dt_buffer); zap_buffer_zero(dt_buffer);
teletone_run(&ts, chan->span->tone_map[ZAP_TONEMAP_ATTN]); teletone_run(&ts, chan->span->tone_map[ZAP_TONEMAP_ATTN]);
indicate = 1; indicate = 1;
} }
break; break;
default: default:
zap_channel_done(chan);
break; break;
} }
} }

View File

@ -644,6 +644,26 @@ zap_status_t zap_channel_open(uint32_t span_id, uint32_t chan_id, zap_channel_t
return status; return status;
} }
zap_status_t zap_channel_done(zap_channel_t *zchan)
{
assert(zchan != NULL);
zap_clear_flag_locked(zchan, ZAP_CHANNEL_INUSE);
return ZAP_SUCCESS;
}
zap_status_t zap_channel_use(zap_channel_t *zchan)
{
assert(zchan != NULL);
zap_set_flag_locked(zchan, ZAP_CHANNEL_INUSE);
return ZAP_SUCCESS;
}
zap_status_t zap_channel_close(zap_channel_t **zchan) zap_status_t zap_channel_close(zap_channel_t **zchan)
{ {
zap_channel_t *check; zap_channel_t *check;