Fri Feb 10 06:36:01 2012

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 "asterisk/cli.h"

Include dependency graph for event.c:

Go to the source code of this file.

Data Structures

struct  ast_ev_check_list
 Subscription event check list. More...
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  ie_map
 IE payload types and names. More...

Defines

#define MAX_CACHE_ARGS   8
#define NUM_CACHE_BUCKETS   563

Functions

static struct ast_event_refalloc_event_ref (void)
int ast_event_append_eid (struct ast_event **event)
 Append the global EID IE.
int ast_event_append_ie_bitflags (struct ast_event **event, enum ast_event_ie_type ie_type, uint32_t flags)
 Append an information element that has a bitflags payload.
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_eventast_event_dup (const struct ast_event *event)
struct ast_eventast_event_get_cached (enum ast_event_type type,...)
 Retrieve an event from the cache.
uint32_t ast_event_get_ie_bitflags (const struct ast_event *event, enum ast_event_ie_type ie_type)
 Get the value of an information element that has a bitflags payload.
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.
uint16_t ast_event_get_ie_raw_payload_len (const struct ast_event *event, enum ast_event_ie_type ie_type)
 Get the length of the raw payload for a particular IE.
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)
uint32_t ast_event_iterator_get_ie_bitflags (struct ast_event_iterator *iterator)
 Get the value of the current IE in the iterator as a bitflags payload.
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.
uint16_t ast_event_iterator_get_ie_raw_payload_len (struct ast_event_iterator *iterator)
 Get the length of the raw payload for the current IE for an iterator.
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 iterator 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.
size_t ast_event_minimum_length (void)
 Get the minimum length of an ast_event.
struct 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)
 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_bitflags (struct ast_event_sub *sub, enum ast_event_ie_type ie_type, uint32_t flags)
 Append a bitflags parameter to a 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_subast_event_subscribe (enum ast_event_type type, ast_event_cb_t cb, const char *description, void *userdata,...)
 Subscribe to events.
struct 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.
const char * ast_event_subscriber_get_description (struct ast_event_sub *sub)
 Get description for a subscription.
struct 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 void dump_raw_ie (struct ast_event_iterator *i, struct ast_cli_args *a)
static char * event_dump_cache (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static int event_dump_cli (void *obj, void *arg, int flags)
static void event_update_cache (struct ao2_container *cache, struct ast_event *event)
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)
static int match_sub_ie_val_to_event (const struct ast_event_ie_val *sub_ie_val, const struct ast_ev_check_list *check_ie_vals)

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.
static const char *const cached_event_types [] = { "MWI", "DeviceState", "DeviceStateChange", NULL }
 Names of cached event types, for CLI tab completion.
static struct ast_cli_entry event_cli []
static struct ast_taskprocessorevent_dispatcher
static const char *const event_names [AST_EVENT_TOTAL]
 Event Names.
static struct ie_map ie_maps [AST_EVENT_IE_TOTAL]
 IE payload types and names.
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 147 of file event.c.

#define NUM_CACHE_BUCKETS   563

Definition at line 144 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 1382 of file event.c.

References ao2_alloc, and ast_event_ref_destroy().

Referenced by ast_event_queue(), and event_update_cache().

01383 {
01384    return ao2_alloc(sizeof(struct ast_event_ref), ast_event_ref_destroy);
01385 }

int ast_event_append_eid ( struct ast_event **  event  ) 

Append the global EID IE.

Parameters:
event the event to append IE to
Note:
For ast_event_new() that includes IEs, this is done automatically for you.
Return values:
0 success
-1 failure

Definition at line 1271 of file event.c.

References ast_eid_default, ast_event_append_ie_raw(), and AST_EVENT_IE_EID.

Referenced by ast_event_new().

01272 {
01273    return ast_event_append_ie_raw(event, AST_EVENT_IE_EID,
01274          &ast_eid_default, sizeof(ast_eid_default));
01275 }

int ast_event_append_ie_bitflags ( struct ast_event **  event,
enum ast_event_ie_type  ie_type,
uint32_t  bitflags 
)

Append an information element that has a bitflags payload.

Parameters:
event the event that the IE will be appended to
ie_type the type of IE to append
bitflags the flags that are the payload of the IE
Return values:
0 success
-1 failure
Since:
1.8
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 1135 of file event.c.

References ast_event_append_ie_raw().

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

01137 {
01138    flags = htonl(flags);
01139    return ast_event_append_ie_raw(event, ie_type, &flags, sizeof(flags));
01140 }

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

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

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

01144 {
01145    struct ast_event_ie *ie;
01146    unsigned int extra_len;
01147    uint16_t event_len;
01148 
01149    event_len = ntohs((*event)->event_len);
01150    extra_len = sizeof(*ie) + data_len;
01151 
01152    if (!(*event = ast_realloc(*event, event_len + extra_len))) {
01153       return -1;
01154    }
01155 
01156    ie = (struct ast_event_ie *) ( ((char *) *event) + event_len );
01157    ie->ie_type = htons(ie_type);
01158    ie->ie_payload_len = htons(data_len);
01159    memcpy(ie->ie_payload, data, data_len);
01160 
01161    (*event)->event_len = htons(event_len + extra_len);
01162 
01163    return 0;
01164 }

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 1113 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 add_ie(), add_ipv4_ie(), add_timeval_ie(), ast_event_get_cached(), ast_event_new(), and gen_sub_event().

01115 {
01116    struct ast_event_ie_str_payload *str_payload;
01117    size_t payload_len;
01118 
01119    payload_len = sizeof(*str_payload) + strlen(str);
01120    str_payload = alloca(payload_len);
01121 
01122    strcpy(str_payload->str, str);
01123    str_payload->hash = ast_str_hash(str);
01124 
01125    return ast_event_append_ie_raw(event, ie_type, str_payload, payload_len);
01126 }

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

References ast_event_append_ie_raw().

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

01130 {
01131    data = htonl(data);
01132    return ast_event_append_ie_raw(event, ie_type, &data, sizeof(data));
01133 }

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

References ARRAY_LEN, AST_EVENT_ALL, AST_EVENT_IE_END, AST_EVENT_IE_PLTYPE_BITFLAGS, 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_EXISTS, AST_EVENT_SUB_NONE, ast_event_subs, AST_LIST_HEAD_NOLOCK_INIT_VALUE, AST_LIST_INSERT_TAIL, AST_LIST_TRAVERSE, ast_log(), AST_RWDLLIST_RDLOCK, AST_RWDLLIST_TRAVERSE, AST_RWDLLIST_UNLOCK, AST_RWLIST_FIRST, event_types, ast_event_ie_val::ie_pltype, ast_event_ie_val::ie_type, ast_event_sub::ie_vals, ast_ev_check_list::ie_vals, LOG_ERROR, LOG_WARNING, match_sub_ie_val_to_event(), ast_event_ie_val::payload, ast_event_ie_val::raw, ast_event_ie_val::raw_datalen, ast_event_ie_val::str, sub, and ast_event_ie_val::uint.

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

