gnunet-svn
[Top][All Lists]
Advanced

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

[taler-taler-mdb] 01/02: add advertising logic


From: gnunet
Subject: [taler-taler-mdb] 01/02: add advertising logic
Date: Sat, 13 Jan 2024 15:26:48 +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 7fec3a399aa0dbe1cad881046b3317554273e1ce
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Sat Jan 13 14:26:53 2024 +0100

    add advertising logic
---
 src/.gitignore  |   1 +
 src/taler-mdb.c | 133 +++++++++++++++++++++++++++++++++++++++-----------------
 taler.conf      |   6 +--
 3 files changed, 97 insertions(+), 43 deletions(-)

diff --git a/src/.gitignore b/src/.gitignore
index 7639f69..f66074a 100644
--- a/src/.gitignore
+++ b/src/.gitignore
@@ -1,2 +1,3 @@
 *.o
 taler-nfc
+taler-coin-acceptor
diff --git a/src/taler-mdb.c b/src/taler-mdb.c
index 0f5df48..1d34207 100644
--- a/src/taler-mdb.c
+++ b/src/taler-mdb.c
@@ -1,6 +1,6 @@
 /*
  This file is part of TALER
- Copyright (C) 2019, 2020, 2022 Taler Systems SA
+ Copyright (C) 2019, 2020, 2022, 2024 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
@@ -17,17 +17,17 @@ along with
  TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
 */
 /**
-* @file main.c
-* @brief runs the payment logic for a Taler-enabled snack machine
-* @author Marco Boss
-* @author Christian Grothoff
-* @author Dominik Hofer
-*
-*/
+ * @file taler-mdb.c
+ * @brief runs the payment logic for a Taler-enabled snack machine
+ * @author Marco Boss
+ * @author Christian Grothoff
+ * @author Dominik Hofer
+ */
 #include "config.h"
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <signal.h>
 #include <unistd.h>
 #include <sys/socket.h>
 #if HAVE_SYS_UN_H
@@ -633,6 +633,18 @@ static struct GNUNET_SCHEDULER_Task *keyboard_task;
  */
 static struct GNUNET_SCHEDULER_Task *cancelbutton_task;
 
+/**
+ * Handle to the process showing messages/advertisements
+ * while we are inactive.
+ */
+static struct GNUNET_OS_Process *adv_child;
+
+/**
+ * Name of the process to run when advertising is enabled.
+ * Can be NULL.
+ */
+static char *adv_process_filename;
+
 /**
  * Taler Backend url read from configuration file
  */
@@ -804,6 +816,41 @@ static const uint8_t get_data[] = { 0x00, 0xCA, 0x01, 
0x00, 0x00, 0x00 };
 static struct Display qrDisplay;
 
 
+/**
+ * Stop the advertising process.
+ */
+static void
+stop_advertising (void)
+{
+  if (NULL == adv_child)
+    return;
+  GNUNET_break (0 ==
+                GNUNET_OS_process_kill (adv_child,
+                                        SIGTERM));
+  GNUNET_break (GNUNET_OK ==
+                GNUNET_OS_process_wait (adv_child));
+  GNUNET_OS_process_destroy (adv_child);
+  adv_child = NULL;
+}
+
+
+/**
+ * Start the advertising process.
+ */
+static void
+start_advertising (void)
+{
+  stop_advertising (); /* just to be sure */
+  adv_child = GNUNET_OS_start_process (GNUNET_OS_INHERIT_STD_NONE,
+                                       NULL,
+                                       NULL,
+                                       NULL,
+                                       adv_process_filename,
+                                       adv_process_filename,
+                                       NULL);
+}
+
+
 #if HAVE_QRENCODE_H
 #include <qrencode.h>
 
@@ -824,6 +871,7 @@ show_qrcode (const char *uri)
   size_t yOff;
   const char *dddash;
 
+  stop_advertising ();
   if (0 > qrDisplay.devicefd)
     return; /* no display, no dice */
   /* find the fourth '/' in the payto://pay/hostname/-uri */
@@ -926,7 +974,7 @@ show_qrcode (const char *uri)
   QRcode_free (qrc);
   QRinput_free (qri);
 
