Revision
14903
Author
gmaruzz
Date
2009-09-17 12:51:11 -0500 (Thu, 17 Sep 2009)

Log Message

celliax: it has not to answer each call is incoming: go to the RING state, wait for an explicit answer()

Modified Paths

Diff

Modified: freeswitch/branches/gmaruzz/mod_celliax/celliax.h (14902 => 14903)


--- freeswitch/branches/gmaruzz/mod_celliax/celliax.h	2009-09-17 17:27:15 UTC (rev 14902)
+++ freeswitch/branches/gmaruzz/mod_celliax/celliax.h	2009-09-17 17:51:11 UTC (rev 14903)
@@ -128,7 +128,7 @@
 #define CELLIAX_CAUSE_FAILURE		2
 #define CELLIAX_CAUSE_NO_ANSWER		3
 /*********************************/
-#define CELLIAX_FRAME_DTMF			1
+#define CELLIAX_FRAME_DTMF		1
 /*********************************/
 #define CELLIAX_CONTROL_RINGING		1
 #define CELLIAX_CONTROL_ANSWER		2
@@ -136,22 +136,22 @@
 #define CELLIAX_CONTROL_BUSY		4
 
 /*********************************/
-#define		CELLIAX_STATE_IDLE					0
-#define		CELLIAX_STATE_DOWN					1
-#define		CELLIAX_STATE_RING					2
+#define		CELLIAX_STATE_IDLE				0
+#define		CELLIAX_STATE_DOWN				1
+#define		CELLIAX_STATE_RING				2
 #define		CELLIAX_STATE_DIALING				3
-#define		CELLIAX_STATE_BUSY					4
-#define		CELLIAX_STATE_UP					5
+#define		CELLIAX_STATE_BUSY				4
+#define		CELLIAX_STATE_UP				5
 #define		CELLIAX_STATE_RINGING				6
 #define		CELLIAX_STATE_PRERING				7
-#define		CELLIAX_STATE_ERROR_DOUBLE_CALL		8
+#define		CELLIAX_STATE_ERROR_DOUBLE_CALL			8
 #define		CELLIAX_STATE_SELECTED				9
-#define 	CELLIAX_STATE_HANGUP_REQUESTED		10
+#define 	CELLIAX_STATE_HANGUP_REQUESTED			10
 #define		CELLIAX_STATE_PREANSWER				11
 /*********************************/
 /* call flow from the device */
-#define 	CALLFLOW_CALL_IDLE					0
-#define 	CALLFLOW_CALL_DOWN					1
+#define 	CALLFLOW_CALL_IDLE				0
+#define 	CALLFLOW_CALL_DOWN				1
 #define 	CALLFLOW_INCOMING_RING				2
 #define 	CALLFLOW_CALL_DIALING				3
 #define 	CALLFLOW_CALL_LINEBUSY				4
@@ -163,7 +163,7 @@
 #define 	CALLFLOW_CALL_INCOMING				10
 #define 	CALLFLOW_CALL_FAILED				11
 #define 	CALLFLOW_CALL_NOSERVICE				12
-#define 	CALLFLOW_CALL_OUTGOINGRESTRICTED	13
+#define 	CALLFLOW_CALL_OUTGOINGRESTRICTED		13
 #define 	CALLFLOW_CALL_SECURITYFAIL			14
 #define 	CALLFLOW_CALL_NOANSWER				15
 #define 	CALLFLOW_STATUS_FINISHED			16
@@ -178,6 +178,7 @@
 #define 	CALLFLOW_INCOMING_CALLID			25
 #define 	CALLFLOW_STATUS_REMOTEHOLD			26
 #define 	CALLFLOW_CALL_REMOTEANSWER			27
+#define 	CALLFLOW_CALL_HANGUP_REQUESTED			28
 
 /*********************************/
 
@@ -558,3 +559,4 @@
 void celliax_store_boost(char *s, double *boost);
 int celliax_sound_boost(void *data, int samples_num, double boost);
 int sms_incoming(private_t * tech_pvt, char *value);
+int celliax_ring(private_t * tech_pvt);

Modified: freeswitch/branches/gmaruzz/mod_celliax/celliax_protocol.c (14902 => 14903)


--- freeswitch/branches/gmaruzz/mod_celliax/celliax_protocol.c	2009-09-17 17:27:15 UTC (rev 14902)
+++ freeswitch/branches/gmaruzz/mod_celliax/celliax_protocol.c	2009-09-17 17:51:11 UTC (rev 14903)
@@ -704,12 +704,14 @@
 					switch_core_session_t *session = NULL;
 					switch_channel_t *channel = NULL;
 
+tech_pvt->interface_state = CELLIAX_STATE_DOWN;
+
 					session = switch_core_session_locate(tech_pvt->session_uuid_str);
 					if(session){
 						channel = switch_core_session_get_channel(session);
-						switch_channel_hangup(channel, 0);
 						//celliax_hangup(tech_pvt);
 						switch_core_session_rwunlock(session);
+						switch_channel_hangup(channel, 0);
 					}
 					//
 					//tech_pvt->owner->hangupcause = CELLIAX_CAUSE_FAILURE;
@@ -1961,7 +1963,50 @@
 	}
 	return res;
 }
