#include "asterisk/channel.h"
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... | |
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 } |
Device States. More... | |
Functions | |
enum ast_device_state | ast_device_state (const char *device) |
Asks a channel for 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.). | |
int | ast_device_state_changed_literal (const char *device) |
Tells Asterisk the State for Device is changed. | |
void | ast_devstate_aggregate_add (struct ast_devstate_aggregate *agg, enum ast_device_state state) |
Add a device state to the aggregate device state. | |
void | ast_devstate_aggregate_init (struct ast_devstate_aggregate *agg) |
Initialize aggregate device state. | |
enum ast_device_state | ast_devstate_aggregate_result (struct ast_devstate_aggregate *agg) |
Get the aggregate device state result. | |
int | ast_devstate_changed (enum ast_device_state state, const char *fmt,...) |
Tells Asterisk the State for Device is changed. | |
int | ast_devstate_changed_literal (enum ast_device_state state, const char *device) |
Tells Asterisk the State for Device is changed. | |
int | ast_devstate_prov_add (const char *label, ast_devstate_prov_cb_type callback) |
Add device state provider. | |
int | ast_devstate_prov_del (const char *label) |
Remove device state provider. | |
const char * | ast_devstate_str (enum ast_device_state devstate) |
Convert device state to text string that is easier to parse. | |
enum ast_device_state | ast_devstate_val (const char *val) |
Convert device state from text to integer value. | |
int | ast_enable_distributed_devstate (void) |
Enable distributed device state processing. | |
enum ast_device_state | ast_parse_device_state (const char *device) |
Search the Channels by Name. | |
enum ast_device_state | ast_state_chan2dev (enum ast_channel_state chanstate) |
Convert channel state to devicestate. | |
const char * | devstate2str (enum ast_device_state devstate) |
Convert device state to text string for output. | |
Variables | |
enum ast_device_state(*) | ast_devstate_prov_cb_type (const char *data) |
Devicestate provider call back. |
To subscribe to device state changes, use the generic ast_event_subscribe method. For an example, see apps/app_queue.c.
Definition in file devicestate.h.
enum ast_device_state |
Device States.
Definition at line 51 of file devicestate.h.
00051 { 00052 AST_DEVICE_UNKNOWN, /*!< Device is valid but channel didn't know state */ 00053 AST_DEVICE_NOT_INUSE, /*!< Device is not used */ 00054 AST_DEVICE_INUSE, /*!< Device is in use */ 00055 AST_DEVICE_BUSY, /*!< Device is busy */ 00056 AST_DEVICE_INVALID, /*!< Device is invalid */ 00057 AST_DEVICE_UNAVAILABLE, /*!< Device is unavailable */ 00058 AST_DEVICE_RINGING, /*!< Device is ringing */ 00059 AST_DEVICE_RINGINUSE, /*!< Device is ringing *and* in use */ 00060 AST_DEVICE_ONHOLD, /*!< Device is on hold */ 00061 };
enum ast_device_state ast_device_state | ( | const char * | device | ) |
Asks a channel for device state.
device | like a dial string |
an | AST_DEVICE_??? state | |
-1 | on failure |
Definition at line 387 of file devicestate.c.
References _ast_device_state().
Referenced by _ast_device_state(), ast_extension_state2(), ast_parse_device_state(), chanavail_exec(), create_queue_member(), device_state_cb(), devstate_cached(), devstate_read(), devstate_write(), do_state_change(), handle_cli_devstate_change(), page_exec(), process_collection(), ring_entry(), skinny_extensionstate_cb(), sla_state(), and transmit_state_notify().
00388 { 00389 /* This function is called from elsewhere in the code to find out the 00390 * current state of a device. Check the cache, first. */ 00391 00392 return _ast_device_state(device, 1); 00393 }
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 |
0 | on success | |
-1 | on failure |
Definition at line 547 of file devicestate.c.
References AST_DEVICE_UNKNOWN, ast_devstate_changed_literal(), AST_MAX_EXTENSION, and buf.
00548 { 00549 char buf[AST_MAX_EXTENSION]; 00550 va_list ap; 00551 00552 va_start(ap, fmt); 00553 vsnprintf(buf, sizeof(buf), fmt, ap); 00554 va_end(ap); 00555 00556 return ast_devstate_changed_literal(AST_DEVICE_UNKNOWN, buf); 00557 }
int ast_device_state_changed_literal | ( | const char * | device | ) |
Tells Asterisk the State for Device is changed.
device | device name like a dial string |
0 | on success | |
-1 | on failure |
Definition at line 530 of file devicestate.c.
References AST_DEVICE_UNKNOWN, and ast_devstate_changed_literal().
00531 { 00532 return ast_devstate_changed_literal(AST_DEVICE_UNKNOWN, dev); 00533 }
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 770 of file devicestate.c.
References ast_devstate_aggregate::all_busy, ast_devstate_aggregate::all_free, ast_devstate_aggregate::all_on_hold, ast_devstate_aggregate::all_unavail, 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, AST_DEVICE_UNKNOWN, ast_devstate_aggregate::busy, ast_devstate_aggregate::in_use, and ast_devstate_aggregate::ring.
Referenced by ast_extension_state2(), and process_collection().
00771 { 00772 switch (state) { 00773 case AST_DEVICE_NOT_INUSE: 00774 agg->all_unavail = 0; 00775 agg->all_busy = 0; 00776 agg->all_on_hold = 0; 00777 break; 00778 case AST_DEVICE_INUSE: 00779 agg->in_use = 1; 00780 agg->all_busy = 0; 00781 agg->all_unavail = 0; 00782 agg->all_free = 0; 00783 agg->all_on_hold = 0; 00784 break; 00785 case AST_DEVICE_RINGING: 00786 agg->ring = 1; 00787 agg->all_busy = 0; 00788 agg->all_unavail = 0; 00789 agg->all_free = 0; 00790 agg->all_on_hold = 0; 00791 break; 00792 case AST_DEVICE_RINGINUSE: 00793 agg->in_use = 1; 00794 agg->ring = 1; 00795 agg->all_busy = 0; 00796 agg->all_unavail = 0; 00797 agg->all_free = 0; 00798 agg->all_on_hold = 0; 00799 break; 00800 case AST_DEVICE_ONHOLD: 00801 agg->all_unavail = 0; 00802 agg->all_free = 0; 00803 break; 00804 case AST_DEVICE_BUSY: 00805 agg->all_unavail = 0; 00806 agg->all_free = 0; 00807 agg->all_on_hold = 0; 00808 agg->busy = 1; 00809 break; 00810 case AST_DEVICE_UNAVAILABLE: 00811 case AST_DEVICE_INVALID: 00812 agg->all_busy = 0; 00813 agg->all_free = 0; 00814 agg->all_on_hold = 0; 00815 break; 00816 case AST_DEVICE_UNKNOWN: 00817 break; 00818 } 00819 }
void ast_devstate_aggregate_init | ( | struct ast_devstate_aggregate * | agg | ) |
Initialize aggregate device state.
[in] | agg | the state object |
Definition at line 760 of file devicestate.c.
Referenced by ast_extension_state2(), and process_collection().
00761 { 00762 memset(agg, 0, sizeof(*agg)); 00763 00764 agg->all_unavail = 1; 00765 agg->all_busy = 1; 00766 agg->all_free = 1; 00767 agg->all_on_hold = 1; 00768 }
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 821 of file devicestate.c.
References ast_devstate_aggregate::all_busy, ast_devstate_aggregate::all_free, ast_devstate_aggregate::all_on_hold, ast_devstate_aggregate::all_unavail, AST_DEVICE_BUSY, AST_DEVICE_INUSE, AST_DEVICE_NOT_INUSE, AST_DEVICE_ONHOLD, AST_DEVICE_RINGING, AST_DEVICE_RINGINUSE, AST_DEVICE_UNAVAILABLE, ast_devstate_aggregate::busy, ast_devstate_aggregate::in_use, and ast_devstate_aggregate::ring.
Referenced by ast_extension_state2(), and process_collection().
00822 { 00823 if (agg->all_free) 00824 return AST_DEVICE_NOT_INUSE; 00825 00826 if (agg->all_on_hold) 00827 return AST_DEVICE_ONHOLD; 00828 00829 if (agg->all_busy) 00830 return AST_DEVICE_BUSY; 00831 00832 if (agg->all_unavail) 00833 return AST_DEVICE_UNAVAILABLE; 00834 00835 if (agg->ring) 00836 return agg->in_use ? AST_DEVICE_RINGINUSE : AST_DEVICE_RINGING; 00837 00838 if (agg->in_use) 00839 return AST_DEVICE_INUSE; 00840 00841 if (agg->busy) 00842 return AST_DEVICE_BUSY; 00843 00844 return AST_DEVICE_NOT_INUSE; 00845 }
int ast_devstate_changed | ( | enum ast_device_state | state, | |
const char * | fmt, | |||
... | ||||
) |
Tells Asterisk the State for Device is changed.
state | the new state of the device | |
fmt | device name like a dial string with format parameters |
0 | on success | |
-1 | on failure |
Definition at line 535 of file devicestate.c.
References ast_devstate_changed_literal(), AST_MAX_EXTENSION, and buf.
Referenced by __expire_registry(), __iax2_poke_noanswer(), agent_call(), agent_hangup(), agent_logoff_maintenance(), agent_read(), conf_run(), 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(), load_module(), login_exec(), notify_metermaids(), reg_source_db(), register_verify(), reload_agents(), 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().
00536 { 00537 char buf[AST_MAX_EXTENSION]; 00538 va_list ap; 00539 00540 va_start(ap, fmt); 00541 vsnprintf(buf, sizeof(buf), fmt, ap); 00542 va_end(ap); 00543 00544 return ast_devstate_changed_literal(state, buf); 00545 }
int ast_devstate_changed_literal | ( | enum ast_device_state | state, | |
const char * | device | |||
) |
Tells Asterisk the State for Device is changed.
state | the new state of the device | |
device | device name like a dial string with format parameters |
0 | on success | |
-1 | on failure |
Definition at line 492 of file devicestate.c.
References ast_calloc, ast_cond_signal(), AST_DEVICE_UNKNOWN, AST_LIST_INSERT_TAIL, AST_LIST_LOCK, AST_LIST_UNLOCK, change_thread, devstate_event(), do_state_change(), and devstate_prov::list.
Referenced by ast_channel_free(), ast_device_state_changed(), ast_device_state_changed_literal(), ast_devstate_changed(), ast_setstate(), and dahdi_new().
00493 { 00494 struct state_change *change; 00495 00496 /* 00497 * If we know the state change (how nice of the caller of this function!) 00498 * then we can just generate a device state event. 00499 * 00500 * Otherwise, we do the following: 00501 * - Queue an event up to another thread that the state has changed 00502 * - In the processing thread, it calls the callback provided by the 00503 * device state provider (which may or may not be a channel driver) 00504 * to determine the state. 00505 * - If the device state provider does not know the state, or this is 00506 * for a channel and the channel driver does not implement a device 00507 * state callback, then we will look through the channel list to 00508 * see if we can determine a state based on active calls. 00509 * - Once a state has been determined, a device state event is generated. 00510 */ 00511 00512 if (state != AST_DEVICE_UNKNOWN) { 00513 devstate_event(device, state); 00514 } else if (change_thread == AST_PTHREADT_NULL || !(change = ast_calloc(1, sizeof(*change) + strlen(device)))) { 00515 /* we could not allocate a change struct, or */ 00516 /* there is no background thread, so process the change now */ 00517 do_state_change(device); 00518 } else { 00519 /* queue the change */ 00520 strcpy(change->device, device); 00521 AST_LIST_LOCK(&state_changes); 00522 AST_LIST_INSERT_TAIL(&state_changes, change, list); 00523 ast_cond_signal(&change_pending); 00524 AST_LIST_UNLOCK(&state_changes); 00525 } 00526 00527 return 1; 00528 }
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 396 of file devicestate.c.
References ast_calloc, ast_copy_string(), AST_RWLIST_INSERT_HEAD, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, and devstate_prov::list.
Referenced by ast_features_init(), and load_module().
00397 { 00398 struct devstate_prov *devprov; 00399 00400 if (!callback || !(devprov = ast_calloc(1, sizeof(*devprov)))) 00401 return -1; 00402 00403 devprov->callback = callback; 00404 ast_copy_string(devprov->label, label, sizeof(devprov->label)); 00405 00406 AST_RWLIST_WRLOCK(&devstate_provs); 00407 AST_RWLIST_INSERT_HEAD(&devstate_provs, devprov, list); 00408 AST_RWLIST_UNLOCK(&devstate_provs); 00409 00410 return 0; 00411 }
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 414 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, devstate_prov::label, and devstate_prov::list.
Referenced by unload_module().
00415 { 00416 struct devstate_prov *devcb; 00417 int res = -1; 00418 00419 AST_RWLIST_WRLOCK(&devstate_provs); 00420 AST_RWLIST_TRAVERSE_SAFE_BEGIN(&devstate_provs, devcb, list) { 00421 if (!strcasecmp(devcb->label, label)) { 00422 AST_RWLIST_REMOVE_CURRENT(list); 00423 ast_free(devcb); 00424 res = 0; 00425 break; 00426 } 00427 } 00428 AST_RWLIST_TRAVERSE_SAFE_END; 00429 AST_RWLIST_UNLOCK(&devstate_provs); 00430 00431 return res; 00432 }
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 226 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 devstate_read().
00227 { 00228 const char *res = "UNKNOWN"; 00229 00230 switch (state) { 00231 case AST_DEVICE_UNKNOWN: 00232 break; 00233 case AST_DEVICE_NOT_INUSE: 00234 res = "NOT_INUSE"; 00235 break; 00236 case AST_DEVICE_INUSE: 00237 res = "INUSE"; 00238 break; 00239 case AST_DEVICE_BUSY: 00240 res = "BUSY"; 00241 break; 00242 case AST_DEVICE_INVALID: 00243 res = "INVALID"; 00244 break; 00245 case AST_DEVICE_UNAVAILABLE: 00246 res = "UNAVAILABLE"; 00247 break; 00248 case AST_DEVICE_RINGING: 00249 res = "RINGING"; 00250 break; 00251 case AST_DEVICE_RINGINUSE: 00252 res = "RINGINUSE"; 00253 break; 00254 case AST_DEVICE_ONHOLD: 00255 res = "ONHOLD"; 00256 break; 00257 } 00258 00259 return res; 00260 }
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 262 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 custom_devstate_callback(), devstate_write(), handle_cli_devstate_change(), and load_module().
00263 { 00264 if (!strcasecmp(val, "NOT_INUSE")) 00265 return AST_DEVICE_NOT_INUSE; 00266 else if (!strcasecmp(val, "INUSE")) 00267 return AST_DEVICE_INUSE; 00268 else if (!strcasecmp(val, "BUSY")) 00269 return AST_DEVICE_BUSY; 00270 else if (!strcasecmp(val, "INVALID")) 00271 return AST_DEVICE_INVALID; 00272 else if (!strcasecmp(val, "UNAVAILABLE")) 00273 return AST_DEVICE_UNAVAILABLE; 00274 else if (!strcasecmp(val, "RINGING")) 00275 return AST_DEVICE_RINGING; 00276 else if (!strcasecmp(val, "RINGINUSE")) 00277 return AST_DEVICE_RINGINUSE; 00278 else if (!strcasecmp(val, "ONHOLD")) 00279 return AST_DEVICE_ONHOLD; 00280 00281 return AST_DEVICE_UNKNOWN; 00282 }
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 847 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().
00848 { 00849 if (devstate_collector.enabled) { 00850 return 0; 00851 } 00852 00853 devstate_collector.event_sub = ast_event_subscribe(AST_EVENT_DEVICE_STATE_CHANGE, 00854 devstate_change_collector_cb, NULL, AST_EVENT_IE_END); 00855 00856 if (!devstate_collector.event_sub) { 00857 ast_log(LOG_ERROR, "Failed to create subscription for the device state change collector\n"); 00858 return -1; 00859 } 00860 00861 ast_mutex_init(&devstate_collector.lock); 00862 ast_cond_init(&devstate_collector.cond, NULL); 00863 if (ast_pthread_create_background(&devstate_collector.thread, NULL, run_devstate_collector, NULL) < 0) { 00864 ast_log(LOG_ERROR, "Unable to start device state collector thread.\n"); 00865 return -1; 00866 } 00867 00868 devstate_collector.enabled = 1; 00869 00870 return 0; 00871 }
enum ast_device_state ast_parse_device_state | ( | const char * | device | ) |
Search the Channels by Name.
Definition at line 289 of file devicestate.c.
References ast_channel::_state, AST_CHANNEL_NAME, ast_channel_unlock, ast_copy_string(), AST_DEVICE_INUSE, AST_DEVICE_RINGING, ast_device_state(), AST_DEVICE_UNKNOWN, ast_get_channel_by_name_prefix_locked(), AST_STATE_RINGING, chan, and match().
Referenced by _ast_device_state(), and chanavail_exec().
00290 { 00291 struct ast_channel *chan; 00292 char match[AST_CHANNEL_NAME]; 00293 enum ast_device_state res; 00294 00295 ast_copy_string(match, device, sizeof(match)-1); 00296 strcat(match, "-"); 00297 chan = ast_get_channel_by_name_prefix_locked(match, strlen(match)); 00298 00299 if (!chan) 00300 return AST_DEVICE_UNKNOWN; 00301 00302 if (chan->_state == AST_STATE_RINGING) 00303 res = AST_DEVICE_RINGING; 00304 else 00305 res = AST_DEVICE_INUSE; 00306 00307 ast_channel_unlock(chan); 00308 00309 return res; 00310 }
enum ast_device_state ast_state_chan2dev | ( | enum ast_channel_state | chanstate | ) |
Convert channel state to devicestate.
chanstate | Current channel state |
Definition at line 214 of file devicestate.c.
References AST_DEVICE_UNKNOWN, and chan.
Referenced by dahdi_new().
00215 { 00216 int i; 00217 chanstate &= 0xFFFF; 00218 for (i = 0; chan2dev[i].chan != -100; i++) { 00219 if (chan2dev[i].chan == chanstate) { 00220 return chan2dev[i].dev; 00221 } 00222 } 00223 return AST_DEVICE_UNKNOWN; 00224 }
const char* devstate2str | ( | enum ast_device_state | devstate | ) |
Convert device state to text string for output.
devstate | Current device state |
Definition at line 209 of file devicestate.c.
Referenced by __queues_show(), do_state_change(), handle_statechange(), notify_metermaids(), page_exec(), and process_collection().
00210 { 00211 return devstatestring[devstate]; 00212 }
enum ast_device_state(*) ast_devstate_prov_cb_type(const char *data) |