summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorirungentoo <irungentoo@tox.im>2014-03-11 18:23:38 -0400
committerirungentoo <irungentoo@tox.im>2014-03-11 18:23:38 -0400
commite364c648697279a895cf04b9d3fcb1f7b97d95c9 (patch)
treec3f9bcf879c7bc9268c6b697410ce20815758d63
parent6858d6387d76dd7e61cba147b8c492a33d91c9d5 (diff)
parent54b1dafb0b6f56e1f2f153cf7bf457be9053ae09 (diff)
Merge pull request #796 from mannol1/master
Changed msi callbacks
-rwxr-xr-xtoxav/msi.c54
-rwxr-xr-xtoxav/msi.h2
-rwxr-xr-xtoxav/phone.c32
-rwxr-xr-xtoxav/toxav.h2
4 files changed, 44 insertions, 46 deletions
diff --git a/toxav/msi.c b/toxav/msi.c
index 17c0b5c3..7cc55de2 100755
--- a/toxav/msi.c
+++ b/toxav/msi.c
@@ -36,6 +36,8 @@
36#include <string.h> 36#include <string.h>
37#include <stdlib.h> 37#include <stdlib.h>
38 38
39#define inline__ inline __attribute__((always_inline))
40
39#define same(x, y) strcmp((const char*) x, (const char*) y) == 0 41#define same(x, y) strcmp((const char*) x, (const char*) y) == 0
40 42
41#define MSI_MAXMSG_SIZE 1024 43#define MSI_MAXMSG_SIZE 1024
@@ -117,6 +119,12 @@ static struct _Callbacks {
117 void* data; 119 void* data;
118} callbacks[10] = {0}; 120} callbacks[10] = {0};
119 121
122inline__ void invoke_callback(MSICallbackID id)
123{
124 /*if ( callbacks[id].function ) event.rise ( callbacks[id].function, callbacks[id].data );*/
125 if ( callbacks[id].function ) callbacks[id].function ( callbacks[id].data );
126}
127
120/*static MSICallback callbacks[10] = {0};*/ 128/*static MSICallback callbacks[10] = {0};*/
121 129
122 130
@@ -153,7 +161,7 @@ typedef enum {
153 * @param request The request. 161 * @param request The request.
154 * @return const uint8_t* The string 162 * @return const uint8_t* The string
155 */ 163 */
156static inline const uint8_t *stringify_request ( MSIRequest request ) 164static inline__ const uint8_t *stringify_request ( MSIRequest request )
157{ 165{
158 static const uint8_t *strings[] = { 166 static const uint8_t *strings[] = {
159 ( uint8_t * ) "INVITE", 167 ( uint8_t * ) "INVITE",
@@ -182,7 +190,7 @@ typedef enum {
182 * @param response The response. 190 * @param response The response.
183 * @return const uint8_t* The string 191 * @return const uint8_t* The string
184 */ 192 */
185static inline const uint8_t *stringify_response ( MSIResponse response ) 193static inline__ const uint8_t *stringify_response ( MSIResponse response )
186{ 194{
187 static const uint8_t *strings[] = { 195 static const uint8_t *strings[] = {
188 ( uint8_t * ) "ringing", 196 ( uint8_t * ) "ringing",
@@ -550,7 +558,7 @@ typedef enum {
550 * @param error_code The code. 558 * @param error_code The code.
551 * @return const uint8_t* The string. 559 * @return const uint8_t* The string.
552 */ 560 */
553static inline const uint8_t *stringify_error ( MSICallError error_code ) 561static inline__ const uint8_t *stringify_error ( MSICallError error_code )
554{ 562{
555 static const uint8_t *strings[] = { 563 static const uint8_t *strings[] = {
556 ( uint8_t * ) "", 564 ( uint8_t * ) "",
@@ -572,7 +580,7 @@ static inline const uint8_t *stringify_error ( MSICallError error_code )
572 * @param error_code The code. 580 * @param error_code The code.
573 * @return const uint8_t* The string. 581 * @return const uint8_t* The string.
574 */ 582 */
575static inline const uint8_t *stringify_error_code ( MSICallError error_code ) 583static inline__ const uint8_t *stringify_error_code ( MSICallError error_code )
576{ 584{
577 static const uint8_t *strings[] = { 585 static const uint8_t *strings[] = {
578 ( uint8_t * ) "", 586 ( uint8_t * ) "",
@@ -679,7 +687,7 @@ int handle_error ( MSISession *session, MSICallError errid, uint32_t to )
679 session->last_error_id = errid; 687 session->last_error_id = errid;
680 session->last_error_str = stringify_error ( errid ); 688 session->last_error_str = stringify_error ( errid );
681 689
682 if ( callbacks[MSI_OnError].function ) event.rise ( callbacks[MSI_OnError].function, callbacks[MSI_OnError].data ); 690 invoke_callback(MSI_OnError);
683 691
684 return 0; 692 return 0;
685} 693}
@@ -873,7 +881,7 @@ int handle_recv_invite ( MSISession *session, MSIMessage *msg )
873 send_message ( session, _msg_ringing, msg->friend_id ); 881 send_message ( session, _msg_ringing, msg->friend_id );
874 free_message ( _msg_ringing ); 882 free_message ( _msg_ringing );
875 883
876 if ( callbacks[MSI_OnInvite].function ) event.rise ( callbacks[MSI_OnInvite].function, callbacks[MSI_OnInvite].data ); 884 invoke_callback(MSI_OnInvite);
877 885
878 return 1; 886 return 1;
879} 887}
@@ -897,7 +905,7 @@ int handle_recv_start ( MSISession *session, MSIMessage *msg )
897 905
898 flush_peer_type ( session, msg, 0 ); 906 flush_peer_type ( session, msg, 0 );
899 907
900 if ( callbacks[MSI_OnStart].function ) event.rise ( callbacks[MSI_OnStart].function, callbacks[MSI_OnStart].data ); 908 invoke_callback(MSI_OnStart);
901 909
902 return 1; 910 return 1;
903} 911}
@@ -914,7 +922,9 @@ int handle_recv_reject ( MSISession *session, MSIMessage *msg )
914 free_message ( _msg_end ); 922 free_message ( _msg_end );
915 923
916 event.timer_release ( session->call->request_timer_id ); 924 event.timer_release ( session->call->request_timer_id );
917 if ( callbacks[MSI_OnReject].function ) event.rise ( callbacks[MSI_OnReject].function, callbacks[MSI_OnReject].data ); 925
926 invoke_callback(MSI_OnReject);
927
918 session->call->request_timer_id = event.timer_alloc ( handle_timeout, session, m_deftout ); 928 session->call->request_timer_id = event.timer_alloc ( handle_timeout, session, m_deftout );
919 929
920 return 1; 930 return 1;
@@ -925,12 +935,11 @@ int handle_recv_cancel ( MSISession *session, MSIMessage *msg )
925 935
926 if ( has_call_error ( session, msg ) == 0 ) 936 if ( has_call_error ( session, msg ) == 0 )
927 return 0; 937 return 0;
928 938
929 939 invoke_callback(MSI_OnCancel);
940
930 terminate_call ( session ); 941 terminate_call ( session );
931 942
932 if ( callbacks[MSI_OnCancel].function ) event.rise ( callbacks[MSI_OnCancel].function, callbacks[MSI_OnCancel].data );
933
934 return 1; 943 return 1;
935} 944}
936int handle_recv_end ( MSISession *session, MSIMessage *msg ) 945int handle_recv_end ( MSISession *session, MSIMessage *msg )
@@ -945,10 +954,9 @@ int handle_recv_end ( MSISession *session, MSIMessage *msg )
945 send_message ( session, _msg_ending, msg->friend_id ); 954 send_message ( session, _msg_ending, msg->friend_id );
946 free_message ( _msg_ending ); 955 free_message ( _msg_ending );
947 956
948 terminate_call ( session ); 957 invoke_callback(MSI_OnEnd);
949
950 if ( callbacks[MSI_OnEnd].function ) event.rise ( callbacks[MSI_OnEnd].function, callbacks[MSI_OnEnd].data );
951 958
959 terminate_call ( session );
952 return 1; 960 return 1;
953} 961}
954 962
@@ -961,7 +969,8 @@ int handle_recv_ringing ( MSISession *session, MSIMessage *msg )
961 return 0; 969 return 0;
962 970
963 session->call->ringing_timer_id = event.timer_alloc ( handle_timeout, session, session->call->ringing_tout_ms ); 971 session->call->ringing_timer_id = event.timer_alloc ( handle_timeout, session, session->call->ringing_tout_ms );
964 if ( callbacks[MSI_OnRinging].function ) event.rise ( callbacks[MSI_OnRinging].function, callbacks[MSI_OnRinging].data ); 972
973 invoke_callback(MSI_OnRinging);
965 974
966 return 1; 975 return 1;
967} 976}
@@ -1000,7 +1009,8 @@ int handle_recv_starting ( MSISession *session, MSIMessage *msg )
1000 1009
1001 flush_peer_type ( session, msg, 0 ); 1010 flush_peer_type ( session, msg, 0 );
1002 1011
1003 if ( callbacks[MSI_OnStarting].function ) event.rise ( callbacks[MSI_OnStarting].function, callbacks[MSI_OnStarting].data ); 1012 invoke_callback(MSI_OnStarting);
1013
1004 event.timer_release ( session->call->ringing_timer_id ); 1014 event.timer_release ( session->call->ringing_timer_id );
1005 1015
1006 return 1; 1016 return 1;
@@ -1015,8 +1025,7 @@ int handle_recv_ending ( MSISession *session, MSIMessage *msg )
1015 /* Stop timer */ 1025 /* Stop timer */
1016 event.timer_release ( session->call->request_timer_id ); 1026 event.timer_release ( session->call->request_timer_id );
1017 1027
1018 /* Call callback */ 1028 invoke_callback(MSI_OnEnding);
1019 if ( callbacks[MSI_OnEnding].function ) callbacks[MSI_OnEnding].function (callbacks[MSI_OnEnding].data);
1020 1029
1021 /* Terminate call */ 1030 /* Terminate call */
1022 terminate_call ( session ); 1031 terminate_call ( session );
@@ -1034,10 +1043,9 @@ int handle_recv_error ( MSISession *session, MSIMessage *msg )
1034 session->last_error_str = stringify_error ( session->last_error_id ); 1043 session->last_error_str = stringify_error ( session->last_error_id );
1035 } 1044 }
1036 1045
1046 invoke_callback(MSI_OnEnding);
1047
1037 terminate_call ( session ); 1048 terminate_call ( session );
1038
1039 if ( callbacks[MSI_OnEnding].function ) event.rise ( callbacks[MSI_OnEnding].function, callbacks[MSI_OnEnding].data );
1040
1041 return 1; 1049 return 1;
1042} 1050}
1043 1051
diff --git a/toxav/msi.h b/toxav/msi.h
index e7752ef9..fcc24b4a 100755
--- a/toxav/msi.h
+++ b/toxav/msi.h
@@ -33,7 +33,7 @@
33#define CALL_ID_LEN 12 33#define CALL_ID_LEN 12
34 34
35 35
36typedef void *( *MSICallback ) ( void *arg ); 36typedef void ( *MSICallback ) ( void *arg );
37 37
38 38
39/** 39/**
diff --git a/toxav/phone.c b/toxav/phone.c
index 2d7b4c90..43d24a2f 100755
--- a/toxav/phone.c
+++ b/toxav/phone.c
@@ -890,7 +890,7 @@ int phone_startmedia_loop ( ToxAv *arg )
890 INFO ("Shit-head"); 890 INFO ("Shit-head");
891 return -1; 891 return -1;
892 } 892 }
893 893
894 return 0; 894 return 0;
895} 895}
896 896
@@ -912,7 +912,7 @@ int phone_startmedia_loop ( ToxAv *arg )
912 912
913/* Some example callbacks */ 913/* Some example callbacks */
914 914
915void *callback_recv_invite ( void *_arg ) 915void callback_recv_invite ( void *_arg )
916{ 916{
917 assert(_arg); 917 assert(_arg);
918 918
@@ -926,14 +926,12 @@ void *callback_recv_invite ( void *_arg )
926 break; 926 break;
927 } 927 }
928 928
929 pthread_exit(NULL);
930} 929}
931void *callback_recv_ringing ( void *_arg ) 930void callback_recv_ringing ( void *_arg )
932{ 931{
933 INFO ( "Ringing!" ); 932 INFO ( "Ringing!" );
934 pthread_exit(NULL);
935} 933}
936void *callback_recv_starting ( void *_arg ) 934void callback_recv_starting ( void *_arg )
937{ 935{
938 if ( 0 != phone_startmedia_loop(_arg) ) { 936 if ( 0 != phone_startmedia_loop(_arg) ) {
939 INFO("Starting call failed!"); 937 INFO("Starting call failed!");
@@ -941,9 +939,8 @@ void *callback_recv_starting ( void *_arg )
941 INFO ("Call started! ( press h to hangup )"); 939 INFO ("Call started! ( press h to hangup )");
942 } 940 }
943 941
944 pthread_exit(NULL);
945} 942}
946void *callback_recv_ending ( void *_arg ) 943void callback_recv_ending ( void *_arg )
947{ 944{
948 _phone->running_encaud = 0; 945 _phone->running_encaud = 0;
949 _phone->running_decaud = 0; 946 _phone->running_decaud = 0;
@@ -960,18 +957,16 @@ void *callback_recv_ending ( void *_arg )
960 usleep(10000000); 957 usleep(10000000);
961 958
962 INFO ( "Call ended!" ); 959 INFO ( "Call ended!" );
963 pthread_exit(NULL);
964} 960}
965 961
966void *callback_recv_error ( void *_arg ) 962void callback_recv_error ( void *_arg )
967{ 963{
968 /*MSISession* _session = _arg; 964 /*MSISession* _session = _arg;
969 965
970 INFO( "Error: %s", _session->last_error_str ); */ 966 INFO( "Error: %s", _session->last_error_str ); */
971 pthread_exit(NULL);
972} 967}
973 968
974void *callback_call_started ( void *_arg ) 969void callback_call_started ( void *_arg )
975{ 970{
976 if ( 0 != phone_startmedia_loop(_arg) ) { 971 if ( 0 != phone_startmedia_loop(_arg) ) {
977 INFO("Starting call failed!"); 972 INFO("Starting call failed!");
@@ -979,19 +974,16 @@ void *callback_call_started ( void *_arg )
979 INFO ("Call started! ( press h to hangup )"); 974 INFO ("Call started! ( press h to hangup )");
980 } 975 }
981 976
982 pthread_exit(NULL);
983} 977}
984void *callback_call_canceled ( void *_arg ) 978void callback_call_canceled ( void *_arg )
985{ 979{
986 INFO ( "Call canceled!" ); 980 INFO ( "Call canceled!" );
987 pthread_exit(NULL);
988} 981}
989void *callback_call_rejected ( void *_arg ) 982void callback_call_rejected ( void *_arg )
990{ 983{
991 INFO ( "Call rejected!" ); 984 INFO ( "Call rejected!" );
992 pthread_exit(NULL);
993} 985}
994void *callback_call_ended ( void *_arg ) 986void callback_call_ended ( void *_arg )
995{ 987{
996 _phone->running_encaud = 0; 988 _phone->running_encaud = 0;
997 _phone->running_decaud = 0; 989 _phone->running_decaud = 0;
@@ -1011,13 +1003,11 @@ void *callback_call_ended ( void *_arg )
1011 1003
1012 toxav_kill_transmission(_phone->av); 1004 toxav_kill_transmission(_phone->av);
1013 INFO ( "Call ended!" ); 1005 INFO ( "Call ended!" );
1014 pthread_exit(NULL);
1015} 1006}
1016 1007
1017void *callback_requ_timeout ( void *_arg ) 1008void callback_requ_timeout ( void *_arg )
1018{ 1009{
1019 INFO( "No answer! " ); 1010 INFO( "No answer! " );
1020 pthread_exit(NULL);
1021} 1011}
1022 1012
1023av_session_t *av_init_session() 1013av_session_t *av_init_session()
diff --git a/toxav/toxav.h b/toxav/toxav.h
index 7e76e4c9..ffe79249 100755
--- a/toxav/toxav.h
+++ b/toxav/toxav.h
@@ -29,7 +29,7 @@
29/* vpx_image_t */ 29/* vpx_image_t */
30#include <vpx/vpx_image.h> 30#include <vpx/vpx_image.h>
31 31
32typedef void *( *ToxAVCallback ) ( void *arg ); 32typedef void ( *ToxAVCallback ) ( void *arg );
33typedef struct _ToxAv ToxAv; 33typedef struct _ToxAv ToxAv;
34 34
35#ifndef __TOX_DEFINED__ 35#ifndef __TOX_DEFINED__