[Feature][T8TSK-187][Call]handle updates in real time when the status of a call changes

Change-Id: I8604b78c6f1f448c6e0b884092256ac5d35148e8
diff --git a/src/lynq/lib/liblynq-call/lynq_call.cpp b/src/lynq/lib/liblynq-call/lynq_call.cpp
index 678b0f5..d973bc7 100755
--- a/src/lynq/lib/liblynq-call/lynq_call.cpp
+++ b/src/lynq/lib/liblynq-call/lynq_call.cpp
@@ -386,9 +386,10 @@
     pthread_cond_signal(&call_state_change_cond);

     pthread_mutex_unlock(&call_state_change_mutex);

 }

-void send_call_state_change()

+void send_call_state_change(int callid)

 {

     LYINFLOG("send call state change");

+    s_CallId = callid;

     pthread_mutex_lock(&s_call_state_change_mutex);

     pthread_cond_signal(&s_call_state_change_cond);

     pthread_mutex_unlock(&s_call_state_change_mutex);

@@ -418,6 +419,7 @@
 #endif

     pthread_mutex_lock(&s_notice_get_call_list_mutex);

     pthread_cleanup_push(cleanup_call_list_mutex, NULL); // thread cleanup handler

+    int tmp_call_id;

     while(s_call_list_loop)

     {

         update=0;       

@@ -458,10 +460,10 @@
                 {

                     LYINFLOG("MT/MO hungup,then clean call info local idx is %d id is %d",i, s_call_lists[i].call_id);

                     //update_end_state(i);//lei modify for:update end state for this call

+                    tmp_call_id = s_call_lists[i].call_id;

                     cleanCallList(i);

                     //Release the end handle

-                    //s_CallId = 

-                    send_call_state_change();//means mt/mo call is end

+                    send_call_state_change(tmp_call_id);//means mt/mo call is end

                     //cleanCallList(i);

                 }

             } //fix bug API-54

@@ -508,8 +510,7 @@
                 {

                     n = addAddr(call_list[i].addr,call_list[i].call_id);

                     updateCallList(&s_call_lists[n],call_list[i].call_id,call_list[i].call_state,call_list[i].toa,call_list[i].direction);

-                    s_CallId = call_list[i].call_id;

-                    send_call_state_change();

+                    send_call_state_change(call_list[i].call_id);

                 }

                 else if(s_call_lists[n].call_state == call_list[i].call_state)

                 {

@@ -521,7 +522,7 @@
                         **fix bug API-54

                         */

                         LYINFLOG("resend incoming call signal");

-                        send_call_state_change();

+                        send_call_state_change(call_list[i].call_id);

                     }

                 }

                 else 

@@ -529,7 +530,7 @@
                     LYINFLOG("state changed from %d to %d",s_call_lists[n].call_state,call_list[i].call_state);

                     

                     updateCallList(&s_call_lists[n],call_list[i].call_id,call_list[i].call_state,call_list[i].toa,call_list[i].direction);//update mt call

-                    send_call_state_change();

+                    send_call_state_change(call_list[i].call_id);

                 }                            

             }

             else

@@ -544,12 +545,11 @@
                         {

                             LYINFLOG("add a call id");

                             update=1;//for send sigal

-                            s_CallId = call_list[i].call_id;

                         }

                         LYINFLOG("local idx %d updated, original call id is %d origial addr is %s original state is %d",n,s_call_lists[n].call_id,s_call_lists[n].addr,s_call_lists[n].call_state);                    

                         updateCallList(&s_call_lists[n],call_list[i].call_id,call_list[i].call_state,call_list[i].toa,call_list[i].direction);

                         call_end = 1;

-                        send_call_state_change();//means mo call is success

+                        send_call_state_change(call_list[i].call_id);//means mo call is success

                         break;

                     }                    

                 }

@@ -890,14 +890,17 @@
     LYINFLOG("wait Call state Change");

     int ret = 0;

     int sec = 0;

-    int usec = 0;

+    int ms  = 0;

     struct timeval now;

     struct timespec timeout;

     gettimeofday(&now,NULL);

     sec = mtime/1000;

-    usec = mtime%1000;

+    ms  = mtime%1000;

     timeout.tv_sec = now.tv_sec+sec;

-    timeout.tv_nsec = now.tv_usec*1000+usec*1000000;

+    unsigned long long ns;

+    ns = now.tv_usec*1000ull + ms*1000000ull;

+    timeout.tv_sec += ns/1000000000;

+    timeout.tv_nsec = ns % 1000000000;

     pthread_mutex_lock(&call_state_change_mutex);

     ret = pthread_cond_timedwait(&call_state_change_cond,&call_state_change_mutex,&timeout);

     pthread_mutex_unlock(&call_state_change_mutex);

@@ -956,7 +959,6 @@
         s_module_isDial = 0;      

         LYERRLOG("lynq_call timeout:wait Call state fail!!! clear local idx %d",lynq_call_id);

         cleanCallList(lynq_call_id);

-        send_call_state_change();

         return LYNQ_E_TIME_OUT;

     }

     s_module_isDial = 0;

@@ -970,7 +972,6 @@
     {   

         LYERRLOG("lynq_call dial addr %s fail, invalid id",addr);

         cleanCallList(lynq_call_id);

-        send_call_state_change();

         return LYNQ_E_INVALID_ID_ANONALY;

     }        

 }

@@ -1011,17 +1012,16 @@
     if(ret!=0)

     {

         return ret; 

-    }     

+    }

     delete p; 

 

     int lynq_call_id=find_call_id_with_call_id(call_id);

-    /* lei  modify for API-857

     if(lynq_call_id!=INVALID_ID)

     {

+        //lei  modify for API-857

         cleanCallList(lynq_call_id);

+        send_call_state_change(call_id);

     }

-    */

-    

     return RESULT_OK;

 }

 int lynq_call_hungup_all()

@@ -1092,20 +1092,17 @@
         LYERRLOG("handle is NULL");

         return LYNQ_E_PARAMETER_ANONALY;

     }

+    if((*handle) <= 0)

+    {

+        LYINFLOG("lynq_get_current_call_state input error %d\n ", *handle);

+        return LYNQ_E_INVALID_ID_ANONALY;

+    }

     LYINFLOG("lynq_get_current_call_state %d\n ", *handle);

     lynq_call_id = find_call_id_with_call_id(*handle);

     if(lynq_call_id==INVALID_ID)

     {

-        //find end state

-        if((*handle) >= 0)

-        {

-            *call_state = (int)LYNQ_CALL_END;

-            return RESULT_OK; 

-        }

-        else

-        {

-            return LYNQ_E_INVALID_ID_ANONALY;

-        }

+        *call_state = (int)LYNQ_CALL_END;

+        return RESULT_OK;

     }

     *call_state = s_call_lists[lynq_call_id].call_state;

     *toa = s_call_lists[lynq_call_id].toa;