Wed Jan 8 2020 09:50:11

Asterisk developer's documentation


devicestate.h File Reference

Device state management. More...

Go to the source code of this file.

Data Structures

struct  ast_devstate_aggregate
 You shouldn't care about the contents of this struct. 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...
 
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 *device)
 Tells Asterisk the State for Device is changed. More...
 
const char * ast_devstate2str (enum ast_device_state devstate) attribute_pure
 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 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...
 
int ast_enable_distributed_devstate (void)
 Enable distributed device state processing. More...
 
enum ast_device_state ast_parse_device_state (const char *device)
 Search the Channels by Name. More...
 
enum ast_device_state ast_state_chan2dev (enum ast_channel_state chanstate)
 Convert channel state to devicestate. More...
 
const char * devstate2str (enum ast_device_state devstate) attribute_pure
 Convert device state to text string for output. More...
 

Detailed Description

Device state management.

To subscribe to device state changes, use the generic ast_event_subscribe method. For an example, see apps/app_queue.c.

Todo:
Currently, when the state of a device changes, the device state provider calls one of the functions defined here to queue an object to say that the state of a device has changed. However, this does not include the new state. Another thread processes these device state change objects and calls the device state provider's callback to figure out what the new state is. It would make a lot more sense for the new state to be included in the original function call that says the state of a device has changed. However, it will take a lot of work to change this.

Definition in file devicestate.h.

Typedef Documentation

typedef enum ast_device_state(* ast_devstate_prov_cb_type)(const char *data)

Devicestate provider call back.

Definition at line 73 of file devicestate.h.

Enumeration Type Documentation

Device States.

Note
The order of these states may not change because they are included in Asterisk events which may be transmitted across the network to other servers.
Enumerator
AST_DEVICE_UNKNOWN 

Device is valid but channel didn't know state

AST_DEVICE_NOT_INUSE 

Device is not used

AST_DEVICE_INUSE 

Device is in use

AST_DEVICE_BUSY 

Device is busy

AST_DEVICE_INVALID 

Device is invalid

AST_DEVICE_UNAVAILABLE 

Device is unavailable

AST_DEVICE_RINGING 

Device is ringing

AST_DEVICE_RINGINUSE 

Device is ringing and in use

AST_DEVICE_ONHOLD 

Device is on hold

AST_DEVICE_TOTAL 

Definition at line 51 of file devicestate.h.

51  {
52  AST_DEVICE_UNKNOWN, /*!< Device is valid but channel didn't know state */
53  AST_DEVICE_NOT_INUSE, /*!< Device is not used */
54  AST_DEVICE_INUSE, /*!< Device is in use */
55  AST_DEVICE_BUSY, /*!< Device is busy */
56  AST_DEVICE_INVALID, /*!< Device is invalid */
57  AST_DEVICE_UNAVAILABLE, /*!< Device is unavailable */
58  AST_DEVICE_RINGING, /*!< Device is ringing */
59  AST_DEVICE_RINGINUSE, /*!< Device is ringing *and* in use */
60  AST_DEVICE_ONHOLD, /*!< Device is on hold */
61  AST_DEVICE_TOTAL, /*/ Total num of device states, used for testing */
62 };

Device State Cachability.

Note
This is used to define the cachability of a device state when set.
Enumerator
AST_DEVSTATE_NOT_CACHABLE 

This device state is not cachable

AST_DEVSTATE_CACHABLE 

This device state is cachable

Definition at line 67 of file devicestate.h.

67  {
68  AST_DEVSTATE_NOT_CACHABLE, /*!< This device state is not cachable */
69  AST_DEVSTATE_CACHABLE, /*!< This device state is cachable */
70 };

Function Documentation

enum ast_device_state ast_device_state ( const char *  device)

Asks a channel for device state.

Parameters
devicelike 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.

Return values
anAST_DEVICE_??? state

Definition at line 362 of file devicestate.c.

References _ast_device_state().

363 {
364  /* This function is called from elsewhere in the code to find out the
365  * current state of a device. Check the cache, first. */
366 
367  return _ast_device_state(device, 1);
368 }
static enum ast_device_state _ast_device_state(const char *device, int check_cache)
Check device state through channel specific function or generic function.
Definition: devicestate.c:310
int ast_device_state_changed ( const char *  fmt,
  ... 
)

Tells Asterisk the State for Device is changed. (Accept change notification, add it to change queue.)

Parameters
fmtdevice name like a dial string with format parameters

Asterisk polls the new extension states and calls the registered callbacks for the changed extensions

Return values
0on success
-1on failure
Note
This is deprecated in favor of ast_devstate_changed()
Version
1.6.1 deprecated

Definition at line 528 of file devicestate.c.