00440 {
00441    va_list ap;
00442    enum ast_event_ie_type ie_type;
00443    enum ast_event_subscriber_res res = AST_EVENT_SUB_NONE;
00444    struct ast_event_ie_val *ie_val;
00445    struct ast_event_sub *sub;
00446    struct ast_ev_check_list check_ie_vals = {
00447       .ie_vals = AST_LIST_HEAD_NOLOCK_INIT_VALUE
00448    };
00449    const enum ast_event_type event_types[] = { type, AST_EVENT_ALL };
00450    int i;
00451    int want_specific_event;/* TRUE if looking for subscribers wanting specific parameters. */
00452 
00453    if (type >= AST_EVENT_TOTAL) {
00454       ast_log(LOG_ERROR, "%u is an invalid type!\n", type);
00455       return res;
00456    }
00457 
00458    want_specific_event = 0;
00459    va_start(ap, type);
00460    for (ie_type = va_arg(ap, enum ast_event_ie_type);
00461       ie_type != AST_EVENT_IE_END;
00462       ie_type = va_arg(ap, enum ast_event_ie_type))
00463    {
00464       struct ast_event_ie_val *ie_value = alloca(sizeof(*ie_value));
00465       int insert = 0;
00466 
00467       memset(ie_value, 0, sizeof(*ie_value));
00468       ie_value->ie_type = ie_type;
00469       ie_value->ie_pltype = va_arg(ap, enum ast_event_ie_pltype);
00470       switch (ie_value->ie_pltype) {
00471       case AST_EVENT_IE_PLTYPE_UINT:
00472          ie_value->payload.uint = va_arg(ap, uint32_t);
00473          insert = 1;
00474          break;
00475       case AST_EVENT_IE_PLTYPE_BITFLAGS:
00476          ie_value->payload.uint = va_arg(ap, uint32_t);
00477          insert = 1;
00478          break;
00479       case AST_EVENT_IE_PLTYPE_STR:
00480          ie_value->payload.str = va_arg(ap, const char *);
00481          insert = 1;
00482          break;
00483       case AST_EVENT_IE_PLTYPE_RAW:
00484       {
00485          void *data = va_arg(ap, void *);
00486          size_t datalen = va_arg(ap, size_t);
00487 
00488          ie_value->payload.raw = alloca(datalen);
00489          memcpy(ie_value->payload.raw, data, datalen);
00490          ie_value->raw_datalen = datalen;
00491          insert = 1;
00492          break;
00493       }
00494       case AST_EVENT_IE_PLTYPE_UNKNOWN:
00495       case AST_EVENT_IE_PLTYPE_EXISTS:
00496          /* Unsupported payload type. */
00497          break;
00498       }
00499 
00500       if (insert) {
00501          want_specific_event = 1;
00502          AST_LIST_INSERT_TAIL(&check_ie_vals.ie_vals, ie_value, entry);
00503       } else {
00504          ast_log(LOG_WARNING, "Unsupported PLTYPE(%d)\n", ie_value->ie_pltype);
00505       }
00506    }
00507    va_end(ap);
00508 
00509    for (i = 0; i < ARRAY_LEN(event_types); i++) {
00510       AST_RWDLLIST_RDLOCK(&ast_event_subs[event_types[i]]);
00511       if (want_specific_event) {
00512          AST_RWDLLIST_TRAVERSE(&ast_event_subs[event_types[i]], sub, entry) {
00513             AST_LIST_TRAVERSE(&sub->ie_vals, ie_val, entry) {
00514                if (!match_sub_ie_val_to_event(ie_val, &check_ie_vals)) {
00515                   /* The current subscription ie did not match an event ie. */
00516                   break;
00517                }
00518             }
00519             if (!ie_val) {
00520                /* Everything matched.  A subscriber is looking for this event. */
00521                break;
00522             }
00523          }
00524       } else {
00525          /* Just looking to see if there are ANY subscribers to the event type. */
00526          sub = AST_RWLIST_FIRST(&ast_event_subs[event_types[i]]);
00527       }
00528       AST_RWDLLIST_UNLOCK(&ast_event_subs[event_types[i]]);
00529       if (sub) {
00530          break;
00531       }
00532    }
00533 
00534    return sub ? AST_EVENT_SUB_EXISTS : AST_EVENT_SUB_NONE;
00535 }

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

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

01592 {
01593    struct ast_event_ref *event_ref, *event_ref2;
01594    struct ast_event *event, *event2;
01595    int res = CMP_MATCH;
01596    int i;
01597    enum ast_event_ie_type *cache_args;
01598 
01599    event_ref = obj;
01600    event = event_ref->event;
01601 
01602    event_ref2 = arg;
01603    event2 = event_ref2->event;
01604 
01605    cache_args = ast_event_cache[ast_event_get_type(event)].cache_args;
01606 
01607    for (i = 0; i < ARRAY_LEN(ast_event_cache[0].cache_args) && cache_args[i]; i++) {
01608       struct ast_event_ie_val ie_val = {
01609          .ie_pltype = ast_event_get_ie_pltype(cache_args[i]),
01610          .ie_type = cache_args[i],
01611       };
01612 
01613       if (!match_ie_val(event, &ie_val, event2)) {
01614          res = 0;
01615          break;
01616       }
01617    }
01618 
01619    return res;
01620 }

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

References ast_free.

Referenced by ast_cel_report_event(), ast_event_get_cached(), ast_event_queue(), ast_event_queue_and_cache(), ast_event_ref_destroy(), ast_event_report_subs(), ast_event_sub_activate(), ast_event_unsubscribe(), devstate_cached(), event_update_cache(), get_cached_mwi(), handle_security_event(), has_voicemail(), process_collection(), stun_monitor_request(), unistim_send_mwi_to_peer(), and update_registry().

01278 {
01279    ast_free(event);
01280 }

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

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

Referenced by aji_init_event_distribution(), cpg_confchg_cb(), and handle_devstate_change().

00635 {
00636    ao2_callback(ast_event_cache[event_sub->type].container, OBJ_NODATA,
00637          dump_cache_cb, (void *) event_sub);
00638 }

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

Definition at line 1289 of file event.c.

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

Referenced by ast_event_get_cached(), and event_update_cache().

01290 {
01291    struct ast_event *dup_event;
01292    uint16_t event_len;
01293 
01294    event_len = ast_event_get_size(event);
01295 
01296    if (!(dup_event = ast_calloc(1, event_len))) {
01297       return NULL;
01298    }
01299 
01300    memcpy(dup_event, event, event_len);
01301 
01302    return dup_event;
01303 }

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

References ao2_find, ao2_ref, ast_event_append_ie_bitflags(), 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_BITFLAGS, 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().

01306 {
01307    va_list ap;
01308    enum ast_event_ie_type ie_type;
01309    struct ast_event *dup_event = NULL;
01310    struct ast_event_ref *cached_event_ref;
01311    struct ast_event *cache_arg_event;
01312    struct ast_event_ref tmp_event_ref = {
01313       .event = NULL,
01314    };
01315    struct ao2_container *container = NULL;
01316 
01317    if (type >= AST_EVENT_TOTAL) {
01318       ast_log(LOG_ERROR, "%u is an invalid type!\n", type);
01319       return NULL;
01320    }
01321 
01322    if (!(container = ast_event_cache[type].container)) {
01323       ast_log(LOG_ERROR, "%u is not a cached event type\n", type);
01324       return NULL;
01325    }
01326 
01327    if (!(cache_arg_event = ast_event_new(type, AST_EVENT_IE_END))) {
01328       return NULL;
01329    }
01330 
01331    va_start(ap, type);
01332    for (ie_type = va_arg(ap, enum ast_event_ie_type);
01333       ie_type != AST_EVENT_IE_END;
01334       ie_type = va_arg(ap, enum ast_event_ie_type))
01335    {
01336       enum ast_event_ie_pltype ie_pltype;
01337 
01338       ie_pltype = va_arg(ap, enum ast_event_ie_pltype);
01339 
01340       switch (ie_pltype) {
01341       case AST_EVENT_IE_PLTYPE_UINT:
01342          ast_event_append_ie_uint(&cache_arg_event, ie_type, va_arg(ap, uint32_t));
01343          break;
01344       case AST_EVENT_IE_PLTYPE_BITFLAGS:
01345          ast_event_append_ie_bitflags(&cache_arg_event, ie_type, va_arg(ap, uint32_t));
01346          break;
01347       case AST_EVENT_IE_PLTYPE_STR:
01348          ast_event_append_ie_str(&cache_arg_event, ie_type, va_arg(ap, const char *));
01349          break;
01350       case AST_EVENT_IE_PLTYPE_RAW:
01351       {
01352          void *data = va_arg(ap, void *);
01353          size_t datalen = va_arg(ap, size_t);
01354          ast_event_append_ie_raw(&cache_arg_event, ie_type, data, datalen);
01355          break;
01356       }
01357       case AST_EVENT_IE_PLTYPE_EXISTS:
01358          ast_log(LOG_WARNING, "PLTYPE_EXISTS not supported by this function\n");
01359          break;
01360       case AST_EVENT_IE_PLTYPE_UNKNOWN:
01361          break;
01362       }
01363    }
01364    va_end(ap);
01365 
01366    tmp_event_ref.event = cache_arg_event;
01367 
01368    cached_event_ref = ao2_find(container, &tmp_event_ref, OBJ_POINTER);
01369 
01370    ast_event_destroy(cache_arg_event);
01371    cache_arg_event = NULL;
01372 
01373    if (cached_event_ref) {
01374       dup_event = ast_event_dup(cached_event_ref->event);
01375       ao2_ref(cached_event_ref, -1);
01376       cached_event_ref = NULL;
01377    }
01378 
01379    return dup_event;
01380 }

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

Get the value of an information element that has a bitflags 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 1058 of file event.c.

References ast_event_get_ie_raw(), and get_unaligned_uint32().

Referenced by append_ie(), and match_ie_val().

01059 {
01060    const uint32_t *ie_val;
01061 
01062    ie_val = ast_event_get_ie_raw(event, ie_type);
01063 
01064    return ie_val ? ntohl(get_unaligned_uint32(ie_val)) : 0;
01065 }

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

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

Referenced by append_ie(), ast_event_cmp(), and event_dump_cli().

