[asterisk-commits] moy: branch moy/mfcr2-1.2 r133393 - /team/moy/mfcr2-1.2/channels/chan_zap.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Jul 23 23:53:14 CDT 2008


Author: moy
Date: Wed Jul 23 23:53:14 2008
New Revision: 133393

URL: http://svn.digium.com/view/asterisk?view=rev&rev=133393
Log:
added proper clean up on module unload

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

Modified: team/moy/mfcr2-1.2/channels/chan_zap.c
URL: http://svn.digium.com/view/asterisk/team/moy/mfcr2-1.2/channels/chan_zap.c?view=diff&rev=133393&r1=133392&r2=133393
==============================================================================
--- team/moy/mfcr2-1.2/channels/chan_zap.c (original)
+++ team/moy/mfcr2-1.2/channels/chan_zap.c Wed Jul 23 23:53:14 2008
@@ -387,6 +387,31 @@
 static char mfcr2_cur_r2proto_file[OR2_MAX_LOGDIR];
 static openr2_log_level_t mfcr2_cur_loglevel = OR2_LOG_ERROR | OR2_LOG_WARNING;
 static openr2_calling_party_category_t mfcr2_cur_category = OR2_CALLING_PARTY_CATEGORY_NATIONAL_SUBSCRIBER;
+
+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;
+	}
+}
 
 #endif
 
@@ -9928,6 +9953,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++) {
@@ -9951,11 +9977,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();
@@ -9974,6 +10008,7 @@
 		}
 		pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);
 	}
+	ast_log(LOG_NOTICE, "Quitting MFC/R2 monitor thread\n");
 	return 0;
 }
 
@@ -10899,6 +10934,14 @@
 		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;
 }
 
@@ -11800,11 +11843,7 @@
 	pri_set_message(zt_pri_message);
 #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