[asterisk-commits] russell: branch russell/events r73844 - /team/russell/events/main/devicestate.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sat Jul 7 22:00:57 CDT 2007


Author: russell
Date: Sat Jul  7 22:00:57 2007
New Revision: 73844

URL: http://svn.digium.com/view/asterisk?view=rev&rev=73844
Log:
Update the ast_device_state() function to check to see if the device state
is cached.  If so, use that instead of calling the devstate provider's callback
to retrieve it.

Modified:
    team/russell/events/main/devicestate.c

Modified: team/russell/events/main/devicestate.c
URL: http://svn.digium.com/view/asterisk/team/russell/events/main/devicestate.c?view=diff&rev=73844&r1=73843&r2=73844
==============================================================================
--- team/russell/events/main/devicestate.c (original)
+++ team/russell/events/main/devicestate.c Sat Jul  7 22:00:57 2007
@@ -25,6 +25,7 @@
  *
  *	\arg \ref AstExtState
  */
+
 /*! \page AstExtState Extension and device states in Asterisk
  *
  *	Asterisk has an internal system that reports states
@@ -261,18 +262,42 @@
 	return res;
 }
 
+static enum ast_device_state devstate_cached(const char *device)
+{
+	enum ast_device_state res = AST_DEVICE_UNKNOWN;
+	struct ast_event *event;
+
+	event = ast_event_get_cached(AST_EVENT_DEVICE_STATE,
+		AST_EVENT_IE_DEVICE, AST_EVENT_IE_PLTYPE_STR, device,
+		AST_EVENT_IE_END);
+
+	if (!event)
+		return res;
+
+	res = ast_event_get_ie_uint(event, AST_EVENT_IE_STATE);
+
+	ast_event_destroy(event);
+
+	return res;
+}
+
 /*! \brief Check device state through channel specific function or generic function */
 enum ast_device_state ast_device_state(const char *device)
 {
 	char *buf;
 	char *number;
 	const struct ast_channel_tech *chan_tech;
-	enum ast_device_state res = AST_DEVICE_UNKNOWN;
+	enum ast_device_state res;
 	/*! \brief Channel driver that provides device state */
 	char *tech;
 	/*! \brief Another provider of device state */
 	char *provider = NULL;
-	
+
+	/* If the last known state is cached, just return that */
+	res = devstate_cached(device);
+	if (res != AST_DEVICE_UNKNOWN)
+		return res;
+
 	buf = ast_strdupa(device);
 	tech = strsep(&buf, "/");
 	if (!(number = buf)) {




More information about the asterisk-commits mailing list