References AST_DEVICE_UNKNOWN, AST_DEVSTATE_CACHABLE, ast_devstate_changed_literal(), and AST_MAX_EXTENSION.

529 {
530  char buf[AST_MAX_EXTENSION];
531  va_list ap;
532 
533  va_start(ap, fmt);
534  vsnprintf(buf, sizeof(buf), fmt, ap);
535  va_end(ap);
536 
538 }
#define AST_MAX_EXTENSION
Definition: channel.h:135
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.
Definition: devicestate.c:472
int ast_device_state_changed_literal ( const char *  device)

Tells Asterisk the State for Device is changed.

Parameters
devicedevice name like a dial string

Asterisk polls the new extension states and calls the registered callbacks for the changed extensions

Return values
0on success
-1on failure
Note
This is deprecated in favor of ast_devstate_changed_literal()
Version
1.6.1 deprecated

Definition at line 511 of file devicestate.c.

References AST_DEVICE_UNKNOWN, AST_DEVSTATE_CACHABLE, and ast_devstate_changed_literal().

512 {
514 }
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.
Definition: devicestate.c:472
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().

216 {
217  return devstatestring[devstate][0];
218 }
static const char *const devstatestring[][2]
Device state strings for printing.
Definition: devicestate.c:135
void ast_devstate_aggregate_add ( struct ast_devstate_aggregate agg,
enum ast_device_state  state 
)

Add a device state to the aggregate device state.

Parameters
[in]aggthe state object
[in]statethe state to add
Returns
nothing
Since
1.6.1

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().

765 {
766  static enum ast_device_state state_order[] = {
767  1, /* AST_DEVICE_UNKNOWN */
768  3, /* AST_DEVICE_NOT_INUSE */
769  6, /* AST_DEVICE_INUSE */
770  7, /* AST_DEVICE_BUSY */
771  0, /* AST_DEVICE_INVALID */
772  2, /* AST_DEVICE_UNAVAILABLE */
773  5, /* AST_DEVICE_RINGING */
774  8, /* AST_DEVICE_RINGINUSE */
775  4, /* AST_DEVICE_ONHOLD */
776  };
777 
778  if (state == AST_DEVICE_RINGING) {
779  agg->ringing = 1;
781  agg->inuse = 1;
782  }
783 
784  if (agg->ringing && agg->inuse) {
786  } else if (state_order[state] > state_order[agg->state]) {
787  agg->state = state;
788  }
789 }
enum sip_cc_notify_state state
Definition: chan_sip.c:842
ast_device_state
Device States.
Definition: devicestate.h:51
unsigned int ringing
Definition: devicestate.h:266
enum ast_device_state state
Definition: devicestate.h:268
void ast_devstate_aggregate_init ( struct ast_devstate_aggregate agg)

Initialize aggregate device state.

Parameters
[in]aggthe state object
Returns
nothing
Since
1.6.1

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().

759 {
760  memset(agg, 0, sizeof(*agg));
761  agg->state = AST_DEVICE_INVALID;
762 }
enum ast_device_state state
Definition: devicestate.h:268
enum ast_device_state ast_devstate_aggregate_result ( struct ast_devstate_aggregate agg)

Get the aggregate device state result.

Parameters
[in]aggthe state object
Returns
the aggregate device state after adding some number of device states.
Since
1.6.1

Definition at line 791 of file devicestate.c.

References ast_devstate_aggregate::state.

Referenced by ast_extension_state3(), and process_collection().

792 {
793  return agg->state;
794 }
enum ast_device_state state
Definition: devicestate.h:268
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.

Parameters
statethe new state of the device
cachablewhether this device state is cachable
fmtdevice 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.

Return values
0on success
-1on 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().

517 {
518  char buf[AST_MAX_EXTENSION];
519  va_list ap;
520 
521  va_start(ap, fmt);
522  vsnprintf(buf, sizeof(buf), fmt, ap);
523  va_end(ap);
524 
526 }
#define AST_MAX_EXTENSION
Definition: channel.h:135
enum ast_devstate_cache cachable
Definition: devicestate.c:195
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.
Definition: devicestate.c:472
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.

Parameters
statethe new state of the device
cachablewhether this device state is cachable
devicedevice 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.

Return values
0on success
-1on 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().

