aboutsummaryrefslogtreecommitdiff
path: root/src/conversation
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-10-03 18:06:51 +0000
committerChristian Grothoff <christian@grothoff.org>2013-10-03 18:06:51 +0000
commit9fd836bda9b9255d84fcaa0a463c5427980b3e79 (patch)
treee49f9aad2afb4d396876c2d23f3a6ee0bf5b4c0d /src/conversation
parentec3d41bc58ed32ab7678d0b5f04e956d1cf97afc (diff)
downloadgnunet-9fd836bda9b9255d84fcaa0a463c5427980b3e79.tar.gz
gnunet-9fd836bda9b9255d84fcaa0a463c5427980b3e79.zip
-mostly finished call API
Diffstat (limited to 'src/conversation')
-rw-r--r--src/conversation/conversation.h2
-rw-r--r--src/conversation/conversation_api2.c96
2 files changed, 82 insertions, 16 deletions
diff --git a/src/conversation/conversation.h b/src/conversation/conversation.h
index ff4795ef8..50a169a28 100644
--- a/src/conversation/conversation.h
+++ b/src/conversation/conversation.h
@@ -508,7 +508,7 @@ struct ClientAudioMessage
508struct ClientCallMessage 508struct ClientCallMessage
509{ 509{
510 /** 510 /**
511 * Type is: #GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_REGISTER 511 * Type is: #GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_CALL
512 */ 512 */
513 struct GNUNET_MessageHeader header; 513 struct GNUNET_MessageHeader header;
514 514
diff --git a/src/conversation/conversation_api2.c b/src/conversation/conversation_api2.c
index 6593f2a74..69e54c13b 100644
--- a/src/conversation/conversation_api2.c
+++ b/src/conversation/conversation_api2.c
@@ -313,7 +313,7 @@ handle_phone_hangup (void *cls,
313 */ 313 */
314static void 314static void
315handle_phone_audio_message (void *cls, 315handle_phone_audio_message (void *cls,
316 const struct GNUNET_MessageHeader *msg) 316 const struct GNUNET_MessageHeader *msg)
317{ 317{
318 struct GNUNET_CONVERSATION_Phone *phone = cls; 318 struct GNUNET_CONVERSATION_Phone *phone = cls;
319 const struct ClientAudioMessage *am; 319 const struct ClientAudioMessage *am;
@@ -487,16 +487,19 @@ GNUNET_CONVERSATION_phone_get_record (struct GNUNET_CONVERSATION_Phone *phone,
487 * @param data audio data to play 487 * @param data audio data to play
488 */ 488 */
489static void 489static void
490transmit_audio (void *cls, 490transmit_phone_audio (void *cls,
491 size_t data_size, 491 size_t data_size,
492 const void *data) 492 const void *data)
493{ 493{
494 struct GNUNET_CONVERSATION_Phone *phone = cls; 494 struct GNUNET_CONVERSATION_Phone *phone = cls;
495 struct GNUNET_MQ_Envelope *e; 495 struct GNUNET_MQ_Envelope *e;
496 struct ClientAudioMessage *am; 496 struct ClientAudioMessage *am;
497 497
498 GNUNET_assert (PS_ACTIVE == phone->state); 498 GNUNET_assert (PS_ACTIVE == phone->state);
499 e = GNUNET_MQ_msg_extra (am, data_size, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_AUDIO); 499 e = GNUNET_MQ_msg_extra (am,
500 data_size,
501 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_AUDIO);
502 memcpy (&am[1], data, data_size);
500 GNUNET_MQ_send (phone->mq, e); 503 GNUNET_MQ_send (phone->mq, e);
501} 504}
502 505
@@ -530,7 +533,7 @@ GNUNET_CONVERSTATION_phone_pick_up (struct GNUNET_CONVERSATION_Phone *phone,
530 phone->state = PS_ACTIVE; 533 phone->state = PS_ACTIVE;
531 phone->speaker->enable_speaker (phone->speaker->cls); 534 phone->speaker->enable_speaker (phone->speaker->cls);
532 phone->mic->enable_microphone (phone->mic->cls, 535 phone->mic->enable_microphone (phone->mic->cls,
533 &transmit_audio, 536 &transmit_phone_audio,
534 phone); 537 phone);
535} 538}
536 539
@@ -737,7 +740,9 @@ handle_call_busy (void *cls,
737 reconnect_call (call); 740 reconnect_call (call);
738 break; 741 break;
739 case CS_RINGING: 742 case CS_RINGING:
740 GNUNET_break (0); // FIXME 743 call->event_handler (call->event_handler_cls,
744 GNUNET_CONVERSATION_EC_BUSY);
745 GNUNET_CONVERSATION_call_stop (call, NULL);
741 break; 746 break;
742 case CS_ACTIVE: 747 case CS_ACTIVE:
743 GNUNET_break (0); 748 GNUNET_break (0);
@@ -751,6 +756,31 @@ handle_call_busy (void *cls,
751 756
752 757
753/** 758/**
759 * Process recorded audio data.
760 *
761 * @param cls closure with the `struct GNUNET_CONVERSATION_Call`
762 * @param data_size number of bytes in @a data
763 * @param data audio data to play
764 */
765static void
766transmit_call_audio (void *cls,
767 size_t data_size,
768 const void *data)
769{
770 struct GNUNET_CONVERSATION_Call *call = cls;
771 struct GNUNET_MQ_Envelope *e;
772 struct ClientAudioMessage *am;
773
774 GNUNET_assert (CS_ACTIVE == call->state);
775 e = GNUNET_MQ_msg_extra (am,
776 data_size,
777 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_AUDIO);
778 memcpy (&am[1], data, data_size);
779 GNUNET_MQ_send (call->mq, e);
780}
781
782
783/**
754 * We received a `struct ClientPhonePickedupMessage` 784 * We received a `struct ClientPhonePickedupMessage`
755 * 785 *
756 * @param cls the `struct GNUNET_CONVERSATION_Call` 786 * @param cls the `struct GNUNET_CONVERSATION_Call`
@@ -762,8 +792,15 @@ handle_call_picked_up (void *cls,
762{ 792{
763 struct GNUNET_CONVERSATION_Call *call = cls; 793 struct GNUNET_CONVERSATION_Call *call = cls;
764 const struct ClientPhonePickedupMessage *am; 794 const struct ClientPhonePickedupMessage *am;
795 const char *metadata;
796 size_t size;
765 797
766 am = (const struct ClientPhonePickedupMessage *) msg; 798 am = (const struct ClientPhonePickedupMessage *) msg;
799 size = ntohs (am->header.size) - sizeof (struct ClientPhonePickedupMessage);
800 metadata = (const char *) &am[1];
801 if ( (0 == size) ||
802 ('\0' != metadata[size - 1]) )
803 metadata = NULL;
767 switch (call->state) 804 switch (call->state)
768 { 805 {
769 case CS_LOOKUP: 806 case CS_LOOKUP:
@@ -771,7 +808,14 @@ handle_call_picked_up (void *cls,
771 reconnect_call (call); 808 reconnect_call (call);
772 break; 809 break;
773 case CS_RINGING: 810 case CS_RINGING:
774 GNUNET_break (0); // FIXME 811 call->state = CS_ACTIVE;
812 call->event_handler (call->event_handler_cls,
813 GNUNET_CONVERSATION_EC_READY,
814 metadata);
815 call->speaker->enable_speaker (call->speaker->cls);
816 call->mic->enable_microphone (call->mic->cls,
817 &transmit_call_audio,
818 call);
775 break; 819 break;
776 case CS_ACTIVE: 820 case CS_ACTIVE:
777 GNUNET_break (0); 821 GNUNET_break (0);
@@ -796,8 +840,15 @@ handle_call_hangup (void *cls,
796{ 840{
797 struct GNUNET_CONVERSATION_Call *call = cls; 841 struct GNUNET_CONVERSATION_Call *call = cls;
798 const struct ClientPhoneHangupMessage *am; 842 const struct ClientPhoneHangupMessage *am;
843 const char *reason;
844 size_t size;
799 845
800 am = (const struct ClientPhoneHangupMessage *) msg; 846 am = (const struct ClientPhoneHangupMessage *) msg;
847 size = ntohs (am->header.size) - sizeof (struct ClientPhoneHangupMessage);
848 reason = (const char *) &am[1];
849 if ( (0 == size) ||
850 ('\0' != reason[size - 1]) )
851 reason = NULL;
801 switch (call->state) 852 switch (call->state)
802 { 853 {
803 case CS_LOOKUP: 854 case CS_LOOKUP:
@@ -805,11 +856,17 @@ handle_call_hangup (void *cls,
805 reconnect_call (call); 856 reconnect_call (call);
806 break; 857 break;
807 case CS_RINGING: 858 case CS_RINGING:
808 GNUNET_break (0); // FIXME 859 call->event_handler (call->event_handler_cls,
809 break; 860 GNUNET_CONVERSATION_EC_TERMINATED,
861 reason);
862 GNUNET_CONVERSATION_call_stop (call, NULL);
863 return;
810 case CS_ACTIVE: 864 case CS_ACTIVE:
811 GNUNET_break (0); // FIXME 865 call->event_handler (call->event_handler_cls,
812 break; 866 GNUNET_CONVERSATION_EC_TERMINATED,
867 reason);
868 GNUNET_CONVERSATION_call_stop (call, NULL);
869 return;
813 case CS_SHUTDOWN: 870 case CS_SHUTDOWN:
814 GNUNET_CONVERSATION_call_stop (call, NULL); 871 GNUNET_CONVERSATION_call_stop (call, NULL);
815 break; 872 break;
@@ -868,6 +925,8 @@ handle_gns_response (void *cls,
868{ 925{
869 struct GNUNET_CONVERSATION_Call *call = cls; 926 struct GNUNET_CONVERSATION_Call *call = cls;
870 uint32_t i; 927 uint32_t i;
928 struct GNUNET_MQ_Envelope *e;
929 struct ClientCallMessage *ccm;
871 930
872 for (i=0;i<rd_count;i++) 931 for (i=0;i<rd_count;i++)
873 { 932 {
@@ -881,8 +940,14 @@ handle_gns_response (void *cls,
881 memcpy (&call->phone_record, 940 memcpy (&call->phone_record,
882 rd[i].data, 941 rd[i].data,
883 rd[i].data_size); 942 rd[i].data_size);
884 GNUNET_break (0); 943 e = GNUNET_MQ_msg (ccm, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_CALL);
885 // FIXME: send call request! 944 ccm->line = call->phone_record.line;
945 ccm->target = call->phone_record.peer;
946 ccm->caller_id = *GNUNET_IDENTITY_ego_get_private_key (call->caller_id);
947 GNUNET_MQ_send (call->mq, e);
948 call->state = CS_RINGING;
949 call->event_handler (call->event_handler_cls,
950 GNUNET_CONVERSATION_EC_RINGING);
886 return; 951 return;
887 } 952 }
888 } 953 }
@@ -1024,7 +1089,8 @@ GNUNET_CONVERSATION_call_stop (struct GNUNET_CONVERSATION_Call *call,
1024 if (NULL != reason) 1089 if (NULL != reason)
1025 { 1090 {
1026 // FIXME: transmit reason to service... 1091 // FIXME: transmit reason to service...
1027 return; 1092 GNUNET_break (0);
1093 // return;
1028 } 1094 }
1029 if (NULL != call->speaker) 1095 if (NULL != call->speaker)
1030 { 1096 {