]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
more heartbeat work
authorAnthony Minessale <anthony.minessale@gmail.com>
Tue, 7 Oct 2008 21:42:31 +0000 (21:42 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Tue, 7 Oct 2008 21:42:31 +0000 (21:42 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@9883 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/mod/applications/mod_commands/mod_commands.c
src/switch_channel.c
src/switch_core_session.c

index cd816518b727e124dc2b997274d4c1bcc75844d7..788f9c4c88e4ebd1e05d0b740e8eed107df2d180 100644 (file)
@@ -2321,6 +2321,57 @@ SWITCH_STANDARD_API(help_function)
        return SWITCH_STATUS_SUCCESS;
 }
 
+#define HEARTBEAT_SYNTAX "<uuid> <on|off|<seconds>>"
+SWITCH_STANDARD_API(uuid_session_heartbeat_function)
+{
+       char *mycmd = NULL, *argv[2] = { 0 };
+       uint32_t seconds = 60;
+       int argc, tmp;
+       switch_core_session_t *l_session = NULL;
+
+       if (switch_strlen_zero(cmd) || !(mycmd = strdup(cmd))) {
+               goto error;
+       }
+
+       argc = switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
+
+       if (argc != 2) {
+               goto error;
+       }
+
+       if (!(l_session = switch_core_session_locate(argv[0]))) {
+               stream->write_function(stream, "-ERR Usage: cannot locate session.\n");
+               return SWITCH_STATUS_SUCCESS;
+       }
+
+       if (switch_is_number(argv[1])) {
+               tmp = atoi(argv[1]);
+               if (tmp > 0) {
+                       seconds = tmp;
+               }
+       } else if (!switch_true(argv[1])) {
+               seconds = 0;
+       }
+       
+       if (seconds) {
+               switch_core_session_enable_heartbeat(l_session, seconds);
+       } else {
+               switch_core_session_disable_heartbeat(l_session);
+       }
+       
+       switch_core_session_rwunlock(l_session);
+       
+       switch_safe_free(mycmd);        
+       stream->write_function(stream, "+OK\n");
+       return SWITCH_STATUS_SUCCESS;
+       
+ error:
+       switch_safe_free(mycmd);
+       stream->write_function(stream, "-ERR Usage: uuid_session_heartbeat %s", HEARTBEAT_SYNTAX);
+       return SWITCH_STATUS_SUCCESS;
+
+}
+
 #define SETVAR_SYNTAX "<uuid> <var> <value>"
 SWITCH_STANDARD_API(uuid_setvar_function)
 {
@@ -2694,6 +2745,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_commands_load)
        switch_console_set_complete("add alias add");
        switch_console_set_complete("add alias del");
        SWITCH_ADD_API(commands_api_interface, "status", "status", status_function, "");
+       SWITCH_ADD_API(commands_api_interface, "uuid_session_heartbeat", "uuid_session_heartbeat", uuid_session_heartbeat_function, HEARTBEAT_SYNTAX);
        SWITCH_ADD_API(commands_api_interface, "uuid_bridge", "uuid_bridge", uuid_bridge_function, "");
        SWITCH_ADD_API(commands_api_interface, "uuid_setvar", "uuid_setvar", uuid_setvar_function, SETVAR_SYNTAX);
        SWITCH_ADD_API(commands_api_interface, "uuid_getvar", "uuid_getvar", uuid_getvar_function, GETVAR_SYNTAX);
index 42ae7864ba1f0862d8727b3dc8f03713ad0d1d2d..91ac11b2cd50e00e4fa23cc615b8bd1b2534bafc 100644 (file)
@@ -1633,7 +1633,7 @@ SWITCH_DECLARE(switch_status_t) switch_channel_perform_mark_answered(switch_chan
 
                if (switch_is_number(var)) {
                        tmp = atoi(var);
-                       if (tmp > 10) {
+                       if (tmp > 0) {
                                seconds = tmp;
                        }
                } else if (!switch_true(var)) {
index 531d19a5042d97a694a3aa06c116f2aabd551daf..19402dbae57868fa4ce1811711df585f7124a1b4 100644 (file)
@@ -783,14 +783,21 @@ SWITCH_DECLARE(void) switch_core_session_perform_destroy(switch_core_session_t *
 SWITCH_DECLARE(void) switch_core_session_enable_heartbeat(switch_core_session_t *session, uint32_t seconds)
 {
        switch_assert(session != NULL);
-       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%s setting session heartbeat to %u second(s).", 
+
+       if (seconds < 10) {
+               seconds = 60;
+       }
+
+       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%s setting session heartbeat to %u second(s).\n", 
                                          switch_channel_get_name(session->channel), seconds);
        session->track_duration = seconds;
+       session->read_frame_count = 0;
 }
 
 SWITCH_DECLARE(void) switch_core_session_disable_heartbeat(switch_core_session_t *session)
 {
        switch_assert(session != NULL);
+       session->read_frame_count = 0;
        session->track_duration = 0;
 }