00314 {
00315    if (ie_type <= 0 || ie_type >= ARRAY_LEN(ie_maps)) {
00316       ast_log(LOG_ERROR, "Invalid IE type - '%d'\n", ie_type);
00317       return AST_EVENT_IE_PLTYPE_UNKNOWN;
00318    }
00319 
00320    return ie_maps[ie_type].ie_pltype;
00321 }

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 1085 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 aji_devstate_cb(), aji_mwi_cb(), ast_event_cb(), ast_event_get_ie_bitflags(), ast_event_get_ie_str(), ast_event_get_ie_str_hash(), ast_event_get_ie_uint(), ast_event_new(), cpg_deliver_cb(), devstate_cache_cb(), devstate_change_collector_cb(), ie_is_present(), and match_ie_val().

01086 {
01087    struct ast_event_iterator iterator;
01088    int res;
01089 
01090    for (res = ast_event_iterator_init(&iterator, event); !res; res = ast_event_iterator_next(&iterator)) {
01091       if (ast_event_iterator_get_ie_type(&iterator) == ie_type) {
01092          return ast_event_iterator_get_ie_raw(&iterator);
01093       }
01094    }
01095 
01096    return NULL;
01097 }

uint16_t ast_event_get_ie_raw_payload_len ( const struct ast_event event,
enum ast_event_ie_type  ie_type 
)

Get the length of the raw payload for a particular IE.

Parameters:
event The event to get the IE payload length from
ie_type the type of information element to get the length of
Returns:
If an IE of type ie_type is found, its payload length is returned. Otherwise, 0 is returned.

Definition at line 1099 of file event.c.

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

Referenced by match_ie_val().

01100 {
01101    struct ast_event_iterator iterator;
01102    int res;
01103 
01104    for (res = ast_event_iterator_init(&iterator, event); !res; res = ast_event_iterator_next(&iterator)) {
01105       if (ast_event_iterator_get_ie_type(&iterator) == ie_type) {
01106          return ast_event_iterator_get_ie_raw_payload_len(&iterator);
01107       }
01108    }
01109 
01110    return 0;
01111 }

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

References ast_event_get_ie_raw(), and ast_event_ie_str_payload::str.

Referenced by aji_devstate_cb(), aji_mwi_cb(), append_ie(), ast_cel_fill_record(), ast_event_hash_devstate(), ast_event_hash_devstate_change(), ast_event_hash_mwi(), device_state_cb(), devstate_change_collector_cb(), generic_monitor_devstate_cb(), match_ie_val(), mwi_sub_event_cb(), and print_cel_sub().

01077 {
01078    const struct ast_event_ie_str_payload *str_payload;
01079 
01080    str_payload = ast_event_get_ie_raw(event, ie_type);
01081 
01082    return str_payload ? str_payload->str : NULL;
01083 }

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

References ast_event_get_ie_raw(), and ast_event_ie_str_payload::hash.

Referenced by match_ie_val().

01068 {
01069    const struct ast_event_ie_str_payload *str_payload;
01070 
01071    str_payload = ast_event_get_ie_raw(event, ie_type);
01072 
01073    return str_payload ? str_payload->hash : 0;
01074 }

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

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

Referenced by append_ie(), dump_raw_ie(), event_dump_cache(), event_dump_cli(), and security_event_cb().

00304 {
00305    if (ie_type <= 0 || ie_type >= ARRAY_LEN(ie_maps)) {
00306       ast_log(LOG_ERROR, "Invalid IE type - '%d'\n", ie_type);
00307       return "";
00308    }
00309 
00310    return ie_maps[ie_type].name;
00311 }

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

References ast_event_get_ie_raw(), and get_unaligned_uint32().

Referenced by aji_devstate_cb(), aji_mwi_cb(), append_ie(), ast_cel_fill_record(), device_state_cb(), devstate_cache_cb(), devstate_cached(), devstate_change_collector_cb(), generic_agent_devstate_cb(), generic_monitor_devstate_cb(), get_cached_mwi(), has_voicemail(), match_ie_val(), mwi_event_cb(), mwi_sub_event_cb(), mwi_unsub_event_cb(), process_collection(), security_event_cb(), unistim_send_mwi_to_peer(), and update_registry().

01050 {
01051    const uint32_t *ie_val;
01052 
01053    ie_val = ast_event_get_ie_raw(event, ie_type);
01054 
01055    return ie_val ? ntohl(get_unaligned_uint32(ie_val)) : 0;
01056 }

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

References ast_event::event_len.

Referenced by ast_event_cb(), ast_event_dup(), and ast_event_iterator_init().

00340 {
00341    size_t res;
00342 
00343    res = ntohs(event->event_len);
00344 
00345    return res;
00346 }

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

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

01045 {
01046    return ntohs(event->type);
01047 }

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

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

Referenced by event_dump_cli().

00274 {
00275    enum ast_event_type type;
00276 
00277    type = ast_event_get_type(event);
00278 
00279    if (type < 0 || type >= ARRAY_LEN(event_names)) {
00280       ast_log(LOG_ERROR, "Invalid event type - '%d'\n", type);
00281       return "";
00282    }
00283 
00284    return event_names[type];
00285 }

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

Definition at line 1557 of file event.c.

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

Referenced by ast_event_init().

01558 {
01559    const struct ast_event_ref *event_ref;
01560    const struct ast_event *event;
01561    ao2_hash_fn *hash_fn;
01562 
01563    event_ref = obj;
01564    event = event_ref->event;
01565 
01566    if (!(hash_fn = ast_event_cache[ast_event_get_type(event)].hash_fn)) {
01567       return 0;
01568    }
01569 
01570    return hash_fn(event, flags);
01571 }

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

Definition at line 1534 of file event.c.

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

01535 {
01536    const struct ast_event *event = obj;
01537 
01538    return ast_str_hash(ast_event_get_ie_str(event, AST_EVENT_IE_DEVICE));
01539 }

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

Definition at line 1550 of file event.c.

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

01551 {
01552    const struct ast_event *event = obj;
01553 
01554    return ast_str_hash(ast_event_get_ie_str(event, AST_EVENT_IE_DEVICE));
01555 }

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

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

01517 {
01518    const struct ast_event *event = obj;
01519    const char *mailbox = ast_event_get_ie_str(event, AST_EVENT_IE_MAILBOX);
01520    const char *context = ast_event_get_ie_str(event, AST_EVENT_IE_CONTEXT);
01521 
01522    return ast_str_hash_add(context, ast_str_hash(mailbox));
01523 }

static void ast_event_ie_val_destroy ( struct ast_event_ie_val ie_val  )  [static]

int ast_event_init ( void   ) 

Provided by event.c

Definition at line 1748 of file event.c.

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

Referenced by main().

01749 {
01750    int i;
01751 
01752    for (i = 0; i < AST_EVENT_TOTAL; i++) {
01753       AST_RWDLLIST_HEAD_INIT(&ast_event_subs[i]);
01754    }
01755 
01756    for (i = 0; i < AST_EVENT_TOTAL; i++) {
01757       if (!ast_event_cache[i].hash_fn) {
01758          /* This event type is not cached. */
01759          continue;
01760       }
01761 
01762       if (!(ast_event_cache[i].container = ao2_container_alloc(NUM_CACHE_BUCKETS,
01763             ast_event_hash, ast_event_cmp))) {
01764          return -1;
01765       }
01766    }
01767 
01768    if (!(event_dispatcher = ast_taskprocessor_get("core_event_dispatcher", 0))) {
01769       return -1;
01770    }
01771 
01772    ast_cli_register_multiple(event_cli, ARRAY_LEN(event_cli));
01773 
01774    return 0;
01775 }

uint32_t ast_event_iterator_get_ie_bitflags ( struct ast_event_iterator iterator  ) 

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

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

Definition at line 1020 of file event.c.

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

Referenced by event_dump_cli().

01021 {
01022    return ntohl(get_unaligned_uint32(iterator->ie->ie_payload));
01023 }

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

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

Referenced by ast_event_get_ie_raw(), and dump_raw_ie().

01035 {
01036    return iterator->ie->ie_payload;
01037 }

uint16_t ast_event_iterator_get_ie_raw_payload_len ( struct ast_event_iterator iterator  ) 

Get the length of the raw payload for the current IE for an iterator.

Parameters:
iterator The IE iterator
Returns:
The payload length of the current IE

Definition at line 1039 of file event.c.

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

Referenced by ast_event_get_ie_raw_payload_len().

01040 {
01041    return ntohs(iterator->ie->ie_payload_len);
01042 }

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

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

Referenced by event_dump_cli().

01026 {
01027    const struct ast_event_ie_str_payload *str_payload;
01028 
01029    str_payload = (struct ast_event_ie_str_payload *) iterator->ie->ie_payload;
01030 
01031    return str_payload ? str_payload->str : NULL;
01032 }

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

