Revision
16787
Author
sathieu
Date
2010-02-24 06:05:26 -0600 (Wed, 24 Feb 2010)

Log Message

Skinny: Line state

Avoid the use of TFLAG_WAITING_DEST an replace by a line_state corresponding to the softkey events

Modified Paths

Diff

Modified: freeswitch/trunk/src/mod/endpoints/mod_skinny/mod_skinny.c (16786 => 16787)


--- freeswitch/trunk/src/mod/endpoints/mod_skinny/mod_skinny.c	2010-02-24 12:05:16 UTC (rev 16786)
+++ freeswitch/trunk/src/mod/endpoints/mod_skinny/mod_skinny.c	2010-02-24 12:05:26 UTC (rev 16787)
@@ -238,7 +238,29 @@
 /*****************************************************************************/
 /* CHANNEL FUNCTIONS */
 /*****************************************************************************/
+uint32_t skinny_line_perform_set_state(listener_t *listener, const char *file, const char *func, int line, uint32_t instance, uint32_t state, uint32_t call_id)
+{
+	switch_assert(listener);
+	
+	if(listener->session[instance]) {
+		switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(listener->session[instance]), SWITCH_LOG_DEBUG, "Device %s, line %d State Change %d -> %d\n",
+			listener->device_name, instance, listener->line_state[instance], state);
+	} else {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Device %s, line %d State Change %d -> %d (no session)\n",
+			listener->device_name, instance, listener->line_state[instance], state);
+	}
+	send_select_soft_keys(listener, instance, call_id, state, 0xffff);
+	listener->line_state[instance] = state;
+	
+	return listener->line_state[instance];
+}
 
+uint32_t skinny_line_get_state(listener_t *listener, uint32_t instance)
+{
+	switch_assert(listener);
+
+	return listener->line_state[instance];
+}
 switch_status_t skinny_tech_set_codec(private_t *tech_pvt, int force)
 {
 	int ms;

Modified: freeswitch/trunk/src/mod/endpoints/mod_skinny/mod_skinny.h (16786 => 16787)


--- freeswitch/trunk/src/mod/endpoints/mod_skinny/mod_skinny.h	2010-02-24 12:05:16 UTC (rev 16786)
+++ freeswitch/trunk/src/mod/endpoints/mod_skinny/mod_skinny.h	2010-02-24 12:05:26 UTC (rev 16787)
@@ -112,6 +112,7 @@
 	skinny_profile_t *profile;
 	char device_name[16];
 	switch_core_session_t *session[SKINNY_MAX_LINES];
+	uint32_t line_state[SKINNY_MAX_LINES]; /* See enum skinny_key_set */
 
 	switch_socket_t *sock;
 	switch_memory_pool_t *pool;
@@ -145,9 +146,7 @@
 	TFLAG_BREAK = (1 << 8),
 	
 	TFLAG_READING = (1 << 9),
-	TFLAG_WRITING = (1 << 10),
-	
-	TFLAG_WAITING_DEST = (1 << 11)
+	TFLAG_WRITING = (1 << 10)
 } TFLAGS;
 
 typedef enum {
@@ -204,6 +203,11 @@
 /*****************************************************************************/
 /* CHANNEL FUNCTIONS */
 /*****************************************************************************/
+uint32_t skinny_line_perform_set_state(listener_t *listener, const char *file, const char *func, int line, uint32_t instance, uint32_t state, uint32_t call_id);
+#define  skinny_line_set_state(listener, instance, state, call_id)  skinny_line_perform_set_state(listener, __FILE__, __SWITCH_FUNC__, __LINE__, instance, state, call_id)
+
+uint32_t skinny_line_get_state(listener_t *listener, uint32_t instance);
+
 switch_status_t skinny_tech_set_codec(private_t *tech_pvt, int force);
 void tech_init(private_t *tech_pvt, switch_core_session_t *session);
 switch_status_t channel_on_init(switch_core_session_t *session);

Modified: freeswitch/trunk/src/mod/endpoints/mod_skinny/skinny_protocol.c (16786 => 16787)


--- freeswitch/trunk/src/mod/endpoints/mod_skinny/skinny_protocol.c	2010-02-24 12:05:16 UTC (rev 16786)
+++ freeswitch/trunk/src/mod/endpoints/mod_skinny/skinny_protocol.c	2010-02-24 12:05:26 UTC (rev 16787)
@@ -308,8 +308,6 @@
 
 	tech_init(tech_pvt, session);
 
-	switch_set_flag_locked(tech_pvt, TFLAG_WAITING_DEST);
-
 	set_ringer(listener, SKINNY_RING_OFF, SKINNY_RING_FOREVER, 0);
 	set_speaker_mode(listener, SKINNY_SPEAKER_ON);
 	set_lamp(listener, SKINNY_BUTTON_LINE, tech_pvt->line, SKINNY_LAMP_ON);
@@ -317,8 +315,7 @@
 		SKINNY_OFF_HOOK,
 		tech_pvt->line,
 		tech_pvt->call_id);
