gnunet-svn
[Top][All Lists]
Advanced

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

[taler-taler-mdb] 01/02: improve MDB termination logic


From: gnunet
Subject: [taler-taler-mdb] 01/02: improve MDB termination logic
Date: Fri, 24 Jan 2020 12:27:58 +0100

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

grothoff pushed a commit to branch master
in repository taler-mdb.

commit 237dbf9290ab2198894a703149eb1a5e2347da73
Author: Christian Grothoff <address@hidden>
AuthorDate: Fri Jan 24 12:26:44 2020 +0100

    improve MDB termination logic
---
 src/main.c | 42 +++++++++++++++++++++++++++++++++++-------
 1 file changed, 35 insertions(+), 7 deletions(-)

diff --git a/src/main.c b/src/main.c
index 90a9efb..3110a13 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1,6 +1,6 @@
 /*
  This file is part of TALER
- Copyright (C) 2019 GNUnet e.V.
+ Copyright (C) 2019, 2020 Taler Systems SA
 
  TALER 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
@@ -18,7 +18,7 @@ along with
 */
 /**
 * @file main.c
-* @brief main functionality of the application
+* @brief runs the payment logic for a Taler-enabled snack machine
 * @author Marco Boss
 * @author Christian Grothoff
 * @author Dominik Hofer
@@ -215,6 +215,13 @@ along with
 #define READER_SESSION_CANCEL_REQUEST "04"
 #define READER_REVALUE_DENIED "0E"
 
+/**
+ * How long are we willing to wait for MDB during
+ * shutdown?
+ */
+#define SHUTDOWN_MDB_TIMEOUT GNUNET_TIME_relative_multiply ( \
+    GNUNET_TIME_UNIT_MILLISECONDS, 100)
+
 /**
  * Datatype for mdb subcommands and data
  */
@@ -475,10 +482,19 @@ static int global_ret;
 static int in_shutdown;
 
 /**
- * Refenence to the keyboard task
+ * Flag set to remember that MDB needs shutdown
+ * (because we were actually able to talk to MDB).
+ */
+static int mdb_active;
+
+/**
+ * Reference to the keyboard task
  */
 static struct GNUNET_SCHEDULER_Task *keyboard_task;
 
+/**
+ * Reference to the cancel button task
+ */
 static struct GNUNET_SCHEDULER_Task *cancelbutton_task;
 
 /**
@@ -601,11 +617,16 @@ static char backlight_on = '1';
  */
 static char backlight_off = '0';
 
+/**
+ * State for the implementation of the 'cancel' button.
+ */
 struct CancelButton
 {
   int cancelbuttonfd;
 };
+
 static struct CancelButton cancelButton;
+
 /**
  * Name of the UART device with the MDB (i.e. /dev/ttyAMA0).
  */
@@ -905,6 +926,7 @@ shutdown_task (void *cls)
   in_shutdown = GNUNET_YES;
   mdb.cmd = &endSession;
   run_mdb_event_loop ();
+
   if (NULL != ctx)
   {
     GNUNET_CURL_fini (ctx);
@@ -1749,13 +1771,15 @@ write_mdb_command (void *cls)
     run_mdb_event_loop ();
     return;
   }
-  /* if command was sent completely send the rest */
+  /* if command was sent partially, send the rest */
   if (mdb.tx_off < mdb.tx_len)
   {
     ssize_t ret = write (mdb.uartfd,
                          &mdb.txBuffer[mdb.tx_off],
                          mdb.tx_len - mdb.tx_off);
-
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "Wrote %d bytes to MDB\n",
+                (int) ret);
     did_write = 1;
     if (-1 == ret)
     {
@@ -2167,6 +2191,7 @@ read_mdb_command (void *cls)
 
   while (mdb.rx_off > 0)
   {
+    mdb_active = GNUNET_YES;
     /* find begining of command */
     for (cmdStartIdx = 0; cmdStartIdx < mdb.rx_off; cmdStartIdx++)
       if (VMC_CMD_START == mdb.rxBuffer[cmdStartIdx])
@@ -2239,11 +2264,14 @@ run_mdb_event_loop ()
          (in_shutdown) ||
          (mdb.tx_len > mdb.tx_off) ) )
   {
-    if (disable_mdb)
+    if (disable_mdb || ! mdb_active)
       mdb.wtask = GNUNET_SCHEDULER_add_now (&write_mdb_command,
                                             NULL);
     else
-      mdb.wtask = GNUNET_SCHEDULER_add_write_file 
(GNUNET_TIME_UNIT_FOREVER_REL,
+      mdb.wtask = GNUNET_SCHEDULER_add_write_file ((in_shutdown)
+                                                   ? SHUTDOWN_MDB_TIMEOUT
+                                                   :
+                                                   
GNUNET_TIME_UNIT_FOREVER_REL,
                                                    &fh,
                                                    &write_mdb_command,
                                                    NULL);

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



reply via email to

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