[asterisk-commits] file: branch file/usecnt-cleanup r54288 - in /team/file/usecnt-cleanup: ./ ap...

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Tue Feb 13 15:43:07 MST 2007


Author: file
Date: Tue Feb 13 16:43:06 2007
New Revision: 54288

URL: http://svn.digium.com/view/asterisk?view=rev&rev=54288
Log:
Merged revisions 54239,54260-54261 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/trunk

................
r54239 | russell | 2007-02-13 16:33:03 -0500 (Tue, 13 Feb 2007) | 10 lines

Merged revisions 54235 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.4

........
r54235 | russell | 2007-02-13 15:31:22 -0600 (Tue, 13 Feb 2007) | 2 lines

Remove a couple of leftover debug messages

........

................
r54260 | russell | 2007-02-13 16:57:31 -0500 (Tue, 13 Feb 2007) | 13 lines

Merged revisions 54204 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.4

........
r54204 | russell | 2007-02-13 13:42:00 -0600 (Tue, 13 Feb 2007) | 5 lines

If we fail to create the SIP socket, then return -1 from reload_config() so
that load_module() will return AST_MODULE_LOAD_DECLINE.  Otherwise, the console
will just get spammed with error messages every time chan_sip tries to send a
message.

........

................
r54261 | russell | 2007-02-13 17:02:20 -0500 (Tue, 13 Feb 2007) | 13 lines

This introduces a new dialplan function, DEVSTATE, which allows you to do some
pretty cool things.

First, you can get the device state of anything in the dialplan:
  NoOp(SIP/mypeer has state ${DEVSTATE(SIP/mypeer)})
  NoOp(The conference room 1234 has state ${DEVSTATE(MeetMe:1234)})

Most importantly, this allows you to create custom device states so you can
control phone lamps directly from the dialplan.
  Set(DEVSTATE(Custom:mycustomlamp)=BUSY)
  ...
  exten => mycustomlamp,hint,Custom:mycustomlamp

................

Added:
    team/file/usecnt-cleanup/funcs/func_devstate.c
      - copied, changed from r54261, trunk/funcs/func_devstate.c
Modified:
    team/file/usecnt-cleanup/   (props changed)
    team/file/usecnt-cleanup/CHANGES
    team/file/usecnt-cleanup/apps/app_meetme.c
    team/file/usecnt-cleanup/apps/app_queue.c
    team/file/usecnt-cleanup/channels/chan_sip.c
    team/file/usecnt-cleanup/include/asterisk/cli.h
    team/file/usecnt-cleanup/include/asterisk/devicestate.h
    team/file/usecnt-cleanup/main/cli.c
    team/file/usecnt-cleanup/main/devicestate.c
    team/file/usecnt-cleanup/res/res_features.c

Propchange: team/file/usecnt-cleanup/
------------------------------------------------------------------------------
    automerge = *

Propchange: team/file/usecnt-cleanup/
------------------------------------------------------------------------------
Binary property 'branch-1.4-merged' - no diff available.

Propchange: team/file/usecnt-cleanup/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Tue Feb 13 16:43:06 2007
@@ -1,1 +1,1 @@
-/trunk:1-54225
+/trunk:1-54287

Modified: team/file/usecnt-cleanup/CHANGES
URL: http://svn.digium.com/view/asterisk/team/file/usecnt-cleanup/CHANGES?view=diff&rev=54288&r1=54287&r2=54288
==============================================================================
--- team/file/usecnt-cleanup/CHANGES (original)
+++ team/file/usecnt-cleanup/CHANGES Tue Feb 13 16:43:06 2007
@@ -68,6 +68,9 @@
   * Added 'E' and 'V' commands to ExternalIVR.
   * Added 'DBDel' and 'DBDelTree' manager commands.
   * Added 'core show channels count' CLI command.
+  * Added the DEVSTATE() dialplan function which allows retrieving any device
+    state in the dialplan, as well as creating custom device states that are
+	controllable from the dialplan.
 
 SIP changes
 -----------

Modified: team/file/usecnt-cleanup/apps/app_meetme.c
URL: http://svn.digium.com/view/asterisk/team/file/usecnt-cleanup/apps/app_meetme.c?view=diff&rev=54288&r1=54287&r2=54288
==============================================================================
--- team/file/usecnt-cleanup/apps/app_meetme.c (original)
+++ team/file/usecnt-cleanup/apps/app_meetme.c Tue Feb 13 16:43:06 2007
@@ -2850,7 +2850,7 @@
 }
 
 /*! \brief Callback for devicestate providers */
