devicestate.h File Reference

Device state management. More...

#include "asterisk/channelstate.h"
#include "asterisk/utils.h"

Include dependency graph for devicestate.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ast_device_state_message
 The structure that contains device state. More...
struct  ast_devstate_aggregate
 You shouldn't care about the contents of this struct. More...

Defines

#define ast_publish_device_state(device, state, cachable)   ast_publish_device_state_full(device, state, cachable, &ast_eid_default)
 Publish a device state update.

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.
struct stasis_cacheast_device_state_cache (void)
 Backend cache for ast_device_state_topic_cached().
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.
int ast_device_state_clear_cache (const char *device)
 Clear the device from the stasis cache.
struct stasis_message_typeast_device_state_message_type (void)
 Get the Stasis message type for device state messages.
struct stasis_topicast_device_state_topic (const char *device)
 Get the Stasis topic for device state messages for a specific device.
struct stasis_topicast_device_state_topic_all (void)
 Get the Stasis topic for device state messages.
struct stasis_topicast_device_state_topic_cached (void)
 Get the Stasis caching topic for device state messages.
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, enum ast_devstate_cache cachable, const char *fmt,...)
 Tells Asterisk the State for Device is changed.
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.
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.
enum ast_device_state ast_parse_device_state (const char *device)
 Search the Channels by Name.
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.
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.
int devstate_init (void)
 Initialize the device state core.

Variables

enum ast_device_state(* ast_devstate_prov_cb_type )(const char *data)
 Devicestate provider call back.


Detailed Description

Device state management.

To subscribe to device state changes, use the stasis_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.


Define Documentation

#define ast_publish_device_state ( device,
state,
cachable   )     ast_publish_device_state_full(device, state, cachable, &ast_eid_default)

Publish a device state update.

Parameters:
[in] device The device name
[in] state The state of the device
[in] cachable Whether the device state can be cached
Return values:
0 Success
-1 Failure
Since:
12

Definition at line 359 of file devicestate.h.

Referenced by ast_devstate_changed_literal(), AST_TEST_DEFINE(), and do_state_change().


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  Total num of device states, used for testing

Definition at line 52 of file devicestate.h.

00052                       {
00053    AST_DEVICE_UNKNOWN,      /*!< Device is valid but channel didn't know state */
00054    AST_DEVICE_NOT_INUSE,    /*!< Device is not used */
00055    AST_DEVICE_INUSE,        /*!< Device is in use */
00056    AST_DEVICE_BUSY,         /*!< Device is busy */
00057    AST_DEVICE_INVALID,      /*!< Device is invalid */
00058    AST_DEVICE_UNAVAILABLE,  /*!< Device is unavailable */
00059    AST_DEVICE_RINGING,      /*!< Device is ringing */
00060    AST_DEVICE_RINGINUSE,    /*!< Device is ringing *and* in use */
00061    AST_DEVICE_ONHOLD,       /*!< Device is on hold */
00062    AST_DEVICE_TOTAL,        /*!< Total num of device states, used for testing */
00063 };

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 68 of file devicestate.h.

00068                         {
00069    AST_DEVSTATE_NOT_CACHABLE,  /*!< This device state is not cachable */
00070    AST_DEVSTATE_CACHABLE,      /*!< This device state is cachable */
00071 };


Function Documentation

enum ast_device_state ast_device_state ( const char *  device  ) 

Asks a channel for device state.

Parameters:
device like 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:
an AST_DEVICE_??? state

Definition at line 389 of file devicestate.c.

References _ast_device_state().

00390 {
00391    /* This function is called from elsewhere in the code to find out the
00392     * current state of a device.  Check the cache, first. */
00393 
00394    return _ast_device_state(device, 1);
00395 }

struct stasis_cache* ast_device_state_cache ( void   )  [read]

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:
fmt device 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:
0 on success
-1 on failure
Note:
This is deprecated in favor of ast_devstate_changed()
Version:
1.6.1 deprecated

Definition at line 525 of file devicestate.c.

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

