#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, AST_DEVICE_TOTAL } |
| 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. | |
| const char * | ast_devstate2str (enum ast_device_state devstate) attribute_pure |
| Find devicestate as text message for output. | |
| 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) attribute_pure |
| 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) attribute_pure |
| 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.
| 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.
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 AST_DEVICE_TOTAL, /*/ Total num of device states, used for testing */ 00062 };
| 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 362 of file devicestate.c.
References _ast_device_state().
00363 { 00364 /* This function is called from elsewhere in the code to find out the 00365 * current state of a device. Check the cache, first. */ 00366 00367 return _ast_device_state(device, 1); 00368 }
| 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 522 of file devicestate.c.
References AST_DEVICE_UNKNOWN, ast_devstate_changed_literal(), AST_MAX_EXTENSION, and buf.
00523 { 00524 char buf[AST_MAX_EXTENSION]; 00525 va_list ap; 00526 00527 va_start(ap, fmt); 00528 vsnprintf(buf, sizeof(buf), fmt, ap); 00529 va_end(ap); 00530 00531 return ast_devstate_changed_literal(AST_DEVICE_UNKNOWN, buf); 00532 }
| 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 505 of file devicestate.c.
References AST_DEVICE_UNKNOWN, and ast_devstate_changed_literal().
00506 { 00507 return ast_devstate_changed_literal(AST_DEVICE_UNKNOWN, dev); 00508 }
| const char* ast_devstate2str | ( | enum ast_device_state | devstate | ) |
Find devicestate as text message for output.
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][0]; 00212 }
| void ast_devstate_aggregate_add | ( | struct ast_devstate_aggregate * | agg, | |
| enum ast_device_state | state | |||
| ) |
Add a device state to the aggregate device state.
Definition at line 745 of file devicestate.c.
References ast_devstate_aggregate::all_busy, ast_devstate_aggregate::all_free, ast_devstate_aggregate::all_unavail, ast_devstate_aggregate::all_unknown, AST_DEVICE_BUSY, AST_DEVICE_INUSE, AST_DEVICE_INVALID, AST_DEVICE_NOT_INUSE, AST_DEVICE_ONHOLD, AST_DEVICE_RINGING, AST_DEVICE_RINGINUSE, AST_DEVICE_TOTAL, AST_DEVICE_UNAVAILABLE, AST_DEVICE_UNKNOWN, ast_devstate_aggregate::busy, ast_devstate_aggregate::in_use, ast_devstate_aggregate::on_hold, and ast_devstate_aggregate::ring.
Referenced by ast_extension_state2(), and process_collection().
00746 { 00747 switch (state) { 00748 case AST_DEVICE_NOT_INUSE: 00749 agg->all_unknown = 0; 00750 agg->all_unavail = 0; 00751 agg->all_busy = 0; 00752 break; 00753 case AST_DEVICE_INUSE: 00754 agg->in_use = 1; 00755 agg->all_unavail = 0; 00756 agg->all_free = 0; 00757 agg->all_unknown = 0; 00758 break; 00759 case AST_DEVICE_RINGING: 00760 agg->ring = 1; 00761 agg->all_unavail = 0; 00762 agg->all_free = 0; 00763 agg->all_unknown = 0; 00764 break; 00765 case AST_DEVICE_RINGINUSE: 00766 agg->in_use = 1; 00767 agg->ring = 1; 00768 agg->all_unavail = 0; 00769 agg->all_free = 0; 00770 agg->all_unknown = 0; 00771 break; 00772 case AST_DEVICE_ONHOLD: 00773 agg->all_unknown = 0; 00774 agg->all_unavail = 0; 00775 agg->all_free = 0; 00776 agg->on_hold = 1; 00777 break; 00778 case AST_DEVICE_BUSY: 00779 agg->all_unknown = 0; 00780 agg->all_unavail = 0; 00781 agg->all_free = 0; 00782 agg->busy = 1; 00783 agg->in_use = 1; 00784 break; 00785 case AST_DEVICE_UNAVAILABLE: 00786 agg->all_unknown = 0; 00787 case AST_DEVICE_INVALID: 00788 agg->all_busy = 0; 00789 agg->all_free = 0; 00790 break; 00791 case AST_DEVICE_UNKNOWN: 00792 agg->all_busy = 0; 00793 agg->all_free = 0; 00794 break; 00795 case AST_DEVICE_TOTAL: /* not a device state, included for completeness. */ 00796 break; 00797 } 00798 }
| void ast_devstate_aggregate_init | ( | struct ast_devstate_aggregate * | agg | ) |
Initialize aggregate device state.
| [in] | agg | the state object |
Definition at line 735 of file devicestate.c.
References ast_devstate_aggregate::all_busy, ast_devstate_aggregate::all_free, ast_devstate_aggregate::all_unavail, and ast_devstate_aggregate::all_unknown.
Referenced by ast_extension_state2(), and process_collection().
00736 { 00737 memset(agg, 0, sizeof(*agg)); 00738 00739 agg->all_unknown = 1; 00740 agg->all_unavail = 1; 00741 agg->all_busy = 1; 00742 agg->all_free = 1; 00743 }
| 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 801 of file devicestate.c.
References ast_devstate_aggregate::all_busy, ast_devstate_aggregate::all_free, ast_devstate_aggregate::all_unavail, ast_devstate_aggregate::all_unknown, AST_DEVICE_BUSY, AST_DEVICE_INUSE, 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, ast_devstate_aggregate::on_hold, and ast_devstate_aggregate::ring.
Referenced by ast_extension_state2(), and process_collection().
00802 { 00803 if (agg->all_free) 00804 return AST_DEVICE_NOT_INUSE; 00805 if ((agg->in_use || agg->on_hold) && agg->ring) 00806 return AST_DEVICE_RINGINUSE; 00807 if (agg->ring) 00808 return AST_DEVICE_RINGING; 00809 if (agg->busy) 00810 return AST_DEVICE_BUSY; 00811 if (agg->in_use) 00812 return AST_DEVICE_INUSE; 00813 if (agg->on_hold) 00814 return AST_DEVICE_ONHOLD; 00815 if (agg->all_busy) 00816 return AST_DEVICE_BUSY; 00817 if (agg->all_unknown) 00818 return AST_DEVICE_UNKNOWN; 00819 if (agg->all_unavail) 00820 return AST_DEVICE_UNAVAILABLE; 00821 00822 return AST_DEVICE_NOT_INUSE; 00823 }
| 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 510 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().
00511 { 00512 char buf[AST_MAX_EXTENSION]; 00513 va_list ap; 00514 00515 va_start(ap, fmt); 00516 vsnprintf(buf, sizeof(buf), fmt, ap); 00517 va_end(ap); 00518 00519 return ast_devstate_changed_literal(state, buf); 00520 }
| 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 467 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, state_change::device, devstate_event(), and do_state_change().
Referenced by ast_channel_free(), ast_device_state_changed(), ast_device_state_changed_literal(), ast_devstate_changed(), ast_setstate(), and dahdi_new().
00468 { 00469 struct state_change *change; 00470 00471 /* 00472 * If we know the state change (how nice of the caller of this function!) 00473 * then we can just generate a device state event. 00474 * 00475 * Otherwise, we do the following: 00476 * - Queue an event up to another thread that the state has changed 00477 * - In the processing thread, it calls the callback provided by the 00478 * device state provider (which may or may not be a channel driver) 00479 * to determine the state. 00480 * - If the device state provider does not know the state, or this is 00481 * for a channel and the channel driver does not implement a device 00482 * state callback, then we will look through the channel list to 00483 * see if we can determine a state based on active calls. 00484 * - Once a state has been determined, a device state event is generated. 00485 */ 00486 00487 if (state != AST_DEVICE_UNKNOWN) { 00488 devstate_event(device, state); 00489 } else if (change_thread == AST_PTHREADT_NULL || !(change = ast_calloc(1, sizeof(*change) + strlen(device)))) { 00490 /* we could not allocate a change struct, or */ 00491 /* there is no background thread, so process the change now */ 00492 do_state_change(device); 00493 } else { 00494 /* queue the change */ 00495 strcpy(change->device, device); 00496 AST_LIST_LOCK(&state_changes); 00497 AST_LIST_INSERT_TAIL(&state_changes, change, list); 00498 ast_cond_signal(&change_pending); 00499 AST_LIST_UNLOCK(&state_changes); 00500 } 00501 00502 return 1; 00503 }
| 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 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().
00372 { 00373 struct devstate_prov *devprov; 00374 00375 if (!callback || !(devprov = ast_calloc(1, sizeof(*devprov)))) 00376 return -1; 00377 00378 devprov->callback = callback; 00379 ast_copy_string(devprov->label, label, sizeof(devprov->label)); 00380 00381 AST_RWLIST_WRLOCK(&devstate_provs); 00382 AST_RWLIST_INSERT_HEAD(&devstate_provs, devprov, list); 00383 AST_RWLIST_UNLOCK(&devstate_provs); 00384 00385 return 0; 00386 }
| 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 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 unload_module().
00390 { 00391 struct devstate_prov *devcb; 00392 int res = -1; 00393 00394 AST_RWLIST_WRLOCK(&devstate_provs); 00395 AST_RWLIST_TRAVERSE_SAFE_BEGIN(&devstate_provs, devcb, list) { 00396 if (!strcasecmp(devcb->label, label)) { 00397 AST_RWLIST_REMOVE_CURRENT(list); 00398 ast_free(devcb); 00399 res = 0; 00400 break; 00401 } 00402 } 00403 AST_RWLIST_TRAVERSE_SAFE_END; 00404 AST_RWLIST_UNLOCK(&devstate_provs); 00405 00406 return res; 00407 }
| 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 233 of file devicestate.c.
Referenced by devstate_read().
00234 { 00235 return devstatestring[state][1]; 00236 }
| 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 238 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().
00239 { 00240 if (!strcasecmp(val, "NOT_INUSE")) 00241 return AST_DEVICE_NOT_INUSE; 00242 else if (!strcasecmp(val, "INUSE")) 00243 return AST_DEVICE_INUSE; 00244 else if (!strcasecmp(val, "BUSY")) 00245 return AST_DEVICE_BUSY; 00246 else if (!strcasecmp(val, "INVALID")) 00247 return AST_DEVICE_INVALID; 00248 else if (!strcasecmp(val, "UNAVAILABLE")) 00249 return AST_DEVICE_UNAVAILABLE; 00250 else if (!strcasecmp(val, "RINGING")) 00251 return AST_DEVICE_RINGING; 00252 else if (!strcasecmp(val, "RINGINUSE")) 00253 return AST_DEVICE_RINGINUSE; 00254 else if (!strcasecmp(val, "ONHOLD")) 00255 return AST_DEVICE_ONHOLD; 00256 00257 return AST_DEVICE_UNKNOWN; 00258 }
| 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 825 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(), and add_subscribe_event().
00826 { 00827 if (devstate_collector.enabled) { 00828 return 0; 00829 } 00830 00831 devstate_collector.event_sub = ast_event_subscribe(AST_EVENT_DEVICE_STATE_CHANGE, 00832 devstate_change_collector_cb, NULL, AST_EVENT_IE_END); 00833 00834 if (!devstate_collector.event_sub) { 00835 ast_log(LOG_ERROR, "Failed to create subscription for the device state change collector\n"); 00836 return -1; 00837 } 00838 00839 ast_mutex_init(&devstate_collector.lock); 00840 ast_cond_init(&devstate_collector.cond, NULL); 00841 if (ast_pthread_create_background(&devstate_collector.thread, NULL, run_devstate_collector, NULL) < 0) { 00842 ast_log(LOG_ERROR, "Unable to start device state collector thread.\n"); 00843 return -1; 00844 } 00845 00846 devstate_collector.enabled = 1; 00847 00848 return 0; 00849 }
| enum ast_device_state ast_parse_device_state | ( | const char * | device | ) |
Search the Channels by Name.
| device | like a dial string |
| AST_DEVICE_UNKNOWN | if no channel found | |
| AST_DEVICE_INUSE | if a channel is found |
Definition at line 265 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_UNKNOWN, ast_get_channel_by_name_prefix_locked(), AST_STATE_RINGING, chan, and match().
Referenced by _ast_device_state(), and chanavail_exec().
00266 { 00267 struct ast_channel *chan; 00268 char match[AST_CHANNEL_NAME]; 00269 enum ast_device_state res; 00270 00271 ast_copy_string(match, device, sizeof(match)-1); 00272 strcat(match, "-"); 00273 chan = ast_get_channel_by_name_prefix_locked(match, strlen(match)); 00274 00275 if (!chan) 00276 return AST_DEVICE_UNKNOWN; 00277 00278 if (chan->_state == AST_STATE_RINGING) 00279 res = AST_DEVICE_RINGING; 00280 else 00281 res = AST_DEVICE_INUSE; 00282 00283 ast_channel_unlock(chan); 00284 00285 return res; 00286 }
| enum ast_device_state ast_state_chan2dev | ( | enum ast_channel_state | chanstate | ) |
Convert channel state to devicestate.
| chanstate | Current channel state |
Definition at line 220 of file devicestate.c.
References AST_DEVICE_UNKNOWN, and chan.
Referenced by dahdi_new().
00221 { 00222 int i; 00223 chanstate &= 0xFFFF; 00224 for (i = 0; chan2dev[i].chan != -100; i++) { 00225 if (chan2dev[i].chan == chanstate) { 00226 return chan2dev[i].dev; 00227 } 00228 } 00229 return AST_DEVICE_UNKNOWN; 00230 }
| const char* devstate2str | ( | enum ast_device_state | devstate | ) |
Convert device state to text string for output.
| devstate | Current device state |
Definition at line 215 of file devicestate.c.
00216 { 00217 return devstatestring[devstate][0]; 00218 }
| enum ast_device_state(* ast_devstate_prov_cb_type)(const char *data) |
Devicestate provider call back.
1.5.9