Asterisk - The Open Source Telephony Project
18.5.0
|
Device state management. More...
Go to the source code of this file.
Data Structures | |
struct | ast_device_state_message |
The structure that contains device state. More... | |
struct | ast_devstate_aggregate |
You shouldn't care about the contents of this struct. More... | |
Macros | |
#define | ast_publish_device_state(device, state, cachable) ast_publish_device_state_full(device, state, cachable, &ast_eid_default) |
Publish a device state update. More... | |
Typedefs | |
typedef enum ast_device_state(* | ast_devstate_prov_cb_type) (const char *data) |
Devicestate provider call back. More... | |
Enumerations | |
enum | ast_device_state { AST_DEVICE_UNKNOWN, AST_DEVICE_NOT_INUSE, AST_DEVICE_INUSE, AST_DEVICE_BUSY, AST_DEVICE_INVALID, AST_DEVICE_UNAVAILABLE, AST_DEVICE_RINGING, AST_DEVICE_RINGINUSE, AST_DEVICE_ONHOLD, AST_DEVICE_TOTAL } |
Device States. More... | |
enum | ast_devstate_cache { AST_DEVSTATE_NOT_CACHABLE, AST_DEVSTATE_CACHABLE } |
Device State Cachability. More... | |
Functions | |
enum ast_device_state | ast_device_state (const char *device) |
Asks a channel for device state. More... | |
struct stasis_cache * | ast_device_state_cache (void) |
Backend cache for ast_device_state_topic_cached() More... | |
int | ast_device_state_clear_cache (const char *device) |
Clear the device from the stasis cache. More... | |
struct stasis_message_type * | ast_device_state_message_type (void) |
Get the Stasis message type for device state messages. More... | |
struct stasis_topic * | ast_device_state_topic (const char *device) |
Get the Stasis topic for device state messages for a specific device. More... | |
struct stasis_topic * | ast_device_state_topic_all (void) |
Get the Stasis topic for device state messages. More... | |
struct stasis_topic * | ast_device_state_topic_cached (void) |
Get the Stasis caching topic for device state messages. More... | |
const char * | ast_devstate2str (enum ast_device_state devstate) attribute_pure |
Convert device state to text string for output. More... | |
void | ast_devstate_aggregate_add (struct ast_devstate_aggregate *agg, enum ast_device_state state) |
Add a device state to the aggregate device state. More... | |
void | ast_devstate_aggregate_init (struct ast_devstate_aggregate *agg) |
Initialize aggregate device state. More... | |
enum ast_device_state | ast_devstate_aggregate_result (struct ast_devstate_aggregate *agg) |
Get the aggregate device state result. More... | |
int | ast_devstate_changed (enum ast_device_state state, enum ast_devstate_cache cachable, const char *fmt,...) |
Tells Asterisk the State for Device is changed. More... | |
int | ast_devstate_changed_literal (enum ast_device_state state, enum ast_devstate_cache cachable, const char *device) |
Tells Asterisk the State for Device is changed. More... | |
int | ast_devstate_prov_add (const char *label, ast_devstate_prov_cb_type callback) |
Add device state provider. More... | |
int | ast_devstate_prov_del (const char *label) |
Remove device state provider. More... | |
const char * | ast_devstate_str (enum ast_device_state devstate) attribute_pure |
Convert device state to text string that is easier to parse. More... | |
enum ast_device_state | ast_devstate_val (const char *val) |
Convert device state from text to integer value. More... | |
enum ast_device_state | ast_parse_device_state (const char *device) |
Search the Channels by Name. More... | |
int | ast_publish_device_state_full (const char *device, enum ast_device_state state, enum ast_devstate_cache cachable, struct ast_eid *eid) |
Publish a device state update with EID. More... | |
enum ast_device_state | ast_state_chan2dev (enum ast_channel_state chanstate) |
Convert channel state to devicestate. More... | |
int | devstate_init (void) |
Initialize the device state core. More... | |
Device state management.
To subscribe to device state changes, use the stasis_subscribe method. For an example, see apps/app_queue.c.
Definition in file devicestate.h.
#define ast_publish_device_state | ( | device, | |
state, | |||
cachable | |||
) | ast_publish_device_state_full(device, state, cachable, &ast_eid_default) |
Publish a device state update.
[in] | device | The device name |
[in] | state | The state of the device |
[in] | cachable | Whether the device state can be cached |
0 | Success |
-1 | Failure |
Definition at line 323 of file devicestate.h.
Referenced by ast_devstate_changed_literal(), AST_TEST_DEFINE(), and do_state_change().
typedef enum ast_device_state(* ast_devstate_prov_cb_type) (const char *data) |
Devicestate provider call back.
Definition at line 74 of file devicestate.h.
enum ast_device_state |
Device States.
Definition at line 52 of file devicestate.h.
enum ast_devstate_cache |
Device State Cachability.
Enumerator | |
---|---|
AST_DEVSTATE_NOT_CACHABLE | This device state is not cachable |
AST_DEVSTATE_CACHABLE | This device state is cachable |
Definition at line 68 of file devicestate.h.
enum ast_device_state ast_device_state | ( | const char * | device | ) |
Asks a channel for device state.
device | like a dial string |
Asks a channel for device state, data is normally a number from a dial string used by the low level module Tries the channel device state callback if not supported search in the active channels list for the device.
an | AST_DEVICE_??? state |
Definition at line 382 of file devicestate.c.
References _ast_device_state().
struct stasis_cache* ast_device_state_cache | ( | void | ) |
Backend cache for ast_device_state_topic_cached()
Cache | of ast_device_state_message. |
Definition at line 673 of file devicestate.c.
References device_state_cache.
Referenced by action_devicestatelist(), ast_device_state_clear_cache(), AST_TEST_DEFINE(), asterisk_publication_devicestate_refresh(), asterisk_start_devicestate_publishing(), cache_cleanup(), devstate_cached(), and xmpp_init_event_distribution().
int ast_device_state_clear_cache | ( | const char * | device | ) |
Clear the device from the stasis cache.
The | device to clear |
0 | if successful |
-1 | nothing to clear |
Definition at line 688 of file devicestate.c.
References ao2_cleanup, ast_device_state_cache(), ast_device_state_message_type(), ast_device_state_topic(), ast_eid_default, stasis_cache_clear_create(), stasis_cache_get_by_eid(), and stasis_publish().
Referenced by stasis_app_device_state_delete().
struct stasis_message_type* ast_device_state_message_type | ( | void | ) |
Get the Stasis message type for device state messages.
The | message type for device state messages |
NULL | if it has not been allocated |
Referenced by action_devicestatelist(), ast_device_state_clear_cache(), ast_publish_device_state_full(), AST_TEST_DEFINE(), asterisk_publisher_devstate_cb(), asterisk_start_devicestate_publishing(), cc_generic_agent_start_monitoring(), create_new_generic_list(), device_state_aggregate_calc(), device_state_cb(), device_state_get_id(), devstate_cached(), devstate_change_cb(), devstate_cleanup(), devstate_init(), generic_agent_devstate_cb(), generic_monitor_devstate_cb(), load_module(), load_pbx(), subscribe_device_state(), xmpp_init_event_distribution(), and xmpp_pubsub_devstate_cb().
struct stasis_topic* ast_device_state_topic | ( | const char * | device | ) |
Get the Stasis topic for device state messages for a specific device.
uniqueid | The device for which to get the topic |
The | topic structure for MWI messages for a given device |
NULL | if it failed to be found or allocated |
Definition at line 683 of file devicestate.c.
References stasis_topic_pool_get_topic().
Referenced by ast_device_state_clear_cache(), ast_publish_device_state_full(), cc_generic_agent_start_monitoring(), create_new_generic_list(), device_state_aggregate_publish(), remove_device_states_cb(), and subscribe_device_state().
struct stasis_topic* ast_device_state_topic_all | ( | void | ) |
Get the Stasis topic for device state messages.
The | topic for device state messages |
NULL | if it has not been allocated |
Definition at line 668 of file devicestate.c.
References device_state_topic_all.
Referenced by ast_publish_device_state_full(), AST_TEST_DEFINE(), asterisk_start_devicestate_publishing(), devstate_init(), load_module(), load_pbx(), publish_hint_change(), publish_hint_remove(), subscribe_device_state(), and xmpp_init_event_distribution().
struct stasis_topic* ast_device_state_topic_cached | ( | void | ) |
Get the Stasis caching topic for device state messages.
The | caching topic for device state messages |
NULL | if it has not been allocated |
Definition at line 678 of file devicestate.c.
References stasis_caching_get_topic().
Referenced by AST_TEST_DEFINE().
const char* ast_devstate2str | ( | enum ast_device_state | devstate | ) |
Convert device state to text string for output.
devstate | Current device state |
Convert device state to text string for output.
Definition at line 237 of file devicestate.c.
References devstatestring.
Referenced by ast_sip_get_device_state(), AST_TEST_DEFINE(), ccss_notify_device_state_change(), device_state_cb(), do_state_change(), extension_state_cb(), page_exec(), parking_notify_metermaids(), and print_queue().
void ast_devstate_aggregate_add | ( | struct ast_devstate_aggregate * | agg, |
enum ast_device_state | state | ||
) |
Add a device state to the aggregate device state.
[in] | agg | the state object |
[in] | state | the state to add |
Definition at line 636 of file devicestate.c.
References AST_DEVICE_BUSY, AST_DEVICE_INUSE, AST_DEVICE_ONHOLD, AST_DEVICE_RINGING, AST_DEVICE_RINGINUSE, ast_devstate_aggregate::inuse, ast_devstate_aggregate::ringing, ast_devstate_aggregate::state, and state.
Referenced by ast_extension_state3(), AST_TEST_DEFINE(), chan_pjsip_devicestate(), device_state_aggregate_calc(), and handle_show_device2extenstate().
void ast_devstate_aggregate_init | ( | struct ast_devstate_aggregate * | agg | ) |
Initialize aggregate device state.
[in] | agg | the state object |
Definition at line 630 of file devicestate.c.
References AST_DEVICE_INVALID, and ast_devstate_aggregate::state.
Referenced by ast_extension_state3(), AST_TEST_DEFINE(), chan_pjsip_devicestate(), device_state_aggregate_calc(), and handle_show_device2extenstate().
enum ast_device_state ast_devstate_aggregate_result | ( | struct ast_devstate_aggregate * | agg | ) |
Get the aggregate device state result.
[in] | agg | the state object |
Definition at line 663 of file devicestate.c.
References ast_devstate_aggregate::state.
Referenced by ast_extension_state3(), AST_TEST_DEFINE(), chan_pjsip_devicestate(), device_state_aggregate_calc(), and handle_show_device2extenstate().
int ast_devstate_changed | ( | enum ast_device_state | state, |
enum ast_devstate_cache | cachable, | ||
const char * | fmt, | ||
... | |||
) |
Tells Asterisk the State for Device is changed.
state | the new state of the device |
cachable | whether this device state is cachable |
fmt | device name like a dial string with format parameters |
The new state of the device will be sent off to any subscribers of device states. It will also be stored in the internal event cache.
0 | on success |
-1 | on failure |
Definition at line 510 of file devicestate.c.
References ast_devstate_changed_literal(), AST_MAX_EXTENSION, and buf.
Referenced by __expire_registry(), __iax2_poke_noanswer(), add_to_queue(), agent_devstate_changed(), ast_sip_persistent_endpoint_update_state(), calendar_devstate_change(), ccss_notify_device_state_change(), chan_pjsip_indicate(), conf_handle_first_join(), conf_run(), destroy_event(), device_state_cb(), devstate_write(), expire_register(), handle_cli_devstate_change(), handle_offhook_message(), handle_onhook_message(), handle_response_invite(), handle_response_peerpoke(), handle_soft_key_event_message(), handle_stimulus_message(), init_queue(), join_queue(), leave_queue(), load_module(), member_add_to_queue(), member_remove_from_queue(), mwi_update_cb(), my_on_hook(), parking_notify_metermaids(), populate_cache(), reg_source_db(), register_verify(), remove_from_queue(), rt_handle_member_record(), set_queue_member_pause(), sip_peer_hold(), sip_poke_noanswer(), skinny_register(), skinny_session_cleanup(), sla_change_trunk_state(), sla_handle_hold_event(), sla_station_exec(), socket_process_helper(), stasis_app_device_state_delete(), stasis_app_device_state_update(), transition_to_empty(), update_call_counter(), update_devstate(), update_registry(), and xmpp_pak_presence().
int ast_devstate_changed_literal | ( | enum ast_device_state | state, |
enum ast_devstate_cache | cachable, | ||
const char * | device | ||
) |
Tells Asterisk the State for Device is changed.
state | the new state of the device |
cachable | whether this device state is cachable |
device | device name like a dial string with format parameters |
The new state of the device will be sent off to any subscribers of device states. It will also be stored in the internal event cache.
0 | on success |
-1 | on failure |
Definition at line 471 of file devicestate.c.
References ast_calloc, ast_cond_signal, AST_DEVICE_UNKNOWN, AST_LIST_INSERT_TAIL, AST_LIST_LOCK, AST_LIST_UNLOCK, AST_PTHREADT_NULL, ast_publish_device_state, state_change::cachable, change_pending, change_thread, state_change::device, do_state_change(), and state_change::list.
Referenced by ast_channel_destructor(), ast_devstate_changed(), ast_setstate(), AST_TEST_DEFINE(), chan_pjsip_indicate(), and dahdi_new().
int ast_devstate_prov_add | ( | const char * | label, |
ast_devstate_prov_cb_type | callback | ||
) |
Add device state provider.
label | to use in hint, like label:object |
callback | Callback |
0 | success |
-1 | failure |
Definition at line 391 of file devicestate.c.
References ast_calloc, ast_copy_string(), ast_free, ast_log, AST_RWLIST_INSERT_HEAD, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, devstate_prov::callback, devstate_prov::label, and LOG_WARNING.
Referenced by AST_TEST_DEFINE(), load_module(), and load_parking_devstate().
int ast_devstate_prov_del | ( | const char * | label | ) |
Remove device state provider.
label | to use in hint, like label:object |
-1 | on failure |
0 | on success |
Definition at line 418 of file devicestate.c.
References ast_free, AST_RWLIST_REMOVE_CURRENT, AST_RWLIST_TRAVERSE_SAFE_BEGIN, AST_RWLIST_TRAVERSE_SAFE_END, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, and devstate_prov::label.
Referenced by AST_TEST_DEFINE(), load_module(), unload_module(), and unload_parking_devstate().
const char* ast_devstate_str | ( | enum ast_device_state | devstate | ) |
Convert device state to text string that is easier to parse.
devstate | Current device state |
Definition at line 255 of file devicestate.c.
References devstatestring, and state.
Referenced by agent_handle_show_specific(), agent_show_requested(), AST_TEST_DEFINE(), asterisk_publisher_devstate_cb(), devstate_read(), devstate_to_ami(), handle_show_device2extenstate(), stasis_app_device_state_to_json(), and xmpp_pubsub_devstate_cb().
enum ast_device_state ast_devstate_val | ( | const char * | val | ) |
Convert device state from text to integer value.
val | The text representing the device state. Valid values are anything that comes after AST_DEVICE_ in one of the defined values. |
Definition at line 260 of file devicestate.c.
References AST_DEVICE_BUSY, AST_DEVICE_INUSE, AST_DEVICE_INVALID, AST_DEVICE_NOT_INUSE, AST_DEVICE_ONHOLD, AST_DEVICE_RINGING, AST_DEVICE_RINGINUSE, AST_DEVICE_UNAVAILABLE, and AST_DEVICE_UNKNOWN.
Referenced by AST_TEST_DEFINE(), asterisk_publication_devicestate(), custom_devstate_callback(), devstate_write(), handle_cli_devstate_change(), initialize_cc_devstate_map_helper(), load_module(), populate_cache(), stasis_app_device_state_update(), stasis_device_state_cb(), and xmpp_pubsub_handle_event().
enum ast_device_state ast_parse_device_state | ( | const char * | device | ) |
Search the Channels by Name.
device | like a dial string |
Search the Device in active channels by compare the channel name against the device name. Compared are only the first chars to the first '-' char.
AST_DEVICE_UNKNOWN | if no channel found |
AST_DEVICE_INUSE | if a channel is found |
Search the Channels by Name.
Definition at line 287 of file devicestate.c.
References ast_channel_get_by_name_prefix(), ast_channel_hold_state(), AST_CHANNEL_NAME, ast_channel_unref, AST_CONTROL_HOLD, AST_DEVICE_ONHOLD, AST_DEVICE_UNKNOWN, ast_state_chan2dev(), chan2dev::chan, and match().
Referenced by _ast_device_state(), AST_TEST_DEFINE(), and chanavail_exec().
int ast_publish_device_state_full | ( | const char * | device, |
enum ast_device_state | state, | ||
enum ast_devstate_cache | cachable, | ||
struct ast_eid * | eid | ||
) |
Publish a device state update with EID.
[in] | device | The device name |
[in] | state | The state of the device |
[in] | cachable | Whether the device state can be cached |
[in] | eid | The EID of the server that originally published the message |
0 | Success |
-1 | Failure |
Definition at line 709 of file devicestate.c.
References ao2_cleanup, ast_assert, ast_device_state_message_type(), ast_device_state_topic(), ast_device_state_topic_all(), ast_strlen_zero, device_state_alloc(), NULL, RAII_VAR, stasis_message_create_full(), stasis_publish(), and stasis_topic_pool_topic_exists().
Referenced by AST_TEST_DEFINE(), asterisk_publication_devicestate(), devstate_change_cb(), publish_device_state_to_stasis(), and xmpp_pubsub_handle_event().
enum ast_device_state ast_state_chan2dev | ( | enum ast_channel_state | chanstate | ) |
Convert channel state to devicestate.
chanstate | Current channel state |
Definition at line 242 of file devicestate.c.
References ARRAY_LEN, AST_DEVICE_UNKNOWN, chan2dev::chan, and chan2dev::dev.
Referenced by ast_parse_device_state(), AST_TEST_DEFINE(), and chan_pjsip_devicestate().
int devstate_init | ( | void | ) |
Initialize the device state core.
0 | Success |
-1 | Failure |
Definition at line 898 of file devicestate.c.
References ast_device_state_message_type(), ast_device_state_topic_all(), ast_log, ast_register_cleanup(), device_state_aggregate_calc(), device_state_aggregate_publish(), device_state_get_id(), devstate_change_cb(), devstate_cleanup(), LOG_ERROR, NULL, stasis_cache_create_full(), stasis_caching_accept_message_type(), stasis_caching_set_filter(), stasis_caching_topic_create(), STASIS_MESSAGE_TYPE_INIT, stasis_subscribe, stasis_subscription_accept_message_type(), STASIS_SUBSCRIPTION_FILTER_SELECTIVE, stasis_subscription_set_filter(), stasis_topic_create(), and stasis_topic_pool_create().
Referenced by asterisk_daemon().