add a few things to mod_fifo

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@5776 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale 2007-10-02 00:03:53 +00:00
parent 335bff8646
commit c22d70e76f
2 changed files with 122 additions and 13 deletions

View File

@ -1,2 +1,2 @@
BASE=../../../.. BASE=../../../..
include /usr/src/freeswitch.trunk/build/modmake.rules include $(BASE)/build/modmake.rules

View File

@ -24,8 +24,6 @@
* Contributor(s): * Contributor(s):
* *
* Anthony Minessale II <anthmct@yahoo.com> * Anthony Minessale II <anthmct@yahoo.com>
* Neal Horman <neal at wanlink dot com>
*
* *
* mod_fifo.c -- FIFO * mod_fifo.c -- FIFO
* *
@ -36,20 +34,66 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_fifo_shutdown);
SWITCH_MODULE_LOAD_FUNCTION(mod_fifo_load); SWITCH_MODULE_LOAD_FUNCTION(mod_fifo_load);
SWITCH_MODULE_DEFINITION(mod_fifo, mod_fifo_load, mod_fifo_shutdown, NULL); SWITCH_MODULE_DEFINITION(mod_fifo, mod_fifo_load, mod_fifo_shutdown, NULL);
static switch_status_t on_dtmf(switch_core_session_t *session, void *input, switch_input_type_t itype, void *buf, unsigned int buflen)
{
switch_core_session_t *bleg;
switch_channel_t *channel;
bleg = (switch_core_session_t *) buf;
switch (itype) {
case SWITCH_INPUT_TYPE_DTMF:
{
char *dtmf = (char *) input;
if (*dtmf == '*') {
channel = switch_core_session_get_channel(session);
if (switch_channel_test_flag(channel, CF_ORIGINATOR)) {
channel = switch_core_session_get_channel(bleg);
switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
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; }
static switch_status_t read_frame_callback(switch_core_session_t *session, switch_frame_t *frame, void *user_data)
{
switch_queue_t *fifo = (switch_queue_t *) user_data;
if (switch_queue_size(fifo)) {
return SWITCH_STATUS_FALSE;
}
return SWITCH_STATUS_SUCCESS;
}
static struct { static struct {
switch_hash_t *fifo_hash; switch_hash_t *fifo_hash;
switch_memory_pool_t *pool; switch_memory_pool_t *pool;
} globals; } globals;
#define FIFO_DESC "Fifo for stacking parked calls." #define FIFO_DESC "Fifo for stacking parked calls."
#define FIFO_USAGE "<fifo name> [in <file> | out [nowait]]" #define FIFO_USAGE "<fifo name> [in [<announce file>|undef] [<music file>|undef] | out [wait|nowait] [<announce file>|undef] [<music file>|undef]]"
SWITCH_STANDARD_APP(fifo_function) SWITCH_STANDARD_APP(fifo_function)
{ {
int argc; int argc;
char *mydata = NULL, *argv[4] = { 0 }; char *mydata = NULL, *argv[5] = { 0 };
switch_queue_t *fifo; switch_queue_t *fifo;
switch_channel_t *channel; switch_channel_t *channel;
int nowait = 0; int nowait = 0;
char *moh = NULL;
char *announce = NULL;
if (switch_strlen_zero(data)) { if (switch_strlen_zero(data)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No Args\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No Args\n");
@ -70,7 +114,8 @@ SWITCH_STANDARD_APP(fifo_function)
} }
channel = switch_core_session_get_channel(session); channel = switch_core_session_get_channel(session);
moh = switch_channel_get_variable(channel, "fifo_music");
announce = switch_channel_get_variable(channel, "fifo_announce");
if (argc > 2) { if (argc > 2) {
nowait = !strcasecmp(argv[2], "nowait"); nowait = !strcasecmp(argv[2], "nowait");
@ -78,22 +123,42 @@ SWITCH_STANDARD_APP(fifo_function)
if (!strcasecmp(argv[1], "in")) { if (!strcasecmp(argv[1], "in")) {
char *uuid = strdup(switch_core_session_get_uuid(session)); char *uuid = strdup(switch_core_session_get_uuid(session));
char *moh = NULL;
switch_channel_answer(channel); switch_channel_answer(channel);
moh = switch_channel_get_variable(channel, "fifo_music");
if (argc > 2) { if (argc > 2) {
moh = argv[2]; announce = argv[2];
} }
if (argc > 3) {
moh = argv[3];
}
check_string(announce);
check_string(moh);
if (moh) { if (moh) {
switch_ivr_broadcast(uuid, moh, SMF_LOOP | SMF_ECHO_ALEG); switch_ivr_broadcast(uuid, moh, SMF_LOOP | SMF_ECHO_ALEG);
} }
switch_channel_set_flag(channel, CF_TAGGED);
switch_queue_push(fifo, uuid); switch_queue_push(fifo, uuid);
switch_ivr_park(session, NULL); switch_ivr_park(session, NULL);
if (switch_channel_ready(channel)) {
if (announce) {
switch_ivr_play_file(session, NULL, announce, NULL);
}
}
switch_channel_clear_flag(channel, CF_TAGGED);
if (switch_channel_ready(channel)) {
switch_channel_set_state(channel, CS_HIBERNATE);
}
return; return;
} else if (!strcasecmp(argv[1], "out")) { } else if (!strcasecmp(argv[1], "out")) {
void *pop; void *pop;
@ -102,12 +167,31 @@ SWITCH_STANDARD_APP(fifo_function)
char *uuid; char *uuid;
int done = 0; int done = 0;
switch_core_session_t *other_session; switch_core_session_t *other_session;
switch_input_args_t args = { 0 };
if (argc > 3) {
announce = argv[3];
}
if (argc > 4) {
moh = argv[4];
}
check_string(announce);
check_string(moh);
if (!nowait) { if (!nowait) {
switch_channel_answer(channel); switch_channel_answer(channel);
} }
for (;;) { for (;;) {
if (moh) {
args.read_frame_callback = read_frame_callback;
args.user_data = fifo;
switch_ivr_play_file(session, NULL, moh, &args);
}
if (switch_queue_trypop(fifo, &pop) != SWITCH_STATUS_SUCCESS) { if (switch_queue_trypop(fifo, &pop) != SWITCH_STATUS_SUCCESS) {
if (nowait) { if (nowait) {
return; return;
@ -126,13 +210,38 @@ SWITCH_STANDARD_APP(fifo_function)
if ((other_session = switch_core_session_locate(uuid))) { if ((other_session = switch_core_session_locate(uuid))) {
switch_channel_t *other_channel = switch_core_session_get_channel(other_session); switch_channel_t *other_channel = switch_core_session_get_channel(other_session);
switch_caller_profile_t *cloned_profile;
if (announce) {
switch_ivr_play_file(session, NULL, announce, NULL);
} else {
switch_ivr_sleep(session, 500);
}
switch_channel_clear_flag(other_channel, CF_CONTROLLED); switch_channel_clear_flag(other_channel, CF_CONTROLLED);
switch_channel_clear_flag(other_channel, CF_BROADCAST); switch_channel_clear_flag(other_channel, CF_BROADCAST);
switch_channel_set_flag(other_channel, CF_BREAK); switch_channel_set_flag(other_channel, CF_BREAK);
switch_core_session_kill_channel(other_session, SWITCH_SIG_BREAK); switch_core_session_kill_channel(other_session, SWITCH_SIG_BREAK);
switch_ivr_multi_threaded_bridge(session, other_session, NULL, NULL, NULL); while (switch_channel_test_flag(other_channel, CF_TAGGED)) {
status = switch_core_session_read_frame(session, &read_frame, -1, 0);
if (!SWITCH_READ_ACCEPTABLE(status)) {
break;
}
}
switch_channel_answer(channel);
cloned_profile = switch_caller_profile_clone(session, switch_channel_get_caller_profile(channel));
assert(cloned_profile);
switch_channel_set_originator_caller_profile(other_channel, cloned_profile);
cloned_profile = switch_caller_profile_clone(other_session, switch_channel_get_caller_profile(channel));
assert(cloned_profile);
switch_channel_set_originatee_caller_profile(channel, cloned_profile);
switch_ivr_multi_threaded_bridge(session, other_session, on_dtmf, other_session, session);
switch_core_session_rwunlock(other_session); switch_core_session_rwunlock(other_session);
done = 1; if (nowait) {
done = 1;
}
} }
switch_safe_free(uuid); switch_safe_free(uuid);