References ast_event_iterator::ie.

Referenced by ast_event_get_ie_raw(), ast_event_get_ie_raw_payload_len(), dump_raw_ie(), and event_dump_cli().

01011 {
01012    return ntohs(iterator->ie->ie_type);
01013 }

uint32_t ast_event_iterator_get_ie_uint ( struct ast_event_iterator iterator  ) 

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

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

Definition at line 1015 of file event.c.

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

Referenced by event_dump_cli().

01016 {
01017    return ntohl(get_unaligned_uint32(iterator->ie->ie_payload));
01018 }

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

References ast_event_get_size(), ast_event_iterator::event, ast_event_iterator::event_len, and ast_event_iterator::ie.

Referenced by ast_event_get_ie_raw(), ast_event_get_ie_raw_payload_len(), and event_dump_cli().

00989 {
00990    int res = 0;
00991 
00992    iterator->event_len = ast_event_get_size(event);
00993    iterator->event = event;
00994    if (iterator->event_len >= sizeof(*event) + sizeof(struct ast_event_ie)) {
00995       iterator->ie = (struct ast_event_ie *) ( ((char *) event) + sizeof(*event) );
00996    } else {
00997       iterator->ie = NULL;
00998       res = -1;
00999    }
01000 
01001    return res;
01002 }

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 1004 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(), ast_event_get_ie_raw_payload_len(), and event_dump_cli().

01005 {
01006    iterator->ie = (struct ast_event_ie *) ( ((char *) iterator->ie) + sizeof(*iterator->ie) + ntohs(iterator->ie->ie_payload_len));
01007    return ((iterator->event_len <= (((char *) iterator->ie) - ((char *) iterator->event))) ? -1 : 0);
01008 }

size_t ast_event_minimum_length ( void   ) 

Get the minimum length of an ast_event.

Returns:
minimum amount of memory that will be consumed by any ast_event.

Definition at line 1777 of file event.c.

Referenced by cpg_deliver_cb().

01778 {
01779    return sizeof(struct ast_event);
01780 }

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: 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.

Note:
The EID IE will be appended automatically when this function is used with at least one IE specified.
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 1166 of file event.c.

References ast_calloc, ast_event_append_eid(), ast_event_append_ie_bitflags(), 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_BITFLAGS, 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_HEAD_NOLOCK_STATIC, AST_LIST_INSERT_TAIL, AST_LIST_TRAVERSE, ast_log(), 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 aji_handle_pubsub_event(), alloc_event(), ast_cel_report_event(), ast_event_get_cached(), ast_event_unsubscribe(), devstate_event(), gen_sub_event(), handle_request_notify(), notify_message(), process_collection(), queue_mwi_event(), and stun_monitor_request().

01167 {
01168    va_list ap;
01169    struct ast_event *event;
01170    enum ast_event_ie_type ie_type;
01171    struct ast_event_ie_val *ie_val;
01172    int has_ie = 0;
01173    AST_LIST_HEAD_NOLOCK_STATIC(ie_vals, ast_event_ie_val);
01174 
01175    /* Invalid type */
01176    if (type >= AST_EVENT_TOTAL) {
01177       ast_log(LOG_WARNING, "Someone tried to create an event of invalid "
01178          "type '%d'!\n", type);
01179       return NULL;
01180    }
01181 
01182    va_start(ap, type);
01183    for (ie_type = va_arg(ap, enum ast_event_ie_type);
01184       ie_type != AST_EVENT_IE_END;
01185       ie_type = va_arg(ap, enum ast_event_ie_type))
01186    {
01187       struct ast_event_ie_val *ie_value = alloca(sizeof(*ie_value));
01188       int insert = 0;
01189 
01190       memset(ie_value, 0, sizeof(*ie_value));
01191       ie_value->ie_type = ie_type;
01192       ie_value->ie_pltype = va_arg(ap, enum ast_event_ie_pltype);
01193       switch (ie_value->ie_pltype) {
01194       case AST_EVENT_IE_PLTYPE_UINT:
01195          ie_value->payload.uint = va_arg(ap, uint32_t);
01196          insert = 1;
01197          break;
01198       case AST_EVENT_IE_PLTYPE_BITFLAGS:
01199          ie_value->payload.uint = va_arg(ap, uint32_t);
01200          insert = 1;
01201          break;
01202       case AST_EVENT_IE_PLTYPE_STR:
01203          ie_value->payload.str = va_arg(ap, const char *);
01204          insert = 1;
01205          break;
01206       case AST_EVENT_IE_PLTYPE_RAW:
01207       {
01208          void *data = va_arg(ap, void *);
01209          size_t datalen = va_arg(ap, size_t);
01210          ie_value->payload.raw = alloca(datalen);
01211          memcpy(ie_value->payload.raw, data, datalen);
01212          ie_value->raw_datalen = datalen;
01213          insert = 1;
01214          break;
01215       }
01216       case AST_EVENT_IE_PLTYPE_UNKNOWN:
01217       case AST_EVENT_IE_PLTYPE_EXISTS:
01218          break;
01219       }
01220 
01221       if (insert) {
01222          AST_LIST_INSERT_TAIL(&ie_vals, ie_value, entry);
01223          has_ie = 1;
01224       } else {
01225          ast_log(LOG_WARNING, "Unsupported PLTYPE(%d)\n", ie_value->ie_pltype);
01226       }
01227    }
01228    va_end(ap);
01229 
01230    if (!(event = ast_calloc(1, sizeof(*event)))) {
01231       return NULL;
01232    }
01233 
01234    event->type = htons(type);
01235    event->event_len = htons(sizeof(*event));
01236 
01237    AST_LIST_TRAVERSE(&ie_vals, ie_val, entry) {
01238       switch (ie_val->ie_pltype) {
01239       case AST_EVENT_IE_PLTYPE_STR:
01240          ast_event_append_ie_str(&event, ie_val->ie_type, ie_val->payload.str);
01241          break;
01242       case AST_EVENT_IE_PLTYPE_UINT:
01243          ast_event_append_ie_uint(&event, ie_val->ie_type, ie_val->payload.uint);
01244          break;
01245       case AST_EVENT_IE_PLTYPE_BITFLAGS:
01246          ast_event_append_ie_bitflags(&event, ie_val->ie_type, ie_val->payload.uint);
01247          break;
01248       case AST_EVENT_IE_PLTYPE_RAW:
01249          ast_event_append_ie_raw(&event, ie_val->ie_type,
01250                ie_val->payload.raw, ie_val->raw_datalen);
01251          break;
01252       case AST_EVENT_IE_PLTYPE_EXISTS:
01253       case AST_EVENT_IE_PLTYPE_UNKNOWN:
01254          break;
01255       }
01256 
01257       if (!event) {
01258          break;
01259       }
01260    }
01261 
01262    if (has_ie && !ast_event_get_ie_raw(event, AST_EVENT_IE_EID)) {
01263       /* If the event is originating on this server, add the server's
01264        * entity ID to the event. */
01265       ast_event_append_eid(&event);
01266    }
01267 
01268    return event;
01269 }

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

References alloc_event_ref(), ao2_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_cel_report_event(), ast_event_queue_and_cache(), ast_event_sub_activate(), ast_event_unsubscribe(), handle_security_event(), and stun_monitor_request().

01481 {
01482    struct ast_event_ref *event_ref;
01483    uint16_t host_event_type;
01484    int res;
01485 
01486    host_event_type = ntohs(event->type);
01487 
01488    /* Invalid type */
01489    if (host_event_type >= AST_EVENT_TOTAL) {
01490       ast_log(LOG_WARNING, "Someone tried to queue an event of invalid "
01491          "type '%d'!\n", host_event_type);
01492       return -1;
01493    }
01494 
01495    /* If nobody has subscribed to this event type, throw it away now */
01496    if (ast_event_check_subscriber(host_event_type, AST_EVENT_IE_END)
01497          == AST_EVENT_SUB_NONE) {
01498       ast_event_destroy(event);
01499       return 0;
01500    }
01501 
01502    if (!(event_ref = alloc_event_ref())) {
01503       return -1;
01504    }
01505 
01506    event_ref->event = event;
01507 
01508    res = ast_taskprocessor_push(event_dispatcher, handle_event, event_ref);
01509    if (res) {
01510       event_ref->event = NULL;
01511       ao2_ref(event_ref, -1);
01512    }
01513    return res;
01514 }

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.

Definition at line 1428 of file event.c.

References ast_event_cache, ast_event_destroy(), ast_event_get_type(), ast_event_queue(), ast_log(), container, event_update_cache(), and LOG_WARNING.

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

