Wed Aug 11 01:08:06 2010

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"

Include dependency graph for event.c:

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_ref * alloc_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 subscribed event type.
static struct ast_event * ast_event_dup (const struct ast_event *event)
static int ast_event_dup_and_cache (const struct ast_event *event)
 Duplicate an event and add it to the cache.
struct ast_event * ast_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.
int 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.
struct ast_event * ast_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)
 Send AST_EVENT_SUB events to this subscriber of ... subscriber events.
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.
struct ast_event_sub * ast_event_subscribe (enum ast_event_type type, ast_event_cb_t cb, void *userdata,...)
 Subscribe to events.
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.
struct ast_event_sub * ast_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_event * gen_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)
static int match_ie_val_to_sub (const struct ast_event_sub *sub, const struct ast_event_ie_val *ie_val)

Variables

struct {
   enum ast_event_ie_type   cache_args [MAX_CACHE_ARGS]
 Information Elements used for caching.
   struct 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.
struct ast_taskprocessor * event_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, read]

Definition at line 1116 of file event.c.

References ao2_alloc, and ast_event_ref_destroy().

Referenced by ast_event_dup_and_cache(), and ast_event_queue().

01117 {
01118    return ao2_alloc(sizeof(struct ast_event_ref), ast_event_ref_destroy);
01119 }

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 926 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().

00928 {
00929    struct ast_event_ie *ie;
00930    unsigned int extra_len;
00931    uint16_t event_len;
00932 
00933    event_len = ntohs((*event)->event_len);
00934    extra_len = sizeof(*ie) + data_len;
00935 
00936    if (!(*event = ast_realloc(*event, event_len + extra_len)))
00937       return -1;
00938 
00939    ie = (struct ast_event_ie *) ( ((char *) *event) + event_len );
00940    ie->ie_type = htons(ie_type);
00941    ie->ie_payload_len = htons(data_len);
00942    memcpy(ie->ie_payload, data, data_len);
00943 
00944    (*event)->event_len = htons(event_len + extra_len);
00945 
00946    return 0;
00947 }

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 904 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().

00906 {
00907    struct ast_event_ie_str_payload *str_payload;
00908    size_t payload_len;
00909 
00910    payload_len = sizeof(*str_payload) + strlen(str);
00911    str_payload = alloca(payload_len);
00912 
00913    strcpy(str_payload->str, str);
00914    str_payload->hash = ast_str_hash(str);
00915 
00916    return ast_event_append_ie_raw(event, ie_type, str_payload, payload_len);
00917 }

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 919 of file event.c.

References ast_event_append_ie_raw().

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

00921 {
00922    data = htonl(data);
00923    return ast_event_append_ie_raw(event, ie_type, &data, sizeof(data));
00924 }

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 368 of file event.c.

References ARRAY_LEN, AST_EVENT_ALL, AST_EVENT_IE_END, 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, LOG_ERROR, match_ie_val_to_sub(), 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().

00369 {
00370    va_list ap;
00371    enum ast_event_ie_type ie_type;
00372    enum ast_event_subscriber_res res = AST_EVENT_SUB_NONE;
00373    struct ast_event_ie_val *ie_val;
00374    struct ast_event_sub *sub;
00375    AST_LIST_HEAD_NOLOCK_STATIC(ie_vals, ast_event_ie_val);
00376    const enum ast_event_type event_types[] = { type, AST_EVENT_ALL };
00377    int i;
00378 
00379    if (type >= AST_EVENT_TOTAL) {
00380       ast_log(LOG_ERROR, "%u is an invalid type!\n", type);
00381       return res;
00382    }
00383 
00384    va_start(ap, type);
00385    for (ie_type = va_arg(ap, enum ast_event_ie_type);
00386       ie_type != AST_EVENT_IE_END;
00387       ie_type = va_arg(ap, enum ast_event_ie_type))
00388    {
00389       struct ast_event_ie_val *ie_value = alloca(sizeof(*ie_value));
00390       memset(ie_value, 0, sizeof(*ie_value));
00391       ie_value->ie_type = ie_type;
00392       ie_value->ie_pltype = va_arg(ap, enum ast_event_ie_pltype);
00393       if (ie_value->ie_pltype == AST_EVENT_IE_PLTYPE_UINT)
00394          ie_value->payload.uint = va_arg(ap, uint32_t);
00395       else if (ie_value->ie_pltype == AST_EVENT_IE_PLTYPE_STR)
00396          ie_value->payload.str = ast_strdupa(va_arg(ap, const char *));
00397       else if (ie_value->ie_pltype == AST_EVENT_IE_PLTYPE_RAW) {
00398          void *data = va_arg(ap, void *);
00399          size_t datalen = va_arg(ap, size_t);
00400          ie_value->payload.raw = alloca(datalen);
00401          memcpy(ie_value->payload.raw, data, datalen);
00402          ie_value->raw_datalen = datalen;
00403       }
00404       AST_LIST_INSERT_TAIL(&ie_vals, ie_value, entry);
00405    }
00406    va_end(ap);
00407 
00408    for (i = 0; i < ARRAY_LEN(event_types); i++) {
00409       AST_RWDLLIST_RDLOCK(&ast_event_subs[event_types[i]]);
00410       AST_RWDLLIST_TRAVERSE(&ast_event_subs[event_types[i]], sub, entry) {
00411          AST_LIST_TRAVERSE(&ie_vals, ie_val, entry) {
00412             if (match_ie_val_to_sub(sub, ie_val)) {
00413                break;
00414             }
00415          }
00416 
00417          if (!ie_val) {
00418             /* Everything matched. */
00419             break;
00420          }
00421       }
00422       AST_RWDLLIST_UNLOCK(&ast_event_subs[event_types[i]]);
00423       if (sub) {
00424          break;
00425       }
00426    }
00427 
00428    return sub ? AST_EVENT_SUB_EXISTS : AST_EVENT_SUB_NONE;
00429 }

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

