Go to the source code of this file.
Defines | |
#define | AST_DEVICE_BUSY 3 |
#define | AST_DEVICE_INUSE 2 |
#define | AST_DEVICE_INVALID 4 |
#define | AST_DEVICE_NOT_INUSE 1 |
#define | AST_DEVICE_ONHOLD 8 |
#define | AST_DEVICE_RINGING 6 |
#define | AST_DEVICE_RINGINUSE 7 |
#define | AST_DEVICE_UNAVAILABLE 5 |
#define | AST_DEVICE_UNKNOWN 0 |
Typedefs | |
typedef int(* | ast_devstate_cb_type )(const char *dev, int state, void *data) |
Devicestate watcher call back. | |
typedef int(* | ast_devstate_prov_cb_type )(const char *data) |
Devicestate provider call back. | |
Functions | |
int | ast_device_state (const char *device) |
Asks a channel for device state. | |
int | ast_device_state_changed (const char *fmt,...) __attribute__((format(printf |
Tells Asterisk the State for Device is changed. | |
int int | ast_device_state_changed_literal (const char *device) |
Tells Asterisk the State for Device is changed. | |
int | ast_device_state_engine_init (void) |
Initialize the device state engine in separate thread. | |
int | ast_devstate_add (ast_devstate_cb_type callback, void *data) |
Registers a device state change callback. | |
void | ast_devstate_del (ast_devstate_cb_type callback, void *data) |
Unregisters a device state change callback. | |
int | ast_devstate_prov_add (const char *label, ast_devstate_prov_cb_type callback) |
Add device state provider. | |
void | ast_devstate_prov_del (const char *label) |
Remove device state provider. | |
int | ast_parse_device_state (const char *device) |
Search the Channels by Name. | |
const char * | devstate2str (int devstate) |
Convert device state to text string for output. |
Definition in file devicestate.h.
#define AST_DEVICE_BUSY 3 |
Device is busy
Definition at line 37 of file devicestate.h.
Referenced by agent_devicestate(), ast_extension_state2(), sip_devicestate(), and update_dial_status().
#define AST_DEVICE_INUSE 2 |
Device is in use
Definition at line 35 of file devicestate.h.
Referenced by agent_devicestate(), ast_extension_state2(), ast_parse_device_state(), meetmestate(), metermaidstate(), sip_devicestate(), and sla_state().
#define AST_DEVICE_INVALID 4 |
Device is invalid
Definition at line 39 of file devicestate.h.
Referenced by agent_devicestate(), ast_device_state(), ast_extension_state2(), get_member_status(), getproviderstate(), iax2_devicestate(), local_devicestate(), meetmestate(), metermaidstate(), mgcp_devicestate(), sip_devicestate(), sla_state(), and update_dial_status().
#define AST_DEVICE_NOT_INUSE 1 |
Device is not used
Definition at line 33 of file devicestate.h.
Referenced by ast_device_state(), ast_extension_state2(), is_our_turn(), meetmestate(), metermaidstate(), ring_entry(), sip_devicestate(), sla_state(), and try_calling().
#define AST_DEVICE_ONHOLD 8 |
Device is on hold
Definition at line 47 of file devicestate.h.
Referenced by ast_extension_state2(), sip_devicestate(), and sla_state().
#define AST_DEVICE_RINGING 6 |
Device is ringing
Definition at line 43 of file devicestate.h.
Referenced by ast_extension_state2(), ast_parse_device_state(), sip_devicestate(), and sla_state().
#define AST_DEVICE_RINGINUSE 7 |
Device is ringing *and* in use
Definition at line 45 of file devicestate.h.
Referenced by ast_extension_state2(), and sip_devicestate().
#define AST_DEVICE_UNAVAILABLE 5 |
Device is unavailable
Definition at line 41 of file devicestate.h.
Referenced by agent_devicestate(), ast_extension_state2(), get_member_status(), iax2_devicestate(), sip_devicestate(), transmit_state_notify(), and update_dial_status().
#define AST_DEVICE_UNKNOWN 0 |
Device is valid but channel didn't know state
Definition at line 31 of file devicestate.h.
Referenced by agent_devicestate(), ast_device_state(), ast_parse_device_state(), iax2_devicestate(), is_our_turn(), local_devicestate(), mgcp_devicestate(), ring_entry(), sip_devicestate(), and update_dial_status().
typedef int(* ast_devstate_cb_type)(const char *dev, int state, void *data) |
typedef int(* ast_devstate_prov_cb_type)(const char *data) |
int ast_device_state | ( | const char * | device | ) |
Asks a channel for device state.
device | like a dialstring Asks a channel for device state, data is normaly a number from dialstring used by the low level module Trys the channel devicestate callback if not supported search in the active channels list for the device. Returns an AST_DEVICE_??? state -1 on failure |
Channel driver that provides device state
Another provider of device state
Definition at line 132 of file devicestate.c.
References AST_DEVICE_INVALID, AST_DEVICE_NOT_INUSE, AST_DEVICE_UNKNOWN, ast_get_channel_tech(), ast_log(), ast_parse_device_state(), ast_strdupa, ast_channel_tech::devicestate, getproviderstate(), LOG_DEBUG, option_debug, and strsep().
00133 { 00134 char *buf; 00135 char *number; 00136 const struct ast_channel_tech *chan_tech; 00137 int res = 0; 00138 /*! \brief Channel driver that provides device state */ 00139 char *tech; 00140 /*! \brief Another provider of device state */ 00141 char *provider = NULL; 00142 00143 buf = ast_strdupa(device); 00144 tech = strsep(&buf, "/"); 00145 number = buf; 00146 if (!number) { 00147 provider = strsep(&tech, ":"); 00148 if (!provider) 00149 return AST_DEVICE_INVALID; 00150 /* We have a provider */ 00151 number = tech; 00152 tech = NULL; 00153 } 00154 00155 if (provider) { 00156 if(option_debug > 2) 00157 ast_log(LOG_DEBUG, "Checking if I can find provider for \"%s\" - number: %s\n", provider, number); 00158 return getproviderstate(provider, number); 00159 } 00160 if (option_debug > 3) 00161 ast_log(LOG_DEBUG, "No provider found, checking channel drivers for %s - %s\n", tech, number); 00162 00163 chan_tech = ast_get_channel_tech(tech); 00164 if (!chan_tech) 00165 return AST_DEVICE_INVALID; 00166 00167 if (!chan_tech->devicestate) /* Does the channel driver support device state notification? */ 00168 return ast_parse_device_state(device); /* No, try the generic function */ 00169 else { 00170 res = chan_tech->devicestate(number); /* Ask the channel driver for device state */ 00171 if (res == AST_DEVICE_UNKNOWN) { 00172 res = ast_parse_device_state(device); 00173 /* at this point we know the device exists, but the channel driver 00174 could not give us a state; if there is no channel state available, 00175 it must be 'not in use' 00176 */ 00177 if (res == AST_DEVICE_UNKNOWN) 00178 res = AST_DEVICE_NOT_INUSE; 00179 return res; 00180 } else 00181 return res; 00182 } 00183 }
int ast_device_state_changed | ( | const char * | fmt, | |
... | ||||
) |
Tells Asterisk the State for Device is changed.
fmt | devicename like a dialstring with format parameters Asterisk polls the new extensionstates and calls the registered callbacks for the changed extensions Returns 0 on success, -1 on failure |
int int ast_device_state_changed_literal | ( | const char * | device | ) |
Tells Asterisk the State for Device is changed.
device | devicename like a dialstring Asterisk polls the new extensionstates and calls the registered callbacks for the changed extensions Returns 0 on success, -1 on failure |
Definition at line 330 of file devicestate.c.
References __ast_device_state_changed_literal(), and ast_strdupa.
00331 { 00332 char *buf; 00333 buf = ast_strdupa(dev); 00334 return __ast_device_state_changed_literal(buf); 00335 }
int ast_device_state_engine_init | ( | void | ) |
Initialize the device state engine in separate thread.
Definition at line 375 of file devicestate.c.
References ast_cond_init(), ast_log(), ast_pthread_create_background, do_devstate_changes(), and LOG_ERROR.
00376 { 00377 ast_cond_init(&change_pending, NULL); 00378 if (ast_pthread_create_background(&change_thread, NULL, do_devstate_changes, NULL) < 0) { 00379 ast_log(LOG_ERROR, "Unable to start device state change thread.\n"); 00380 return -1; 00381 } 00382 00383 return 0; 00384 }
int ast_devstate_add | ( | ast_devstate_cb_type | callback, | |
void * | data | |||
) |
Registers a device state change callback.
callback | Callback | |
data | to pass to callback The callback is called if the state for extension is changed Return -1 on failure, ID on success |
Definition at line 243 of file devicestate.c.
References ast_calloc, AST_LIST_INSERT_HEAD, AST_LIST_LOCK, AST_LIST_UNLOCK, devstate_cb::callback, and devstate_cb::data.
00244 { 00245 struct devstate_cb *devcb; 00246 00247 if (!callback || !(devcb = ast_calloc(1, sizeof(*devcb)))) 00248 return -1; 00249 00250 devcb->data = data; 00251 devcb->callback = callback; 00252 00253 AST_LIST_LOCK(&devstate_cbs); 00254 AST_LIST_INSERT_HEAD(&devstate_cbs, devcb, list); 00255 AST_LIST_UNLOCK(&devstate_cbs); 00256 00257 return 0; 00258 }
void ast_devstate_del | ( | ast_devstate_cb_type | callback, | |
void * | data | |||
) |
Unregisters a device state change callback.
callback | Callback | |
data | to pass to callback The callback is called if the state for extension is changed Return -1 on failure, ID on success |
Definition at line 261 of file devicestate.c.
References AST_LIST_LOCK, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, AST_LIST_UNLOCK, devstate_cb::callback, devstate_cb::data, and free.
00262 { 00263 struct devstate_cb *devcb; 00264 00265 AST_LIST_LOCK(&devstate_cbs); 00266 AST_LIST_TRAVERSE_SAFE_BEGIN(&devstate_cbs, devcb, list) { 00267 if ((devcb->callback == callback) && (devcb->data == data)) { 00268 AST_LIST_REMOVE_CURRENT(&devstate_cbs, list); 00269 free(devcb); 00270 break; 00271 } 00272 } 00273 AST_LIST_TRAVERSE_SAFE_END; 00274 AST_LIST_UNLOCK(&devstate_cbs); 00275 }
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 |
-1 | failure | |
0 | success |
Definition at line 186 of file devicestate.c.
References ast_calloc, AST_LIST_INSERT_HEAD, AST_LIST_LOCK, AST_LIST_UNLOCK, devstate_prov::callback, and devstate_prov::label.
00187 { 00188 struct devstate_prov *devprov; 00189 00190 if (!callback || !(devprov = ast_calloc(1, sizeof(*devprov)))) 00191 return -1; 00192 00193 devprov->callback = callback; 00194 ast_copy_string(devprov->label, label, sizeof(devprov->label)); 00195 00196 AST_LIST_LOCK(&devstate_provs); 00197 AST_LIST_INSERT_HEAD(&devstate_provs, devprov, list); 00198 AST_LIST_UNLOCK(&devstate_provs); 00199 00200 return 0; 00201 }
void ast_devstate_prov_del | ( | const char * | label | ) |
Remove device state provider.
label | to use in hint, like label:object |
Definition at line 204 of file devicestate.c.
References AST_LIST_LOCK, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, AST_LIST_UNLOCK, free, and devstate_prov::label.
00205 { 00206 struct devstate_prov *devcb; 00207 00208 AST_LIST_LOCK(&devstate_provs); 00209 AST_LIST_TRAVERSE_SAFE_BEGIN(&devstate_provs, devcb, list) { 00210 if (!strcasecmp(devcb->label, label)) { 00211 AST_LIST_REMOVE_CURRENT(&devstate_provs, list); 00212 free(devcb); 00213 break; 00214 } 00215 } 00216 AST_LIST_TRAVERSE_SAFE_END; 00217 AST_LIST_UNLOCK(&devstate_provs); 00218 }
int ast_parse_device_state | ( | const char * | device | ) |
Search the Channels by Name.
device | like a dialstring Search the Device in active channels by compare the channelname against the devicename. Compared are only the first chars to the first '-' char. Returns an AST_DEVICE_UNKNOWN if no channel found or AST_DEVICE_INUSE if a channel is found |
Definition at line 108 of file devicestate.c.
References ast_channel::_state, AST_CHANNEL_NAME, ast_channel_unlock, AST_DEVICE_INUSE, AST_DEVICE_RINGING, AST_DEVICE_UNKNOWN, ast_get_channel_by_name_prefix_locked(), AST_STATE_RINGING, and match().
00109 { 00110 struct ast_channel *chan; 00111 char match[AST_CHANNEL_NAME]; 00112 int res; 00113 00114 ast_copy_string(match, device, sizeof(match)-1); 00115 strcat(match, "-"); 00116 chan = ast_get_channel_by_name_prefix_locked(match, strlen(match)); 00117 00118 if (!chan) 00119 return AST_DEVICE_UNKNOWN; 00120 00121 if (chan->_state == AST_STATE_RINGING) 00122 res = AST_DEVICE_RINGING; 00123 else 00124 res = AST_DEVICE_INUSE; 00125 00126 ast_channel_unlock(chan); 00127 00128 return res; 00129 }
const char* devstate2str | ( | int | devstate | ) |
Convert device state to text string for output.
devstate | Current device state |
Definition at line 98 of file devicestate.c.
00099 { 00100 return devstatestring[devstate]; 00101 }