-	send_select_soft_keys(listener, tech_pvt->line, tech_pvt->call_id,
-		SKINNY_KEY_SET_OFF_HOOK, 0xffff);
+	skinny_line_set_state(listener, tech_pvt->line, SKINNY_KEY_SET_OFF_HOOK, tech_pvt->call_id);
 	display_prompt_status(listener,
 		0,
 		"\200\000",
@@ -368,11 +365,7 @@
 		SKINNY_CONNECTED,
 		tech_pvt->line,
 		tech_pvt->call_id);
-	send_select_soft_keys(listener,
-		tech_pvt->line,
-		tech_pvt->call_id,
-		SKINNY_KEY_SET_CONNECTED,
-		0xffff);
+	skinny_line_set_state(listener, tech_pvt->line, SKINNY_KEY_SET_CONNECTED, tech_pvt->call_id);
 	display_prompt_status(listener,
 		0,
 		"\200\030",
@@ -1474,21 +1467,20 @@
 
 		/* TODO check call_id and line */
 
-		if(switch_test_flag(tech_pvt, TFLAG_WAITING_DEST)) {
+		if((skinny_line_get_state(listener, tech_pvt->line) == SKINNY_KEY_SET_OFF_HOOK)
+				|| (skinny_line_get_state(listener, tech_pvt->line) == SKINNY_KEY_SET_DIGITS_AFTER_DIALING_FIRST_DIGIT)) {
 			char name[128];
 			switch_channel_t *channel;
 			char *cid_name = "TODO-soft_key_event"; /* TODO */
 			char *cid_num = "00000"; /* TODO */
 			if(strlen(tech_pvt->dest) == 0) {/* first digit */
 				stop_tone(listener, tech_pvt->line, tech_pvt->call_id);
-				send_select_soft_keys(listener, tech_pvt->line, tech_pvt->call_id,
-					SKINNY_KEY_SET_DIGITS_AFTER_DIALING_FIRST_DIGIT, 0xffff);
+				skinny_line_set_state(listener, tech_pvt->line, SKINNY_KEY_SET_DIGITS_AFTER_DIALING_FIRST_DIGIT, tech_pvt->call_id);
 			}
 			
 			tech_pvt->dest[strlen(tech_pvt->dest)] = digit;
 			
 			if(strlen(tech_pvt->dest) >= 4) { /* TODO Number is complete */
-				switch_clear_flag_locked(tech_pvt, TFLAG_WAITING_DEST);
 				if (!(tech_pvt->caller_profile = switch_caller_profile_new(switch_core_session_get_pool(listener->session[line]),
 																		  NULL, listener->profile->dialplan, cid_name, cid_num, listener->remote_ip, NULL, NULL, NULL, "skinny" /* modname */, listener->profile->context, tech_pvt->dest)) != 0) {
 					switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(listener->session[line]), SWITCH_LOG_CRIT, "Error Creating Session caller profile\n");
@@ -1510,11 +1502,7 @@
 					goto error;
 				}
 
-				send_select_soft_keys(listener,
-					tech_pvt->line,
-					tech_pvt->call_id,
-					SKINNY_KEY_SET_CONNECTED,
-					0xffff);
+				skinny_line_set_state(listener, tech_pvt->line, SKINNY_KEY_SET_CONNECTED, tech_pvt->call_id);
 				send_dialed_number(listener, tech_pvt->dest, tech_pvt->line, tech_pvt->call_id);
 				skinny_answer(listener->session[line]);