gnunet-svn
[Top][All Lists]
Advanced

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

[taler-anastasis] 01/03: cmd waiting for input


From: gnunet
Subject: [taler-anastasis] 01/03: cmd waiting for input
Date: Sat, 16 May 2020 19:25:23 +0200

This is an automated email from the git hooks/post-receive script.

dennis-neufeld pushed a commit to branch master
in repository anastasis.

commit 435cff25af72dfa9235926c44b55db23fad3f3be
Author: Dennis Neufeld <address@hidden>
AuthorDate: Sat May 16 15:50:00 2020 +0000

    cmd waiting for input
---
 src/cli/anastasis-cli-splitter.c | 67 ++++++++++++++++++++++++++++++++++++++--
 1 file changed, 65 insertions(+), 2 deletions(-)

diff --git a/src/cli/anastasis-cli-splitter.c b/src/cli/anastasis-cli-splitter.c
index f882e50..73dc646 100644
--- a/src/cli/anastasis-cli-splitter.c
+++ b/src/cli/anastasis-cli-splitter.c
@@ -21,6 +21,7 @@
  * @author Dominik Meister
  */
 #include "platform.h"
+#include <gnunet/gnunet_util_lib.h>
 #include "anastasis_service.h"
 #include "anastasis.h"
 
@@ -46,6 +47,56 @@ static struct GNUNET_CURL_Context *ctx;
 static struct GNUNET_CURL_RescheduleContext *rc;
 
 
+static void
+start_read_keyboard (void);
+
+
+/**
+ * @brief Read the character from stdin and activate the selected task
+ *
+ * @param cls closure
+ */
+static void
+read_keyboard_command (void *cls)
+{
+  (void) cls;
+  int input;
+
+  keyboard_task = NULL;
+  input = getchar ();
+  if ( (EOF == input) ||
+       ('x' == (char) input) )
+  {
+    GNUNET_SCHEDULER_shutdown ();
+    return;
+  }
+  
+  fprintf (stderr,
+           "Unknown command '%c'\n",
+           (char) input);
+  start_read_keyboard ();
+}
+
+
+/**
+ * @brief Wait for a keyboard input
+ */
+static void
+start_read_keyboard ()
+{
+  static struct GNUNET_DISK_FileHandle fh = { STDIN_FILENO };
+
+  GNUNET_assert (NULL == keyboard_task);
+ 
+  printf ("'x' to quit\n");
+  printf ("Waiting for keyboard input\n");
+  keyboard_task = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
+                                                  &fh,
+                                                  &read_keyboard_command,
+                                                  NULL);
+}
+
+
 /**
  * @brief Shutdown the application.
  *
@@ -59,9 +110,14 @@ shutdown_task (void *cls)
               "Shutdown initiated\n");
 
   // FIXME shutdown routine here
+  if (NULL != ctx)
+  {
+    GNUNET_CURL_fini (ctx);
+    ctx = NULL;
+  }
 
   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-              "Shutdown complete (except for MDB)\n");
+              "Shutdown complete\n");
 }
 
 
@@ -81,6 +137,7 @@ run (void *cls,
 {
   (void) cls;
   (void) args;
+  (void) cfgfile;
 
   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
               "Starting anastasis-splitter\n");
@@ -97,14 +154,20 @@ run (void *cls,
   ctx = GNUNET_CURL_init (&GNUNET_CURL_gnunet_scheduler_reschedule,
                           &rc);
   rc = GNUNET_CURL_gnunet_rc_create (ctx);
+
+  start_read_keyboard ();
 }
 
 int
 main (int argc,
-      char*const*argv)
+      char *const *argv)
 {
   int ret;
 
+  GNUNET_log_setup ("test-anastasis",
+                    "DEBUG",
+                    NULL);
+
   /* the available command line options */
   struct GNUNET_GETOPT_CommandLineOption options[] = {
     GNUNET_GETOPT_option_flag ('m',

-- 
To stop receiving notification emails like this one, please contact
address@hidden.



reply via email to

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