124 #include "asterisk/_private.h"
136 {
"Unknown",
"UNKNOWN" },
137 {
"Not in use",
"NOT_INUSE" },
138 {
"In use",
"INUSE" },
140 {
"Invalid",
"INVALID" },
141 {
"Unavailable",
"UNAVAILABLE" },
142 {
"Ringing",
"RINGING" },
143 {
"Ring+Inuse",
"RINGINUSE" },
144 {
"On Hold",
"ONHOLD" },
217 return devstatestring[devstate][0];
223 return devstatestring[devstate][0];
231 if (
chan2dev[i].chan == chanstate) {
241 return devstatestring[
state][1];
246 if (!strcasecmp(val,
"NOT_INUSE"))
248 else if (!strcasecmp(val,
"INUSE"))
250 else if (!strcasecmp(val,
"BUSY"))
252 else if (!strcasecmp(val,
"INVALID"))
254 else if (!strcasecmp(val,
"UNAVAILABLE"))
256 else if (!strcasecmp(val,
"RINGING"))
258 else if (!strcasecmp(val,
"RINGINUSE"))
260 else if (!strcasecmp(val,
"ONHOLD"))
277 snprintf(match,
sizeof(match),
"%s-", device);
319 char *provider = NULL;
331 if (!(number = buf)) {
332 provider =
strsep(&tech,
":");
340 ast_debug(3,
"Checking if I can find provider for \"%s\" - number: %s\n", provider, number);
344 ast_debug(4,
"No provider found, checking channel drivers for %s - %s\n", tech, number);
373 struct devstate_prov *devprov;
375 if (!callback || !(devprov =
ast_calloc(1,
sizeof(*devprov))))
391 struct devstate_prov *devcb;
396 if (!strcasecmp(devcb->
label, label)) {
412 struct devstate_prov *devprov;
417 ast_debug(5,
"Checking provider %s with %s\n", devprov->
label, provider);
419 if (!strcasecmp(devprov->
label, provider)) {
442 ast_debug(3,
"device '%s' state '%u'\n", device, state);
474 struct state_change *change;
494 }
else if (
change_thread == AST_PTHREADT_NULL || !(change =
ast_calloc(1,
sizeof(*change) + strlen(device)))) {
500 strcpy(change->
device, device);
522 vsnprintf(buf,
sizeof(buf), fmt, ap);
534 vsnprintf(buf,
sizeof(buf), fmt, ap);
543 struct state_change *
next, *current;
555 while ((current = next)) {
570 #define MAX_SERVERS 64
583 ast_log(
LOG_ERROR,
"More per-server state values than we have room for (MAX_SERVERS is %d)\n",
610 for (i = 0; i < collection->
num_states; i++) {
611 ast_debug(1,
"Adding per-server state of '%s' for '%s'\n",
618 ast_debug(1,
"Aggregate devstate result is '%s' for '%s'\n",
632 if (state == old_state) {
634 ast_debug(1,
"Aggregate state for device '%s' has not changed from '%s'\n",
640 ast_debug(1,
"Aggregate state for device '%s' has changed to '%s'\n",
690 struct devstate_change *sc;
707 struct devstate_change *sc;
708 const char *
device, *cachable_str;
722 if (!(sc =
ast_calloc(1,
sizeof(*sc) + strlen(device))))
725 strcpy(sc->
device, device);
736 sscanf(cachable_str,
"%30u", &cachable);
760 memset(agg, 0,
sizeof(*agg));
786 }
else if (state_order[state] > state_order[agg->
state]) {
806 ast_log(
LOG_ERROR,
"Failed to create subscription for the device state change collector\n");
int ast_event_sub_append_ie_str(struct ast_event_sub *sub, enum ast_event_ie_type ie_type, const char *str)
Append a string parameter to a subscription.
enum sip_cc_notify_state state
const char * ast_devstate2str(enum ast_device_state devstate) attribute_pure
Find devicestate as text message for output.
Main Channel structure associated with a channel.
ast_device_state
Device States.
enum ast_device_state dev
#define AST_LIST_LOCK(head)
Locks a list.
Asterisk locking-related definitions:
struct state_change * next
Asterisk main include file. File version handling, generic pbx functions.
#define AST_LIST_FIRST(head)
Returns the first entry contained in a list.
char * strsep(char **str, const char *delims)
static int getproviderstate(const char *provider, const char *address)
Get provider device state.
static void devstate_event(const char *device, enum ast_device_state state, int cachable)
#define AST_RWLIST_HEAD_STATIC(name, type)
Defines a structure to be used to hold a read/write list of specified type, statically initialized...
struct ast_channel_tech * ast_get_channel_tech(const char *name)
Get a channel technology structure by name.
#define ast_channel_unref(c)
Decrease channel reference count.
const char * devstate2str(enum ast_device_state devstate) attribute_pure
Convert device state to text string for output.
A device state provider (not a channel)
static struct @248 devstate_collector
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
int ast_event_queue_and_cache(struct ast_event *event)
Queue and cache an event.
#define AST_LIST_UNLOCK(head)
Attempts to unlock a list.
struct ast_event_sub * event_sub
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
static enum ast_device_state devstate_cached(const char *device)
struct devstate_change states[MAX_SERVERS]
enum ast_device_state ast_parse_device_state(const char *device)
Search the Channels by Name.
ast_devstate_prov_cb_type callback
#define AST_LIST_NEXT(elm, field)
Returns the next entry in the list after the given entry.
int ast_enable_distributed_devstate(void)
Enable distributed device state processing.
int ast_devstate_prov_del(const char *label)
Remove device state provider.
struct ast_event * ast_event_get_cached(enum ast_event_type,...)
Retrieve an event from the cache.
ast_channel_state
ast_channel states
static void devstate_cache_cb(const struct ast_event *event, void *data)
#define ast_cond_wait(cond, mutex)
#define ast_cond_init(cond, attr)
int ast_devstate_prov_add(const char *label, ast_devstate_prov_cb_type callback)
Add device state provider.
#define AST_LIST_EMPTY(head)
Checks whether the specified list contains any entries.
#define ast_mutex_lock(a)
static void destroy_devstate_change(struct devstate_change *sc)
static void * run_devstate_collector(void *data)
void ast_event_sub_destroy(struct ast_event_sub *sub)
Destroy an allocated subscription.
enum ast_devstate_cache cachable
struct @248::@251 devstate_change_q
#define ast_cond_signal(cond)
An Entity ID is essentially a MAC address, brief and unique.
Entity ID Used by All events Payload type: RAW This IE indicates which server the event originated fr...
enum ast_device_state ast_devstate_aggregate_result(struct ast_devstate_aggregate *agg)
Get the aggregate device state result.
struct ast_channel * ast_channel_get_by_name_prefix(const char *name, size_t name_len)
Find a channel by a name prefix.
pthread_cond_t ast_cond_t
#define ast_pthread_create_background(a, b, c, d)
#define AST_RWLIST_RDLOCK(head)
Read locks a list.
#define AST_RWLIST_INSERT_HEAD
#define ast_debug(level,...)
Log a DEBUG message.
int ast_event_queue(struct ast_event *event)
Queue an event.
ast_event_type
Event types.
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.
enum ast_device_state ast_devstate_val(const char *val)
Convert device state from text to integer value.
General Asterisk PBX channel definitions.
static void do_state_change(const char *device, int cachable)
int ast_device_state_changed(const char *fmt,...)
Tells Asterisk the State for Device is changed. (Accept change notification, add it to change queue...
#define AST_PTHREADT_NULL
static force_inline int attribute_pure ast_strlen_zero(const char *s)
#define AST_MAX_EXTENSION
#define AST_RWLIST_TRAVERSE
#define AST_RWLIST_REMOVE_CURRENT
A set of macros to manage forward-linked lists.
enum ast_device_state ast_state_chan2dev(enum ast_channel_state chanstate)
Convert channel state to devicestate.
int ast_device_state_changed_literal(const char *device)
Tells Asterisk the State for Device is changed.
#define AST_LIST_REMOVE_HEAD(head, field)
Removes and returns the head entry from a list.
Event non-cachability flag Used by: All events Payload type: UINT.
Structure to describe a channel "technology", ie a channel driver See for examples: ...
Core PBX routines and definitions.
#define AST_RWLIST_TRAVERSE_SAFE_BEGIN
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.
#define AST_LIST_HEAD_STATIC(name, type)
Defines a structure to be used to hold a list of specified type, statically initialized.
void ast_devstate_aggregate_add(struct ast_devstate_aggregate *agg, enum ast_device_state state)
Add a device state to the aggregate device state.
const char * ast_devstate_str(enum ast_device_state devstate) attribute_pure
Convert device state to text string that is easier to parse.
static void devstate_change_collector_cb(const struct ast_event *event, void *data)
enum ast_channel_state chan
void ast_event_dump_cache(const struct ast_event_sub *event_sub)
Dump the event cache for the subscriber.
#define AST_LIST_HEAD_NOLOCK(name, type)
Defines a structure to be used to hold a list of specified type (with no lock).
#define ast_strdupa(s)
duplicate a string in memory from the stack
int ast_device_state_engine_init(void)
Initialize the device state engine in separate thread.
static const char *const devstatestring[][2]
Device state strings for printing.
#define AST_LIST_INSERT_TAIL(head, elm, field)
Appends a list entry to the tail of a list.
static pthread_t change_thread
The device state change notification thread.
enum ast_channel_state _state
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
enum ast_devstate_cache cachable
#define AST_LIST_ENTRY(type)
Declare a forward link structure inside a list entry.
ast_devstate_cache
Device State Cachability.
static void handle_devstate_change(struct devstate_change *sc)
enum ast_device_state(* ast_devstate_prov_cb_type)(const char *data)
Devicestate provider call back.
void ast_devstate_aggregate_init(struct ast_devstate_aggregate *agg)
Initialize aggregate device state.
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.
Mapping for channel states to device states.
static void * do_devstate_changes(void *data)
Go through the dev state change queue and update changes in the dev state thread. ...
#define AST_LIST_HEAD_INIT_NOLOCK(head)
Initializes a list head structure.
int(*const devicestate)(void *data)
void ast_event_destroy(struct ast_event *event)
Destroy an event.
static ast_cond_t change_pending
Flag for the queue.
struct ast_event * ast_event_new(enum ast_event_type event_type,...)
Create a new event.
struct ast_event_sub * ast_event_subscribe(enum ast_event_type event_type, ast_event_cb_t cb, const char *description, void *userdata,...)
Subscribe to events.
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Application convenience functions, designed to give consistent look and feel to Asterisk apps...
You shouldn't care about the contents of this struct.
#define ast_mutex_init(pmutex)
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.
Generic State IE Used by AST_EVENT_DEVICE_STATE_CHANGE Payload type: UINT The actual state values dep...
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.
The state change queue. State changes are queued for processing by a separate thread.
enum ast_device_state state
Device Name Used by AST_EVENT_DEVICE_STATE_CHANGE Payload type: STR.
static int match(struct sockaddr_in *sin, unsigned short callno, unsigned short dcallno, const struct chan_iax2_pvt *cur, int check_dcallno)
struct ast_event_sub * ast_event_subscribe_new(enum ast_event_type type, ast_event_cb_t cb, void *userdata)
Allocate a subscription, but do not activate it.
static void process_collection(const char *device, enum ast_devstate_cache cachable, struct change_collection *collection)
#define AST_RWLIST_TRAVERSE_SAFE_END
Structure for mutex and tracking information.
#define ASTERISK_FILE_VERSION(file, version)
Register/unregister a source code file with the core.
#define ast_mutex_unlock(a)