mirror of
https://github.com/asterisk/asterisk.git
synced 2025-10-13 00:04:53 +00:00
devicestate.c: Simplified some logic in _ast_device_state().
git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/12@409274 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -297,14 +297,11 @@ static enum ast_device_state devstate_cached(const char *device)
|
|||||||
/*! \brief Check device state through channel specific function or generic function */
|
/*! \brief Check device state through channel specific function or generic function */
|
||||||
static enum ast_device_state _ast_device_state(const char *device, int check_cache)
|
static enum ast_device_state _ast_device_state(const char *device, int check_cache)
|
||||||
{
|
{
|
||||||
char *buf;
|
|
||||||
char *number;
|
char *number;
|
||||||
const struct ast_channel_tech *chan_tech;
|
const struct ast_channel_tech *chan_tech;
|
||||||
enum ast_device_state res;
|
enum ast_device_state res;
|
||||||
/*! \brief Channel driver that provides device state */
|
/*! \brief Channel driver that provides device state */
|
||||||
char *tech;
|
char *tech;
|
||||||
/*! \brief Another provider of device state */
|
|
||||||
char *provider = NULL;
|
|
||||||
|
|
||||||
/* If the last known state is cached, just return that */
|
/* If the last known state is cached, just return that */
|
||||||
if (check_cache) {
|
if (check_cache) {
|
||||||
@@ -314,16 +311,18 @@ static enum ast_device_state _ast_device_state(const char *device, int check_cac
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
buf = ast_strdupa(device);
|
number = ast_strdupa(device);
|
||||||
tech = strsep(&buf, "/");
|
tech = strsep(&number, "/");
|
||||||
if (!(number = buf)) {
|
if (!number) {
|
||||||
|
/*! \brief Another provider of device state */
|
||||||
|
char *provider;
|
||||||
|
|
||||||
provider = strsep(&tech, ":");
|
provider = strsep(&tech, ":");
|
||||||
if (!tech) {
|
if (!tech) {
|
||||||
return AST_DEVICE_INVALID;
|
return AST_DEVICE_INVALID;
|
||||||
}
|
}
|
||||||
/* We have a provider */
|
/* We have a provider */
|
||||||
number = tech;
|
number = tech;
|
||||||
tech = NULL;
|
|
||||||
|
|
||||||
ast_debug(3, "Checking if I can find provider for \"%s\" - number: %s\n", provider, number);
|
ast_debug(3, "Checking if I can find provider for \"%s\" - number: %s\n", provider, number);
|
||||||
return getproviderstate(provider, number);
|
return getproviderstate(provider, number);
|
||||||
@@ -331,18 +330,21 @@ static enum ast_device_state _ast_device_state(const char *device, int check_cac
|
|||||||
|
|
||||||
ast_debug(4, "No provider found, checking channel drivers for %s - %s\n", tech, number);
|
ast_debug(4, "No provider found, checking channel drivers for %s - %s\n", tech, number);
|
||||||
|
|
||||||
if (!(chan_tech = ast_get_channel_tech(tech)))
|
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? */
|
/* Does the channel driver support device state notification? */
|
||||||
return ast_parse_device_state(device); /* No, try the generic function */
|
if (!chan_tech->devicestate) {
|
||||||
|
/* No, try the generic function */
|
||||||
|
return ast_parse_device_state(device);
|
||||||
|
}
|
||||||
|
|
||||||
res = chan_tech->devicestate(number);
|
res = chan_tech->devicestate(number);
|
||||||
|
if (res == AST_DEVICE_UNKNOWN) {
|
||||||
if (res != AST_DEVICE_UNKNOWN)
|
res = ast_parse_device_state(device);
|
||||||
return res;
|
}
|
||||||
|
|
||||||
res = ast_parse_device_state(device);
|
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user