From 9fd836bda9b9255d84fcaa0a463c5427980b3e79 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Thu, 3 Oct 2013 18:06:51 +0000 Subject: -mostly finished call API --- src/conversation/conversation.h | 2 +- src/conversation/conversation_api2.c | 96 ++++++++++++++++++++++++++----- src/include/gnunet_conversation_service.h | 6 ++ src/include/gnunet_protocols.h | 13 +++-- 4 files changed, 97 insertions(+), 20 deletions(-) (limited to 'src') 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 struct ClientCallMessage { /** - * Type is: #GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_REGISTER + * Type is: #GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_CALL */ struct GNUNET_MessageHeader header; 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, */ static void handle_phone_audio_message (void *cls, - const struct GNUNET_MessageHeader *msg) + const struct GNUNET_MessageHeader *msg) { struct GNUNET_CONVERSATION_Phone *phone = cls; const struct ClientAudioMessage *am; @@ -487,16 +487,19 @@ GNUNET_CONVERSATION_phone_get_record (struct GNUNET_CONVERSATION_Phone *phone, * @param data audio data to play */ static void -transmit_audio (void *cls, - size_t data_size, - const void *data) +transmit_phone_audio (void *cls, + size_t data_size, + const void *data) { struct GNUNET_CONVERSATION_Phone *phone = cls; struct GNUNET_MQ_Envelope *e; struct ClientAudioMessage *am; GNUNET_assert (PS_ACTIVE == phone->state); - e = GNUNET_MQ_msg_extra (am, data_size, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_AUDIO); + e = GNUNET_MQ_msg_extra (am, + data_size, + GNUNET_MESSAGE_TYPE_CONVERSATION_CS_AUDIO); + memcpy (&am[1], data, data_size); GNUNET_MQ_send (phone->mq, e); } @@ -530,7 +533,7 @@ GNUNET_CONVERSTATION_phone_pick_up (struct GNUNET_CONVERSATION_Phone *phone, phone->state = PS_ACTIVE; phone->speaker->enable_speaker (phone->speaker->cls); phone->mic->enable_microphone (phone->mic->cls, - &transmit_audio, + &transmit_phone_audio, phone); } @@ -737,7 +740,9 @@ handle_call_busy (void *cls, reconnect_call (call); break; case CS_RINGING: - GNUNET_break (0); // FIXME + call->event_handler (call->event_handler_cls, + GNUNET_CONVERSATION_EC_BUSY); + GNUNET_CONVERSATION_call_stop (call, NULL); break; case CS_ACTIVE: GNUNET_break (0); @@ -750,6 +755,31 @@ handle_call_busy (void *cls, } +/** + * Process recorded audio data. + * + * @param cls closure with the `struct GNUNET_CONVERSATION_Call` + * @param data_size number of bytes in @a data + * @param data audio data to play + */ +static void +transmit_call_audio (void *cls, + size_t data_size, + const void *data) +{ + struct GNUNET_CONVERSATION_Call *call = cls; + struct GNUNET_MQ_Envelope *e; + struct ClientAudioMessage *am; + + GNUNET_assert (CS_ACTIVE == call->state); + e = GNUNET_MQ_msg_extra (am, + data_size, + GNUNET_MESSAGE_TYPE_CONVERSATION_CS_AUDIO); + memcpy (&am[1], data, data_size); + GNUNET_MQ_send (call->mq, e); +} + + /** * We received a `struct ClientPhonePickedupMessage` * @@ -762,8 +792,15 @@ handle_call_picked_up (void *cls, { struct GNUNET_CONVERSATION_Call *call = cls; const struct ClientPhonePickedupMessage *am; + const char *metadata; + size_t size; am = (const struct ClientPhonePickedupMessage *) msg; + size = ntohs (am->header.size) - sizeof (struct ClientPhonePickedupMessage); + metadata = (const char *) &am[1]; + if ( (0 == size) || + ('\0' != metadata[size - 1]) ) + metadata = NULL; switch (call->state) { case CS_LOOKUP: @@ -771,7 +808,14 @@ handle_call_picked_up (void *cls, reconnect_call (call); break; case CS_RINGING: - GNUNET_break (0); // FIXME + call->state = CS_ACTIVE; + call->event_handler (call->event_handler_cls, + GNUNET_CONVERSATION_EC_READY, + metadata); + call->speaker->enable_speaker (call->speaker->cls); + call->mic->enable_microphone (call->mic->cls, + &transmit_call_audio, + call); break; case CS_ACTIVE: GNUNET_break (0); @@ -796,8 +840,15 @@ handle_call_hangup (void *cls, { struct GNUNET_CONVERSATION_Call *call = cls; const struct ClientPhoneHangupMessage *am; + const char *reason; + size_t size; am = (const struct ClientPhoneHangupMessage *) msg; + size = ntohs (am->header.size) - sizeof (struct ClientPhoneHangupMessage); + reason = (const char *) &am[1]; + if ( (0 == size) || + ('\0' != reason[size - 1]) ) + reason = NULL; switch (call->state) { case CS_LOOKUP: @@ -805,11 +856,17 @@ handle_call_hangup (void *cls, reconnect_call (call); break; case CS_RINGING: - GNUNET_break (0); // FIXME - break; + call->event_handler (call->event_handler_cls, + GNUNET_CONVERSATION_EC_TERMINATED, + reason); + GNUNET_CONVERSATION_call_stop (call, NULL); + return; case CS_ACTIVE: - GNUNET_break (0); // FIXME - break; + call->event_handler (call->event_handler_cls, + GNUNET_CONVERSATION_EC_TERMINATED, + reason); + GNUNET_CONVERSATION_call_stop (call, NULL); + return; case CS_SHUTDOWN: GNUNET_CONVERSATION_call_stop (call, NULL); break; @@ -868,6 +925,8 @@ handle_gns_response (void *cls, { struct GNUNET_CONVERSATION_Call *call = cls; uint32_t i; + struct GNUNET_MQ_Envelope *e; + struct ClientCallMessage *ccm; for (i=0;iphone_record, rd[i].data, rd[i].data_size); - GNUNET_break (0); - // FIXME: send call request! + e = GNUNET_MQ_msg (ccm, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_CALL); + ccm->line = call->phone_record.line; + ccm->target = call->phone_record.peer; + ccm->caller_id = *GNUNET_IDENTITY_ego_get_private_key (call->caller_id); + GNUNET_MQ_send (call->mq, e); + call->state = CS_RINGING; + call->event_handler (call->event_handler_cls, + GNUNET_CONVERSATION_EC_RINGING); return; } } @@ -1024,7 +1089,8 @@ GNUNET_CONVERSATION_call_stop (struct GNUNET_CONVERSATION_Call *call, if (NULL != reason) { // FIXME: transmit reason to service... - return; + GNUNET_break (0); + // return; } if (NULL != call->speaker) { diff --git a/src/include/gnunet_conversation_service.h b/src/include/gnunet_conversation_service.h index 098cec9ab..76fcbfe6a 100644 --- a/src/include/gnunet_conversation_service.h +++ b/src/include/gnunet_conversation_service.h @@ -259,6 +259,12 @@ enum GNUNET_CONVERSATION_EventCode * a `const char *`. The caller ID will be a GNS name. */ GNUNET_CONVERSATION_EC_RING, + + /** + * We are the caller and are now ringing the other party. + * The varargs will be empty. + */ + GNUNET_CONVERSATION_EC_RINGING, /** * We are ready to talk, metadata about the call may be supplied diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h index 2cc54401c..afc56cfe2 100644 --- a/src/include/gnunet_protocols.h +++ b/src/include/gnunet_protocols.h @@ -2249,22 +2249,27 @@ extern "C" /** * Client <- Server message to indicate a ringing phone */ -#define GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RING 733 +#define GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_CALL 733 + +/** + * Client <- Server message to indicate a ringing phone + */ +#define GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RING 734 /** * Client <-> Server message to send audio data. */ -#define GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_BUSY 734 +#define GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_BUSY 735 /** * Client <-> Server message to send audio data. */ -#define GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_PICKED_UP 735 +#define GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_PICKED_UP 736 /** * Client <-> Server message to send audio data. */ -#define GNUNET_MESSAGE_TYPE_CONVERSATION_CS_AUDIO 736 +#define GNUNET_MESSAGE_TYPE_CONVERSATION_CS_AUDIO 737 -- cgit v1.2.3