Device state management. More...
#include "asterisk.h"
#include "asterisk/_private.h"
#include "asterisk/channel.h"
#include "asterisk/utils.h"
#include "asterisk/lock.h"
#include "asterisk/linkedlists.h"
#include "asterisk/devicestate.h"
#include "asterisk/pbx.h"
#include "asterisk/app.h"
#include "asterisk/event.h"
Go to the source code of this file.
Data Structures | |
struct | chan2dev |
Mapping for channel states to device states. More... | |
struct | change_collection |
struct | devstate_change |
struct | devstate_prov |
A device state provider (not a channel) More... | |
struct | devstate_provs |
A list of providers. More... | |
struct | state_change |
struct | state_changes |
The state change queue. State changes are queued for processing by a separate thread. More... | |
Macros | |
#define | MAX_SERVERS 64 |
Functions | |
static enum ast_device_state | _ast_device_state (const char *device, int check_cache) |
Check device state through channel specific function or generic function. More... | |
enum ast_device_state | ast_device_state (const char *device) |
Asks a channel for device state. More... | |
int | ast_device_state_changed (const char *fmt,...) |
Tells Asterisk the State for Device is changed. (Accept change notification, add it to change queue.) More... | |
int | ast_device_state_changed_literal (const char *dev) |
Tells Asterisk the State for Device is changed. More... | |
int | ast_device_state_engine_init (void) |
Initialize the device state engine in separate thread. More... | |
const char * | ast_devstate2str (enum ast_device_state devstate) |
Find devicestate as text message 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 state) |
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... | |
int | ast_enable_distributed_devstate (void) |
Enable distributed device state processing. More... | |
enum ast_device_state | ast_parse_device_state (const char *device) |
Find out if device is active in a call or not. More... | |
enum ast_device_state | ast_state_chan2dev (enum ast_channel_state chanstate) |
Convert channel state to devicestate. More... | |
static void | destroy_devstate_change (struct devstate_change *sc) |
const char * | devstate2str (enum ast_device_state devstate) |
Convert device state to text string for output. More... | |
static void | devstate_cache_cb (const struct ast_event *event, void *data) |
static enum ast_device_state | devstate_cached (const char *device) |
static void | devstate_change_collector_cb (const struct ast_event *event, void *data) |
static void | devstate_event (const char *device, enum ast_device_state state, int cachable) |
static void * | do_devstate_changes (void *data) |
Go through the dev state change queue and update changes in the dev state thread. More... | |
static void | do_state_change (const char *device, int cachable) |
static int | getproviderstate (const char *provider, const char *address) |
Get provider device state. More... | |
static void | handle_devstate_change (struct devstate_change *sc) |
static void | process_collection (const char *device, enum ast_devstate_cache cachable, struct change_collection *collection) |
static void * | run_devstate_collector (void *data) |
Variables | |
static struct chan2dev | chan2dev [] |
static ast_cond_t | change_pending |
Flag for the queue. More... | |
static pthread_t | change_thread = AST_PTHREADT_NULL |
The device state change notification thread. More... | |
struct { | |
ast_cond_t cond | |
struct { | |
struct devstate_change * first | |
struct devstate_change * last | |
} devstate_change_q | |
unsigned int enabled:1 | |
struct ast_event_sub * event_sub | |
ast_mutex_t lock | |
pthread_t thread | |
} | devstate_collector |
static struct devstate_provs | devstate_provs = { .first = NULL, .last = NULL, .lock = { PTHREAD_RWLOCK_INITIALIZER , NULL, 1 } , } |
static const char *const | devstatestring [][2] |
Device state strings for printing. More... | |
static struct state_changes | state_changes = { .first = NULL, .last = NULL, .lock = { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP , NULL, 1 } , } |
#define MAX_SERVERS 64 |
Definition at line 570 of file devicestate.c.
Referenced by devstate_cache_cb().
|
static |
Check device state through channel specific function or generic function.
Channel driver that provides device state
Another provider of device state
Definition at line 310 of file devicestate.c.
References ast_debug, AST_DEVICE_INVALID, AST_DEVICE_UNKNOWN, ast_get_channel_tech(), ast_parse_device_state(), ast_strdupa, ast_channel_tech::devicestate, devstate_cached(), getproviderstate(), and strsep().
Referenced by ast_device_state(), and do_state_change().
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 362 of file devicestate.c.
References _ast_device_state().
int ast_device_state_changed | ( | const char * | fmt, |
... | |||
) |
Tells Asterisk the State for Device is changed. (Accept change notification, add it to change queue.)
fmt | device name like a dial string with format parameters |
Asterisk polls the new extension states and calls the registered callbacks for the changed extensions
0 | on success |
-1 | on failure |
Definition at line 528 of file devicestate.c.
References AST_DEVICE_UNKNOWN, AST_DEVSTATE_CACHABLE, ast_devstate_changed_literal(), and AST_MAX_EXTENSION.
int ast_device_state_changed_literal | ( | const char * | device | ) |
Tells Asterisk the State for Device is changed.
device | device name like a dial string |
Asterisk polls the new extension states and calls the registered callbacks for the changed extensions
0 | on success |
-1 | on failure |
Definition at line 511 of file devicestate.c.
References AST_DEVICE_UNKNOWN, AST_DEVSTATE_CACHABLE, and ast_devstate_changed_literal().
int ast_device_state_engine_init | ( | void | ) |
Initialize the device state engine in separate thread.
Provided by devicestate.c
Definition at line 747 of file devicestate.c.
References ast_cond_init, ast_log(), ast_pthread_create_background, change_thread, do_devstate_changes(), and LOG_ERROR.
Referenced by main().
const char* ast_devstate2str | ( | enum ast_device_state | devstate | ) |
Find devicestate as text message for output.
Definition at line 215 of file devicestate.c.
Referenced by __queues_show(), do_state_change(), extension_state_cb(), handle_statechange(), notify_metermaids(), page_exec(), process_collection(), and queue_function_queuememberstatus().
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 764 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(), and process_collection().
void ast_devstate_aggregate_init | ( | struct ast_devstate_aggregate * | agg | ) |
Initialize aggregate device state.
[in] | agg | the state object |
Definition at line 758 of file devicestate.c.
References AST_DEVICE_INVALID, and ast_devstate_aggregate::state.
Referenced by ast_extension_state3(), and process_collection().
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 791 of file devicestate.c.
References ast_devstate_aggregate::state.
Referenced by ast_extension_state3(), and process_collection().
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 516 of file devicestate.c.
References ast_devstate_changed_literal(), and AST_MAX_EXTENSION.
Referenced by __expire_registry(), __iax2_poke_noanswer(), calendar_devstate_change(), conf_run(), dahdi_pri_update_span_devstate(), destroy_event(), devstate_write(), expire_register(), handle_cli_devstate_change(), handle_offhook_message(), handle_onhook_message(), handle_response_peerpoke(), handle_soft_key_event_message(), handle_stimulus_message(), join_conference_bridge(), leave_conference_bridge(), load_module(), login_exec(), notify_metermaids(), reg_source_db(), register_verify(), sip_peer_hold(), sip_poke_noanswer(), skinny_register(), skinny_unregister(), sla_change_trunk_state(), sla_handle_hold_event(), sla_station_exec(), socket_process(), update_call_counter(), and update_registry().
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 472 of file devicestate.c.
References ast_calloc, ast_cond_signal, AST_DEVICE_UNKNOWN, AST_LIST_INSERT_TAIL, AST_LIST_LOCK, AST_LIST_UNLOCK, state_change::cachable, change_thread, state_change::device, devstate_event(), and do_state_change().
Referenced by ast_channel_destructor(), ast_device_state_changed(), ast_device_state_changed_literal(), ast_devstate_changed(), ast_setstate(), 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 371 of file devicestate.c.
References ast_calloc, ast_copy_string(), AST_RWLIST_INSERT_HEAD, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, devstate_prov::callback, and devstate_prov::label.
Referenced by ast_features_init(), and load_module().
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 389 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 cc_shutdown(), features_shutdown(), and unload_module().
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 239 of file devicestate.c.
References state.
Referenced by aji_devstate_cb(), and devstate_read().
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 244 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 aji_handle_pubsub_event(), custom_devstate_callback(), devstate_write(), handle_cli_devstate_change(), and load_module().
int ast_enable_distributed_devstate | ( | void | ) |
Enable distributed device state processing.
By default, Asterisk assumes that device state change events will only be originating from one instance. If a module gets loaded and configured such that multiple instances of Asterisk will be sharing device state, this function should be called to enable distributed device state processing. It is off by default to save on unnecessary processing.
0 | success |
-1 | failure |
Definition at line 796 of file devicestate.c.
References ast_cond_init, AST_EVENT_DEVICE_STATE_CHANGE, AST_EVENT_IE_END, ast_event_subscribe(), ast_log(), ast_mutex_init, ast_pthread_create_background, devstate_change_collector_cb(), devstate_collector, LOG_ERROR, and run_devstate_collector().
Referenced by add_publish_event(), add_subscribe_event(), and aji_init_event_distribution().
enum ast_device_state ast_parse_device_state | ( | const char * | device | ) |
Find out if device is active in a call or not.
Search the Channels by Name.
Definition at line 271 of file devicestate.c.
References ast_channel::_state, ast_channel_get_by_name_prefix(), AST_CHANNEL_NAME, ast_channel_unref, AST_DEVICE_INUSE, AST_DEVICE_RINGING, AST_DEVICE_UNKNOWN, AST_STATE_RINGING, and match().
Referenced by _ast_device_state(), and chanavail_exec().
enum ast_device_state ast_state_chan2dev | ( | enum ast_channel_state | chanstate | ) |
Convert channel state to devicestate.
chanstate | Current channel state |
Definition at line 226 of file devicestate.c.
References AST_DEVICE_UNKNOWN, chan2dev::chan, and chan2dev::dev.
|
static |
Definition at line 565 of file devicestate.c.
References ast_free.
Referenced by run_devstate_collector().
const char* devstate2str | ( | enum ast_device_state | devstate | ) |
Convert device state to text string for output.
devstate | Current device state |
Definition at line 221 of file devicestate.c.
|
static |
Definition at line 576 of file devicestate.c.
References ARRAY_LEN, ast_event_get_ie_raw(), ast_event_get_ie_uint(), AST_EVENT_IE_EID, AST_EVENT_IE_STATE, ast_log(), devstate_change::eid, ast_eid::eid, LOG_ERROR, MAX_SERVERS, change_collection::num_states, devstate_change::state, and change_collection::states.
Referenced by handle_devstate_change().
|
static |
Definition at line 290 of file devicestate.c.
References AST_DEVICE_UNKNOWN, ast_event_destroy(), AST_EVENT_DEVICE_STATE, ast_event_get_cached(), ast_event_get_ie_uint(), AST_EVENT_IE_DEVICE, AST_EVENT_IE_END, AST_EVENT_IE_PLTYPE_STR, and AST_EVENT_IE_STATE.
Referenced by _ast_device_state().
|
static |
Definition at line 705 of file devicestate.c.
References ast_calloc, ast_cond_signal, AST_DEVSTATE_CACHABLE, ast_event_get_ie_raw(), ast_event_get_ie_str(), ast_event_get_ie_uint(), AST_EVENT_IE_CACHABLE, AST_EVENT_IE_DEVICE, AST_EVENT_IE_EID, AST_EVENT_IE_STATE, AST_LIST_INSERT_TAIL, ast_log(), ast_mutex_lock, ast_mutex_unlock, ast_strlen_zero(), devstate_change::cachable, devstate_change::device, devstate_collector, devstate_change::eid, ast_eid::eid, LOG_ERROR, devstate_change::state, and state.
Referenced by ast_enable_distributed_devstate().
|
static |
Definition at line 429 of file devicestate.c.
References ast_debug, AST_EVENT_DEVICE_STATE, AST_EVENT_DEVICE_STATE_CHANGE, AST_EVENT_IE_CACHABLE, AST_EVENT_IE_DEVICE, AST_EVENT_IE_END, AST_EVENT_IE_PLTYPE_STR, AST_EVENT_IE_PLTYPE_UINT, AST_EVENT_IE_STATE, ast_event_new(), ast_event_queue(), ast_event_queue_and_cache(), and devstate_collector.
Referenced by ast_devstate_changed_literal(), and do_state_change().
|
static |
Go through the dev state change queue and update changes in the dev state thread.
Definition at line 541 of file devicestate.c.
References ast_cond_wait, ast_free, AST_LIST_EMPTY, AST_LIST_FIRST, AST_LIST_HEAD_INIT_NOLOCK, AST_LIST_LOCK, AST_LIST_NEXT, AST_LIST_UNLOCK, state_change::cachable, state_change::device, do_state_change(), and state_change::next.
Referenced by ast_device_state_engine_init().
|
static |
Called by the state change thread to find out what the state is, and then to queue up the state change event
Definition at line 461 of file devicestate.c.
References _ast_device_state(), ast_debug, ast_devstate2str(), devstate_event(), and state.
Referenced by ast_devstate_changed_literal(), and do_devstate_changes().
|
static |
Get provider device state.
Definition at line 410 of file devicestate.c.
References ast_debug, AST_DEVICE_INVALID, AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, devstate_prov::callback, and devstate_prov::label.
Referenced by _ast_device_state().
|
static |
Definition at line 659 of file devicestate.c.
References ast_debug, AST_EVENT_DEVICE_STATE_CHANGE, ast_event_dump_cache(), AST_EVENT_IE_DEVICE, ast_event_sub_append_ie_str(), ast_event_sub_destroy(), ast_event_subscribe_new(), ast_log(), devstate_change::cachable, devstate_change::device, devstate_cache_cb(), LOG_ERROR, change_collection::num_states, and process_collection().
Referenced by run_devstate_collector().
|
static |
Definition at line 601 of file devicestate.c.
References ast_debug, ast_devstate2str(), ast_devstate_aggregate_add(), ast_devstate_aggregate_init(), ast_devstate_aggregate_result(), ast_event_destroy(), AST_EVENT_DEVICE_STATE, ast_event_get_cached(), ast_event_get_ie_uint(), AST_EVENT_IE_DEVICE, AST_EVENT_IE_END, AST_EVENT_IE_PLTYPE_STR, AST_EVENT_IE_PLTYPE_UINT, AST_EVENT_IE_STATE, ast_event_new(), ast_event_queue(), ast_event_queue_and_cache(), change_collection::num_states, devstate_change::state, state, and change_collection::states.
Referenced by handle_devstate_change().
|
static |
Definition at line 687 of file devicestate.c.
References ast_cond_wait, AST_LIST_REMOVE_HEAD, ast_mutex_lock, ast_mutex_unlock, destroy_devstate_change(), devstate_collector, and handle_devstate_change().
Referenced by ast_enable_distributed_devstate().
|
static |
Flag for the queue.
Definition at line 189 of file devicestate.c.
|
static |
The device state change notification thread.
Definition at line 186 of file devicestate.c.
Referenced by ast_device_state_engine_init(), and ast_devstate_changed_literal().
ast_cond_t cond |
Definition at line 202 of file devicestate.c.
struct { ... } devstate_change_q |
struct { ... } devstate_collector |
Referenced by ast_enable_distributed_devstate(), devstate_change_collector_cb(), devstate_event(), and run_devstate_collector().
|
static |
|
static |
Device state strings for printing.
Definition at line 135 of file devicestate.c.
unsigned int enabled |
Definition at line 205 of file devicestate.c.
Referenced by __ast_http_load(), load_odbc_config(), and osp_check_destination().
struct ast_event_sub* event_sub |
Definition at line 201 of file devicestate.c.
Referenced by dump_cache_cb().
struct devstate_change* first |
Definition at line 204 of file devicestate.c.
struct devstate_change* last |
Definition at line 204 of file devicestate.c.
ast_mutex_t lock |
Definition at line 203 of file devicestate.c.
|
static |
pthread_t thread |
Definition at line 200 of file devicestate.c.