From: gumartinm Date: Tue, 24 Apr 2012 07:00:44 +0000 (+0200) Subject: JavaPOS: fire event thread. X-Git-Url: https://git.gumartinm.name/?a=commitdiff_plain;h=5de7359cbd3c6da9c930bb77bdb5fd97a1d94b91;p=JavaForFun JavaPOS: fire event thread. I missed this class in the last commit related to JavaPOS... --- 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); + } + } + } +}