Definition at line 1306 of file event.c.

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

Referenced by ast_event_init(), and ast_event_queue_and_cache().

01307 {
01308    struct ast_event_ref *event_ref, *event_ref2;
01309    struct ast_event *event, *event2;
01310    int res = CMP_MATCH;
01311    int i;
01312    enum ast_event_ie_type *cache_args;
01313 
01314    event_ref = obj;
01315    event = event_ref->event;
01316 
01317    event_ref2 = arg;
01318    event2 = event_ref2->event;
01319 
01320    cache_args = ast_event_cache[ast_event_get_type(event)].cache_args;
01321 
01322    for (i = 0; i < ARRAY_LEN(ast_event_cache[0].cache_args) && cache_args[i]; i++) {
01323       struct ast_event_ie_val ie_val = {
01324          .ie_pltype = ast_event_get_ie_pltype(cache_args[i]),
01325          .ie_type = cache_args[i],
01326       };
01327 
01328       if (!match_ie_val(event, &ie_val, event2)) {
01329          res = 0;
01330          break;
01331       }
01332    }
01333 
01334    return res;
01335 }

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 1015 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().

01016 {
01017    ast_free(event);
01018 }

void ast_event_dump_cache ( const struct ast_event_sub *  event_sub  ) 

Dump the event cache for the subscribed event type.

Dump the event cache for the subscriber.

Definition at line 509 of file event.c.

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

Referenced by add_publish_event(), and handle_devstate_change().

00510 {
00511    ao2_callback(ast_event_cache[event_sub->type].container, OBJ_NODATA,
00512          dump_cache_cb, (void *) event_sub);
00513 }

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

Definition at line 1027 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().

01028 {
01029    struct ast_event *dup_event;
01030    uint16_t event_len;
01031 
01032    event_len = ast_event_get_size(event);
01033 
01034    if (!(dup_event = ast_calloc(1, event_len))) {
01035       return NULL;
01036    }
01037 
01038    memcpy(dup_event, event, event_len);
01039 
01040    return dup_event;
01041 }

static int 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 1123 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.

Referenced by ast_event_queue_and_cache().

01124 {
01125    struct ast_event *dup_event;
01126    struct ast_event_ref *event_ref;
01127 
01128    if (!(dup_event = ast_event_dup(event))) {
01129       return -1;
01130    }
01131 
01132    if (!(event_ref = alloc_event_ref())) {
01133       ast_event_destroy(dup_event);
01134       return -1;
01135    }
01136 
01137    event_ref->event = dup_event;
01138 
01139    ao2_link(ast_event_cache[ast_event_get_type(event)].container, event_ref);
01140 
01141    ao2_ref(event_ref, -1);
01142 
01143    return 0;
01144 }

struct ast_event* ast_event_get_cached ( enum  ast_event_type,
  ... 
) [read]

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 1043 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().

01044 {
01045    va_list ap;
01046    enum ast_event_ie_type ie_type;
01047    struct ast_event *dup_event = NULL;
01048    struct ast_event_ref *cached_event_ref;
01049    struct ast_event *cache_arg_event;
01050    struct ast_event_ref tmp_event_ref = {
01051       .event = NULL,
01052    };
01053    struct ao2_container *container = NULL;
01054 
01055    if (type >= AST_EVENT_TOTAL) {
01056       ast_log(LOG_ERROR, "%u is an invalid type!\n", type);
01057       return NULL;
01058    }
01059 
01060    if (!(container = ast_event_cache[type].container)) {
01061       ast_log(LOG_ERROR, "%u is not a cached event type\n", type);
01062       return NULL;
01063    }
01064 
01065    if (!(cache_arg_event = ast_event_new(type, AST_EVENT_IE_END))) {
01066       return NULL;
01067    }
01068 
01069    va_start(ap, type);
01070    for (ie_type = va_arg(ap, enum ast_event_ie_type);
01071       ie_type != AST_EVENT_IE_END;
01072       ie_type = va_arg(ap, enum ast_event_ie_type))
01073    {
01074       enum ast_event_ie_pltype ie_pltype;
01075 
01076       ie_pltype = va_arg(ap, enum ast_event_ie_pltype);
01077 
01078       switch (ie_pltype) {
01079       case AST_EVENT_IE_PLTYPE_UINT:
01080          ast_event_append_ie_uint(&cache_arg_event, ie_type, va_arg(ap, uint32_t));
01081          break;
01082       case AST_EVENT_IE_PLTYPE_STR:
01083          ast_event_append_ie_str(&cache_arg_event, ie_type, va_arg(ap, const char *));
01084          break;
01085       case AST_EVENT_IE_PLTYPE_RAW:
01086       {
01087          void *data = va_arg(ap, void *);
01088          size_t datalen = va_arg(ap, size_t);
01089          ast_event_append_ie_raw(&cache_arg_event, ie_type, data, datalen);
01090       }
01091       case AST_EVENT_IE_PLTYPE_EXISTS:
01092          ast_log(LOG_WARNING, "PLTYPE_EXISTS not supported by this function\n");
01093          break;
01094       case AST_EVENT_IE_PLTYPE_UNKNOWN:
01095          break;
01096       }
01097    }
01098    va_end(ap);
01099 
01100    tmp_event_ref.event = cache_arg_event;
01101 
01102    cached_event_ref = ao2_find(container, &tmp_event_ref, OBJ_POINTER);
01103 
01104    ast_event_destroy(cache_arg_event);
01105    cache_arg_event = NULL;
01106 
01107    if (cached_event_ref) {
01108       dup_event = ast_event_dup(cached_event_ref->event);
01109       ao2_ref(cached_event_ref, -1);
01110       cached_event_ref = NULL;
01111    }
01112 
01113    return dup_event;
01114 }

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.

