| Asterisk - The Open Source Telephony Project GIT-master-27fb039
    | 
Internal generic event system. More...
#include "asterisk.h"#include "asterisk/_private.h"#include "asterisk/event.h"#include "asterisk/linkedlists.h"#include "asterisk/dlinkedlists.h"#include "asterisk/lock.h"#include "asterisk/utils.h"#include "asterisk/unaligned.h"#include "asterisk/taskprocessor.h"#include "asterisk/astobj2.h"#include "asterisk/cli.h"
Go to the source code of this file.
| Data Structures | |
| struct | ast_ev_check_list | 
| Subscription event check list.  More... | |
| struct | ast_event | 
| An event.  More... | |
| struct | ast_event_ie | 
| An event information element.  More... | |
| struct | ast_event_ie_str_payload | 
| The payload for a string information element.  More... | |
| struct | ast_event_ie_val | 
| struct | ie_map | 
| IE payload types and names.  More... | |
| Functions | |
| int | ast_event_append_eid (struct ast_event **event) | 
| Append the global EID IE. | |
| int | ast_event_append_ie_bitflags (struct ast_event **event, enum ast_event_ie_type ie_type, uint32_t flags) | 
| Append an information element that has a bitflags payload. | |
| int | ast_event_append_ie_raw (struct ast_event **event, enum ast_event_ie_type ie_type, const void *data, size_t data_len) | 
| Append an information element that has a raw payload. | |
| int | ast_event_append_ie_str (struct ast_event **event, enum ast_event_ie_type ie_type, const char *str) | 
| Append an information element that has a string payload. | |
| int | ast_event_append_ie_uint (struct ast_event **event, enum ast_event_ie_type ie_type, uint32_t data) | 
| Append an information element that has an integer payload. | |
| void | ast_event_destroy (struct ast_event *event) | 
| Destroy an event. | |
| 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. | |
| 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. | |
| const char * | ast_event_iterator_get_ie_str (struct ast_event_iterator *iterator) | 
| Get the value of the current IE in the iterator as a string payload. | |
| enum ast_event_ie_type | ast_event_iterator_get_ie_type (struct ast_event_iterator *iterator) | 
| Get the type of the current IE in the iterator instance. | |
| uint32_t | ast_event_iterator_get_ie_uint (struct ast_event_iterator *iterator) | 
| Get the value of the current IE in the iterator as an integer payload. | |
| int | ast_event_iterator_init (struct ast_event_iterator *iterator, const struct ast_event *event) | 
| Initialize an event iterator instance. | |
| int | ast_event_iterator_next (struct ast_event_iterator *iterator) | 
| Move iterator instance to next IE. | |
| size_t | ast_event_minimum_length (void) | 
| Get the minimum length of an ast_event. | |
| struct ast_event * | ast_event_new (enum ast_event_type type,...) | 
| Create a new event. | |
| static void * | event_iterator_get_ie_raw (struct ast_event_iterator *iterator) | 
| static uint16_t | event_iterator_get_ie_raw_payload_len (struct ast_event_iterator *iterator) | 
| Variables | |
| static const char *const | event_names [AST_EVENT_TOTAL] | 
| Event Names. | |
| static const struct ie_map | ie_maps [AST_EVENT_IE_TOTAL] | 
Internal generic event system.
Definition in file event.c.
| int ast_event_append_eid | ( | struct ast_event ** | event | ) | 
Append the global EID IE.
| event | the event to append IE to | 
| 0 | success | 
| -1 | failure | 
Definition at line 519 of file event.c.
References ast_eid_default, ast_event_append_ie_raw(), and AST_EVENT_IE_EID.
Referenced by ast_event_new().
| 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 | 
| bitflags | the flags that are the payload of the IE | 
| 0 | success | 
| -1 | failure | 
The pointer to the event will get updated with the new location for the event that now contains the appended information element. If the re-allocation of the memory for this event fails, it will be set to NULL.
Definition at line 368 of file event.c.
References ast_event_append_ie_raw().
Referenced by ast_event_new().
| 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 | 
The pointer to the event will get updated with the new location for the event that now contains the appended information element. If the re-allocation of the memory for this event fails, it will be set to NULL.
Definition at line 375 of file event.c.
References ast_free, ast_realloc, ast_event::event_len, ast_event_ie::ie_payload, ast_event_ie::ie_payload_len, and ast_event_ie::ie_type.
Referenced by ast_event_append_eid(), ast_event_append_ie_bitflags(), ast_event_append_ie_str(), ast_event_append_ie_uint(), and ast_event_new().
| 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 | 
The pointer to the event will get updated with the new location for the event that now contains the appended information element. If the re-allocation of the memory for this event fails, it will be set to NULL.
Definition at line 346 of file event.c.
References ast_alloca, ast_event_append_ie_raw(), ast_str_hash(), ast_event_ie_str_payload::hash, str, and ast_event_ie_str_payload::str.
Referenced by ast_event_new(), and AST_TEST_DEFINE().
| 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 | 
The pointer to the event will get updated with the new location for the event that now contains the appended information element. If the re-allocation of the memory for this event fails, it will be set to NULL.
Definition at line 361 of file event.c.
References ast_event_append_ie_raw().
Referenced by ast_event_new(), and AST_TEST_DEFINE().
| void ast_event_destroy | ( | struct ast_event * | event | ) | 
Destroy an event.
| event | the event to destroy | 
Definition at line 525 of file event.c.
References ast_free.
Referenced by AST_TEST_DEFINE(), cel_report_event(), corosync_ping(), publish_to_corosync(), and send_cluster_notify().
| 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 219 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 dump_event(), and match_ie_val().
| 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 312 of file event.c.
References ast_event_iterator_get_ie_type(), ast_event_iterator_init(), ast_event_iterator_next(), event_iterator_get_ie_raw(), and NULL.
Referenced by ast_event_get_ie_str(), ast_event_get_ie_uint(), ast_event_new(), corosync_node_alloc(), corosync_ping_to_event(), cpg_deliver_cb(), publish_cluster_discovery_to_stasis(), publish_corosync_ping_to_stasis(), publish_device_state_to_stasis(), publish_mwi_to_stasis(), and publish_to_corosync().
| 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 331 of file event.c.
References ast_event_iterator_get_ie_type(), ast_event_iterator_init(), ast_event_iterator_next(), and event_iterator_get_ie_raw_payload_len().
| 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 303 of file event.c.
References ast_event_get_ie_raw(), NULL, and ast_event_ie_str_payload::str.
Referenced by ast_cel_fill_record(), check_event(), corosync_node_alloc(), match_ie_val(), publish_device_state_to_stasis(), publish_mwi_to_stasis(), and test_sub().
| 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 209 of file event.c.
References ARRAY_LEN, ast_log, ie_maps, LOG_ERROR, and ie_map::name.
Referenced by add_ip_json_object(), add_json_object(), alloc_security_event_json_object(), append_event_str_single(), append_json_single(), dump_event(), and events_are_equal().
| 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 294 of file event.c.
References ast_event_get_ie_raw(), and get_unaligned_uint32().
Referenced by ast_cel_fill_record(), check_event(), corosync_node_alloc(), dump_event(), match_ie_val(), publish_cluster_discovery_to_stasis(), publish_device_state_to_stasis(), and publish_mwi_to_stasis().
| 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 229 of file event.c.
Referenced by ao2_dup_event(), ast_event_iterator_init(), AST_TEST_DEFINE(), and publish_event_to_corosync().
| 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 289 of file event.c.
Referenced by ast_event_get_type_name(), check_event(), check_events(), cpg_deliver_cb(), events_are_equal(), publish_cluster_discovery_to_stasis(), publish_corosync_ping_to_stasis(), publish_device_state_to_stasis(), publish_event_to_corosync(), publish_mwi_to_stasis(), and publish_to_corosync().
| 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 195 of file event.c.
References ARRAY_LEN, ast_event_get_type(), ast_log, event_names, LOG_ERROR, and type.
Referenced by cpg_deliver_cb(), and publish_event_to_corosync().
| 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 275 of file event.c.
References ast_event_iterator::ie, ast_event_ie::ie_payload, NULL, and ast_event_ie_str_payload::str.
Referenced by dump_event().
| 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 265 of file event.c.
References ast_event_iterator::ie, and ast_event_ie::ie_type.
Referenced by ast_event_get_ie_raw(), ast_event_get_ie_raw_payload_len(), dump_event(), and events_are_equal().
| 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 270 of file event.c.
References get_unaligned_uint32(), ast_event_iterator::ie, and ast_event_ie::ie_payload.
Referenced by dump_event().
| 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 243 of file event.c.
References ast_event_get_size(), ast_event_iterator::event, ast_event_iterator::event_len, ast_event_iterator::ie, and NULL.
Referenced by ast_event_get_ie_raw(), ast_event_get_ie_raw_payload_len(), dump_event(), and events_are_equal().
| 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 259 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(), dump_event(), and events_are_equal().
| size_t ast_event_minimum_length | ( | void | ) | 
| struct ast_event * ast_event_new | ( | enum ast_event_type | event_type, | 
| ... | |||
| ) | 
Create a new event.
| event_type | The type of event to create | 
The rest of the arguments to this function specify information elements to add to the event. They are specified in the form:
and must end with AST_EVENT_IE_END.
If the ie_type specified is not AST_EVENT_IE_END, then it must be followed by a valid IE payload type. A payload must also be specified after the IE payload type.
Example usage:
This creates a MWI event with 3 information elements, a mailbox which is a string, and the number of new and old messages, specified as integers.
Definition at line 403 of file event.c.
References ast_calloc, ast_event_append_eid(), ast_event_append_ie_bitflags(), ast_event_append_ie_raw(), ast_event_append_ie_str(), ast_event_append_ie_uint(), ast_event_get_ie_raw(), AST_EVENT_IE_EID, AST_EVENT_IE_END, AST_EVENT_IE_PLTYPE_BITFLAGS, AST_EVENT_IE_PLTYPE_EXISTS, AST_EVENT_IE_PLTYPE_RAW, AST_EVENT_IE_PLTYPE_STR, AST_EVENT_IE_PLTYPE_UINT, AST_EVENT_IE_PLTYPE_UNKNOWN, AST_EVENT_TOTAL, ast_free, AST_LIST_HEAD_NOLOCK_STATIC, AST_LIST_INSERT_TAIL, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, ast_log, ast_malloc, cleanup(), ast_event_ie_val::entry, ast_event_ie_val::ie_pltype, ast_event_ie_val::ie_type, LOG_WARNING, NULL, ast_event_ie_val::payload, ast_event_ie_val::raw, ast_event_ie_val::raw_datalen, ast_event_ie_val::str, type, and ast_event_ie_val::uint.
Referenced by ast_cel_create_event_with_time(), AST_TEST_DEFINE(), corosync_ping(), corosync_ping_to_event(), devstate_to_event(), fake_event(), mwi_to_event(), publish_corosync_ping_to_stasis(), and send_cluster_notify().
| 
 | static | 
Definition at line 284 of file event.c.
References ast_event_iterator::ie, and ast_event_ie::ie_payload.
Referenced by ast_event_get_ie_raw().
| 
 | static | 
Definition at line 326 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().
| 
 | static | 
Event Names.
Definition at line 109 of file event.c.
Referenced by ast_event_get_type_name().
| 
 | static | 
Referenced by ast_event_get_ie_pltype(), and ast_event_get_ie_type_name().