[asterisk-commits] moy: branch moy/mfcr2-1.4 r133362 - /team/moy/mfcr2-1.4/channels/chan_zap.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Jul 23 22:49:50 CDT 2008


Author: moy
Date: Wed Jul 23 22:49:49 2008
New Revision: 133362

URL: http://svn.digium.com/view/asterisk?view=rev&rev=133362
Log:
fixed zap restart command and proper clean up on module unload

Modified:
    team/moy/mfcr2-1.4/channels/chan_zap.c

Modified: team/moy/mfcr2-1.4/channels/chan_zap.c
URL: http://svn.digium.com/view/asterisk/team/moy/mfcr2-1.4/channels/chan_zap.c?view=diff&rev=133362&r1=133361&r2=133362
==============================================================================
--- team/moy/mfcr2-1.4/channels/chan_zap.c (original)
+++ team/moy/mfcr2-1.4/channels/chan_zap.c Wed Jul 23 22:49:49 2008
@@ -883,6 +883,32 @@
 
 static struct ast_channel *zt_new(struct zt_pvt *, int, int, int, int, int);
 #ifdef HAVE_OPENR2
+
+static void init_mfcr2_globals(void)
+{
+	mfcr2_cur_context_index = 0;
+	mfcr2_cur_variant = OR2_VAR_UNKNOWN;
+	mfcr2_cur_mfback_timeout = -1;
+	mfcr2_cur_metering_pulse_timeout = -1;
+	mfcr2_cur_max_ani = 10;
+	mfcr2_cur_max_dnis = 4;
+	mfcr2_cur_get_ani_first = 0;
+	mfcr2_cur_context_index = 0;
+	mfcr2_cur_call_files = 0;
+	mfcr2_cur_allow_collect_calls = 0;
+	mfcr2_cur_double_answer = 0;
+	mfcr2_cur_immediate_accept = 0;
+	mfcr2_cur_loglevel = OR2_LOG_ERROR | OR2_LOG_WARNING;
+	mfcr2_cur_category = OR2_CALLING_PARTY_CATEGORY_NATIONAL_SUBSCRIBER;
+	memset(mfcr2_cur_logdir, 0, sizeof(mfcr2_cur_logdir));
+	memset(mfcr2_cur_r2proto_file, 0, sizeof(mfcr2_cur_r2proto_file));
+	memset(r2links, 0, sizeof(r2links));
+	int r;
+	for (r = 0; r < NUM_SPANS; r++) {
+		r2links[r].master = AST_PTHREADT_NULL;
+	}
+}
+
 static openr2_calling_party_category_t zt_r2_get_channel_category(struct ast_channel *c)
 {
 	openr2_calling_party_category_t cat;
@@ -8566,6 +8592,7 @@
 	int res = 0;
 	int i = 0;
 	int oldstate = 0;
+	int quit_loop = 0;
 	/* now that we're ready to get calls, unblock our side and
 	   get current line state */
 	for (i = 0; i < mfcr2->numchans; i++) {
@@ -8589,9 +8616,17 @@
 			if (mfcr2->pvts[i]->owner) {
 				continue;
 			}
+			if (!mfcr2->pvts[i]->r2chan) {
+				ast_log(LOG_DEBUG, "Wow, no r2chan on channel %d\n", mfcr2->pvts[i]->channel);
+				quit_loop = 1;
+				break;
+			}
 			openr2_chan_enable_read(mfcr2->pvts[i]->r2chan);
 			pollers[i].events = POLLIN | POLLPRI;
 			pollers[i].fd = mfcr2->pvts[i]->subs[SUB_REAL].zfd;
+		}
+		if (quit_loop) {
+			break;
 		}
 		ast_mutex_unlock(&mfcr2->monitored_count_lock);
 		/* probably poll() is a valid cancel point, lets just be on the safe side
@@ -8612,6 +8647,7 @@
 		}
 		pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);
 	}
+	ast_log(LOG_NOTICE, "Quitting MFC/R2 monitor thread\n");
 	return 0;
 }
 #endif
@@ -10786,12 +10822,23 @@
 
 	return zap_destroy_channel_bynum(channel);
 }
-
 static int setup_zap(int reload);
 static int zap_restart(void)
 {
 	if (option_verbose > 0)
 		ast_verbose(VERBOSE_PREFIX_1 "Destroying channels and reloading zaptel configuration.\n");
+#ifdef HAVE_OPENR2
+	int r;
+	for (r = 0; r < NUM_SPANS; r++) {
+		if (r2links[r].master != AST_PTHREADT_NULL) {
+			ast_log(LOG_DEBUG, "Killing MFC/R2 monitor thread %p\n", &r2links[r].master);
+			pthread_cancel(r2links[r].master);
+			pthread_join(r2links[r].master, NULL);
+			openr2_context_delete(r2links[r].protocol_context);
+		}
+	}
+	init_mfcr2_globals();
+#endif
 	while (iflist) {
 		if (option_debug)
 			ast_log(LOG_DEBUG, "Destroying zaptel channel no. %d\n", iflist->channel);
@@ -11445,6 +11492,13 @@
 		if (pris[i].master && (pris[i].master != AST_PTHREADT_NULL))
 			pthread_join(pris[i].master, NULL);
 		zt_close(pris[i].fds[i]);
+	}
+#endif
+#ifdef HAVE_OPENR2
+	for (r = 0; r < NUM_SPANS; r++) {
+		if (r2links[r].protocol_context) {
+			openr2_context_delete(r2links[r].protocol_context);
+		}
 	}
 #endif
 	return 0;
@@ -12465,11 +12519,7 @@
 			zap_send_keypad_facility_synopsis, zap_send_keypad_facility_descrip);
 #endif
 #ifdef HAVE_OPENR2
-	int r;
-	memset(r2links, 0, sizeof(r2links));
-	for (r = 0; r < NUM_SPANS; r++) {
-		r2links[r].master = AST_PTHREADT_NULL;
-	}
+	init_mfcr2_globals();
 #endif
 	res = setup_zap(0);
 	/* Make sure we can register our Zap channel type */




More information about the asterisk-commits mailing list