01429 {
01430    struct ao2_container *container;
01431 
01432    container = ast_event_cache[ast_event_get_type(event)].container;
01433    if (!container) {
01434       ast_log(LOG_WARNING, "cache requested for non-cached event type\n");
01435    } else {
01436       event_update_cache(container, event);
01437    }
01438 
01439    if (ast_event_queue(event)) {
01440       ast_event_destroy(event);
01441    }
01442    return 0;
01443 }

static void ast_event_ref_destroy ( void *  obj  )  [static]

Definition at line 1282 of file event.c.

References ast_event_destroy(), and ast_event_ref::event.

Referenced by alloc_event_ref().

01283 {
01284    struct ast_event_ref *event_ref = obj;
01285 
01286    ast_event_destroy(event_ref->event);
01287 }

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 681 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, sub, ast_event_sub::type, ast_event_ie_val::uint, and ast_event_sub::userdata.

Referenced by handle_cli_status(), and start_poll_thread().

00682 {
00683    struct ast_event *event;
00684    struct ast_event_sub *sub;
00685    enum ast_event_type event_type = -1;
00686    struct ast_event_ie_val *ie_val;
00687 
00688    if (event_sub->type != AST_EVENT_SUB)
00689       return;
00690 
00691    AST_LIST_TRAVERSE(&event_sub->ie_vals, ie_val, entry) {
00692       if (ie_val->ie_type == AST_EVENT_IE_EVENTTYPE) {
00693          event_type = ie_val->payload.uint;
00694          break;
00695       }
00696    }
00697 
00698    if (event_type == -1)
00699       return;
00700 
00701    AST_RWDLLIST_RDLOCK(&ast_event_subs[event_type]);
00702    AST_RWDLLIST_TRAVERSE(&ast_event_subs[event_type], sub, entry) {
00703       if (event_sub == sub) {
00704          continue;
00705       }
00706 
00707       event = gen_sub_event(sub);
00708       if (!event) {
00709          continue;
00710       }
00711 
00712       event_sub->cb(event, event_sub->userdata);
00713 
00714       ast_event_destroy(event);
00715    }
00716    AST_RWDLLIST_UNLOCK(&ast_event_subs[event_type]);
00717 }

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

References ARRAY_LEN, ast_strlen_zero(), and event_names.

Referenced by event_dump_cache().

00288 {
00289    int i;
00290 
00291    for (i = 0; i < ARRAY_LEN(event_names); i++) {
00292       if (ast_strlen_zero(event_names[i]) || strcasecmp(event_names[i], str)) {
00293          continue;
00294       }
00295 
00296       *event_type = i;
00297       return 0;
00298    }
00299 
00300    return -1;
00301 }

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

References ARRAY_LEN, ie_maps, and name.

00324 {
00325    int i;
00326 
00327    for (i = 0; i < ARRAY_LEN(ie_maps); i++) {
00328       if (strcasecmp(ie_maps[i].name, str)) {
00329          continue;
00330       }
00331 
00332       *ie_type = i;
00333       return 0;
00334    }
00335 
00336    return -1;
00337 }

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

References ast_event_check_subscriber(), ast_event_destroy(), 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().

00864 {
00865    if (ast_event_check_subscriber(AST_EVENT_SUB,
00866       AST_EVENT_IE_EVENTTYPE, AST_EVENT_IE_PLTYPE_UINT, sub->type,
00867       AST_EVENT_IE_END) != AST_EVENT_SUB_NONE) {
00868       struct ast_event *event;
00869 
00870       event = gen_sub_event(sub);
00871       if (event && ast_event_queue(event)) {
00872          ast_event_destroy(event);
00873       }
00874    }
00875 
00876    AST_RWDLLIST_WRLOCK(&ast_event_subs[sub->type]);
00877    AST_RWDLLIST_INSERT_TAIL(&ast_event_subs[sub->type], sub, entry);
00878    AST_RWDLLIST_UNLOCK(&ast_event_subs[sub->type]);
00879 
00880    return 0;
00881 }

int ast_event_sub_append_ie_bitflags ( struct ast_event_sub sub,
enum ast_event_ie_type  ie_type,
uint32_t  flags 
)

Append a bitflags parameter to a subscription.

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

Definition at line 763 of file event.c.

References ast_calloc, AST_EVENT_IE_PLTYPE_BITFLAGS, AST_EVENT_IE_TOTAL, 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().

00765 {
00766    struct ast_event_ie_val *ie_val;
00767 
00768    if (ie_type <= 0 || ie_type >= AST_EVENT_IE_TOTAL) {
00769       return -1;
00770    }
00771 
00772    if (!(ie_val = ast_calloc(1, sizeof(*ie_val)))) {
00773       return -1;
00774    }
00775 
00776    ie_val->ie_type = ie_type;
00777    ie_val->payload.uint = flags;
00778    ie_val->ie_pltype = AST_EVENT_IE_PLTYPE_BITFLAGS;
00779 
00780    AST_LIST_INSERT_TAIL(&sub->ie_vals, ie_val, entry);
00781 
00782    return 0;
00783 }

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

References ast_calloc, AST_EVENT_IE_PLTYPE_EXISTS, AST_EVENT_IE_TOTAL, 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().

00787 {
00788    struct ast_event_ie_val *ie_val;
00789 
00790    if (ie_type <= 0 || ie_type >= AST_EVENT_IE_TOTAL) {
00791       return -1;
00792    }
00793 
00794    if (!(ie_val = ast_calloc(1, sizeof(*ie_val)))) {
00795       return -1;
00796    }
00797 
00798    ie_val->ie_type = ie_type;
00799    ie_val->ie_pltype = AST_EVENT_IE_PLTYPE_EXISTS;
00800 
00801    AST_LIST_INSERT_TAIL(&sub->ie_vals, ie_val, entry);
00802 
00803    return 0;
00804 }

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
data the data that must be present in the event to match this subscription
raw_datalen length of data
Return values:
0 success
non-zero failure
Since:
1.6.1

Definition at line 834 of file event.c.

References ast_calloc, AST_EVENT_IE_PLTYPE_RAW, AST_EVENT_IE_TOTAL, 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(), and cpg_confchg_cb().

00836 {
00837    struct ast_event_ie_val *ie_val;
00838 
00839    if (ie_type <= 0 || ie_type >= AST_EVENT_IE_TOTAL) {
00840       return -1;
00841    }
00842 
00843    if (!(ie_val = ast_calloc(1, sizeof(*ie_val)))) {
00844       return -1;
00845    }
00846 
00847    ie_val->ie_type = ie_type;
00848    ie_val->ie_pltype = AST_EVENT_IE_PLTYPE_RAW;
00849    ie_val->raw_datalen = raw_datalen;
00850 
00851    if (!(ie_val->payload.raw = ast_malloc(raw_datalen))) {
00852       ast_free(ie_val);
00853       return -1;
00854    }
00855 
00856    memcpy(ie_val->payload.raw, data, raw_datalen);
00857 
00858    AST_LIST_INSERT_TAIL(&sub->ie_vals, ie_val, entry);
00859 
00860    return 0;
00861 }

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

References ast_calloc, AST_EVENT_IE_PLTYPE_STR, AST_EVENT_IE_TOTAL, 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().

00808 {
00809    struct ast_event_ie_val *ie_val;
00810 
00811    if (ie_type <= 0 || ie_type >= AST_EVENT_IE_TOTAL) {
00812       return -1;
00813    }
00814 
00815    if (!(ie_val = ast_calloc(1, sizeof(*ie_val)))) {
00816       return -1;
00817    }
00818 
00819    ie_val->ie_type = ie_type;
00820    ie_val->ie_pltype = AST_EVENT_IE_PLTYPE_STR;
00821 
00822    if (!(ie_val->payload.str = ast_strdup(str))) {
00823       ast_free(ie_val);
00824       return -1;
00825    }
00826 
00827    ie_val->payload.hash = ast_str_hash(str);
00828 
00829    AST_LIST_INSERT_TAIL(&sub->ie_vals, ie_val, entry);
00830 
00831    return 0;
00832 }

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

References ast_calloc, AST_EVENT_IE_PLTYPE_UINT, AST_EVENT_IE_TOTAL, 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(), and handle_cli_status().

00743 {
00744    struct ast_event_ie_val *ie_val;
00745 
00746    if (ie_type <= 0 || ie_type >= AST_EVENT_IE_TOTAL) {
00747       return -1;
00748    }
00749 
00750    if (!(ie_val = ast_calloc(1, sizeof(*ie_val)))) {
00751       return -1;
00752    }
00753 
00754    ie_val->ie_type = ie_type;
00755    ie_val->payload.uint = unsigned_int;
00756    ie_val->ie_pltype = AST_EVENT_IE_PLTYPE_UINT;
00757 
00758    AST_LIST_INSERT_TAIL(&sub->ie_vals, ie_val, entry);
00759 
00760    return 0;
00761 }

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 945 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(), cpg_confchg_cb(), handle_cli_status(), and handle_devstate_change().

