gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r29823 - in gnunet/src: conversation include


From: gnunet
Subject: [GNUnet-SVN] r29823 - in gnunet/src: conversation include
Date: Thu, 3 Oct 2013 20:06:51 +0200

Author: grothoff
Date: 2013-10-03 20:06:51 +0200 (Thu, 03 Oct 2013)
New Revision: 29823

Modified:
   gnunet/src/conversation/conversation.h
   gnunet/src/conversation/conversation_api2.c
   gnunet/src/include/gnunet_conversation_service.h
   gnunet/src/include/gnunet_protocols.h
Log:
-mostly finished call API

Modified: gnunet/src/conversation/conversation.h
===================================================================
--- gnunet/src/conversation/conversation.h      2013-10-03 16:09:13 UTC (rev 
29822)
+++ gnunet/src/conversation/conversation.h      2013-10-03 18:06:51 UTC (rev 
29823)
@@ -508,7 +508,7 @@
 struct ClientCallMessage
 {
   /**
-   * Type is: #GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_REGISTER
+   * Type is: #GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_CALL
    */
   struct GNUNET_MessageHeader header;
 

Modified: gnunet/src/conversation/conversation_api2.c
===================================================================
--- gnunet/src/conversation/conversation_api2.c 2013-10-03 16:09:13 UTC (rev 
29822)
+++ gnunet/src/conversation/conversation_api2.c 2013-10-03 18:06:51 UTC (rev 
29823)
@@ -313,7 +313,7 @@
  */
 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 @@
  * @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 @@
   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 @@
     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);
@@ -751,6 +756,31 @@
 
 
 /**
+ * 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`
  *
  * @param cls the `struct GNUNET_CONVERSATION_Call`
@@ -762,8 +792,15 @@
 {
   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 @@
     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 @@
 {
   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 @@
     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 @@
 {
   struct GNUNET_CONVERSATION_Call *call = cls;
   uint32_t i;
+  struct GNUNET_MQ_Envelope *e;
+  struct ClientCallMessage *ccm;
 
   for (i=0;i<rd_count;i++)
   {
@@ -881,8 +940,14 @@
       memcpy (&call->phone_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 @@
   if (NULL != reason)
   {
     // FIXME: transmit reason to service...
-    return;
+    GNUNET_break (0);
+    // return;
   }
   if (NULL != call->speaker)
   {

Modified: gnunet/src/include/gnunet_conversation_service.h
===================================================================
--- gnunet/src/include/gnunet_conversation_service.h    2013-10-03 16:09:13 UTC 
(rev 29822)
+++ gnunet/src/include/gnunet_conversation_service.h    2013-10-03 18:06:51 UTC 
(rev 29823)
@@ -259,6 +259,12 @@
    * 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

Modified: gnunet/src/include/gnunet_protocols.h
===================================================================
--- gnunet/src/include/gnunet_protocols.h       2013-10-03 16:09:13 UTC (rev 
29822)
+++ gnunet/src/include/gnunet_protocols.h       2013-10-03 18:06:51 UTC (rev 
29823)
@@ -2249,22 +2249,27 @@
 /**
  * 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
 
 
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]