24#ifndef _ASTERISK_SCHED_H 
   25#define _ASTERISK_SCHED_H 
   27#if defined(__cplusplus) || defined(c_plusplus) 
   46#define AST_SCHED_DEL(sched, id) \ 
   49        int _sched_res = -1; \ 
   50        while (id > -1 && (_sched_res = ast_sched_del(sched, id)) && ++_count < 10) \ 
   53            ast_debug(3, "Unable to cancel schedule ID %d.\n", id); \ 
 
   59#define AST_SCHED_DEL_ACCESSOR(sched, obj, getter, setter) \ 
   62        int _sched_res = -1; \ 
   63        while (getter(obj) > -1 && (_sched_res = ast_sched_del(sched, getter(obj))) && ++_count < 10) \ 
   66            ast_debug(3, "Unable to cancel schedule ID %d.\n", getter(obj)); \ 
 
   82#define AST_SCHED_DEL_UNREF(sched, id, refcall)         \ 
   84        int _count = 0, _id, _ret = 0; \ 
   85        while ((_id = id) > -1 && (( _ret = ast_sched_del_nonrunning(sched, _id)) == -1) && ++_count < 10) { \ 
   89            ast_log(LOG_WARNING, "Unable to cancel schedule ID %d.  This is probably a bug (%s: %s, line %d).\n", _id, __FILE__, __PRETTY_FUNCTION__, __LINE__); \ 
   90        } else if (_id > -1 && _ret >-2) { \ 
 
  100#define AST_SCHED_DEL_SPINLOCK(sched, id, lock) \ 
  103        int _sched_res = -1; \ 
  104        while (id > -1 && (_sched_res = ast_sched_del(sched, id)) && ++_count < 10) { \ 
  105            ast_mutex_unlock(lock); \ 
  107            ast_mutex_lock(lock); \ 
  109        if (_count == 10) { \ 
  110            ast_debug(3, "Unable to cancel schedule ID %d.\n", id); \ 
 
  116#define AST_SCHED_REPLACE_VARIABLE(id, sched, when, callback, data, variable) \ 
  119        while (id > -1 && ast_sched_del(sched, id) && ++_count < 10) { \ 
  123            ast_log(LOG_WARNING, "Unable to cancel schedule ID %d.  This is probably a bug (%s: %s, line %d).\n", id, __FILE__, __PRETTY_FUNCTION__, __LINE__); \ 
  124        id = ast_sched_add_variable(sched, when, callback, data, variable); \ 
 
  127#define AST_SCHED_REPLACE(id, sched, when, callback, data) \ 
  128        AST_SCHED_REPLACE_VARIABLE(id, sched, when, callback, data, 0) 
 
  134#define AST_SCHED_REPLACE_VARIABLE_UNREF(id, sched, when, callback, data, variable, unrefcall, addfailcall, refcall) \ 
  136        int _count = 0, _res=1;                                          \ 
  137        void *_data = (void *)ast_sched_find_data(sched, id);           \ 
  138        while (id > -1 && (_res = ast_sched_del(sched, id) && _count++ < 10)) { \ 
  141        if (!_res && _data && _data != data)                    \ 
  144            ast_log(LOG_WARNING, "Unable to cancel schedule ID %d.  This is probably a bug (%s: %s, line %d).\n", id, __FILE__, __PRETTY_FUNCTION__, __LINE__); \ 
  147        id = ast_sched_add_variable(sched, when, callback, data, variable); \ 
 
  152#define AST_SCHED_REPLACE_UNREF(id, sched, when, callback, data, unrefcall, addfailcall, refcall) \ 
  153    AST_SCHED_REPLACE_VARIABLE_UNREF(id, sched, when, callback, data, 0, unrefcall, addfailcall, refcall) 
 
  179#define AST_SCHED_CB(a) ((ast_sched_cb)(a)) 
  370#define ast_sched_add_object(obj,con,when,callback) ast_sched_add((con),(when),(callback), ASTOBJ_REF((obj))) 
  376#define ast_sched_del_object(obj,destructor,con,id) do { \ 
  378        ast_sched_del((con),(id)); \ 
  380        ASTOBJ_UNREF((obj),(destructor)); \ 
 
  394#if defined(__cplusplus) || defined(c_plusplus) 
static int match(struct ast_sockaddr *addr, unsigned short callno, unsigned short dcallno, const struct chan_iax2_pvt *cur, int check_dcallno)
static struct ast_channel * callback(struct ast_channelstorage_instance *driver, ao2_callback_data_fn *cb_fn, void *arg, void *data, int ao2_flags)
#define attribute_warn_unused_result
static int cleanup_cb(void *obj, void *arg, int flags)
const void * ast_sched_find_data(struct ast_sched_context *con, int id)
Find a sched structure and return the data field associated with it.
int ast_sched_del(struct ast_sched_context *con, int id) attribute_warn_unused_result
Deletes a scheduled event.
void ast_sched_report(struct ast_sched_context *con, struct ast_str **buf, struct ast_cb_names *cbnames)
Show statics on what it is in the schedule queue.
void ast_sched_clean_by_callback(struct ast_sched_context *con, ast_sched_cb match, ast_sched_cb cleanup_cb)
Clean all scheduled events with matching callback.
long ast_sched_when(struct ast_sched_context *con, int id)
Returns the number of seconds before an event takes place.
int ast_sched_replace(int old_id, struct ast_sched_context *con, int when, ast_sched_cb callback, const void *data) attribute_warn_unused_result
replace a scheduler entry
void ast_sched_dump(struct ast_sched_context *con)
Dumps the scheduler contents.
int ast_sched_add(struct ast_sched_context *con, int when, ast_sched_cb callback, const void *data) attribute_warn_unused_result
Adds a scheduled event.
void ast_sched_context_destroy(struct ast_sched_context *c)
destroys a schedule context
int ast_sched_start_thread(struct ast_sched_context *con)
Start a thread for processing scheduler entries.
int ast_sched_runq(struct ast_sched_context *con)
Runs the queue.
int ast_sched_del_nonrunning(struct ast_sched_context *con, int id) attribute_warn_unused_result
Deletes a scheduled event with care against the event running.
int ast_sched_add_variable(struct ast_sched_context *con, int when, ast_sched_cb callback, const void *data, int variable) attribute_warn_unused_result
Adds a scheduled event with rescheduling support.
int(* ast_sched_cb)(const void *data)
scheduler callback
struct ast_sched_context * ast_sched_context_create(void)
Create a scheduler context.
int ast_sched_wait(struct ast_sched_context *con) attribute_warn_unused_result
Determines number of seconds until the next outstanding event to take place.
int ast_sched_replace_variable(int old_id, struct ast_sched_context *con, int when, ast_sched_cb callback, const void *data, int variable) attribute_warn_unused_result
replace a scheduler entry
Support for dynamic strings.