Referenced by ast_event_cmp().

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 890 of file event.c.

References ast_event_iterator_get_ie_raw(), ast_event_iterator_get_ie_type(), ast_event_iterator_init(), and ast_event_iterator_next().

Referenced by ast_event_cb(), 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(), evt_event_deliver_cb(), and match_ie_val().

00891 {
00892    struct ast_event_iterator iterator;
00893    int res = 0;
00894 
00895    for (res = ast_event_iterator_init(&iterator, event); !res; res = ast_event_iterator_next(&iterator)) {
00896       if (ast_event_iterator_get_ie_type(&iterator) == ie_type) {
00897          return ast_event_iterator_get_ie_raw(&iterator);
00898       }
00899    }
00900 
00901    return NULL;
00902 }

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 881 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().

00882 {
00883    const struct ast_event_ie_str_payload *str_payload;
00884 
00885    str_payload = ast_event_get_ie_raw(event, ie_type);
00886 
00887    return str_payload ? str_payload->str : NULL;
00888 }

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 872 of file event.c.

References ast_event_get_ie_raw(), and ast_event_ie_str_payload::hash.

Referenced by match_ie_val().

00873 {
00874    const struct ast_event_ie_str_payload *str_payload;
00875 
00876    str_payload = ast_event_get_ie_raw(event, ie_type);
00877 
00878    return str_payload ? str_payload->hash : 0;
00879 }

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 863 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_event_cb(), mwi_sub_event_cb(), mwi_unsub_event_cb(), process_collection(), sip_send_mwi_to_peer(), unistim_send_mwi_to_peer(), and update_registry().

00864 {
00865    const uint32_t *ie_val;
00866 
00867    ie_val = ast_event_get_ie_raw(event, ie_type);
00868 
00869    return ie_val ? ntohl(get_unaligned_uint32(ie_val)) : 0;
00870 }

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_cb(), and 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 858 of file event.c.

Referenced by ast_event_cb(), 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().

00859 {
00860    return ntohs(event->type);
00861 }

const char* ast_event_get_type_name ( const struct ast_event *  event  ) 

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

  • event the event to get the type of
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 1272 of file event.c.

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

Referenced by ast_event_init().

01273 {
01274    const struct ast_event_ref *event_ref;
01275    const struct ast_event *event;
01276    ao2_hash_fn *hash_fn;
01277 
01278    event_ref = obj;
01279    event = event_ref->event;
01280 
01281    if (!(hash_fn = ast_event_cache[ast_event_get_type(event)].hash_fn)) {
01282       return 0;
01283    }
01284 
01285    return hash_fn(event, flags);
01286 }

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

Definition at line 1249 of file event.c.

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

01250 {
01251    const struct ast_event *event = obj;
01252 
01253    return ast_str_hash(ast_event_get_ie_str(event, AST_EVENT_IE_DEVICE));
01254 }

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

Definition at line 1265 of file event.c.

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

01266 {
01267    const struct ast_event *event = obj;
01268 
01269    return ast_str_hash(ast_event_get_ie_str(event, AST_EVENT_IE_DEVICE));
01270 }

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

Definition at line 1231 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.

01232 {
01233    const struct ast_event *event = obj;
01234    const char *mailbox = ast_event_get_ie_str(event, AST_EVENT_IE_MAILBOX);
01235    const char *context = ast_event_get_ie_str(event, AST_EVENT_IE_CONTEXT);
01236 
01237    return ast_str_hash_add(context, ast_str_hash(mailbox));
01238 }

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 1337 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, hash_fn, and NUM_CACHE_BUCKETS.

Referenced by main().

01338 {
01339    int i;
01340 
01341    for (i = 0; i < AST_EVENT_TOTAL; i++) {
01342       AST_RWDLLIST_HEAD_INIT(&ast_event_subs[i]);
01343    }
01344 
01345    for (i = 0; i < AST_EVENT_TOTAL; i++) {
01346       if (!ast_event_cache[i].hash_fn) {
01347          /* This event type is not cached. */
01348          continue;
01349       }
01350 
01351       if (!(ast_event_cache[i].container = ao2_container_alloc(NUM_CACHE_BUCKETS,
01352             ast_event_hash, ast_event_cmp))) {
01353          return -1;
01354       }
01355    }
01356 
01357    if (!(event_dispatcher = ast_taskprocessor_get("core_event_dispatcher", 0))) {
01358       return -1;
01359    }
01360 
01361    return 0;
01362 }

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 853 of file event.c.

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

