#include "asterisk/event_defs.h"


Go to the source code of this file.
Typedefs | |
| typedef void(* | ast_event_cb_t )(const struct ast_event *event, void *userdata) |
| Subscriber event callback type. | |
Functions | |
| 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 event_type,...) |
| Check if subscribers exist. | |
| void | ast_event_destroy (struct ast_event *event) |
| Destroy an event. | |
| void | ast_event_dump_cache (const struct ast_event_sub *event_sub) |
| Dump the event cache for the subscriber. | |
| struct ast_event * | ast_event_get_cached (enum ast_event_type,...) |
| Retrieve an event from the cache. | |
| enum ast_event_ie_pltype | ast_event_get_ie_pltype (enum ast_event_ie_type ie_type) |
| Get the payload type for a given information element type. | |
| const void * | ast_event_get_ie_raw (const struct ast_event *event, enum ast_event_ie_type ie_type) |
| Get the value of an information element that has a raw payload. | |
| 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. | |
| 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 ierator as an integer payload. | |
| int | ast_event_iterator_init (struct ast_event_iterator *iterator, const struct ast_event *event) |
| Initialize an event iterator instance. | |
| int | ast_event_iterator_next (struct ast_event_iterator *iterator) |
| Move iterator instance to next IE. | |
| struct ast_event * | ast_event_new (enum ast_event_type event_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. | |
| void | ast_event_report_subs (const struct ast_event_sub *sub) |
| Report current subscriptions to a subscription subscriber. | |
| int | ast_event_str_to_event_type (const char *str, enum ast_event_type *event_type) |
| Convert a string into an event type. | |
| int | ast_event_str_to_ie_type (const char *str, enum ast_event_ie_type *ie_type) |
| Convert a string to an IE type. | |
| int | ast_event_sub_activate (struct ast_event_sub *sub) |
| Activate a dynamically built subscription. | |
| int | ast_event_sub_append_ie_exists (struct ast_event_sub *sub, enum ast_event_ie_type ie_type) |
| Append an 'exists' parameter to a subscription. | |
| int | ast_event_sub_append_ie_raw (struct ast_event_sub *sub, enum ast_event_ie_type ie_type, void *data, size_t raw_datalen) |
| Append a raw parameter to a subscription. | |
| int | ast_event_sub_append_ie_str (struct ast_event_sub *sub, enum ast_event_ie_type ie_type, const char *str) |
| Append a string parameter to a subscription. | |
| int | ast_event_sub_append_ie_uint (struct ast_event_sub *sub, enum ast_event_ie_type ie_type, uint32_t uint) |
| 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 event_type, ast_event_cb_t cb, void *userdata,...) |
| Subscribe to events. | |
| struct ast_event_sub * | ast_event_subscribe_new (enum ast_event_type type, ast_event_cb_t cb, void *userdata) |
| Allocate a subscription, but do not activate it. | |
| struct ast_event_sub * | ast_event_unsubscribe (struct ast_event_sub *event_sub) |
| Un-subscribe from events. | |
Definition in file event.h.
| typedef void(* ast_event_cb_t)(const struct ast_event *event, void *userdata) |
Subscriber event callback type.
| event | the event being passed to the subscriber | |
| userdata | the data provider in the call to ast_event_subscribe() |
| 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 953 of file event.c.
References ast_realloc, ast_event_ie::ie_payload, and ast_event_ie::ie_payload_len.
Referenced by ast_event_append_ie_str(), ast_event_append_ie_uint(), ast_event_get_cached(), ast_event_new(), and gen_sub_event().
00955 { 00956 struct ast_event_ie *ie; 00957 unsigned int extra_len; 00958 uint16_t event_len; 00959 00960 event_len = ntohs((*event)->event_len); 00961 extra_len = sizeof(*ie) + data_len; 00962 00963 if (!(*event = ast_realloc(*event, event_len + extra_len))) 00964 return -1; 00965 00966 ie = (struct ast_event_ie *) ( ((char *) *event) + event_len ); 00967 ie->ie_type = htons(ie_type); 00968 ie->ie_payload_len = htons(data_len); 00969 memcpy(ie->ie_payload, data, data_len); 00970 00971 (*event)->event_len = htons(event_len + extra_len); 00972 00973 return 0; 00974 }
| 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 931 of file event.c.
References ast_event_append_ie_raw(), ast_str_hash(), ast_event_ie_str_payload::hash, and ast_event_ie_str_payload::str.
Referenced by ast_event_get_cached(), ast_event_new(), and gen_sub_event().
00933 { 00934 struct ast_event_ie_str_payload *str_payload; 00935 size_t payload_len; 00936 00937 payload_len = sizeof(*str_payload) + strlen(str); 00938 str_payload = alloca(payload_len); 00939 00940 strcpy(str_payload->str, str); 00941 str_payload->hash = ast_str_hash(str); 00942 00943 return ast_event_append_ie_raw(event, ie_type, str_payload, payload_len); 00944 }
| 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 946 of file event.c.
References ast_event_append_ie_raw().
Referenced by ast_event_get_cached(), ast_event_new(), and gen_sub_event().
00948 { 00949 data = htonl(data); 00950 return ast_event_append_ie_raw(event, ie_type, &data, sizeof(data)); 00951 }
| 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 376 of file event.c.
References ARRAY_LEN, AST_EVENT_ALL, AST_EVENT_IE_END, AST_EVENT_IE_PLTYPE_RAW, AST_EVENT_IE_PLTYPE_STR, AST_EVENT_IE_PLTYPE_UINT, AST_EVENT_SUB_EXISTS, AST_EVENT_SUB_NONE, ast_event_subs, AST_LIST_HEAD_NOLOCK_STATIC, AST_LIST_INSERT_TAIL, AST_LIST_TRAVERSE, ast_log(), AST_RWDLLIST_RDLOCK, AST_RWDLLIST_TRAVERSE, AST_RWDLLIST_UNLOCK, ast_strdupa, ast_event_ie_val::ie_pltype, ast_event_ie_val::ie_type, LOG_ERROR, match_ie_val_to_sub(), ast_event_ie_val::payload, ast_event_ie_val::raw, ast_event_ie_val::raw_datalen, ast_event_ie_val::str, and ast_event_ie_val::uint.
Referenced by ast_event_queue(), ast_event_sub_activate(), and ast_event_unsubscribe().
00377 { 00378 va_list ap; 00379 enum ast_event_ie_type ie_type; 00380 enum ast_event_subscriber_res res = AST_EVENT_SUB_NONE; 00381 struct ast_event_ie_val *ie_val; 00382 struct ast_event_sub *sub; 00383 AST_LIST_HEAD_NOLOCK_STATIC(ie_vals, ast_event_ie_val); 00384 const enum ast_event_type event_types[] = { type, AST_EVENT_ALL }; 00385 int i; 00386 00387 if (type >= AST_EVENT_TOTAL) { 00388 ast_log(LOG_ERROR, "%u is an invalid type!\n", type); 00389 return res; 00390 } 00391 00392 va_start(ap, type); 00393 for (ie_type = va_arg(ap, enum ast_event_ie_type); 00394 ie_type != AST_EVENT_IE_END; 00395 ie_type = va_arg(ap, enum ast_event_ie_type)) 00396 { 00397 struct ast_event_ie_val *ie_value = alloca(sizeof(*ie_value)); 00398 memset(ie_value, 0, sizeof(*ie_value)); 00399 ie_value->ie_type = ie_type; 00400 ie_value->ie_pltype = va_arg(ap, enum ast_event_ie_pltype); 00401 if (ie_value->ie_pltype == AST_EVENT_IE_PLTYPE_UINT) 00402 ie_value->payload.uint = va_arg(ap, uint32_t); 00403 else if (ie_value->ie_pltype == AST_EVENT_IE_PLTYPE_STR) 00404 ie_value->payload.str = ast_strdupa(va_arg(ap, const char *)); 00405 else if (ie_value->ie_pltype == AST_EVENT_IE_PLTYPE_RAW) { 00406 void *data = va_arg(ap, void *); 00407 size_t datalen = va_arg(ap, size_t); 00408 ie_value->payload.raw = alloca(datalen); 00409 memcpy(ie_value->payload.raw, data, datalen); 00410 ie_value->raw_datalen = datalen; 00411 } 00412 AST_LIST_INSERT_TAIL(&ie_vals, ie_value, entry); 00413 } 00414 va_end(ap); 00415 00416 for (i = 0; i < ARRAY_LEN(event_types); i++) { 00417 AST_RWDLLIST_RDLOCK(&ast_event_subs[event_types[i]]); 00418 AST_RWDLLIST_TRAVERSE(&ast_event_subs[event_types[i]], sub, entry) { 00419 AST_LIST_TRAVERSE(&ie_vals, ie_val, entry) { 00420 if (match_ie_val_to_sub(sub, ie_val)) { 00421 break; 00422 } 00423 } 00424 00425 if (!ie_val) { 00426 /* Everything matched. */ 00427 break; 00428 } 00429 } 00430 AST_RWDLLIST_UNLOCK(&ast_event_subs[event_types[i]]); 00431 if (sub) { 00432 break; 00433 } 00434 } 00435 00436 return sub ? AST_EVENT_SUB_EXISTS : AST_EVENT_SUB_NONE; 00437 }
| void ast_event_destroy | ( | struct ast_event * | event | ) |
Destroy an event.
| event | the event to destroy |
Definition at line 1042 of file event.c.
References ast_free.
Referenced by ast_event_dup_and_cache(), ast_event_get_cached(), ast_event_queue(), ast_event_ref_destroy(), ast_event_report_subs(), devstate_cached(), get_cached_mwi(), has_voicemail(), process_collection(), unistim_send_mwi_to_peer(), and update_registry().
01043 { 01044 ast_free(event); 01045 }
| void ast_event_dump_cache | ( | const struct ast_event_sub * | event_sub | ) |
Dump the event cache for the subscriber.
Definition at line 517 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().
00518 { 00519 ao2_callback(ast_event_cache[event_sub->type].container, OBJ_NODATA, 00520 dump_cache_cb, (void *) event_sub); 00521 }
| 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 1070 of file event.c.
References ao2_find, ao2_ref, ast_event_append_ie_raw(), ast_event_append_ie_str(), ast_event_append_ie_uint(), ast_event_cache, ast_event_destroy(), ast_event_dup(), AST_EVENT_IE_END, AST_EVENT_IE_PLTYPE_EXISTS, AST_EVENT_IE_PLTYPE_RAW, AST_EVENT_IE_PLTYPE_STR, AST_EVENT_IE_PLTYPE_UINT, AST_EVENT_IE_PLTYPE_UNKNOWN, ast_event_new(), ast_log(), container, ast_event_ref::event, LOG_ERROR, LOG_WARNING, and OBJ_POINTER.
Referenced by devstate_cached(), get_cached_mwi(), has_voicemail(), process_collection(), unistim_send_mwi_to_peer(), and update_registry().
01071 { 01072 va_list ap; 01073 enum ast_event_ie_type ie_type; 01074 struct ast_event *dup_event = NULL; 01075 struct ast_event_ref *cached_event_ref; 01076 struct ast_event *cache_arg_event; 01077 struct ast_event_ref tmp_event_ref = { 01078 .event = NULL, 01079 }; 01080 struct ao2_container *container = NULL; 01081 01082 if (type >= AST_EVENT_TOTAL) { 01083 ast_log(LOG_ERROR, "%u is an invalid type!\n", type); 01084 return NULL; 01085 } 01086 01087 if (!(container = ast_event_cache[type].container)) { 01088 ast_log(LOG_ERROR, "%u is not a cached event type\n", type); 01089 return NULL; 01090 } 01091 01092 if (!(cache_arg_event = ast_event_new(type, AST_EVENT_IE_END))) { 01093 return NULL; 01094 } 01095 01096 va_start(ap, type); 01097 for (ie_type = va_arg(ap, enum ast_event_ie_type); 01098 ie_type != AST_EVENT_IE_END; 01099 ie_type = va_arg(ap, enum ast_event_ie_type)) 01100 { 01101 enum ast_event_ie_pltype ie_pltype; 01102 01103 ie_pltype = va_arg(ap, enum ast_event_ie_pltype); 01104 01105 switch (ie_pltype) { 01106 case AST_EVENT_IE_PLTYPE_UINT: 01107 ast_event_append_ie_uint(&cache_arg_event, ie_type, va_arg(ap, uint32_t)); 01108 break; 01109 case AST_EVENT_IE_PLTYPE_STR: 01110 ast_event_append_ie_str(&cache_arg_event, ie_type, va_arg(ap, const char *)); 01111 break; 01112 case AST_EVENT_IE_PLTYPE_RAW: 01113 { 01114 void *data = va_arg(ap, void *); 01115 size_t datalen = va_arg(ap, size_t); 01116 ast_event_append_ie_raw(&cache_arg_event, ie_type, data, datalen); 01117 } 01118 case AST_EVENT_IE_PLTYPE_EXISTS: 01119 ast_log(LOG_WARNING, "PLTYPE_EXISTS not supported by this function\n"); 01120 break; 01121 case AST_EVENT_IE_PLTYPE_UNKNOWN: 01122 break; 01123 } 01124 } 01125 va_end(ap); 01126 01127 tmp_event_ref.event = cache_arg_event; 01128 01129 cached_event_ref = ao2_find(container, &tmp_event_ref, OBJ_POINTER); 01130 01131 ast_event_destroy(cache_arg_event); 01132 cache_arg_event = NULL; 01133 01134 if (cached_event_ref) { 01135 dup_event = ast_event_dup(cached_event_ref->event); 01136 ao2_ref(cached_event_ref, -1); 01137 cached_event_ref = NULL; 01138 } 01139 01140 return dup_event; 01141 }
| 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 273 of file event.c.
References AST_EVENT_IE_MAX, AST_EVENT_IE_PLTYPE_UNKNOWN, ast_log(), ie_maps, ie_map::ie_pltype, and LOG_ERROR.
Referenced by ast_event_cmp(), and event_dump_cli().
00274 { 00275 if (ie_type <= 0 || ie_type > AST_EVENT_IE_MAX) { 00276 ast_log(LOG_ERROR, "Invalid IE type - '%d'\n", ie_type); 00277 return AST_EVENT_IE_PLTYPE_UNKNOWN; 00278 } 00279 00280 if (ie_maps[ie_type].ie_type != ie_type) { 00281 ast_log(LOG_ERROR, "The ie type passed in does not match the ie type defined in the ie table.\n"); 00282 return AST_EVENT_IE_PLTYPE_UNKNOWN; 00283 } 00284 00285 return ie_maps[ie_type].ie_pltype; 00286 }
| 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 903 of file event.c.
References ast_event_iterator_get_ie_raw(), ast_event_iterator_get_ie_type(), ast_event_iterator_init(), and ast_event_iterator_next().
Referenced by ast_event_cb(), ast_event_get_ie_str(), ast_event_get_ie_str_hash(), ast_event_get_ie_uint(), ast_event_new(), devstate_cache_cb(), devstate_change_collector_cb(), evt_event_deliver_cb(), and match_ie_val().
00904 { 00905 struct ast_event_iterator iterator; 00906 int res = 0; 00907 00908 for (res = ast_event_iterator_init(&iterator, event); !res; res = ast_event_iterator_next(&iterator)) { 00909 if (ast_event_iterator_get_ie_type(&iterator) == ie_type) { 00910 return ast_event_iterator_get_ie_raw(&iterator); 00911 } 00912 } 00913 00914 return NULL; 00915 }
| 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.
| event | The event to get the IE payload length from | |
| ie_type | the type of information element to get the length of |
Definition at line 917 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().
00918 { 00919 struct ast_event_iterator iterator; 00920 int res; 00921 00922 for (res = ast_event_iterator_init(&iterator, event); !res; res = ast_event_iterator_next(&iterator)) { 00923 if (ast_event_iterator_get_ie_type(&iterator) == ie_type) { 00924 return ast_event_iterator_get_ie_raw_payload_len(&iterator); 00925 } 00926 } 00927 00928 return 0; 00929 }
| 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 894 of file event.c.
References ast_event_get_ie_raw(), and ast_event_ie_str_payload::str.
Referenced by ast_event_hash_devstate(), ast_event_hash_devstate_change(), ast_event_hash_mwi(), device_state_cb(), devstate_change_collector_cb(), match_ie_val(), and mwi_sub_event_cb().
00895 { 00896 const struct ast_event_ie_str_payload *str_payload; 00897 00898 str_payload = ast_event_get_ie_raw(event, ie_type); 00899 00900 return str_payload ? str_payload->str : NULL; 00901 }
| 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 885 of file event.c.
References ast_event_get_ie_raw(), and ast_event_ie_str_payload::hash.
Referenced by match_ie_val().
00886 { 00887 const struct ast_event_ie_str_payload *str_payload; 00888 00889 str_payload = ast_event_get_ie_raw(event, ie_type); 00890 00891 return str_payload ? str_payload->hash : 0; 00892 }
| 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 258 of file event.c.
References AST_EVENT_IE_MAX, ast_log(), ie_maps, LOG_ERROR, and ie_map::name.
Referenced by dump_raw_ie(), event_dump_cache(), and event_dump_cli().
00259 { 00260 if (ie_type <= 0 || ie_type > AST_EVENT_IE_MAX) { 00261 ast_log(LOG_ERROR, "Invalid IE type - '%d'\n", ie_type); 00262 return ""; 00263 } 00264 00265 if (ie_maps[ie_type].ie_type != ie_type) { 00266 ast_log(LOG_ERROR, "The ie type passed in does not match the ie type defined in the ie table.\n"); 00267 return ""; 00268 } 00269 00270 return ie_maps[ie_type].name; 00271 }
| 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 876 of file event.c.
References ast_event_get_ie_raw(), and get_unaligned_uint32().
Referenced by device_state_cb(), devstate_cache_cb(), devstate_cached(), devstate_change_collector_cb(), get_cached_mwi(), has_voicemail(), match_ie_val(), mwi_event_cb(), mwi_sub_event_cb(), mwi_unsub_event_cb(), process_collection(), sip_send_mwi_to_peer(), unistim_send_mwi_to_peer(), and update_registry().
00877 { 00878 const uint32_t *ie_val; 00879 00880 ie_val = ast_event_get_ie_raw(event, ie_type); 00881 00882 return ie_val ? ntohl(get_unaligned_uint32(ie_val)) : 0; 00883 }
| 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 303 of file event.c.
References ast_event::event_len.
Referenced by ast_event_cb(), and ast_event_dup().
00304 { 00305 size_t res; 00306 00307 res = ntohs(event->event_len); 00308 00309 return res; 00310 }
| 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 871 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 229 of file event.c.
References ast_event_get_type(), ast_log(), event_names, LOG_ERROR, event_name::name, and ast_event_sub::type.
Referenced by event_dump_cli().
00230 { 00231 enum ast_event_type type; 00232 00233 type = ast_event_get_type(event); 00234 00235 if (type >= AST_EVENT_TOTAL || type < 0) { 00236 ast_log(LOG_ERROR, "Invalid event type - '%d'\n", type); 00237 return ""; 00238 } 00239 00240 return event_names[type].name; 00241 }
| 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 861 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().
00862 { 00863 return iterator->ie->ie_payload; 00864 }
| 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.
| iterator | The IE iterator |
Definition at line 866 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().
00867 { 00868 return ntohs(iterator->ie->ie_payload_len); 00869 }
| 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 852 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().
00853 { 00854 const struct ast_event_ie_str_payload *str_payload; 00855 00856 str_payload = (struct ast_event_ie_str_payload *) iterator->ie->ie_payload; 00857 00858 return str_payload ? str_payload->str : NULL; 00859 }
| 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 842 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().
00843 { 00844 return ntohs(iterator->ie->ie_type); 00845 }
| uint32_t ast_event_iterator_get_ie_uint | ( | struct ast_event_iterator * | iterator | ) |
Get the value of the current IE in the ierator as an integer payload.
| iterator | The iterator instance |
Definition at line 847 of file event.c.
References get_unaligned_uint32(), ast_event_iterator::ie, and ast_event_ie::ie_payload.
Referenced by event_dump_cli().
00848 { 00849 return ntohl(get_unaligned_uint32(iterator->ie->ie_payload)); 00850 }
| int 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 |
| 0 | Success, there are IEs available to iterate | |
| -1 | Failure, there are no IEs in the event to iterate |
Definition at line 820 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(), ast_event_get_ie_raw_payload_len(), and event_dump_cli().
00821 { 00822 int res = 0; 00823 00824 iterator->event_len = ntohs(event->event_len); 00825 iterator->event = event; 00826 if (iterator->event_len >= sizeof(*event) + sizeof(struct ast_event_ie)) { 00827 iterator->ie = (struct ast_event_ie *) ( ((char *) event) + sizeof(*event) ); 00828 } else { 00829 iterator->ie = NULL; 00830 res = -1; 00831 } 00832 00833 return res; 00834 }
| 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 836 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().
00837 { 00838 iterator->ie = (struct ast_event_ie *) ( ((char *) iterator->ie) + sizeof(*iterator->ie) + ntohs(iterator->ie->ie_payload_len)); 00839 return ((iterator->event_len <= (((char *) iterator->ie) - ((char *) iterator->event))) ? -1 : 0); 00840 }
| 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 976 of file event.c.
References ast_calloc, ast_eid_default, ast_event_append_ie_raw(), ast_event_append_ie_str(), ast_event_append_ie_uint(), ast_event_get_ie_raw(), AST_EVENT_IE_EID, AST_EVENT_IE_END, AST_EVENT_IE_PLTYPE_RAW, AST_EVENT_IE_PLTYPE_STR, AST_EVENT_IE_PLTYPE_UINT, AST_LIST_HEAD_NOLOCK_STATIC, AST_LIST_INSERT_TAIL, AST_LIST_TRAVERSE, ast_log(), ast_strdupa, ast_event_ie_val::ie_pltype, ast_event_ie_val::ie_type, LOG_WARNING, ast_event_ie_val::payload, ast_event_ie_val::raw, ast_event_ie_val::raw_datalen, ast_event_ie_val::str, and ast_event_ie_val::uint.
Referenced by ast_event_get_cached(), ast_event_unsubscribe(), devstate_event(), gen_sub_event(), handle_request_notify(), notify_message(), process_collection(), and queue_mwi_event().
00977 { 00978 va_list ap; 00979 struct ast_event *event; 00980 enum ast_event_ie_type ie_type; 00981 struct ast_event_ie_val *ie_val; 00982 AST_LIST_HEAD_NOLOCK_STATIC(ie_vals, ast_event_ie_val); 00983 00984 /* Invalid type */ 00985 if (type >= AST_EVENT_TOTAL) { 00986 ast_log(LOG_WARNING, "Someone tried to create an event of invalid " 00987 "type '%d'!\n", type); 00988 return NULL; 00989 } 00990 00991 va_start(ap, type); 00992 for (ie_type = va_arg(ap, enum ast_event_ie_type); 00993 ie_type != AST_EVENT_IE_END; 00994 ie_type = va_arg(ap, enum ast_event_ie_type)) 00995 { 00996 struct ast_event_ie_val *ie_value = alloca(sizeof(*ie_value)); 00997 memset(ie_value, 0, sizeof(*ie_value)); 00998 ie_value->ie_type = ie_type; 00999 ie_value->ie_pltype = va_arg(ap, enum ast_event_ie_pltype); 01000 if (ie_value->ie_pltype == AST_EVENT_IE_PLTYPE_UINT) 01001 ie_value->payload.uint = va_arg(ap, uint32_t); 01002 else if (ie_value->ie_pltype == AST_EVENT_IE_PLTYPE_STR) 01003 ie_value->payload.str = ast_strdupa(va_arg(ap, const char *)); 01004 else if (ie_value->ie_pltype == AST_EVENT_IE_PLTYPE_RAW) { 01005 void *data = va_arg(ap, void *); 01006 size_t datalen = va_arg(ap, size_t); 01007 ie_value->payload.raw = alloca(datalen); 01008 memcpy(ie_value->payload.raw, data, datalen); 01009 ie_value->raw_datalen = datalen; 01010 } 01011 AST_LIST_INSERT_TAIL(&ie_vals, ie_value, entry); 01012 } 01013 va_end(ap); 01014 01015 if (!(event = ast_calloc(1, sizeof(*event)))) 01016 return NULL; 01017 01018 event->type = htons(type); 01019 event->event_len = htons(sizeof(*event)); 01020 01021 AST_LIST_TRAVERSE(&ie_vals, ie_val, entry) { 01022 if (ie_val->ie_pltype == AST_EVENT_IE_PLTYPE_STR) 01023 ast_event_append_ie_str(&event, ie_val->ie_type, ie_val->payload.str); 01024 else if (ie_val->ie_pltype == AST_EVENT_IE_PLTYPE_UINT) 01025 ast_event_append_ie_uint(&event, ie_val->ie_type, ie_val->payload.uint); 01026 else if (ie_val->ie_pltype == AST_EVENT_IE_PLTYPE_RAW) 01027 ast_event_append_ie_raw(&event, ie_val->ie_type, ie_val->payload.raw, ie_val->raw_datalen); 01028 01029 if (!event) 01030 break; 01031 } 01032 01033 if (!ast_event_get_ie_raw(event, AST_EVENT_IE_EID)) { 01034 /* If the event is originating on this server, add the server's 01035 * entity ID to the event. */ 01036 ast_event_append_ie_raw(&event, AST_EVENT_IE_EID, &ast_eid_default, sizeof(ast_eid_default)); 01037 } 01038 01039 return event; 01040 }
| 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 1228 of file event.c.
References alloc_event_ref(), ast_event_check_subscriber(), ast_event_destroy(), AST_EVENT_IE_END, AST_EVENT_SUB_NONE, ast_log(), ast_taskprocessor_push(), ast_event_ref::event, handle_event(), and LOG_WARNING.
Referenced by ast_event_queue_and_cache(), ast_event_sub_activate(), and ast_event_unsubscribe().
01229 { 01230 struct ast_event_ref *event_ref; 01231 uint16_t host_event_type; 01232 01233 host_event_type = ntohs(event->type); 01234 01235 /* Invalid type */ 01236 if (host_event_type >= AST_EVENT_TOTAL) { 01237 ast_log(LOG_WARNING, "Someone tried to queue an event of invalid " 01238 "type '%d'!\n", host_event_type); 01239 return -1; 01240 } 01241 01242 /* If nobody has subscribed to this event type, throw it away now */ 01243 if (ast_event_check_subscriber(host_event_type, AST_EVENT_IE_END) 01244 == AST_EVENT_SUB_NONE) { 01245 ast_event_destroy(event); 01246 return 0; 01247 } 01248 01249 if (!(event_ref = alloc_event_ref())) { 01250 return -1; 01251 } 01252 01253 event_ref->event = event; 01254 01255 return ast_taskprocessor_push(event_dispatcher, handle_event, event_ref); 01256 }
| 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 1173 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().
01174 { 01175 struct ao2_container *container; 01176 struct ast_event_ref tmp_event_ref = { 01177 .event = event, 01178 }; 01179 int res = -1; 01180 01181 if (!(container = ast_event_cache[ast_event_get_type(event)].container)) { 01182 ast_log(LOG_WARNING, "cache requested for non-cached event type\n"); 01183 goto queue_event; 01184 } 01185 01186 /* Remove matches from the cache */ 01187 ao2_callback(container, OBJ_POINTER | OBJ_UNLINK | OBJ_MULTIPLE | OBJ_NODATA, 01188 ast_event_cmp, &tmp_event_ref); 01189 01190 res = ast_event_dup_and_cache(event); 01191 01192 queue_event: 01193 return ast_event_queue(event) ? -1 : res; 01194 }
| void ast_event_report_subs | ( | const struct ast_event_sub * | event_sub | ) |
Report current subscriptions to a subscription subscriber.
The idea here is that it is sometimes very useful for a module to know when someone subscribes to events. However, when they first subscribe, this provides that module the ability to request the event core report to them all of the subscriptions to that event type that already exist.
Definition at line 561 of file event.c.
References ast_event_destroy(), AST_EVENT_IE_EVENTTYPE, AST_EVENT_SUB, ast_event_subs, AST_LIST_TRAVERSE, AST_RWDLLIST_RDLOCK, AST_RWDLLIST_TRAVERSE, AST_RWDLLIST_UNLOCK, ast_event_sub::cb, gen_sub_event(), ast_event_ie_val::ie_type, ast_event_sub::ie_vals, ast_event_ie_val::payload, ast_event_sub::type, ast_event_ie_val::uint, and ast_event_sub::userdata.
Referenced by start_poll_thread().
00562 { 00563 struct ast_event *event; 00564 struct ast_event_sub *sub; 00565 enum ast_event_type event_type = -1; 00566 struct ast_event_ie_val *ie_val; 00567 00568 if (event_sub->type != AST_EVENT_SUB) 00569 return; 00570 00571 AST_LIST_TRAVERSE(&event_sub->ie_vals, ie_val, entry) { 00572 if (ie_val->ie_type == AST_EVENT_IE_EVENTTYPE) { 00573 event_type = ie_val->payload.uint; 00574 break; 00575 } 00576 } 00577 00578 if (event_type == -1) 00579 return; 00580 00581 AST_RWDLLIST_RDLOCK(&ast_event_subs[event_type]); 00582 AST_RWDLLIST_TRAVERSE(&ast_event_subs[event_type], sub, entry) { 00583 if (event_sub == sub) 00584 continue; 00585 00586 event = gen_sub_event(sub); 00587 00588 if (!event) 00589 continue; 00590 00591 event_sub->cb(event, event_sub->userdata); 00592 00593 ast_event_destroy(event); 00594 } 00595 AST_RWDLLIST_UNLOCK(&ast_event_subs[event_type]); 00596 }
| 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 243 of file event.c.
References ARRAY_LEN, event_names, name, and event_name::type.
Referenced by event_dump_cache().
00244 { 00245 int i; 00246 00247 for (i = 0; i < ARRAY_LEN(event_names); i++) { 00248 if (strcasecmp(event_names[i].name, str)) 00249 continue; 00250 00251 *event_type = event_names[i].type; 00252 return 0; 00253 } 00254 00255 return -1; 00256 }
| 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 288 of file event.c.
References ARRAY_LEN, ie_maps, ie_map::ie_type, and name.
00289 { 00290 int i; 00291 00292 for (i = 0; i < ARRAY_LEN(ie_maps); i++) { 00293 if (strcasecmp(ie_maps[i].name, str)) 00294 continue; 00295 00296 *ie_type = ie_maps[i].ie_type; 00297 return 0; 00298 } 00299 00300 return -1; 00301 }
| 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 711 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().
00712 { 00713 if (ast_event_check_subscriber(AST_EVENT_SUB, 00714 AST_EVENT_IE_EVENTTYPE, AST_EVENT_IE_PLTYPE_UINT, sub->type, 00715 AST_EVENT_IE_END) != AST_EVENT_SUB_NONE) { 00716 struct ast_event *event; 00717 00718 event = gen_sub_event(sub); 00719 00720 if (event) 00721 ast_event_queue(event); 00722 } 00723 00724 AST_RWDLLIST_WRLOCK(&ast_event_subs[sub->type]); 00725 AST_RWDLLIST_INSERT_TAIL(&ast_event_subs[sub->type], sub, entry); 00726 AST_RWDLLIST_UNLOCK(&ast_event_subs[sub->type]); 00727 00728 return 0; 00729 }
| 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 639 of file event.c.
References ast_calloc, AST_EVENT_IE_MAX, AST_EVENT_IE_PLTYPE_EXISTS, AST_LIST_INSERT_TAIL, ast_event_ie_val::ie_pltype, ast_event_ie_val::ie_type, and ast_event_sub::ie_vals.
Referenced by ast_event_subscribe().
00641 { 00642 struct ast_event_ie_val *ie_val; 00643 00644 if (ie_type < 0 || ie_type > AST_EVENT_IE_MAX) 00645 return -1; 00646 00647 if (!(ie_val = ast_calloc(1, sizeof(*ie_val)))) 00648 return -1; 00649 00650 ie_val->ie_type = ie_type; 00651 ie_val->ie_pltype = AST_EVENT_IE_PLTYPE_EXISTS; 00652 00653 AST_LIST_INSERT_TAIL(&sub->ie_vals, ie_val, entry); 00654 00655 return 0; 00656 }
| 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 684 of file event.c.
References ast_calloc, AST_EVENT_IE_MAX, AST_EVENT_IE_PLTYPE_RAW, ast_free, AST_LIST_INSERT_TAIL, ast_malloc, ast_event_ie_val::ie_pltype, ast_event_ie_val::ie_type, ast_event_sub::ie_vals, ast_event_ie_val::payload, ast_event_ie_val::raw, and ast_event_ie_val::raw_datalen.
Referenced by ast_event_subscribe().
00686 { 00687 struct ast_event_ie_val *ie_val; 00688 00689 if (ie_type < 0 || ie_type > AST_EVENT_IE_MAX) 00690 return -1; 00691 00692 if (!(ie_val = ast_calloc(1, sizeof(*ie_val)))) 00693 return -1; 00694 00695 ie_val->ie_type = ie_type; 00696 ie_val->ie_pltype = AST_EVENT_IE_PLTYPE_RAW; 00697 ie_val->raw_datalen = raw_datalen; 00698 00699 if (!(ie_val->payload.raw = ast_malloc(raw_datalen))) { 00700 ast_free(ie_val); 00701 return -1; 00702 } 00703 00704 memcpy(ie_val->payload.raw, data, raw_datalen); 00705 00706 AST_LIST_INSERT_TAIL(&sub->ie_vals, ie_val, entry); 00707 00708 return 0; 00709 }
| 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 658 of file event.c.
References ast_calloc, AST_EVENT_IE_MAX, AST_EVENT_IE_PLTYPE_STR, ast_free, AST_LIST_INSERT_TAIL, ast_str_hash(), ast_strdup, ast_event_ie_val::hash, ast_event_ie_val::ie_pltype, ast_event_ie_val::ie_type, ast_event_sub::ie_vals, ast_event_ie_val::payload, and ast_event_ie_val::str.
Referenced by ast_event_subscribe(), and handle_devstate_change().
00660 { 00661 struct ast_event_ie_val *ie_val; 00662 00663 if (ie_type < 0 || ie_type > AST_EVENT_IE_MAX) 00664 return -1; 00665 00666 if (!(ie_val = ast_calloc(1, sizeof(*ie_val)))) 00667 return -1; 00668 00669 ie_val->ie_type = ie_type; 00670 ie_val->ie_pltype = AST_EVENT_IE_PLTYPE_STR; 00671 00672 if (!(ie_val->payload.str = ast_strdup(str))) { 00673 ast_free(ie_val); 00674 return -1; 00675 } 00676 00677 ie_val->payload.hash = ast_str_hash(str); 00678 00679 AST_LIST_INSERT_TAIL(&sub->ie_vals, ie_val, entry); 00680 00681 return 0; 00682 }
| 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 619 of file event.c.
References ast_calloc, AST_EVENT_IE_MAX, AST_EVENT_IE_PLTYPE_UINT, AST_LIST_INSERT_TAIL, ast_event_ie_val::ie_pltype, ast_event_ie_val::ie_type, ast_event_sub::ie_vals, ast_event_ie_val::payload, and ast_event_ie_val::uint.
Referenced by ast_event_subscribe().
00621 { 00622 struct ast_event_ie_val *ie_val; 00623 00624 if (ie_type < 0 || ie_type > AST_EVENT_IE_MAX) 00625 return -1; 00626 00627 if (!(ie_val = ast_calloc(1, sizeof(*ie_val)))) 00628 return -1; 00629 00630 ie_val->ie_type = ie_type; 00631 ie_val->payload.uint = unsigned_int; 00632 ie_val->ie_pltype = AST_EVENT_IE_PLTYPE_UINT; 00633 00634 AST_LIST_INSERT_TAIL(&sub->ie_vals, ie_val, entry); 00635 00636 return 0; 00637 }
| void ast_event_sub_destroy | ( | struct ast_event_sub * | sub | ) |
Destroy an allocated subscription.
| sub | the subscription to destroy |
Definition at line 784 of file event.c.
References ast_event_ie_val_destroy(), ast_free, AST_LIST_REMOVE_HEAD, and ast_event_sub::ie_vals.
Referenced by ast_event_unsubscribe(), and handle_devstate_change().
00785 { 00786 struct ast_event_ie_val *ie_val; 00787 00788 while ((ie_val = AST_LIST_REMOVE_HEAD(&sub->ie_vals, entry))) 00789 ast_event_ie_val_destroy(ie_val); 00790 00791 ast_free(sub); 00792 }
| struct ast_event_sub* ast_event_subscribe | ( | enum ast_event_type | event_type, | |
| ast_event_cb_t | cb, | |||
| void * | userdata, | |||
| ... | ||||
| ) | [read] |
Subscribe to events.
| event_type | The type of events to subscribe to | |
| cb | The function to be called with events | |
| userdata | data to be passed to the event callback |
<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 731 of file event.c.
References AST_EVENT_IE_END, AST_EVENT_IE_PLTYPE_EXISTS, AST_EVENT_IE_PLTYPE_RAW, AST_EVENT_IE_PLTYPE_STR, AST_EVENT_IE_PLTYPE_UINT, AST_EVENT_IE_PLTYPE_UNKNOWN, ast_event_sub_activate(), ast_event_sub_append_ie_exists(), ast_event_sub_append_ie_raw(), ast_event_sub_append_ie_str(), ast_event_sub_append_ie_uint(), ast_event_subscribe_new(), and str.
Referenced by add_peer_mwi_subs(), add_publish_event(), ast_enable_distributed_devstate(), build_gateway(), build_peer(), config_line(), load_module(), load_pbx(), mkintf(), and start_poll_thread().
00733 { 00734 va_list ap; 00735 enum ast_event_ie_type ie_type; 00736 struct ast_event_sub *sub; 00737 00738 if (!(sub = ast_event_subscribe_new(type, cb, userdata))) 00739 return NULL; 00740 00741 va_start(ap, userdata); 00742 for (ie_type = va_arg(ap, enum ast_event_ie_type); 00743 ie_type != AST_EVENT_IE_END; 00744 ie_type = va_arg(ap, enum ast_event_ie_type)) 00745 { 00746 enum ast_event_ie_pltype ie_pltype; 00747 00748 ie_pltype = va_arg(ap, enum ast_event_ie_pltype); 00749 00750 switch (ie_pltype) { 00751 case AST_EVENT_IE_PLTYPE_UNKNOWN: 00752 break; 00753 case AST_EVENT_IE_PLTYPE_UINT: 00754 { 00755 uint32_t unsigned_int = va_arg(ap, uint32_t); 00756 ast_event_sub_append_ie_uint(sub, ie_type, unsigned_int); 00757 break; 00758 } 00759 case AST_EVENT_IE_PLTYPE_STR: 00760 { 00761 const char *str = va_arg(ap, const char *); 00762 ast_event_sub_append_ie_str(sub, ie_type, str); 00763 break; 00764 } 00765 case AST_EVENT_IE_PLTYPE_RAW: 00766 { 00767 void *data = va_arg(ap, void *); 00768 size_t data_len = va_arg(ap, size_t); 00769 ast_event_sub_append_ie_raw(sub, ie_type, data, data_len); 00770 break; 00771 } 00772 case AST_EVENT_IE_PLTYPE_EXISTS: 00773 ast_event_sub_append_ie_exists(sub, ie_type); 00774 break; 00775 } 00776 } 00777 va_end(ap); 00778 00779 ast_event_sub_activate(sub); 00780 00781 return sub; 00782 }
| 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 598 of file event.c.
References ast_atomic_fetchadd_int(), ast_calloc, ast_log(), ast_event_sub::cb, LOG_ERROR, ast_event_sub::type, ast_event_sub::uniqueid, and ast_event_sub::userdata.
Referenced by ast_event_subscribe(), and handle_devstate_change().
00600 { 00601 struct ast_event_sub *sub; 00602 00603 if (type < 0 || type >= AST_EVENT_TOTAL) { 00604 ast_log(LOG_ERROR, "%u is an invalid type!\n", type); 00605 return NULL; 00606 } 00607 00608 if (!(sub = ast_calloc(1, sizeof(*sub)))) 00609 return NULL; 00610 00611 sub->type = type; 00612 sub->cb = cb; 00613 sub->userdata = userdata; 00614 sub->uniqueid = ast_atomic_fetchadd_int((int *) &sub_uniqueid, 1); 00615 00616 return sub; 00617 }
| 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 794 of file event.c.
References AST_DLLIST_REMOVE, ast_event_check_subscriber(), AST_EVENT_IE_END, AST_EVENT_IE_EVENTTYPE, AST_EVENT_IE_PLTYPE_UINT, AST_EVENT_IE_UNIQUEID, ast_event_new(), ast_event_queue(), ast_event_sub_destroy(), AST_EVENT_SUB_NONE, ast_event_subs, AST_EVENT_UNSUB, AST_RWDLLIST_UNLOCK, AST_RWDLLIST_WRLOCK, ast_event_sub::type, and ast_event_sub::uniqueid.
Referenced by destroy_dahdi_pvt(), destroy_endpoint(), destroy_mailbox(), peer_destructor(), publish_event_destroy(), stop_poll_thread(), and unload_module().
00795 { 00796 struct ast_event *event; 00797 00798 AST_RWDLLIST_WRLOCK(&ast_event_subs[sub->type]); 00799 AST_DLLIST_REMOVE(&ast_event_subs[sub->type], sub, entry); 00800 AST_RWDLLIST_UNLOCK(&ast_event_subs[sub->type]); 00801 00802 if (ast_event_check_subscriber(AST_EVENT_UNSUB, 00803 AST_EVENT_IE_EVENTTYPE, AST_EVENT_IE_PLTYPE_UINT, sub->type, 00804 AST_EVENT_IE_END) != AST_EVENT_SUB_NONE) { 00805 00806 event = ast_event_new(AST_EVENT_UNSUB, 00807 AST_EVENT_IE_UNIQUEID, AST_EVENT_IE_PLTYPE_UINT, sub->uniqueid, 00808 AST_EVENT_IE_EVENTTYPE, AST_EVENT_IE_PLTYPE_UINT, sub->type, 00809 AST_EVENT_IE_END); 00810 00811 if (event) 00812 ast_event_queue(event); 00813 } 00814 00815 ast_event_sub_destroy(sub); 00816 00817 return NULL; 00818 }
1.5.9