158#define DEVSTATE_TOPIC_BUCKETS 57
162 {
"Unknown",
"UNKNOWN" },
163 {
"Not in use",
"NOT_INUSE" },
164 {
"In use",
"INUSE" },
166 {
"Invalid",
"INVALID" },
167 {
"Unavailable",
"UNAVAILABLE" },
168 {
"Ringing",
"RINGING" },
169 {
"Ring+Inuse",
"RINGINUSE" },
170 {
"On Hold",
"ONHOLD" },
247 if (
chan2dev[i].chan == chanstate) {
262 if (!strcasecmp(
val,
"NOT_INUSE"))
264 else if (!strcasecmp(
val,
"INUSE"))
266 else if (!strcasecmp(
val,
"BUSY"))
268 else if (!strcasecmp(
val,
"INVALID"))
270 else if (!strcasecmp(
val,
"UNAVAILABLE"))
272 else if (!strcasecmp(
val,
"RINGING"))
274 else if (!strcasecmp(
val,
"RINGINUSE"))
276 else if (!strcasecmp(
val,
"ONHOLD"))
293 snprintf(
match,
sizeof(
match),
"%s-", device);
361 ast_debug(4,
"No provider found, checking channel drivers for %s - %s\n", tech,
number);
516 vsnprintf(
buf,
sizeof(
buf), fmt, ap);
555 stuff_len = strlen(
device) + 1;
557 stuff_len +=
sizeof(*eid);
561 if (!new_device_state) {
568 new_device_state->
eid = &new_device_state->
stuff[0];
569 pos = (
char *) &new_device_state->
stuff[1];
571 pos = (
char *) &new_device_state->
stuff[0];
575 new_device_state->
device = pos;
580 return new_device_state;
632 memset(agg, 0,
sizeof(*agg));
658 }
else if (state_order[
state] > state_order[agg->
state]) {
774 return device_state->
device;
795 if (!device_specific_topic) {
834 device = device_state->
device;
837 for (idx = 0; ; ++idx) {
844 device = device_state->
device;
871 if (!aggregate_snapshot) {
876 return aggregate_snapshot;
927 ast_log(
LOG_ERROR,
"Failed to create subscription creating uncached device state aggregate events.\n");
943 if (dev_state->
eid) {
965 if (device_state->
eid) {
Prototypes for public functions only of internal interest,.
Asterisk main include file. File version handling, generic pbx functions.
int ast_register_cleanup(void(*func)(void))
Register a function to be executed before Asterisk gracefully exits.
#define ast_strdupa(s)
duplicate a string in memory from the stack
#define ast_calloc(num, len)
A wrapper for calloc()
@ AO2_ALLOC_OPT_LOCK_NOLOCK
#define ao2_alloc_options(data_size, destructor_fn, options)
#define ao2_bump(obj)
Bump refcount on an AO2 object by one, returning the object.
static struct prometheus_metrics_provider provider
static int match(struct ast_sockaddr *addr, unsigned short callno, unsigned short dcallno, const struct chan_iax2_pvt *cur, int check_dcallno)
General Asterisk PBX channel definitions.
struct ast_channel * ast_channel_get_by_name_prefix(const char *name, size_t name_len)
Find a channel by a name prefix.
#define ast_channel_unref(c)
Decrease channel reference count.
int ast_channel_hold_state(const struct ast_channel *chan)
const struct ast_channel_tech * ast_get_channel_tech(const char *name)
Get a channel technology structure by name.
#define AST_MAX_EXTENSION
ast_channel_state
ast_channel states
@ AST_STATE_DIALING_OFFHOOK
static void devstate_change_cb(void *data, struct stasis_subscription *sub, struct stasis_message *msg)
static volatile int shuttingdown
int ast_device_state_engine_init(void)
Initialize the device state engine in separate thread.
int ast_devstate_prov_del(const char *label)
Remove device state provider.
static void device_state_engine_cleanup(void)
void ast_devstate_aggregate_add(struct ast_devstate_aggregate *agg, enum ast_device_state state)
Add a device state to the aggregate device state.
enum ast_device_state ast_device_state(const char *device)
Asks a channel for device state.
static enum ast_device_state devstate_cached(const char *device)
struct stasis_cache * ast_device_state_cache(void)
Backend cache for ast_device_state_topic_cached()
static const char *const devstatestring[][2]
Device state strings for printing.
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.
void ast_devstate_aggregate_init(struct ast_devstate_aggregate *agg)
Initialize aggregate device state.
struct stasis_topic * ast_device_state_topic_cached(void)
Get the Stasis caching topic for device state messages.
const char * ast_devstate_str(enum ast_device_state state)
Convert device state to text string that is easier to parse.
static pthread_t change_thread
The device state change notification thread.
static void devstate_cleanup(void)
STASIS_MESSAGE_TYPE_DEFN(ast_device_state_message_type,.to_ami=devstate_to_ami,.to_event=devstate_to_event,)
static void * do_devstate_changes(void *data)
Go through the dev state change queue and update changes in the dev state thread.
static int getproviderstate(const char *provider, const char *address)
Get provider device state.
struct stasis_topic * ast_device_state_topic_all(void)
Get the Stasis topic for device state messages.
enum ast_device_state ast_devstate_aggregate_result(struct ast_devstate_aggregate *agg)
Get the aggregate device state result.
static struct stasis_message * device_state_aggregate_calc(struct stasis_cache_entry *entry, struct stasis_message *new_snapshot)
static struct ast_manager_event_blob * devstate_to_ami(struct stasis_message *msg)
enum ast_device_state ast_state_chan2dev(enum ast_channel_state chanstate)
Convert channel state to devicestate.
static struct stasis_caching_topic * device_state_topic_cached
enum ast_device_state ast_parse_device_state(const char *device)
Find out if device is active in a call or not.
static ast_cond_t change_pending
Flag for the queue.
int devstate_init(void)
Initialize the device state core.
static struct stasis_topic_pool * device_state_topic_pool
static struct stasis_topic * device_state_topic_all
static void device_state_aggregate_publish(struct stasis_topic *cache_topic, struct stasis_message *aggregate)
struct stasis_subscription * devstate_message_sub
int ast_device_state_clear_cache(const char *device)
Clear the device from the stasis cache.
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.
static enum ast_device_state _ast_device_state(const char *device, int check_cache)
Check device state through channel specific function or generic function.
static void do_state_change(const char *device, enum ast_devstate_cache cachable)
static struct stasis_cache * device_state_cache
static const char * device_state_get_id(struct stasis_message *message)
enum ast_device_state ast_devstate_val(const char *val)
Convert device state from text to integer value.
struct stasis_topic * ast_device_state_topic(const char *device)
Get the Stasis topic for device state messages for a specific device.
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)
int ast_devstate_prov_add(const char *label, ast_devstate_prov_cb_type callback)
Add device state provider.
static struct ast_event * devstate_to_event(struct stasis_message *msg)
Convert a stasis_message to a ast_event.
const char * ast_devstate2str(enum ast_device_state devstate)
Find devicestate as text message for output.
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.
#define ast_publish_device_state(device, state, cachable)
Publish a device state update.
struct stasis_message_type * ast_device_state_message_type(void)
Get the Stasis message type for device state messages.
ast_devstate_cache
Device State Cachability.
@ AST_DEVSTATE_NOT_CACHABLE
enum ast_device_state(* ast_devstate_prov_cb_type)(const char *data)
Devicestate provider call back.
ast_device_state
Device States.
struct ast_event * ast_event_new(enum ast_event_type event_type,...)
Create a new event.
@ AST_EVENT_IE_STATE
Generic State IE Used by AST_EVENT_DEVICE_STATE_CHANGE Payload type: UINT The actual state values dep...
@ AST_EVENT_IE_DEVICE
Device Name Used by AST_EVENT_DEVICE_STATE_CHANGE Payload type: STR.
@ AST_EVENT_IE_EID
Entity ID Used by All events Payload type: RAW This IE indicates which server the event originated fr...
@ AST_EVENT_IE_CACHABLE
Event non-cacheability flag Used by: All events Payload type: UINT.
@ AST_EVENT_DEVICE_STATE_CHANGE
@ AST_EVENT_IE_PLTYPE_RAW
@ AST_EVENT_IE_PLTYPE_UINT
@ AST_EVENT_IE_PLTYPE_STR
Application convenience functions, designed to give consistent look and feel to Asterisk apps.
char * strsep(char **str, const char *delims)
#define ast_debug(level,...)
Log a DEBUG message.
A set of macros to manage forward-linked lists.
#define AST_RWLIST_REMOVE_CURRENT
#define AST_RWLIST_RDLOCK(head)
Read locks a list.
#define AST_LIST_HEAD_INIT_NOLOCK(head)
Initializes a list head structure.
#define AST_LIST_HEAD_STATIC(name, type)
Defines a structure to be used to hold a list of specified type, statically initialized.
#define AST_RWLIST_TRAVERSE_SAFE_BEGIN
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
#define AST_RWLIST_HEAD_STATIC(name, type)
Defines a structure to be used to hold a read/write list of specified type, statically initialized.
#define AST_LIST_EMPTY(head)
Checks whether the specified list contains any entries.
#define AST_LIST_INSERT_TAIL(head, elm, field)
Appends a list entry to the tail of a list.
#define AST_LIST_ENTRY(type)
Declare a forward link structure inside a list entry.
#define AST_RWLIST_TRAVERSE_SAFE_END
#define AST_LIST_LOCK(head)
Locks a list.
#define AST_RWLIST_TRAVERSE
#define AST_RWLIST_INSERT_HEAD
#define AST_LIST_UNLOCK(head)
Attempts to unlock a list.
#define AST_LIST_FIRST(head)
Returns the first entry contained in a list.
#define AST_LIST_NEXT(elm, field)
Returns the next entry in the list after the given entry.
Asterisk locking-related definitions:
#define ast_cond_wait(cond, mutex)
#define AST_PTHREADT_NULL
#define ast_cond_init(cond, attr)
pthread_cond_t ast_cond_t
#define ast_cond_signal(cond)
struct ast_manager_event_blob * ast_manager_event_blob_create(int event_flags, const char *manager_event, const char *extra_fields_fmt,...)
Construct a ast_manager_event_blob.
Core PBX routines and definitions.
struct stasis_forward * sub
static void to_ami(struct ast_sip_subscription *sub, struct ast_str **buf)
Stasis Message Bus API. See Stasis Message Bus API for detailed documentation.
struct stasis_message * stasis_cache_clear_create(struct stasis_message *message)
A message which instructs the caching topic to remove an entry from its cache.
struct stasis_message_type * stasis_message_type(const struct stasis_message *msg)
Get the message type for a stasis_message.
struct stasis_topic * stasis_caching_get_topic(struct stasis_caching_topic *caching_topic)
Returns the topic of cached events from a caching topics.
#define STASIS_MESSAGE_TYPE_CLEANUP(name)
Boiler-plate messaging macro for cleaning up message types.
struct stasis_topic * stasis_topic_pool_get_topic(struct stasis_topic_pool *pool, const char *topic_name)
Find or create a topic in the pool.
@ STASIS_SUBSCRIPTION_FILTER_SELECTIVE
struct stasis_topic * stasis_topic_create(const char *name)
Create a new topic.
struct stasis_caching_topic * stasis_caching_topic_create(struct stasis_topic *original_topic, struct stasis_cache *cache)
Create a topic which monitors and caches messages from another topic.
int stasis_subscription_accept_message_type(struct stasis_subscription *subscription, const struct stasis_message_type *type)
Indicate to a subscription that we are interested in a message type.
int stasis_subscription_set_filter(struct stasis_subscription *subscription, enum stasis_subscription_message_filter filter)
Set the message type filtering level on a subscription.
int stasis_caching_set_filter(struct stasis_caching_topic *caching_topic, enum stasis_subscription_message_filter filter)
Set the message type filtering level on a cache.
struct stasis_message * stasis_cache_entry_get_aggregate(struct stasis_cache_entry *entry)
Get the aggregate cache entry snapshot.
#define STASIS_MESSAGE_TYPE_INIT(name)
Boiler-plate messaging macro for initializing message types.
void * stasis_message_data(const struct stasis_message *msg)
Get the data contained in a message.
struct stasis_cache * stasis_cache_create_full(snapshot_get_id id_fn, cache_aggregate_calc_fn aggregate_calc_fn, cache_aggregate_publish_fn aggregate_publish_fn)
Create a cache.
struct stasis_subscription * stasis_unsubscribe_and_join(struct stasis_subscription *subscription)
Cancel a subscription, blocking until the last message is processed.
struct stasis_caching_topic * stasis_caching_unsubscribe_and_join(struct stasis_caching_topic *caching_topic)
Unsubscribes a caching topic from its upstream topic, blocking until all messages have been forwarded...
int stasis_topic_pool_topic_exists(const struct stasis_topic_pool *pool, const char *topic_name)
Check if a topic exists in a pool.
struct stasis_message * stasis_message_create_full(struct stasis_message_type *type, void *data, const struct ast_eid *eid)
Create a new message for an entity.
struct stasis_topic_pool * stasis_topic_pool_create(struct stasis_topic *pooled_topic)
Create a topic pool that routes messages from dynamically generated topics to the given topic.
void stasis_publish(struct stasis_topic *topic, struct stasis_message *message)
Publish a message to a topic's subscribers.
struct stasis_message * stasis_cache_get_by_eid(struct stasis_cache *cache, struct stasis_message_type *type, const char *id, const struct ast_eid *eid)
Retrieve an item from the cache for a specific entity.
struct stasis_message * stasis_cache_entry_get_local(struct stasis_cache_entry *entry)
Get the local entity's cache entry snapshot.
#define stasis_subscribe(topic, callback, data)
struct stasis_message * stasis_cache_entry_get_remote(struct stasis_cache_entry *entry, int idx)
Get a remote entity's cache entry snapshot by index.
int stasis_caching_accept_message_type(struct stasis_caching_topic *caching_topic, struct stasis_message_type *type)
Indicate to a caching topic that we are interested in a message type.
static force_inline int attribute_pure ast_strlen_zero(const char *s)
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Structure to describe a channel "technology", ie a channel driver See for examples:
int(*const devicestate)(const char *device_number)
Main Channel structure associated with a channel.
The structure that contains device state.
enum ast_device_state state
const struct ast_eid * eid
The EID of the server where this message originated.
enum ast_devstate_cache cachable
You shouldn't care about the contents of this struct.
enum ast_device_state state
An Entity ID is essentially a MAC address, brief and unique.
Struct containing info for an AMI event to send out.
Mapping for channel states to device states.
enum ast_device_state dev
enum ast_channel_state chan
A device state provider (not a channel)
ast_devstate_prov_cb_type callback
struct state_change::@342 list
struct state_change * next
enum ast_devstate_cache cachable
The state change queue. State changes are queued for processing by a separate thread.
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
#define ast_pthread_create_background(a, b, c, d)
struct ast_eid ast_eid_default
Global EID.