Referenced by ast_event_get_ie_raw().

00854 {
00855    return iterator->ie->ie_payload;
00856 }

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 844 of file event.c.

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

00845 {
00846    const struct ast_event_ie_str_payload *str_payload;
00847 
00848    str_payload = (struct ast_event_ie_str_payload *) iterator->ie->ie_payload;
00849 
00850    return str_payload ? str_payload->str : NULL;
00851 }

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 834 of file event.c.

References ast_event_iterator::ie.

Referenced by ast_event_get_ie_raw().

00835 {
00836    return ntohs(iterator->ie->ie_type);
00837 }

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 839 of file event.c.

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

00840 {
00841    return ntohl(get_unaligned_uint32(iterator->ie->ie_payload));
00842 }

int 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
Return values:
0 Success, there are IEs available to iterate
-1 Failure, there are no IEs in the event to iterate

Definition at line 812 of file event.c.

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

Referenced by ast_event_get_ie_raw().

00813 {
00814    int res = 0;
00815 
00816    iterator->event_len = ntohs(event->event_len);
00817    iterator->event = event;
00818    if (iterator->event_len >= sizeof(*event) + sizeof(struct ast_event_ie)) {
00819       iterator->ie = (struct ast_event_ie *) ( ((char *) event) + sizeof(*event) );
00820    } else {
00821       iterator->ie = NULL;
00822       res = -1;
00823    }
00824 
00825    return res;
00826 }

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 828 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().

00829 {
00830    iterator->ie = (struct ast_event_ie *) ( ((char *) iterator->ie) + sizeof(*iterator->ie) + ntohs(iterator->ie->ie_payload_len));
00831    return ((iterator->event_len <= (((char *) iterator->ie) - ((char *) iterator->event))) ? -1 : 0);
00832 }

struct ast_event* ast_event_new ( enum ast_event_type  event_type,
  ... 
) [read]

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 949 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, 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(), handle_request_notify(), notify_message(), process_collection(), and queue_mwi_event().

00950 {
00951    va_list ap;
00952    struct ast_event *event;
00953    enum ast_event_ie_type ie_type;
00954    struct ast_event_ie_val *ie_val;
00955    AST_LIST_HEAD_NOLOCK_STATIC(ie_vals, ast_event_ie_val);
00956 
00957    /* Invalid type */
00958    if (type >= AST_EVENT_TOTAL) {
00959       ast_log(LOG_WARNING, "Someone tried to create an event of invalid "
00960          "type '%d'!\n", type);
00961       return NULL;
00962    }
00963 
00964    va_start(ap, type);
00965    for (ie_type = va_arg(ap, enum ast_event_ie_type);
00966       ie_type != AST_EVENT_IE_END;
00967       ie_type = va_arg(ap, enum ast_event_ie_type))
00968    {
00969       struct ast_event_ie_val *ie_value = alloca(sizeof(*ie_value));
00970       memset(ie_value, 0, sizeof(*ie_value));
00971       ie_value->ie_type = ie_type;
00972       ie_value->ie_pltype = va_arg(ap, enum ast_event_ie_pltype);
00973       if (ie_value->ie_pltype == AST_EVENT_IE_PLTYPE_UINT)
00974          ie_value->payload.uint = va_arg(ap, uint32_t);
00975       else if (ie_value->ie_pltype == AST_EVENT_IE_PLTYPE_STR)
00976          ie_value->payload.str = ast_strdupa(va_arg(ap, const char *));
00977       else if (ie_value->ie_pltype == AST_EVENT_IE_PLTYPE_RAW) {
00978          void *data = va_arg(ap, void *);
00979          size_t datalen = va_arg(ap, size_t);
00980          ie_value->payload.raw = alloca(datalen);
00981          memcpy(ie_value->payload.raw, data, datalen);
00982          ie_value->raw_datalen = datalen;
00983       }
00984       AST_LIST_INSERT_TAIL(&ie_vals, ie_value, entry);
00985    }
00986    va_end(ap);
00987 
00988    if (!(event = ast_calloc(1, sizeof(*event))))
00989       return NULL;
00990 
00991    event->type = htons(type);
00992    event->event_len = htons(sizeof(*event));
00993 
00994    AST_LIST_TRAVERSE(&ie_vals, ie_val, entry) {
00995       if (ie_val->ie_pltype == AST_EVENT_IE_PLTYPE_STR)
00996          ast_event_append_ie_str(&event, ie_val->ie_type, ie_val->payload.str);
00997       else if (ie_val->ie_pltype == AST_EVENT_IE_PLTYPE_UINT)
00998          ast_event_append_ie_uint(&event, ie_val->ie_type, ie_val->payload.uint);
00999       else if (ie_val->ie_pltype == AST_EVENT_IE_PLTYPE_RAW)
01000          ast_event_append_ie_raw(&event, ie_val->ie_type, ie_val->payload.raw, ie_val->raw_datalen);
01001 
01002       if (!event)
01003          break;
01004    }
01005 
01006    if (!ast_event_get_ie_raw(event, AST_EVENT_IE_EID)) {
01007       /* If the event is originating on this server, add the server's
01008        * entity ID to the event. */
01009       ast_event_append_ie_raw(&event, AST_EVENT_IE_EID, &ast_eid_default, sizeof(ast_eid_default));
01010    }
01011 
01012    return event;
01013 }

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. Note that the caller of this function is responsible for destroying the event in the case of a 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 the event is queued up for a dispatching thread to handle.

