]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
tweaks
authorAnthony Minessale <anthony.minessale@gmail.com>
Fri, 30 Mar 2007 14:57:06 +0000 (14:57 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Fri, 30 Mar 2007 14:57:06 +0000 (14:57 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@4805 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/include/switch_scheduler.h
src/include/switch_types.h
src/include/switch_utils.h
src/mod/applications/mod_commands/mod_commands.c
src/switch_core.c
src/switch_scheduler.c

index beff65f9f9ab166db74ada4fbc1f32e84eb15bd3..2241247ea714f6c864e67e4500eb8ddcfad6e443 100644 (file)
@@ -67,16 +67,16 @@ SWITCH_DECLARE(uint32_t) switch_scheduler_add_task(time_t task_runtime,
 /*!
   \brief Delete a scheduled task
   \param task_id the id of the task
-  \return SWITCH_STATUS_SUCCESS if the task was deleted.
+  \return the number of jobs deleted
 */
-SWITCH_DECLARE(switch_status_t) switch_scheduler_del_task_id(uint32_t task_id);
+SWITCH_DECLARE(uint32_t) switch_scheduler_del_task_id(uint32_t task_id);
 
 /*!
   \brief Delete a scheduled task based on the group name
   \param group the group name
-  \return SWITCH_STATUS_SUCCESS if any tasks were deleted
+  \return the number of jobs deleted
 */
-SWITCH_DECLARE(switch_status_t) switch_scheduler_del_task_group(char *group);
+SWITCH_DECLARE(uint32_t) switch_scheduler_del_task_group(char *group);
 
 
 /*!
index 4bf208053fb760a5943c3e2c72facb72f559910f..3465d60eb7d64dfa6fdbe2df794d1d8f8c55c4f9 100644 (file)
@@ -158,7 +158,8 @@ typedef enum {
 typedef enum {
        SSHF_NONE = 0,
        SSHF_OWN_THREAD = (1 << 0),
-       SSHF_FREE_ARG = (1 << 1)
+       SSHF_FREE_ARG = (1 << 1),
+       SSHF_NO_DEL = (1 << 2)
 } switch_scheduler_flag_t;
 
 typedef enum {
index e88b15fb67745df9c857cedf3059192e46e8db84..ce664352d4a85b414e9f3aad822d44cf8a06faa1 100644 (file)
@@ -54,6 +54,19 @@ SWITCH_BEGIN_EXTERN_C
 #else
 #define switch_is_file_path(file) ((*file == '/') || strstr(file, SWITCH_URL_SEPARATOR))
 #endif
+
+static inline switch_bool_t switch_is_digit_string(char *s) {
+
+       while(s && *s) {
+               if (*s < 48 || *s > 57) {
+                       return SWITCH_FALSE;
+               }
+               s++;
+       }
+
+       return SWITCH_TRUE;
+}
+
 /*!
   \brief Evaluate the truthfullness of a string expression
   \param expr a string expression
index bd416f5eb646a12f56149c76e04e68b5edbaa799..8223e38911ea83fd657e8720d08213dc19ec5c43 100644 (file)
@@ -705,6 +705,25 @@ static void sch_api_callback(switch_scheduler_task_t *task)
        switch_safe_free(stream.data);
 }
 
+static switch_status_t sched_del_function(char *cmd, switch_core_session_t *isession, switch_stream_handle_t *stream)
+{
+       uint32_t cnt = 0;
+       
+       if (switch_is_digit_string(cmd)) {
+               int64_t tmp;
+               tmp = (uint32_t) atoi(cmd);
+               if (tmp > 0) {
+                       cnt = switch_scheduler_del_task_id((uint32_t)tmp);
+               }
+       } else {
+               cnt = switch_scheduler_del_task_group(cmd);
+       }
+
+       stream->write_function(stream, "DELETED: %u\n", cnt);
+
+       return SWITCH_STATUS_SUCCESS;
+}
+
 static switch_status_t sched_api_function(char *cmd, switch_core_session_t *isession, switch_stream_handle_t *stream)
 {
        char *tm = NULL, *dcmd, *group;
@@ -729,7 +748,7 @@ static switch_status_t sched_api_function(char *cmd, switch_core_session_t *ises
                        }
                
                        id = switch_scheduler_add_task(when, sch_api_callback, (char *) __SWITCH_FUNC__, group, 0, strdup(dcmd), SSHF_FREE_ARG);
-                       stream->write_function(stream, "Added task %u for command [%s] group [%s]\n", id, dcmd, group);
+                       stream->write_function(stream, "ADDED: %u\n", id);
                        goto good;
                } 
        }
@@ -895,12 +914,20 @@ static switch_status_t help_function(char *cmd, switch_core_session_t *session,
        return SWITCH_STATUS_SUCCESS;
 }
 
+static switch_api_interface_t sched_del_api_interface = {
+       /*.interface_name */ "sched_del",
+       /*.desc */ "Delete a Scheduled task",
+       /*.function */ sched_del_function,
+       /*.syntax */ "<task_id>|<group_id>",
+       /*.next */ NULL
+};
+
 static switch_api_interface_t sched_api_api_interface = {
        /*.interface_name */ "sched_api",
        /*.desc */ "Schedule an api command",
        /*.function */ sched_api_function,
        /*.syntax */ "[+]<time> <group_name> <command_string>",
-       /*.next */ NULL
+       /*.next */ &sched_del_api_interface
 };
 
 static switch_api_interface_t sched_transfer_api_interface = {
index 7d5eeddc191d04458d55b58bfe473824fcf8ccbb..ceb502bfb5c0a4d01f0d620c89fc74c9f7817b31 100644 (file)
@@ -489,7 +489,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_init(char *console, const char **err
        switch_scheduler_task_thread_start();
        runtime.initiated = switch_time_now();
 
-       switch_scheduler_add_task(time(NULL), heartbeat_callback, "heartbeat", "core", 0, NULL, SSHF_NONE);
+       switch_scheduler_add_task(time(NULL), heartbeat_callback, "heartbeat", "core", 0, NULL, SSHF_NONE | SSHF_NO_DEL);
 
 
        switch_uuid_get(&uuid);
index 58ca9cdad27342d4f3ddaeba6792b6286da90cd6..5daa47c062221ee711a72253e5c2b5f7eb36c09c 100644 (file)
@@ -187,15 +187,20 @@ SWITCH_DECLARE(uint32_t) switch_scheduler_add_task(time_t task_runtime,
        return container->task.task_id;
 }
 
-SWITCH_DECLARE(switch_status_t) switch_scheduler_del_task_id(uint32_t task_id)
+SWITCH_DECLARE(uint32_t) switch_scheduler_del_task_id(uint32_t task_id)
 {
        switch_scheduler_task_container_t *tp;
-       switch_status_t status = SWITCH_STATUS_FALSE;
        switch_event_t *event;
+       uint32_t delcnt = 0;
 
        switch_mutex_lock(globals.task_mutex);
        for (tp = globals.task_list; tp; tp = tp->next) {
                if (tp->task.task_id == task_id) {
+                       if (switch_test_flag(tp, SSHF_NO_DEL)) {
+                               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Attempt made to delete undeleteable task #%u (group %s)\n", 
+                                                                 tp->task.task_id, tp->task.group);
+                               break;
+                       }
                        tp->destroyed++;
                        if (switch_event_create(&event, SWITCH_EVENT_DEL_SCHEDULE) == SWITCH_STATUS_SUCCESS) {
                                switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Task-ID", "%u", tp->task.task_id);
@@ -204,24 +209,29 @@ SWITCH_DECLARE(switch_status_t) switch_scheduler_del_task_id(uint32_t task_id)
                                switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Task-Runtime", "%" SWITCH_INT64_T_FMT, tp->task.runtime);
                                switch_event_fire(&event);
                        }
-                       status = SWITCH_STATUS_SUCCESS;
+                       delcnt++;
                        break;
                }
        }
        switch_mutex_unlock(globals.task_mutex);
 
-       return status;
+       return delcnt;
 }
 
-SWITCH_DECLARE(switch_status_t) switch_scheduler_del_task_group(char *group)
+SWITCH_DECLARE(uint32_t) switch_scheduler_del_task_group(char *group)
 {
        switch_scheduler_task_container_t *tp;
-       switch_status_t status = SWITCH_STATUS_FALSE;
        switch_event_t *event;
+       uint32_t delcnt = 0;
 
        switch_mutex_lock(globals.task_mutex);
        for (tp = globals.task_list; tp; tp = tp->next) {
-               if (!strcmp(tp->task.group, group)) {
+               if (!switch_strlen_zero(group) && !strcmp(tp->task.group, group)) {
+                       if (switch_test_flag(tp, SSHF_NO_DEL)) {
+                               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Attempt made to delete undeleteable task #%u (group %s)\n",
+                                                                 tp->task.task_id, group);
+                               continue;
+                       }
                        if (switch_event_create(&event, SWITCH_EVENT_DEL_SCHEDULE) == SWITCH_STATUS_SUCCESS) {
                                switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Task-ID", "%u", tp->task.task_id);
                                switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Task-Desc", "%s", tp->desc);
@@ -230,12 +240,12 @@ SWITCH_DECLARE(switch_status_t) switch_scheduler_del_task_group(char *group)
                                switch_event_fire(&event);
                        }
                        tp->destroyed++;
-                       status = SWITCH_STATUS_SUCCESS;
+                       delcnt++;
                }
        }
        switch_mutex_unlock(globals.task_mutex);
 
-       return status;
+       return delcnt;
 }
 
 SWITCH_DECLARE(void) switch_scheduler_task_thread_start(void)