[Freeswitch-svn] [commit] r4805 - in freeswitch/trunk/src: . include mod/applications/mod_commands

Freeswitch SVN anthm at freeswitch.org
Fri Mar 30 10:57:07 EDT 2007


Author: anthm
Date: Fri Mar 30 10:57:06 2007
New Revision: 4805

Modified:
   freeswitch/trunk/src/include/switch_scheduler.h
   freeswitch/trunk/src/include/switch_types.h
   freeswitch/trunk/src/include/switch_utils.h
   freeswitch/trunk/src/mod/applications/mod_commands/mod_commands.c
   freeswitch/trunk/src/switch_core.c
   freeswitch/trunk/src/switch_scheduler.c

Log:
tweaks

Modified: freeswitch/trunk/src/include/switch_scheduler.h
==============================================================================
--- freeswitch/trunk/src/include/switch_scheduler.h	(original)
+++ freeswitch/trunk/src/include/switch_scheduler.h	Fri Mar 30 10:57:06 2007
@@ -67,16 +67,16 @@
 /*!
   \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);
 
 
 /*!

Modified: freeswitch/trunk/src/include/switch_types.h
==============================================================================
--- freeswitch/trunk/src/include/switch_types.h	(original)
+++ freeswitch/trunk/src/include/switch_types.h	Fri Mar 30 10:57:06 2007
@@ -158,7 +158,8 @@
 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 {

Modified: freeswitch/trunk/src/include/switch_utils.h
==============================================================================
--- freeswitch/trunk/src/include/switch_utils.h	(original)
+++ freeswitch/trunk/src/include/switch_utils.h	Fri Mar 30 10:57:06 2007
@@ -54,6 +54,19 @@
 #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

Modified: freeswitch/trunk/src/mod/applications/mod_commands/mod_commands.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_commands/mod_commands.c	(original)
+++ freeswitch/trunk/src/mod/applications/mod_commands/mod_commands.c	Fri Mar 30 10:57:06 2007
@@ -705,6 +705,25 @@
 	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 @@
 			}
 		
 			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 @@
 	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 = {

Modified: freeswitch/trunk/src/switch_core.c
==============================================================================
--- freeswitch/trunk/src/switch_core.c	(original)
+++ freeswitch/trunk/src/switch_core.c	Fri Mar 30 10:57:06 2007
@@ -489,7 +489,7 @@
 	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);

Modified: freeswitch/trunk/src/switch_scheduler.c
==============================================================================
--- freeswitch/trunk/src/switch_scheduler.c	(original)
+++ freeswitch/trunk/src/switch_scheduler.c	Fri Mar 30 10:57:06 2007
@@ -187,15 +187,20 @@
 	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_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_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)



More information about the Freeswitch-svn mailing list