[asterisk-commits] nadi: branch group/trunk-cm-csel-hash r47723 - /team/group/trunk-cm-csel-hash...

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Thu Nov 16 05:11:27 MST 2006


Author: nadi
Date: Thu Nov 16 06:11:27 2006
New Revision: 47723

URL: http://svn.digium.com/view/asterisk?view=rev&rev=47723
Log:
reworked a lot in cb_events

Modified:
    team/group/trunk-cm-csel-hash/channels/chan_misdn.c

Modified: team/group/trunk-cm-csel-hash/channels/chan_misdn.c
URL: http://svn.digium.com/view/asterisk/team/group/trunk-cm-csel-hash/channels/chan_misdn.c?view=diff&rev=47723&r1=47722&r2=47723
==============================================================================
--- team/group/trunk-cm-csel-hash/channels/chan_misdn.c (original)
+++ team/group/trunk-cm-csel-hash/channels/chan_misdn.c Thu Nov 16 06:11:27 2006
@@ -4035,26 +4035,7 @@
 		}
 	}
 
-	if (ch) {
-		switch (event) {
-		case EVENT_TONE_GENERATE:
-			break;
-		case EVENT_DISCONNECT:
-		case EVENT_RELEASE:
-		case EVENT_RELEASE_COMPLETE:
-		case EVENT_CLEANUP:
-		case EVENT_TIMEOUT:
-			if (!ch->ast)
-				chan_misdn_log(3, bc->port, "ast_hangup already called, so we have no ast ptr anymore in event(%s)\n", manager_isdn_get_info(event));
-			break;
-		default:
-			if (!ch->ast || !MISDN_ASTERISK_PVT(ch->ast) || !MISDN_ASTERISK_TECH_PVT(ch->ast)) {
-				if (event != EVENT_BCHAN_DATA)
-					ast_log(LOG_NOTICE, "No Ast or No private Pointer in Event (%d:%s)\n", event, manager_isdn_get_info(event));
-				return -1;
-			}
-		}
-	} else {
+	if (!ch) {
 		switch (event) {
 		case EVENT_RETRIEVE:
 			ch = find_holded_l3(cl_te, bc->l3_id, 1);
@@ -4065,13 +4046,12 @@
 			}
 			ch->bc = bc;
 			break;
+		case EVENT_DISCONNECT:
+			bc->out_cause = -1;
 		case EVENT_SETUP:
 		case EVENT_PORT_ALARM:
 		case EVENT_NEW_BC:
 		case EVENT_FACILITY:
-			break;
-		case EVENT_DISCONNECT:
-			bc->out_cause = -1;
 			break;
 		case EVENT_RELEASE_COMPLETE:
 			chan_misdn_log(2, bc->port, " --> no Ch, so we've already released.\n");
@@ -4084,137 +4064,163 @@
 						   bc->l3_id, bc, manager_isdn_get_info(event), bc->port, bc->channel);
 			return -1;
 		}