-  /* turn on backlight if supported */
+  /* Turn on backlight if supported */
   if (0 < qrDisplay.backlightfd)
     (void) ! write (qrDisplay.backlightfd,
                     &backlight_on,
@@ -957,6 +1005,7 @@ async_pa_cleanup_job (void *cls)
   if (NULL != pa->rc)
     GNUNET_CURL_gnunet_rc_destroy (pa->rc);
   GNUNET_free (pa);
+  start_advertising ();
 }
 
 
@@ -1098,6 +1147,7 @@ mdb_shutdown (void)
     GNUNET_SCHEDULER_cancel (mdb.wtask);
     mdb.wtask = NULL;
   }
+  stop_advertising ();
   if (disable_mdb)
     return;
   /* restore UART */
@@ -1131,6 +1181,7 @@ shutdown_task (void *cls)
   (void) cls;
   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
               "Shutdown initiated\n");
+  stop_advertising ();
   while (NULL != (r = refund_head))
   {
     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
@@ -2816,12 +2867,12 @@ read_products (void *cls,
   if (GNUNET_OK !=
       GNUNET_CONFIGURATION_get_value_string (cfg,
                                              section,
-                                             "description",
+                                             "DESCRIPTION",
                                              &tmpProduct.description))
   {
     GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
                                section,
-                               "description");
+                               "DESCRIPTION");
     return;
   }
   if (sold_out_enabled)
@@ -2851,7 +2902,7 @@ read_products (void *cls,
   if (GNUNET_OK ==
       GNUNET_CONFIGURATION_get_value_string (cfg,
                                              section,
-                                             "key",
+                                             "KEY",
                                              &tmpKey))
   {
     tmpProduct.key = tmpKey[0];
@@ -2865,14 +2916,14 @@ read_products (void *cls,
   if (GNUNET_OK !=
       GNUNET_CONFIGURATION_get_value_string (cfg,
                                              section,
-                                             "instance",
+                                             "INSTANCE",
                                              &tmpProduct.instance))
     tmpProduct.instance = NULL;
   tmpProduct.preview = NULL;
   if (GNUNET_OK ==
       GNUNET_CONFIGURATION_get_value_string (cfg,
                                              section,
-                                             "thumbnail",
+                                             "THUMBNAIL",
                                              &thumbnail_fn))
   {
     struct GNUNET_DISK_FileHandle *fh;
@@ -2964,12 +3015,12 @@ read_products (void *cls,
   if (GNUNET_OK !=
       GNUNET_CONFIGURATION_get_value_number (cfg,
                                              section,
-                                             "number",
+                                             "NUMBER",
                                              &tmpProduct.number))
   {
     GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
                                section,
-                               "number");
+                               "NUMBER");
     GNUNET_free (tmpProduct.description);
     GNUNET_free (tmpProduct.instance);
     GNUNET_free (tmpProduct.preview);
@@ -2982,17 +3033,17 @@ read_products (void *cls,
     if ( (GNUNET_OK !=
           GNUNET_CONFIGURATION_get_value_string (cfg,
                                                  section,
-                                                 "BACKEND-AUTHORIZATION",
+                                                 "BACKEND_AUTHORIZATION",
                                                  &auth)) &&
          (GNUNET_OK !=
           GNUNET_CONFIGURATION_get_value_string (cfg,
                                                  "taler-mdb",
-                                                 "BACKEND-AUTHORIZATION",
+                                                 "BACKEND_AUTHORIZATION",
                                                  &auth)) )
     {
       GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
                                  section,
-                                 "BACKEND-AUTHORIZATION");
+                                 "BACKEND_AUTHORIZATION");
       GNUNET_free (tmpProduct.description);
       GNUNET_free (tmpProduct.instance);
       GNUNET_free (tmpProduct.preview);
@@ -3120,7 +3171,7 @@ run (void *cls,
                                                "FRAMEBUFFER_DEVICE",
                                                &framebuffer_device_filename))
   {
-    GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+    GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING,
                                "taler-mdb",
                                "FRAMEBUFFER_DEVICE");
     framebuffer_device_filename = GNUNET_strdup ("/dev/fb1");
@@ -3141,35 +3192,37 @@ run (void *cls,
   if (GNUNET_OK !=
       GNUNET_CONFIGURATION_get_value_string (cfg,
                                              "taler-mdb",
-                                             "backend-base-url",
+                                             "BACKEND_BASE_URL",
                                              &backend_base_url))
   {
     GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
                                "taler-mdb",
-                               "backend-base-url");
+                               "BACKEND_BASE_URL");
     global_ret = EXIT_FAILURE;
     return;
   }
+  (void) GNUNET_CONFIGURATION_get_value_filename (cfg,
+                                                  "taler-mdb",
+                                                  "ADVERTISEMENT_BINARY",
+                                                  &adv_process_filename);
+  if (GNUNET_OK !=
+      GNUNET_CONFIGURATION_get_value_string (cfg,
+                                             "taler-mdb",
+                                             "ESSID",
+                                             &essid))
   {
-    if (GNUNET_OK !=
-        GNUNET_CONFIGURATION_get_value_string (cfg,
-                                               "taler-mdb",
-                                               "essid",
-                                               &essid))
-    {
-      GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-                  "No ESSID specified, will not advertise WLAN\n");
-    }
+    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                "No ESSID specified, will not advertise WLAN\n");
   }
   if (GNUNET_OK !=
       GNUNET_CONFIGURATION_get_value_string (cfg,
                                              "taler-mdb",
-                                             "fulfillment-msg",
+                                             "FULFILLMENT_MSG",
                                              &fulfillment_msg))
   {
     GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
                                "taler-mdb",
-                               "fulfillment-msg");
+                               "FULFILLMENT_MSG");
     global_ret = EXIT_FAILURE;
     return;
   }
