summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2020-01-24 12:26:44 +0100
committerChristian Grothoff <christian@grothoff.org>2020-01-24 12:26:44 +0100
commit237dbf9290ab2198894a703149eb1a5e2347da73 (patch)
treeee9d0a8892a8b9fde9db7f7f4e7c052d687ef1a5 /src
parent4bb273a3790c17d0932ba3983da8d5030444d93b (diff)
downloadtaler-mdb-237dbf9290ab2198894a703149eb1a5e2347da73.tar.gz
taler-mdb-237dbf9290ab2198894a703149eb1a5e2347da73.tar.bz2
taler-mdb-237dbf9290ab2198894a703149eb1a5e2347da73.zip
improve MDB termination logic
Diffstat (limited to 'src')
-rw-r--r--src/main.c42
1 files 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
@@ -216,6 +216,13 @@ along with
#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
*/
struct MdbBlock
@@ -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);