From: gumartinm Date: Tue, 24 Apr 2012 06:58:44 +0000 (+0200) Subject: JavaPOS: Working on the fire even thread. X-Git-Url: https://git.gumartinm.name/?a=commitdiff_plain;h=1f299aac6f80dc55e58e4a2370a8e72c872daf44;p=JavaForFun JavaPOS: Working on the fire even thread. --- diff --git a/JavaPOS/KeyBoardDriver/src/main/java/de/javapos/example/MyPOSKeyboard.java b/JavaPOS/KeyBoardDriver/src/main/java/de/javapos/example/MyPOSKeyboard.java index 44c3983..fd19269 100644 --- a/JavaPOS/KeyBoardDriver/src/main/java/de/javapos/example/MyPOSKeyboard.java +++ b/JavaPOS/KeyBoardDriver/src/main/java/de/javapos/example/MyPOSKeyboard.java @@ -171,7 +171,7 @@ public class MyPOSKeyboard implements POSKeyboardService112, JposConst, POSKeybo @Override public int getDeviceServiceVersion() throws JposException { - return this.deviceVersion12; + return MyPOSKeyboard.deviceVersion12; } @Override @@ -275,6 +275,8 @@ public class MyPOSKeyboard implements POSKeyboardService112, JposConst, POSKeybo this.deviceDriver.addEventListener(eventListener); + //estaria genial poner esto en el jpos.xml y asi puede tambien cambiar el firethread + //Lo malo es que no tengo interfaz para ello :( Luego nada :/ } @@ -437,7 +439,7 @@ public class MyPOSKeyboard implements POSKeyboardService112, JposConst, POSKeybo @Override public void inputAvailable(int input) { try { - this.jposEventQueue.putEvent(new DataEvent(this.callbacks, input)); + this.jposEventQueue.putEvent(new DataEvent(this.callbacks.getEventSource(), input)); } catch (InterruptedException e) { //restore interrupt status. Thread.currentThread().interrupt(); diff --git a/JavaPOS/KeyBoardDriver/src/main/java/de/javapos/example/hardware/KeyBoardDeviceLinux.java b/JavaPOS/KeyBoardDriver/src/main/java/de/javapos/example/hardware/KeyBoardDeviceLinux.java index e10f905..5f9828b 100644 --- a/JavaPOS/KeyBoardDriver/src/main/java/de/javapos/example/hardware/KeyBoardDeviceLinux.java +++ b/JavaPOS/KeyBoardDriver/src/main/java/de/javapos/example/hardware/KeyBoardDeviceLinux.java @@ -158,6 +158,7 @@ public class KeyBoardDeviceLinux implements BaseKeyBoardDriver { } /** + * Not thread-safe.!!!!! * * NO OLVIDAR try/finally PARA DEJAR EL DISPOSITIVO CORRECTAMENTE * @throws JposException @@ -296,8 +297,8 @@ public class KeyBoardDeviceLinux implements BaseKeyBoardDriver { private void runBatchTask() { - //OS 64 bits timeval 8 bytes -> struct input_event 16 bytes - //OS 32 bits timeval 16 bytes -> struct input_event 24 bytes + //OS 64 bits timeval 16 bytes -> struct input_event 24 bytes + //OS 32 bits timeval 8 bytes -> struct input_event 16 bytes byte []buffer = new byte[16]; //byte []buffer = new byte[24]; short code = 0; diff --git a/JavaPOS/KeyBoardDriver/src/main/java/de/javapos/example/queue/JposEventQueue.java b/JavaPOS/KeyBoardDriver/src/main/java/de/javapos/example/queue/JposEventQueue.java index 8816d32..73ad76e 100644 --- a/JavaPOS/KeyBoardDriver/src/main/java/de/javapos/example/queue/JposEventQueue.java +++ b/JavaPOS/KeyBoardDriver/src/main/java/de/javapos/example/queue/JposEventQueue.java @@ -8,16 +8,23 @@ public interface JposEventQueue { public void putEvent(JposEvent paramJposEvent) throws InterruptedException; - public void clearAllEvents(); + public JposEvent getEvent() throws InterruptedException; public void clearInputEvents(); public void clearOutputEvents(); - + public int getNumberOfEvents(); public void checkEvents(); - public boolean eventQueueIsFull(); + public void removeAllEvents(); + + public boolean removeEvent(JposEvent paramJposEvent); + + public JposEvent peekElement(int paramInt); + + public boolean isFull(); + public int getSize(); } diff --git a/JavaPOS/KeyBoardDriver/src/main/java/de/javapos/example/queue/JposEventQueueImpl.java b/JavaPOS/KeyBoardDriver/src/main/java/de/javapos/example/queue/JposEventQueueImpl.java index 2816b3e..6e90064 100644 --- a/JavaPOS/KeyBoardDriver/src/main/java/de/javapos/example/queue/JposEventQueueImpl.java +++ b/JavaPOS/KeyBoardDriver/src/main/java/de/javapos/example/queue/JposEventQueueImpl.java @@ -16,8 +16,8 @@ public class JposEventQueueImpl implements JposEventQueue { } @Override - public void clearAllEvents() { - this.linkedBlockingQueue.clear(); + public JposEvent getEvent() throws InterruptedException { + return this.linkedBlockingQueue.take(); } @Override @@ -41,8 +41,28 @@ public class JposEventQueueImpl implements JposEventQueue { } @Override - public boolean eventQueueIsFull() { + public void removeAllEvents() { + this.linkedBlockingQueue.clear(); + } + + @Override + public boolean removeEvent(JposEvent paramJposEvent) { + return this.linkedBlockingQueue.remove(paramJposEvent); + } + + @Override + public JposEvent peekElement(int paramInt) { + return null; + } + + @Override + public boolean isFull() { //No seguro de esto :/ return false; } + + @Override + public int getSize() { + return this.linkedBlockingQueue.size(); + } }