00526 {
00527    char buf[AST_MAX_EXTENSION];
00528    va_list ap;
00529 
00530    va_start(ap, fmt);
00531    vsnprintf(buf, sizeof(buf), fmt, ap);
00532    va_end(ap);
00533 
00534    return ast_devstate_changed_literal(AST_DEVICE_UNKNOWN, AST_DEVSTATE_CACHABLE, buf);
00535 }

int ast_device_state_changed_literal ( const char *  device  ) 

Tells Asterisk the State for Device is changed.

Parameters:
device device name like a dial string
Asterisk polls the new extension states and calls the registered callbacks for the changed extensions

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

Definition at line 508 of file devicestate.c.

References AST_DEVICE_UNKNOWN, AST_DEVSTATE_CACHABLE, and ast_devstate_changed_literal().

int ast_device_state_clear_cache ( const char *  device  ) 

Clear the device from the stasis cache.

Parameters:
The device to clear
Return values:
0 if successful
-1 nothing to clear
Since:
12

Definition at line 690 of file devicestate.c.

References ao2_cleanup, ast_device_state_cache(), ast_device_state_message_type(), ast_device_state_topic(), ast_eid_default, stasis_cache_clear_create(), stasis_cache_get_by_eid(), and stasis_publish().

Referenced by stasis_app_device_state_delete().

00691 {
00692    struct stasis_message *cached_msg;
00693    struct stasis_message *msg;
00694 
00695    cached_msg = stasis_cache_get_by_eid(ast_device_state_cache(),
00696       ast_device_state_message_type(), device, &ast_eid_default);
00697    if (!cached_msg) {
00698       /* nothing to clear */
00699       return -1;
00700    }
00701 
00702    msg = stasis_cache_clear_create(cached_msg);
00703    if (msg) {
00704       stasis_publish(ast_device_state_topic(device), msg);
00705    }
00706    ao2_cleanup(msg);
00707    ao2_cleanup(cached_msg);
00708    return 0;
00709 }

struct stasis_message_type* ast_device_state_message_type ( void   )  [read]

struct stasis_topic* ast_device_state_topic ( const char *  device  )  [read]

Get the Stasis topic for device state messages for a specific device.

Parameters:
uniqueid The device for which to get the topic
Return values:
The topic structure for MWI messages for a given device
NULL if it failed to be found or allocated
Since:
12

Definition at line 685 of file devicestate.c.

References device_state_topic_pool, and stasis_topic_pool_get_topic().

Referenced by ast_device_state_clear_cache(), ast_publish_device_state_full(), cc_generic_agent_start_monitoring(), create_new_generic_list(), device_state_aggregate_publish(), remove_device_states_cb(), and subscribe_device_state().

00686 {
00687    return stasis_topic_pool_get_topic(device_state_topic_pool, device);
00688 }

struct stasis_topic* ast_device_state_topic_all ( void   )  [read]

Get the Stasis topic for device state messages.

Return values:
The topic for device state messages
NULL if it has not been allocated
Since:
12

Definition at line 670 of file devicestate.c.

References device_state_topic_all.

Referenced by asterisk_start_devicestate_publishing(), devstate_init(), load_module(), load_pbx(), and xmpp_init_event_distribution().

00671 {
00672    return device_state_topic_all;
00673 }

struct stasis_topic* ast_device_state_topic_cached ( void   )  [read]

Get the Stasis caching topic for device state messages.

Return values:
The caching topic for device state messages
NULL if it has not been allocated
Since:
12

Definition at line 680 of file devicestate.c.

References device_state_topic_cached, and stasis_caching_get_topic().

Referenced by AST_TEST_DEFINE().

00681 {
00682    return stasis_caching_get_topic(device_state_topic_cached);
00683 }

const char* ast_devstate2str ( enum ast_device_state  devstate  ) 

Find devicestate as text message for output.

Definition at line 238 of file devicestate.c.

Referenced by __queues_show(), ast_sip_get_device_state(), AST_TEST_DEFINE(), ccss_notify_device_state_change(), device_state_cb(), do_state_change(), extension_state_cb(), page_exec(), and parking_notify_metermaids().

