Asterisk - The Open Source Telephony Project  21.4.1
Data Structures | Macros | Functions | Variables
pjsip_scheduler.c File Reference

res_pjsip Scheduler More...

#include "asterisk.h"
#include "asterisk/res_pjsip.h"
#include "include/res_pjsip_private.h"
#include "asterisk/res_pjsip_cli.h"
#include "asterisk/taskprocessor.h"
#include <regex.h>

Go to the source code of this file.

Data Structures

struct  ast_sip_sched_task
 

Macros

#define ID_LEN   13 /* task_deadbeef */
 
#define TASK_BUCKETS   53
 
#define TIME_FORMAT   "%a %T"
 

Functions

 AO2_STRING_FIELD_CMP_FN (ast_sip_sched_task, name)
 
 AO2_STRING_FIELD_HASH_FN (ast_sip_sched_task, name)
 
 AO2_STRING_FIELD_SORT_FN (ast_sip_sched_task, name)
 
int ast_sip_destroy_scheduler (void)
 
int ast_sip_initialize_scheduler (void)
 Initialize scheduler. More...
 
int ast_sip_sched_is_task_running (struct ast_sip_sched_task *schtd)
 Checks if the task is currently running. More...
 
int ast_sip_sched_is_task_running_by_name (const char *name)
 Checks if the task is currently running. More...
 
int ast_sip_sched_task_cancel (struct ast_sip_sched_task *schtd)
 Cancels the next invocation of a task. More...
 
int ast_sip_sched_task_cancel_by_name (const char *name)
 Cancels the next invocation of a task by name. More...
 
int ast_sip_sched_task_get_name (struct ast_sip_sched_task *schtd, char *name, size_t maxlen)
 Gets the task name. More...
 
int ast_sip_sched_task_get_next_run (struct ast_sip_sched_task *schtd)
 Gets the number of milliseconds until the next invocation. More...
 
int ast_sip_sched_task_get_next_run_by_name (const char *name)
 Gets the number of milliseconds until the next invocation. More...
 
int ast_sip_sched_task_get_times (struct ast_sip_sched_task *schtd, struct timeval *queued, struct timeval *last_start, struct timeval *last_end)
 Gets the last start and end times of the task. More...
 
int ast_sip_sched_task_get_times2 (struct ast_sip_sched_task *schtd, struct timeval *queued, struct timeval *last_start, struct timeval *last_end, int *interval, int *time_left, struct timeval *next_start)
 Gets the queued, last start, last_end, time left, interval, next run. More...
 
int ast_sip_sched_task_get_times_by_name (const char *name, struct timeval *queued, struct timeval *last_start, struct timeval *last_end)
 Gets the last start and end times of the task by name. More...
 
int ast_sip_sched_task_get_times_by_name2 (const char *name, struct timeval *queued, struct timeval *last_start, struct timeval *last_end, int *interval, int *time_left, struct timeval *next_start)
 Gets the queued, last start, last_end, time left, interval, next run by task name. More...
 
struct ast_sip_sched_taskast_sip_schedule_task (struct ast_taskprocessor *serializer, int interval, ast_sip_task sip_task, const char *name, void *task_data, enum ast_sip_scheduler_task_flags flags)
 Schedule a task to run in the res_pjsip thread pool. More...
 
static char * cli_show_tasks (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
static int push_to_serializer (const void *data)
 
static int run_task (void *data)
 
static void schtd_dtor (void *data)
 

Variables

static struct ast_cli_entry cli_commands []
 
static struct ast_sched_contextscheduler_context
 
static int task_count
 
static struct ao2_containertasks
 

Detailed Description

res_pjsip Scheduler

Author
George Joseph georg.nosp@m.e.jo.nosp@m.seph@.nosp@m.fair.nosp@m.view5.nosp@m..com

Definition in file pjsip_scheduler.c.

Function Documentation

int ast_sip_initialize_scheduler ( void  )

Initialize scheduler.

Since
13.9.0
Return values
-1failure
0success

Definition at line 614 of file pjsip_scheduler.c.

References AO2_ALLOC_OPT_LOCK_RWLOCK, ao2_container_alloc_hash, AO2_CONTAINER_ALLOC_OPT_DUPS_REJECT, ast_cli_register_multiple, ast_sched_context_create(), ast_sched_context_destroy(), and ast_sched_start_thread().

615 {
616  scheduler_context = ast_sched_context_create();
617  if (!scheduler_context) {
618  ast_log(LOG_ERROR, "Failed to create scheduler. Aborting load\n");
619  return -1;
620  }
621 
622  if (ast_sched_start_thread(scheduler_context)) {
623  ast_log(LOG_ERROR, "Failed to start scheduler. Aborting load\n");
624  ast_sched_context_destroy(scheduler_context);
625  return -1;
626  }
627 
629  AO2_CONTAINER_ALLOC_OPT_DUPS_REJECT, TASK_BUCKETS, ast_sip_sched_task_hash_fn,
630  ast_sip_sched_task_sort_fn, ast_sip_sched_task_cmp_fn);
631  if (!tasks) {
632  ast_log(LOG_ERROR, "Failed to allocate task container. Aborting load\n");
633  ast_sched_context_destroy(scheduler_context);
634  return -1;
635  }
636 
637  ast_cli_register_multiple(cli_commands, ARRAY_LEN(cli_commands));
638 
639  return 0;
640 }
int ast_sched_start_thread(struct ast_sched_context *con)
Start a thread for processing scheduler entries.
Definition: sched.c:197
#define ast_cli_register_multiple(e, len)
Register multiple commands.
Definition: cli.h:265
struct ast_sched_context * ast_sched_context_create(void)
Create a scheduler context.
Definition: sched.c:238
#define ao2_container_alloc_hash(ao2_options, container_options, n_buckets, hash_fn, sort_fn, cmp_fn)
Allocate and initialize a hash container with the desired number of buckets.
Definition: astobj2.h:1303
Reject objects with duplicate keys in container.
Definition: astobj2.h:1188
void ast_sched_context_destroy(struct ast_sched_context *c)
destroys a schedule context
Definition: sched.c:271

Variable Documentation

struct ast_cli_entry cli_commands[]
static
Initial value:
= {
{ .handler = cli_show_tasks , .summary = "Show pjsip scheduled tasks" ,},
}

Definition at line 610 of file pjsip_scheduler.c.