Clean up ast_device_state. It's pretty now!
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@53113 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
parent
8a889843ba
commit
880e319b7a
|
@ -226,10 +226,8 @@ int ast_device_state(const char *device)
|
||||||
|
|
||||||
buf = ast_strdupa(device);
|
buf = ast_strdupa(device);
|
||||||
tech = strsep(&buf, "/");
|
tech = strsep(&buf, "/");
|
||||||
number = buf;
|
if (!(number = buf)) {
|
||||||
if (!number) {
|
if (!(provider = strsep(&tech, ":")))
|
||||||
provider = strsep(&tech, ":");
|
|
||||||
if (!provider)
|
|
||||||
return AST_DEVICE_INVALID;
|
return AST_DEVICE_INVALID;
|
||||||
/* We have a provider */
|
/* We have a provider */
|
||||||
number = tech;
|
number = tech;
|
||||||
|
@ -241,29 +239,27 @@ int ast_device_state(const char *device)
|
||||||
ast_log(LOG_DEBUG, "Checking if I can find provider for \"%s\" - number: %s\n", provider, number);
|
ast_log(LOG_DEBUG, "Checking if I can find provider for \"%s\" - number: %s\n", provider, number);
|
||||||
return getproviderstate(provider, number);
|
return getproviderstate(provider, number);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (option_debug > 3)
|
if (option_debug > 3)
|
||||||
ast_log(LOG_DEBUG, "No provider found, checking channel drivers for %s - %s\n", tech, number);
|
ast_log(LOG_DEBUG, "No provider found, checking channel drivers for %s - %s\n", tech, number);
|
||||||
|
|
||||||
chan_tech = ast_get_channel_tech(tech);
|
if (!(chan_tech = ast_get_channel_tech(tech)))
|
||||||
if (!chan_tech)
|
|
||||||
return AST_DEVICE_INVALID;
|
return AST_DEVICE_INVALID;
|
||||||
|
|
||||||
if (!chan_tech->devicestate) /* Does the channel driver support device state notification? */
|
if (!(chan_tech->devicestate)) /* Does the channel driver support device state notification? */
|
||||||
return ast_parse_device_state(device); /* No, try the generic function */
|
return ast_parse_device_state(device); /* No, try the generic function */
|
||||||
else {
|
|
||||||
res = chan_tech->devicestate(number); /* Ask the channel driver for device state */
|
res = chan_tech->devicestate(number);
|
||||||
if (res == AST_DEVICE_UNKNOWN) {
|
|
||||||
res = ast_parse_device_state(device);
|
if (res != AST_DEVICE_UNKNOWN)
|
||||||
/* at this point we know the device exists, but the channel driver
|
return res;
|
||||||
could not give us a state; if there is no channel state available,
|
|
||||||
it must be 'not in use'
|
res = ast_parse_device_state(device);
|
||||||
*/
|
|
||||||
if (res == AST_DEVICE_UNKNOWN)
|
if (res == AST_DEVICE_UNKNOWN)
|
||||||
res = AST_DEVICE_NOT_INUSE;
|
return AST_DEVICE_NOT_INUSE;
|
||||||
return res;
|
|
||||||
} else
|
return res;
|
||||||
return res;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! \brief Add device state provider */
|
/*! \brief Add device state provider */
|
||||||
|
@ -389,8 +385,6 @@ static int __ast_device_state_changed_literal(char *buf)
|
||||||
if ((tmp = strrchr(device, '-')))
|
if ((tmp = strrchr(device, '-')))
|
||||||
*tmp = '\0';
|
*tmp = '\0';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (change_thread == AST_PTHREADT_NULL || !(change = ast_calloc(1, sizeof(*change) + strlen(device)))) {
|
if (change_thread == AST_PTHREADT_NULL || !(change = ast_calloc(1, sizeof(*change) + strlen(device)))) {
|
||||||
/* we could not allocate a change struct, or */
|
/* we could not allocate a change struct, or */
|
||||||
/* there is no background thread, so process the change now */
|
/* there is no background thread, so process the change now */
|
||||||
|
|
Loading…
Reference in New Issue