[asterisk-commits] tilghman: branch tilghman/compiler_attributes r133809 - in /team/tilghman/com...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Jul 25 15:21:46 CDT 2008


Author: tilghman
Date: Fri Jul 25 15:21:45 2008
New Revision: 133809

URL: http://svn.digium.com/view/asterisk?view=rev&rev=133809
Log:
Draw a mapping for channel states to the closest devstate

Modified:
    team/tilghman/compiler_attributes/include/asterisk/devicestate.h
    team/tilghman/compiler_attributes/main/channel.c
    team/tilghman/compiler_attributes/main/devicestate.c

Modified: team/tilghman/compiler_attributes/include/asterisk/devicestate.h
URL: http://svn.digium.com/view/asterisk/team/tilghman/compiler_attributes/include/asterisk/devicestate.h?view=diff&rev=133809&r1=133808&r2=133809
==============================================================================
--- team/tilghman/compiler_attributes/include/asterisk/devicestate.h (original)
+++ team/tilghman/compiler_attributes/include/asterisk/devicestate.h Fri Jul 25 15:21:45 2008
@@ -61,6 +61,13 @@
 /*! \brief Devicestate provider call back */
 typedef enum ast_device_state (*ast_devstate_prov_cb_type)(const char *data);
 
+/*!
+ * \brief Convert channel state to devicestate
+ *
+ * \param chanstate Current channel state
+ */
+enum ast_device_state ast_state_chan2dev(enum ast_channel_state chanstate);
+
 /*! 
  * \brief Convert device state to text string for output 
  *

Modified: team/tilghman/compiler_attributes/main/channel.c
URL: http://svn.digium.com/view/asterisk/team/tilghman/compiler_attributes/main/channel.c?view=diff&rev=133809&r1=133808&r2=133809
==============================================================================
--- team/tilghman/compiler_attributes/main/channel.c (original)
+++ team/tilghman/compiler_attributes/main/channel.c Fri Jul 25 15:21:45 2008
@@ -4100,7 +4100,7 @@
 	}
 
 	chan->_state = state;
-	ast_devstate_changed(state == AST_STATE_DOWN ? AST_DEVICE_NOT_INUSE : AST_DEVICE_INUSE, "%s", name);
+	ast_devstate_changed(ast_state_chan2dev(state), "%s", name);
 	/* setstate used to conditionally report Newchannel; this is no more */
 	manager_event(EVENT_FLAG_CALL,
 		      "Newstate",

Modified: team/tilghman/compiler_attributes/main/devicestate.c
URL: http://svn.digium.com/view/asterisk/team/tilghman/compiler_attributes/main/devicestate.c?view=diff&rev=133809&r1=133808&r2=133809
==============================================================================
--- team/tilghman/compiler_attributes/main/devicestate.c (original)
+++ team/tilghman/compiler_attributes/main/devicestate.c Fri Jul 25 15:21:45 2008
@@ -140,6 +140,24 @@
 	/* 8 AST_DEVICE_ONHOLD */	"On Hold"	/*!< On Hold */
 };
 
+/*!\brief Mapping for channel states to device states */
+static const struct chan2dev {
+	enum ast_channel_state chan;
+	enum ast_device_state dev;
+} chan2dev[] = {
+	{ AST_STATE_DOWN,            AST_DEVICE_NOT_INUSE },
+	{ AST_STATE_RESERVED,        AST_DEVICE_INUSE },
+	{ AST_STATE_OFFHOOK,         AST_DEVICE_INUSE },
+	{ AST_STATE_DIALING,         AST_DEVICE_INUSE },
+	{ AST_STATE_RING,            AST_DEVICE_INUSE },
+	{ AST_STATE_RINGING,         AST_DEVICE_RINGING },
+	{ AST_STATE_UP,              AST_DEVICE_INUSE },
+	{ AST_STATE_BUSY,            AST_DEVICE_BUSY },
+	{ AST_STATE_DIALING_OFFHOOK, AST_DEVICE_INUSE },
+	{ AST_STATE_PRERING,         AST_DEVICE_RINGING },
+	{ NULL,                      NULL },
+};
+
 /*! \brief  A device state provider (not a channel) */
 struct devstate_prov {
 	char label[40];
@@ -200,6 +218,18 @@
 const char *devstate2str(enum ast_device_state devstate) 
 {
 	return devstatestring[devstate];
+}
+
+enum ast_device_state ast_state_chan2dev(enum ast_channel_state chanstate)
+{
+	int i;
+	chanstate &= 0xFFFF;
+	for (i = 0; chan2dev[i].chan != NULL; i++) {
+		if (chan2dev[i].chan == chanstate) {
+			return chan2dev[i].dev;
+		}
+	}
+	return AST_DEVICE_UNKNOWN;
 }
 
 const char *ast_devstate_str(enum ast_device_state state)




More information about the asterisk-commits mailing list