[asterisk-commits] russell: branch russell/smdi-1.4 r93117 - /team/russell/smdi-1.4/res/res_smdi.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Dec 14 16:46:51 CST 2007


Author: russell
Date: Fri Dec 14 16:46:50 2007
New Revision: 93117

URL: http://svn.digium.com/view/asterisk?view=rev&rev=93117
Log:
Finish SMDI_MSG_RETRIEVE() ... leave a note by smdi_msg_wait() for the next
change i need to make there for it to work properly

Modified:
    team/russell/smdi-1.4/res/res_smdi.c

Modified: team/russell/smdi-1.4/res/res_smdi.c
URL: http://svn.digium.com/view/asterisk/team/russell/smdi-1.4/res/res_smdi.c?view=diff&rev=93117&r1=93116&r2=93117
==============================================================================
--- team/russell/smdi-1.4/res/res_smdi.c (original)
+++ team/russell/smdi-1.4/res/res_smdi.c Fri Dec 14 16:46:50 2007
@@ -1,9 +1,10 @@
 /*
  * Asterisk -- A telephony toolkit for Linux.
  *
- * Copyright (C) 2005-2006, Digium, Inc.
+ * Copyright (C) 2005-2007, Digium, Inc.
  *
  * Matthew A. Nicholson <mnicholson at digium.com>
+ * Russell Bryant <russell at digium.com>
  *
  * See http://www.asterisk.org for more information about
  * the Asterisk project. Please do not directly contact
@@ -20,6 +21,7 @@
  * \file
  * \brief SMDI support for Asterisk.
  * \author Matthew A. Nicholson <mnicholson at digium.com>
+ * \author Russell Bryant <russell at digium.com>
  */
 
 #include "asterisk.h"
@@ -343,7 +345,12 @@
 	return msg;
 }
 
-static void *smdi_message_wait(struct ast_smdi_interface *iface, int timeout, enum smdi_message_type type)
+/*!
+ * \todo XXX Make use of the terminal argument to allow waiting for a message
+ * for a specific terminal.
+ */
+static void *smdi_message_wait(struct ast_smdi_interface *iface, int timeout, 
+	enum smdi_message_type type, const char *terminal)
 {
 	struct timeval start;
 	long diff = 0;
@@ -415,7 +422,7 @@
  */
 struct ast_smdi_md_message *ast_smdi_md_message_wait(struct ast_smdi_interface *iface, int timeout)
 {
-	return smdi_message_wait(iface, timeout, SMDI_MD);
+	return smdi_message_wait(iface, timeout, SMDI_MD, NULL);
 }
 
 /*!
@@ -447,7 +454,7 @@
  */
 extern struct ast_smdi_mwi_message *ast_smdi_mwi_message_wait(struct ast_smdi_interface *iface, int timeout)
 {
-	return smdi_message_wait(iface, timeout, SMDI_MWI);
+	return smdi_message_wait(iface, timeout, SMDI_MWI, NULL);
 }
 
 /*!
@@ -1028,8 +1035,8 @@
 
 static int smdi_msg_id;
 
-/*! In seconds */
-#define SMDI_RETRIEVE_TIMEOUT_DEFAULT 3
+/*! In milliseconds */
+#define SMDI_RETRIEVE_TIMEOUT_DEFAULT 3000
 
 static int smdi_msg_retrieve_read(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
 {
@@ -1045,6 +1052,7 @@
 	struct smdi_msg_datastore *smd = NULL;
 	struct ast_datastore *datastore = NULL;
 	struct ast_smdi_interface *iface = NULL;
+	struct ast_smdi_md_message *md_msg = NULL;
 
 	u = ast_module_user_add(chan);
 
@@ -1080,12 +1088,17 @@
 		}
 	}
 
-	/* XXX get message here */
+	if (!(md_msg = smdi_message_wait(iface, timeout, SMDI_MD, args.terminal))) {
+		ast_log(LOG_WARNING, "No SMDI message retrieved for terminal '%s' after "
+			"waiting %u ms.\n", args.terminal, timeout);
+		goto return_error;
+	}
 
 	if (!(smd = ast_calloc(1, sizeof(*smd))))
 		goto return_error;
 
 	smd->iface = ASTOBJ_REF(iface);
+	smd->md_msg = ASTOBJ_REF(md_msg);
 	smd->id = ast_atomic_fetchadd_int((int *) &smdi_msg_id, 1);
 	snprintf(buf, len, "%u", smd->id);
 
@@ -1102,7 +1115,10 @@
 
 return_error:
 	if (iface)
-		ASTOBJ_UNREF(iface,ast_smdi_interface_destroy);
+		ASTOBJ_UNREF(iface, ast_smdi_interface_destroy);
+
+	if (md_msg)
+		ASTOBJ_UNREF(md_msg, ast_smdi_md_message_destroy);
 
 	if (smd && !datastore)
 		smdi_msg_datastore_destroy(smd);
@@ -1139,7 +1155,7 @@
 	"once an SMDI message is retrieved using this function, it is no longer in\n"
 	"the global SMDI message queue, and can not be accessed by any other Asterisk\n"
 	"channels.  The timeout for this function is optional, and the default is\n"
-	"3 seconds.\n"
+	"3 seconds.  When providing a timeout, it should be in milliseconds.\n"
 	"",
 	.read = smdi_msg_retrieve_read,
 };




More information about the asterisk-commits mailing list