[bugfix]
1.API-54
2.fix the bug if mt huangup call,we need clean the calllist

Change-Id: Ia2ee4afd2f3453fa990f50760e1165f75fd47414
diff --git a/lib/liblynq-call/lynq_call.cpp b/lib/liblynq-call/lynq_call.cpp
index 198738e..fc6a9da 100755
--- a/lib/liblynq-call/lynq_call.cpp
+++ b/lib/liblynq-call/lynq_call.cpp
@@ -291,6 +291,7 @@
 }

 void updateCallList(lynq_call_list_e_t *callList,    int call_id,int call_state,int toa,int direction)

 {

+    LYINFLOG("Update Call List");

     callList->call_id = call_id;

     callList->call_state = call_state;

     callList->toa = toa;

@@ -301,6 +302,7 @@
 }

 int waitCallstateChange(int mtime)

 {

+    LYINFLOG("wait Call state Change");

     int ret = 0;

     int sec = 0;

     int usec = 0;

@@ -318,6 +320,7 @@
 }

 int waitIncomingCall()

 {

+    LYINFLOG("wait incming call");

     int ret = 0;

     pthread_mutex_lock(&s_incoming_call_mutex);

     ret = pthread_cond_wait(&s_incoming_call_cond,&s_incoming_call_mutex);

@@ -326,6 +329,7 @@
 }

 int checkHasCall(char addr[])

 {

+    LYINFLOG("check has call");

     for(int i = 0;i<LYNQ_CALL_MAX;i++)

     {

         if(strcmp(lynq_call_lists[i].addr,addr)==0)

@@ -335,14 +339,28 @@
     }

     return 0;

 }

+int find_call_id_with_addr(char *addr)

+{

+    LYINFLOG("find call id with addr!!!");

+    for(int id = 0; id < LYNQ_CALL_MAX; id++)

+    {

+        if(strcmp(lynq_call_lists[id].addr,addr) == 0)

+        {

+            return id;

+        }

+    }

+    return -1;

+}

 void sendSignalToWaitCallStateChange()

 {

+    LYINFLOG("send Signal To Wait Call State Change");

     pthread_mutex_lock(&call_state_change_mutex);

     pthread_cond_signal(&call_state_change_cond);

     pthread_mutex_unlock(&call_state_change_mutex);

 }

 void sendSignalIncomingCall()

 {

+    LYINFLOG("send incoming call signal");

     pthread_mutex_lock(&s_incoming_call_mutex);

     pthread_cond_signal(&s_incoming_call_cond);

     pthread_mutex_unlock(&s_incoming_call_mutex);

@@ -363,6 +381,8 @@
 void *triggerGetCallList(void *parg)

 {

     int ret=0;

+    bool call_end;

+    call_end = 0;//0:this call end,1:call on

     lynq_call_list_t call_list[LYNQ_CALL_MAX];

     while(call_list_loop)

     {

@@ -376,8 +396,27 @@
             LYDBGLOG("get current call list failure!!!\n");

             continue;

         }

+        LYINFLOG("++++++++++++++triggerGetCallList++++++++++++++");

         for(int i = 0;i < LYNQ_CALL_MAX;i++)

         {

+            if(strlen(lynq_call_lists[i].addr) != 0)

+            {

+                call_end = 0;

+                for(int id = 0; id < LYNQ_CALL_MAX; id++)

+                {

+                    if(strcmp(call_list[id].addr,lynq_call_lists[i].addr) == 0)

+                    {

+                        call_end = 1;

+                        LYINFLOG("find lynq call i %d, id %d!!!",i,id);

+                    }

+                }

+                if(call_end == 0)

+                {

+                    LYINFLOG("MT hungup,then clean call info");

+                    cleanCallList(i);

+                    continue;

+                }

+            } //fix bug API-54

             if(call_list[i].direction == 1)//MT call

             {

                 if(call_list[i].call_state ==4)//LYNQ_CALL_INCOMING = 4,   /* MT call only */

@@ -389,6 +428,18 @@
                         addCallListToLynqCallList(&lynq_call_lists[lynqIncomingCallId],call_list[i].call_id,call_list[i].call_state,call_list[i].toa,call_list[i].direction,call_list[i].addr);

                         sendSignalIncomingCall();

                     }

+                    else

+                    {

+                        int temp_call_id = find_call_id_with_addr(call_list[i].addr);

+                        /*if call state not change,Maybe this call was ignored, so we need to continue to inform the user of 

+                        **an incoming call until the status changes.

+                        **fix bug API-54

+                        */

+                        if((temp_call_id > 0) && (lynq_call_lists[temp_call_id].call_state == call_list[i].call_state))

+                        {

+                            sendSignalIncomingCall();

+                        }

+                    }

                 }

                 /*if state changed*/

                 else

@@ -412,10 +463,11 @@
                 }

                 for(int n = 0 ; n < LYNQ_CALL_MAX; n++)

                 {

-                    if(lynq_call_lists[n].hasTimeout==1)

+                    if((lynq_call_lists[n].hasTimeout == 1) && (strcmp(lynq_call_lists[n].addr,call_list[i].addr) == 0))

                     {

-                        /*hangup call with id*/

-                        lynq_call_hungup(&n);

+                        cleanCallList(n);//if this call time out,need clean lynq call list.

+                        /*hangup call with call id*/

+                        lynq_call_hungup(&call_list[i].call_id);

                         lynq_call_lists[n].hasTimeout==0;

                         continue;

                     }

@@ -801,6 +853,9 @@
         isDial = 1;

         if(waitCallstateChange(6000)==ETIMEDOUT)//6000ms

         {

+            //if timeout,this call need destroy.

+            isDial = 0;

+

             error = LYNQ_E_TIME_OUT;

             LYERRLOG("timeout:wait Call state fail!!!");

             lynq_call_lists[lynq_call_id].hasTimeout = 1;