aboutsummaryrefslogtreecommitdiffstats
path: root/main/devicestate.c
diff options
context:
space:
mode:
authorfile <file@f38db490-d61c-443f-a65b-d21fe96a405b>2007-02-02 00:58:09 +0000
committerfile <file@f38db490-d61c-443f-a65b-d21fe96a405b>2007-02-02 00:58:09 +0000
commitcad66eb8cbbb7ba1c42f3cc995eb0837fa8dd579 (patch)
tree88ad41697229936560efa2abc42f5e7805287ad9 /main/devicestate.c
parent440f1b53340b23f519833d443c30d6f404b9c418 (diff)
Clean up ast_device_state. It's pretty now!
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@53113 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'main/devicestate.c')
-rw-r--r--main/devicestate.c42
1 files changed, 18 insertions, 24 deletions
diff --git a/main/devicestate.c b/main/devicestate.c
index 74227a064..3715b60cc 100644
--- a/main/devicestate.c
+++ b/main/devicestate.c
@@ -226,10 +226,8 @@ int ast_device_state(const char *device)
buf = ast_strdupa(device);
tech = strsep(&buf, "/");
- number = buf;
- if (!number) {
- provider = strsep(&tech, ":");
- if (!provider)
+ if (!(number = buf)) {
+ if (!(provider = strsep(&tech, ":")))
return AST_DEVICE_INVALID;
/* We have a provider */
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);
return getproviderstate(provider, number);
}
+
if (option_debug > 3)
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)
+ if (!(chan_tech = ast_get_channel_tech(tech)))
return AST_DEVICE_INVALID;
- if (!chan_tech->devicestate) /* Does the channel driver support device state notification? */
- return ast_parse_device_state(device); /* No, try the generic function */
- else {
- res = chan_tech->devicestate(number); /* Ask the channel driver for device state */
- if (res == AST_DEVICE_UNKNOWN) {
- res = ast_parse_device_state(device);
- /* at this point we know the device exists, but the channel driver
- could not give us a state; if there is no channel state available,
- it must be 'not in use'
- */
- if (res == AST_DEVICE_UNKNOWN)
- res = AST_DEVICE_NOT_INUSE;
- return res;
- } else
- return res;
- }
+ if (!(chan_tech->devicestate)) /* Does the channel driver support device state notification? */
+ return ast_parse_device_state(device); /* No, try the generic function */
+
+ res = chan_tech->devicestate(number);
+
+ if (res != AST_DEVICE_UNKNOWN)
+ return res;
+
+ res = ast_parse_device_state(device);
+
+ if (res == AST_DEVICE_UNKNOWN)
+ return AST_DEVICE_NOT_INUSE;
+
+ return res;
}
/*! \brief Add device state provider */
@@ -389,8 +385,6 @@ static int __ast_device_state_changed_literal(char *buf)
if ((tmp = strrchr(device, '-')))
*tmp = '\0';
-
-
if (change_thread == AST_PTHREADT_NULL || !(change = ast_calloc(1, sizeof(*change) + strlen(device)))) {
/* we could not allocate a change struct, or */
/* there is no background thread, so process the change now */