[svn-commits] moy: branch moy/mfcr2 r133394 - /team/moy/mfcr2/channels/chan_zap.c

SVN commits to the Digium repositories svn-commits at lists.digium.com
Thu Jul 24 00:03:16 CDT 2008


Author: moy
Date: Thu Jul 24 00:03:16 2008
New Revision: 133394

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

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

Modified: team/moy/mfcr2/channels/chan_zap.c
URL: http://svn.digium.com/view/asterisk/team/moy/mfcr2/channels/chan_zap.c?view=diff&rev=133394&r1=133393&r2=133394
==============================================================================
--- team/moy/mfcr2/channels/chan_zap.c (original)
+++ team/moy/mfcr2/channels/chan_zap.c Thu Jul 24 00:03:16 2008
@@ -1122,6 +1122,31 @@
 }
 
 #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)
 {
@@ -10597,6 +10622,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++) {
@@ -10620,11 +10646,19 @@
 			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;
 		}
 		ast_mutex_unlock(&mfcr2->monitored_count_lock);
+		if (quit_loop) {
+			break;
+		}
 		/* probably poll() is a valid cancel point, lets just be on the safe side
 		   by calling pthread_testcancel */
 		pthread_testcancel();
@@ -10643,6 +10677,7 @@
 		}
 		pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);
 	}
+	ast_log(LOG_NOTICE, "Quitting MFC/R2 monitor thread\n");
 	return 0;
 }
 #endif
@@ -12891,6 +12926,18 @@
 static int zap_restart(void)
 {
 	ast_verb(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) {
 		ast_debug(1, "Destroying Zaptel channel no. %d\n", iflist->channel);
 		/* Also updates iflist: */
@@ -13966,6 +14013,13 @@
 		zt_close(linksets[i].fds[i]);
 	}
 #endif /* HAVE_SS7 */
+#ifdef HAVE_OPENR2
+	for (i = 0; i < NUM_SPANS; i++) {
+		if (r2links[i].protocol_context) {
+			openr2_context_delete(r2links[i].protocol_context);
+		}
+	}
+#endif
 
 	return 0;
 }
@@ -15585,8 +15639,6 @@
 	int res;
 #if defined(HAVE_PRI) || defined(HAVE_SS7) 
 	int y, i;
-#elif defined(HAVE_OPENR2)
-	int i;
 #endif
 
 #ifdef HAVE_PRI
@@ -15615,10 +15667,7 @@
 	ss7_set_message(zt_ss7_message);
 #endif /* HAVE_SS7 */
 #ifdef HAVE_OPENR2
-	memset(r2links, 0, sizeof(r2links));
-	for (i = 0; i < NUM_SPANS; i++) {
-		r2links[i].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 svn-commits mailing list