Definition at line 1201 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, handle_event(), and LOG_WARNING.

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

01202 {
01203    struct ast_event_ref *event_ref;
01204    uint16_t host_event_type;
01205 
01206    host_event_type = ntohs(event->type);
01207 
01208    /* Invalid type */
01209    if (host_event_type >= AST_EVENT_TOTAL) {
01210       ast_log(LOG_WARNING, "Someone tried to queue an event of invalid "
01211          "type '%d'!\n", host_event_type);
01212       return -1;
01213    }
01214 
01215    /* If nobody has subscribed to this event type, throw it away now */
01216    if (ast_event_check_subscriber(host_event_type, AST_EVENT_IE_END)
01217          == AST_EVENT_SUB_NONE) {
01218       ast_event_destroy(event);
01219       return 0;
01220    }
01221 
01222    if (!(event_ref = alloc_event_ref())) {
01223       return -1;
01224    }
01225 
01226    event_ref->event = event;
01227 
01228    return ast_taskprocessor_push(event_dispatcher, handle_event, event_ref);
01229 }

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 1146 of file event.c.

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

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

01147 {
01148    struct ao2_container *container;
01149    struct ast_event_ref tmp_event_ref = {
01150       .event = event,
01151    };
01152    int res = -1;
01153 
01154    if (!(container = ast_event_cache[ast_event_get_type(event)].container)) {
01155       ast_log(LOG_WARNING, "cache requested for non-cached event type\n");
01156       goto queue_event;
01157    }
01158 
01159    /* Remove matches from the cache */
01160    ao2_callback(container, OBJ_POINTER | OBJ_UNLINK | OBJ_MULTIPLE | OBJ_NODATA,
01161          ast_event_cmp, &tmp_event_ref);
01162 
01163    res = ast_event_dup_and_cache(event);
01164 
01165 queue_event:
01166    return ast_event_queue(event) ? -1 : res;
01167 }

static void ast_event_ref_destroy ( void *  obj  )  [static]

Definition at line 1020 of file event.c.

References ast_event_destroy(), and ast_event_ref::event.

Referenced by alloc_event_ref().

01021 {
01022    struct ast_event_ref *event_ref = obj;
01023 
01024    ast_event_destroy(event_ref->event);
01025 }

void ast_event_report_subs ( const struct ast_event_sub *  event_sub  ) 

Send AST_EVENT_SUB events to this subscriber of ... subscriber events.

Report current subscriptions to a subscription subscriber.

Definition at line 553 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, 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().

00554 {
00555    struct ast_event *event;
00556    struct ast_event_sub *sub;
00557    enum ast_event_type event_type = -1;
00558    struct ast_event_ie_val *ie_val;
00559 
00560    if (event_sub->type != AST_EVENT_SUB)
00561       return;
00562 
00563    AST_LIST_TRAVERSE(&event_sub->ie_vals, ie_val, entry) {
00564       if (ie_val->ie_type == AST_EVENT_IE_EVENTTYPE) {
00565          event_type = ie_val->payload.uint;
00566          break;
00567       }
00568    }
00569 
00570    if (event_type == -1)
00571       return;
00572 
00573    AST_RWDLLIST_RDLOCK(&ast_event_subs[event_type]);
00574    AST_RWDLLIST_TRAVERSE(&ast_event_subs[event_type], sub, entry) {
00575       if (event_sub == sub)
00576          continue;
00577 
00578       event = gen_sub_event(sub);
00579 
00580       if (!event)
00581          continue;
00582 
00583       event_sub->cb(event, event_sub->userdata);
00584 
00585       ast_event_destroy(event);
00586    }
00587    AST_RWDLLIST_UNLOCK(&ast_event_subs[event_type]);
00588 }

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 703 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().

00704 {
00705    if (ast_event_check_subscriber(AST_EVENT_SUB,
00706       AST_EVENT_IE_EVENTTYPE, AST_EVENT_IE_PLTYPE_UINT, sub->type,
00707       AST_EVENT_IE_END) != AST_EVENT_SUB_NONE) {
00708       struct ast_event *event;
00709 
00710       event = gen_sub_event(sub);
00711 
00712       if (event)
00713          ast_event_queue(event);
00714    }
00715 
00716    AST_RWDLLIST_WRLOCK(&ast_event_subs[sub->type]);
00717    AST_RWDLLIST_INSERT_TAIL(&ast_event_subs[sub->type], sub, entry);
00718    AST_RWDLLIST_UNLOCK(&ast_event_subs[sub->type]);
00719 
00720    return 0;
00721 }

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 631 of file event.c.

References ast_calloc, AST_EVENT_IE_MAX, AST_EVENT_IE_PLTYPE_EXISTS, AST_LIST_INSERT_TAIL, ast_event_ie_val::ie_pltype, ast_event_ie_val::ie_type, and ast_event_sub::ie_vals.

Referenced by ast_event_subscribe().