-static int meetmestate(const char *data)
+static enum ast_device_state meetmestate(const char *data)
 {
 	struct ast_conference *conf;
 
@@ -3523,12 +3523,12 @@
 	return 0;
 }
 
-static int sla_state(const char *data)
+static enum ast_device_state sla_state(const char *data)
 {
 	char *buf, *station_name, *trunk_name;
 	struct sla_station *station;
 	struct sla_trunk_ref *trunk_ref;
-	int res = AST_DEVICE_INVALID;
+	enum ast_device_state res = AST_DEVICE_INVALID;
 
 	trunk_name = buf = ast_strdupa(data);
 	station_name = strsep(&trunk_name, "_");

Modified: team/file/usecnt-cleanup/apps/app_queue.c
URL: http://svn.digium.com/view/asterisk/team/file/usecnt-cleanup/apps/app_queue.c?view=diff&rev=54288&r1=54287&r2=54288
==============================================================================
--- team/file/usecnt-cleanup/apps/app_queue.c (original)
+++ team/file/usecnt-cleanup/apps/app_queue.c Tue Feb 13 16:43:06 2007
@@ -612,7 +612,7 @@
 	return NULL;
 }
 
-static int statechange_queue(const char *dev, int state, void *ign)
+static int statechange_queue(const char *dev, enum ast_device_state state, void *ign)
 {
 	/* Avoid potential for deadlocks by spawning a new thread to handle
 	   the event */

Modified: team/file/usecnt-cleanup/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/file/usecnt-cleanup/channels/chan_sip.c?view=diff&rev=54288&r1=54287&r2=54288
==============================================================================
--- team/file/usecnt-cleanup/channels/chan_sip.c (original)
+++ team/file/usecnt-cleanup/channels/chan_sip.c Tue Feb 13 16:43:06 2007
@@ -5410,14 +5410,10 @@
 	}
 	
 	if (sin.sin_addr.s_addr && !sendonly) {
-		if (option_debug > 1)
-			ast_log(LOG_DEBUG, "Setting call off HOLD! - %s\n", p->callid);
 		ast_queue_control(p->owner, AST_CONTROL_UNHOLD);
 		/* Activate a re-invite */
 		ast_queue_frame(p->owner, &ast_null_frame);
 	} else if (!sin.sin_addr.s_addr || sendonly) {
-		if (option_debug > 1)
-			ast_log(LOG_DEBUG, "Setting call on HOLD! - %s\n", p->callid);
 		ast_queue_control_data(p->owner, AST_CONTROL_HOLD, 
 				       S_OR(p->mohsuggest, NULL),
 				       !ast_strlen_zero(p->mohsuggest) ? strlen(p->mohsuggest) + 1 : 0);
@@ -16884,6 +16880,7 @@
 		sipsock = socket(AF_INET, SOCK_DGRAM, 0);
 		if (sipsock < 0) {
 			ast_log(LOG_WARNING, "Unable to create SIP socket: %s\n", strerror(errno));
+			return -1;
 		} else {
 			/* Allow SIP clients on the same host to access us: */
 			const int reuseFlag = 1;

Copied: team/file/usecnt-cleanup/funcs/func_devstate.c (from r54261, trunk/funcs/func_devstate.c)
URL: http://svn.digium.com/view/asterisk/team/file/usecnt-cleanup/funcs/func_devstate.c?view=diff&rev=54288&p1=trunk/funcs/func_devstate.c&r1=54261&p2=team/file/usecnt-cleanup/funcs/func_devstate.c&r2=54288
==============================================================================
--- trunk/funcs/func_devstate.c (original)
+++ team/file/usecnt-cleanup/funcs/func_devstate.c Tue Feb 13 16:43:06 2007
@@ -195,7 +195,7 @@
 {
 	int res = 0;
 
-	res |= ast_custom_function_register(&devstate_function);
+	res |= ast_custom_function_register(&devstate_function, ast_module_info->self);
 	res |= ast_devstate_prov_add("Custom", custom_devstate_callback);
 	res |= ast_cli_register_multiple(cli_funcdevstate, ARRAY_LEN(cli_funcdevstate));
 

Modified: team/file/usecnt-cleanup/include/asterisk/cli.h
URL: http://svn.digium.com/view/asterisk/team/file/usecnt-cleanup/include/asterisk/cli.h?view=diff&rev=54288&r1=54287&r2=54288
==============================================================================
--- team/file/usecnt-cleanup/include/asterisk/cli.h (original)
+++ team/file/usecnt-cleanup/include/asterisk/cli.h Tue Feb 13 16:43:06 2007
@@ -236,7 +236,7 @@
  * \param len number of entries to register
  */
 #define ast_cli_register_multiple(a,b) __ast_cli_register_multiple(a, b, ast_module_info->self)
-void __ast_cli_register_multiple(struct ast_cli_entry *e, int len, struct ast_module *mod);
+int __ast_cli_register_multiple(struct ast_cli_entry *e, int len, struct ast_module *mod);
 
 /*! \brief Unregisters a command or an array of commands
  *
@@ -251,7 +251,7 @@
  * \param e pointer to first cli entry to unregister
  * \param len number of entries to unregister
  */
-void ast_cli_unregister_multiple(struct ast_cli_entry *e, int len);
+int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len);
 
 /*! \brief Readline madness
  * Useful for readline, that's about it

Modified: team/file/usecnt-cleanup/include/asterisk/devicestate.h
URL: http://svn.digium.com/view/asterisk/team/file/usecnt-cleanup/include/asterisk/devicestate.h?view=diff&rev=54288&r1=54287&r2=54288
==============================================================================
--- team/file/usecnt-cleanup/include/asterisk/devicestate.h (original)
+++ team/file/usecnt-cleanup/include/asterisk/devicestate.h Tue Feb 13 16:43:06 2007
@@ -28,29 +28,42 @@
 #if defined(__cplusplus) || defined(c_plusplus)
 extern "C" {
 #endif
-/*! @name DeviceStates */
-/*! \@{ */
-#define AST_DEVICE_UNKNOWN	0 /*!< Device is valid but channel didn't know state */
-#define AST_DEVICE_NOT_INUSE	1 /*!< Device is not used */
-#define AST_DEVICE_INUSE	2 /*!< Device is in use */
-#define AST_DEVICE_BUSY		3 /*!< Device is busy */
-#define AST_DEVICE_INVALID	4 /*!< Device is invalid */
-#define AST_DEVICE_UNAVAILABLE	5 /*!< Device is unavailable */
-#define AST_DEVICE_RINGING	6 /*!< Device is ringing */
-#define AST_DEVICE_RINGINUSE	7 /*!< Device is ringing *and* in use */
-#define AST_DEVICE_ONHOLD	8 /*!< Device is on hold */
-/*! \@} */
+
+/*! Device States */
+enum ast_device_state {
+	AST_DEVICE_UNKNOWN,      /*!< Device is valid but channel didn't know state */
+	AST_DEVICE_NOT_INUSE,    /*!< Device is not used */
+	AST_DEVICE_INUSE,        /*!< Device is in use */
+	AST_DEVICE_BUSY,         /*!< Device is busy */
+	AST_DEVICE_INVALID,      /*!< Device is invalid */
+	AST_DEVICE_UNAVAILABLE,  /*!< Device is unavailable */
+	AST_DEVICE_RINGING,      /*!< Device is ringing */
+	AST_DEVICE_RINGINUSE,    /*!< Device is ringing *and* in use */
+	AST_DEVICE_ONHOLD,       /*!< Device is on hold */
+};
 
 /*! \brief Devicestate watcher call back */
-typedef int (*ast_devstate_cb_type)(const char *dev, int state, void *data);
+typedef int (*ast_devstate_cb_type)(const char *dev, enum ast_device_state state, void *data);
 
 /*!  \brief Devicestate provider call back */
-typedef int (*ast_devstate_prov_cb_type)(const char *data);
+typedef enum ast_device_state (*ast_devstate_prov_cb_type)(const char *data);
 
 /*! \brief Convert device state to text string for output 
  * \param devstate Current device state 
  */
-const char *devstate2str(int devstate);
+const char *devstate2str(enum ast_device_state devstate);
+
+/*! \brief Convert device state to text string that is easier to parse 
+ * \param devstate Current device state 
+ */
+const char *ast_devstate_str(enum ast_device_state devstate);
+
+/*! \brief Convert device state from text to integer value
+ * \param The text representing the device state.  Valid values are anything
+ *        that comes after AST_DEVICE_ in one of the defined values.
+ * \return The AST_DEVICE_ integer value
+ */
+enum ast_device_state ast_devstate_val(const char *val);
 
 /*! \brief Search the Channels by Name
  * \param device like a dialstring
@@ -59,7 +72,7 @@
  * Returns an AST_DEVICE_UNKNOWN if no channel found or
  * AST_DEVICE_INUSE if a channel is found
  */
-int ast_parse_device_state(const char *device);
+enum ast_device_state ast_parse_device_state(const char *device);
 
 /*! \brief Asks a channel for device state
  * \param device like a dialstring
@@ -69,7 +82,7 @@
  * active channels list for the device.
  * Returns an AST_DEVICE_??? state -1 on failure
  */
-int ast_device_state(const char *device);
+enum ast_device_state ast_device_state(const char *device);
 
 /*! \brief Tells Asterisk the State for Device is changed
  * \param fmt devicename like a dialstring with format parameters
@@ -115,9 +128,9 @@
 
 /*! \brief Remove device state provider 
  * \param label to use in hint, like label:object
- * \return nothing
+ * Return -1 on failure, 0 on success
  */ 
-void ast_devstate_prov_del(const char *label);
+int ast_devstate_prov_del(const char *label);
 
 int ast_device_state_engine_init(void);
 

Modified: team/file/usecnt-cleanup/main/cli.c
URL: http://svn.digium.com/view/asterisk/team/file/usecnt-cleanup/main/cli.c?view=diff&rev=54288&r1=54287&r2=54288
==============================================================================
--- team/file/usecnt-cleanup/main/cli.c (original)
+++ team/file/usecnt-cleanup/main/cli.c Tue Feb 13 16:43:06 2007
@@ -1355,20 +1355,24 @@
 /*
  * register/unregister an array of entries.
  */
-void __ast_cli_register_multiple(struct ast_cli_entry *e, int len, struct ast_module *mod)
-{
-	int i;
+int __ast_cli_register_multiple(struct ast_cli_entry *e, int len, struct ast_module *mod)
+{
+	int i, res = 0;
 
 	for (i = 0; i < len; i++)
-		__ast_cli_register(e + i, mod);
-}
-
-void ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
-{
-	int i;
+		res |= __ast_cli_register(e + i, mod);
+
+	return res;
+}
+
+int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
+{
+	int i, res = 0;
 
 	for (i = 0; i < len; i++)
-		ast_cli_unregister(e + i);
+		res |= ast_cli_unregister(e + i);
+
+	return res;
 }
 
 

Modified: team/file/usecnt-cleanup/main/devicestate.c
URL: http://svn.digium.com/view/asterisk/team/file/usecnt-cleanup/main/devicestate.c?view=diff&rev=54288&r1=54287&r2=54288
==============================================================================
--- team/file/usecnt-cleanup/main/devicestate.c (original)
+++ team/file/usecnt-cleanup/main/devicestate.c Tue Feb 13 16:43:06 2007
@@ -179,9 +179,67 @@
 static int getproviderstate(const char *provider, const char *address);
 
 /*! \brief Find devicestate as text message for output */
-const char *devstate2str(int devstate) 
+const char *devstate2str(enum ast_device_state devstate) 
 {
 	return devstatestring[devstate];
+}
+
+const char *ast_devstate_str(enum ast_device_state state)
+{
+	const char *res = "UNKNOWN";
+
+	switch (state) {
+	case AST_DEVICE_UNKNOWN:
+		break;
+	case AST_DEVICE_NOT_INUSE:
+		res = "NOT_INUSE";
+		break;
+	case AST_DEVICE_INUSE:
+		res = "INUSE";
+		break;
+	case AST_DEVICE_BUSY:
+		res = "BUSY";
+		break;
+	case AST_DEVICE_INVALID:
+		res = "INVALID";
+		break;
+	case AST_DEVICE_UNAVAILABLE:
+		res = "UNAVAILABLE";
+		break;
+	case AST_DEVICE_RINGING:
+		res = "RINGING";
+		break;
+	case AST_DEVICE_RINGINUSE:
+		res = "RINGINUSE";
+		break;
+	case AST_DEVICE_ONHOLD:
+		res = "ONHOLD";
+		break;
+	}
+
+	return res;
+}
+
+enum ast_device_state ast_devstate_val(const char *val)
+{
+	if (!strcasecmp(val, "NOT_INUSE"))
+		return AST_DEVICE_NOT_INUSE;
+	else if (!strcasecmp(val, "INUSE"))
+		return AST_DEVICE_INUSE;
+	else if (!strcasecmp(val, "BUSY"))
+		return AST_DEVICE_BUSY;
+	else if (!strcasecmp(val, "INVALID"))
+		return AST_DEVICE_INVALID;
+	else if (!strcasecmp(val, "UNAVAILABLE"))
+		return AST_DEVICE_UNAVAILABLE;
+	else if (!strcasecmp(val, "RINGING"))
+		return AST_DEVICE_RINGING;
+	else if (!strcasecmp(val, "RINGINUSE"))
+		return AST_DEVICE_RINGINUSE;
+	else if (!strcasecmp(val, "ONHOLD"))
+		return AST_DEVICE_ONHOLD;
+
+	return AST_DEVICE_UNKNOWN;
 }
 
 /*! \brief Find out if device is active in a call or not 
@@ -189,11 +247,11 @@
 	This function is only used for channels that does not implement 
 	devicestate natively
 */
-int ast_parse_device_state(const char *device)
+enum ast_device_state ast_parse_device_state(const char *device)
 {
 	struct ast_channel *chan;
 	char match[AST_CHANNEL_NAME];
-	int res;
+	enum ast_device_state res;
 
 	ast_copy_string(match, device, sizeof(match)-1);
 	strcat(match, "-");
@@ -213,12 +271,12 @@
 }
 
 /*! \brief Check device state through channel specific function or generic function */
-int ast_device_state(const char *device)
+enum ast_device_state ast_device_state(const char *device)
 {
 	char *buf;
 	char *number;
 	const struct ast_channel_tech *chan_tech;
-	int res = 0;
+	enum ast_device_state res = AST_DEVICE_UNKNOWN;
 	/*! \brief Channel driver that provides device state */
 	char *tech;
 	/*! \brief Another provider of device state */
@@ -281,20 +339,24 @@
 }
 
 /*! \brief Remove device state provider */
-void ast_devstate_prov_del(const char *label)
+int ast_devstate_prov_del(const char *label)
 {
 	struct devstate_prov *devcb;
+	int res = -1;
 
 	AST_RWLIST_WRLOCK(&devstate_provs);
 	AST_RWLIST_TRAVERSE_SAFE_BEGIN(&devstate_provs, devcb, list) {
 		if (!strcasecmp(devcb->label, label)) {
 			AST_RWLIST_REMOVE_CURRENT(&devstate_provs, list);
 			free(devcb);
+			res = 0;
 			break;
 		}
 	}
 	AST_RWLIST_TRAVERSE_SAFE_END;
 	AST_RWLIST_UNLOCK(&devstate_provs);
+
+	return res;
 }
 
 /*! \brief Get provider device state */

Modified: team/file/usecnt-cleanup/res/res_features.c
URL: http://svn.digium.com/view/asterisk/team/file/usecnt-cleanup/res/res_features.c?view=diff&rev=54288&r1=54287&r2=54288
==============================================================================
--- team/file/usecnt-cleanup/res/res_features.c (original)
+++ team/file/usecnt-cleanup/res/res_features.c Tue Feb 13 16:43:06 2007
@@ -284,9 +284,9 @@
 }
 
 /*! \brief metermaids callback from devicestate.c */
-static int metermaidstate(const char *data)
-{
-	int res = AST_DEVICE_INVALID;
+static enum ast_device_state metermaidstate(const char *data)
+{
+	enum ast_device_state res = AST_DEVICE_INVALID;
 	char *context = ast_strdupa(data);
 	char *exten;
 
@@ -299,7 +299,7 @@
 
 	res = ast_exists_extension(NULL, context, exten, 1, NULL);
 
-	if (!res)
+	if (res == AST_DEVICE_UNKNOWN)
 		return AST_DEVICE_NOT_INUSE;
 	else
 		return AST_DEVICE_INUSE;



More information about the asterisk-commits mailing list