00239 {
00240    return devstatestring[devstate][0];
00241 }

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] agg the state object
[in] state the state to add
Returns:
nothing
Since:
1.6.1

Definition at line 638 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, and ast_devstate_aggregate::state.

Referenced by ast_extension_state3(), AST_TEST_DEFINE(), chan_pjsip_devicestate(), and device_state_aggregate_calc().

00639 {
00640    static enum ast_device_state state_order[] = {
00641       1, /* AST_DEVICE_UNKNOWN */
00642       3, /* AST_DEVICE_NOT_INUSE */
00643       6, /* AST_DEVICE_INUSE */
00644       7, /* AST_DEVICE_BUSY */
00645       0, /* AST_DEVICE_INVALID */
00646       2, /* AST_DEVICE_UNAVAILABLE */
00647       5, /* AST_DEVICE_RINGING */
00648       8, /* AST_DEVICE_RINGINUSE */
00649       4, /* AST_DEVICE_ONHOLD */
00650    };
00651 
00652    if (state == AST_DEVICE_RINGING) {
00653       agg->ringing = 1;
00654    } else if (state == AST_DEVICE_INUSE || state == AST_DEVICE_ONHOLD || state == AST_DEVICE_BUSY) {
00655       agg->inuse = 1;
00656    }
00657 
00658    if (agg->ringing && agg->inuse) {
00659       agg->state = AST_DEVICE_RINGINUSE;
00660    } else if (state_order[state] > state_order[agg->state]) {
00661       agg->state = state;
00662    }
00663 }

void ast_devstate_aggregate_init ( struct ast_devstate_aggregate agg  ) 

Initialize aggregate device state.

Parameters:
[in] agg the state object
Returns:
nothing
Since:
1.6.1

Definition at line 632 of file devicestate.c.

References AST_DEVICE_INVALID, and ast_devstate_aggregate::state.

Referenced by ast_extension_state3(), AST_TEST_DEFINE(), chan_pjsip_devicestate(), and device_state_aggregate_calc().

00633 {
00634    memset(agg, 0, sizeof(*agg));
00635    agg->state = AST_DEVICE_INVALID;
00636 }

enum ast_device_state ast_devstate_aggregate_result ( struct ast_devstate_aggregate agg  ) 

Get the aggregate device state result.

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

Definition at line 665 of file devicestate.c.

References ast_devstate_aggregate::state.

Referenced by ast_extension_state3(), AST_TEST_DEFINE(), chan_pjsip_devicestate(), and device_state_aggregate_calc().

00666 {
00667    return agg->state;
00668 }

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:
state the new state of the device
cachable whether this device state is cachable
fmt device 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:
0 on success
-1 on failure

Definition at line 513 of file devicestate.c.

References ast_devstate_changed_literal(), AST_MAX_EXTENSION, and buf.

Referenced by __expire_registry(), __iax2_poke_noanswer(), add_to_queue(), agent_devstate_changed(), calendar_devstate_change(), ccss_notify_device_state_change(), chan_pjsip_indicate(), conf_handle_first_join(), conf_run(), destroy_event(), device_state_cb(), 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(), init_queue(), join_queue(), leave_queue(), load_module(), member_add_to_queue(), member_remove_from_queue(), parking_notify_metermaids(), persistent_endpoint_update_state(), populate_cache(), queue_function_mem_write(), reg_source_db(), register_verify(), remove_from_queue(), rt_handle_member_record(), set_member_paused(), sip_peer_hold(), sip_poke_noanswer(), skinny_register(), skinny_session_cleanup(), sla_change_trunk_state(), sla_handle_hold_event(), sla_station_exec(), socket_process_helper(), stasis_app_device_state_delete(), stasis_app_device_state_update(), transition_to_empty(), update_call_counter(), update_devstate(), update_registry(), and xmpp_pak_presence().

00514 {
00515    char buf[AST_MAX_EXTENSION];
00516    va_list ap;
00517 
00518    va_start(ap, fmt);
00519    vsnprintf(buf, sizeof(buf), fmt, ap);
00520    va_end(ap);
00521 
00522    return ast_devstate_changed_literal(state, cachable, buf);
00523 }

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:
state the new state of the device
cachable whether this device state is cachable
device device 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:
0 on success
-1 on failure