473 {
474  struct state_change *change;
475 
476  /*
477  * If we know the state change (how nice of the caller of this function!)
478  * then we can just generate a device state event.
479  *
480  * Otherwise, we do the following:
481  * - Queue an event up to another thread that the state has changed
482  * - In the processing thread, it calls the callback provided by the
483  * device state provider (which may or may not be a channel driver)
484  * to determine the state.
485  * - If the device state provider does not know the state, or this is
486  * for a channel and the channel driver does not implement a device
487  * state callback, then we will look through the channel list to
488  * see if we can determine a state based on active calls.
489  * - Once a state has been determined, a device state event is generated.
490  */
491 
492  if (state != AST_DEVICE_UNKNOWN) {
494  } else if (change_thread == AST_PTHREADT_NULL || !(change = ast_calloc(1, sizeof(*change) + strlen(device)))) {
495  /* we could not allocate a change struct, or */
496  /* there is no background thread, so process the change now */
498  } else {
499  /* queue the change */
500  strcpy(change->device, device);
501  change->cachable = cachable;
506  }
507 
508  return 0;
509 }
#define AST_LIST_LOCK(head)
Locks a list.
Definition: linkedlists.h:39
static void devstate_event(const char *device, enum ast_device_state state, int cachable)
Definition: devicestate.c:429
struct state_change::@249 list
#define AST_LIST_UNLOCK(head)
Attempts to unlock a list.
Definition: linkedlists.h:139
enum ast_devstate_cache cachable
Definition: devicestate.c:177
#define ast_cond_signal(cond)
Definition: lock.h:169
static void do_state_change(const char *device, int cachable)
Definition: devicestate.c:461
#define AST_PTHREADT_NULL
Definition: lock.h:65
#define AST_LIST_INSERT_TAIL(head, elm, field)
Appends a list entry to the tail of a list.
Definition: linkedlists.h:716
static pthread_t change_thread
The device state change notification thread.
Definition: devicestate.c:186
char device[1]
Definition: devicestate.c:178
static ast_cond_t change_pending
Flag for the queue.
Definition: devicestate.c:189
#define ast_calloc(a, b)
Definition: astmm.h:82
The state change queue. State changes are queued for processing by a separate thread.
Definition: devicestate.c:183
int ast_devstate_prov_add ( const char *  label,
ast_devstate_prov_cb_type  callback 
)

Add device state provider.

Parameters
labelto use in hint, like label:object
callbackCallback
Return values
0success
-1failure

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().

372 {
373  struct devstate_prov *devprov;
374 
375  if (!callback || !(devprov = ast_calloc(1, sizeof(*devprov))))
376  return -1;
377 
378  devprov->callback = callback;
379  ast_copy_string(devprov->label, label, sizeof(devprov->label));
380 
382  AST_RWLIST_INSERT_HEAD(&devstate_provs, devprov, list);
384 
385  return 0;
386 }
A list of providers.
Definition: devicestate.c:173
A device state provider (not a channel)
Definition: devicestate.c:166
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:51
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
ast_devstate_prov_cb_type callback
Definition: devicestate.c:168
#define AST_RWLIST_INSERT_HEAD
Definition: linkedlists.h:703
char label[40]
Definition: devicestate.c:167
#define ast_calloc(a, b)
Definition: astmm.h:82
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:223
int ast_devstate_prov_del ( const char *  label)

Remove device state provider.

Parameters
labelto use in hint, like label:object
Return values
-1on failure
0on 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().

390 {
391  struct devstate_prov *devcb;
392  int res = -1;
393 
396  if (!strcasecmp(devcb->label, label)) {
398  ast_free(devcb);
399  res = 0;
400  break;
401  }
402  }
405 
406  return res;
407 }
A list of providers.
Definition: devicestate.c:173
A device state provider (not a channel)
Definition: devicestate.c:166
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:51
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
#define AST_RWLIST_REMOVE_CURRENT
Definition: linkedlists.h:565
#define AST_RWLIST_TRAVERSE_SAFE_BEGIN
Definition: linkedlists.h:542
#define ast_free(a)
Definition: astmm.h:97
char label[40]
Definition: devicestate.c:167
#define AST_RWLIST_TRAVERSE_SAFE_END
Definition: linkedlists.h:602
const char* ast_devstate_str ( enum ast_device_state  devstate)

Convert device state to text string that is easier to parse.

Parameters
devstateCurrent device state

Definition at line 239 of file devicestate.c.

References state.

Referenced by aji_devstate_cb(), and devstate_read().

240 {
241  return devstatestring[state][1];
242 }
enum sip_cc_notify_state state
Definition: chan_sip.c:842
static const char *const devstatestring[][2]
Device state strings for printing.
Definition: devicestate.c:135
enum ast_device_state ast_devstate_val ( const char *  val)

Convert device state from text to integer value.

Parameters
valThe text representing the device state. Valid values are anything that comes after AST_DEVICE_ in one of the defined values.
Returns
The AST_DEVICE_ integer value

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().

