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

Go to the source code of this file.
Data Structures | |
| struct | ast_event |
| An event. More... | |
| struct | ast_event_ie |
| An event information element. More... | |
| struct | ast_event_ie_str_payload |
| The payload for a string information element. More... | |
| struct | ast_event_ie_val |
| struct | ast_event_ref |
| A holder for an event. More... | |
| struct | ast_event_sub |
| Event subscription. More... | |
| struct | ast_event_sub_list |
| Event subscriptions The event subscribers are indexed by which event they are subscribed to. More... | |
| struct | ie_map |
| IE payload types and names. More... | |
Defines | |
| #define | MAX_CACHE_ARGS 8 |
| #define | NUM_CACHE_BUCKETS 563 |
Functions | |
| static struct ast_event_ref * | alloc_event_ref (void) |
| int | ast_event_append_ie_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_event * | ast_event_dup (const struct ast_event *event) |
| static int | ast_event_dup_and_cache (const struct ast_event *event) |
| Duplicate an event and add it to the cache. | |
| struct ast_event * | ast_event_get_cached (enum ast_event_type type,...) |
| Retrieve an event from the cache. | |
| 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. | |
| 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. | |
| 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. | |
| void | ast_event_iterator_init (struct ast_event_iterator *iterator, const struct ast_event *event) |
| Initialize an event iterator instance. | |
| int | ast_event_iterator_next (struct ast_event_iterator *iterator) |
| Move iterator instance to next IE. | |
| struct ast_event * | ast_event_new (enum ast_event_type type,...) |
| Create a new event. | |
| int | ast_event_queue (struct ast_event *event) |
| Queue an event. | |
| int | ast_event_queue_and_cache (struct ast_event *event) |
| Queue and cache an event. | |
| static void | ast_event_ref_destroy (void *obj) |
| void | ast_event_report_subs (const struct ast_event_sub *event_sub) |
| Send AST_EVENT_SUB events to this subscriber of ... subscriber events. | |
| int | ast_event_str_to_event_type (const char *str, enum ast_event_type *event_type) |
| Convert a string into an event type. | |
| int | ast_event_str_to_ie_type (const char *str, enum ast_event_ie_type *ie_type) |
| Convert a string to an IE type. | |
| int | ast_event_sub_activate (struct ast_event_sub *sub) |
| Activate a dynamically built subscription. | |
| int | ast_event_sub_append_ie_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_sub * | ast_event_subscribe (enum ast_event_type type, ast_event_cb_t cb, char *description, void *userdata,...) |
| Subscribe to events. | |
| struct ast_event_sub * | ast_event_subscribe_new (enum ast_event_type type, ast_event_cb_t cb, void *userdata) |
| Allocate a subscription, but do not activate it. | |
| const char * | ast_event_subscriber_get_description (struct ast_event_sub *sub) |
| Get description for a subscription. | |
| struct ast_event_sub * | ast_event_unsubscribe (struct ast_event_sub *sub) |
| Un-subscribe from events. | |
| static int | dump_cache_cb (void *obj, void *arg, int flags) |
| static struct ast_event * | gen_sub_event (struct ast_event_sub *sub) |
| static int | handle_event (void *data) |
| static int | match_ie_val (const struct ast_event *event, const struct ast_event_ie_val *ie_val, const struct ast_event *event2) |
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 struct ast_taskprocessor * | event_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 |
Definition in file event.c.
| #define NUM_CACHE_BUCKETS 563 |
| static struct ast_event_ref* alloc_event_ref | ( | void | ) | [static, read] |
Definition at line 1270 of file event.c.
References ao2_alloc, and ast_event_ref_destroy().
Referenced by ast_event_dup_and_cache(), and ast_event_queue().
01271 { 01272 return ao2_alloc(sizeof(struct ast_event_ref), ast_event_ref_destroy); 01273 }
| 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.
| event | the event that the IE will be appended to | |
| ie_type | the type of IE to append | |
| flags | the flags that are the payload of the IE |
| 0 | success | |
| -1 | failure |
Definition at line 1033 of file event.c.
References ast_event_append_ie_raw().
Referenced by ast_event_get_cached(), ast_event_new(), and gen_sub_event().
01035 { 01036 flags = htonl(flags); 01037 return ast_event_append_ie_raw(event, ie_type, &flags, sizeof(flags)); 01038 }
| 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.
| 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 |
| 0 | success | |
| -1 | failure |
Definition at line 1040 of file event.c.
References ast_realloc, ast_event_ie::ie_payload, and ast_event_ie::ie_payload_len.
Referenced by ast_event_append_ie_bitflags(), ast_event_append_ie_str(), ast_event_append_ie_uint(), ast_event_get_cached(), ast_event_new(), and gen_sub_event().
01042 { 01043 struct ast_event_ie *ie; 01044 unsigned int extra_len; 01045 uint16_t event_len; 01046 01047 event_len = ntohs((*event)->event_len); 01048 extra_len = sizeof(*ie) + data_len; 01049 01050 if (!(*event = ast_realloc(*event, event_len + extra_len))) { 01051 return -1; 01052 } 01053 01054 ie = (struct ast_event_ie *) ( ((char *) *event) + event_len ); 01055 ie->ie_type = htons(ie_type); 01056 ie->ie_payload_len = htons(data_len); 01057 memcpy(ie->ie_payload, data, data_len); 01058 01059 (*event)->event_len = htons(event_len + extra_len); 01060 01061 return 0; 01062 }
| 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.
| 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 |
| 0 | success | |
| -1 | failure |
Definition at line 1011 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().
01013 { 01014 struct ast_event_ie_str_payload *str_payload; 01015 size_t payload_len; 01016 01017 payload_len = sizeof(*str_payload) + strlen(str); 01018 str_payload = alloca(payload_len); 01019 01020 strcpy(str_payload->str, str); 01021 str_payload->hash = ast_str_hash(str); 01022 01023 return ast_event_append_ie_raw(event, ie_type, str_payload, payload_len); 01024 }
| 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.
| 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 |
| 0 | success | |
| -1 | failure |
Definition at line 1026 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().
01028 { 01029 data = htonl(data); 01030 return ast_event_append_ie_raw(event, ie_type, &data, sizeof(data)); 01031 }
| enum ast_event_subscriber_res ast_event_check_subscriber | ( | enum ast_event_type | event_type, | |
| ... | ||||
| ) |
Check if subscribers exist.
| event_type | This is the type of event that the caller would like to check for subscribers to. |
<enum ast_event_ie_type>, [enum ast_event_ie_pltype, [payload] ]
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.
if (ast_event_check_subscriber(AST_EVENT_MWI, AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, mailbox, AST_EVENT_IE_END) == AST_EVENT_SUB_NONE) { return; }
This example will check if there are any subscribers to MWI events for the mailbox defined in the "mailbox" variable.
Definition at line 353 of file event.c.
References AST_DLLIST_EMPTY, 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_STATIC, AST_LIST_INSERT_TAIL, AST_LIST_TRAVERSE, ast_log(), AST_RWDLLIST_RDLOCK, AST_RWDLLIST_TRAVERSE, AST_RWDLLIST_UNLOCK, ast_event_ie_val::ie_pltype, ast_event_ie_val::ie_type, ast_event_sub::ie_vals, LOG_ERROR, ast_event_ie_val::payload, ast_event_ie_val::raw, ast_event_ie_val::raw_datalen, ast_event_ie_val::str, and ast_event_ie_val::uint.
Referenced by ast_event_queue(), ast_event_sub_activate(), and ast_event_unsubscribe().
00354 { 00355 va_list ap; 00356 enum ast_event_ie_type ie_type; 00357 enum ast_event_subscriber_res res = AST_EVENT_SUB_NONE; 00358 struct ast_event_ie_val *ie_val, *sub_ie_val; 00359 struct ast_event_sub *sub; 00360 AST_LIST_HEAD_NOLOCK_STATIC(ie_vals, ast_event_ie_val); 00361 00362 if (type >= AST_EVENT_TOTAL) { 00363 ast_log(LOG_ERROR, "%u is an invalid type!\n", type); 00364 return res; 00365 } 00366 00367 va_start(ap, type); 00368 for (ie_type = va_arg(ap, enum ast_event_ie_type); 00369 ie_type != AST_EVENT_IE_END; 00370 ie_type = va_arg(ap, enum ast_event_ie_type)) 00371 { 00372 struct ast_event_ie_val *ie_value = alloca(sizeof(*ie_value)); 00373 int insert = 1; 00374 memset(ie_value, 0, sizeof(*ie_value)); 00375 ie_value->ie_type = ie_type; 00376 ie_value->ie_pltype = va_arg(ap, enum ast_event_ie_pltype); 00377 switch (ie_value->ie_pltype) { 00378 case AST_EVENT_IE_PLTYPE_UINT: 00379 ie_value->payload.uint = va_arg(ap, uint32_t); 00380 break; 00381 case AST_EVENT_IE_PLTYPE_BITFLAGS: 00382 ie_value->payload.uint = va_arg(ap, uint32_t); 00383 break; 00384 case AST_EVENT_IE_PLTYPE_STR: 00385 ie_value->payload.str = va_arg(ap, const char *); 00386 break; 00387 case AST_EVENT_IE_PLTYPE_RAW: 00388 { 00389 void *data = va_arg(ap, void *); 00390 size_t datalen = va_arg(ap, size_t); 00391 ie_value->payload.raw = alloca(datalen); 00392 memcpy(ie_value->payload.raw, data, datalen); 00393 ie_value->raw_datalen = datalen; 00394 break; 00395 } 00396 case AST_EVENT_IE_PLTYPE_UNKNOWN: 00397 insert = 0; 00398 case AST_EVENT_IE_PLTYPE_EXISTS: 00399 break; 00400 } 00401 00402 if (insert) { 00403 AST_LIST_INSERT_TAIL(&ie_vals, ie_value, entry); 00404 } 00405 } 00406 va_end(ap); 00407 00408 AST_RWDLLIST_RDLOCK(&ast_event_subs[type]); 00409 AST_RWDLLIST_TRAVERSE(&ast_event_subs[type], sub, entry) { 00410 AST_LIST_TRAVERSE(&ie_vals, ie_val, entry) { 00411 int break_out = 0; 00412 00413 AST_LIST_TRAVERSE(&sub->ie_vals, sub_ie_val, entry) { 00414 if (sub_ie_val->ie_type == ie_val->ie_type) { 00415 break; 00416 } 00417 } 00418 00419 if (!sub_ie_val) { 00420 /* This subscriber doesn't care about this IE, so consider 00421 * it matched. */ 00422 continue; 00423 } 00424 00425 switch (ie_val->ie_pltype) { 00426 case AST_EVENT_IE_PLTYPE_UINT: 00427 break_out = (ie_val->payload.uint != sub_ie_val->payload.uint); 00428 break; 00429 case AST_EVENT_IE_PLTYPE_BITFLAGS: 00430 /* if the subscriber has requested *any* of the bitflags we are providing, 00431 * then it's a match 00432 */ 00433 break_out = (ie_val->payload.uint & sub_ie_val->payload.uint); 00434 break; 00435 case AST_EVENT_IE_PLTYPE_STR: 00436 break_out = strcmp(ie_val->payload.str, sub_ie_val->payload.str); 00437 break; 00438 case AST_EVENT_IE_PLTYPE_RAW: 00439 break_out = memcmp(ie_val->payload.raw, 00440 sub_ie_val->payload.raw, ie_val->raw_datalen); 00441 break; 00442 case AST_EVENT_IE_PLTYPE_EXISTS: 00443 /* The subscriber doesn't actually care what the value is */ 00444 break_out = 1; 00445 break; 00446 case AST_EVENT_IE_PLTYPE_UNKNOWN: 00447 break; 00448 } 00449 00450 if (break_out) { 00451 break; 00452 } 00453 } 00454 00455 if (!ie_val) { 00456 /* Everything matched */ 00457 break; 00458 } 00459 } 00460 AST_RWDLLIST_UNLOCK(&ast_event_subs[type]); 00461 00462 if (sub) { 00463 /* All parameters were matched */ 00464 return AST_EVENT_SUB_EXISTS; 00465 } 00466 00467 AST_RWDLLIST_RDLOCK(&ast_event_subs[AST_EVENT_ALL]); 00468 if (!AST_DLLIST_EMPTY(&ast_event_subs[AST_EVENT_ALL])) { 00469 res = AST_EVENT_SUB_EXISTS; 00470 } 00471 AST_RWDLLIST_UNLOCK(&ast_event_subs[AST_EVENT_ALL]); 00472 00473 return res; 00474 }
| static int ast_event_cmp | ( | void * | obj, | |
| void * | arg, | |||
| int | flags | |||
| ) | [static] |
Definition at line 1465 of file event.c.
References ARRAY_LEN, ast_event_cache, ast_event_get_type(), cache_args, CMP_MATCH, ast_event_ref::event, ast_event_ie_val::ie_type, and match_ie_val().
Referenced by ast_event_init(), and ast_event_queue_and_cache().
01466 { 01467 struct ast_event_ref *event_ref, *event_ref2; 01468 struct ast_event *event, *event2; 01469 int res = CMP_MATCH; 01470 int i; 01471 enum ast_event_ie_type *cache_args; 01472 01473 event_ref = obj; 01474 event = event_ref->event; 01475 01476 event_ref2 = arg; 01477 event2 = event_ref2->event; 01478 01479 cache_args = ast_event_cache[ast_event_get_type(event)].cache_args; 01480 01481 for (i = 0; i < ARRAY_LEN(ast_event_cache[0].cache_args) && cache_args[i]; i++) { 01482 struct ast_event_ie_val ie_val = { 01483 .ie_type = cache_args[i], 01484 }; 01485 01486 if (!match_ie_val(event, &ie_val, event2)) { 01487 res = 0; 01488 break; 01489 } 01490 } 01491 01492 return res; 01493 }
| void ast_event_destroy | ( | struct ast_event * | event | ) |
Destroy an event.
| event | the event to destroy |
Definition at line 1166 of file event.c.
References ast_free.
Referenced by ast_cel_report_event(), ast_event_dup_and_cache(), ast_event_get_cached(), ast_event_queue(), ast_event_ref_destroy(), ast_event_report_subs(), devstate_cached(), get_cached_mwi(), handle_security_event(), has_voicemail(), process_collection(), unistim_send_mwi_to_peer(), and update_registry().
01167 { 01168 ast_free(event); 01169 }
| 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 556 of file event.c.
References ao2_callback, ast_event_cache, dump_cache_cb(), OBJ_NODATA, and ast_event_sub::type.
Referenced by add_publish_event(), and handle_devstate_change().
00557 { 00558 ao2_callback(ast_event_cache[event_sub->type].container, OBJ_NODATA, 00559 dump_cache_cb, (void *) event_sub); 00560 }
Definition at line 1178 of file event.c.
References ast_calloc, ast_event_get_size(), and ast_event::event_len.
Referenced by ast_event_dup_and_cache(), and ast_event_get_cached().
01179 { 01180 struct ast_event *dup_event; 01181 uint16_t event_len; 01182 01183 event_len = ast_event_get_size(event); 01184 01185 if (!(dup_event = ast_calloc(1, event_len))) { 01186 return NULL; 01187 } 01188 01189 memcpy(dup_event, event, event_len); 01190 01191 return dup_event; 01192 }
| static int ast_event_dup_and_cache | ( | const struct ast_event * | event | ) | [static] |
Duplicate an event and add it to the cache.
Definition at line 1277 of file event.c.
References alloc_event_ref(), ao2_link, ao2_ref, ast_event_cache, ast_event_destroy(), ast_event_dup(), ast_event_get_type(), container, and ast_event_ref::event.
Referenced by ast_event_queue_and_cache().
01278 { 01279 struct ast_event *dup_event; 01280 struct ast_event_ref *event_ref; 01281 01282 if (!(dup_event = ast_event_dup(event))) { 01283 return -1; 01284 } 01285 01286 if (!(event_ref = alloc_event_ref())) { 01287 ast_event_destroy(dup_event); 01288 return -1; 01289 } 01290 01291 event_ref->event = dup_event; 01292 01293 ao2_link(ast_event_cache[ast_event_get_type(event)].container, event_ref); 01294 01295 ao2_ref(event_ref, -1); 01296 01297 return 0; 01298 }
| struct ast_event* ast_event_get_cached | ( | enum | ast_event_type, | |
| ... | ||||
| ) | [read] |
Retrieve an event from the cache.
| ast_event_type | The type of event to retrieve from the cache |
<enum ast_event_ie_type>, [enum ast_event_ie_pltype, [payload] ]
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.
The caller of this function *must* call ast_event_destroy() on the returned event after it is done using it.
event = ast_event_get_cached(AST_EVENT_MWI, AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, mailbox, AST_EVENT_IE_END);
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 1194 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().
01195 { 01196 va_list ap; 01197 enum ast_event_ie_type ie_type; 01198 struct ast_event *dup_event = NULL; 01199 struct ast_event_ref *cached_event_ref; 01200 struct ast_event *cache_arg_event; 01201 struct ast_event_ref tmp_event_ref = { 01202 .event = NULL, 01203 }; 01204 struct ao2_container *container = NULL; 01205 01206 if (type >= AST_EVENT_TOTAL) { 01207 ast_log(LOG_ERROR, "%u is an invalid type!\n", type); 01208 return NULL; 01209 } 01210 01211 if (!(container = ast_event_cache[type].container)) { 01212 ast_log(LOG_ERROR, "%u is not a cached event type\n", type); 01213 return NULL; 01214 } 01215 01216 if (!(cache_arg_event = ast_event_new(type, AST_EVENT_IE_END))) { 01217 return NULL; 01218 } 01219 01220 va_start(ap, type); 01221 for (ie_type = va_arg(ap, enum ast_event_ie_type); 01222 ie_type != AST_EVENT_IE_END; 01223 ie_type = va_arg(ap, enum ast_event_ie_type)) 01224 { 01225 enum ast_event_ie_pltype ie_pltype; 01226 01227 ie_pltype = va_arg(ap, enum ast_event_ie_pltype); 01228 01229 switch (ie_pltype) { 01230 case AST_EVENT_IE_PLTYPE_UINT: 01231 ast_event_append_ie_uint(&cache_arg_event, ie_type, va_arg(ap, uint32_t)); 01232 break; 01233 case AST_EVENT_IE_PLTYPE_BITFLAGS: 01234 ast_event_append_ie_bitflags(&cache_arg_event, ie_type, va_arg(ap, uint32_t)); 01235 break; 01236 case AST_EVENT_IE_PLTYPE_STR: 01237 ast_event_append_ie_str(&cache_arg_event, ie_type, va_arg(ap, const char *)); 01238 break; 01239 case AST_EVENT_IE_PLTYPE_RAW: 01240 { 01241 void *data = va_arg(ap, void *); 01242 size_t datalen = va_arg(ap, size_t); 01243 ast_event_append_ie_raw(&cache_arg_event, ie_type, data, datalen); 01244 } 01245 case AST_EVENT_IE_PLTYPE_EXISTS: 01246 ast_log(LOG_WARNING, "PLTYPE_EXISTS not supported by this function\n"); 01247 break; 01248 case AST_EVENT_IE_PLTYPE_UNKNOWN: 01249 break; 01250 } 01251 } 01252 va_end(ap); 01253 01254 tmp_event_ref.event = cache_arg_event; 01255 01256 cached_event_ref = ao2_find(container, &tmp_event_ref, OBJ_POINTER); 01257 01258 ast_event_destroy(cache_arg_event); 01259 cache_arg_event = NULL; 01260 01261 if (cached_event_ref) { 01262 dup_event = ast_event_dup(cached_event_ref->event); 01263 ao2_ref(cached_event_ref, -1); 01264 cached_event_ref = NULL; 01265 } 01266 01267 return dup_event; 01268 }
| 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.
| event | The event to get the IE from | |
| ie_type | the type of information element to retrieve |
Definition at line 970 of file event.c.
References ast_event_get_ie_raw(), and get_unaligned_uint32().
Referenced by append_ie(), and match_ie_val().
00971 { 00972 const uint32_t *ie_val; 00973 00974 ie_val = ast_event_get_ie_raw(event, ie_type); 00975 00976 return ie_val ? ntohl(get_unaligned_uint32(ie_val)) : 0; 00977 }
| 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.
| ie_type | the information element type to get the payload type of |
Definition at line 299 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().
00300 { 00301 if (ie_type <= 0 || ie_type >= ARRAY_LEN(ie_maps)) { 00302 ast_log(LOG_ERROR, "Invalid IE type - '%d'\n", ie_type); 00303 return AST_EVENT_IE_PLTYPE_UNKNOWN; 00304 } 00305 00306 return ie_maps[ie_type].ie_pltype; 00307 }
| 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.
| event | The event to get the IE from | |
| ie_type | the type of information element to retrieve |
Definition at line 997 of file event.c.
References ast_event_iterator_get_ie_raw(), ast_event_iterator_get_ie_type(), ast_event_iterator_init(), and ast_event_iterator_next().
Referenced by ast_event_cb(), ast_event_get_ie_bitflags(), ast_event_get_ie_str(), ast_event_get_ie_str_hash(), ast_event_get_ie_uint(), ast_event_new(), devstate_cache_cb(), devstate_change_collector_cb(), evt_event_deliver_cb(), ie_is_present(), and match_ie_val().
00998 { 00999 struct ast_event_iterator iterator; 01000 int res = 0; 01001 01002 for (ast_event_iterator_init(&iterator, event); !res; res = ast_event_iterator_next(&iterator)) { 01003 if (ast_event_iterator_get_ie_type(&iterator) == ie_type) { 01004 return ast_event_iterator_get_ie_raw(&iterator); 01005 } 01006 } 01007 01008 return NULL; 01009 }
| 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.
| event | The event to get the IE from | |
| ie_type | the type of information element to retrieve |
Definition at line 988 of file event.c.
References ast_event_get_ie_raw(), and ast_event_ie_str_payload::str.
Referenced by 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(), match_ie_val(), mwi_sub_event_cb(), and print_cel_sub().
00989 { 00990 const struct ast_event_ie_str_payload *str_payload; 00991 00992 str_payload = ast_event_get_ie_raw(event, ie_type); 00993 00994 return str_payload->str; 00995 }
| 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.
| event | The event to get the IE from | |
| ie_type | the type of information element to retrieve the hash for |
Definition at line 979 of file event.c.
References ast_event_get_ie_raw(), and ast_event_ie_str_payload::hash.
Referenced by match_ie_val().
00980 { 00981 const struct ast_event_ie_str_payload *str_payload; 00982 00983 str_payload = ast_event_get_ie_raw(event, ie_type); 00984 00985 return str_payload->hash; 00986 }
| const char* ast_event_get_ie_type_name | ( | enum ast_event_ie_type | ie_type | ) |
Get the string representation of an information element type.
| ie_type | the information element type to get the string representation of |
Definition at line 289 of file event.c.
References ARRAY_LEN, ast_log(), ie_maps, LOG_ERROR, and ie_map::name.
Referenced by append_ie(), and security_event_cb().
00290 { 00291 if (ie_type <= 0 || ie_type >= ARRAY_LEN(ie_maps)) { 00292 ast_log(LOG_ERROR, "Invalid IE type - '%d'\n", ie_type); 00293 return ""; 00294 } 00295 00296 return ie_maps[ie_type].name; 00297 }
| 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.
| event | The event to get the IE from | |
| ie_type | the type of information element to retrieve |
Definition at line 961 of file event.c.
References ast_event_get_ie_raw(), and get_unaligned_uint32().
Referenced by append_ie(), ast_cel_fill_record(), device_state_cb(), devstate_cache_cb(), devstate_cached(), devstate_change_collector_cb(), get_cached_mwi(), has_voicemail(), match_ie_val(), mwi_event_cb(), mwi_sub_event_cb(), mwi_unsub_event_cb(), process_collection(), security_event_cb(), sip_send_mwi_to_peer(), unistim_send_mwi_to_peer(), and update_registry().
00962 { 00963 const uint32_t *ie_val; 00964 00965 ie_val = ast_event_get_ie_raw(event, ie_type); 00966 00967 return ie_val ? ntohl(get_unaligned_uint32(ie_val)) : 0; 00968 }
| size_t ast_event_get_size | ( | const struct ast_event * | event | ) |
Get the size of an event.
| event | the event to get the size of |
Definition at line 325 of file event.c.
References ast_event::event_len.
Referenced by ast_event_cb(), and ast_event_dup().
00326 { 00327 size_t res; 00328 00329 res = ntohs(event->event_len); 00330 00331 return res; 00332 }
| enum ast_event_type ast_event_get_type | ( | const struct ast_event * | event | ) |
Get the type for an event.
| event | the event to get the type for |
Definition at line 956 of file event.c.
Referenced by ast_event_cb(), ast_event_cmp(), ast_event_dup_and_cache(), ast_event_get_type_name(), ast_event_hash(), ast_event_queue_and_cache(), mwi_sub_event_cb(), and mwi_unsub_event_cb().
| const char* ast_event_get_type_name | ( | const struct ast_event * | event | ) |
Get the string representation of the type of the given event.
Definition at line 259 of file event.c.
References ARRAY_LEN, ast_event_get_type(), ast_log(), event_names, LOG_ERROR, and ast_event_sub::type.
00260 { 00261 enum ast_event_type type; 00262 00263 type = ast_event_get_type(event); 00264 00265 if (type < 0 || type >= ARRAY_LEN(event_names)) { 00266 ast_log(LOG_ERROR, "Invalid event type - '%d'\n", type); 00267 return ""; 00268 } 00269 00270 return event_names[type]; 00271 }
| static int ast_event_hash | ( | const void * | obj, | |
| const int | flags | |||
| ) | [static] |
Definition at line 1431 of file event.c.
References ast_event_cache, ast_event_get_type(), ast_event_ref::event, and hash_fn.
Referenced by ast_event_init().
01432 { 01433 const struct ast_event_ref *event_ref; 01434 const struct ast_event *event; 01435 ao2_hash_fn *hash_fn; 01436 01437 event_ref = obj; 01438 event = event_ref->event; 01439 01440 if (!(hash_fn = ast_event_cache[ast_event_get_type(event)].hash_fn)) { 01441 return 0; 01442 } 01443 01444 return hash_fn(event, flags); 01445 }
| static int ast_event_hash_devstate | ( | const void * | obj, | |
| const int | flags | |||
| ) | [static] |
Definition at line 1408 of file event.c.
References ast_event_get_ie_str(), AST_EVENT_IE_DEVICE, and ast_str_hash().
01409 { 01410 const struct ast_event *event = obj; 01411 01412 return ast_str_hash(ast_event_get_ie_str(event, AST_EVENT_IE_DEVICE)); 01413 }
| static int ast_event_hash_devstate_change | ( | const void * | obj, | |
| const int | flags | |||
| ) | [static] |
Definition at line 1424 of file event.c.
References ast_event_get_ie_str(), AST_EVENT_IE_DEVICE, and ast_str_hash().
01425 { 01426 const struct ast_event *event = obj; 01427 01428 return ast_str_hash(ast_event_get_ie_str(event, AST_EVENT_IE_DEVICE)); 01429 }
| static int ast_event_hash_mwi | ( | const void * | obj, | |
| const int | flags | |||
| ) | [static] |
Definition at line 1390 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.
01391 { 01392 const struct ast_event *event = obj; 01393 const char *mailbox = ast_event_get_ie_str(event, AST_EVENT_IE_MAILBOX); 01394 const char *context = ast_event_get_ie_str(event, AST_EVENT_IE_CONTEXT); 01395 01396 return ast_str_hash_add(context, ast_str_hash(mailbox)); 01397 }
| static void ast_event_ie_val_destroy | ( | struct ast_event_ie_val * | ie_val | ) | [static] |
Definition at line 334 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_free, ast_event_ie_val::ie_pltype, ast_event_ie_val::payload, ast_event_ie_val::raw, and ast_event_ie_val::str.
Referenced by ast_event_sub_destroy().
00335 { 00336 switch (ie_val->ie_pltype) { 00337 case AST_EVENT_IE_PLTYPE_STR: 00338 ast_free((char *) ie_val->payload.str); 00339 break; 00340 case AST_EVENT_IE_PLTYPE_RAW: 00341 ast_free(ie_val->payload.raw); 00342 break; 00343 case AST_EVENT_IE_PLTYPE_UINT: 00344 case AST_EVENT_IE_PLTYPE_BITFLAGS: 00345 case AST_EVENT_IE_PLTYPE_EXISTS: 00346 case AST_EVENT_IE_PLTYPE_UNKNOWN: 00347 break; 00348 } 00349 00350 ast_free(ie_val); 00351 }
| int ast_event_init | ( | void | ) |
Provided by event.c
Definition at line 1495 of file event.c.
References ao2_container_alloc, ast_event_cache, ast_event_cmp(), ast_event_hash(), ast_event_subs, AST_RWDLLIST_HEAD_INIT, ast_taskprocessor_get(), container, hash_fn, and NUM_CACHE_BUCKETS.
Referenced by main().
01496 { 01497 int i; 01498 01499 for (i = 0; i < AST_EVENT_TOTAL; i++) { 01500 AST_RWDLLIST_HEAD_INIT(&ast_event_subs[i]); 01501 } 01502 01503 for (i = 0; i < AST_EVENT_TOTAL; i++) { 01504 if (!ast_event_cache[i].hash_fn) { 01505 /* This event type is not cached. */ 01506 continue; 01507 } 01508 01509 if (!(ast_event_cache[i].container = ao2_container_alloc(NUM_CACHE_BUCKETS, 01510 ast_event_hash, ast_event_cmp))) { 01511 return -1; 01512 } 01513 } 01514 01515 if (!(event_dispatcher = ast_taskprocessor_get("core_event_dispatcher", 0))) { 01516 return -1; 01517 } 01518 01519 return 0; 01520 }
| 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.
| iterator | The iterator instance |
Definition at line 937 of file event.c.
References get_unaligned_uint32(), ast_event_iterator::ie, and ast_event_ie::ie_payload.
00938 { 00939 return ntohl(get_unaligned_uint32(iterator->ie->ie_payload)); 00940 }
| 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.
| iterator | The iterator instance |
Definition at line 951 of file event.c.
References ast_event_iterator::ie, and ast_event_ie::ie_payload.
Referenced by ast_event_get_ie_raw().
00952 { 00953 return iterator->ie->ie_payload; 00954 }
| 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.
| iterator | The iterator instance |
Definition at line 942 of file event.c.
References ast_event_iterator::ie, ast_event_ie::ie_payload, and ast_event_ie_str_payload::str.
00943 { 00944 const struct ast_event_ie_str_payload *str_payload; 00945 00946 str_payload = (struct ast_event_ie_str_payload *) iterator->ie->ie_payload; 00947 00948 return str_payload->str; 00949 }
| 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.
| iterator | The iterator instance |
Definition at line 927 of file event.c.
References ast_event_iterator::ie.
Referenced by ast_event_get_ie_raw().
00928 { 00929 return ntohs(iterator->ie->ie_type); 00930 }
| 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.
| iterator | The iterator instance |
Definition at line 932 of file event.c.
References get_unaligned_uint32(), ast_event_iterator::ie, and ast_event_ie::ie_payload.
00933 { 00934 return ntohl(get_unaligned_uint32(iterator->ie->ie_payload)); 00935 }
| void ast_event_iterator_init | ( | struct ast_event_iterator * | iterator, | |
| const struct ast_event * | event | |||
| ) |
Initialize an event iterator instance.
| iterator | The iterator instance to initialize | |
| event | The event that will be iterated through |
Definition at line 914 of file event.c.
References ast_event_iterator::event, ast_event::event_len, ast_event_iterator::event_len, and ast_event_iterator::ie.
Referenced by ast_event_get_ie_raw().
00915 { 00916 iterator->event_len = ntohs(event->event_len); 00917 iterator->event = event; 00918 iterator->ie = (struct ast_event_ie *) ( ((char *) event) + sizeof(*event) ); 00919 }
| int ast_event_iterator_next | ( | struct ast_event_iterator * | iterator | ) |
Move iterator instance to next IE.
| iterator | The iterator instance |
| 0 | on success | |
| -1 | if end is reached |
Definition at line 921 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().
00922 { 00923 iterator->ie = (struct ast_event_ie *) ( ((char *) iterator->ie) + sizeof(*iterator->ie) + ntohs(iterator->ie->ie_payload_len)); 00924 return ((iterator->event_len <= (((char *) iterator->ie) - ((char *) iterator->event))) ? -1 : 0); 00925 }
| struct ast_event* ast_event_new | ( | enum ast_event_type | event_type, | |
| ... | ||||
| ) | [read] |
Create a new event.
| event_type | The type of event to create |
<enum ast_event_ie_type>, [enum ast_event_ie_pltype, [payload] ]
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.
if (!(event = ast_event_new(AST_EVENT_MWI, AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, mailbox, AST_EVENT_IE_NEWMSGS, AST_EVENT_IE_PLTYPE_UINT, new, AST_EVENT_IE_OLDMSGS, AST_EVENT_IE_PLTYPE_UINT, old, AST_EVENT_IE_END))) { return; }
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 1064 of file event.c.
References ast_calloc, ast_eid_default, 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 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(), and queue_mwi_event().
01065 { 01066 va_list ap; 01067 struct ast_event *event; 01068 enum ast_event_ie_type ie_type; 01069 struct ast_event_ie_val *ie_val; 01070 AST_LIST_HEAD_NOLOCK_STATIC(ie_vals, ast_event_ie_val); 01071 01072 /* Invalid type */ 01073 if (type >= AST_EVENT_TOTAL) { 01074 ast_log(LOG_WARNING, "Someone tried to create an event of invalid " 01075 "type '%d'!\n", type); 01076 return NULL; 01077 } 01078 01079 va_start(ap, type); 01080 for (ie_type = va_arg(ap, enum ast_event_ie_type); 01081 ie_type != AST_EVENT_IE_END; 01082 ie_type = va_arg(ap, enum ast_event_ie_type)) 01083 { 01084 struct ast_event_ie_val *ie_value = alloca(sizeof(*ie_value)); 01085 int insert = 1; 01086 memset(ie_value, 0, sizeof(*ie_value)); 01087 ie_value->ie_type = ie_type; 01088 ie_value->ie_pltype = va_arg(ap, enum ast_event_ie_pltype); 01089 switch (ie_value->ie_pltype) { 01090 case AST_EVENT_IE_PLTYPE_UINT: 01091 ie_value->payload.uint = va_arg(ap, uint32_t); 01092 break; 01093 case AST_EVENT_IE_PLTYPE_BITFLAGS: 01094 ie_value->payload.uint = va_arg(ap, uint32_t); 01095 break; 01096 case AST_EVENT_IE_PLTYPE_STR: 01097 ie_value->payload.str = va_arg(ap, const char *); 01098 break; 01099 case AST_EVENT_IE_PLTYPE_RAW: 01100 { 01101 void *data = va_arg(ap, void *); 01102 size_t datalen = va_arg(ap, size_t); 01103 ie_value->payload.raw = alloca(datalen); 01104 memcpy(ie_value->payload.raw, data, datalen); 01105 ie_value->raw_datalen = datalen; 01106 break; 01107 } 01108 case AST_EVENT_IE_PLTYPE_UNKNOWN: 01109 insert = 0; 01110 break; 01111 case AST_EVENT_IE_PLTYPE_EXISTS: 01112 break; 01113 } 01114 01115 if (insert) { 01116 AST_LIST_INSERT_TAIL(&ie_vals, ie_value, entry); 01117 } 01118 } 01119 va_end(ap); 01120 01121 if (!(event = ast_calloc(1, sizeof(*event)))) { 01122 return NULL; 01123 } 01124 01125 event->type = htons(type); 01126 event->event_len = htons(sizeof(*event)); 01127 01128 AST_LIST_TRAVERSE(&ie_vals, ie_val, entry) { 01129 switch (ie_val->ie_pltype) { 01130 case AST_EVENT_IE_PLTYPE_STR: 01131 ast_event_append_ie_str(&event, ie_val->ie_type, ie_val->payload.str); 01132 break; 01133 case AST_EVENT_IE_PLTYPE_UINT: 01134 ast_event_append_ie_uint(&event, ie_val->ie_type, ie_val->payload.uint); 01135 break; 01136 case AST_EVENT_IE_PLTYPE_BITFLAGS: 01137 ast_event_append_ie_bitflags(&event, ie_val->ie_type, ie_val->payload.uint); 01138 break; 01139 case AST_EVENT_IE_PLTYPE_RAW: 01140 ast_event_append_ie_raw(&event, ie_val->ie_type, 01141 ie_val->payload.raw, ie_val->raw_datalen); 01142 break; 01143 case AST_EVENT_IE_PLTYPE_EXISTS: 01144 ast_log(LOG_WARNING, "PLTYPE_EXISTS unsupported in event_new\n"); 01145 break; 01146 case AST_EVENT_IE_PLTYPE_UNKNOWN: 01147 ast_log(LOG_WARNING, "PLTYPE_UNKNOWN passed as an IE type " 01148 "for a new event\n"); 01149 break; 01150 } 01151 01152 if (!event) { 01153 break; 01154 } 01155 } 01156 01157 if (!ast_event_get_ie_raw(event, AST_EVENT_IE_EID)) { 01158 /* If the event is originating on this server, add the server's 01159 * entity ID to the event. */ 01160 ast_event_append_ie_raw(&event, AST_EVENT_IE_EID, &ast_eid_default, sizeof(ast_eid_default)); 01161 } 01162 01163 return event; 01164 }
| int ast_event_queue | ( | struct ast_event * | event | ) |
Queue an event.
| event | the event to be queued |
| zero | success | |
| non-zero | failure. Note that the caller of this function is responsible for destroying the event in the case of a failure. |
Definition at line 1359 of file event.c.
References alloc_event_ref(), ast_event_check_subscriber(), ast_event_destroy(), AST_EVENT_IE_END, AST_EVENT_SUB_NONE, ast_log(), ast_taskprocessor_push(), ast_event_ref::event, handle_event(), LOG_NOTICE, and LOG_WARNING.
Referenced by ast_cel_report_event(), ast_event_queue_and_cache(), ast_event_sub_activate(), ast_event_unsubscribe(), and handle_security_event().
01360 { 01361 struct ast_event_ref *event_ref; 01362 uint16_t host_event_type; 01363 01364 host_event_type = ntohs(event->type); 01365 01366 /* Invalid type */ 01367 if (host_event_type >= AST_EVENT_TOTAL) { 01368 ast_log(LOG_WARNING, "Someone tried to queue an event of invalid " 01369 "type '%d'!\n", host_event_type); 01370 return -1; 01371 } 01372 01373 /* If nobody has subscribed to this event type, throw it away now */ 01374 if (ast_event_check_subscriber(host_event_type, AST_EVENT_IE_END) 01375 == AST_EVENT_SUB_NONE) { 01376 ast_event_destroy(event); 01377 ast_log(LOG_NOTICE, "Event destroyed, no subscriber\n"); 01378 return 0; 01379 } 01380 01381 if (!(event_ref = alloc_event_ref())) { 01382 return -1; 01383 } 01384 01385 event_ref->event = event; 01386 01387 return ast_taskprocessor_push(event_dispatcher, handle_event, event_ref); 01388 }
| int ast_event_queue_and_cache | ( | struct ast_event * | event | ) |
Queue and cache an event.
| event | the event to be queued and cached |
The event API already knows which events can be cached and how to cache them.
| 0 | success | |
| non-zero | failure. If failure is returned, the event must be destroyed by the caller of this function. |
Definition at line 1300 of file event.c.
References ao2_callback, ast_event_cache, ast_event_cmp(), ast_event_dup_and_cache(), ast_event_get_type(), ast_event_queue(), ast_log(), container, ast_event_ref::event, LOG_WARNING, OBJ_MULTIPLE, OBJ_NODATA, OBJ_POINTER, OBJ_UNLINK, and queue_event().
Referenced by devstate_event(), handle_request_notify(), notify_message(), process_collection(), queue_event(), and queue_mwi_event().
01301 { 01302 struct ao2_container *container; 01303 struct ast_event_ref tmp_event_ref = { 01304 .event = event, 01305 }; 01306 int res = -1; 01307 01308 if (!(container = ast_event_cache[ast_event_get_type(event)].container)) { 01309 ast_log(LOG_WARNING, "cache requested for non-cached event type\n"); 01310 goto queue_event; 01311 } 01312 01313 /* Remove matches from the cache */ 01314 ao2_callback(container, OBJ_POINTER | OBJ_UNLINK | OBJ_MULTIPLE | OBJ_NODATA, 01315 ast_event_cmp, &tmp_event_ref); 01316 01317 res = ast_event_dup_and_cache(event); 01318 01319 queue_event: 01320 return ast_event_queue(event) ? -1 : res; 01321 }
| static void ast_event_ref_destroy | ( | void * | obj | ) | [static] |
Definition at line 1171 of file event.c.
References ast_event_destroy(), and ast_event_ref::event.
Referenced by alloc_event_ref().
01172 { 01173 struct ast_event_ref *event_ref = obj; 01174 01175 ast_event_destroy(event_ref->event); 01176 }
| 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 604 of file event.c.
References ast_event_destroy(), AST_EVENT_IE_EVENTTYPE, AST_EVENT_SUB, ast_event_subs, AST_LIST_TRAVERSE, AST_RWDLLIST_RDLOCK, AST_RWDLLIST_TRAVERSE, AST_RWDLLIST_UNLOCK, ast_event_sub::cb, gen_sub_event(), ast_event_ie_val::ie_type, ast_event_sub::ie_vals, ast_event_ie_val::payload, ast_event_sub::type, ast_event_ie_val::uint, and ast_event_sub::userdata.
Referenced by handle_cli_status(), and start_poll_thread().
00605 { 00606 struct ast_event *event; 00607 struct ast_event_sub *sub; 00608 enum ast_event_type event_type = -1; 00609 struct ast_event_ie_val *ie_val; 00610 00611 if (event_sub->type != AST_EVENT_SUB) 00612 return; 00613 00614 AST_LIST_TRAVERSE(&event_sub->ie_vals, ie_val, entry) { 00615 if (ie_val->ie_type == AST_EVENT_IE_EVENTTYPE) { 00616 event_type = ie_val->payload.uint; 00617 break; 00618 } 00619 } 00620 00621 if (event_type == -1) 00622 return; 00623 00624 AST_RWDLLIST_RDLOCK(&ast_event_subs[event_type]); 00625 AST_RWDLLIST_TRAVERSE(&ast_event_subs[event_type], sub, entry) { 00626 if (event_sub == sub) { 00627 continue; 00628 } 00629 00630 event = gen_sub_event(sub); 00631 00632 if (!event) { 00633 continue; 00634 } 00635 00636 event_sub->cb(event, event_sub->userdata); 00637 00638 ast_event_destroy(event); 00639 } 00640 AST_RWDLLIST_UNLOCK(&ast_event_subs[event_type]); 00641 }
| int ast_event_str_to_event_type | ( | const char * | str, | |
| enum ast_event_type * | event_type | |||
| ) |
Convert a string into an event type.
| str | the string to convert | |
| event_type | an output parameter for the event type |
| 0 | success | |
| non-zero | failure |
Definition at line 273 of file event.c.
References ARRAY_LEN, and event_names.
00274 { 00275 int i; 00276 00277 for (i = 0; i < ARRAY_LEN(event_names); i++) { 00278 if (strcasecmp(event_names[i], str)) { 00279 continue; 00280 } 00281 00282 *event_type = i; 00283 return 0; 00284 } 00285 00286 return -1; 00287 }
| int ast_event_str_to_ie_type | ( | const char * | str, | |
| enum ast_event_ie_type * | ie_type | |||
| ) |
Convert a string to an IE type.
| str | the string to convert | |
| ie_type | an output parameter for the IE type |
| 0 | success | |
| non-zero | failure |
Definition at line 309 of file event.c.
References ARRAY_LEN, ie_maps, and name.
00310 { 00311 int i; 00312 00313 for (i = 0; i < ARRAY_LEN(ie_maps); i++) { 00314 if (strcasecmp(ie_maps[i].name, str)) { 00315 continue; 00316 } 00317 00318 *ie_type = i; 00319 return 0; 00320 } 00321 00322 return -1; 00323 }
| int ast_event_sub_activate | ( | struct ast_event_sub * | sub | ) |
Activate a dynamically built subscription.
| sub | the subscription to activate that was allocated using ast_event_subscribe_new() |
| 0 | success | |
| non-zero | failure |
Definition at line 787 of file event.c.
References ast_event_check_subscriber(), AST_EVENT_IE_END, AST_EVENT_IE_EVENTTYPE, AST_EVENT_IE_PLTYPE_UINT, ast_event_queue(), AST_EVENT_SUB, AST_EVENT_SUB_NONE, ast_event_subs, AST_RWDLLIST_INSERT_TAIL, AST_RWDLLIST_UNLOCK, AST_RWDLLIST_WRLOCK, gen_sub_event(), and ast_event_sub::type.
Referenced by ast_event_subscribe().
00788 { 00789 if (ast_event_check_subscriber(AST_EVENT_SUB, 00790 AST_EVENT_IE_EVENTTYPE, AST_EVENT_IE_PLTYPE_UINT, sub->type, 00791 AST_EVENT_IE_END) != AST_EVENT_SUB_NONE) { 00792 struct ast_event *event; 00793 00794 event = gen_sub_event(sub); 00795 00796 if (event) { 00797 ast_event_queue(event); 00798 } 00799 } 00800 00801 AST_RWDLLIST_WRLOCK(&ast_event_subs[sub->type]); 00802 AST_RWDLLIST_INSERT_TAIL(&ast_event_subs[sub->type], sub, entry); 00803 AST_RWDLLIST_UNLOCK(&ast_event_subs[sub->type]); 00804 00805 return 0; 00806 }
| 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.
| 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 |
| 0 | success | |
| non-zero | failure |
Definition at line 687 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().
00689 { 00690 struct ast_event_ie_val *ie_val; 00691 00692 if (ie_type <= 0 || ie_type >= AST_EVENT_IE_TOTAL) { 00693 return -1; 00694 } 00695 00696 if (!(ie_val = ast_calloc(1, sizeof(*ie_val)))) { 00697 return -1; 00698 } 00699 00700 ie_val->ie_type = ie_type; 00701 ie_val->payload.uint = flags; 00702 ie_val->ie_pltype = AST_EVENT_IE_PLTYPE_BITFLAGS; 00703 00704 AST_LIST_INSERT_TAIL(&sub->ie_vals, ie_val, entry); 00705 00706 return 0; 00707 }
| 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.
| 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. |
| 0 | success | |
| non-zero | failure |
Definition at line 709 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().
00711 { 00712 struct ast_event_ie_val *ie_val; 00713 00714 if (ie_type <= 0 || ie_type >= AST_EVENT_IE_TOTAL) { 00715 return -1; 00716 } 00717 00718 if (!(ie_val = ast_calloc(1, sizeof(*ie_val)))) { 00719 return -1; 00720 } 00721 00722 ie_val->ie_type = ie_type; 00723 ie_val->ie_pltype = AST_EVENT_IE_PLTYPE_EXISTS; 00724 00725 AST_LIST_INSERT_TAIL(&sub->ie_vals, ie_val, entry); 00726 00727 return 0; 00728 }
| 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.
| sub | the dynamic subscription allocated with ast_event_subscribe_new() | |
| ie_type | the information element type for the parameter | |
| raw | the data that must be present in the event to match this subscription |
| 0 | success | |
| non-zero | failure |
Definition at line 758 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().
00760 { 00761 struct ast_event_ie_val *ie_val; 00762 00763 if (ie_type <= 0 || ie_type >= AST_EVENT_IE_TOTAL) { 00764 return -1; 00765 } 00766 00767 if (!(ie_val = ast_calloc(1, sizeof(*ie_val)))) { 00768 return -1; 00769 } 00770 00771 ie_val->ie_type = ie_type; 00772 ie_val->ie_pltype = AST_EVENT_IE_PLTYPE_RAW; 00773 ie_val->raw_datalen = raw_datalen; 00774 00775 if (!(ie_val->payload.raw = ast_malloc(raw_datalen))) { 00776 ast_free(ie_val); 00777 return -1; 00778 } 00779 00780 memcpy(ie_val->payload.raw, data, raw_datalen); 00781 00782 AST_LIST_INSERT_TAIL(&sub->ie_vals, ie_val, entry); 00783 00784 return 0; 00785 }
| 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.
| 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 |
| 0 | success | |
| non-zero | failure |
Definition at line 730 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().
00732 { 00733 struct ast_event_ie_val *ie_val; 00734 00735 if (ie_type <= 0 || ie_type >= AST_EVENT_IE_TOTAL) { 00736 return -1; 00737 } 00738 00739 if (!(ie_val = ast_calloc(1, sizeof(*ie_val)))) { 00740 return -1; 00741 } 00742 00743 ie_val->ie_type = ie_type; 00744 ie_val->ie_pltype = AST_EVENT_IE_PLTYPE_STR; 00745 00746 if (!(ie_val->payload.str = ast_strdup(str))) { 00747 ast_free(ie_val); 00748 return -1; 00749 } 00750 00751 ie_val->payload.hash = ast_str_hash(str); 00752 00753 AST_LIST_INSERT_TAIL(&sub->ie_vals, ie_val, entry); 00754 00755 return 0; 00756 }
| 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.
| 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 |
| 0 | success | |
| non-zero | failure |
Definition at line 665 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().
00667 { 00668 struct ast_event_ie_val *ie_val; 00669 00670 if (ie_type <= 0 || ie_type >= AST_EVENT_IE_TOTAL) { 00671 return -1; 00672 } 00673 00674 if (!(ie_val = ast_calloc(1, sizeof(*ie_val)))) { 00675 return -1; 00676 } 00677 00678 ie_val->ie_type = ie_type; 00679 ie_val->payload.uint = unsigned_int; 00680 ie_val->ie_pltype = AST_EVENT_IE_PLTYPE_UINT; 00681 00682 AST_LIST_INSERT_TAIL(&sub->ie_vals, ie_val, entry); 00683 00684 return 0; 00685 }
| void ast_event_sub_destroy | ( | struct ast_event_sub * | sub | ) |
Destroy an allocated subscription.
| sub | the subscription to destroy |
Definition at line 870 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(), handle_cli_status(), and handle_devstate_change().
00871 { 00872 struct ast_event_ie_val *ie_val; 00873 00874 while ((ie_val = AST_LIST_REMOVE_HEAD(&sub->ie_vals, entry))) { 00875 ast_event_ie_val_destroy(ie_val); 00876 } 00877 00878 ast_free(sub); 00879 }
| struct ast_event_sub* ast_event_subscribe | ( | enum ast_event_type | event_type, | |
| ast_event_cb_t | cb, | |||
| char * | description, | |||
| void * | userdata, | |||
| ... | ||||
| ) | [read] |
Subscribe to events.
| 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 |
<enum ast_event_ie_type>, [enum ast_event_ie_pltype, [payload] ]
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.
peer->mwi_event_sub = ast_event_subscribe(AST_EVENT_MWI, mwi_event_cb, peer, AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, peer->mailbox, AST_EVENT_IE_END);
This creates a subscription to AST_EVENT_MWI events that contain an information element, AST_EVENT_IE_MAILBOX, with the same string value contained in peer->mailbox. Also, the event callback will be passed a pointer to the peer.
Definition at line 808 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, and str.
Referenced by add_peer_mwi_subs(), add_publish_event(), ast_enable_distributed_devstate(), build_gateway(), build_peer(), config_line(), load_module(), load_pbx(), mkintf(), and start_poll_thread().
00810 { 00811 va_list ap; 00812 enum ast_event_ie_type ie_type; 00813 struct ast_event_sub *sub; 00814 00815 if (!(sub = ast_event_subscribe_new(type, cb, userdata))) { 00816 return NULL; 00817 } 00818 00819 ast_copy_string(sub->description, description, sizeof(sub->description)); 00820 00821 va_start(ap, userdata); 00822 for (ie_type = va_arg(ap, enum ast_event_ie_type); 00823 ie_type != AST_EVENT_IE_END; 00824 ie_type = va_arg(ap, enum ast_event_ie_type)) 00825 { 00826 enum ast_event_ie_pltype ie_pltype; 00827 00828 ie_pltype = va_arg(ap, enum ast_event_ie_pltype); 00829 00830 switch (ie_pltype) { 00831 case AST_EVENT_IE_PLTYPE_UNKNOWN: 00832 break; 00833 case AST_EVENT_IE_PLTYPE_UINT: 00834 { 00835 uint32_t unsigned_int = va_arg(ap, uint32_t); 00836 ast_event_sub_append_ie_uint(sub, ie_type, unsigned_int); 00837 break; 00838 } 00839 case AST_EVENT_IE_PLTYPE_BITFLAGS: 00840 { 00841 uint32_t unsigned_int = va_arg(ap, uint32_t); 00842 ast_event_sub_append_ie_bitflags(sub, ie_type, unsigned_int); 00843 break; 00844 } 00845 case AST_EVENT_IE_PLTYPE_STR: 00846 { 00847 const char *str = va_arg(ap, const char *); 00848 ast_event_sub_append_ie_str(sub, ie_type, str); 00849 break; 00850 } 00851 case AST_EVENT_IE_PLTYPE_RAW: 00852 { 00853 void *data = va_arg(ap, void *); 00854 size_t data_len = va_arg(ap, size_t); 00855 ast_event_sub_append_ie_raw(sub, ie_type, data, data_len); 00856 break; 00857 } 00858 case AST_EVENT_IE_PLTYPE_EXISTS: 00859 ast_event_sub_append_ie_exists(sub, ie_type); 00860 break; 00861 } 00862 } 00863 va_end(ap); 00864 00865 ast_event_sub_activate(sub); 00866 00867 return sub; 00868 }
| 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.
| 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 |
Definition at line 643 of file event.c.
References ast_atomic_fetchadd_int(), ast_calloc, ast_log(), ast_event_sub::cb, LOG_ERROR, ast_event_sub::type, ast_event_sub::uniqueid, and ast_event_sub::userdata.
Referenced by ast_event_subscribe(), handle_cli_status(), and handle_devstate_change().
00645 { 00646 struct ast_event_sub *sub; 00647 00648 if (type < 0 || type >= AST_EVENT_TOTAL) { 00649 ast_log(LOG_ERROR, "%u is an invalid type!\n", type); 00650 return NULL; 00651 } 00652 00653 if (!(sub = ast_calloc(1, sizeof(*sub)))) { 00654 return NULL; 00655 } 00656 00657 sub->type = type; 00658 sub->cb = cb; 00659 sub->userdata = userdata; 00660 sub->uniqueid = ast_atomic_fetchadd_int((int *) &sub_uniqueid, 1); 00661 00662 return sub; 00663 }
| const char* ast_event_subscriber_get_description | ( | struct ast_event_sub * | sub | ) |
Get description for a subscription.
| sub | subscription |
Definition at line 881 of file event.c.
References ast_event_sub::description.
00882 { 00883 return sub ? sub->description : NULL; 00884 }
| struct ast_event_sub* ast_event_unsubscribe | ( | struct ast_event_sub * | event_sub | ) | [read] |
Un-subscribe from events.
| event_sub | This is the reference to the subscription returned by ast_event_subscribe. |
Definition at line 886 of file event.c.
References AST_DLLIST_REMOVE, ast_event_check_subscriber(), 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 destroy_dahdi_pvt(), destroy_endpoint(), destroy_mailbox(), peer_destructor(), publish_event_destroy(), stop_poll_thread(), and unload_module().
00887 { 00888 struct ast_event *event; 00889 00890 AST_RWDLLIST_WRLOCK(&ast_event_subs[sub->type]); 00891 AST_DLLIST_REMOVE(&ast_event_subs[sub->type], sub, entry); 00892 AST_RWDLLIST_UNLOCK(&ast_event_subs[sub->type]); 00893 00894 if (ast_event_check_subscriber(AST_EVENT_UNSUB, 00895 AST_EVENT_IE_EVENTTYPE, AST_EVENT_IE_PLTYPE_UINT, sub->type, 00896 AST_EVENT_IE_END) != AST_EVENT_SUB_NONE) { 00897 00898 event = ast_event_new(AST_EVENT_UNSUB, 00899 AST_EVENT_IE_UNIQUEID, AST_EVENT_IE_PLTYPE_UINT, sub->uniqueid, 00900 AST_EVENT_IE_EVENTTYPE, AST_EVENT_IE_PLTYPE_UINT, sub->type, 00901 AST_EVENT_IE_DESCRIPTION, AST_EVENT_IE_PLTYPE_STR, sub->description, 00902 AST_EVENT_IE_END); 00903 00904 if (event) { 00905 ast_event_queue(event); 00906 } 00907 } 00908 00909 ast_event_sub_destroy(sub); 00910 00911 return NULL; 00912 }
| static int dump_cache_cb | ( | void * | obj, | |
| void * | arg, | |||
| int | flags | |||
| ) | [static] |
Definition at line 534 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().
00535 { 00536 const struct ast_event_ref *event_ref = obj; 00537 const struct ast_event *event = event_ref->event; 00538 const struct ast_event_sub *event_sub = arg; 00539 struct ast_event_ie_val *ie_val = NULL; 00540 00541 AST_LIST_TRAVERSE(&event_sub->ie_vals, ie_val, entry) { 00542 if (!match_ie_val(event, ie_val, NULL)) { 00543 break; 00544 } 00545 } 00546 00547 if (!ie_val) { 00548 /* All parameters were matched on this cache entry, so dump it */ 00549 event_sub->cb(event, event_sub->userdata); 00550 } 00551 00552 return 0; 00553 }
| static struct ast_event* gen_sub_event | ( | struct ast_event_sub * | sub | ) | [static, read] |
Definition at line 562 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().
00563 { 00564 struct ast_event_ie_val *ie_val; 00565 struct ast_event *event; 00566 00567 event = ast_event_new(AST_EVENT_SUB, 00568 AST_EVENT_IE_UNIQUEID, AST_EVENT_IE_PLTYPE_UINT, sub->uniqueid, 00569 AST_EVENT_IE_EVENTTYPE, AST_EVENT_IE_PLTYPE_UINT, sub->type, 00570 AST_EVENT_IE_DESCRIPTION, AST_EVENT_IE_PLTYPE_STR, sub->description, 00571 AST_EVENT_IE_END); 00572 00573 if (!event) 00574 return NULL; 00575 00576 AST_LIST_TRAVERSE(&sub->ie_vals, ie_val, entry) { 00577 switch (ie_val->ie_pltype) { 00578 case AST_EVENT_IE_PLTYPE_UNKNOWN: 00579 break; 00580 case AST_EVENT_IE_PLTYPE_EXISTS: 00581 ast_event_append_ie_uint(&event, AST_EVENT_IE_EXISTS, ie_val->ie_type); 00582 break; 00583 case AST_EVENT_IE_PLTYPE_UINT: 00584 ast_event_append_ie_uint(&event, ie_val->ie_type, ie_val->payload.uint); 00585 break; 00586 case AST_EVENT_IE_PLTYPE_BITFLAGS: 00587 ast_event_append_ie_bitflags(&event, ie_val->ie_type, ie_val->payload.uint); 00588 break; 00589 case AST_EVENT_IE_PLTYPE_STR: 00590 ast_event_append_ie_str(&event, ie_val->ie_type, ie_val->payload.str); 00591 break; 00592 case AST_EVENT_IE_PLTYPE_RAW: 00593 ast_event_append_ie_raw(&event, ie_val->ie_type, ie_val->payload.raw, ie_val->raw_datalen); 00594 break; 00595 } 00596 if (!event) 00597 break; 00598 } 00599 00600 return event; 00601 }
| static int handle_event | ( | void * | data | ) | [static] |
Definition at line 1323 of file event.c.
References ao2_ref, AST_EVENT_ALL, ast_event_subs, AST_LIST_TRAVERSE, AST_RWDLLIST_RDLOCK, AST_RWDLLIST_TRAVERSE, AST_RWDLLIST_UNLOCK, ast_event_sub::cb, ast_event_ref::event, ast_event_sub::ie_vals, match_ie_val(), and ast_event_sub::userdata.
01324 { 01325 struct ast_event_ref *event_ref = data; 01326 struct ast_event_sub *sub; 01327 uint16_t host_event_type; 01328 01329 host_event_type = ntohs(event_ref->event->type); 01330 01331 /* Subscribers to this specific event first */ 01332 AST_RWDLLIST_RDLOCK(&ast_event_subs[host_event_type]); 01333 AST_RWDLLIST_TRAVERSE(&ast_event_subs[host_event_type], sub, entry) { 01334 struct ast_event_ie_val *ie_val; 01335 AST_LIST_TRAVERSE(&sub->ie_vals, ie_val, entry) { 01336 if (!match_ie_val(event_ref->event, ie_val, NULL)) { 01337 break; 01338 } 01339 } 01340 if (ie_val) { 01341 continue; 01342 } 01343 sub->cb(event_ref->event, sub->userdata); 01344 } 01345 AST_RWDLLIST_UNLOCK(&ast_event_subs[host_event_type]); 01346 01347 /* Now to subscribers to all event types */ 01348 AST_RWDLLIST_RDLOCK(&ast_event_subs[AST_EVENT_ALL]); 01349 AST_RWDLLIST_TRAVERSE(&ast_event_subs[AST_EVENT_ALL], sub, entry) { 01350 sub->cb(event_ref->event, sub->userdata); 01351 } 01352 AST_RWDLLIST_UNLOCK(&ast_event_subs[AST_EVENT_ALL]); 01353 01354 ao2_ref(event_ref, -1); 01355 01356 return 0; 01357 }
| 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 476 of file event.c.
References ast_event_get_ie_bitflags(), ast_event_get_ie_raw(), ast_event_get_ie_str(), ast_event_get_ie_str_hash(), ast_event_get_ie_uint(), AST_EVENT_IE_PLTYPE_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, buf, ast_event_ie_val::hash, ast_event_ie_val::ie_pltype, ast_event_ie_val::ie_type, ast_event_ie_val::payload, ast_event_ie_val::raw, ast_event_ie_val::raw_datalen, ast_event_ie_val::str, str, and ast_event_ie_val::uint.
Referenced by ast_event_cmp(), dump_cache_cb(), and handle_event().
00478 { 00479 switch (ie_val->ie_pltype) { 00480 case AST_EVENT_IE_PLTYPE_UINT: 00481 { 00482 uint32_t val = event2 ? ast_event_get_ie_uint(event2, ie_val->ie_type) : ie_val->payload.uint; 00483 00484 return (val == ast_event_get_ie_uint(event, ie_val->ie_type)) ? 1 : 0; 00485 } 00486 00487 case AST_EVENT_IE_PLTYPE_BITFLAGS: 00488 { 00489 uint32_t flags = event2 ? ast_event_get_ie_uint(event2, ie_val->ie_type) : ie_val->payload.uint; 00490 00491 /* if the subscriber has requested *any* of the bitflags that this event provides, 00492 * then it's a match 00493 */ 00494 return (flags & ast_event_get_ie_bitflags(event, ie_val->ie_type)) ? 1 : 0; 00495 } 00496 00497 case AST_EVENT_IE_PLTYPE_STR: 00498 { 00499 const char *str; 00500 uint32_t hash; 00501 00502 hash = event2 ? ast_event_get_ie_str_hash(event2, ie_val->ie_type) : ie_val->payload.hash; 00503 if (hash != ast_event_get_ie_str_hash(event, ie_val->ie_type)) { 00504 return 0; 00505 } 00506 00507 str = event2 ? ast_event_get_ie_str(event2, ie_val->ie_type) : ie_val->payload.str; 00508 if (str && !strcmp(str, ast_event_get_ie_str(event, ie_val->ie_type))) { 00509 return 1; 00510 } 00511 00512 return 0; 00513 } 00514 00515 case AST_EVENT_IE_PLTYPE_RAW: 00516 { 00517 const void *buf = event2 ? ast_event_get_ie_raw(event2, ie_val->ie_type) : ie_val->payload.raw; 00518 00519 return (buf && !memcmp(buf, ast_event_get_ie_raw(event, ie_val->ie_type), ie_val->raw_datalen)) ? 1 : 0; 00520 } 00521 00522 case AST_EVENT_IE_PLTYPE_EXISTS: 00523 { 00524 return ast_event_get_ie_raw(event, ie_val->ie_type) ? 1 : 0; 00525 } 00526 00527 case AST_EVENT_IE_PLTYPE_UNKNOWN: 00528 return 0; 00529 } 00530 00531 return 0; 00532 }
struct { ... } ast_event_cache[AST_EVENT_TOTAL] [static] |
Event types that are kept in the cache.
Referenced by ast_event_cmp(), ast_event_dump_cache(), ast_event_dup_and_cache(), ast_event_get_cached(), ast_event_hash(), ast_event_init(), and ast_event_queue_and_cache().
struct ast_event_sub_list ast_event_subs[AST_EVENT_TOTAL] [static] |
Event subscriptions The event subscribers are indexed by which event they are subscribed to.
Referenced by ast_event_check_subscriber(), ast_event_init(), ast_event_report_subs(), ast_event_sub_activate(), ast_event_unsubscribe(), and handle_event().
| enum ast_event_ie_type cache_args[MAX_CACHE_ARGS] |
Information Elements used for caching.
This array is the set of information elements that will be unique among all events in the cache for this event type. When a new event gets cached, a previous event with the same values for these information elements will be replaced.
Definition at line 169 of file event.c.
Referenced by ast_event_cmp().
| struct ao2_container* container |
Container of cached events.
This gets allocated in ast_event_init() when Asterisk starts for the event types declared as using the cache.
Definition at line 158 of file event.c.
Referenced by ast_event_dup_and_cache(), ast_event_get_cached(), ast_event_init(), and ast_event_queue_and_cache().
struct ast_taskprocessor* event_dispatcher [static] |
const char* const event_names[AST_EVENT_TOTAL] [static] |
Event Names.
Definition at line 188 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 160 of file event.c.
Referenced by ast_event_hash(), and ast_event_init().
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] |
1.5.6