-	}
-
-	if (event == EVENT_BCHAN_DATA) {
-		struct ast_frame frame;
-		struct timeval tv;
-		int t;
-
-		if (!misdn_cap_is_speech(ch->bc->capability)) {
-			/* in data modes we queue frames */
-			frame.frametype = AST_FRAME_VOICE; /* we have no data frames yet */
-			frame.subclass = AST_FORMAT_ALAW;
-			frame.datalen = bc->bframe_len;
-			frame.samples = bc->bframe_len;
-			frame.mallocd =	frame.offset = 0;
-			frame.delivery = ast_tv(0, 0);
-			frame.src = NULL;
-			frame.data = bc->bframe;
-			ast_queue_frame(ch->ast, &frame);
-		} else {
-			fd_set wrfs;
-			tv.tv_sec = 0;
-			tv.tv_usec = 0;
-			FD_ZERO(&wrfs);
-			FD_SET(ch->pipe[1], &wrfs);
-			t = select(FD_SETSIZE, NULL, &wrfs, NULL, &tv);
-			if (!t) {
-				chan_misdn_log(9, bc->port, "Select Timed out\n");
+	} else {
+		switch (event) {
+		case EVENT_DISCONNECT:
+		case EVENT_RELEASE:
+		case EVENT_RELEASE_COMPLETE:
+		case EVENT_CLEANUP:
+		case EVENT_TIMEOUT:
+			if (!ch->ast)
+				chan_misdn_log(3, bc->port, "ast_hangup already called, so we have no ast ptr anymore in event(%s)\n", manager_isdn_get_info(event));
+		case EVENT_TONE_GENERATE:
+			break;
+		default:
+			if (!ch->ast || !MISDN_ASTERISK_PVT(ch->ast) || !MISDN_ASTERISK_TECH_PVT(ch->ast)) {
+				if (event != EVENT_BCHAN_DATA)
+					ast_log(LOG_NOTICE, "No Ast or No private Pointer in Event (%d:%s)\n", event, manager_isdn_get_info(event));
+				return -1;
+			}
+		}
+	}
+
+	switch (event) {
+	case EVENT_BCHAN_DATA:
+		{
+			struct ast_frame frame;
+			struct timeval tv;
+			int t;
+
+			if (!misdn_cap_is_speech(ch->bc->capability)) {
+				/* in data modes we queue frames */
+				frame.frametype = AST_FRAME_VOICE; /* we have no data frames yet */
+				frame.subclass = AST_FORMAT_ALAW;
+				frame.datalen = bc->bframe_len;
+				frame.samples = bc->bframe_len;
+				frame.mallocd =	frame.offset = 0;
+				frame.delivery = ast_tv(0, 0);
+				frame.src = NULL;
+				frame.data = bc->bframe;
+				ast_queue_frame(ch->ast, &frame);
+			} else {
+				fd_set wrfs;
+				tv.tv_sec = 0;
+				tv.tv_usec = 0;
+				FD_ZERO(&wrfs);
+				FD_SET(ch->pipe[1], &wrfs);
+				t = select(FD_SETSIZE, NULL, &wrfs, NULL, &tv);
+				if (!t)
+					chan_misdn_log(9, bc->port, "Select Timed out\n");
+				else if (t < 0)
+					chan_misdn_log(-1, bc->port, "Select Error (err = %s)\n", strerror(errno));
+				else if (FD_ISSET(ch->pipe[1], &wrfs)) {
+					chan_misdn_log(9, bc->port, "writing %d bytes to asterisk\n", bc->bframe_len);
+					if (write(ch->pipe[1], bc->bframe, bc->bframe_len) <= 0)
+						chan_misdn_log(-1, bc->port, "Write returned <= 0 (err = %s)\n", strerror(errno));
+				} else
+					chan_misdn_log(2, bc->port, "Wripe Pipe full!\n");
+			}
+			return RESPONSE_OK;
+		}
+	case EVENT_TONE_GENERATE:
+		{
+			int tone_len = bc->tone_cnt,
+				res;
+			struct ast_channel *ast = ch->ast;
+			void *tmp;
+
+			if (!ast || !ast->generator)
 				return RESPONSE_OK;
+
+			chan_misdn_log(9, bc->port, "TONE_GEN: len:%d\n");
+			tmp = ast->generatordata;
+			ast->generatordata = NULL;
+			if (tone_len < 0 || tone_len > 512) {
+				ast_log(LOG_NOTICE, "TONE_GEN: len was %d, set to 128\n", tone_len);
+				tone_len = 128;
 			}
-			if (t < 0) {
-				chan_misdn_log(-1, bc->port, "Select Error (err = %s)\n", strerror(errno));
-				return RESPONSE_OK;
+			res = ast->generator->generate(ast, tmp, tone_len, tone_len);
+			ast->generatordata = tmp;
+			if (res) {
+				ast_log(LOG_WARNING, "Auto-deactivating generator\n");
+				ast_deactivate_generator(ast);
+			} else
+				bc->tone_cnt = 0;
+
+			return RESPONSE_OK;
+		}
+	case EVENT_SETUP:
+		{
+			char msns[BUFFERSIZE],
+				 tmp[16];
+			int msn_valid = 0,
+				exceed;
+
+			if (ch) {
+				if (statemachine_get_state(ch->sm) == MISDN_NOTHING)
+					ch = NULL;
+				else {
+					chan_misdn_log(2, bc->port, " --> Ignoring Call we already have one\n");
+					return RESPONSE_IGNORE_SETUP_WITHOUT_CLOSE;
+				}
 			}
-			if (FD_ISSET(ch->pipe[1], &wrfs)) {
-				chan_misdn_log(9, bc->port, "writing %d bytes to asterisk\n", bc->bframe_len);
-				if (write(ch->pipe[1], bc->bframe, bc->bframe_len) <= 0)
-					chan_misdn_log(-1, bc->port, "Write returned <= 0 (err = %s)\n", strerror(errno));
-			} else
-				chan_misdn_log(2, bc->port, "Wripe Pipe full!\n");
-		}
-		return RESPONSE_OK;
-	}
-
-	if (event == EVENT_TONE_GENERATE) {
-		int tone_len = bc->tone_cnt,
-			res;
-		struct ast_channel *ast = ch->ast;
-		void *tmp;
-
-		chan_misdn_log(9, bc->port, "TONE_GEN: len:%d\n");
-		if (!ast || !ast->generator)
+
+			if (!cm_get(misdn_cm, msns, sizeof(msns), PORT, MCFG_MSNS, bc->port))
+				msn_valid = is_msn_valid(msns, bc->dad);
+
+			if (!bc->nt && !msn_valid) {
+				chan_misdn_log(2, bc->port, " --> Ignoring Call, its not in our MSN List\n");
+				return RESPONSE_IGNORE_SETUP; /*  Ignore MSNs which are not in our list. */
+			}
+
+			if (bc->cw) {
+				chan_misdn_log(0, bc->port, " --> Call Waiting on PMP sending RELEASE_COMPLETE\n");
+				if (cm_get_int(misdn_cm, bc->out_cause, PORT, MCFG_REJECT_CAUSE, bc->port))
+					bc->out_cause = 0;
+				if (!bc->out_cause)
+					bc->out_cause = 16;
+				return RESPONSE_RELEASE_SETUP;
+			}
+
+			print_bearer(bc);
+
+			ch = init_chan_list(ORG_MISDN);
+			if (!ch) {
+				chan_misdn_log(-1, bc->port, "cb_events: malloc for chan_list failed!\n");
+				return RESPONSE_IGNORE_SETUP;
+			}
+
+			ch->bc = bc;
+			ch->l3id = bc->l3_id;
+			ch->addr = bc->addr;
+			ch->orginator = ORG_MISDN;
+			ch->ast = misdn_new(ch, AST_STATE_RESERVED, bc->dad, bc->oad, AST_FORMAT_ALAW, bc->port, bc->channel);
+
+			if ((exceed = add_in_calls(bc->port))) {
+				snprintf(tmp, sizeof(tmp), "%d", exceed);
+				pbx_builtin_setvar_helper(ch->ast, "MAX_OVERFLOW", tmp);
+			}
+
+			config_ch(ch, ORG_MISDN);
+			config_ch_pres_screen(ch);
+			export_chan(ch->ast, bc, ch);
+
+			cl_queue_chan(&cl_te, ch) ;
+			
+			break; /* continue with statemachine */
+		}
+	case EVENT_NEW_BC:
+		{
+			if (!ch)
+				ch = find_holded(cl_te, bc);
+			if (!ch)
+				ast_log(LOG_WARNING, "NEW_BC without chan_list?\n");
+			else if (bc)
+				ch->bc = user_data;
 			return RESPONSE_OK;
-		tmp = ast->generatordata;
-		ast->generatordata = NULL;
-		if (tone_len < 0 || tone_len > 512) {
-			ast_log(LOG_NOTICE, "TONE_GEN: len was %d, set to 128\n", tone_len);
-			tone_len = 128;
-		}
-		res = ast->generator->generate(ast, tmp, tone_len, tone_len);
-		ast->generatordata = tmp;
-		if (res) {
-			ast_log(LOG_WARNING, "Auto-deactivating generator\n");
-			ast_deactivate_generator(ast);
-		} else
-			bc->tone_cnt = 0;
-		return RESPONSE_OK;
-	}
-
-	if (event == EVENT_SETUP) {
-		char msns[BUFFERSIZE],
-			 tmp[16];
-		int msn_valid = 0,
-			exceed;
-		if (ch) {
-			if (statemachine_get_state(ch->sm) == MISDN_NOTHING)
-				ch = NULL;
-			else {
-				chan_misdn_log(2, bc->port, " --> Ignoring Call we already have one\n");
-				return RESPONSE_IGNORE_SETUP_WITHOUT_CLOSE;
-			}
-		}
-		if (!cm_get(misdn_cm, msns, sizeof(msns), PORT, MCFG_MSNS, bc->port))
-			msn_valid = is_msn_valid(msns, bc->dad);
-		if (!bc->nt && !msn_valid) {
-			chan_misdn_log(2, bc->port, " --> Ignoring Call, its not in our MSN List\n");
-			return RESPONSE_IGNORE_SETUP; /*  Ignore MSNs which are not in our list. */
-		}
-
-		if (bc->cw) {
-			chan_misdn_log(0, bc->port, " --> Call Waiting on PMP sending RELEASE_COMPLETE\n");
-			if (cm_get_int(misdn_cm, bc->out_cause, PORT, MCFG_REJECT_CAUSE, bc->port))
-				bc->out_cause = 0;
-			if (!bc->out_cause)
-				bc->out_cause = 16;
-			return RESPONSE_RELEASE_SETUP;
-		}
-
-		print_bearer(bc);
-
-		ch = init_chan_list(ORG_MISDN);
-		if (!ch) {
-			chan_misdn_log(-1, bc->port, "cb_events: malloc for chan_list failed!\n");
-			return RESPONSE_IGNORE_SETUP;
-		}
-
-		ch->bc = bc;
-		ch->l3id = bc->l3_id;
-		ch->addr = bc->addr;
-		ch->orginator = ORG_MISDN;
-		ch->ast = misdn_new(ch, AST_STATE_RESERVED, bc->dad, bc->oad, AST_FORMAT_ALAW, bc->port, bc->channel);
-
-		if ((exceed = add_in_calls(bc->port))) {
-			snprintf(tmp, sizeof(tmp), "%d", exceed);
-			pbx_builtin_setvar_helper(ch->ast, "MAX_OVERFLOW", tmp);
-		}
-
-		config_ch(ch, ORG_MISDN);
-		config_ch_pres_screen(ch);
-		export_chan(ch->ast, bc, ch);
-		
-		cl_queue_chan(&cl_te, ch) ;
-	}
-
-	if (event == EVENT_NEW_BC) {
-		if (!ch)
-			ch = find_holded(cl_te, bc);
-		if (!ch)
-			ast_log(LOG_WARNING, "NEW_BC without chan_list?\n");
-		else if (bc)
-			ch->bc = user_data;
-		return RESPONSE_OK;
+		}
+	default:
+		break;
 	}
 
 	/*
@@ -4223,13 +4229,8 @@
 	if (ch && !statemachine_run(ch->sm, event)) {
 		if (ch->destroy_me)
 			release_chan(ch);
-		return RESPONSE_OK;
-	}
-
-	/*
-	 * this is for events not (yet) handled by our statemachine
-	 */
-	ast_log(LOG_NOTICE, "Got Unknown Event\n");
+	} else
+		ast_log(LOG_NOTICE, "Got unhandled event: %d\n", event);
 
 	return RESPONSE_OK;
 }



More information about the asterisk-commits mailing list