[svn-commits] crichter: branch 1.2 r72087 - /branches/1.2/channels/misdn/

SVN commits to the Digium repositories svn-commits at lists.digium.com
Wed Jun 27 04:26:54 CDT 2007


Author: crichter
Date: Wed Jun 27 04:26:53 2007
New Revision: 72087

URL: http://svn.digium.com/view/asterisk?view=rev&rev=72087
Log:
simplified channel finding and locking a lot. removed unnecessary #ifdefed areas.

Modified:
    branches/1.2/channels/misdn/isdn_lib.c
    branches/1.2/channels/misdn/isdn_lib.h

Modified: branches/1.2/channels/misdn/isdn_lib.c
URL: http://svn.digium.com/view/asterisk/branches/1.2/channels/misdn/isdn_lib.c?view=diff&rev=72087&r1=72086&r2=72087
==============================================================================
--- branches/1.2/channels/misdn/isdn_lib.c (original)
+++ branches/1.2/channels/misdn/isdn_lib.c Wed Jun 27 04:26:53 2007
@@ -427,11 +427,40 @@
 
 }
 
-static int find_free_chan_in_stack(struct misdn_stack *stack, int channel, int dec)
+int set_chan_in_stack(struct misdn_stack *stack, int channel)
+{
+
+	cb_log(4,stack->port,"set_chan_in_stack: %d\n",channel);
+	dump_chan_list(stack);
+	if (channel >=1 && channel <= MAX_BCHANS) {
+		if (!stack->channels[channel-1])
+			stack->channels[channel-1] = 1;
+		else {
+			cb_log(4,stack->port,"channel already in use:%d\n", channel );
+			return -1;
+		}
+	} else {
+		cb_log(0,stack->port,"couldn't set channel %d in\n", channel );
+		return -1;
+	}
+  
+	return 0;
+}
+
+
+
+static int find_free_chan_in_stack(struct misdn_stack *stack, struct misdn_bchannel *bc, int channel, int dec)
 {
 	int i;
+	int chan=0;
+
+	if (bc->channel_found) 	
+		return 0;
+	
+	bc->channel_found=1;
 
 	cb_log(5,stack->port,"find_free_chan: req_chan:%d\n",channel);
+
 
 	if (channel < 0 || channel > MAX_BCHANS) {
 		cb_log(0, stack->port, " !! out of bound call to find_free_chan_in_stack! (ch:%d)\n", channel);
@@ -447,7 +476,8 @@
 			if (i != 15 && (channel < 0 || i == channel)) { /* skip E1 Dchannel ;) and work with chan preselection */
 				if (!stack->channels[i]) {
 					cb_log (3, stack->port, " --> found chan%s: %d\n", channel>=0?" (preselected)":"", i+1);
-					return i+1;
+					chan=i+1;
+					break;
 				}
 			}
 		}
@@ -456,15 +486,27 @@
 			if (i != 15 && (channel < 0 || i == channel)) { /* skip E1 Dchannel ;) and work with chan preselection */
 				if (!stack->channels[i]) {
 					cb_log (3, stack->port, " --> found chan%s: %d\n", channel>=0?" (preselected)":"", i+1);
-					return i+1;
+					chan=i+1;
+					break;
 				}
 			}
 		}
 	}
 
-	cb_log (1, stack->port, " !! NO FREE CHAN IN STACK\n");
-	dump_chan_list(stack);
-  
+	if (!chan) {
+		cb_log (1, stack->port, " !! NO FREE CHAN IN STACK\n");
+		dump_chan_list(stack);
+		bc->out_cause=34;
+		return -1;
+	}	
+
+	if (set_chan_in_stack(stack, chan)<0) {
+		cb_log (0, stack->port, "Channel Already in use:%d\n", chan);
+		bc->out_cause=44;
+		return -1;
+	}
+
+	bc->channel=chan;
 	return 0;
 }
 
@@ -631,6 +673,7 @@
 	bc->out_fac_type=FACILITY_NONE;
 	
 	bc->te_choose_channel = 0;
+	bc->channel_found= 0;
 }
 
 
@@ -688,26 +731,6 @@
 	} 
 }
 