@@ -3361,6 +3414,7 @@ run (void *cls,
                               framebuffer_device_filename);
   }
 #endif
+  start_advertising ();
   if (! disable_tty)
     start_read_keyboard ();
 }
@@ -3425,16 +3479,19 @@ int
 main (int argc,
       char*const*argv)
 {
-  struct termios tty_opts_backup, tty_opts_raw;
+  struct termios tty_opts_backup;
+  struct termios tty_opts_raw;
   int have_tty;
   int ret;
-
-  /* the available command line options */
   struct GNUNET_GETOPT_CommandLineOption options[] = {
     GNUNET_GETOPT_option_flag ('d',
                                "disable-mdb",
                                "disable all interactions with the MDB (for 
testing without machine)",
                                &disable_mdb),
+    GNUNET_GETOPT_option_flag ('i',
+                               "backlight-invert",
+                               "invert the backlight on/off values (standard 
on = 1)",
+                               &backlight_invert),
     GNUNET_GETOPT_option_flag ('s',
                                "enable-soldout",
                                "enable detection of sold-out products, 
preventing vend operations of the respective product until the process is 
restarted",
@@ -3443,10 +3500,6 @@ main (int argc,
                                "disable-tty",
                                "disable all keyboard interactions (for running 
from systemd)",
                                &disable_tty),
-    GNUNET_GETOPT_option_flag ('i',
-                               "backlight-invert",
-                               "invert the backlight on/off values (standard 
on = 1)",
-                               &backlight_invert),
     GNUNET_GETOPT_OPTION_END
   };
 
diff --git a/taler.conf b/taler.conf
index b133ec5..984faf2 100644
--- a/taler.conf
+++ b/taler.conf
@@ -1,8 +1,8 @@
 [taler-mdb]
-BACKEND-BASE-URL = https://backend.demo.taler.net/instances/Taler/
-BACKEND-AUTHORIZATION = Bearer secret-token:secret
+BACKEND_BASE_URL = https://backend.demo.taler.net/instances/Taler/
+BACKEND_AUTHORIZATION = Bearer secret-token:secret
 # Message to diplay after purchase is completed,
-fulfillment-msg = Enjoy your ${PRODUCT_DESCRIPTION}
+FULFILLMENT_MSG = Enjoy your ${PRODUCT_DESCRIPTION}
 
 # Name of the UART where the MDB connector is reachable.
 UART_DEVICE = /dev/ttyAMA0

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

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