JavaPOS: Working on the fire even thread.
authorgumartinm <gustavo@gumartinm.name>
Tue, 24 Apr 2012 06:58:44 +0000 (08:58 +0200)
committergumartinm <gustavo@gumartinm.name>
Tue, 24 Apr 2012 06:58:44 +0000 (08:58 +0200)
JavaPOS/KeyBoardDriver/src/main/java/de/javapos/example/MyPOSKeyboard.java
JavaPOS/KeyBoardDriver/src/main/java/de/javapos/example/hardware/KeyBoardDeviceLinux.java
JavaPOS/KeyBoardDriver/src/main/java/de/javapos/example/queue/JposEventQueue.java
JavaPOS/KeyBoardDriver/src/main/java/de/javapos/example/queue/JposEventQueueImpl.java

index 44c3983..fd19269 100644 (file)
@@ -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();
index e10f905..5f9828b 100644 (file)
@@ -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;
index 8816d32..73ad76e 100644 (file)
@@ -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();
 }
index 2816b3e..6e90064 100644 (file)
@@ -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();
+       }
 }