Definition at line 469 of file devicestate.c.

References ast_calloc, ast_cond_signal, AST_DEVICE_UNKNOWN, AST_LIST_INSERT_TAIL, AST_LIST_LOCK, AST_LIST_UNLOCK, AST_PTHREADT_NULL, ast_publish_device_state, state_change::cachable, change_pending, change_thread, state_change::device, and do_state_change().

Referenced by ast_channel_destructor(), ast_device_state_changed(), ast_device_state_changed_literal(), ast_devstate_changed(), ast_setstate(), chan_pjsip_indicate(), and dahdi_new().

00470 {
00471    struct state_change *change;
00472 
00473    /*
00474     * If we know the state change (how nice of the caller of this function!)
00475     * then we can just generate a device state event.
00476     *
00477     * Otherwise, we do the following:
00478     *   - Queue an event up to another thread that the state has changed
00479     *   - In the processing thread, it calls the callback provided by the
00480     *     device state provider (which may or may not be a channel driver)
00481     *     to determine the state.
00482     *   - If the device state provider does not know the state, or this is
00483     *     for a channel and the channel driver does not implement a device
00484     *     state callback, then we will look through the channel list to
00485     *     see if we can determine a state based on active calls.
00486     *   - Once a state has been determined, a device state event is generated.
00487     */
00488 
00489    if (state != AST_DEVICE_UNKNOWN) {
00490       ast_publish_device_state(device, state, cachable);
00491    } else if (change_thread == AST_PTHREADT_NULL || !(change = ast_calloc(1, sizeof(*change) + strlen(device)))) {
00492       /* we could not allocate a change struct, or */
00493       /* there is no background thread, so process the change now */
00494       do_state_change(device, cachable);
00495    } else {
00496       /* queue the change */
00497       strcpy(change->device, device);
00498       change->cachable = cachable;
00499       AST_LIST_LOCK(&state_changes);
00500       AST_LIST_INSERT_TAIL(&state_changes, change, list);
00501       ast_cond_signal(&change_pending);
00502       AST_LIST_UNLOCK(&state_changes);
00503    }
00504 
00505    return 0;
00506 }

int ast_devstate_prov_add ( const char *  label,
ast_devstate_prov_cb_type  callback 
)

Add device state provider.

Parameters:
label to use in hint, like label:object
callback Callback
Return values:
0 success
-1 failure

Definition at line 398 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_cc_init(), load_module(), and load_parking_devstate().

00399 {
00400    struct devstate_prov *devprov;
00401 
00402    if (!callback || !(devprov = ast_calloc(1, sizeof(*devprov))))
00403       return -1;
00404 
00405    devprov->callback = callback;
00406    ast_copy_string(devprov->label, label, sizeof(devprov->label));
00407 
00408    AST_RWLIST_WRLOCK(&devstate_provs);
00409    AST_RWLIST_INSERT_HEAD(&devstate_provs, devprov, list);
00410    AST_RWLIST_UNLOCK(&devstate_provs);
00411 
00412    return 0;
00413 }

int ast_devstate_prov_del ( const char *  label  ) 

Remove device state provider.

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

Definition at line 416 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(), unload_module(), and unload_parking_devstate().

00417 {
00418    struct devstate_prov *devcb;
00419    int res = -1;
00420 
00421    AST_RWLIST_WRLOCK(&devstate_provs);
00422    AST_RWLIST_TRAVERSE_SAFE_BEGIN(&devstate_provs, devcb, list) {
00423       if (!strcasecmp(devcb->label, label)) {
00424          AST_RWLIST_REMOVE_CURRENT(list);
00425          ast_free(devcb);
00426          res = 0;
00427          break;
00428       }
00429    }
00430    AST_RWLIST_TRAVERSE_SAFE_END;
00431    AST_RWLIST_UNLOCK(&devstate_provs);
00432 
00433    return res;
00434 }

const char* ast_devstate_str ( enum ast_device_state  devstate  ) 

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