00946 {
00947    struct ast_event_ie_val *ie_val;
00948 
00949    while ((ie_val = AST_LIST_REMOVE_HEAD(&sub->ie_vals, entry))) {
00950       ast_event_ie_val_destroy(ie_val);
00951    }
00952 
00953    ast_free(sub);
00954 }

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

Subscribe to events.

Parameters:
event_type The type of events to subscribe to
cb The function to be called with events
description Description of the subscription.
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.

Note:
A NULL description will cause this function to crash, so watch out!

Definition at line 883 of file event.c.

References ast_copy_string(), AST_EVENT_IE_END, AST_EVENT_IE_PLTYPE_BITFLAGS, 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_bitflags(), 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(), ast_event_sub::description, str, and sub.

Referenced by add_peer_mwi_subs(), aji_init_event_distribution(), ast_enable_distributed_devstate(), build_gateway(), build_peer(), cc_generic_agent_start_monitoring(), config_line(), create_new_generic_list(), load_general_config(), load_module(), load_pbx(), mkintf(), network_change_event_subscribe(), and start_poll_thread().

00885 {
00886    va_list ap;
00887    enum ast_event_ie_type ie_type;
00888    struct ast_event_sub *sub;
00889 
00890    if (!(sub = ast_event_subscribe_new(type, cb, userdata))) {
00891       return NULL;
00892    }
00893 
00894    ast_copy_string(sub->description, description, sizeof(sub->description));
00895 
00896    va_start(ap, userdata);
00897    for (ie_type = va_arg(ap, enum ast_event_ie_type);
00898       ie_type != AST_EVENT_IE_END;
00899       ie_type = va_arg(ap, enum ast_event_ie_type))
00900    {
00901       enum ast_event_ie_pltype ie_pltype;
00902 
00903       ie_pltype = va_arg(ap, enum ast_event_ie_pltype);
00904 
00905       switch (ie_pltype) {
00906       case AST_EVENT_IE_PLTYPE_UNKNOWN:
00907          break;
00908       case AST_EVENT_IE_PLTYPE_UINT:
00909       {
00910          uint32_t unsigned_int = va_arg(ap, uint32_t);
00911          ast_event_sub_append_ie_uint(sub, ie_type, unsigned_int);
00912          break;
00913       }
00914       case AST_EVENT_IE_PLTYPE_BITFLAGS:
00915       {
00916          uint32_t unsigned_int = va_arg(ap, uint32_t);
00917          ast_event_sub_append_ie_bitflags(sub, ie_type, unsigned_int);
00918          break;
00919       }
00920       case AST_EVENT_IE_PLTYPE_STR:
00921       {
00922          const char *str = va_arg(ap, const char *);
00923          ast_event_sub_append_ie_str(sub, ie_type, str);
00924          break;
00925       }
00926       case AST_EVENT_IE_PLTYPE_RAW:
00927       {
00928          void *data = va_arg(ap, void *);
00929          size_t data_len = va_arg(ap, size_t);
00930          ast_event_sub_append_ie_raw(sub, ie_type, data, data_len);
00931          break;
00932       }
00933       case AST_EVENT_IE_PLTYPE_EXISTS:
00934          ast_event_sub_append_ie_exists(sub, ie_type);
00935          break;
00936       }
00937    }
00938    va_end(ap);
00939 
00940    ast_event_sub_activate(sub);
00941 
00942    return sub;
00943 }

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

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

Referenced by ast_event_subscribe(), cpg_confchg_cb(), handle_cli_status(), and handle_devstate_change().

00721 {
00722    struct ast_event_sub *sub;
00723 
00724    if (type < 0 || type >= AST_EVENT_TOTAL) {
00725       ast_log(LOG_ERROR, "%u is an invalid type!\n", type);
00726       return NULL;
00727    }
00728 
00729    if (!(sub = ast_calloc(1, sizeof(*sub)))) {
00730       return NULL;
00731    }
00732 
00733    sub->type = type;
00734    sub->cb = cb;
00735    sub->userdata = userdata;
00736    sub->uniqueid = ast_atomic_fetchadd_int((int *) &sub_uniqueid, 1);
00737 
00738    return sub;
00739 }

const char* ast_event_subscriber_get_description ( struct ast_event_sub sub  ) 

Get description for a subscription.

Parameters:
sub subscription
Returns:
string description of the subscription

Definition at line 956 of file event.c.

References ast_event_sub::description.

00957 {
00958    return sub ? sub->description : NULL;
00959 }

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

References AST_DLLIST_REMOVE, ast_event_check_subscriber(), ast_event_destroy(), AST_EVENT_IE_DESCRIPTION, AST_EVENT_IE_END, AST_EVENT_IE_EVENTTYPE, AST_EVENT_IE_PLTYPE_STR, 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::description, ast_event_sub::type, and ast_event_sub::uniqueid.

Referenced by add_peer_mwi_subs(), cc_generic_agent_destructor(), cleanup_module(), destroy_dahdi_pvt(), destroy_endpoint(), destroy_mailbox(), generic_agent_devstate_unsubscribe(), generic_monitor_instance_list_destructor(), load_general_config(), network_change_event_unsubscribe(), peer_destructor(), stop_poll_thread(), and unload_module().

00962 {
00963    struct ast_event *event;
00964 
00965    AST_RWDLLIST_WRLOCK(&ast_event_subs[sub->type]);
00966    AST_DLLIST_REMOVE(&ast_event_subs[sub->type], sub, entry);
00967    AST_RWDLLIST_UNLOCK(&ast_event_subs[sub->type]);
00968 
00969    if (ast_event_check_subscriber(AST_EVENT_UNSUB,
00970       AST_EVENT_IE_EVENTTYPE, AST_EVENT_IE_PLTYPE_UINT, sub->type,
00971       AST_EVENT_IE_END) != AST_EVENT_SUB_NONE) {
00972 
00973       event = ast_event_new(AST_EVENT_UNSUB,
00974          AST_EVENT_IE_UNIQUEID,    AST_EVENT_IE_PLTYPE_UINT, sub->uniqueid,
00975          AST_EVENT_IE_EVENTTYPE,   AST_EVENT_IE_PLTYPE_UINT, sub->type,
00976          AST_EVENT_IE_DESCRIPTION, AST_EVENT_IE_PLTYPE_STR, sub->description,
00977          AST_EVENT_IE_END);
00978       if (event && ast_event_queue(event)) {
00979          ast_event_destroy(event);
00980       }
00981    }
00982 
00983    ast_event_sub_destroy(sub);
00984 
00985    return NULL;
00986 }

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

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

00613 {
00614    const struct ast_event_ref *event_ref = obj;
00615    const struct ast_event *event = event_ref->event;
00616    const struct ast_event_sub *event_sub = arg;
00617    struct ast_event_ie_val *ie_val = NULL;
00618 
00619    AST_LIST_TRAVERSE(&event_sub->ie_vals, ie_val, entry) {
00620       if (!match_ie_val(event, ie_val, NULL)) {
00621          break;
00622       }
00623    }
00624 
00625    if (!ie_val) {
00626       /* All parameters were matched on this cache entry, so dump it */
00627       event_sub->cb(event, event_sub->userdata);
00628    }
00629 
00630    return 0;
00631 }

static void dump_raw_ie ( struct ast_event_iterator i,
struct ast_cli_args a 
) [static]

Definition at line 1622 of file event.c.

References ast_cli(), ast_eid_to_str(), ast_event_get_ie_type_name(), AST_EVENT_IE_EID, ast_event_iterator_get_ie_raw(), ast_event_iterator_get_ie_type(), ast_cli_args::fd, and ast_event_ie_val::ie_type.

Referenced by event_dump_cli().

01623 {
01624    char eid_buf[32];
01625    enum ast_event_ie_type ie_type;
01626    const char *ie_type_name;
01627 
01628    ie_type = ast_event_iterator_get_ie_type(i);
01629    ie_type_name = ast_event_get_ie_type_name(ie_type);
01630 
01631    switch (ie_type) {
01632    case AST_EVENT_IE_EID:
01633       ast_eid_to_str(eid_buf, sizeof(eid_buf), ast_event_iterator_get_ie_raw(i));
01634       ast_cli(a->fd, "%.30s: %s\n", ie_type_name, eid_buf);
01635       break;
01636    default:
01637       ast_cli(a->fd, "%s\n", ie_type_name);
01638       break;
01639    }
01640 }

static char* event_dump_cache ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
) [static]

Definition at line 1693 of file event.c.