00633 {
00634    struct ast_event_ie_val *ie_val;
00635 
00636    if (ie_type < 0 || ie_type > AST_EVENT_IE_MAX)
00637       return -1;
00638 
00639    if (!(ie_val = ast_calloc(1, sizeof(*ie_val))))
00640       return -1;
00641 
00642    ie_val->ie_type = ie_type;
00643    ie_val->ie_pltype = AST_EVENT_IE_PLTYPE_EXISTS;
00644 
00645    AST_LIST_INSERT_TAIL(&sub->ie_vals, ie_val, entry);
00646 
00647    return 0;
00648 }

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 676 of file event.c.

References ast_calloc, AST_EVENT_IE_MAX, AST_EVENT_IE_PLTYPE_RAW, ast_free, AST_LIST_INSERT_TAIL, ast_malloc, 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, and ast_event_ie_val::raw_datalen.

Referenced by ast_event_subscribe().

00678 {
00679    struct ast_event_ie_val *ie_val;
00680 
00681    if (ie_type < 0 || ie_type > AST_EVENT_IE_MAX)
00682       return -1;
00683 
00684    if (!(ie_val = ast_calloc(1, sizeof(*ie_val))))
00685       return -1;
00686 
00687    ie_val->ie_type = ie_type;
00688    ie_val->ie_pltype = AST_EVENT_IE_PLTYPE_RAW;
00689    ie_val->raw_datalen = raw_datalen;
00690 
00691    if (!(ie_val->payload.raw = ast_malloc(raw_datalen))) {
00692       ast_free(ie_val);
00693       return -1;
00694    }
00695 
00696    memcpy(ie_val->payload.raw, data, raw_datalen);
00697 
00698    AST_LIST_INSERT_TAIL(&sub->ie_vals, ie_val, entry);
00699 
00700    return 0;
00701 }

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 650 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, ast_event_ie_val::hash, ast_event_ie_val::ie_pltype, ast_event_ie_val::ie_type, ast_event_sub::ie_vals, ast_event_ie_val::payload, and ast_event_ie_val::str.

Referenced by ast_event_subscribe(), and handle_devstate_change().

00652 {
00653    struct ast_event_ie_val *ie_val;
00654 
00655    if (ie_type < 0 || ie_type > AST_EVENT_IE_MAX)
00656       return -1;
00657 
00658    if (!(ie_val = ast_calloc(1, sizeof(*ie_val))))
00659       return -1;
00660 
00661    ie_val->ie_type = ie_type;
00662    ie_val->ie_pltype = AST_EVENT_IE_PLTYPE_STR;
00663 
00664    if (!(ie_val->payload.str = ast_strdup(str))) {
00665       ast_free(ie_val);
00666       return -1;
00667    }
00668 
00669    ie_val->payload.hash = ast_str_hash(str);
00670 
00671    AST_LIST_INSERT_TAIL(&sub->ie_vals, ie_val, entry);
00672 
00673    return 0;
00674 }

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 611 of file event.c.

References ast_calloc, AST_EVENT_IE_MAX, AST_EVENT_IE_PLTYPE_UINT, AST_LIST_INSERT_TAIL, ast_event_ie_val::ie_pltype, ast_event_ie_val::ie_type, ast_event_sub::ie_vals, ast_event_ie_val::payload, and ast_event_ie_val::uint.

Referenced by ast_event_subscribe().

00613 {
00614    struct ast_event_ie_val *ie_val;
00615 
00616    if (ie_type < 0 || ie_type > AST_EVENT_IE_MAX)
00617       return -1;
00618 
00619    if (!(ie_val = ast_calloc(1, sizeof(*ie_val))))
00620       return -1;
00621 
00622    ie_val->ie_type = ie_type;
00623    ie_val->payload.uint = unsigned_int;
00624    ie_val->ie_pltype = AST_EVENT_IE_PLTYPE_UINT;
00625 
00626    AST_LIST_INSERT_TAIL(&sub->ie_vals, ie_val, entry);
00627 
00628    return 0;
00629 }

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 776 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().

00777 {
00778    struct ast_event_ie_val *ie_val;
00779 
00780    while ((ie_val = AST_LIST_REMOVE_HEAD(&sub->ie_vals, entry)))
00781       ast_event_ie_val_destroy(ie_val);
00782 
00783    ast_free(sub);
00784 }

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

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 723 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(), add_publish_event(), ast_enable_distributed_devstate(), build_gateway(), build_peer(), config_line(), load_module(), load_pbx(), mkintf(), and start_poll_thread().

00725 {
00726    va_list ap;
00727    enum ast_event_ie_type ie_type;
00728    struct ast_event_sub *sub;
00729 
00730    if (!(sub = ast_event_subscribe_new(type, cb, userdata)))
00731       return NULL;
00732 
00733    va_start(ap, userdata);
00734    for (ie_type = va_arg(ap, enum ast_event_ie_type);
00735       ie_type != AST_EVENT_IE_END;
00736       ie_type = va_arg(ap, enum ast_event_ie_type))
00737    {
00738       enum ast_event_ie_pltype ie_pltype;
00739 
00740       ie_pltype = va_arg(ap, enum ast_event_ie_pltype);
00741 
00742       switch (ie_pltype) {
00743       case AST_EVENT_IE_PLTYPE_UNKNOWN:
00744          break;
00745       case AST_EVENT_IE_PLTYPE_UINT:
00746       {
00747          uint32_t unsigned_int = va_arg(ap, uint32_t);
00748          ast_event_sub_append_ie_uint(sub, ie_type, unsigned_int);
00749          break;
00750       }
00751       case AST_EVENT_IE_PLTYPE_STR:
00752       {
00753          const char *str = va_arg(ap, const char *);
00754          ast_event_sub_append_ie_str(sub, ie_type, str);
00755          break;
00756       }
00757       case AST_EVENT_IE_PLTYPE_RAW:
00758       {
00759          void *data = va_arg(ap, void *);
00760          size_t data_len = va_arg(ap, size_t);
00761          ast_event_sub_append_ie_raw(sub, ie_type, data, data_len);
00762          break;
00763       }
00764       case AST_EVENT_IE_PLTYPE_EXISTS:
00765          ast_event_sub_append_ie_exists(sub, ie_type);
00766          break;
00767       }
00768    }
00769    va_end(ap);
00770 
00771    ast_event_sub_activate(sub);
00772 
00773    return sub;
00774 }

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

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 590 of file event.c.

