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

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Fri Oct 27 07:30:43 MST 2006


Author: nadi
Date: Fri Oct 27 09:30:42 2006
New Revision: 46357

URL: http://svn.digium.com/view/asterisk?rev=46357&view=rev
Log:
more work for state_machine

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?rev=46357&r1=46356&r2=46357&view=diff
==============================================================================
--- team/group/trunk-cm-csel-hash/channels/chan_misdn.c (original)
+++ team/group/trunk-cm-csel-hash/channels/chan_misdn.c Fri Oct 27 09:30:42 2006
@@ -745,20 +745,12 @@
 
 /* State Machine: mISDN */
 static int handle_aevent_hangup (void *p, int state, int event);
-static int handle_aevent_control (void *p, int state, int event) { return 0; }
+static int handle_mevent_proceeding_progress (void *p, int state, int event);
 
 static struct state_machine_transition misdn_state_table[] = {
 	{ MISDN_NOTHING,              AEVENT_CALL,   MISDN_CALLING,  EVENT_SETUP,            NULL },
 
 	{ MISDN_CALLING,              AEVENT_HANGUP, MISDN_CLEANING, EVENT_RELEASE_COMPLETE, NULL },
-	{ MISDN_HOLDED,               AEVENT_HANGUP, MISDN_CLEANING, EVENT_DISCONNECT,       handle_aevent_hangup },
-	{ MISDN_DIALING,              AEVENT_HANGUP, MISDN_CLEANING, EVENT_DISCONNECT,       handle_aevent_hangup },
-	{ MISDN_CALLING_ACKNOWLEDGE,  AEVENT_HANGUP, MISDN_CLEANING, EVENT_DISCONNECT,       handle_aevent_hangup },
-	{ MISDN_ALERTING,             AEVENT_HANGUP, MISDN_CLEANING, EVENT_DISCONNECT,       handle_aevent_hangup },
-	{ MISDN_PROGRESS,             AEVENT_HANGUP, MISDN_CLEANING, EVENT_DISCONNECT,       handle_aevent_hangup },
-	{ MISDN_PROCEEDING,           AEVENT_HANGUP, MISDN_CLEANING, EVENT_DISCONNECT,       handle_aevent_hangup },
-	{ MISDN_CONNECTED,            AEVENT_HANGUP, MISDN_CLEANING, EVENT_DISCONNECT,       handle_aevent_hangup },
-	{ MISDN_PRECONNECTED,         AEVENT_HANGUP, MISDN_CLEANING, EVENT_DISCONNECT,       handle_aevent_hangup },
 	{ MISDN_DISCONNECTED,         AEVENT_HANGUP, MISDN_CLEANING, EVENT_RELEASE,          NULL },
 	{ MISDN_RELEASED,             AEVENT_HANGUP, MISDN_CLEANING, EVENT_NONE,             NULL },
 	{ MISDN_CLEANING,             AEVENT_HANGUP, MISDN_CLEANING, EVENT_NONE,             NULL },
@@ -769,19 +761,26 @@
 
 	{ STATE_ANY,                  AEVENT_ANSWER, MISDN_CONNECTED, EVENT_CONNECT,         NULL },
 
-	{ STATE_ANY,                  AEVENT_CBUSY,  MISDN_CLEANING, EVENT_DISCONNECT,       handle_aevent_control },
+	{ STATE_ANY,                  AEVENT_CBUSY,  MISDN_CLEANING, EVENT_DISCONNECT,       NULL },
+
+	{ STATE_ANY,                  EVENT_PROCEEDING, MISDN_PROCEEDING, 127 + AST_CONTROL_PROCEEDING, handle_mevent_proceeding_progress },
+	{ STATE_ANY,                  EVENT_PROGRESS, MISDN_PROGRESS, 127 + AST_CONTROL_PROGRESS, handle_mevent_proceeding_progress },
 };
 
 static int send_event (void *p, int event)
 {
-	struct misdn_bchannel *bc = ((struct chan_list *)p)->bc;
+	int re = -1;
+	struct chan_list *ch = p;
 
 	if (event > EVENT_NOTHING && event < EVENT_UNKNOWN) {
-		misdn_lib_send_event(bc, event);
-		return 0;
-	}
-
-	return -1;
+		misdn_lib_send_event(ch->bc, event);
+		re = 0;
+	} else {
+		ast_queue_control(ch->ast, event - 127);
+		re = 0;
+	}
+
+	return re;
 }
 
 /* Channel Selection */