245 {
246  if (!strcasecmp(val, "NOT_INUSE"))
247  return AST_DEVICE_NOT_INUSE;
248  else if (!strcasecmp(val, "INUSE"))
249  return AST_DEVICE_INUSE;
250  else if (!strcasecmp(val, "BUSY"))
251  return AST_DEVICE_BUSY;
252  else if (!strcasecmp(val, "INVALID"))
253  return AST_DEVICE_INVALID;
254  else if (!strcasecmp(val, "UNAVAILABLE"))
255  return AST_DEVICE_UNAVAILABLE;
256  else if (!strcasecmp(val, "RINGING"))
257  return AST_DEVICE_RINGING;
258  else if (!strcasecmp(val, "RINGINUSE"))
259  return AST_DEVICE_RINGINUSE;
260  else if (!strcasecmp(val, "ONHOLD"))
261  return AST_DEVICE_ONHOLD;
262 
263  return AST_DEVICE_UNKNOWN;
264 }
Definition: ast_expr2.c:325
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.

Return values
0success
-1failure

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().

797 {
798  if (devstate_collector.enabled) {
799  return 0;
800  }
801 
803  devstate_change_collector_cb, "devicestate_engine_enable_distributed", NULL, AST_EVENT_IE_END);
804 
805  if (!devstate_collector.event_sub) {
806  ast_log(LOG_ERROR, "Failed to create subscription for the device state change collector\n");
807  return -1;
808  }
809 
811  ast_cond_init(&devstate_collector.cond, NULL);
813  ast_log(LOG_ERROR, "Unable to start device state collector thread.\n");
814  return -1;
815  }
816 
817  devstate_collector.enabled = 1;
818 
819  return 0;
820 }
static struct @248 devstate_collector
#define ast_cond_init(cond, attr)
Definition: lock.h:167
static void * run_devstate_collector(void *data)
Definition: devicestate.c:687
#define ast_pthread_create_background(a, b, c, d)
Definition: utils.h:426
static void devstate_change_collector_cb(const struct ast_event *event, void *data)
Definition: devicestate.c:705
#define LOG_ERROR
Definition: logger.h:155
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...
Definition: logger.c:1207
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.
Definition: event.c:909
#define ast_mutex_init(pmutex)
Definition: lock.h:152
enum ast_device_state ast_parse_device_state ( const char *  device)

Search the Channels by Name.

Parameters
devicelike 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.

Return values
AST_DEVICE_UNKNOWNif no channel found
AST_DEVICE_INUSEif a channel is found

Search the Channels by Name.

Note
find channels with the device's name in it This function is only used for channels that does not implement devicestate natively

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().

272 {
273  struct ast_channel *chan;
274  char match[AST_CHANNEL_NAME];
275  enum ast_device_state res;
276 
277  snprintf(match, sizeof(match), "%s-", device);
278 
279  if (!(chan = ast_channel_get_by_name_prefix(match, strlen(match)))) {
280  return AST_DEVICE_UNKNOWN;
281  }
282 
284 
285  chan = ast_channel_unref(chan);
286 
287  return res;
288 }
Main Channel structure associated with a channel.
Definition: channel.h:742
ast_device_state
Device States.
Definition: devicestate.h:51
#define ast_channel_unref(c)
Decrease channel reference count.
Definition: channel.h:2502
struct ast_channel * ast_channel_get_by_name_prefix(const char *name, size_t name_len)
Find a channel by a name prefix.
Definition: channel.c:1808
enum ast_channel_state _state
Definition: channel.h:839
#define AST_CHANNEL_NAME
Definition: channel.h:137
static int match(struct sockaddr_in *sin, unsigned short callno, unsigned short dcallno, const struct chan_iax2_pvt *cur, int check_dcallno)
Definition: chan_iax2.c:2069
enum ast_device_state ast_state_chan2dev ( enum ast_channel_state  chanstate)

Convert channel state to devicestate.

Parameters
chanstateCurrent channel state
Since
1.6.1

Definition at line 226 of file devicestate.c.

References AST_DEVICE_UNKNOWN, chan2dev::chan, and chan2dev::dev.

227 {
228  int i;
229  chanstate &= 0xFFFF;
230  for (i = 0; chan2dev[i].chan != -100; i++) {
231  if (chan2dev[i].chan == chanstate) {
232  return chan2dev[i].dev;
233  }
234  }
235  return AST_DEVICE_UNKNOWN;
236 }
enum ast_device_state dev
Definition: devicestate.c:150
enum ast_channel_state chan
Definition: devicestate.c:149
Mapping for channel states to device states.
Definition: devicestate.c:148
const char* devstate2str ( enum ast_device_state  devstate)

Convert device state to text string for output.

Parameters
devstateCurrent device state

Definition at line 221 of file devicestate.c.

222 {
223  return devstatestring[devstate][0];
224 }
static const char *const devstatestring[][2]
Device state strings for printing.
Definition: devicestate.c:135