Parameters:
devstate Current device state

Definition at line 262 of file devicestate.c.

Referenced by agent_handle_show_specific(), agent_show_requested(), asterisk_publisher_devstate_cb(), devstate_read(), devstate_to_ami(), stasis_app_device_state_to_json(), and xmpp_pubsub_devstate_cb().

00263 {
00264    return devstatestring[state][1];
00265 }

enum ast_device_state ast_devstate_val ( const char *  val  ) 

Convert device state from text to integer value.

Parameters:
val The 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 267 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 asterisk_publication_devicestate(), custom_devstate_callback(), devstate_write(), handle_cli_devstate_change(), initialize_cc_devstate_map_helper(), load_module(), populate_cache(), stasis_app_device_state_update(), stasis_device_state_cb(), and xmpp_pubsub_handle_event().

00268 {
00269    if (!strcasecmp(val, "NOT_INUSE"))
00270       return AST_DEVICE_NOT_INUSE;
00271    else if (!strcasecmp(val, "INUSE"))
00272       return AST_DEVICE_INUSE;
00273    else if (!strcasecmp(val, "BUSY"))
00274       return AST_DEVICE_BUSY;
00275    else if (!strcasecmp(val, "INVALID"))
00276       return AST_DEVICE_INVALID;
00277    else if (!strcasecmp(val, "UNAVAILABLE"))
00278       return AST_DEVICE_UNAVAILABLE;
00279    else if (!strcasecmp(val, "RINGING"))
00280       return AST_DEVICE_RINGING;
00281    else if (!strcasecmp(val, "RINGINUSE"))
00282       return AST_DEVICE_RINGINUSE;
00283    else if (!strcasecmp(val, "ONHOLD"))
00284       return AST_DEVICE_ONHOLD;
00285 
00286    return AST_DEVICE_UNKNOWN;
00287 }

enum ast_device_state ast_parse_device_state ( const char *  device  ) 

Search the Channels by Name.

Parameters:
device like 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_UNKNOWN if no channel found
AST_DEVICE_INUSE if 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 294 of file devicestate.c.

References ast_channel_get_by_name_prefix(), ast_channel_hold_state(), AST_CHANNEL_NAME, ast_channel_unref, AST_CONTROL_HOLD, AST_DEVICE_ONHOLD, AST_DEVICE_UNKNOWN, ast_state_chan2dev(), and match().

Referenced by _ast_device_state(), and chanavail_exec().

00295 {
00296    struct ast_channel *chan;
00297    char match[AST_CHANNEL_NAME];
00298    enum ast_device_state res;
00299 
00300    snprintf(match, sizeof(match), "%s-", device);
00301 
00302    if (!(chan = ast_channel_get_by_name_prefix(match, strlen(match)))) {
00303       return AST_DEVICE_UNKNOWN;
00304    }
00305 
00306    if (ast_channel_hold_state(chan) == AST_CONTROL_HOLD) {
00307       res = AST_DEVICE_ONHOLD;
00308    } else {
00309       res = ast_state_chan2dev(ast_channel_state(chan));
00310    }
00311    ast_channel_unref(chan);
00312 
00313    return res;
00314 }

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.

Parameters:
[in] device The device name
[in] state The state of the device
[in] cachable Whether the device state can be cached
[in] eid The EID of the server that originally published the message
Return values:
0 Success
-1 Failure
Since:
12

Definition at line 711 of file devicestate.c.

References ao2_cleanup, ast_assert, ast_device_state_message_type(), ast_device_state_topic(), ast_strlen_zero, device_state_alloc(), NULL, RAII_VAR, stasis_message_create_full(), and stasis_publish().

Referenced by AST_TEST_DEFINE(), asterisk_publication_devicestate(), devstate_change_cb(), publish_device_state_to_stasis(), and xmpp_pubsub_handle_event().

