From 5de7359cbd3c6da9c930bb77bdb5fd97a1d94b91 Mon Sep 17 00:00:00 2001 From: gumartinm Date: Tue, 24 Apr 2012 09:00:44 +0200 Subject: [PATCH] JavaPOS: fire event thread. I missed this class in the last commit related to JavaPOS... --- .../java/de/javapos/example/ThreadFireEvent.java | 67 ++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 JavaPOS/KeyBoardDriver/src/main/java/de/javapos/example/ThreadFireEvent.java diff --git a/JavaPOS/KeyBoardDriver/src/main/java/de/javapos/example/ThreadFireEvent.java b/JavaPOS/KeyBoardDriver/src/main/java/de/javapos/example/ThreadFireEvent.java new file mode 100644 index 0000000..d9e6914 --- /dev/null +++ b/JavaPOS/KeyBoardDriver/src/main/java/de/javapos/example/ThreadFireEvent.java @@ -0,0 +1,67 @@ +package de.javapos.example; + +import jpos.events.DataEvent; +import jpos.events.DirectIOEvent; +import jpos.events.ErrorEvent; +import jpos.events.JposEvent; +import jpos.events.OutputCompleteEvent; +import jpos.events.StatusUpdateEvent; +import jpos.services.EventCallbacks; +import de.javapos.example.queue.JposEventQueue; + +public class ThreadFireEvent extends Thread { + private final JposEventQueue jposEventQueue; + private boolean isDataEventEnabled; + private final EventCallbacks eventCallbacks; + + public ThreadFireEvent (JposEventQueue jposEventQueue, + boolean isDataEventEnabled, EventCallbacks eventCallbacks) { + this.jposEventQueue = jposEventQueue; + this.isDataEventEnabled = isDataEventEnabled; + this.eventCallbacks = eventCallbacks; + } + + public void run () { + JposEvent jposEvent = null; + + while (true) { + if (this.jposEventQueue.getNumberOfEvents() != 0) { + //PROBLEMA: si DataEventEnabled es false y lo unico que hay en la cola son eventos de datos + //me meto en un bucle que va a dejar la CPU frita... :/ + if (this.isDataEventEnabled) { + try { + jposEvent = this.jposEventQueue.getEvent(); + } catch (InterruptedException e) { + //restore interrupt status. + Thread.currentThread().interrupt(); + //End of thread. + break; + } + } + else { + //TODO: Buscar eventos que no sean DataEvent o ErrorEvent + } + } + + //TODO: Bloquearme hasta que freezeEvent sea false + + if (jposEvent instanceof DataEvent) { + this.eventCallbacks.fireDataEvent((DataEvent)jposEvent); + //TODO: synchronized? + this.isDataEventEnabled = false; + } + if (jposEvent instanceof ErrorEvent) { + this.eventCallbacks.fireErrorEvent((ErrorEvent)jposEvent); + } + if (jposEvent instanceof StatusUpdateEvent) { + this.eventCallbacks.fireStatusUpdateEvent((StatusUpdateEvent)jposEvent); + } + if (jposEvent instanceof DirectIOEvent) { + this.eventCallbacks.fireDirectIOEvent((DirectIOEvent)jposEvent); + } + if (jposEvent instanceof OutputCompleteEvent) { + this.eventCallbacks.fireOutputCompleteEvent((OutputCompleteEvent)jposEvent); + } + } + } +} -- 2.1.4