tweaks
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@4805 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
324f6b00aa
commit
33efc5eeb5
|
@ -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);
|
||||
|
||||
|
||||
/*!
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 = {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue