[asterisk-commits] branch crichter/0.4.0 r37376 - /team/crichter/0.4.0/channels/

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Tue Jul 11 04:00:22 MST 2006


Author: crichter
Date: Tue Jul 11 06:00:21 2006
New Revision: 37376

URL: http://svn.digium.com/view/asterisk?rev=37376&view=rev
Log:
overlap_dial functionality implemented.

Modified:
    team/crichter/0.4.0/channels/chan_misdn.c
    team/crichter/0.4.0/channels/misdn_config.c

Modified: team/crichter/0.4.0/channels/chan_misdn.c
URL: http://svn.digium.com/view/asterisk/team/crichter/0.4.0/channels/chan_misdn.c?rev=37376&r1=37375&r2=37376&view=diff
==============================================================================
--- team/crichter/0.4.0/channels/chan_misdn.c (original)
+++ team/crichter/0.4.0/channels/chan_misdn.c Tue Jul 11 06:00:21 2006
@@ -136,8 +136,6 @@
 
 struct chan_list {
   
-	ast_mutex_t lock;
-
 	char allowed_bearers[BUFFERSIZE+1];
 	
 	enum misdn_chan_state state;
@@ -188,6 +186,11 @@
 
 	const struct tone_zone_sound *ts;
 	
+	int overlap_dial;
+	int overlap_dial_task;
+	ast_mutex_t overlap_tv_lock;
+	struct timeval overlap_tv;
+  
 	struct chan_list *peer;
 	struct chan_list *next;
 	struct chan_list *prev;
@@ -520,18 +523,37 @@
 	}
 }
 
-static void misdn_tasks_wakeup (void)
+static inline void misdn_tasks_wakeup (void)
 {
 	pthread_kill(misdn_tasks_thread, SIGUSR1);
 }
 
-static void misdn_tasks_add (int timeout, ast_sched_cb callback, void *data)
-{
+static inline int _misdn_tasks_add_variable (int timeout, ast_sched_cb callback, void *data, int variable)
+{
+	int task_id;
+
 	if (!misdn_tasks) {
 		misdn_tasks_init();
 	}
-	ast_sched_add(misdn_tasks, timeout, callback, data);
+	task_id = ast_sched_add_variable(misdn_tasks, timeout, callback, data, variable);
 	misdn_tasks_wakeup();
+
+	return task_id;
+}
+
+static int misdn_tasks_add (int timeout, ast_sched_cb callback, void *data)
+{
+	return _misdn_tasks_add_variable(timeout, callback, data, 0);
+}
+
+static int misdn_tasks_add_variable (int timeout, ast_sched_cb callback, void *data)
+{
+	return _misdn_tasks_add_variable(timeout, callback, data, 1);
+}
+
+static void misdn_tasks_remove (int task_id)
+{
+	ast_sched_del(misdn_tasks, task_id);
 }
 
 static int misdn_l1_task (void *data)
@@ -539,6 +561,51 @@
 	misdn_lib_isdn_l1watcher((int)data);
 	chan_misdn_log(5, (int)data, "L1watcher timeout\n");
 	return 1;
+}
+
+static int misdn_overlap_dial_task (void *data)
+{
+	struct timeval tv_end, tv_now;
+	int diff;
+	struct chan_list *ch = (struct chan_list *)data;
+
+	chan_misdn_log(4, ch->bc->port, "overlap dial task, chan_state: %d\n", ch->state);
+
+	if (ch->state != MISDN_WAITING4DIGS) {
+		ch->overlap_dial_task = -1;
+		return 0;
+	}
+	
+	ast_mutex_lock(&ch->overlap_tv_lock);
+	tv_end = ch->overlap_tv;
+	ast_mutex_unlock(&ch->overlap_tv_lock);
+	
+	tv_end.tv_sec += ch->overlap_dial;
+	tv_now = ast_tvnow();
+
+	diff = ast_tvdiff_ms(tv_end, tv_now);
+
+	if (diff <= 100) {
+		/* if we are 100ms near the timeout, we are satisfied.. */
+		tone_indicate(ch,TONE_NONE);
+		if (ast_exists_extension(ch->ast, ch->context, ch->bc->dad, 1, ch->bc->oad)) {
+			ch->state=MISDN_DIALING;
+			if (ast_pbx_start(ch->ast) < 0) {
+				chan_misdn_log(-1, ch->bc->port, "ast_pbx_start returned < 0 in misdn_overlap_dial_task\n");
+				goto misdn_overlap_dial_task_disconnect;
+			}
+		} else {
+misdn_overlap_dial_task_disconnect:
+			tone_indicate(ch,TONE_BUSY);
+			if (ch->bc->nt)
+				misdn_lib_send_event(ch->bc, EVENT_RELEASE_COMPLETE );
+			else
+				misdn_lib_send_event(ch->bc, EVENT_RELEASE);
+		}
+		ch->overlap_dial_task = -1;
+		return 0;
+	} else
+		return diff;
 }
 
 static void send_digit_to_chan(struct chan_list *cl, char digit )
@@ -1678,8 +1745,7 @@
 			debug_numplan(port, bc->cpnnumplan,"CTON");
 		}
 
-		
-		
+		ch->overlap_dial = 0;
 	} else { /** ORIGINATOR MISDN **/
 		if (!strcasecmp(faxdetect,"incoming")||	!strcasecmp(faxdetect,"both"))
 			ch->faxdetect=1;
@@ -1746,7 +1812,11 @@
 		if ( !ast_strlen_zero(bc->rad) ) 
 			ast->cid.cid_rdnis=strdup(bc->rad);
 		
+		misdn_cfg_get(bc->port, MISDN_CFG_OVERLAP_DIAL, &ch->overlap_dial, sizeof(ch->overlap_dial));
+		ast_mutex_init(&ch->overlap_tv_lock);
 	} /* ORIG MISDN END */
+
+	ch->overlap_dial_task = -1;
 	
 	return 0;
 }
@@ -3133,6 +3203,13 @@
 				chan_misdn_log(5,bc->port,"Jitterbuffer already destroyed.\n");
 		}
 
+		if (ch->overlap_dial) {
+			if (ch->overlap_dial_task != -1) {
+				misdn_tasks_remove(ch->overlap_dial_task);
+				ch->overlap_dial_task = -1;
+			}
+			ast_mutex_destroy(&ch->overlap_tv_lock);
+		}
 
 		if (ch->orginator == ORG_AST) {
 			misdn_out_calls[bc->port]--;
@@ -3547,6 +3624,18 @@
 
 				break;
 			}
+
+			if (ch->overlap_dial) {
+				ast_mutex_lock(&ch->overlap_tv_lock);
+				ch->overlap_tv = ast_tvnow();
+				ast_mutex_unlock(&ch->overlap_tv_lock);
+				if (ch->overlap_dial_task == -1) {
+					ch->overlap_dial_task = 
+						misdn_tasks_add_variable(ch->overlap_dial, misdn_overlap_dial_task, ch);
+				}
+				break;
+			}
+
 			if (ast_exists_extension(ch->ast, ch->context, bc->dad, 1, bc->oad)) {
 				ch->state=MISDN_DIALING;
 	  
@@ -3603,14 +3692,6 @@
 	}
 	
 
-	/* Overlap Dial */
-/* 	{ */
-/* 		int overlap; */
-/* 		misdn_cfg_get(bc->port, MISDN_CFG_OVERLAP_DIAL, &overlap, sizeof(overlap)); */
-/* 		if (overlap) */
-/* 			chan_misdn_log(0, bc->port, "Overlap Dial activated. Waiting %d seconds of idle until continueing with EVENT_SETUP.\n", overlap); */
-/* 	} */
-	
 	int msn_valid = misdn_cfg_is_msn_valid(bc->port, bc->dad);
 	if (!bc->nt && ! msn_valid) {
 		chan_misdn_log(1, bc->port, " --> Ignoring Call, its not in our MSN List\n");
@@ -3745,7 +3826,7 @@
 			break;
 		}
 		
-		if (ast_exists_extension(ch->ast, ch->context, bc->dad, 1, bc->oad)) {
+		if (!ch->overlap_dial && ast_exists_extension(ch->ast, ch->context, bc->dad, 1, bc->oad)) {
 			ch->state=MISDN_DIALING;
 			
 			if (bc->nt || (bc->need_more_infos && misdn_lib_is_ptp(bc->port)) ) {
@@ -3782,7 +3863,7 @@
 				}
 
 			} else {
-				
+
 				int ret= misdn_lib_send_event(bc, EVENT_SETUP_ACKNOWLEDGE );
 				if (ret == -ENOCHAN) {
 					ast_log(LOG_WARNING,"Channel was catched, before we could Acknowledge\n");
@@ -3792,14 +3873,25 @@
 				
 				/** ADD IGNOREPAT **/
 				
-				int stop_tone;
+				int stop_tone, dad_len;
 				misdn_cfg_get( 0, MISDN_GEN_STOP_TONE, &stop_tone, sizeof(int));
-				if ( (!ast_strlen_zero(bc->dad)) && stop_tone ) 
+				dad_len = ast_strlen_zero(bc->dad);
+				if ( !dad_len && stop_tone ) 
 					tone_indicate(ch,TONE_NONE);
 				else
 					tone_indicate(ch,TONE_DIAL);
 				
 				ch->state=MISDN_WAITING4DIGS;
+
+				if (ch->overlap_dial && !dad_len) {
+					ast_mutex_lock(&ch->overlap_tv_lock);
+					ch->overlap_tv = ast_tvnow();
+					ast_mutex_unlock(&ch->overlap_tv_lock);
+					if (ch->overlap_dial_task == -1) {
+						ch->overlap_dial_task = 
+							misdn_tasks_add_variable(ch->overlap_dial, misdn_overlap_dial_task, ch);
+					}
+				}
 			}
 		}
       

Modified: team/crichter/0.4.0/channels/misdn_config.c
URL: http://svn.digium.com/view/asterisk/team/crichter/0.4.0/channels/misdn_config.c?rev=37376&r1=37375&r2=37376&view=diff
==============================================================================
--- team/crichter/0.4.0/channels/misdn_config.c (original)
+++ team/crichter/0.4.0/channels/misdn_config.c Tue Jul 11 06:00:21 2006
@@ -990,6 +990,8 @@
 		return;
 	}
 
+	ast_mutex_init(&config_mutex);
+
 	misdn_cfg_lock();
 
 	if (this_max_ports) {



More information about the asterisk-commits mailing list