Fri Jul 24 00:41:42 2009

Asterisk developer's documentation


event.c File Reference

Internal generic event system. More...

#include "asterisk.h"
#include "asterisk/_private.h"
#include "asterisk/event.h"
#include "asterisk/linkedlists.h"
#include "asterisk/dlinkedlists.h"
#include "asterisk/lock.h"
#include "asterisk/utils.h"
#include "asterisk/unaligned.h"
#include "asterisk/taskprocessor.h"
#include "asterisk/astobj2.h"

Go to the source code of this file.

Data Structures

struct  ast_event
 An event. More...
struct  ast_event_ie
 An event information element. More...
struct  ast_event_ie_str_payload
 The payload for a string information element. More...
struct  ast_event_ie_val
struct  ast_event_ref
 A holder for an event. More...
struct  ast_event_sub
 Event subscription. More...
struct  ast_event_sub_list
 Event subscriptions The event subscribers are indexed by which event they are subscribed to. More...
struct  event_name
struct  ie_map

Defines

#define MAX_CACHE_ARGS   8
#define NUM_CACHE_BUCKETS   563

Functions

static struct ast_event_refalloc_event_ref (void)
int ast_event_append_ie_raw (struct ast_event **event, enum ast_event_ie_type ie_type, const void *data, size_t data_len)
 Append an information element that has a raw payload.
int ast_event_append_ie_str (struct ast_event **event, enum ast_event_ie_type ie_type, const char *str)
 Append an information element that has a string payload.
int ast_event_append_ie_uint (struct ast_event **event, enum ast_event_ie_type ie_type, uint32_t data)
 Append an information element that has an integer payload.
enum ast_event_subscriber_res ast_event_check_subscriber (enum ast_event_type type,...)
 Check if subscribers exist.
static int ast_event_cmp (void *obj, void *arg, int flags)
void ast_event_destroy (struct ast_event *event)
 Destroy an event.
void ast_event_dump_cache (const struct ast_event_sub *event_sub)
 Dump the event cache for the subscriber.
static struct ast_eventast_event_dup (const struct ast_event *event)
static int attribute_unused ast_event_dup_and_cache (const struct ast_event *event)
 Duplicate an event and add it to the cache.
ast_eventast_event_get_cached (enum ast_event_type type,...)
 Retrieve an event from the cache.
enum ast_event_ie_pltype ast_event_get_ie_pltype (enum ast_event_ie_type ie_type)
 Get the payload type for a given information element type.
const void * ast_event_get_ie_raw (const struct ast_event *event, enum ast_event_ie_type ie_type)
 Get the value of an information element that has a raw payload.
const char * ast_event_get_ie_str (const struct ast_event *event, enum ast_event_ie_type ie_type)
 Get the value of an information element that has a string payload.
uint32_t ast_event_get_ie_str_hash (const struct ast_event *event, enum ast_event_ie_type ie_type)
 Get the hash for the string payload of an IE.
const char * ast_event_get_ie_type_name (enum ast_event_ie_type ie_type)
 Get the string representation of an information element type.
uint32_t ast_event_get_ie_uint (const struct ast_event *event, enum ast_event_ie_type ie_type)
 Get the value of an information element that has an integer payload.
size_t ast_event_get_size (const struct ast_event *event)
 Get the size of an event.
enum ast_event_type ast_event_get_type (const struct ast_event *event)
 Get the type for an event.
const char * ast_event_get_type_name (const struct ast_event *event)
 Get the string representation of the type of the given event.
static int ast_event_hash (const void *obj, const int flags)
static int ast_event_hash_devstate (const void *obj, const int flags)
static int ast_event_hash_devstate_change (const void *obj, const int flags)
static int ast_event_hash_mwi (const void *obj, const int flags)
static void ast_event_ie_val_destroy (struct ast_event_ie_val *ie_val)
int ast_event_init (void)
void * ast_event_iterator_get_ie_raw (struct ast_event_iterator *iterator)
 Get the value of the current IE in the iterator instance that has a raw payload.
const char * ast_event_iterator_get_ie_str (struct ast_event_iterator *iterator)
 Get the value of the current IE in the iterator as a string payload.
enum ast_event_ie_type ast_event_iterator_get_ie_type (struct ast_event_iterator *iterator)
 Get the type of the current IE in the iterator instance.
uint32_t ast_event_iterator_get_ie_uint (struct ast_event_iterator *iterator)
 Get the value of the current IE in the ierator as an integer payload.
void ast_event_iterator_init (struct ast_event_iterator *iterator, const struct ast_event *event)
 Initialize an event iterator instance.
int ast_event_iterator_next (struct ast_event_iterator *iterator)
 Move iterator instance to next IE.
ast_eventast_event_new (enum ast_event_type type,...)
 Create a new event.
int ast_event_queue (struct ast_event *event)
 Queue an event.
int ast_event_queue_and_cache (struct ast_event *event)
 Queue and cache an event.
static void ast_event_ref_destroy (void *obj)
void ast_event_report_subs (const struct ast_event_sub *event_sub)
 Report current subscriptions to a subscription subscriber.
int ast_event_str_to_event_type (const char *str, enum ast_event_type *event_type)
 Convert a string into an event type.
int ast_event_str_to_ie_type (const char *str, enum ast_event_ie_type *ie_type)
 Convert a string to an IE type.
int ast_event_sub_activate (struct ast_event_sub *sub)
 Activate a dynamically built subscription.
int ast_event_sub_append_ie_exists (struct ast_event_sub *sub, enum ast_event_ie_type ie_type)
 Append an 'exists' parameter to a subscription.
int ast_event_sub_append_ie_raw (struct ast_event_sub *sub, enum ast_event_ie_type ie_type, void *data, size_t raw_datalen)
 Append a raw parameter to a subscription.
int ast_event_sub_append_ie_str (struct ast_event_sub *sub, enum ast_event_ie_type ie_type, const char *str)
 Append a string parameter to a subscription.
int ast_event_sub_append_ie_uint (struct ast_event_sub *sub, enum ast_event_ie_type ie_type, uint32_t unsigned_int)
 Append a uint parameter to a subscription.
void ast_event_sub_destroy (struct ast_event_sub *sub)
 Destroy an allocated subscription.
ast_event_subast_event_subscribe (enum ast_event_type type, ast_event_cb_t cb, void *userdata,...)
 Subscribe to events.
ast_event_subast_event_subscribe_new (enum ast_event_type type, ast_event_cb_t cb, void *userdata)
 Allocate a subscription, but do not activate it.
ast_event_subast_event_unsubscribe (struct ast_event_sub *sub)
 Un-subscribe from events.
static int dump_cache_cb (void *obj, void *arg, int flags)
static struct ast_eventgen_sub_event (struct ast_event_sub *sub)
static int handle_event (void *data)
static int match_ie_val (const struct ast_event *event, const struct ast_event_ie_val *ie_val, const struct ast_event *event2)

Variables

