mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-04-17 17:22:21 +00:00
tweak fifo
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@8012 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
bc02db94ea
commit
85b79c083a
@ -76,6 +76,28 @@ static switch_status_t on_dtmf(switch_core_session_t *session, void *input, swit
|
|||||||
return SWITCH_STATUS_SUCCESS;
|
return SWITCH_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static switch_status_t moh_on_dtmf(switch_core_session_t *session, void *input, switch_input_type_t itype, void *buf, unsigned int buflen)
|
||||||
|
{
|
||||||
|
|
||||||
|
switch (itype) {
|
||||||
|
case SWITCH_INPUT_TYPE_DTMF:
|
||||||
|
{
|
||||||
|
switch_dtmf_t *dtmf = (switch_dtmf_t *) input;
|
||||||
|
if (dtmf->digit == '*') {
|
||||||
|
char *bp = buf;
|
||||||
|
*bp = dtmf->digit;
|
||||||
|
return SWITCH_STATUS_BREAK;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return SWITCH_STATUS_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
#define check_string(s) if (!switch_strlen_zero(s) && !strcasecmp(s, "undef")) { s = NULL; }
|
#define check_string(s) if (!switch_strlen_zero(s) && !strcasecmp(s, "undef")) { s = NULL; }
|
||||||
|
|
||||||
static switch_status_t read_frame_callback(switch_core_session_t *session, switch_frame_t *frame, void *user_data)
|
static switch_status_t read_frame_callback(switch_core_session_t *session, switch_frame_t *frame, void *user_data)
|
||||||
@ -206,6 +228,7 @@ SWITCH_STANDARD_APP(fifo_function)
|
|||||||
switch_time_exp_t tm;
|
switch_time_exp_t tm;
|
||||||
switch_time_t ts = switch_timestamp_now();
|
switch_time_t ts = switch_timestamp_now();
|
||||||
switch_size_t retsize;
|
switch_size_t retsize;
|
||||||
|
const char *serviced_uuid = NULL;
|
||||||
|
|
||||||
if (!globals.running) {
|
if (!globals.running) {
|
||||||
return;
|
return;
|
||||||
@ -233,9 +256,12 @@ SWITCH_STANDARD_APP(fifo_function)
|
|||||||
announce = switch_channel_get_variable(channel, "fifo_announce");
|
announce = switch_channel_get_variable(channel, "fifo_announce");
|
||||||
|
|
||||||
if (!strcasecmp(argv[1], "in")) {
|
if (!strcasecmp(argv[1], "in")) {
|
||||||
|
switch_core_session_t *other_session;
|
||||||
|
switch_channel_t *other_channel;
|
||||||
const char *uuid = strdup(switch_core_session_get_uuid(session));
|
const char *uuid = strdup(switch_core_session_get_uuid(session));
|
||||||
const char *pri;
|
const char *pri;
|
||||||
int p = 0;
|
int p = 0;
|
||||||
|
int aborted = 0;
|
||||||
|
|
||||||
switch_channel_answer(channel);
|
switch_channel_answer(channel);
|
||||||
|
|
||||||
@ -250,12 +276,6 @@ SWITCH_STANDARD_APP(fifo_function)
|
|||||||
check_string(announce);
|
check_string(announce);
|
||||||
check_string(moh);
|
check_string(moh);
|
||||||
|
|
||||||
if (moh) {
|
|
||||||
switch_ivr_broadcast(uuid, moh, SMF_LOOP | SMF_ECHO_ALEG);
|
|
||||||
}
|
|
||||||
|
|
||||||
switch_channel_set_flag(channel, CF_TAGGED);
|
|
||||||
|
|
||||||
switch_mutex_lock(node->mutex);
|
switch_mutex_lock(node->mutex);
|
||||||
node->caller_count++;
|
node->caller_count++;
|
||||||
node->waiting_count++;
|
node->waiting_count++;
|
||||||
@ -287,7 +307,45 @@ SWITCH_STANDARD_APP(fifo_function)
|
|||||||
switch_event_fire(&event);
|
switch_event_fire(&event);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch_ivr_park(session, NULL);
|
switch_channel_set_flag(channel, CF_TAGGED);
|
||||||
|
|
||||||
|
while(switch_channel_ready(channel)) {
|
||||||
|
switch_input_args_t args = { 0 };
|
||||||
|
char buf[25] = "";
|
||||||
|
args.input_callback = moh_on_dtmf;
|
||||||
|
args.buf = buf;
|
||||||
|
args.buflen = sizeof(buf);
|
||||||
|
|
||||||
|
|
||||||
|
if ((serviced_uuid = switch_channel_get_variable(channel, "fifo_serviced_uuid"))) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (moh) {
|
||||||
|
switch_ivr_play_file(session, NULL, moh, &args);
|
||||||
|
} else {
|
||||||
|
switch_ivr_collect_digits_callback(session, &args, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (*buf == '*') {
|
||||||
|
aborted = 1;
|
||||||
|
goto abort;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!serviced_uuid && switch_channel_ready(channel)) {
|
||||||
|
switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
|
||||||
|
} else if ((other_session = switch_core_session_locate(serviced_uuid))) {
|
||||||
|
int ready;
|
||||||
|
other_channel = switch_core_session_get_channel(other_session);
|
||||||
|
ready = switch_channel_ready(other_channel);
|
||||||
|
switch_core_session_rwunlock(other_session);
|
||||||
|
if (!ready) {
|
||||||
|
switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (switch_channel_ready(channel)) {
|
if (switch_channel_ready(channel)) {
|
||||||
if (announce) {
|
if (announce) {
|
||||||
@ -297,7 +355,9 @@ SWITCH_STANDARD_APP(fifo_function)
|
|||||||
|
|
||||||
switch_channel_clear_flag(channel, CF_TAGGED);
|
switch_channel_clear_flag(channel, CF_TAGGED);
|
||||||
|
|
||||||
if (switch_channel_ready(channel)) {
|
abort:
|
||||||
|
|
||||||
|
if (!aborted && switch_channel_ready(channel)) {
|
||||||
switch_channel_set_state(channel, CS_HIBERNATE);
|
switch_channel_set_state(channel, CS_HIBERNATE);
|
||||||
} else {
|
} else {
|
||||||
ts = switch_timestamp_now();
|
ts = switch_timestamp_now();
|
||||||
@ -335,9 +395,14 @@ SWITCH_STANDARD_APP(fifo_function)
|
|||||||
char *pop_list[MAX_PRI] = { 0 };
|
char *pop_list[MAX_PRI] = { 0 };
|
||||||
const char *fifo_consumer_wrapup_sound = NULL;
|
const char *fifo_consumer_wrapup_sound = NULL;
|
||||||
const char *fifo_consumer_wrapup_key = NULL;
|
const char *fifo_consumer_wrapup_key = NULL;
|
||||||
|
const char *my_id;
|
||||||
char buf[5] = "";
|
char buf[5] = "";
|
||||||
|
|
||||||
|
|
||||||
|
if (!(my_id = switch_channel_get_variable(channel, "fifo_consumer_id"))) {
|
||||||
|
my_id = switch_core_session_get_uuid(session);
|
||||||
|
}
|
||||||
|
|
||||||
if (argc > 2) {
|
if (argc > 2) {
|
||||||
if (!strcasecmp(argv[2], "nowait")) {
|
if (!strcasecmp(argv[2], "nowait")) {
|
||||||
nowait++;
|
nowait++;
|
||||||
@ -457,23 +522,34 @@ SWITCH_STANDARD_APP(fifo_function)
|
|||||||
|
|
||||||
if (announce) {
|
if (announce) {
|
||||||
switch_ivr_play_file(session, NULL, announce, NULL);
|
switch_ivr_play_file(session, NULL, announce, NULL);
|
||||||
|
} else {
|
||||||
|
const char *o_announce = switch_channel_get_variable(other_channel, "fifo_override_announce");
|
||||||
|
if (o_announce) {
|
||||||
|
switch_ivr_play_file(session, NULL, o_announce, NULL);
|
||||||
} else {
|
} else {
|
||||||
switch_ivr_sleep(session, 500);
|
switch_ivr_sleep(session, 500);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (switch_channel_test_flag(other_channel, CF_TAGGED)) {
|
|
||||||
switch_channel_clear_flag(other_channel, CF_CONTROLLED);
|
switch_channel_set_variable(other_channel, "fifo_serviced_by", my_id);
|
||||||
switch_core_session_flush_private_events(other_session);
|
switch_channel_set_variable(other_channel, "fifo_serviced_uuid", switch_core_session_get_uuid(session));
|
||||||
switch_channel_stop_broadcast(other_channel);
|
switch_channel_set_flag(other_channel, CF_BREAK);
|
||||||
switch_core_session_kill_channel(other_session, SWITCH_SIG_BREAK);
|
|
||||||
while (switch_channel_test_flag(other_channel, CF_TAGGED)) {
|
while (switch_channel_ready(channel) && switch_channel_ready(other_channel) && switch_channel_test_flag(other_channel, CF_TAGGED)) {
|
||||||
status = switch_core_session_read_frame(session, &read_frame, -1, 0);
|
status = switch_core_session_read_frame(session, &read_frame, -1, 0);
|
||||||
if (!SWITCH_READ_ACCEPTABLE(status)) {
|
if (!SWITCH_READ_ACCEPTABLE(status)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!(switch_channel_ready(channel))) {
|
||||||
|
switch_channel_hangup(other_channel, SWITCH_CAUSE_NORMAL_CLEARING);
|
||||||
|
switch_core_session_rwunlock(other_session);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
switch_channel_answer(channel);
|
switch_channel_answer(channel);
|
||||||
cloned_profile = switch_caller_profile_clone(other_session, switch_channel_get_caller_profile(channel));
|
cloned_profile = switch_caller_profile_clone(other_session, switch_channel_get_caller_profile(channel));
|
||||||
switch_assert(cloned_profile);
|
switch_assert(cloned_profile);
|
||||||
|
@ -576,6 +576,12 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_collect_digits_callback(switch_core_s
|
|||||||
switch_event_t *event;
|
switch_event_t *event;
|
||||||
switch_dtmf_t dtmf = {0};
|
switch_dtmf_t dtmf = {0};
|
||||||
|
|
||||||
|
if (switch_channel_test_flag(channel, CF_BREAK)) {
|
||||||
|
switch_channel_clear_flag(channel, CF_BREAK);
|
||||||
|
status = SWITCH_STATUS_BREAK;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (timeout) {
|
if (timeout) {
|
||||||
elapsed = (uint32_t) ((switch_timestamp_now() - started) / 1000);
|
elapsed = (uint32_t) ((switch_timestamp_now() - started) / 1000);
|
||||||
if (elapsed >= timeout) {
|
if (elapsed >= timeout) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user