Asterisk - The Open Source Telephony Project
21.4.1
|
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/astobj2.h"
#include "asterisk/stasis.h"
Go to the source code of this file.
Data Structures | |
struct | chan2dev |
Mapping for channel states to device states. More... | |
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 | DEVSTATE_TOPIC_BUCKETS 57 |
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... | |
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... | |
int | ast_device_state_engine_init (void) |
Initialize the device state engine in separate thread. 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) |
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... | |
enum ast_device_state | ast_parse_device_state (const char *device) |
Find out if device is active in a call or not. 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... | |
static struct stasis_message * | device_state_aggregate_calc (struct stasis_cache_entry *entry, struct stasis_message *new_snapshot) |
static void | device_state_aggregate_publish (struct stasis_topic *cache_topic, struct stasis_message *aggregate) |
static struct ast_device_state_message * | device_state_alloc (const char *device, enum ast_device_state state, enum ast_devstate_cache cachable, const struct ast_eid *eid) |
static void | device_state_engine_cleanup (void) |
static const char * | device_state_get_id (struct stasis_message *message) |
static enum ast_device_state | devstate_cached (const char *device) |
static void | devstate_change_cb (void *data, struct stasis_subscription *sub, struct stasis_message *msg) |
static void | devstate_cleanup (void) |
int | devstate_init (void) |
Initialize the device state core. More... | |
static struct ast_manager_event_blob * | devstate_to_ami (struct stasis_message *msg) |
static struct ast_event * | devstate_to_event (struct stasis_message *message) |
Convert a stasis_message to a ast_event. | |
static void * | do_devstate_changes (void *data) |
Go through the dev state change queue and update changes in the dev state thread. | |
static void | do_state_change (const char *device, enum ast_devstate_cache cachable) |
static int | getproviderstate (const char *provider, const char *address) |
Get provider device state. | |
STASIS_MESSAGE_TYPE_DEFN (ast_device_state_message_type,.to_ami=devstate_to_ami,.to_event=devstate_to_event,) | |
Variables | |
static const struct chan2dev | chan2dev [] |
static ast_cond_t | change_pending |
Flag for the queue. | |
static pthread_t | change_thread = AST_PTHREADT_NULL |
The device state change notification thread. | |
static struct stasis_cache * | device_state_cache |
static struct stasis_topic * | device_state_topic_all |
static struct stasis_caching_topic * | device_state_topic_cached |
static struct stasis_topic_pool * | device_state_topic_pool |
struct stasis_subscription * | devstate_message_sub |
static struct devstate_provs | devstate_provs = { .first = NULL, .last = NULL, .lock = { PTHREAD_RWLOCK_INITIALIZER , NULL, {1, 0} } , } |
static const char *const | devstatestring [][2] |
Device state strings for printing. | |
static volatile int | shuttingdown |
static struct state_changes | state_changes = { .first = NULL, .last = NULL, .lock = { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP , NULL, {1, 0} } , } |
|
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 328 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, and getproviderstate().
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.
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()
Definition at line 673 of file devicestate.c.
Referenced by ast_device_state_clear_cache(), and xmpp_init_event_distribution().
int ast_device_state_clear_cache | ( | const char * | device | ) |
Clear the device from the stasis cache.
device | The device to clear |
0 | if successful |
-1 | nothing to clear |
Definition at line 688 of file devicestate.c.
References 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().
int ast_device_state_engine_init | ( | void | ) |
Initialize the device state engine in separate thread.
Provided by devicestate.c
Definition at line 618 of file devicestate.c.
References ast_register_cleanup(), change_pending, change_thread, and do_devstate_changes().
struct stasis_topic* ast_device_state_topic | ( | const char * | device | ) |
Get the Stasis topic for device state messages for a specific device.
device | The device for which to get the topic |
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(), and ast_publish_device_state_full().
struct stasis_topic* ast_device_state_topic_all | ( | void | ) |
Get the Stasis topic for device state messages.
NULL | if it has not been allocated |
Definition at line 668 of file devicestate.c.
Referenced by ast_publish_device_state_full(), devstate_init(), load_module(), load_pbx(), publish_hint_change(), publish_hint_remove(), and xmpp_init_event_distribution().
struct stasis_topic* ast_device_state_topic_cached | ( | void | ) |
Get the Stasis 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().
const char* ast_devstate2str | ( | enum ast_device_state | devstate | ) |
Find devicestate as text message for output.
Convert device state to text string for output.
Definition at line 237 of file devicestate.c.
References devstatestring.
Referenced by device_state_cb(), do_state_change(), 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, and ast_device_state_message::state.
Referenced by chan_pjsip_devicestate().
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.
Referenced by chan_pjsip_devicestate().
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.
Referenced by chan_pjsip_devicestate().
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(), and AST_MAX_EXTENSION.
Referenced by add_to_queue(), chan_pjsip_indicate(), conf_handle_first_join(), device_state_cb(), init_queue(), leave_queue(), parking_notify_metermaids(), register_verify(), remove_from_queue(), rt_handle_member_record(), stasis_app_device_state_delete(), stasis_app_device_state_update(), 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_DEVICE_UNKNOWN, AST_LIST_INSERT_TAIL, AST_LIST_LOCK, AST_LIST_UNLOCK, ast_publish_device_state, change_pending, change_thread, and do_state_change().
Referenced by ast_channel_destructor(), ast_devstate_changed(), ast_setstate(), and chan_pjsip_indicate().
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_RWLIST_UNLOCK, and AST_RWLIST_WRLOCK.
Referenced by 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_RWLIST_UNLOCK, and AST_RWLIST_WRLOCK.
Referenced by 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.
Referenced by 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 stasis_app_device_state_update(), and xmpp_pubsub_handle_event().
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 287 of file devicestate.c.
References ast_channel_get_by_name_prefix(), AST_CHANNEL_NAME, ast_channel_unref, AST_CONTROL_HOLD, AST_DEVICE_ONHOLD, AST_DEVICE_UNKNOWN, and ast_state_chan2dev().
Referenced by _ast_device_state().
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 ast_device_state_message_type(), ast_device_state_topic(), ast_device_state_topic_all(), RAII_VAR, stasis_message_create_full(), stasis_publish(), and stasis_topic_pool_topic_exists().
Referenced by 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 AST_DEVICE_UNKNOWN.
Referenced by ast_parse_device_state(), and chan_pjsip_devicestate().
int devstate_init | ( | void | ) |
Initialize the device state core.
0 | Success |
-1 | Failure |
Definition at line 896 of file devicestate.c.
References ast_device_state_message_type(), ast_device_state_topic_all(), ast_register_cleanup(), stasis_cache_create_full(), stasis_caching_accept_message_type(), stasis_caching_set_filter(), stasis_caching_topic_create(), STASIS_MESSAGE_TYPE_INIT, stasis_subscription_accept_message_type(), STASIS_SUBSCRIPTION_FILTER_SELECTIVE, stasis_subscription_set_filter(), stasis_topic_create(), and stasis_topic_pool_create().
|
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 460 of file devicestate.c.
References _ast_device_state(), ast_debug, ast_devstate2str(), and ast_publish_device_state.
Referenced by ast_devstate_changed_literal(), and do_devstate_changes().