summaryrefslogtreecommitdiff
path: root/toxav/msi.c
diff options
context:
space:
mode:
Diffstat (limited to 'toxav/msi.c')
-rw-r--r--toxav/msi.c41
1 files changed, 20 insertions, 21 deletions
diff --git a/toxav/msi.c b/toxav/msi.c
index 999f86b6..6409b314 100644
--- a/toxav/msi.c
+++ b/toxav/msi.c
@@ -538,8 +538,9 @@ GENERIC_SETTER_DEFINITION ( callid )
538 538
539 539
540typedef struct _Timer { 540typedef struct _Timer {
541 void *(*func)(void *); 541 void *(*func)(void *, int);
542 void *func_args; 542 void *func_arg1;
543 int func_arg2;
543 uint64_t timeout; 544 uint64_t timeout;
544 size_t idx; 545 size_t idx;
545 546
@@ -567,7 +568,7 @@ typedef struct _TimerHandler {
567 * @param timeout Timeout in ms 568 * @param timeout Timeout in ms
568 * @return int 569 * @return int
569 */ 570 */
570int timer_alloc ( TimerHandler *timers_container, void *(func)(void *), void *arg, unsigned timeout) 571int timer_alloc ( TimerHandler *timers_container, void *(func)(void *, int), void *arg1, int arg2, unsigned timeout)
571{ 572{
572 pthread_mutex_lock(&timers_container->mutex); 573 pthread_mutex_lock(&timers_container->mutex);
573 574
@@ -592,7 +593,8 @@ int timer_alloc ( TimerHandler *timers_container, void *(func)(void *), void *ar
592 timers_container->size ++; 593 timers_container->size ++;
593 594
594 timer->func = func; 595 timer->func = func;
595 timer->func_args = arg; 596 timer->func_arg1 = arg1;
597 timer->func_arg2 = arg2;
596 timer->timeout = timeout + current_time_monotonic(); /* In ms */ 598 timer->timeout = timeout + current_time_monotonic(); /* In ms */
597 timer->idx = i; 599 timer->idx = i;
598 600
@@ -672,15 +674,9 @@ void *timer_poll( void *arg )
672 674
673 uint64_t time = current_time_monotonic(); 675 uint64_t time = current_time_monotonic();
674 676
675 while ( handler->timers[0] && handler->timers[0]->timeout < time ) { 677 if ( handler->timers[0] && handler->timers[0]->timeout < time ) {
676 678 handler->timers[0]->func(handler->timers[0]->func_arg1, handler->timers[0]->func_arg2);
677 pthread_t _tid; 679 LOGGER_DEBUG("Exectued timer assigned at: %d", handler->timers[0]->timeout);
678
679 if ( 0 != pthread_create(&_tid, NULL, handler->timers[0]->func, handler->timers[0]->func_args) ||
680 0 != pthread_detach(_tid) )
681 LOGGER_ERROR("Failed to execute timer at: %d!", handler->timers[0]->timeout);
682
683 else LOGGER_DEBUG("Exectued timer assigned at: %d", handler->timers[0]->timeout);
684 680
685 timer_release(handler, 0); 681 timer_release(handler, 0);
686 } 682 }
@@ -1142,18 +1138,20 @@ int terminate_call ( MSISession *session, MSICall *call )
1142 * @param arg Control session 1138 * @param arg Control session
1143 * @return void* 1139 * @return void*
1144 */ 1140 */
1145void *handle_timeout ( void *arg ) 1141void *handle_timeout ( void *arg1, int arg2 )
1146{ 1142{
1147 /* TODO: Cancel might not arrive there; set up 1143 /* TODO: Cancel might not arrive there; set up
1148 * timers on these cancels and terminate call on 1144 * timers on these cancels and terminate call on
1149 * their timeout 1145 * their timeout
1150 */ 1146 */
1151 MSICall *_call = arg; 1147 int call_index = arg2;
1148 MSISession *session = arg1;
1149 MSICall *_call = session->calls[call_index];
1152 1150
1153 if (_call) { 1151 if (_call) {
1154 LOGGER_DEBUG("[Call: %s] Request timed out!", _call->id); 1152 LOGGER_DEBUG("[Call: %s] Request timed out!", _call->id);
1155 1153
1156 invoke_callback(_call->call_idx, MSI_OnRequestTimeout); 1154 invoke_callback(call_index, MSI_OnRequestTimeout);
1157 } 1155 }
1158 1156
1159 if ( _call && _call->session ) { 1157 if ( _call && _call->session ) {
@@ -1347,7 +1345,8 @@ int handle_recv_ringing ( MSISession *session, MSICall *call, MSIMessage *msg )
1347 1345
1348 LOGGER_DEBUG("Session: %p Handling 'ringing' on call: %s", session, call->id ); 1346 LOGGER_DEBUG("Session: %p Handling 'ringing' on call: %s", session, call->id );
1349 1347
1350 call->ringing_timer_id = timer_alloc ( session->timer_handler, handle_timeout, call, call->ringing_tout_ms ); 1348 call->ringing_timer_id = timer_alloc ( session->timer_handler, handle_timeout, session, call->call_idx,
1349 call->ringing_tout_ms );
1351 1350
1352 pthread_mutex_unlock(&session->mutex); 1351 pthread_mutex_unlock(&session->mutex);
1353 1352
@@ -1725,7 +1724,7 @@ int msi_invite ( MSISession *session, int32_t *call_index, MSICallType call_type
1725 1724
1726 _call->state = call_inviting; 1725 _call->state = call_inviting;
1727 1726
1728 _call->request_timer_id = timer_alloc ( session->timer_handler, handle_timeout, _call, m_deftout ); 1727 _call->request_timer_id = timer_alloc ( session->timer_handler, handle_timeout, session, _call->call_idx, m_deftout );
1729 1728
1730 LOGGER_DEBUG("Invite sent"); 1729 LOGGER_DEBUG("Invite sent");
1731 1730
@@ -1774,7 +1773,7 @@ int msi_hangup ( MSISession *session, int32_t call_index )
1774 free_message ( _msg_end ); 1773 free_message ( _msg_end );
1775 1774
1776 session->calls[call_index]->request_timer_id = 1775 session->calls[call_index]->request_timer_id =
1777 timer_alloc ( session->timer_handler, handle_timeout, session->calls[call_index], m_deftout ); 1776 timer_alloc ( session->timer_handler, handle_timeout, session, call_index, m_deftout );
1778 1777
1779 pthread_mutex_unlock(&session->mutex); 1778 pthread_mutex_unlock(&session->mutex);
1780 return 0; 1779 return 0;
@@ -1850,7 +1849,7 @@ int msi_cancel ( MSISession *session, int32_t call_index, uint32_t peer, const c
1850 free_message ( _msg_cancel ); 1849 free_message ( _msg_cancel );
1851 1850
1852 /*session->calls[call_index]->state = call_hanged_up; 1851 /*session->calls[call_index]->state = call_hanged_up;
1853 session->calls[call_index]->request_timer_id = timer_alloc ( handle_timeout, session->calls[call_index], m_deftout );*/ 1852 session->calls[call_index]->request_timer_id = timer_alloc ( handle_timeout, session, call_index, m_deftout );*/
1854 terminate_call ( session, session->calls[call_index] ); 1853 terminate_call ( session, session->calls[call_index] );
1855 pthread_mutex_unlock(&session->mutex); 1854 pthread_mutex_unlock(&session->mutex);
1856 1855
@@ -1887,7 +1886,7 @@ int msi_reject ( MSISession *session, int32_t call_index, const uint8_t *reason
1887 session->calls[call_index]->state = call_hanged_up; 1886 session->calls[call_index]->state = call_hanged_up;
1888 1887
1889 session->calls[call_index]->request_timer_id = 1888 session->calls[call_index]->request_timer_id =
1890 timer_alloc ( session->timer_handler, handle_timeout, session->calls[call_index], m_deftout ); 1889 timer_alloc ( session->timer_handler, handle_timeout, session, call_index, m_deftout );
1891 1890
1892 pthread_mutex_unlock(&session->mutex); 1891 pthread_mutex_unlock(&session->mutex);
1893 return 0; 1892 return 0;