-int set_chan_in_stack(struct misdn_stack *stack, int channel)
-{
-
-	cb_log(4,stack->port,"set_chan_in_stack: %d\n",channel);
-	dump_chan_list(stack);
-	if (channel >=1 && channel <= MAX_BCHANS) {
-		if (!stack->channels[channel-1])
-			stack->channels[channel-1] = 1;
-		else {
-			cb_log(4,stack->port,"channel already in use:%d\n", channel );
-			return -1;
-		}
-	} else {
-		cb_log(0,stack->port,"couldn't set channel %d in\n", channel );
-		return -1;
-	}
-  
-	return 0;
-}
-
 int chan_in_stack_free(struct misdn_stack *stack, int channel)
 {
 	if (stack->channels[channel-1])
@@ -841,16 +864,10 @@
 	int l3_id;
 	int i;
 	struct misdn_stack *stack=get_stack_by_bc(bc);
-	int free_chan;
   
 	if (stack->nt) {
-		free_chan = find_free_chan_in_stack(stack, bc->channel_preselected?bc->channel:0, 0);
-		if (!free_chan) return -1;
-		bc->channel=free_chan;
-
-		if (set_chan_in_stack(stack ,bc->channel)<0) return -1;
-		
-		cb_log(4,stack->port, " -->  found channel: %d\n",free_chan);
+		if (find_free_chan_in_stack(stack, bc, bc->channel_preselected?bc->channel:0, 0)<0) return -1;
+		cb_log(4,stack->port, " -->  found channel: %d\n",bc->channel);
     
 		for (i=0; i <= MAXPROCS; i++)
 			if (stack->procids[i]==0) break;
@@ -876,11 +893,8 @@
 	} else { 
 		if (stack->ptp || bc->te_choose_channel) {
 			/* we know exactly which channels are in use */
-			free_chan = find_free_chan_in_stack(stack, bc->channel_preselected?bc->channel:0, bc->dec);
-			if (!free_chan) return -1;
-			bc->channel=free_chan;
-			cb_log(2,stack->port, " -->  found channel: %d\n",free_chan);
-			if (set_chan_in_stack(stack ,bc->channel)<0) return -1;
+			if (find_free_chan_in_stack(stack, bc, bc->channel_preselected?bc->channel:0, bc->dec)<0) return -1;
+			cb_log(2,stack->port, " -->  found channel: %d\n",bc->channel);
 		} else {
 			/* other phones could have made a call also on this port (ptmp) */
 			bc->channel=0xff;
@@ -1502,25 +1516,13 @@
 
 		case EVENT_SETUP:
 		{
-			if (bc->channel == 0xff) {
-				bc->channel=find_free_chan_in_stack(stack, 0, 0);
-				if (!bc->channel) {
-					cb_log(0, stack->port, "Any Channel Requested, but we have no more!!\n");
-					bc->out_cause=34;
-					misdn_lib_send_event(bc,EVENT_RELEASE_COMPLETE);
-					return -1;
-				}
-			} 
-
-			if (bc->channel >0 && bc->channel<255) {
-				int ret=set_chan_in_stack(stack ,bc->channel);
-				if (event == EVENT_SETUP && ret<0){
-					/* empty bchannel */
-					bc->channel=0;
-					bc->out_cause=44;
-					misdn_lib_send_event(bc,EVENT_RELEASE_COMPLETE);
-					return -1;
-				}
+			if (bc->channel == 0xff || bc->channel<=0)
+				bc->channel=0;
+
+			if (find_free_chan_in_stack(stack, bc, bc->channel, 0)<0){
+				cb_log(0, stack->port, "Any Channel Requested, but we have no more!!\n");
+				misdn_lib_send_event(bc,EVENT_RELEASE_COMPLETE);
+				return -1;
 			}
 		}
 		break;
@@ -2016,23 +2018,11 @@
 
 			switch (event) {
 				case EVENT_SETUP:
-					if (bc->channel<=0 || bc->channel==0xff) {
-						bc->channel=find_free_chan_in_stack(stack,0,0);
-		
-						if (bc->channel<=0)
-							goto ERR_NO_CHANNEL;
-					} else if (!stack->ptp) 
-						cb_log(3,stack->port," --> PTMP but channel requested\n"); 
-
-					int ret=set_chan_in_stack(stack, bc->channel);
-					if (event==EVENT_SETUP && ret<0){
-						/* empty bchannel */
+					if (bc->channel<=0 || bc->channel==0xff) 
 						bc->channel=0;
-						bc->out_cause=44;
-
+				
+					if (find_free_chan_in_stack(stack,bc, bc->channel,0)<0) 
 						goto ERR_NO_CHANNEL;
-					}
-
 					break;
 				case EVENT_RELEASE:
 				case EVENT_RELEASE_COMPLETE:
@@ -2638,7 +2628,7 @@
 				if (tmpcause == 44) {
 					cb_log(0,stack->port,"**** Received CAUSE:44, so not cleaning up channel %d\n", channel);
 					cb_log(0,stack->port,"**** This channel is now no longer available,\nplease try to restart it with 'misdn send restart <port> <channel>'\n");
-						set_chan_in_stack(stack,bc->channel);
+					set_chan_in_stack(stack,bc->channel);
 				} else {
 					if (channel>0)
 						empty_chan_in_stack(stack,channel);
@@ -3230,14 +3220,8 @@
 
 		if (stack->nt) {
 			if (bc->channel <=0 ) { /*  else we have the channel already */
-				bc->channel = find_free_chan_in_stack(stack, 0, 0);
-				if (!bc->channel) {
+				if (find_free_chan_in_stack(stack, bc, 0, 0)<0) {
 					cb_log(0, stack->port, " No free channel at the moment\n");
-					/*FIXME: add disconnect*/
-					RETURN(-ENOCHAN,OUT);
-				}
-				
-				if (set_chan_in_stack(stack ,bc->channel)<0) {
 					/*FIXME: add disconnect*/
 					RETURN(-ENOCHAN,OUT);
 				}

Modified: branches/1.2/channels/misdn/isdn_lib.h
URL: http://svn.digium.com/view/asterisk/branches/1.2/channels/misdn/isdn_lib.h?view=diff&rev=72087&r1=72086&r2=72087
==============================================================================
--- branches/1.2/channels/misdn/isdn_lib.h (original)
+++ branches/1.2/channels/misdn/isdn_lib.h Wed Jun 27 04:26:53 2007
@@ -364,16 +364,8 @@
 	int ec_deftaps;
 	int ec_training;
 #endif
-
-#ifdef WITH_BEROEC
-	beroec_t *ec;
-	int bnec_tail;
-	int bnec_ah;
-	int bnec_nlp;
-	int bnec_td;
-	int bnec_adapt;
-	int bnec_zero;
-#endif
+	
+	int channel_found;
 	
 	int orig;
 




More information about the svn-commits mailing list