cash2ecash

cash2ecash: cash acceptor that issues digital cash (experimental)
Log | Files | Refs | Submodules | README | LICENSE

commit c636b7ff2c53cfdba7e6c50a8861f7177d306b9b
parent 11c992d554ac10d33055c43463a43275ca094c4f
Author: Manuel Geissbühler <manuel@debian>
Date:   Thu,  2 Jan 2025 15:36:26 +0100

debugging

Diffstat:
Msrc/bank/bankCommunication.hpp | 12++++++------
Msrc/cash2ecash.cpp | 29++++++++++++++++++++++++-----
Msrc/gui/screenAcceptCash.hpp | 2+-
Msrc/gui/screenConnection.hpp | 2+-
Msrc/gui/screenIdentification.hpp | 4++--
Msrc/gui/screenWelcomme.hpp | 2+-
Msrc/include/global.hpp | 2+-
7 files changed, 36 insertions(+), 17 deletions(-)

diff --git a/src/bank/bankCommunication.hpp b/src/bank/bankCommunication.hpp @@ -14,24 +14,24 @@ class BankCommunication{ static const char **status; static void initCallback(){ - eventHandler(EVENT_BANK_TOKEN_DONE); + event(EVENT_BANK_TOKEN_DONE); } static void withdrawalRequestCallback(){ - eventHandler(EVENT_BANK_WITHDRAWAL_DONE); + event(EVENT_BANK_WITHDRAWAL_DONE); } static void withdrawalConfirmRequestCallback(){ - eventHandler(EVENT_BANK_W_CONFIRMATION_DONE); + event(EVENT_BANK_W_CONFIRMATION_DONE); } static void withdrawalIDInfoRequestCallback(){ if (0 == std::strcmp(*status, "pending")){ - eventHandler(EVENT_BANK_W_STATUS_PENDING); + event(EVENT_BANK_W_STATUS_PENDING); }else if (0 == std::strcmp(*status, "selected")) { - eventHandler(EVENT_BANK_W_STATUS_SELECTED); + event(EVENT_BANK_W_STATUS_SELECTED); }else if (0 == std::strcmp(*status, "aborted")) { - eventHandler(EVENT_BUTTON_ABORT); + event(EVENT_BUTTON_ABORT); }else{ std::cerr << "Unexpected Withdrawal Staus: " << *status << std::endl; exit(EXIT_FAILURE); diff --git a/src/cash2ecash.cpp b/src/cash2ecash.cpp @@ -3,6 +3,7 @@ #include <iostream> #include <ostream> #include <vector> +#include <mutex> #include "utils.hpp" #include "gui.hpp" #include "global.hpp" @@ -26,6 +27,9 @@ enum state_e state = INIT; const char **withdrawal_id; const char **taler_withdraw_uri; +std::vector<event_e> eventFIFO; +std::mutex eventFIFOMutex; + char hello[] = "hello"; char world[] = "wold"; @@ -195,10 +199,24 @@ void initStateEvent(){ } -void eventHandler(event_e event){ - state_e oldstate = state; - state = stateEventTable[state][event].nextState; - stateEventTable[oldstate][event].action(); +void event(event_e event){ + eventFIFOMutex.lock(); + eventFIFO.push_back(event); + eventFIFOMutex.unlock(); +} + +void eventHandler(){ + state_e oldstate; + event_e event; + eventFIFOMutex.lock(); + while (0 < eventFIFO.size()) { + oldstate = state; + event = eventFIFO.front(); + state = stateEventTable[state][event].nextState; + stateEventTable[oldstate][event].action(); + eventFIFO.erase(eventFIFO.begin()); + } + eventFIFOMutex.unlock(); } int main(int argc, char *argv[]){ @@ -212,9 +230,10 @@ int main(int argc, char *argv[]){ initStateEvent(); //Trigger Initialzation Event - eventHandler(EVENT_INITIALIZE); + event(EVENT_INITIALIZE); while (true) { + eventHandler(); guiDriver(); } } diff --git a/src/gui/screenAcceptCash.hpp b/src/gui/screenAcceptCash.hpp @@ -15,7 +15,7 @@ class ScreenAcceptCash : public Screen{ lv_obj_t *amountLabel; static void finishedButtonEvent(lv_event_t *e){ - eventHandler(EVENT_BUTTON_FINISH_CASHIN); + event(EVENT_BUTTON_FINISH_CASHIN); } protected: diff --git a/src/gui/screenConnection.hpp b/src/gui/screenConnection.hpp @@ -15,7 +15,7 @@ class ScreenConnection : public Screen{ lv_obj_t *qrCode; static void callbackEventAbort(lv_event_t *e){ - eventHandler(EVENT_BUTTON_ABORT); + event(EVENT_BUTTON_ABORT); } protected: diff --git a/src/gui/screenIdentification.hpp b/src/gui/screenIdentification.hpp @@ -13,11 +13,11 @@ class ScreenIdentification : public Screen { lv_obj_t *identButton; static void abortButtonEvent(lv_event_t *e){ - eventHandler(EVENT_BUTTON_ABORT); + event(EVENT_BUTTON_ABORT); } static void identButtonEvent(lv_event_t *e){ - eventHandler(EVENT_IDENTIFICATION_SUCCESS); + event(EVENT_IDENTIFICATION_SUCCESS); } protected: diff --git a/src/gui/screenWelcomme.hpp b/src/gui/screenWelcomme.hpp @@ -20,7 +20,7 @@ private: lv_obj_t *startButton; static void startButtonEvent(lv_event_t *e){ - eventHandler(EVENT_BUTTON_START); + event(EVENT_BUTTON_START); } public: diff --git a/src/include/global.hpp b/src/include/global.hpp @@ -19,6 +19,6 @@ enum event_e { }; #define NUMBER_OF_EVENTS 13 -void eventHandler(event_e event); +void event(event_e event); #endif