@@ -3186,7 +3185,7 @@
 	return tmp->ast_dsp ? process_ast_dsp(tmp, &tmp->frame) : &tmp->frame;
 }
 
-static int misdn_write(struct ast_channel *ast, struct ast_frame *frame)
+static int misdn_write (struct ast_channel *ast, struct ast_frame *frame)
 {
 	struct chan_list *ch;
 	int i = 0;
@@ -3383,6 +3382,16 @@
 	return 0;
 }
 
+static int handle_mevent_proceeding_progress (void *p, int state, int event)
+{
+	struct chan_list *ch = p;
+
+	if (misdn_cap_is_speech(ch->bc->capability) && misdn_inband_avail(ch->bc))
+		start_bc_tones(ch);
+
+	return EVENT_DEFAULT;
+}
+
 /* The big event handler for events from mISDN (isdn_lib) */
 static enum event_response_e cb_events (enum event_e event, struct misdn_bchannel *bc, void *user_data)
 {
@@ -3437,6 +3446,75 @@
 			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");
+				return RESPONSE_OK;
+			}
+			if (t < 0) {
+				chan_misdn_log(-1, bc->port, "Select Error (err = %s)\n", strerror(errno));
+				return RESPONSE_OK;
+			}
+			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(1, 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)
+			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 (ch && !state_machine_run(ch->sm, event))
+		return RESPONSE_OK;
 
 	switch (event) {
 	case EVENT_PORT_ALARM:
@@ -3741,20 +3819,6 @@
 			misdn_lib_send_event(bc, EVENT_INFORMATION);
 		}
 		break;
-	case EVENT_PROCEEDING:
-		if (misdn_cap_is_speech(bc->capability) && misdn_inband_avail(bc))
-			start_bc_tones(ch);
-		state_machine_set_state(ch->sm, MISDN_PROCEEDING);
-		ast_queue_control(ch->ast, AST_CONTROL_PROCEEDING);
-		break;
-	case EVENT_PROGRESS:
-		if (!bc->nt) {
-			if (misdn_cap_is_speech(bc->capability) && misdn_inband_avail(bc))
-				start_bc_tones(ch);
-			ast_queue_control(ch->ast, AST_CONTROL_PROGRESS);
-			state_machine_set_state(ch->sm, MISDN_PROGRESS);
-		}
-		break;
 	case EVENT_ALERTING:
 		state_machine_set_state(ch->sm, MISDN_ALERTING);
 		ast_queue_control(ch->ast, AST_CONTROL_RINGING);
@@ -3818,8 +3882,6 @@
 				hangup_chan(ch);
 			}
 			bc->out_cause = -1;
-			if (bc->need_release)
-				misdn_lib_send_event(bc, EVENT_RELEASE);
 		}
 		break;
 	case EVENT_RELEASE:
@@ -3841,72 +3903,6 @@
 			bc->cause = 27; /* Destination out of order */
 		hangup_chan(ch);
 		release_chan(bc);
-		break;
-	case 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)
-				break;
-			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;
-		}
-		break;
-	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");
-					break;
-				}
-				if (t < 0) {
-					chan_misdn_log(-1, bc->port, "Select Error (err = %s)\n", strerror(errno));
-					break;
-				}
-				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(1, bc->port, "Wripe Pipe full!\n");
-			}
-		}
 		break;
 	case EVENT_TIMEOUT:
 		if (ch && bc)



More information about the asterisk-commits mailing list