References ast_atomic_fetchadd_int(), ast_calloc, ast_log(), ast_event_sub::cb, LOG_ERROR, ast_event_sub::type, ast_event_sub::uniqueid, and ast_event_sub::userdata.

Referenced by ast_event_subscribe(), and handle_devstate_change().

00592 {
00593    struct ast_event_sub *sub;
00594 
00595    if (type < 0 || type >= AST_EVENT_TOTAL) {
00596       ast_log(LOG_ERROR, "%u is an invalid type!\n", type);
00597       return NULL;
00598    }
00599 
00600    if (!(sub = ast_calloc(1, sizeof(*sub))))
00601       return NULL;
00602 
00603    sub->type = type;
00604    sub->cb = cb;
00605    sub->userdata = userdata;
00606    sub->uniqueid = ast_atomic_fetchadd_int((int *) &sub_uniqueid, 1);
00607 
00608    return sub;
00609 }

struct ast_event_sub* ast_event_unsubscribe ( struct ast_event_sub *  event_sub  )  [read]

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 786 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_endpoint(), destroy_mailbox(), peer_destructor(), publish_event_destroy(), stop_poll_thread(), and unload_module().

00787 {
00788    struct ast_event *event;
00789 
00790    AST_RWDLLIST_WRLOCK(&ast_event_subs[sub->type]);
00791    AST_DLLIST_REMOVE(&ast_event_subs[sub->type], sub, entry);
00792    AST_RWDLLIST_UNLOCK(&ast_event_subs[sub->type]);
00793 
00794    if (ast_event_check_subscriber(AST_EVENT_UNSUB,
00795       AST_EVENT_IE_EVENTTYPE, AST_EVENT_IE_PLTYPE_UINT, sub->type,
00796       AST_EVENT_IE_END) != AST_EVENT_SUB_NONE) {
00797       
00798       event = ast_event_new(AST_EVENT_UNSUB,
00799          AST_EVENT_IE_UNIQUEID,  AST_EVENT_IE_PLTYPE_UINT, sub->uniqueid,
00800          AST_EVENT_IE_EVENTTYPE, AST_EVENT_IE_PLTYPE_UINT, sub->type,
00801          AST_EVENT_IE_END);
00802 
00803       if (event)
00804          ast_event_queue(event);
00805    }
00806 
00807    ast_event_sub_destroy(sub);
00808 
00809    return NULL;
00810 }

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

Definition at line 487 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().

00488 {
00489    const struct ast_event_ref *event_ref = obj;
00490    const struct ast_event *event = event_ref->event;
00491    const struct ast_event_sub *event_sub = arg;
00492    struct ast_event_ie_val *ie_val = NULL;
00493 
00494    AST_LIST_TRAVERSE(&event_sub->ie_vals, ie_val, entry) {
00495       if (!match_ie_val(event, ie_val, NULL)) {
00496          break;
00497       }
00498    }
00499 
00500    if (!ie_val) {
00501       /* All parameters were matched on this cache entry, so dump it */
00502       event_sub->cb(event, event_sub->userdata);
00503    }
00504 
00505    return 0;
00506 }

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

Definition at line 515 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().

00516 {
00517    struct ast_event_ie_val *ie_val;
00518    struct ast_event *event;
00519 
00520    event = ast_event_new(AST_EVENT_SUB,
00521       AST_EVENT_IE_UNIQUEID,  AST_EVENT_IE_PLTYPE_UINT, sub->uniqueid,
00522       AST_EVENT_IE_EVENTTYPE, AST_EVENT_IE_PLTYPE_UINT, sub->type,
00523       AST_EVENT_IE_END);
00524 
00525    if (!event)
00526       return NULL;
00527 
00528    AST_LIST_TRAVERSE(&sub->ie_vals, ie_val, entry) {
00529       switch (ie_val->ie_pltype) {
00530       case AST_EVENT_IE_PLTYPE_UNKNOWN:
00531          break;
00532       case AST_EVENT_IE_PLTYPE_EXISTS:
00533          ast_event_append_ie_uint(&event, AST_EVENT_IE_EXISTS, ie_val->ie_type);
00534          break;
00535       case AST_EVENT_IE_PLTYPE_UINT:
00536          ast_event_append_ie_uint(&event, ie_val->ie_type, ie_val->payload.uint);
00537          break;
00538       case AST_EVENT_IE_PLTYPE_STR:
00539          ast_event_append_ie_str(&event, ie_val->ie_type, ie_val->payload.str);
00540          break;
00541       case AST_EVENT_IE_PLTYPE_RAW:
00542          ast_event_append_ie_raw(&event, ie_val->ie_type, ie_val->payload.raw, ie_val->raw_datalen);
00543          break;
00544       }
00545       if (!event)
00546          break;
00547    }
00548 
00549    return event;
00550 }