struct {
   enum ast_event_ie_type   cache_args [MAX_CACHE_ARGS]
 Information Elements used for caching.
   ao2_container *   container
 Container of cached events.
   ao2_hash_fn *   hash_fn
 Event type specific hash function.
ast_event_cache [AST_EVENT_TOTAL]
 Event types that are kept in the cache.
static struct ast_event_sub_list ast_event_subs [AST_EVENT_TOTAL]
 Event subscriptions The event subscribers are indexed by which event they are subscribed to.
ast_taskprocessorevent_dispatcher
static struct event_name event_names []
static struct ie_map ie_maps []
static uint32_t sub_uniqueid


Detailed Description

Internal generic event system.

Author:
Russell Bryant <russell@digium.com>

Definition in file event.c.


Define Documentation

#define MAX_CACHE_ARGS   8

Definition at line 145 of file event.c.

#define NUM_CACHE_BUCKETS   563

Definition at line 142 of file event.c.

Referenced by ast_event_init().


Function Documentation

static struct ast_event_ref* alloc_event_ref ( void   )  [static]

Definition at line 1064 of file event.c.

References ao2_alloc, and ast_event_ref_destroy().

Referenced by ast_event_dup_and_cache(), and ast_event_queue().

01065 {
01066    return ao2_alloc(sizeof(struct ast_event_ref), ast_event_ref_destroy);
01067 }

int ast_event_append_ie_raw ( struct ast_event **  event,
enum ast_event_ie_type  ie_type,
const void *  data,
size_t  data_len 
)

Append an information element that has a raw payload.

Parameters:
event the event that the IE will be appended to
ie_type the type of IE to append
data A pointer to the raw data for the payload of the IE
data_len The amount of data to copy into the payload
Return values:
0 success
-1 failure
The pointer to the event will get updated with the new location for the event that now contains the appended information element. If the re-allocation of the memory for this event fails, it will be set to NULL.

Definition at line 874 of file event.c.

References ast_realloc, ast_event_ie::ie_payload, and ast_event_ie::ie_payload_len.

Referenced by ast_event_append_ie_str(), ast_event_append_ie_uint(), ast_event_get_cached(), ast_event_new(), and gen_sub_event().

00876 {
00877    struct ast_event_ie *ie;
00878    unsigned int extra_len;
00879    uint16_t event_len;
00880 
00881    event_len = ntohs((*event)->event_len);
00882    extra_len = sizeof(*ie) + data_len;
00883 
00884    if (!(*event = ast_realloc(*event, event_len + extra_len)))
00885       return -1;
00886 
00887    ie = (struct ast_event_ie *) ( ((char *) *event) + event_len );
00888    ie->ie_type = htons(ie_type);
00889    ie->ie_payload_len = htons(data_len);
00890    memcpy(ie->ie_payload, data, data_len);
00891 
00892    (*event)->event_len = htons(event_len + extra_len);
00893 
00894    return 0;
00895 }

int ast_event_append_ie_str ( struct ast_event **  event,
enum ast_event_ie_type  ie_type,
const char *  str 
)

Append an information element that has a string payload.

Parameters:
event the event that the IE will be appended to
ie_type the type of IE to append
str The string for the payload of the IE
Return values:
0 success
-1 failure
The pointer to the event will get updated with the new location for the event that now contains the appended information element. If the re-allocation of the memory for this event fails, it will be set to NULL.

Definition at line 852 of file event.c.

References ast_event_append_ie_raw(), ast_str_hash(), ast_event_ie_str_payload::hash, and ast_event_ie_str_payload::str.

Referenced by ast_event_get_cached(), ast_event_new(), and gen_sub_event().

00854 {
00855    struct ast_event_ie_str_payload *str_payload;
00856    size_t payload_len;
00857 
00858    payload_len = sizeof(*str_payload) + strlen(str);
00859    str_payload = alloca(payload_len);
00860 
00861    strcpy(str_payload->str, str);
00862    str_payload->hash = ast_str_hash(str);
00863 
00864    return ast_event_append_ie_raw(event, ie_type, str_payload, payload_len);
00865 }

int ast_event_append_ie_uint ( struct ast_event **  event,
enum ast_event_ie_type  ie_type,
uint32_t  data 
)

Append an information element that has an integer payload.

Parameters:
event the event that the IE will be appended to
ie_type the type of IE to append
data The integer for the payload of the IE
Return values:
0 success
-1 failure
The pointer to the event will get updated with the new location for the event that now contains the appended information element. If the re-allocation of the memory for this event fails, it will be set to NULL.

Definition at line 867 of file event.c.

References ast_event_append_ie_raw().

Referenced by ast_event_get_cached(), ast_event_new(), and gen_sub_event().

00869 {
00870    data = htonl(data);
00871    return ast_event_append_ie_raw(event, ie_type, &data, sizeof(data));
00872 }

enum ast_event_subscriber_res ast_event_check_subscriber ( enum ast_event_type  event_type,
  ... 
)

Check if subscribers exist.

Parameters:
event_type This is the type of event that the caller would like to check for subscribers to.
The rest of the arguments to this function specify additional parameters for checking for subscriptions to subsets of an event type. The arguments must in sets of:
    <enum ast_event_ie_type>, [enum ast_event_ie_pltype, [payload] ]
and must end with AST_EVENT_IE_END.

If the ie_type specified is *not* AST_EVENT_IE_END, then it must be followed by a valid IE payload type. If the payload type specified is AST_EVENT_IE_PLTYPE_EXISTS, then the 3rd argument should not be provided. Otherwise, a payload must also be specified.

Returns:
This returns one of the values defined in the ast_event_subscriber_res enum which will indicate if subscribers exist that match the given criteria.
Example usage:

This example will check if there are any subscribers to MWI events for the mailbox defined in the "mailbox" variable.

Definition at line 322 of file event.c.

References AST_DLLIST_EMPTY, AST_EVENT_ALL, AST_EVENT_IE_END, AST_EVENT_IE_PLTYPE_EXISTS, AST_EVENT_IE_PLTYPE_RAW, AST_EVENT_IE_PLTYPE_STR, AST_EVENT_IE_PLTYPE_UINT, AST_EVENT_SUB_EXISTS, AST_EVENT_SUB_NONE, ast_event_subs, AST_LIST_HEAD_NOLOCK_STATIC, AST_LIST_INSERT_TAIL, AST_LIST_TRAVERSE, ast_log(), AST_RWDLLIST_RDLOCK, AST_RWDLLIST_TRAVERSE, AST_RWDLLIST_UNLOCK, ast_strdupa, ast_event_ie_val::ie_pltype, ast_event_ie_val::ie_type, ast_event_sub::ie_vals, LOG_ERROR, ast_event_ie_val::payload, ast_event_ie_val::raw, ast_event_ie_val::raw_datalen, ast_event_ie_val::str, and ast_event_ie_val::uint.

Referenced by ast_event_queue(), ast_event_sub_activate(), and ast_event_unsubscribe().

00323 {
00324    va_list ap;
00325    enum ast_event_ie_type ie_type;
00326    enum ast_event_subscriber_res res = AST_EVENT_SUB_NONE;
00327    struct ast_event_ie_val *ie_val, *sub_ie_val;
00328    struct ast_event_sub *sub;
00329    AST_LIST_HEAD_NOLOCK_STATIC(ie_vals, ast_event_ie_val);
00330 
00331    if (type >= AST_EVENT_TOTAL) {
00332       ast_log(LOG_ERROR, "%u is an invalid type!\n", type);
00333       return res;
00334    }
00335 
00336    va_start(ap, type);
00337    for (ie_type = va_arg(ap, enum ast_event_type);
00338       ie_type != AST_EVENT_IE_END;
00339       ie_type = va_arg(ap, enum ast_event_type))
00340    {
00341       struct ast_event_ie_val *ie_value = alloca(sizeof(*ie_value));
00342       memset(ie_value, 0, sizeof(*ie_value));
00343       ie_value->ie_type = ie_type;
00344       ie_value->ie_pltype = va_arg(ap, enum ast_event_ie_pltype);
00345       if (ie_value->ie_pltype == AST_EVENT_IE_PLTYPE_UINT)
00346          ie_value->payload.uint = va_arg(ap, uint32_t);
00347       else if (ie_value->ie_pltype == AST_EVENT_IE_PLTYPE_STR)
00348          ie_value->payload.str = ast_strdupa(va_arg(ap, const char *));
00349       else if (ie_value->ie_pltype == AST_EVENT_IE_PLTYPE_RAW) {
00350          void *data = va_arg(ap, void *);
00351          size_t datalen = va_arg(ap, size_t);
00352          ie_value->payload.raw = alloca(datalen);
00353          memcpy(ie_value->payload.raw, data, datalen);
00354          ie_value->raw_datalen = datalen;
00355       }
00356       AST_LIST_INSERT_TAIL(&ie_vals, ie_value, entry);
00357    }
00358    va_end(ap);
00359 
00360    AST_RWDLLIST_RDLOCK(&ast_event_subs[type]);
00361    AST_RWDLLIST_TRAVERSE(&ast_event_subs[type], sub, entry) {
00362       AST_LIST_TRAVERSE(&ie_vals, ie_val, entry) {
00363          AST_LIST_TRAVERSE(&sub->ie_vals, sub_ie_val, entry) {
00364             if (sub_ie_val->ie_type == ie_val->ie_type)
00365                break;
00366          }
00367          if (!sub_ie_val) {
00368             if (ie_val->ie_pltype == AST_EVENT_IE_PLTYPE_EXISTS)
00369                break;
00370             continue;
00371          }
00372          /* The subscriber doesn't actually care what the value is */
00373          if (sub_ie_val->ie_pltype == AST_EVENT_IE_PLTYPE_EXISTS)
00374             continue;
00375          if (ie_val->ie_pltype == AST_EVENT_IE_PLTYPE_UINT &&
00376             ie_val->payload.uint != sub_ie_val->payload.uint)
00377             break;
00378          if (ie_val->ie_pltype == AST_EVENT_IE_PLTYPE_STR &&
00379             strcmp(ie_val->payload.str, sub_ie_val->payload.str))
00380             break;
00381          if (ie_val->ie_pltype == AST_EVENT_IE_PLTYPE_RAW &&
00382             memcmp(ie_val->payload.raw, sub_ie_val->payload.raw, ie_val->raw_datalen))
00383             break;
00384       }
00385       if (!ie_val)
00386          break;
00387    }
00388    AST_RWDLLIST_UNLOCK(&ast_event_subs[type]);
00389 
00390    if (sub) /* All parameters were matched */
00391       return AST_EVENT_SUB_EXISTS;
00392 
00393    AST_RWDLLIST_RDLOCK(&ast_event_subs[AST_EVENT_ALL]);
00394    if (!AST_DLLIST_EMPTY(&ast_event_subs[AST_EVENT_ALL]))
00395       res = AST_EVENT_SUB_EXISTS;
00396    AST_RWDLLIST_UNLOCK(&ast_event_subs[AST_EVENT_ALL]);
00397 
00398    return res;
00399 }

static int ast_event_cmp ( void *  obj,
void *  arg,
int  flags 
) [static]

Definition at line 1255 of file event.c.

References ARRAY_LEN, ast_event_cache, ast_event_get_type(), cache_args, CMP_MATCH, ast_event_ref::event, and match_ie_val().

Referenced by ast_event_init(), and ast_event_queue_and_cache().

01256 {
01257    struct ast_event_ref *event_ref, *event_ref2;
01258    struct ast_event *event, *event2;
01259    int res = CMP_MATCH;
01260    int i;
01261    enum ast_event_ie_type *cache_args;
01262 
01263    event_ref = obj;
01264    event = event_ref->event;
01265 
01266    event_ref2 = arg;
01267    event2 = event_ref2->event;
01268 
01269    cache_args = ast_event_cache[ast_event_get_type(event)].cache_args;
01270 
01271    for (i = 0; i < ARRAY_LEN(ast_event_cache[0].cache_args) && cache_args[i]; i++) {
01272       struct ast_event_ie_val ie_val = {
01273          .ie_type = cache_args[i],
01274       };
01275 
01276       if (!match_ie_val(event, &ie_val, event2)) {
01277          res = 0;
01278          break;
01279       }
01280    }
01281 
01282    return res;
01283 }

void ast_event_destroy ( struct ast_event event  ) 

Destroy an event.

Parameters:
event the event to destroy
Returns:
Nothing
Note:
Events that have been queued should *not* be destroyed by the code that created the event. It will be automatically destroyed after being dispatched to the appropriate subscribers.

Definition at line 963 of file event.c.

References ast_free.

Referenced by ast_event_dup_and_cache(), ast_event_get_cached(), ast_event_queue(), ast_event_ref_destroy(), ast_event_report_subs(), devstate_cached(), get_cached_mwi(), has_voicemail(), process_collection(), unistim_send_mwi_to_peer(), and update_registry().

00964 {
00965    ast_free(event);
00966 }

void ast_event_dump_cache ( const struct ast_event_sub event_sub  ) 

Dump the event cache for the subscriber.

Since:
1.6.1

Definition at line 466 of file event.c.

References ao2_callback, ast_event_cache, dump_cache_cb(), event_sub, OBJ_NODATA, and ast_event_sub::type.

Referenced by handle_devstate_change().

00467 {
00468    ao2_callback(ast_event_cache[event_sub->type].container, OBJ_NODATA,
00469          dump_cache_cb, (void *) event_sub);
00470 }

static struct ast_event* ast_event_dup ( const struct ast_event event  )  [static]

Definition at line 975 of file event.c.

References ast_calloc, ast_event_get_size(), and ast_event::event_len.

Referenced by ast_event_dup_and_cache(), and ast_event_get_cached().

00976 {
00977    struct ast_event *dup_event;
00978    uint16_t event_len;
00979 
00980    event_len = ast_event_get_size(event);
00981 
00982    if (!(dup_event = ast_calloc(1, event_len))) {
00983       return NULL;
00984    }
00985 
00986    memcpy(dup_event, event, event_len);
00987 
00988    return dup_event;
00989 }

static int attribute_unused ast_event_dup_and_cache ( const struct ast_event event  )  [static]

Duplicate an event and add it to the cache.

Note:
This assumes this index in to the cache is locked

Definition at line 1071 of file event.c.

References alloc_event_ref(), ao2_link, ao2_ref, ast_event_cache, ast_event_destroy(), ast_event_dup(), ast_event_get_type(), container, and ast_event_ref::event.

01072 {
01073    struct ast_event *dup_event;
01074    struct ast_event_ref *event_ref;
01075 
01076    if (!(dup_event = ast_event_dup(event))) {
01077       return -1;
01078    }
01079 
01080    if (!(event_ref = alloc_event_ref())) {
01081       ast_event_destroy(dup_event);
01082       return -1;
01083    }
01084 
01085    event_ref->event = dup_event;
01086 
01087    ao2_link(ast_event_cache[ast_event_get_type(event)].container, event_ref);
01088 
01089    ao2_ref(event_ref, -1);
01090 
01091    return 0;
01092 }

struct ast_event* ast_event_get_cached ( enum  ast_event_type,
  ... 
)

Retrieve an event from the cache.

Parameters:
ast_event_type The type of event to retrieve from the cache
The rest of the arguments to this function specify information elements to match for retrieving events from the cache. They are specified in the form:
    <enum ast_event_ie_type>, [enum ast_event_ie_pltype, [payload] ]
and must end with AST_EVENT_IE_END.

If the ie_type specified is *not* AST_EVENT_IE_END, then it must be followed by a valid IE payload type. If the payload type specified is AST_EVENT_IE_PLTYPE_EXISTS, then the 3rd argument should not be provided. Otherwise, a payload must also be specified.

Returns:
A reference to an event retrieved from the cache. If no event was found that matches the specified criteria, then NULL will be returned.
Note:
If more than one event in the cache matches the specified criteria, only one will be returned, and it is undefined which one it will be.

The caller of this function *must* call ast_event_destroy() on the returned event after it is done using it.

Example Usage:

This example will check for an MWI event in the cache that matches the specified mailbox. This would be the way to find out the last known state of a mailbox without having to poll the mailbox directly.

Definition at line 991 of file event.c.

References ao2_find, ao2_ref, ast_event_append_ie_raw(), ast_event_append_ie_str(), ast_event_append_ie_uint(), ast_event_cache, ast_event_destroy(), ast_event_dup(), AST_EVENT_IE_END, AST_EVENT_IE_PLTYPE_EXISTS, AST_EVENT_IE_PLTYPE_RAW, AST_EVENT_IE_PLTYPE_STR, AST_EVENT_IE_PLTYPE_UINT, AST_EVENT_IE_PLTYPE_UNKNOWN, ast_event_new(), ast_log(), container, ast_event_ref::event, LOG_ERROR, LOG_WARNING, and OBJ_POINTER.

Referenced by devstate_cached(), get_cached_mwi(), has_voicemail(), process_collection(), unistim_send_mwi_to_peer(), and update_registry().

00992 {
00993    va_list ap;
00994    enum ast_event_ie_type ie_type;
00995    struct ast_event *dup_event = NULL;
00996    struct ast_event_ref *cached_event_ref;
00997    struct ast_event *cache_arg_event;
00998    struct ast_event_ref tmp_event_ref = {
00999       .event = NULL,
01000    };
01001    struct ao2_container *container = NULL;
01002 
01003    if (type >= AST_EVENT_TOTAL) {
01004       ast_log(LOG_ERROR, "%u is an invalid type!\n", type);
01005       return NULL;
01006    }
01007 
01008    if (!(container = ast_event_cache[type].container)) {
01009       ast_log(LOG_ERROR, "%u is not a cached event type\n", type);
01010       return NULL;
01011    }
01012 
01013    if (!(cache_arg_event = ast_event_new(type, AST_EVENT_IE_END))) {
01014       return NULL;
01015    }
01016 
01017    va_start(ap, type);
01018    for (ie_type = va_arg(ap, enum ast_event_type);
01019       ie_type != AST_EVENT_IE_END;
01020       ie_type = va_arg(ap, enum ast_event_type))
01021    {
01022       enum ast_event_ie_pltype ie_pltype;
01023 
01024       ie_pltype = va_arg(ap, enum ast_event_ie_pltype);
01025 
01026       switch (ie_pltype) {
01027       case AST_EVENT_IE_PLTYPE_UINT:
01028          ast_event_append_ie_uint(&cache_arg_event, ie_type, va_arg(ap, uint32_t));
01029          break;
01030       case AST_EVENT_IE_PLTYPE_STR:
01031          ast_event_append_ie_str(&cache_arg_event, ie_type, va_arg(ap, const char *));
01032          break;
01033       case AST_EVENT_IE_PLTYPE_RAW:
01034       {
01035          void *data = va_arg(ap, void *);
01036          size_t datalen = va_arg(ap, size_t);
01037          ast_event_append_ie_raw(&cache_arg_event, ie_type, data, datalen);
01038       }
01039       case AST_EVENT_IE_PLTYPE_EXISTS:
01040          ast_log(LOG_WARNING, "PLTYPE_EXISTS not supported by this function\n");
01041          break;
01042       case AST_EVENT_IE_PLTYPE_UNKNOWN:
01043          break;
01044       }
01045    }
01046    va_end(ap);
01047 
01048    tmp_event_ref.event = cache_arg_event;
01049 
01050    cached_event_ref = ao2_find(container, &tmp_event_ref, OBJ_POINTER);
01051 
01052    ast_event_destroy(cache_arg_event);
01053    cache_arg_event = NULL;
01054 
01055    if (cached_event_ref) {
01056       dup_event = ast_event_dup(cached_event_ref->event);
01057       ao2_ref(cached_event_ref, -1);
01058       cached_event_ref = NULL;
01059    }
01060 
01061    return dup_event;
01062 }

enum ast_event_ie_pltype ast_event_get_ie_pltype ( enum ast_event_ie_type  ie_type  ) 

Get the payload type for a given information element type.

Parameters:
ie_type the information element type to get the payload type of
Returns:
the payload type for the provided IE type
Since:
1.6.1

Definition at line 265 of file event.c.

References AST_EVENT_IE_MAX, AST_EVENT_IE_PLTYPE_UNKNOWN, ast_log(), ie_maps, ie_map::ie_pltype, and LOG_ERROR.

00266 {
00267    if (ie_type <= 0 || ie_type > AST_EVENT_IE_MAX) {
00268       ast_log(LOG_ERROR, "Invalid IE type - '%d'\n", ie_type);
00269       return AST_EVENT_IE_PLTYPE_UNKNOWN;
00270    }
00271 
00272    if (ie_maps[ie_type].ie_type != ie_type) {
00273       ast_log(LOG_ERROR, "The ie type passed in does not match the ie type defined in the ie table.\n");
00274       return AST_EVENT_IE_PLTYPE_UNKNOWN;
00275    }
00276 
00277    return ie_maps[ie_type].ie_pltype;
00278 }

const void* ast_event_get_ie_raw ( const struct ast_event event,
enum ast_event_ie_type  ie_type 
)

Get the value of an information element that has a raw payload.

Parameters:
event The event to get the IE from
ie_type the type of information element to retrieve
Returns:
This returns the payload of the information element with the given type. If the information element isn't found, NULL will be returned.

Definition at line 839 of file event.c.

References ast_event_iterator_get_ie_raw(), ast_event_iterator_get_ie_type(), ast_event_iterator_init(), ast_event_iterator_next(), and ast_event_iterator::event.

Referenced by ast_event_get_ie_str(), ast_event_get_ie_str_hash(), ast_event_get_ie_uint(), ast_event_new(), devstate_cache_cb(), devstate_change_collector_cb(), and match_ie_val().

00840 {
00841    struct ast_event_iterator iterator;
00842    int res = 0;
00843 
00844    for (ast_event_iterator_init(&iterator, event); !res; res = ast_event_iterator_next(&iterator)) {
00845       if (ast_event_iterator_get_ie_type(&iterator) == ie_type)
00846          return ast_event_iterator_get_ie_raw(&iterator);
00847    }
00848 
00849    return NULL;
00850 }

const char* ast_event_get_ie_str ( const struct ast_event event,
enum ast_event_ie_type  ie_type 
)

Get the value of an information element that has a string payload.

Parameters:
event The event to get the IE from
ie_type the type of information element to retrieve
Returns:
This returns the payload of the information element with the given type. If the information element isn't found, NULL will be returned.

Definition at line 830 of file event.c.

References ast_event_get_ie_raw(), and ast_event_ie_str_payload::str.

Referenced by ast_event_hash_devstate(), ast_event_hash_devstate_change(), ast_event_hash_mwi(), device_state_cb(), devstate_change_collector_cb(), match_ie_val(), and mwi_sub_event_cb().

00831 {
00832    const struct ast_event_ie_str_payload *str_payload;
00833 
00834    str_payload = ast_event_get_ie_raw(event, ie_type);
00835 
00836    return str_payload->str;
00837 }

uint32_t ast_event_get_ie_str_hash ( const struct ast_event event,
enum ast_event_ie_type  ie_type 
)

Get the hash for the string payload of an IE.

Parameters:
event The event to get the IE from
ie_type the type of information element to retrieve the hash for
Returns:
This function returns the hash value as calculated by ast_str_hash() for the string payload. This is stored in the event to avoid unnecessary string comparisons.

Definition at line 821 of file event.c.

References ast_event_get_ie_raw(), and ast_event_ie_str_payload::hash.

Referenced by match_ie_val().

00822 {
00823    const struct ast_event_ie_str_payload *str_payload;
00824 
00825    str_payload = ast_event_get_ie_raw(event, ie_type);
00826 
00827    return str_payload->hash;
00828 }

const char* ast_event_get_ie_type_name ( enum ast_event_ie_type  ie_type  ) 

Get the string representation of an information element type.

Parameters:
ie_type the information element type to get the string representation of
Returns:
the string representation of the information element type
Since:
1.6.1

Definition at line 250 of file event.c.

References AST_EVENT_IE_MAX, ast_log(), ie_maps, LOG_ERROR, and ie_map::name.

00251 {
00252    if (ie_type <= 0 || ie_type > AST_EVENT_IE_MAX) {
00253       ast_log(LOG_ERROR, "Invalid IE type - '%d'\n", ie_type);
00254       return "";
00255    }
00256 
00257    if (ie_maps[ie_type].ie_type != ie_type) {
00258       ast_log(LOG_ERROR, "The ie type passed in does not match the ie type defined in the ie table.\n");
00259       return "";
00260    }
00261 
00262    return ie_maps[ie_type].name;
00263 }

uint32_t ast_event_get_ie_uint ( const struct ast_event event,
enum ast_event_ie_type  ie_type 
)

Get the value of an information element that has an integer payload.

Parameters:
event The event to get the IE from
ie_type the type of information element to retrieve
Returns:
This returns the payload of the information element with the given type. However, an IE with a payload of 0, and the case where no IE is found yield the same return value.

Definition at line 812 of file event.c.

References ast_event_get_ie_raw(), and get_unaligned_uint32().

Referenced by device_state_cb(), devstate_cache_cb(), devstate_cached(), devstate_change_collector_cb(), get_cached_mwi(), has_voicemail(), match_ie_val(), mwi_sub_event_cb(), mwi_unsub_event_cb(), process_collection(), sip_send_mwi_to_peer(), unistim_send_mwi_to_peer(), and update_registry().

00813 {
00814    const uint32_t *ie_val;
00815 
00816    ie_val = ast_event_get_ie_raw(event, ie_type);
00817 
00818    return ie_val ? ntohl(get_unaligned_uint32(ie_val)) : 0;
00819 }

size_t ast_event_get_size ( const struct ast_event event  ) 

Get the size of an event.

Parameters:
event the event to get the size of
Returns:
the number of bytes contained in the event
Since:
1.6.1

Definition at line 295 of file event.c.

References ast_event::event_len.

Referenced by ast_event_dup().

00296 {
00297    size_t res;
00298 
00299    res = ntohs(event->event_len);
00300 
00301    return res;
00302 }

enum ast_event_type ast_event_get_type ( const struct ast_event event  ) 

Get the type for an event.

Parameters:
event the event to get the type for
Returns:
the event type as represented by one of the values in the ast_event_type enum

Definition at line 807 of file event.c.

Referenced by ast_event_cmp(), ast_event_dup_and_cache(), ast_event_get_type_name(), ast_event_hash(), ast_event_queue_and_cache(), mwi_sub_event_cb(), and mwi_unsub_event_cb().

00808 {
00809    return ntohs(event->type);
00810 }

const char* ast_event_get_type_name ( const struct ast_event event  ) 

Get the string representation of the type of the given event.

Returns:
the string representation of the event type of the provided event
Since:
1.6.1

Definition at line 221 of file event.c.

References ast_event_get_type(), ast_log(), event_names, LOG_ERROR, event_name::name, and ast_event_sub::type.

00222 {
00223    enum ast_event_type type;
00224 
00225    type = ast_event_get_type(event);
00226 
00227    if (type >= AST_EVENT_TOTAL || type < 0) {
00228       ast_log(LOG_ERROR, "Invalid event type - '%d'\n", type);
00229       return "";
00230    }
00231 
00232    return event_names[type].name;
00233 }

static int ast_event_hash ( const void *  obj,
const int  flags 
) [static]

Definition at line 1221 of file event.c.

References ast_event_cache, ast_event_get_type(), ast_event_ref::event, and hash_fn.

Referenced by ast_event_init().

01222 {
01223    const struct ast_event_ref *event_ref;
01224    const struct ast_event *event;
01225    ao2_hash_fn *hash_fn;
01226 
01227    event_ref = obj;
01228    event = event_ref->event;
01229 
01230    if (!(hash_fn = ast_event_cache[ast_event_get_type(event)].hash_fn)) {
01231       return 0;
01232    }
01233 
01234    return hash_fn(event, flags);
01235 }

static int ast_event_hash_devstate ( const void *  obj,
const int  flags 
) [static]

Definition at line 1198 of file event.c.

References ast_event_get_ie_str(), AST_EVENT_IE_DEVICE, and ast_str_hash().

01199 {
01200    const struct ast_event *event = obj;
01201 
01202    return ast_str_hash(ast_event_get_ie_str(event, AST_EVENT_IE_DEVICE));
01203 }

static int ast_event_hash_devstate_change ( const void *  obj,
const int  flags 
) [static]

Definition at line 1214 of file event.c.

References ast_event_get_ie_str(), AST_EVENT_IE_DEVICE, and ast_str_hash().

01215 {
01216    const struct ast_event *event = obj;
01217 
01218    return ast_str_hash(ast_event_get_ie_str(event, AST_EVENT_IE_DEVICE));
01219 }

static int ast_event_hash_mwi ( const void *  obj,
const int  flags 
) [static]

Definition at line 1180 of file event.c.

References ast_event_get_ie_str(), AST_EVENT_IE_CONTEXT, AST_EVENT_IE_MAILBOX, ast_str_hash(), ast_str_hash_add(), context, and mailbox.

01181 {
01182    const struct ast_event *event = obj;
01183    const char *mailbox = ast_event_get_ie_str(event, AST_EVENT_IE_MAILBOX);
01184    const char *context = ast_event_get_ie_str(event, AST_EVENT_IE_CONTEXT);
01185 
01186    return ast_str_hash_add(context, ast_str_hash(mailbox));
01187 }

static void ast_event_ie_val_destroy ( struct ast_event_ie_val ie_val  )  [static]

Definition at line 304 of file event.c.

References AST_EVENT_IE_PLTYPE_EXISTS, AST_EVENT_IE_PLTYPE_RAW, AST_EVENT_IE_PLTYPE_STR, AST_EVENT_IE_PLTYPE_UINT, AST_EVENT_IE_PLTYPE_UNKNOWN, ast_free, ast_event_ie_val::ie_pltype, ast_event_ie_val::payload, ast_event_ie_val::raw, and ast_event_ie_val::str.

Referenced by ast_event_sub_destroy().

00305 {
00306    switch (ie_val->ie_pltype) {
00307    case AST_EVENT_IE_PLTYPE_STR:
00308       ast_free((char *) ie_val->payload.str);
00309       break;
00310    case AST_EVENT_IE_PLTYPE_RAW:
00311       ast_free(ie_val->payload.raw);
00312       break;
00313    case AST_EVENT_IE_PLTYPE_UINT:
00314    case AST_EVENT_IE_PLTYPE_EXISTS:
00315    case AST_EVENT_IE_PLTYPE_UNKNOWN:
00316       break;
00317    }
00318 
00319    ast_free(ie_val);
00320 }

int ast_event_init ( void   ) 

Provided by event.c

Definition at line 1285 of file event.c.

References ao2_container_alloc, ast_event_cache, ast_event_cmp(), ast_event_hash(), ast_event_subs, AST_RWDLLIST_HEAD_INIT, ast_taskprocessor_get(), container, event_dispatcher, hash_fn, and NUM_CACHE_BUCKETS.

Referenced by main().

01286 {
01287    int i;
01288 
01289    for (i = 0; i < AST_EVENT_TOTAL; i++) {
01290       AST_RWDLLIST_HEAD_INIT(&ast_event_subs[i]);
01291    }
01292 
01293    for (i = 0; i < AST_EVENT_TOTAL; i++) {
01294       if (!ast_event_cache[i].hash_fn) {
01295          /* This event type is not cached. */
01296          continue;
01297       }
01298 
01299       if (!(ast_event_cache[i].container = ao2_container_alloc(NUM_CACHE_BUCKETS,
01300             ast_event_hash, ast_event_cmp))) {
01301          return -1;
01302       }
01303    }
01304 
01305    if (!(event_dispatcher = ast_taskprocessor_get("core_event_dispatcher", 0))) {
01306       return -1;
01307    }
01308 
01309    return 0;
01310 }

void* ast_event_iterator_get_ie_raw ( struct ast_event_iterator iterator  ) 

Get the value of the current IE in the iterator instance that has a raw payload.

Parameters:
iterator The iterator instance
Returns:
This returns the payload of the information element as type raw.

Definition at line 802 of file event.c.

References ast_event_iterator::ie, and ast_event_ie::ie_payload.

Referenced by ast_event_get_ie_raw().

00803 {
00804    return iterator->ie->ie_payload;
00805 }

const char* ast_event_iterator_get_ie_str ( struct ast_event_iterator iterator  ) 

Get the value of the current IE in the iterator as a string payload.

Parameters:
iterator The iterator instance
Returns:
This returns the payload of the information element as a string.

Definition at line 793 of file event.c.

References ast_event_iterator::ie, ast_event_ie::ie_payload, and ast_event_ie_str_payload::str.

00794 {
00795    const struct ast_event_ie_str_payload *str_payload;
00796 
00797    str_payload = (struct ast_event_ie_str_payload *) iterator->ie->ie_payload;
00798 
00799    return str_payload->str;
00800 }

enum ast_event_ie_type ast_event_iterator_get_ie_type ( struct ast_event_iterator iterator  ) 

Get the type of the current IE in the iterator instance.

Parameters:
iterator The iterator instance
Returns:
the ie type as represented by one of the value sin the ast_event_ie_type enum

Definition at line 783 of file event.c.

References ast_event_iterator::ie.

Referenced by ast_event_get_ie_raw().

00784 {
00785    return ntohs(iterator->ie->ie_type);
00786 }

uint32_t ast_event_iterator_get_ie_uint ( struct ast_event_iterator iterator  ) 

Get the value of the current IE in the ierator as an integer payload.

Parameters:
iterator The iterator instance
Returns:
This returns the payload of the information element as a uint.

Definition at line 788 of file event.c.

References get_unaligned_uint32(), ast_event_iterator::ie, and ast_event_ie::ie_payload.

00789 {
00790    return ntohl(get_unaligned_uint32(iterator->ie->ie_payload));
00791 }

void ast_event_iterator_init ( struct ast_event_iterator iterator,
const struct ast_event event 
)

Initialize an event iterator instance.

Parameters:
iterator The iterator instance to initialize
event The event that will be iterated through
Returns:
Nothing

Definition at line 769 of file event.c.

References ast_event_iterator::event, ast_event_iterator::event_len, ast_event::event_len, and ast_event_iterator::ie.

Referenced by ast_event_get_ie_raw().

00770 {
00771    iterator->event_len = ntohs(event->event_len);
00772    iterator->event = event;
00773    iterator->ie = (struct ast_event_ie *) ( ((char *) event) + sizeof(*event) );
00774    return;
00775 }

int ast_event_iterator_next ( struct ast_event_iterator iterator  ) 

Move iterator instance to next IE.

Parameters:
iterator The iterator instance
Return values:
0 on success
-1 if end is reached

Definition at line 777 of file event.c.

References ast_event_iterator::event, ast_event_iterator::event_len, ast_event_iterator::ie, and ast_event_ie::ie_payload_len.

Referenced by ast_event_get_ie_raw().

00778 {
00779    iterator->ie = (struct ast_event_ie *) ( ((char *) iterator->ie) + sizeof(*iterator->ie) + ntohs(iterator->ie->ie_payload_len));
00780    return ((iterator->event_len <= (((char *) iterator->ie) - ((char *) iterator->event))) ? -1 : 0);
00781 }

struct ast_event* ast_event_new ( enum ast_event_type  event_type,
  ... 
)

Create a new event.

Parameters:
event_type The type of event to create
The rest of the arguments to this function specify information elements to add to the event. They are specified in the form:
    <enum ast_event_ie_type>, [enum ast_event_ie_pltype, [payload] ]
and must end with AST_EVENT_IE_END.

If the ie_type specified is *not* AST_EVENT_IE_END, then it must be followed by a valid IE payload type. The payload type, EXISTS, should not be used here because it makes no sense to do so. So, a payload must also be specified after the IE payload type.

Returns:
This returns the event that has been created. If there is an error creating the event, NULL will be returned.
Example usage:

This creates a MWI event with 3 information elements, a mailbox which is a string, and the number of new and old messages, specified as integers.

Definition at line 897 of file event.c.

References ast_calloc, ast_eid_default, ast_event_append_ie_raw(), ast_event_append_ie_str(), ast_event_append_ie_uint(), ast_event_get_ie_raw(), AST_EVENT_IE_EID, AST_EVENT_IE_END, AST_EVENT_IE_PLTYPE_RAW, AST_EVENT_IE_PLTYPE_STR, AST_EVENT_IE_PLTYPE_UINT, AST_LIST_HEAD_NOLOCK_STATIC, AST_LIST_INSERT_TAIL, AST_LIST_TRAVERSE, ast_log(), ast_strdupa, ast_event_ie_val::ie_pltype, ast_event_ie_val::ie_type, ast_event_sub::ie_vals, LOG_WARNING, ast_event_ie_val::payload, ast_event_ie_val::raw, ast_event_ie_val::raw_datalen, ast_event_ie_val::str, and ast_event_ie_val::uint.

Referenced by ast_event_get_cached(), ast_event_unsubscribe(), devstate_event(), gen_sub_event(), notify_message(), process_collection(), and queue_mwi_event().

00898 {
00899    va_list ap;
00900    struct ast_event *event;
00901    enum ast_event_type ie_type;
00902    struct ast_event_ie_val *ie_val;
00903    AST_LIST_HEAD_NOLOCK_STATIC(ie_vals, ast_event_ie_val);
00904 
00905    /* Invalid type */
00906    if (type >= AST_EVENT_TOTAL) {
00907       ast_log(LOG_WARNING, "Someone tried to create an event of invalid "
00908          "type '%d'!\n", type);
00909       return NULL;
00910    }
00911 
00912    va_start(ap, type);
00913    for (ie_type = va_arg(ap, enum ast_event_type);
00914       ie_type != AST_EVENT_IE_END;
00915       ie_type = va_arg(ap, enum ast_event_type))
00916    {
00917       struct ast_event_ie_val *ie_value = alloca(sizeof(*ie_value));
00918       memset(ie_value, 0, sizeof(*ie_value));
00919       ie_value->ie_type = ie_type;
00920       ie_value->ie_pltype = va_arg(ap, enum ast_event_ie_pltype);
00921       if (ie_value->ie_pltype == AST_EVENT_IE_PLTYPE_UINT)
00922          ie_value->payload.uint = va_arg(ap, uint32_t);
00923       else if (ie_value->ie_pltype == AST_EVENT_IE_PLTYPE_STR)
00924          ie_value->payload.str = ast_strdupa(va_arg(ap, const char *));
00925       else if (ie_value->ie_pltype == AST_EVENT_IE_PLTYPE_RAW) {
00926          void *data = va_arg(ap, void *);
00927          size_t datalen = va_arg(ap, size_t);
00928          ie_value->payload.raw = alloca(datalen);
00929          memcpy(ie_value->payload.raw, data, datalen);
00930          ie_value->raw_datalen = datalen;
00931       }
00932       AST_LIST_INSERT_TAIL(&ie_vals, ie_value, entry);
00933    }
00934    va_end(ap);
00935 
00936    if (!(event = ast_calloc(1, sizeof(*event))))
00937       return NULL;
00938 
00939    event->type = htons(type);
00940    event->event_len = htons(sizeof(*event));
00941 
00942    AST_LIST_TRAVERSE(&ie_vals, ie_val, entry) {
00943       if (ie_val->ie_pltype == AST_EVENT_IE_PLTYPE_STR)
00944          ast_event_append_ie_str(&event, ie_val->ie_type, ie_val->payload.str);
00945       else if (ie_val->ie_pltype == AST_EVENT_IE_PLTYPE_UINT)
00946          ast_event_append_ie_uint(&event, ie_val->ie_type, ie_val->payload.uint);
00947       else if (ie_val->ie_pltype == AST_EVENT_IE_PLTYPE_RAW)
00948          ast_event_append_ie_raw(&event, ie_val->ie_type, ie_val->payload.raw, ie_val->raw_datalen);
00949 
00950       if (!event)
00951          break;
00952    }
00953 
00954    if (!ast_event_get_ie_raw(event, AST_EVENT_IE_EID)) {
00955       /* If the event is originating on this server, add the server's
00956        * entity ID to the event. */
00957       ast_event_append_ie_raw(&event, AST_EVENT_IE_EID, &ast_eid_default, sizeof(ast_eid_default));
00958    }
00959 
00960    return event;
00961 }

int ast_event_queue ( struct ast_event event  ) 

Queue an event.

Parameters:
event the event to be queued
Return values:
zero success
non-zero failure
This function queues an event to be dispatched to all of the appropriate subscribers. This function will not block while the event is being dispatched because a pool of event dispatching threads handle the event queue.

Definition at line 1150 of file event.c.

References alloc_event_ref(), ast_event_check_subscriber(), ast_event_destroy(), AST_EVENT_IE_END, AST_EVENT_SUB_NONE, ast_log(), ast_taskprocessor_push(), ast_event_ref::event, event_dispatcher, handle_event(), and LOG_WARNING.

Referenced by ast_event_queue_and_cache(), ast_event_sub_activate(), and ast_event_unsubscribe().

01151 {
01152    struct ast_event_ref *event_ref;
01153    uint16_t host_event_type;
01154 
01155    host_event_type = ntohs(event->type);
01156 
01157    /* Invalid type */
01158    if (host_event_type >= AST_EVENT_TOTAL) {
01159       ast_log(LOG_WARNING, "Someone tried to queue an event of invalid "
01160          "type '%d'!\n", host_event_type);
01161       return -1;
01162    }
01163 
01164    /* If nobody has subscribed to this event type, throw it away now */
01165    if (ast_event_check_subscriber(host_event_type, AST_EVENT_IE_END)
01166          == AST_EVENT_SUB_NONE) {
01167       ast_event_destroy(event);
01168       return 0;
01169    }
01170 
01171    if (!(event_ref = alloc_event_ref())) {
01172       return -1;
01173    }
01174 
01175    event_ref->event = event;
01176 
01177    return ast_taskprocessor_push(event_dispatcher, handle_event, event_ref);
01178 }

int ast_event_queue_and_cache ( struct ast_event event  ) 

Queue and cache an event.

Parameters:
event the event to be queued and cached
The purpose of caching events is so that the core can retain the last known information for events that represent some sort of state. That way, when code needs to find out the current state, it can query the cache.

The event API already knows which events can be cached and how to cache them.

Return values:
0 success
non-zero failure. If failure is returned, the event must be destroyed by the caller of this function.

Definition at line 1094 of file event.c.

References ao2_callback, ast_event_cache, ast_event_cmp(), ast_event_get_type(), ast_event_queue(), ast_log(), container, ast_event_ref::event, LOG_WARNING, OBJ_MULTIPLE, OBJ_NODATA, OBJ_POINTER, and OBJ_UNLINK.

Referenced by devstate_event(), notify_message(), process_collection(), and queue_mwi_event().

01095 {
01096    struct ao2_container *container;
01097    struct ast_event_ref tmp_event_ref = {
01098       .event = event,
01099    };
01100 
01101    if (!(container = ast_event_cache[ast_event_get_type(event)].container)) {
01102       ast_log(LOG_WARNING, "cache requested for non-cached event type\n");
01103       goto queue_event;
01104    }
01105 
01106    /* Remove matches from the cache */
01107    ao2_callback(container, OBJ_POINTER | OBJ_UNLINK | OBJ_MULTIPLE | OBJ_NODATA,
01108          ast_event_cmp, &tmp_event_ref);
01109 
01110 queue_event:
01111    return ast_event_queue(event);
01112 }

static void ast_event_ref_destroy ( void *  obj  )  [static]

Definition at line 968 of file event.c.

References ast_event_destroy(), and ast_event_ref::event.

Referenced by alloc_event_ref().

00969 {
00970    struct ast_event_ref *event_ref = obj;
00971 
00972    ast_event_destroy(event_ref->event);
00973 }

void ast_event_report_subs ( const struct ast_event_sub sub  ) 

Report current subscriptions to a subscription subscriber.

Returns:
nothing
This reports all of the current subscribers to a subscriber of subscribers to a specific event type. (Try saying that a few times fast).

The idea here is that it is sometimes very useful for a module to know when someone subscribes to events. However, when they first subscribe, this provides that module the ability to request the event core report to them all of the subscriptions to that event type that already exist.

Definition at line 510 of file event.c.

References ast_event_destroy(), AST_EVENT_IE_EVENTTYPE, AST_EVENT_SUB, ast_event_subs, AST_LIST_TRAVERSE, AST_RWDLLIST_RDLOCK, AST_RWDLLIST_TRAVERSE, AST_RWDLLIST_UNLOCK, ast_event_sub::cb, event_sub, gen_sub_event(), ast_event_ie_val::ie_type, ast_event_sub::ie_vals, ast_event_ie_val::payload, ast_event_sub::type, ast_event_ie_val::uint, and ast_event_sub::userdata.

Referenced by start_poll_thread().

00511 {
00512    struct ast_event *event;
00513    struct ast_event_sub *sub;
00514    enum ast_event_type event_type = -1;
00515    struct ast_event_ie_val *ie_val;
00516 
00517    if (event_sub->type != AST_EVENT_SUB)
00518       return;
00519 
00520    AST_LIST_TRAVERSE(&event_sub->ie_vals, ie_val, entry) {
00521       if (ie_val->ie_type == AST_EVENT_IE_EVENTTYPE) {
00522          event_type = ie_val->payload.uint;
00523          break;
00524       }
00525    }
00526 
00527    if (event_type == -1)
00528       return;
00529 
00530    AST_RWDLLIST_RDLOCK(&ast_event_subs[event_type]);
00531    AST_RWDLLIST_TRAVERSE(&ast_event_subs[event_type], sub, entry) {
00532       if (event_sub == sub)
00533          continue;
00534 
00535       event = gen_sub_event(sub);
00536 
00537       if (!event)
00538          continue;
00539 
00540       event_sub->cb(event, event_sub->userdata);
00541 
00542       ast_event_destroy(event);
00543    }
00544    AST_RWDLLIST_UNLOCK(&ast_event_subs[event_type]);
00545 }

int ast_event_str_to_event_type ( const char *  str,
enum ast_event_type event_type 
)

Convert a string into an event type.

Parameters:
str the string to convert
event_type an output parameter for the event type
Return values:
0 success
non-zero failure
Since:
1.6.1

Definition at line 235 of file event.c.

References ARRAY_LEN, event_names, name, and event_name::type.

00236 {
00237    int i;
00238 
00239    for (i = 0; i < ARRAY_LEN(event_names); i++) {
00240       if (strcasecmp(event_names[i].name, str))
00241          continue;
00242 
00243       *event_type = event_names[i].type;
00244       return 0;
00245    }
00246 
00247    return -1;
00248 }

int ast_event_str_to_ie_type ( const char *  str,
enum ast_event_ie_type ie_type 
)

Convert a string to an IE type.

Parameters:
str the string to convert
ie_type an output parameter for the IE type
Return values:
0 success
non-zero failure
Since:
1.6.1

Definition at line 280 of file event.c.

References ARRAY_LEN, ie_maps, ie_map::ie_type, and name.

00281 {
00282    int i;
00283 
00284    for (i = 0; i < ARRAY_LEN(ie_maps); i++) {
00285       if (strcasecmp(ie_maps[i].name, str))
00286          continue;
00287 
00288       *ie_type = ie_maps[i].ie_type;
00289       return 0;
00290    }
00291 
00292    return -1;
00293 }

int ast_event_sub_activate ( struct ast_event_sub sub  ) 

Activate a dynamically built subscription.

Parameters:
sub the subscription to activate that was allocated using ast_event_subscribe_new()
Once a dynamically built subscription has had all of the parameters added to it, it should be activated using this function.

Return values:
0 success
non-zero failure
Since:
1.6.1

Definition at line 660 of file event.c.

References ast_event_check_subscriber(), AST_EVENT_IE_END, AST_EVENT_IE_EVENTTYPE, AST_EVENT_IE_PLTYPE_UINT, ast_event_queue(), AST_EVENT_SUB, AST_EVENT_SUB_NONE, ast_event_subs, AST_RWDLLIST_INSERT_TAIL, AST_RWDLLIST_UNLOCK, AST_RWDLLIST_WRLOCK, gen_sub_event(), and ast_event_sub::type.

Referenced by ast_event_subscribe().

00661 {
00662    if (ast_event_check_subscriber(AST_EVENT_SUB,
00663       AST_EVENT_IE_EVENTTYPE, AST_EVENT_IE_PLTYPE_UINT, sub->type,
00664       AST_EVENT_IE_END) != AST_EVENT_SUB_NONE) {
00665       struct ast_event *event;
00666 
00667       event = gen_sub_event(sub);
00668 
00669       if (event)
00670          ast_event_queue(event);
00671    }
00672 
00673    AST_RWDLLIST_WRLOCK(&ast_event_subs[sub->type]);
00674    AST_RWDLLIST_INSERT_TAIL(&ast_event_subs[sub->type], sub, entry);
00675    AST_RWDLLIST_UNLOCK(&ast_event_subs[sub->type]);
00676 
00677    return 0;
00678 }

int ast_event_sub_append_ie_exists ( struct ast_event_sub sub,
enum ast_event_ie_type  ie_type 
)

Append an 'exists' parameter to a subscription.

Parameters:
sub the dynamic subscription allocated with ast_event_subscribe_new()
ie_type the information element type that must be present in the event for it to match this subscription.
Return values:
0 success
non-zero failure
Since:
1.6.1

Definition at line 588 of file event.c.

References ast_calloc, AST_EVENT_IE_MAX, AST_EVENT_IE_PLTYPE_EXISTS, AST_LIST_INSERT_TAIL, and ast_event_sub::ie_vals.

Referenced by ast_event_subscribe().

00590 {
00591    struct ast_event_ie_val *ie_val;
00592 
00593    if (ie_type < 0 || ie_type > AST_EVENT_IE_MAX)
00594       return -1;
00595 
00596    if (!(ie_val = ast_calloc(1, sizeof(*ie_val))))
00597       return -1;
00598 
00599    ie_val->ie_type = ie_type;
00600    ie_val->ie_pltype = AST_EVENT_IE_PLTYPE_EXISTS;
00601 
00602    AST_LIST_INSERT_TAIL(&sub->ie_vals, ie_val, entry);
00603 
00604    return 0;
00605 }

int ast_event_sub_append_ie_raw ( struct ast_event_sub sub,
enum ast_event_ie_type  ie_type,
void *  data,
size_t  raw_datalen 
)

Append a raw parameter to a subscription.

Parameters:
sub the dynamic subscription allocated with ast_event_subscribe_new()
ie_type the information element type for the parameter
raw the data that must be present in the event to match this subscription
Return values:
0 success
non-zero failure
Since:
1.6.1

Definition at line 633 of file event.c.

References ast_calloc, AST_EVENT_IE_MAX, AST_EVENT_IE_PLTYPE_RAW, ast_free, AST_LIST_INSERT_TAIL, ast_malloc, and ast_event_sub::ie_vals.

Referenced by ast_event_subscribe().

00635 {
00636    struct ast_event_ie_val *ie_val;
00637 
00638    if (ie_type < 0 || ie_type > AST_EVENT_IE_MAX)
00639       return -1;
00640 
00641    if (!(ie_val = ast_calloc(1, sizeof(*ie_val))))
00642       return -1;
00643 
00644    ie_val->ie_type = ie_type;
00645    ie_val->ie_pltype = AST_EVENT_IE_PLTYPE_RAW;
00646    ie_val->raw_datalen = raw_datalen;
00647 
00648    if (!(ie_val->payload.raw = ast_malloc(raw_datalen))) {
00649       ast_free(ie_val);
00650       return -1;
00651    }
00652 
00653    memcpy(ie_val->payload.raw, data, raw_datalen);
00654 
00655    AST_LIST_INSERT_TAIL(&sub->ie_vals, ie_val, entry);
00656 
00657    return 0;
00658 }

int ast_event_sub_append_ie_str ( struct ast_event_sub sub,
enum ast_event_ie_type  ie_type,
const char *  str 
)

Append a string parameter to a subscription.

Parameters:
sub the dynamic subscription allocated with ast_event_subscribe_new()
ie_type the information element type for the parameter
str the string that must be present in the event to match this subscription
Return values:
0 success
non-zero failure
Since:
1.6.1

Definition at line 607 of file event.c.

References ast_calloc, AST_EVENT_IE_MAX, AST_EVENT_IE_PLTYPE_STR, ast_free, AST_LIST_INSERT_TAIL, ast_str_hash(), ast_strdup, and ast_event_sub::ie_vals.

Referenced by ast_event_subscribe(), and handle_devstate_change().

00609 {
00610    struct ast_event_ie_val *ie_val;
00611 
00612    if (ie_type < 0 || ie_type > AST_EVENT_IE_MAX)
00613       return -1;
00614 
00615    if (!(ie_val = ast_calloc(1, sizeof(*ie_val))))
00616       return -1;
00617 
00618    ie_val->ie_type = ie_type;
00619    ie_val->ie_pltype = AST_EVENT_IE_PLTYPE_STR;
00620 
00621    if (!(ie_val->payload.str = ast_strdup(str))) {
00622       ast_free(ie_val);
00623       return -1;
00624    }
00625 
00626    ie_val->payload.hash = ast_str_hash(str);
00627 
00628    AST_LIST_INSERT_TAIL(&sub->ie_vals, ie_val, entry);
00629 
00630    return 0;
00631 }

int ast_event_sub_append_ie_uint ( struct ast_event_sub sub,
enum ast_event_ie_type  ie_type,
uint32_t  uint 
)

Append a uint parameter to a subscription.

Parameters:
sub the dynamic subscription allocated with ast_event_subscribe_new()
ie_type the information element type for the parameter
uint the value that must be present in the event to match this subscription
Return values:
0 success
non-zero failure
Since:
1.6.1

Definition at line 568 of file event.c.

References ast_calloc, AST_EVENT_IE_MAX, AST_EVENT_IE_PLTYPE_UINT, AST_LIST_INSERT_TAIL, and ast_event_sub::ie_vals.

Referenced by ast_event_subscribe().

00570 {
00571    struct ast_event_ie_val *ie_val;
00572 
00573    if (ie_type < 0 || ie_type > AST_EVENT_IE_MAX)
00574       return -1;
00575 
00576    if (!(ie_val = ast_calloc(1, sizeof(*ie_val))))
00577       return -1;
00578 
00579    ie_val->ie_type = ie_type;
00580    ie_val->payload.uint = unsigned_int;
00581    ie_val->ie_pltype = AST_EVENT_IE_PLTYPE_UINT;
00582 
00583    AST_LIST_INSERT_TAIL(&sub->ie_vals, ie_val, entry);
00584 
00585    return 0;
00586 }

void ast_event_sub_destroy ( struct ast_event_sub sub  ) 

Destroy an allocated subscription.

Parameters:
sub the subscription to destroy
This function should be used when a subscription is allocated with ast_event_subscribe_new(), but for some reason, you want to destroy it instead of activating it. This could be because of an error when reading in the configuration for the dynamically built subscription.
Since:
1.6.1

Definition at line 733 of file event.c.

References ast_event_ie_val_destroy(), ast_free, AST_LIST_REMOVE_HEAD, and ast_event_sub::ie_vals.

Referenced by ast_event_unsubscribe(), and handle_devstate_change().

00734 {
00735    struct ast_event_ie_val *ie_val;
00736 
00737    while ((ie_val = AST_LIST_REMOVE_HEAD(&sub->ie_vals, entry)))
00738       ast_event_ie_val_destroy(ie_val);
00739 
00740    ast_free(sub);
00741 }

struct ast_event_sub* ast_event_subscribe ( enum ast_event_type  event_type,
ast_event_cb_t  cb,
void *  userdata,
  ... 
)

Subscribe to events.

Parameters:
event_type The type of events to subscribe to
cb The function to be called with events
userdata data to be passed to the event callback
The rest of the arguments to this function specify additional parameters for the subscription to filter which events are passed to this subscriber. The arguments must be in sets of: and must end with AST_EVENT_IE_END.

If the ie_type specified is *not* AST_EVENT_IE_END, then it must be followed by a valid IE payload type. If the payload type specified is AST_EVENT_IE_PLTYPE_EXISTS, then the 3rd argument should not be provided. Otherwise, a payload must also be specified.

Returns:
This returns a reference to the subscription for use with un-subscribing later. If there is a failure in creating the subscription, NULL will be returned.
Example usage:

This creates a subscription to AST_EVENT_MWI events that contain an information element, AST_EVENT_IE_MAILBOX, with the same string value contained in peer->mailbox. Also, the event callback will be passed a pointer to the peer.

Definition at line 680 of file event.c.

References AST_EVENT_IE_END, AST_EVENT_IE_PLTYPE_EXISTS, AST_EVENT_IE_PLTYPE_RAW, AST_EVENT_IE_PLTYPE_STR, AST_EVENT_IE_PLTYPE_UINT, AST_EVENT_IE_PLTYPE_UNKNOWN, ast_event_sub_activate(), ast_event_sub_append_ie_exists(), ast_event_sub_append_ie_raw(), ast_event_sub_append_ie_str(), ast_event_sub_append_ie_uint(), ast_event_subscribe_new(), and str.

Referenced by add_peer_mwi_subs(), ast_enable_distributed_devstate(), build_device(), build_gateway(), build_peer(), load_module(), load_pbx(), and start_poll_thread().

00682 {
00683    va_list ap;
00684    enum ast_event_ie_type ie_type;
00685    struct ast_event_sub *sub;
00686 
00687    if (!(sub = ast_event_subscribe_new(type, cb, userdata)))
00688       return NULL;
00689 
00690    va_start(ap, userdata);
00691    for (ie_type = va_arg(ap, enum ast_event_type);
00692       ie_type != AST_EVENT_IE_END;
00693       ie_type = va_arg(ap, enum ast_event_type))
00694    {
00695       enum ast_event_ie_pltype ie_pltype;
00696 
00697       ie_pltype = va_arg(ap, enum ast_event_ie_pltype);
00698 
00699       switch (ie_pltype) {
00700       case AST_EVENT_IE_PLTYPE_UNKNOWN:
00701          break;
00702       case AST_EVENT_IE_PLTYPE_UINT:
00703       {
00704          uint32_t unsigned_int = va_arg(ap, uint32_t);
00705          ast_event_sub_append_ie_uint(sub, ie_type, unsigned_int);
00706          break;
00707       }
00708       case AST_EVENT_IE_PLTYPE_STR:
00709       {
00710          const char *str = va_arg(ap, const char *);
00711          ast_event_sub_append_ie_str(sub, ie_type, str);
00712          break;
00713       }
00714       case AST_EVENT_IE_PLTYPE_RAW:
00715       {
00716          void *data = va_arg(ap, void *);
00717          size_t data_len = va_arg(ap, size_t);
00718          ast_event_sub_append_ie_raw(sub, ie_type, data, data_len);
00719          break;
00720       }
00721       case AST_EVENT_IE_PLTYPE_EXISTS:
00722          ast_event_sub_append_ie_exists(sub, ie_type);
00723          break;
00724       }
00725    }
00726    va_end(ap);
00727 
00728    ast_event_sub_activate(sub);
00729 
00730    return sub;
00731 }

struct ast_event_sub* ast_event_subscribe_new ( enum ast_event_type  type,
ast_event_cb_t  cb,
void *  userdata 
)

Allocate a subscription, but do not activate it.

Parameters:
type the event type to subscribe to
cb the function to call when an event matches this subscription
userdata data to pass to the provided callback
This function should be used when you want to dynamically build a subscription.

Returns:
the allocated subscription, or NULL on failure
Since:
1.6.1

Definition at line 547 of file event.c.

References ast_atomic_fetchadd_int(), ast_calloc, ast_log(), and LOG_ERROR.

Referenced by ast_event_subscribe(), and handle_devstate_change().

00549 {
00550    struct ast_event_sub *sub;
00551 
00552    if (type < 0 || type >= AST_EVENT_TOTAL) {
00553       ast_log(LOG_ERROR, "%u is an invalid type!\n", type);
00554       return NULL;
00555    }
00556 
00557    if (!(sub = ast_calloc(1, sizeof(*sub))))
00558       return NULL;
00559 
00560    sub->type = type;
00561    sub->cb = cb;
00562    sub->userdata = userdata;
00563    sub->uniqueid = ast_atomic_fetchadd_int((int *) &sub_uniqueid, 1);
00564 
00565    return sub;
00566 }

struct ast_event_sub* ast_event_unsubscribe ( struct ast_event_sub event_sub  ) 

Un-subscribe from events.

Parameters:
event_sub This is the reference to the subscription returned by ast_event_subscribe.
This function will remove a subscription and free the associated data structures.

Returns:
NULL for convenience.
Version:
1.6.1 return changed to NULL

Definition at line 743 of file event.c.

References AST_DLLIST_REMOVE, ast_event_check_subscriber(), AST_EVENT_IE_END, AST_EVENT_IE_EVENTTYPE, AST_EVENT_IE_PLTYPE_UINT, AST_EVENT_IE_UNIQUEID, ast_event_new(), ast_event_queue(), ast_event_sub_destroy(), AST_EVENT_SUB_NONE, ast_event_subs, AST_EVENT_UNSUB, AST_RWDLLIST_UNLOCK, AST_RWDLLIST_WRLOCK, ast_event_sub::type, and ast_event_sub::uniqueid.

Referenced by destroy_dahdi_pvt(), destroy_mailbox(), peer_destructor(), stop_poll_thread(), and unload_module().

00744 {
00745    struct ast_event *event;
00746 
00747    AST_RWDLLIST_WRLOCK(&ast_event_subs[sub->type]);
00748    AST_DLLIST_REMOVE(&ast_event_subs[sub->type], sub, entry);
00749    AST_RWDLLIST_UNLOCK(&ast_event_subs[sub->type]);
00750 
00751    if (ast_event_check_subscriber(AST_EVENT_UNSUB,
00752       AST_EVENT_IE_EVENTTYPE, AST_EVENT_IE_PLTYPE_UINT, sub->type,
00753       AST_EVENT_IE_END) != AST_EVENT_SUB_NONE) {
00754       
00755       event = ast_event_new(AST_EVENT_UNSUB,
00756          AST_EVENT_IE_UNIQUEID,  AST_EVENT_IE_PLTYPE_UINT, sub->uniqueid,
00757          AST_EVENT_IE_EVENTTYPE, AST_EVENT_IE_PLTYPE_UINT, sub->type,
00758          AST_EVENT_IE_END);
00759 
00760       if (event)
00761          ast_event_queue(event);
00762    }
00763 
00764    ast_event_sub_destroy(sub);
00765 
00766    return NULL;
00767 }

static int dump_cache_cb ( void *  obj,
void *  arg,
int  flags 
) [static]

Definition at line 444 of file event.c.

References AST_LIST_TRAVERSE, ast_event_sub::cb, ast_event_ref::event, event_sub, ast_event_sub::ie_vals, match_ie_val(), and ast_event_sub::userdata.

Referenced by ast_event_dump_cache().

00445 {
00446    const struct ast_event_ref *event_ref = obj;
00447    const struct ast_event *event = event_ref->event;
00448    const struct ast_event_sub *event_sub = arg;
00449    struct ast_event_ie_val *ie_val = NULL;
00450 
00451    AST_LIST_TRAVERSE(&event_sub->ie_vals, ie_val, entry) {
00452       if (!match_ie_val(event, ie_val, NULL)) {
00453          break;
00454       }
00455    }
00456 
00457    if (!ie_val) {
00458       /* All parameters were matched on this cache entry, so dump it */
00459       event_sub->cb(event, event_sub->userdata);
00460    }
00461 
00462    return 0;
00463 }

static struct ast_event* gen_sub_event ( struct ast_event_sub sub  )  [static]

Definition at line 472 of file event.c.

References ast_event_append_ie_raw(), ast_event_append_ie_str(), ast_event_append_ie_uint(), AST_EVENT_IE_END, AST_EVENT_IE_EVENTTYPE, AST_EVENT_IE_EXISTS, AST_EVENT_IE_PLTYPE_EXISTS, AST_EVENT_IE_PLTYPE_RAW, AST_EVENT_IE_PLTYPE_STR, AST_EVENT_IE_PLTYPE_UINT, AST_EVENT_IE_PLTYPE_UNKNOWN, AST_EVENT_IE_UNIQUEID, ast_event_new(), AST_EVENT_SUB, AST_LIST_TRAVERSE, ast_event_ie_val::ie_pltype, ast_event_ie_val::ie_type, ast_event_sub::ie_vals, ast_event_ie_val::payload, ast_event_ie_val::raw, ast_event_ie_val::raw_datalen, ast_event_ie_val::str, ast_event_sub::type, ast_event_ie_val::uint, and ast_event_sub::uniqueid.

Referenced by ast_event_report_subs(), and ast_event_sub_activate().

00473 {
00474    struct ast_event_ie_val *ie_val;
00475    struct ast_event *event;
00476 
00477    event = ast_event_new(AST_EVENT_SUB,
00478       AST_EVENT_IE_UNIQUEID,  AST_EVENT_IE_PLTYPE_UINT, sub->uniqueid,
00479       AST_EVENT_IE_EVENTTYPE, AST_EVENT_IE_PLTYPE_UINT, sub->type,
00480       AST_EVENT_IE_END);
00481 
00482    if (!event)
00483       return NULL;
00484 
00485    AST_LIST_TRAVERSE(&sub->ie_vals, ie_val, entry) {
00486       switch (ie_val->ie_pltype) {
00487       case AST_EVENT_IE_PLTYPE_UNKNOWN:
00488          break;
00489       case AST_EVENT_IE_PLTYPE_EXISTS:
00490          ast_event_append_ie_uint(&event, AST_EVENT_IE_EXISTS, ie_val->ie_type);
00491          break;
00492       case AST_EVENT_IE_PLTYPE_UINT:
00493          ast_event_append_ie_uint(&event, ie_val->ie_type, ie_val->payload.uint);
00494          break;
00495       case AST_EVENT_IE_PLTYPE_STR:
00496          ast_event_append_ie_str(&event, ie_val->ie_type, ie_val->payload.str);
00497          break;
00498       case AST_EVENT_IE_PLTYPE_RAW:
00499          ast_event_append_ie_raw(&event, ie_val->ie_type, ie_val->payload.raw, ie_val->raw_datalen);
00500          break;
00501       }
00502       if (!event)
00503          break;
00504    }
00505 
00506    return event;
00507 }

static int handle_event ( void *  data  )  [static]

Definition at line 1114 of file event.c.

References ao2_ref, AST_EVENT_ALL, ast_event_subs, AST_LIST_TRAVERSE, AST_RWDLLIST_RDLOCK, AST_RWDLLIST_TRAVERSE, AST_RWDLLIST_UNLOCK, ast_event_sub::cb, ast_event_ref::event, ast_event_sub::ie_vals, match_ie_val(), and ast_event_sub::userdata.

Referenced by ast_event_queue(), and handle_frm().

01115 {
01116    struct ast_event_ref *event_ref = data;
01117    struct ast_event_sub *sub;
01118    uint16_t host_event_type;
01119 
01120    host_event_type = ntohs(event_ref->event->type);
01121 
01122    /* Subscribers to this specific event first */
01123    AST_RWDLLIST_RDLOCK(&ast_event_subs[host_event_type]);
01124    AST_RWDLLIST_TRAVERSE(&ast_event_subs[host_event_type], sub, entry) {
01125       struct ast_event_ie_val *ie_val;
01126       AST_LIST_TRAVERSE(&sub->ie_vals, ie_val, entry) {
01127          if (!match_ie_val(event_ref->event, ie_val, NULL)) {
01128             break;
01129          }
01130       }
01131       if (ie_val) {
01132          continue;
01133       }
01134       sub->cb(event_ref->event, sub->userdata);
01135    }
01136    AST_RWDLLIST_UNLOCK(&ast_event_subs[host_event_type]);
01137 
01138    /* Now to subscribers to all event types */
01139    AST_RWDLLIST_RDLOCK(&ast_event_subs[AST_EVENT_ALL]);
01140    AST_RWDLLIST_TRAVERSE(&ast_event_subs[AST_EVENT_ALL], sub, entry) {
01141       sub->cb(event_ref->event, sub->userdata);
01142    }
01143    AST_RWDLLIST_UNLOCK(&ast_event_subs[AST_EVENT_ALL]);
01144 
01145    ao2_ref(event_ref, -1);
01146 
01147    return 0;
01148 }

static int match_ie_val ( const struct ast_event event,
const struct ast_event_ie_val ie_val,
const struct ast_event event2 
) [static]

Definition at line 401 of file event.c.

References ast_event_get_ie_raw(), ast_event_get_ie_str(), ast_event_get_ie_str_hash(), ast_event_get_ie_uint(), AST_EVENT_IE_PLTYPE_EXISTS, AST_EVENT_IE_PLTYPE_RAW, AST_EVENT_IE_PLTYPE_STR, AST_EVENT_IE_PLTYPE_UINT, buf, ast_event_ie_val::hash, ast_event_ie_val::ie_pltype, ast_event_ie_val::ie_type, ast_event_ie_val::payload, ast_event_ie_val::raw, ast_event_ie_val::raw_datalen, ast_event_ie_val::str, str, and ast_event_ie_val::uint.

Referenced by ast_event_cmp(), dump_cache_cb(), and handle_event().

00403 {
00404    if (ie_val->ie_pltype == AST_EVENT_IE_PLTYPE_UINT) {
00405       uint32_t val = event2 ? ast_event_get_ie_uint(event2, ie_val->ie_type) : ie_val->payload.uint;
00406       if (val == ast_event_get_ie_uint(event, ie_val->ie_type))
00407          return 1;
00408       return 0;
00409    }
00410 
00411    if (ie_val->ie_pltype == AST_EVENT_IE_PLTYPE_STR) {
00412       const char *str;
00413       uint32_t hash;
00414 
00415       hash = event2 ? ast_event_get_ie_str_hash(event2, ie_val->ie_type) : ie_val->payload.hash;
00416       if (hash != ast_event_get_ie_str_hash(event, ie_val->ie_type)) {
00417          return 0;
00418       }
00419 
00420       str = event2 ? ast_event_get_ie_str(event2, ie_val->ie_type) : ie_val->payload.str;
00421       if (str && !strcmp(str, ast_event_get_ie_str(event, ie_val->ie_type))) {
00422          return 1;
00423       }
00424 
00425       return 0;
00426    }
00427 
00428    if (ie_val->ie_pltype == AST_EVENT_IE_PLTYPE_RAW) {
00429       const void *buf = event2 ? ast_event_get_ie_raw(event2, ie_val->ie_type) : ie_val->payload.raw;
00430       if (buf && !memcmp(buf, ast_event_get_ie_raw(event, ie_val->ie_type), ie_val->raw_datalen))
00431          return 1;
00432       return 0;
00433    }
00434 
00435    if (ie_val->ie_pltype == AST_EVENT_IE_PLTYPE_EXISTS) {
00436       if (ast_event_get_ie_raw(event, ie_val->ie_type))
00437          return 1;
00438       return 0;
00439    }
00440 
00441    return 0;
00442 }


Variable Documentation

struct { ... } ast_event_cache[AST_EVENT_TOTAL] [static]

Event types that are kept in the cache.

Referenced by ast_event_cmp(), ast_event_dump_cache(), ast_event_dup_and_cache(), ast_event_get_cached(), ast_event_hash(), ast_event_init(), and ast_event_queue_and_cache().

struct ast_event_sub_list ast_event_subs[AST_EVENT_TOTAL] [static]

Event subscriptions The event subscribers are indexed by which event they are subscribed to.

Referenced by ast_event_check_subscriber(), ast_event_init(), ast_event_report_subs(), ast_event_sub_activate(), ast_event_unsubscribe(), and handle_event().

enum ast_event_ie_type cache_args[MAX_CACHE_ARGS]

Information Elements used for caching.

This array is the set of information elements that will be unique among all events in the cache for this event type. When a new event gets cached, a previous event with the same values for these information elements will be replaced.

Definition at line 168 of file event.c.

Referenced by ast_event_cmp().

struct ao2_container* container

Container of cached events.

This gets allocated in ast_event_init() when Asterisk starts for the event types declared as using the cache.

Definition at line 157 of file event.c.

Referenced by ast_event_dup_and_cache(), ast_event_get_cached(), ast_event_init(), and ast_event_queue_and_cache().

struct ast_taskprocessor* event_dispatcher

Definition at line 42 of file event.c.

Referenced by ast_event_init(), and ast_event_queue().

struct event_name event_names[] [static]

The index of each entry _must_ match the event type number!

Referenced by ast_event_get_type_name(), and ast_event_str_to_event_type().

ao2_hash_fn* hash_fn

Event type specific hash function.

Definition at line 159 of file event.c.

Referenced by ast_event_hash(), and ast_event_init().

struct ie_map ie_maps[] [static]

The index of each entry _must_ match the event ie number!

Referenced by ast_event_get_ie_pltype(), ast_event_get_ie_type_name(), and ast_event_str_to_ie_type().

uint32_t sub_uniqueid [static]

Definition at line 128 of file event.c.


Generated on Fri Jul 24 00:41:42 2009 for Asterisk - the Open Source PBX by  doxygen 1.4.7