00716 {
00717    RAII_VAR(struct ast_device_state_message *, device_state, NULL, ao2_cleanup);
00718    RAII_VAR(struct stasis_message *, message, NULL, ao2_cleanup);
00719    struct stasis_topic *device_specific_topic;
00720 
00721    ast_assert(!ast_strlen_zero(device));
00722 
00723    if (!ast_device_state_message_type()) {
00724       return -1;
00725    }
00726 
00727    device_state = device_state_alloc(device, state, cachable, eid);
00728    if (!device_state) {
00729       return -1;
00730    }
00731 
00732    message = stasis_message_create_full(ast_device_state_message_type(), device_state,
00733       eid);
00734    if (!message) {
00735       return -1;
00736    }
00737 
00738    device_specific_topic = ast_device_state_topic(device);
00739    if (!device_specific_topic) {
00740       return -1;
00741    }
00742 
00743    stasis_publish(device_specific_topic, message);
00744    return 0;
00745 }

enum ast_device_state ast_state_chan2dev ( enum ast_channel_state  chanstate  ) 

Convert channel state to devicestate.

Parameters:
chanstate Current channel state
Since:
1.6.1

Definition at line 249 of file devicestate.c.

References ARRAY_LEN, and AST_DEVICE_UNKNOWN.

Referenced by ast_parse_device_state(), and chan_pjsip_devicestate().

00250 {
00251    int i;
00252    chanstate &= 0xFFFF;
00253    for (i = 0; i < ARRAY_LEN(chan2dev); i++) {
00254       if (chan2dev[i].chan == chanstate) {
00255          return chan2dev[i].dev;
00256       }
00257    }
00258    return AST_DEVICE_UNKNOWN;
00259 }

const char* devstate2str ( enum ast_device_state  devstate  ) 

Convert device state to text string for output.

Parameters:
devstate Current device state

Definition at line 244 of file devicestate.c.

00245 {
00246    return devstatestring[devstate][0];
00247 }

int devstate_init ( void   ) 

Initialize the device state core.

Return values:
0 Success
-1 Failure
Since:
12

Definition at line 884 of file devicestate.c.

References ast_device_state_message_type(), ast_device_state_topic_all(), ast_log, ast_register_cleanup(), device_state_aggregate_calc(), device_state_aggregate_publish(), device_state_cache, device_state_get_id(), device_state_topic_all, device_state_topic_cached, device_state_topic_pool, devstate_change_cb(), devstate_cleanup(), devstate_message_sub, LOG_ERROR, NULL, stasis_cache_create_full(), stasis_caching_topic_create(), STASIS_MESSAGE_TYPE_INIT, stasis_subscribe(), stasis_topic_create(), and stasis_topic_pool_create().

Referenced by main().

00885 {
00886    ast_register_cleanup(devstate_cleanup);
00887 
00888    if (STASIS_MESSAGE_TYPE_INIT(ast_device_state_message_type) != 0) {
00889       return -1;
00890    }
00891    device_state_topic_all = stasis_topic_create("ast_device_state_topic");
00892    if (!device_state_topic_all) {
00893       devstate_cleanup();
00894       return -1;
00895    }
00896    device_state_topic_pool = stasis_topic_pool_create(ast_device_state_topic_all());
00897    if (!device_state_topic_pool) {
00898       devstate_cleanup();
00899       return -1;
00900    }
00901    device_state_cache = stasis_cache_create_full(device_state_get_id,
00902       device_state_aggregate_calc, device_state_aggregate_publish);
00903    if (!device_state_cache) {
00904       devstate_cleanup();
00905       return -1;
00906    }
00907    device_state_topic_cached = stasis_caching_topic_create(ast_device_state_topic_all(),
00908       device_state_cache);
00909    if (!device_state_topic_cached) {
00910       devstate_cleanup();
00911       return -1;
00912    }
00913 
00914    devstate_message_sub = stasis_subscribe(ast_device_state_topic_all(),
00915       devstate_change_cb, NULL);
00916    if (!devstate_message_sub) {
00917       ast_log(LOG_ERROR, "Failed to create subscription creating uncached device state aggregate events.\n");
00918       devstate_cleanup();
00919       return -1;
00920    }
00921 
00922    return 0;
00923 }


Variable Documentation

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

Devicestate provider call back.


Generated on Thu Apr 16 06:30:38 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6