static int handle_event ( void *  data  )  [static]

Definition at line 1169 of file event.c.

References ao2_ref, ARRAY_LEN, 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().

01170 {
01171    struct ast_event_ref *event_ref = data;
01172    struct ast_event_sub *sub;
01173    const enum ast_event_type event_types[] = {
01174       ntohs(event_ref->event->type),
01175       AST_EVENT_ALL
01176    };
01177    int i;
01178 
01179    for (i = 0; i < ARRAY_LEN(event_types); i++) {
01180       AST_RWDLLIST_RDLOCK(&ast_event_subs[event_types[i]]);
01181       AST_RWDLLIST_TRAVERSE(&ast_event_subs[event_types[i]], sub, entry) {
01182          struct ast_event_ie_val *ie_val;
01183          AST_LIST_TRAVERSE(&sub->ie_vals, ie_val, entry) {
01184             if (!match_ie_val(event_ref->event, ie_val, NULL)) {
01185                break;
01186             }
01187          }
01188          if (ie_val) {
01189             continue;
01190          }
01191          sub->cb(event_ref->event, sub->userdata);
01192       }
01193       AST_RWDLLIST_UNLOCK(&ast_event_subs[event_types[i]]);
01194    }
01195 
01196    ao2_ref(event_ref, -1);
01197 
01198    return 0;
01199 }

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 444 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().

00446 {
00447    if (ie_val->ie_pltype == AST_EVENT_IE_PLTYPE_UINT) {
00448       uint32_t val = event2 ? ast_event_get_ie_uint(event2, ie_val->ie_type) : ie_val->payload.uint;
00449       if (val == ast_event_get_ie_uint(event, ie_val->ie_type))
00450          return 1;
00451       return 0;
00452    }
00453 
00454    if (ie_val->ie_pltype == AST_EVENT_IE_PLTYPE_STR) {
00455       const char *str;
00456       uint32_t hash;
00457 
00458       hash = event2 ? ast_event_get_ie_str_hash(event2, ie_val->ie_type) : ie_val->payload.hash;
00459       if (hash != ast_event_get_ie_str_hash(event, ie_val->ie_type)) {
00460          return 0;
00461       }
00462 
00463       str = event2 ? ast_event_get_ie_str(event2, ie_val->ie_type) : ie_val->payload.str;
00464       if (str && !strcmp(str, ast_event_get_ie_str(event, ie_val->ie_type))) {
00465          return 1;
00466       }
00467 
00468       return 0;
00469    }
00470 
00471    if (ie_val->ie_pltype == AST_EVENT_IE_PLTYPE_RAW) {
00472       const void *buf = event2 ? ast_event_get_ie_raw(event2, ie_val->ie_type) : ie_val->payload.raw;
00473       if (buf && !memcmp(buf, ast_event_get_ie_raw(event, ie_val->ie_type), ie_val->raw_datalen))
00474          return 1;
00475       return 0;
00476    }
00477 
00478    if (ie_val->ie_pltype == AST_EVENT_IE_PLTYPE_EXISTS) {
00479       if (ast_event_get_ie_raw(event, ie_val->ie_type))
00480          return 1;
00481       return 0;
00482    }
00483 
00484    return 0;
00485 }

static int match_ie_val_to_sub ( const struct ast_event_sub *  sub,
const struct ast_event_ie_val *  ie_val 
) [static]

Definition at line 332 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_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, and ast_event_ie_val::uint.

Referenced by ast_event_check_subscriber().

00333 {
00334    const struct ast_event_ie_val *sub_ie_val;
00335    int res = 1;
00336 
00337    AST_LIST_TRAVERSE(&sub->ie_vals, sub_ie_val, entry) {
00338       if (sub_ie_val->ie_type == ie_val->ie_type) {
00339          break;
00340       }
00341    }
00342 
00343    if (!sub_ie_val) {
00344       /* This subscriber doesn't care about this IE, so consider
00345        * it matched. */
00346       return 1;
00347    }
00348 
00349    switch (ie_val->ie_pltype) {
00350    case AST_EVENT_IE_PLTYPE_UINT:
00351       res = (ie_val->payload.uint != sub_ie_val->payload.uint);
00352       break;
00353    case AST_EVENT_IE_PLTYPE_STR:
00354       res = strcmp(ie_val->payload.str, sub_ie_val->payload.str);
00355       break;
00356    case AST_EVENT_IE_PLTYPE_RAW:
00357       res = memcmp(ie_val->payload.raw,
00358             sub_ie_val->payload.raw, ie_val->raw_datalen);
00359       break;
00360    case AST_EVENT_IE_PLTYPE_EXISTS:
00361    case AST_EVENT_IE_PLTYPE_UNKNOWN:
00362       break;
00363    }
00364 
00365    return res;
00366 }


Variable Documentation

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

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().

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().

Definition at line 42 of file event.c.

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().

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 Wed Aug 11 01:08:07 2010 for Asterisk - the Open Source PBX by  doxygen 1.5.9