glitch in the license text detected by hyazinthe, thank you!
[oweals/gnunet.git] / src / conversation / gnunet-conversation-test.c
index 13a55ad0c50a3d5ddd57b95720481756df109a06..cbc5d0aa572c8f554e23a1031efe1116af324c9d 100644 (file)
@@ -1,21 +1,16 @@
 /*
      This file is part of GNUnet.
-     (C) 2013 Christian Grothoff (and other contributing authors)
+     Copyright (C) 2013 GNUnet e.V.
 
-     GNUnet is free software; you can redistribute it and/or modify
-     it under the terms of the GNU General Public License as published
-     by the Free Software Foundation; either version 3, or (at your
-     option) any later version.
+     GNUnet is free software: you can redistribute it and/or modify it
+     under the terms of the GNU Affero General Public License as published
+     by the Free Software Foundation, either version 3 of the License,
+     or (at your option) any later version.
 
      GNUnet is distributed in the hope that it will be useful, but
      WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-     General Public License for more details.
-
-     You should have received a copy of the GNU General Public License
-     along with GNUnet; see the file COPYING.  If not, write to the
-     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-     Boston, MA 02111-1307, USA.
+     Affero General Public License for more details.
 */
 
 /**
  */
 #include "platform.h"
 #include "gnunet_util_lib.h"
-#include "gnunet_speaker_lib.h" 
-#include "gnunet_microphone_lib.h" 
+#include "gnunet_speaker_lib.h"
+#include "gnunet_microphone_lib.h"
 
 /**
  * How long do we record before we replay?
  */
-#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
+#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
 
 
 /**
@@ -74,12 +69,12 @@ static struct GNUNET_SPEAKER_Handle *speaker;
 /**
  * Task scheduled to switch from recording to playback.
  */
-static GNUNET_SCHEDULER_TaskIdentifier switch_task;
+static struct GNUNET_SCHEDULER_Task * switch_task;
 
 /**
  * The shutdown task.
  */
-static GNUNET_SCHEDULER_TaskIdentifier st;
+static struct GNUNET_SCHEDULER_Task * st;
 
 /**
  * Head of DLL with recorded frames.
@@ -96,15 +91,14 @@ static struct Recording *rec_tail;
  * Terminate test.
  *
  * @param cls NULL
- * @param tc unused
  */
 static void
-do_shutdown (void *cls,
-            const struct GNUNET_SCHEDULER_TaskContext *tc)
+do_shutdown (void *cls)
 {
   struct Recording *rec;
 
-  if (GNUNET_SCHEDULER_NO_TASK != switch_task)
+  (void) cls;
+  if (NULL != switch_task)
     GNUNET_SCHEDULER_cancel (switch_task);
   if (NULL != microphone)
     GNUNET_MICROPHONE_destroy (microphone);
@@ -117,7 +111,8 @@ do_shutdown (void *cls,
                                 rec);
     GNUNET_free (rec);
   }
-  fprintf (stderr, "\n");
+  fprintf (stderr,
+          _("\nEnd of transmission.  Have a GNU day.\n"));
 }
 
 
@@ -125,15 +120,12 @@ do_shutdown (void *cls,
  * Terminate recording process and switch to playback.
  *
  * @param cls NULL
- * @param tc unused
  */
 static void
-switch_to_speaker (void *cls,
-                  const struct GNUNET_SCHEDULER_TaskContext *tc)
+switch_to_speaker (void *cls)
 {
-  struct Recording *rec;
-
-  switch_task = GNUNET_SCHEDULER_NO_TASK;
+  (void) cls;
+  switch_task = NULL;
   microphone->disable_microphone (microphone->cls);
   if (GNUNET_OK !=
       speaker->enable_speaker (speaker->cls))
@@ -144,11 +136,17 @@ switch_to_speaker (void *cls,
     GNUNET_SCHEDULER_shutdown ();
     return;
   }
-  fprintf (stderr, "\nPlaying...");
-  for (rec=rec_head;NULL != rec; rec = rec->next)
+  fprintf (stderr,
+          _("\nWe are now playing your recording back.  If you can hear it, your audio settings are working..."));
+  for (struct Recording *rec=rec_head; NULL != rec; rec = rec->next)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+               "Replaying %u bytes\n",
+               (unsigned int) rec->size);
     speaker->play (speaker->cls,
                   rec->size,
                   &rec[1]);
+  }
   GNUNET_SCHEDULER_cancel (st);
   st = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
                                     &do_shutdown,
@@ -163,17 +161,20 @@ switch_to_speaker (void *cls,
  * @param data_size number of bytes in @a data
  * @param data audio data to play
  */
-static void 
+static void
 record (void *cls,
        size_t data_size,
        const void *data)
 {
   struct Recording *rec;
 
-  fprintf (stderr, ".");
+  (void) cls;
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+             "Recorded %u bytes\n",
+             (unsigned int) data_size);
   rec = GNUNET_malloc (sizeof (struct Recording) + data_size);
   rec->size = data_size;
-  memcpy (&rec[1], data, data_size);
+  GNUNET_memcpy (&rec[1], data, data_size);
   GNUNET_CONTAINER_DLL_insert_tail (rec_head,
                                    rec_tail,
                                    rec);
@@ -189,9 +190,14 @@ record (void *cls,
  * @param cfg configuration
  */
 static void
-run (void *cls, char *const *args, const char *cfgfile,
+run (void *cls,
+     char *const *args,
+     const char *cfgfile,
      const struct GNUNET_CONFIGURATION_Handle *cfg)
 {
+  (void) cls;
+  (void) args;
+  (void) cfgfile;
   microphone = GNUNET_MICROPHONE_create_from_hardware (cfg);
   GNUNET_assert (NULL != microphone);
   speaker = GNUNET_SPEAKER_create_from_hardware (cfg);
@@ -199,10 +205,11 @@ run (void *cls, char *const *args, const char *cfgfile,
   switch_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
                                              &switch_to_speaker,
                                              NULL);
-  st = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
-                                    &do_shutdown,
-                                    NULL);
-  fprintf (stderr, "Recording...");
+  st = GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
+                                     NULL);
+  fprintf (stderr,
+          _("We will now be recording you for %s. After that time, the recording will be played back to you..."),
+          GNUNET_STRINGS_relative_time_to_string (TIMEOUT, GNUNET_YES));
   if (GNUNET_OK !=
       microphone->enable_microphone (microphone->cls,
                                     &record, NULL))
@@ -224,17 +231,24 @@ run (void *cls, char *const *args, const char *cfgfile,
  * @return 0 ok, 1 on error
  */
 int
-main (int argc, char *const *argv)
+main (int argc,
+      char *const *argv)
 {
   static const struct GNUNET_GETOPT_CommandLineOption options[] = {
     GNUNET_GETOPT_OPTION_END
   };
-  if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
+  
+  if (GNUNET_OK !=
+      GNUNET_STRINGS_get_utf8_args (argc, argv,
+                                   &argc, &argv))
     return 2;
 
   ret = (GNUNET_OK ==
-        GNUNET_PROGRAM_run (argc, argv, "gnunet-conversation-test",
-                            gettext_noop ("help text"), options, &run,
+        GNUNET_PROGRAM_run (argc, argv,
+                            "gnunet-conversation-test",
+                            gettext_noop ("help text"),
+                            options,
+                            &run,
                             NULL)) ? ret : 1;
   GNUNET_free ((void*) argv);
   return ret;