References ao2_callback, ast_cli_args::argc, ast_cli_entry::args, ast_cli_args::argv, ARRAY_LEN, ast_cli(), ast_cli_complete(), ast_event_cache, ast_event_get_ie_type_name(), ast_event_str_to_event_type(), cache_args, cached_event_types, CLI_GENERATE, CLI_HANDLER, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, container, event_dump_cli(), ast_cli_args::fd, ast_cli_args::n, OBJ_NODATA, ast_cli_args::pos, ast_cli_entry::usage, and ast_cli_args::word.

01694 {
01695    enum ast_event_type event_type;
01696    enum ast_event_ie_type *cache_args;
01697    int i;
01698 
01699    switch (cmd) {
01700    case CLI_INIT:
01701       e->command = "event dump cache";
01702       e->usage =
01703          "Usage: event dump cache <event type>\n"
01704          "       Dump all of the cached events for the given event type.\n"
01705          "       This is primarily intended for debugging.\n";
01706       return NULL;
01707    case CLI_GENERATE:
01708       if (a->pos == 3) {
01709          return ast_cli_complete(a->word, cached_event_types, a->n);
01710       }
01711       return NULL;
01712    case CLI_HANDLER:
01713       break;
01714    }
01715 
01716    if (a->argc != e->args + 1) {
01717       return CLI_SHOWUSAGE;
01718    }
01719 
01720    if (ast_event_str_to_event_type(a->argv[e->args], &event_type)) {
01721       ast_cli(a->fd, "Invalid cached event type: '%s'\n", a->argv[e->args]);
01722       return CLI_SHOWUSAGE;
01723    }
01724 
01725    if (!ast_event_cache[event_type].container) {
01726       ast_cli(a->fd, "Event type '%s' has no cache.\n", a->argv[e->args]);
01727       return CLI_SUCCESS;
01728    }
01729 
01730    ast_cli(a->fd, "Event Type: %s\n", a->argv[e->args]);
01731    ast_cli(a->fd, "Cache Unique Keys:\n");
01732    cache_args = ast_event_cache[event_type].cache_args;
01733    for (i = 0; i < ARRAY_LEN(ast_event_cache[0].cache_args) && cache_args[i]; i++) {
01734       ast_cli(a->fd, "--> %s\n", ast_event_get_ie_type_name(cache_args[i]));
01735    }
01736 
01737    ast_cli(a->fd, "\n--- Begin Cache Dump ---\n\n");
01738    ao2_callback(ast_event_cache[event_type].container, OBJ_NODATA, event_dump_cli, a);
01739    ast_cli(a->fd, "--- End Cache Dump ---\n\n");
01740 
01741    return CLI_SUCCESS;
01742 }

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

Definition at line 1642 of file event.c.

References ast_cli(), ast_event_get_ie_pltype(), ast_event_get_ie_type_name(), ast_event_get_type_name(), AST_EVENT_IE_PLTYPE_BITFLAGS, 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_iterator_get_ie_bitflags(), ast_event_iterator_get_ie_str(), ast_event_iterator_get_ie_type(), ast_event_iterator_get_ie_uint(), ast_event_iterator_init(), ast_event_iterator_next(), dump_raw_ie(), ast_event_iterator::event, ast_event_ref::event, and ast_cli_args::fd.

Referenced by event_dump_cache().

01643 {
01644    const struct ast_event_ref *event_ref = obj;
01645    const struct ast_event *event = event_ref->event;
01646    struct ast_cli_args *a = arg;
01647    struct ast_event_iterator i;
01648 
01649    if (ast_event_iterator_init(&i, event)) {
01650       ast_cli(a->fd, "Failed to initialize event iterator.  :-(\n");
01651       return 0;
01652    }
01653 
01654    ast_cli(a->fd, "Event: %s\n", ast_event_get_type_name(event));
01655 
01656    do {
01657       enum ast_event_ie_type ie_type;
01658       enum ast_event_ie_pltype ie_pltype;
01659       const char *ie_type_name;
01660 
01661       ie_type = ast_event_iterator_get_ie_type(&i);
01662       ie_type_name = ast_event_get_ie_type_name(ie_type);
01663       ie_pltype = ast_event_get_ie_pltype(ie_type);
01664 
01665       switch (ie_pltype) {
01666       case AST_EVENT_IE_PLTYPE_UNKNOWN:
01667       case AST_EVENT_IE_PLTYPE_EXISTS:
01668          ast_cli(a->fd, "%s\n", ie_type_name);
01669          break;
01670       case AST_EVENT_IE_PLTYPE_STR:
01671          ast_cli(a->fd, "%.30s: %s\n", ie_type_name,
01672                ast_event_iterator_get_ie_str(&i));
01673          break;
01674       case AST_EVENT_IE_PLTYPE_UINT:
01675          ast_cli(a->fd, "%.30s: %u\n", ie_type_name,
01676                ast_event_iterator_get_ie_uint(&i));
01677          break;
01678       case AST_EVENT_IE_PLTYPE_BITFLAGS:
01679          ast_cli(a->fd, "%.30s: %u\n", ie_type_name,
01680                ast_event_iterator_get_ie_bitflags(&i));
01681          break;
01682       case AST_EVENT_IE_PLTYPE_RAW:
01683          dump_raw_ie(&i, a);
01684          break;
01685       }
01686    } while (!ast_event_iterator_next(&i));
01687 
01688    ast_cli(a->fd, "\n");
01689 
01690    return 0;
01691 }

static void event_update_cache ( struct ao2_container cache,
struct ast_event event 
) [static]

Definition at line 1397 of file event.c.

References alloc_event_ref(), ao2_callback, ao2_link, ao2_lock, ao2_ref, ao2_unlock, ast_event_cmp(), ast_event_destroy(), ast_event_dup(), ast_event_ref::event, OBJ_MULTIPLE, OBJ_NODATA, OBJ_POINTER, and OBJ_UNLINK.

Referenced by ast_event_queue_and_cache().

01398 {
01399    struct ast_event_ref tmp_event_ref = {
01400       .event = event,
01401    };
01402    struct ast_event *dup_event;
01403    struct ast_event_ref *event_ref;
01404 
01405    /* Hold the cache container lock while it is updated. */
01406    ao2_lock(cache);
01407 
01408    /* Remove matches from the cache. */
01409    ao2_callback(cache, OBJ_POINTER | OBJ_UNLINK | OBJ_MULTIPLE | OBJ_NODATA,
01410       ast_event_cmp, &tmp_event_ref);
01411 
01412    /* Save a copy of the event in the cache. */
01413    dup_event = ast_event_dup(event);
01414    if (dup_event) {
01415       event_ref = alloc_event_ref();
01416       if (event_ref) {
01417          event_ref->event = dup_event;
01418          ao2_link(cache, event_ref);
01419          ao2_ref(event_ref, -1);
01420       } else {
01421          ast_event_destroy(dup_event);
01422       }
01423    }
01424 
01425    ao2_unlock(cache);
01426 }

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

Definition at line 640 of file event.c.

References ast_event_append_ie_bitflags(), ast_event_append_ie_raw(), ast_event_append_ie_str(), ast_event_append_ie_uint(), AST_EVENT_IE_DESCRIPTION, AST_EVENT_IE_END, AST_EVENT_IE_EVENTTYPE, AST_EVENT_IE_EXISTS, AST_EVENT_IE_PLTYPE_BITFLAGS, 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_sub::description, 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().

00641 {
00642    struct ast_event_ie_val *ie_val;
00643    struct ast_event *event;
00644 
00645    event = ast_event_new(AST_EVENT_SUB,
00646       AST_EVENT_IE_UNIQUEID,    AST_EVENT_IE_PLTYPE_UINT, sub->uniqueid,
00647       AST_EVENT_IE_EVENTTYPE,   AST_EVENT_IE_PLTYPE_UINT, sub->type,
00648       AST_EVENT_IE_DESCRIPTION, AST_EVENT_IE_PLTYPE_STR, sub->description,
00649       AST_EVENT_IE_END);
00650    if (!event)
00651       return NULL;
00652 
00653    AST_LIST_TRAVERSE(&sub->ie_vals, ie_val, entry) {
00654       switch (ie_val->ie_pltype) {
00655       case AST_EVENT_IE_PLTYPE_UNKNOWN:
00656          break;
00657       case AST_EVENT_IE_PLTYPE_EXISTS:
00658          ast_event_append_ie_uint(&event, AST_EVENT_IE_EXISTS, ie_val->ie_type);
00659          break;
00660       case AST_EVENT_IE_PLTYPE_UINT:
00661          ast_event_append_ie_uint(&event, ie_val->ie_type, ie_val->payload.uint);
00662          break;
00663       case AST_EVENT_IE_PLTYPE_BITFLAGS:
00664          ast_event_append_ie_bitflags(&event, ie_val->ie_type, ie_val->payload.uint);
00665          break;
00666       case AST_EVENT_IE_PLTYPE_STR:
00667          ast_event_append_ie_str(&event, ie_val->ie_type, ie_val->payload.str);
00668          break;
00669       case AST_EVENT_IE_PLTYPE_RAW:
00670          ast_event_append_ie_raw(&event, ie_val->ie_type, ie_val->payload.raw, ie_val->raw_datalen);
00671          break;
00672       }
00673       if (!event)
00674          break;
00675    }
00676 
00677    return event;
00678 }

