[asterisk-commits] russell: branch russell/smdi-1.4 r92817 - in /team/russell/smdi-1.4: configs/...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Dec 13 15:47:54 CST 2007


Author: russell
Date: Thu Dec 13 15:47:54 2007
New Revision: 92817

URL: http://svn.digium.com/view/asterisk?view=rev&rev=92817
Log:
Complete the implementation of the MWI polling thread for res_smdi

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

Modified: team/russell/smdi-1.4/configs/smdi.conf.sample
URL: http://svn.digium.com/view/asterisk/team/russell/smdi-1.4/configs/smdi.conf.sample?view=diff&rev=92817&r1=92816&r2=92817
==============================================================================
--- team/russell/smdi-1.4/configs/smdi.conf.sample (original)
+++ team/russell/smdi-1.4/configs/smdi.conf.sample Thu Dec 13 15:47:54 2007
@@ -63,6 +63,13 @@
 ;
 ; If no Asterisk voicemail context is specified, "default" will be assumed.
 ;
+; Before specifying mailboxes, you must specify an SMDI interface.  All mailbox
+; definitions that follow will correspond to that SMDI interface.  If you specify
+; another interface, then all definitions following that will correspond to the
+; new interface.
+;
+;smdiport=/dev/ttyS0
 ;2565551234=1234 at vmcontext1
 ;2565555678=5678 at vmcontext2
+;smdiport=/dev/ttyS1
 ;2565559999=9999

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=92817&r1=92816&r2=92817
==============================================================================
--- team/russell/smdi-1.4/res/res_smdi.c (original)
+++ team/russell/smdi-1.4/res/res_smdi.c Thu Dec 13 15:47:54 2007
@@ -46,6 +46,7 @@
 #include "asterisk/options.h"
 #include "asterisk/stringfields.h"
 #include "asterisk/linkedlists.h"
+#include "asterisk/app.h"
 
 /* Message expiry time in milliseconds */
 #define SMDI_MSG_EXPIRY_TIME	30000 /* 30 seconds */
@@ -59,6 +60,11 @@
 
 /*! \brief A mapping between an SMDI mailbox ID and an Asterisk mailbox */
 struct mailbox_mapping {
+	/*! This is the current state of the mailbox.  It is simply on or
+	 *  off to indicate if there are messages waiting or not. */
+	unsigned int cur_state:1;
+	/*! A Pointer to the appropriate SMDI interface */
+	struct ast_smdi_interface *iface;
 	AST_DECLARE_STRING_FIELDS(
 		/*! The Name of the mailbox for the SMDI link. */
 		AST_STRING_FIELD(smdi);
@@ -533,6 +539,7 @@
 static void destroy_mailbox_mapping(struct mailbox_mapping *mm)
 {
 	ast_string_field_free_memory(mm);
+	ASTOBJ_UNREF(mm->iface, ast_smdi_interface_destroy);
 	free(mm);
 }
 
@@ -546,7 +553,7 @@
 	ast_mutex_unlock(&mwi_monitor.lock);
 }
 
-static void append_mailbox_mapping(struct ast_variable *var)
+static void append_mailbox_mapping(struct ast_variable *var, struct ast_smdi_interface *iface)
 {
 	struct mailbox_mapping *mm;
 	char *mailbox, *context;
@@ -569,20 +576,46 @@
 	ast_string_field_set(mm, mailbox, mailbox);
 	ast_string_field_set(mm, context, context);
 
+	mm->iface = ASTOBJ_REF(iface);
+
 	ast_mutex_lock(&mwi_monitor.lock);
 	AST_LIST_INSERT_TAIL(&mwi_monitor.mailbox_mappings, mm, entry);
 	ast_mutex_unlock(&mwi_monitor.lock);
 }
 
+/*!
+ * \note Called with the mwi_monitor.lock locked
+ */
+static void poll_mailbox(struct mailbox_mapping *mm)
+{
+	char buf[1024];
+	unsigned int state;
+
+	snprintf(buf, sizeof(buf), "%s@%s", mm->mailbox, mm->context);
+
+	state = !!ast_app_has_voicemail(mm->mailbox, NULL);
+
+	if (state != mm->cur_state) {
+		if (state)
+			ast_smdi_mwi_set(mm->iface, mm->smdi);
+		else
+			ast_smdi_mwi_unset(mm->iface, mm->smdi);
+
+		mm->cur_state = state;
+	}
+}
+
 static void *mwi_monitor_handler(void *data)
 {
 	while (!mwi_monitor.stop) {
 		struct timespec ts = { 0, };
 		struct timeval tv;
+		struct mailbox_mapping *mm;
 
 		ast_mutex_lock(&mwi_monitor.lock);
 
-		/* XXX Do polling */
+		AST_LIST_TRAVERSE(&mwi_monitor.mailbox_mappings, mm, entry)
+			poll_mailbox(mm);
 
 		/* Sleep up to the configured polling interval.  Allow unload_module()
 		 * to signal us to wake up and exit. */
@@ -787,16 +820,34 @@
 
 	destroy_all_mailbox_mappings();
 	mwi_monitor.polling_interval = DEFAULT_POLLING_INTERVAL;
+	
+	iface = NULL;
 
 	for (v = ast_variable_browse(conf, "mailboxes"); v; v = v->next) {
-		if (!strcasecmp(v->name, "pollinginterval")) {
+		if (!strcasecmp(v->name, "smdiport")) {
+			if (iface)
+				ASTOBJ_UNREF(iface, ast_smdi_interface_destroy);
+
+			if (!(iface = ASTOBJ_CONTAINER_FIND(&smdi_ifaces, v->value))) {
+				ast_log(LOG_NOTICE, "SMDI interface %s not found\n", iface->name);
+				continue;
+			}
+		} else if (!strcasecmp(v->name, "pollinginterval")) {
 			if (sscanf(v->value, "%u", &mwi_monitor.polling_interval) != 1) {
 				ast_log(LOG_ERROR, "Invalid value for pollinginterval: %s\n", v->value);
 				mwi_monitor.polling_interval = DEFAULT_POLLING_INTERVAL;
 			}
-		} else
-			append_mailbox_mapping(v);
-	}
+		} else {
+			if (!iface) {
+				ast_log(LOG_ERROR, "Mailbox mapping ignored, no valid SMDI interface specified in mailboxes section\n");
+				continue;
+			}
+			append_mailbox_mapping(v, iface);
+		}
+	}
+
+	if (iface)
+		ASTOBJ_UNREF(iface, ast_smdi_interface_destroy);
 
 	ast_config_destroy(conf);
 




More information about the asterisk-commits mailing list