aboutsummaryrefslogtreecommitdiff
path: root/src/conversation
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-10-03 16:09:03 +0000
committerChristian Grothoff <christian@grothoff.org>2013-10-03 16:09:03 +0000
commitb7ab6c6faaab407d80a3fb4729fc2746555b5010 (patch)
treeeea314fa98035ff192cde552354f26674db16ae7 /src/conversation
parent1493ff6efb8596c68a2ae3cd7a082d4c439c7f2a (diff)
downloadgnunet-b7ab6c6faaab407d80a3fb4729fc2746555b5010.tar.gz
gnunet-b7ab6c6faaab407d80a3fb4729fc2746555b5010.zip
-more work on call API
Diffstat (limited to 'src/conversation')
-rw-r--r--src/conversation/conversation_api2.c196
1 files changed, 190 insertions, 6 deletions
diff --git a/src/conversation/conversation_api2.c b/src/conversation/conversation_api2.c
index 39ea6e8f1..6593f2a74 100644
--- a/src/conversation/conversation_api2.c
+++ b/src/conversation/conversation_api2.c
@@ -348,8 +348,8 @@ handle_phone_audio_message (void *cls,
348 * @param error details about the error 348 * @param error details about the error
349 */ 349 */
350static void 350static void
351error_handler (void *cls, 351phone_error_handler (void *cls,
352 enum GNUNET_MQ_Error error) 352 enum GNUNET_MQ_Error error)
353{ 353{
354 struct GNUNET_CONVERSATION_Phone *phone = cls; 354 struct GNUNET_CONVERSATION_Phone *phone = cls;
355 355
@@ -398,7 +398,7 @@ reconnect_phone (struct GNUNET_CONVERSATION_Phone *phone)
398 return; 398 return;
399 phone->mq = GNUNET_MQ_queue_for_connection_client (phone->client, 399 phone->mq = GNUNET_MQ_queue_for_connection_client (phone->client,
400 handlers, 400 handlers,
401 &error_handler, 401 &phone_error_handler,
402 phone); 402 phone);
403 e = GNUNET_MQ_msg (reg, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_REGISTER); 403 e = GNUNET_MQ_msg (reg, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_REGISTER);
404 reg->line = phone->my_record.line; 404 reg->line = phone->my_record.line;
@@ -719,6 +719,105 @@ reconnect_call (struct GNUNET_CONVERSATION_Call *call);
719 719
720 720
721/** 721/**
722 * We received a `struct ClientPhoneBusyMessage`
723 *
724 * @param cls the `struct GNUNET_CONVERSATION_Call`
725 * @param msg the message
726 */
727static void
728handle_call_busy (void *cls,
729 const struct GNUNET_MessageHeader *msg)
730{
731 struct GNUNET_CONVERSATION_Call *call = cls;
732
733 switch (call->state)
734 {
735 case CS_LOOKUP:
736 GNUNET_break (0);
737 reconnect_call (call);
738 break;
739 case CS_RINGING:
740 GNUNET_break (0); // FIXME
741 break;
742 case CS_ACTIVE:
743 GNUNET_break (0);
744 reconnect_call (call);
745 break;
746 case CS_SHUTDOWN:
747 GNUNET_CONVERSATION_call_stop (call, NULL);
748 break;
749 }
750}
751
752
753/**
754 * We received a `struct ClientPhonePickedupMessage`
755 *
756 * @param cls the `struct GNUNET_CONVERSATION_Call`
757 * @param msg the message
758 */
759static void
760handle_call_picked_up (void *cls,
761 const struct GNUNET_MessageHeader *msg)
762{
763 struct GNUNET_CONVERSATION_Call *call = cls;
764 const struct ClientPhonePickedupMessage *am;
765
766 am = (const struct ClientPhonePickedupMessage *) msg;
767 switch (call->state)
768 {
769 case CS_LOOKUP:
770 GNUNET_break (0);
771 reconnect_call (call);
772 break;
773 case CS_RINGING:
774 GNUNET_break (0); // FIXME
775 break;
776 case CS_ACTIVE:
777 GNUNET_break (0);
778 reconnect_call (call);
779 break;
780 case CS_SHUTDOWN:
781 GNUNET_CONVERSATION_call_stop (call, NULL);
782 break;
783 }
784}
785
786
787/**
788 * We received a `struct ClientPhoneHangupMessage`
789 *
790 * @param cls the `struct GNUNET_CONVERSATION_Call`
791 * @param msg the message
792 */
793static void
794handle_call_hangup (void *cls,
795 const struct GNUNET_MessageHeader *msg)
796{
797 struct GNUNET_CONVERSATION_Call *call = cls;
798 const struct ClientPhoneHangupMessage *am;
799
800 am = (const struct ClientPhoneHangupMessage *) msg;
801 switch (call->state)
802 {
803 case CS_LOOKUP:
804 GNUNET_break (0);
805 reconnect_call (call);
806 break;
807 case CS_RINGING:
808 GNUNET_break (0); // FIXME
809 break;
810 case CS_ACTIVE:
811 GNUNET_break (0); // FIXME
812 break;
813 case CS_SHUTDOWN:
814 GNUNET_CONVERSATION_call_stop (call, NULL);
815 break;
816 }
817}
818
819
820/**
722 * We received a `struct ClientAudioMessage` 821 * We received a `struct ClientAudioMessage`
723 * 822 *
724 * @param cls the `struct GNUNET_CONVERSATION_Call` 823 * @param cls the `struct GNUNET_CONVERSATION_Call`
@@ -795,6 +894,23 @@ handle_gns_response (void *cls,
795 894
796 895
797/** 896/**
897 * We encountered an error talking with the conversation service.
898 *
899 * @param cls the `struct GNUNET_CONVERSATION_Call`
900 * @param error details about the error
901 */
902static void
903call_error_handler (void *cls,
904 enum GNUNET_MQ_Error error)
905{
906 struct GNUNET_CONVERSATION_Call *call = cls;
907
908 GNUNET_break (0);
909 reconnect_call (call);
910}
911
912
913/**
798 * The call got disconnected, reconnect to the service. 914 * The call got disconnected, reconnect to the service.
799 * 915 *
800 * @param call call to reconnect 916 * @param call call to reconnect
@@ -802,6 +918,39 @@ handle_gns_response (void *cls,
802static void 918static void
803reconnect_call (struct GNUNET_CONVERSATION_Call *call) 919reconnect_call (struct GNUNET_CONVERSATION_Call *call)
804{ 920{
921 static struct GNUNET_MQ_MessageHandler handlers[] =
922 {
923 { &handle_call_busy,
924 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_BUSY,
925 sizeof (struct ClientPhoneBusyMessage) },
926 { &handle_call_picked_up,
927 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_PICKED_UP,
928 0 },
929 { &handle_call_hangup,
930 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP,
931 0 },
932 { &handle_call_audio_message,
933 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_AUDIO,
934 0 },
935 { NULL, 0, 0 }
936 };
937 if (NULL != call->mq)
938 {
939 GNUNET_MQ_destroy (call->mq);
940 call->mq = NULL;
941 }
942 if (NULL != call->client)
943 {
944 GNUNET_CLIENT_disconnect (call->client);
945 call->client = NULL;
946 }
947 call->client = GNUNET_CLIENT_connect ("conversation", call->cfg);
948 if (NULL == call->client)
949 return;
950 call->mq = GNUNET_MQ_queue_for_connection_client (call->client,
951 handlers,
952 &call_error_handler,
953 call);
805} 954}
806 955
807 956
@@ -841,8 +990,9 @@ GNUNET_CONVERSATION_call_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
841 call->mic = mic; 990 call->mic = mic;
842 call->event_handler = event_handler; 991 call->event_handler = event_handler;
843 call->event_handler_cls = event_handler_cls; 992 call->event_handler_cls = event_handler_cls;
844 call->client = GNUNET_CLIENT_connect ("conversation", cfg);
845 call->gns = GNUNET_GNS_connect (cfg); 993 call->gns = GNUNET_GNS_connect (cfg);
994 reconnect_call (call);
995
846 if ( (NULL == call->client) || 996 if ( (NULL == call->client) ||
847 (NULL == call->gns) ) 997 (NULL == call->gns) )
848 { 998 {
@@ -871,8 +1021,42 @@ void
871GNUNET_CONVERSATION_call_stop (struct GNUNET_CONVERSATION_Call *call, 1021GNUNET_CONVERSATION_call_stop (struct GNUNET_CONVERSATION_Call *call,
872 const char *reason) 1022 const char *reason)
873{ 1023{
874 GNUNET_assert (0); 1024 if (NULL != reason)
875 // FIXME 1025 {
1026 // FIXME: transmit reason to service...
1027 return;
1028 }
1029 if (NULL != call->speaker)
1030 {
1031 call->speaker->disable_speaker (call->speaker->cls);
1032 call->speaker = NULL;
1033 }
1034 if (NULL != call->mic)
1035 {
1036 call->mic->disable_microphone (call->mic->cls);
1037 call->mic =NULL;
1038 }
1039 if (NULL != call->mq)
1040 {
1041 GNUNET_MQ_destroy (call->mq);
1042 call->mq = NULL;
1043 }
1044 if (NULL != call->client)
1045 {
1046 GNUNET_CLIENT_disconnect (call->client);
1047 call->client = NULL;
1048 }
1049 if (NULL != call->gns_lookup)
1050 {
1051 GNUNET_GNS_lookup_cancel (call->gns_lookup);
1052 call->gns_lookup = NULL;
1053 }
1054 if (NULL != call->gns)
1055 {
1056 GNUNET_GNS_disconnect (call->gns);
1057 call->gns = NULL;
1058 }
1059
876 GNUNET_free (call); 1060 GNUNET_free (call);
877} 1061}
878 1062