static int handle_event ( void *  data  )  [static]

Definition at line 1445 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, event_types, ast_event_sub::ie_vals, match_ie_val(), sub, and ast_event_sub::userdata.

01446 {
01447    struct ast_event_ref *event_ref = data;
01448    struct ast_event_sub *sub;
01449    const enum ast_event_type event_types[] = {
01450       ntohs(event_ref->event->type),
01451       AST_EVENT_ALL
01452    };
01453    int i;
01454 
01455    for (i = 0; i < ARRAY_LEN(event_types); i++) {
01456       AST_RWDLLIST_RDLOCK(&ast_event_subs[event_types[i]]);
01457       AST_RWDLLIST_TRAVERSE(&ast_event_subs[event_types[i]], sub, entry) {
01458          struct ast_event_ie_val *ie_val;
01459 
01460          AST_LIST_TRAVERSE(&sub->ie_vals, ie_val, entry) {
01461             if (!match_ie_val(event_ref->event, ie_val, NULL)) {
01462                /* The current subscription ie did not match an event ie. */
01463                break;
01464             }
01465          }
01466          if (ie_val) {
01467             /* The event did not match this subscription. */
01468             continue;
01469          }
01470          sub->cb(event_ref->event, sub->userdata);
01471       }
01472       AST_RWDLLIST_UNLOCK(&ast_event_subs[event_types[i]]);
01473    }
01474 
01475    ao2_ref(event_ref, -1);
01476 
01477    return 0;
01478 }

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

References ast_event_get_ie_bitflags(), ast_event_get_ie_raw(), ast_event_get_ie_raw_payload_len(), ast_event_get_ie_str(), ast_event_get_ie_str_hash(), ast_event_get_ie_uint(), AST_EVENT_IE_PLTYPE_BITFLAGS, 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_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().

00552 {
00553    switch (ie_val->ie_pltype) {
00554    case AST_EVENT_IE_PLTYPE_UINT:
00555    {
00556       uint32_t val = event2 ? ast_event_get_ie_uint(event2, ie_val->ie_type) : ie_val->payload.uint;
00557 
00558       return (val == ast_event_get_ie_uint(event, ie_val->ie_type)) ? 1 : 0;
00559    }
00560 
00561    case AST_EVENT_IE_PLTYPE_BITFLAGS:
00562    {
00563       uint32_t flags = event2 ? ast_event_get_ie_uint(event2, ie_val->ie_type) : ie_val->payload.uint;
00564 
00565       /*
00566        * If the subscriber has requested *any* of the bitflags that this event provides,
00567        * then it's a match.
00568        */
00569       return (flags & ast_event_get_ie_bitflags(event, ie_val->ie_type)) ? 1 : 0;
00570    }
00571 
00572    case AST_EVENT_IE_PLTYPE_STR:
00573    {
00574       const char *str;
00575       uint32_t hash;
00576 
00577       hash = event2 ? ast_event_get_ie_str_hash(event2, ie_val->ie_type) : ie_val->payload.hash;
00578       if (hash != ast_event_get_ie_str_hash(event, ie_val->ie_type)) {
00579          return 0;
00580       }
00581 
00582       str = event2 ? ast_event_get_ie_str(event2, ie_val->ie_type) : ie_val->payload.str;
00583       if (str && !strcmp(str, ast_event_get_ie_str(event, ie_val->ie_type))) {
00584          return 1;
00585       }
00586 
00587       return 0;
00588    }
00589 
00590    case AST_EVENT_IE_PLTYPE_RAW:
00591    {
00592       const void *buf = event2 ? ast_event_get_ie_raw(event2, ie_val->ie_type) : ie_val->payload.raw;
00593       uint16_t ie_payload_len = event2 ? ast_event_get_ie_raw_payload_len(event2, ie_val->ie_type) : ie_val->raw_datalen;
00594 
00595       return (buf
00596          && ie_payload_len == ast_event_get_ie_raw_payload_len(event, ie_val->ie_type)
00597          && !memcmp(buf, ast_event_get_ie_raw(event, ie_val->ie_type), ie_payload_len)) ? 1 : 0;
00598    }
00599 
00600    case AST_EVENT_IE_PLTYPE_EXISTS:
00601    {
00602       return ast_event_get_ie_raw(event, ie_val->ie_type) ? 1 : 0;
00603    }
00604 
00605    case AST_EVENT_IE_PLTYPE_UNKNOWN:
00606       return 0;
00607    }
00608 
00609    return 0;
00610 }

static int match_sub_ie_val_to_event ( const struct ast_event_ie_val sub_ie_val,
const struct ast_ev_check_list check_ie_vals 
) [static]

Definition at line 382 of file event.c.

References AST_EVENT_IE_PLTYPE_BITFLAGS, 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_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().

00383 {
00384    const struct ast_event_ie_val *event_ie_val;
00385    int res = 0;
00386 
00387    AST_LIST_TRAVERSE(&check_ie_vals->ie_vals, event_ie_val, entry) {
00388       if (sub_ie_val->ie_type == event_ie_val->ie_type) {
00389          break;
00390       }
00391    }
00392    if (!event_ie_val) {
00393       /* We did not find the event ie the subscriber cares about. */
00394       return 0;
00395    }
00396 
00397    if (sub_ie_val->ie_pltype != event_ie_val->ie_pltype) {
00398       if (sub_ie_val->ie_pltype == AST_EVENT_IE_PLTYPE_EXISTS) {
00399          /* The subscription only cares that this ie exists. */
00400          return 1;
00401       }
00402       /* Payload types do not match. */
00403       return 0;
00404    }
00405 
00406    switch (sub_ie_val->ie_pltype) {
00407    case AST_EVENT_IE_PLTYPE_UINT:
00408       res = (sub_ie_val->payload.uint == event_ie_val->payload.uint);
00409       break;
00410    case AST_EVENT_IE_PLTYPE_BITFLAGS:
00411       /*
00412        * If the subscriber has requested *any* of the bitflags we are providing,
00413        * then it's a match.
00414        */
00415       res = (sub_ie_val->payload.uint & event_ie_val->payload.uint);
00416       break;
00417    case AST_EVENT_IE_PLTYPE_STR:
00418       res = !strcmp(sub_ie_val->payload.str, event_ie_val->payload.str);
00419       break;
00420    case AST_EVENT_IE_PLTYPE_RAW:
00421       res = (sub_ie_val->raw_datalen == event_ie_val->raw_datalen
00422          && !memcmp(sub_ie_val->payload.raw, event_ie_val->payload.raw,
00423             sub_ie_val->raw_datalen));
00424       break;
00425    case AST_EVENT_IE_PLTYPE_EXISTS:
00426       /* Should never get here since check_ie_vals cannot have this type. */
00427       break;
00428    case AST_EVENT_IE_PLTYPE_UNKNOWN:
00429       /*
00430        * Should never be in a subscription event ie val list and
00431        * check_ie_vals cannot have this type either.
00432        */
00433       break;
00434    }
00435 
00436    return res;
00437 }


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

Referenced by ast_event_cmp(), and event_dump_cache().

const char* const cached_event_types[] = { "MWI", "DeviceState", "DeviceStateChange", NULL } [static]

Names of cached event types, for CLI tab completion.

Note:
These names must match what is in the event_names array.

Definition at line 191 of file event.c.

Referenced by event_dump_cache().

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

struct ast_cli_entry event_cli[] [static]

Initial value:

 {
   AST_CLI_DEFINE(event_dump_cache, "Dump the internal event cache (for debugging)"),
}

Definition at line 1744 of file event.c.

Referenced by ast_event_init().

Definition at line 43 of file event.c.

const char* const event_names[AST_EVENT_TOTAL] [static]

Event Names.

Definition at line 196 of file event.c.

Referenced by ast_event_get_type_name(), and ast_event_str_to_event_type().

Event type specific hash function.

Definition at line 161 of file event.c.

Referenced by ast_event_hash(), and ast_event_init().

struct ie_map ie_maps[AST_EVENT_IE_TOTAL] [static]

IE payload types and names.

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


Generated on Fri Feb 10 06:36:02 2012 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6