+int celliax_ring(private_t * tech_pvt)
+{
+	int res=0;
+	switch_core_session_t *session = NULL;
+	switch_channel_t *channel = NULL;
 
+	if (option_debug) {
+		DEBUGA_PBX("ENTERING FUNC\n", CELLIAX_P_LOG);
+	}
+
+	session = switch_core_session_locate(tech_pvt->session_uuid_str);
+	if(session){
+		switch_core_session_rwunlock(session);
+		return 0;
+	}
+
+	new_inbound_channel(tech_pvt);
+
+	usleep(10000);
+
+	session = switch_core_session_locate(tech_pvt->session_uuid_str);
+	if(session){
+		channel = switch_core_session_get_channel(session);
+
+		switch_core_session_queue_indication(session, SWITCH_MESSAGE_INDICATE_RINGING);
+		if(channel){
+			switch_channel_mark_ring_ready(channel);
+		} else {
+			ERRORA("no session\n", CELLIAX_P_LOG);
+		}
+		switch_core_session_rwunlock(session);
+	} else {
+		ERRORA("no session\n", CELLIAX_P_LOG);
+
+	}
+
+
+	if (option_debug) {
+		DEBUGA_PBX("EXITING FUNC\n", CELLIAX_P_LOG);
+	}
+	return res;
+}
+
+
 /*! \brief  Hangup celliax call
  * Part of PBX interface, called from ast_hangup */
 

Modified: freeswitch/branches/gmaruzz/mod_celliax/mod_celliax.c (14902 => 14903)


--- freeswitch/branches/gmaruzz/mod_celliax/mod_celliax.c	2009-09-17 17:27:15 UTC (rev 14902)
+++ freeswitch/branches/gmaruzz/mod_celliax/mod_celliax.c	2009-09-17 17:51:11 UTC (rev 14903)
@@ -521,6 +521,8 @@
 	tech_pvt = switch_core_session_get_private(session);
 	switch_assert(tech_pvt != NULL);
 
+tech_pvt->phone_callflow = CALLFLOW_CALL_HANGUP_REQUESTED;
+
 	if (!switch_channel_test_flag(channel, CF_ANSWERED)) {
 		if (switch_channel_direction(channel) == SWITCH_CALL_DIRECTION_OUTBOUND) {
 			tech_pvt->ob_failed_calls++;
@@ -529,6 +531,7 @@
 		}
 	}
 
+
 	DEBUGA_CELLIAX("%s CHANNEL HANGUP\n", CELLIAX_P_LOG, tech_pvt->name);
 	switch_clear_flag(tech_pvt, TFLAG_IO);
 	switch_clear_flag(tech_pvt, TFLAG_VOICE);
@@ -847,6 +850,36 @@
 	tech_pvt = switch_core_session_get_private(session);
 	switch_assert(tech_pvt != NULL);
 
+	//ERRORA("%s CHANNEL INIT\n", CELLIAX_P_LOG, tech_pvt->name);
+	switch_set_flag(tech_pvt, TFLAG_IO);
+celliax_serial_answer(tech_pvt);
+
+	/* Move channel's state machine to ROUTING. This means the call is trying
+	   to get from the initial start where the call because, to the point
+	   where a destination has been identified. If the channel is simply
+	   left in the initial state, nothing will happen. */
+	switch_channel_set_state(channel, CS_ROUTING);
+	switch_mutex_lock(globals.mutex);
+	globals.calls++;
+
+	switch_mutex_unlock(globals.mutex);
+	DEBUGA_CELLIAX("%s CHANNEL ANSWER %s\n", CELLIAX_P_LOG, tech_pvt->name, switch_core_session_get_uuid(session));
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
 	DEBUGA_CELLIAX("ANSWERED! \n", CELLIAX_P_LOG);
 
 	return SWITCH_STATUS_SUCCESS;
@@ -1721,7 +1754,7 @@
 		}
 	}
 	if (channel) {
-		switch_channel_mark_answered(channel);
+		//switch_channel_mark_answered(channel);
 	}
 
 	DEBUGA_CELLIAX("new_inbound_channel\n", CELLIAX_P_LOG);
@@ -2169,9 +2202,12 @@
 				tech_pvt->controldev_dead = 1;
 				close(tech_pvt->controldevfd);
 				ERRORA("celliax_serial_monitor failed, declaring %s dead\n", CELLIAX_P_LOG, tech_pvt->controldevice_name);
-			} else if (tech_pvt->controldevprotocol != PROTOCOL_NO_SERIAL && tech_pvt->interface_state == CELLIAX_STATE_RING) {
-				WARNINGA("INCOMING RING, let's take the incoming call\n", CELLIAX_P_LOG);
-				celliax_answer(tech_pvt);
+			} else if (tech_pvt->controldevprotocol != PROTOCOL_NO_SERIAL && tech_pvt->interface_state == CELLIAX_STATE_RING && tech_pvt->phone_callflow != CALLFLOW_CALL_HANGUP_REQUESTED ) {
+				WARNINGA("INCOMING RING\n", CELLIAX_P_LOG);
+
+				celliax_ring(tech_pvt);
+
+				//FIXME celliax_answer(tech_pvt);
 				//new_inbound_channel(tech_pvt);
 				//FIXME if (!celliax_new(p, AST_STATE_RING, tech_pvt->context)) {
 				//FIXME ERRORA("celliax_new failed! BAD BAD BAD\n", CELLIAX_P_LOG);
@@ -2303,7 +2339,7 @@
 		switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "proto", MDL_CHAT_PROTO);
 		switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "login", tech_pvt->name);
 		//switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "hint", tech_pvt->chatmessages[which].from_dispname);
-		//switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "from", tech_pvt->chatmessages[which].from_handle);
+		switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "from", "333444555"); //FIXME
 		switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "subject", "SIMPLE MESSAGE");
 		//switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "chatname", tech_pvt->chatmessages[which].chatname);
 		//switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "id", tech_pvt->chatmessages[which].id);