Index: devicestate.c =================================================================== RCS file: /usr/cvsroot/asterisk/devicestate.c,v retrieving revision 1.3 diff -u -r1.3 devicestate.c --- devicestate.c 10 Jul 2005 13:06:54 -0000 1.3 +++ devicestate.c 18 Jul 2005 15:10:53 -0000 @@ -27,6 +27,16 @@ #include "asterisk/pbx.h" #include "asterisk/options.h" +static char *devstatestring[] = { + /* 0 AST_DEVICE_UNKNOWN */ "Unknown", /* Valid, but unknown state */ + /* 1 AST_DEVICE_NOT_INUSE */ "Not in use", /* Not used */ + /* 2 AST_DEVICE IN USE */ "In use", /* In use */ + /* 3 AST_DEVICE_BUSY */ "Busy", /* Busy */ + /* 4 AST_DEVICE_INVALID */ "Invalid", /* Invalid - not known to Asterisk */ + /* 5 AST_DEVICE_UNAVAILABLE */ "Unavailable", /* Unavailable (not registred) */ + /* 6 AST_DEVICE_RINGING */ "Ringing" /* Ring, ring, ring */ +}; + /* ast_devstate_cb: A device state watcher (callback) */ struct devstate_cb { void *data; @@ -46,6 +56,13 @@ static pthread_t change_thread = AST_PTHREADT_NULL; static pthread_cond_t change_pending; +/*--- devstate2str: Find devicestate as text message for output */ +char *devstate2str(int devstate) +{ + return devstatestring[devstate]; +} + +/*--- ast_parse_device_state: Find out if device is active in a call or not */ int ast_parse_device_state(const char *device) { struct ast_channel *chan; @@ -69,6 +86,7 @@ return res; } +/*--- ast_device_state: Check device state through channel specific function or generic function */ int ast_device_state(const char *device) { char *buf; @@ -81,16 +99,16 @@ tech = strsep(&buf, "/"); number = buf; if (!number) - return AST_DEVICE_INVALID; + return AST_DEVICE_INVALID; chan_tech = ast_get_channel_tech(tech); if (!chan_tech) return AST_DEVICE_INVALID; - if (!chan_tech->devicestate) - return ast_parse_device_state(device); + 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); + res = chan_tech->devicestate(number); /* Ask the channel driver for device state */ if (res == AST_DEVICE_UNKNOWN) return ast_parse_device_state(device); else @@ -145,7 +163,7 @@ state = ast_device_state(device); if (option_debug > 2) - ast_log(LOG_DEBUG, "Changing state for %s - state %d\n", device, state); + ast_log(LOG_DEBUG, "Changing state for %s - state %d (%s)\n", device, state, devstate2str(state)); AST_LIST_LOCK(&devstate_cbs); AST_LIST_TRAVERSE(&devstate_cbs, devcb, list) @@ -155,6 +173,7 @@ ast_hint_state_changed(device); } +/*--- ast_device_state_changed: Accept change notification, add it to change queue */ int ast_device_state_changed(const char *fmt, ...) { char buf[AST_MAX_EXTENSION]; @@ -191,7 +210,8 @@ return 1; } -static void *do_changes(void *data) +/*--- do_devstate_changes: Go through the dev state change queue and update changes in the dev state thread */ +static void *do_devstate_changes(void *data) { struct state_change *cur; @@ -215,6 +235,7 @@ return NULL; } +/*--- ast_device_state_engine_init: Initialize the device state engine in separate thread */ int ast_device_state_engine_init(void) { pthread_attr_t attr; @@ -222,7 +243,7 @@ pthread_cond_init(&change_pending, NULL); pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); - if (ast_pthread_create(&change_thread, &attr, do_changes, NULL) < 0) { + if (ast_pthread_create(&change_thread, &attr, do_devstate_changes, NULL) < 0) { ast_log(LOG_ERROR, "Unable to start device state change thread.\n"); return -1; } Index: include/asterisk/devicestate.h =================================================================== RCS file: /usr/cvsroot/asterisk/include/asterisk/devicestate.h,v retrieving revision 1.1 diff -u -r1.1 devicestate.h --- include/asterisk/devicestate.h 8 Jul 2005 21:15:41 -0000 1.1 +++ include/asterisk/devicestate.h 18 Jul 2005 15:10:53 -0000 @@ -33,6 +33,10 @@ typedef int (*ast_devstate_cb_type)(const char *dev, int state, void *data); +/*! Convert device state to text string for output */ +/*! \param devstate Current device state */ +char *devstate2str(int devstate); + /*! Search the Channels by Name */ /*! * \param device like a dialstring Index: apps/app_queue.c =================================================================== RCS file: /usr/cvsroot/asterisk/apps/app_queue.c,v retrieving revision 1.150 diff -u -r1.150 app_queue.c --- apps/app_queue.c 13 Jul 2005 16:44:55 -0000 1.150 +++ apps/app_queue.c 18 Jul 2005 15:10:54 -0000 @@ -423,7 +423,7 @@ return NULL; } if (option_debug) - ast_log(LOG_DEBUG, "Device '%s/%s' changed to state '%d'\n", technology, loc, sc->state); + ast_log(LOG_DEBUG, "Device '%s/%s' changed to state '%d' (%s)\n", technology, loc, sc->state, devstate2str(sc->state)); ast_mutex_lock(&qlock); for (q = queues; q; q = q->next) { ast_mutex_lock(&q->lock); @@ -452,8 +452,6 @@ ast_mutex_unlock(&q->lock); } ast_mutex_unlock(&qlock); - if (option_debug) - ast_log(LOG_DEBUG, "Device '%s/%s' changed to state '%d'\n", technology, loc, sc->state); free(sc); return NULL; }