Many modifications in my JavaPOS key board driver.
authorgumartinm <gustavo@gumartinm.name>
Thu, 29 Mar 2012 15:12:07 +0000 (17:12 +0200)
committergumartinm <gustavo@gumartinm.name>
Thu, 29 Mar 2012 15:12:07 +0000 (17:12 +0200)
18 files changed:
JavaPOS/KeyBoardDriver/pom.xml
JavaPOS/KeyBoardDriver/src/main/java/de/javapos/example/JposDriverInstanceFactory.java [new file with mode: 0755]
JavaPOS/KeyBoardDriver/src/main/java/de/javapos/example/JposDriverInstanceFactoryImpl.java [new file with mode: 0755]
JavaPOS/KeyBoardDriver/src/main/java/de/javapos/example/JposServiceInstanceFactoryImpl.java [new file with mode: 0755]
JavaPOS/KeyBoardDriver/src/main/java/de/javapos/example/MyPOSKeyboard.java [new file with mode: 0755]
JavaPOS/KeyBoardDriver/src/main/java/de/javapos/example/ThreadSafe.java [new file with mode: 0755]
JavaPOS/KeyBoardDriver/src/main/java/de/javapos/example/hardware/BaseKeyBoardDriver.java [new file with mode: 0755]
JavaPOS/KeyBoardDriver/src/main/java/de/javapos/example/hardware/KeyBoardDeviceLinux.java [new file with mode: 0755]
JavaPOS/KeyBoardDriver/src/main/java/de/javapos/example/queue/JposEventQueue.java [new file with mode: 0755]
JavaPOS/KeyBoardDriver/src/main/java/de/javapos/example/queue/JposEventQueueImpl.java [new file with mode: 0755]
JavaPOS/KeyBoardDriver/src/main/java/es/dia/pos/n2a/gus/jpos/BaseKeyBoardDriver.java [deleted file]
JavaPOS/KeyBoardDriver/src/main/java/es/dia/pos/n2a/gus/jpos/EventQueue.java [deleted file]
JavaPOS/KeyBoardDriver/src/main/java/es/dia/pos/n2a/gus/jpos/JposDriverInstanceFactory.java [deleted file]
JavaPOS/KeyBoardDriver/src/main/java/es/dia/pos/n2a/gus/jpos/JposDriverInstanceFactoryImpl.java [deleted file]
JavaPOS/KeyBoardDriver/src/main/java/es/dia/pos/n2a/gus/jpos/JposServiceInstanceFactoryImpl.java [deleted file]
JavaPOS/KeyBoardDriver/src/main/java/es/dia/pos/n2a/gus/jpos/KBDDeviceLinux.java [deleted file]
JavaPOS/KeyBoardDriver/src/main/java/es/dia/pos/n2a/gus/jpos/POSKeyboard.java [deleted file]
JavaPOS/KeyBoardDriver/src/main/resources/jpos.xml [new file with mode: 0755]

index dda8b95..b556c53 100644 (file)
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
     <modelVersion>4.0.0</modelVersion>
-    <groupId>es.dia.pos.n2a</groupId>
+    <groupId>de.javapos.example</groupId>
     <artifactId>javapos-keyboard-driver</artifactId>
     <version>1.0</version>
     <name>javapos-keyboard-driver</name>
             <artifactId>jpos-controls</artifactId>
             <version>1.12.2</version>
         </dependency>
+        <dependency>
+               <groupId>log4j</groupId>
+               <artifactId>log4j</artifactId>
+               <version>1.2.15</version>
+               </dependency>   
     </dependencies>
 </project>
diff --git a/JavaPOS/KeyBoardDriver/src/main/java/de/javapos/example/JposDriverInstanceFactory.java b/JavaPOS/KeyBoardDriver/src/main/java/de/javapos/example/JposDriverInstanceFactory.java
new file mode 100755 (executable)
index 0000000..d6cc664
--- /dev/null
@@ -0,0 +1,24 @@
+/**
+ * 
+ */
+package de.javapos.example;
+
+import jpos.JposException;
+import jpos.config.JposEntry;
+
+/**
+ * @author
+ *
+ */
+public interface JposDriverInstanceFactory {
+
+       /**
+        * 
+        * @param logicalName 
+        * @param jposEntry
+        * @param entry
+        * @return
+        * @throws JposException
+        */
+       public <E> E createInstance(String logicalName, JposEntry entry, Class<E> pruebaClass) throws JposException;
+}
diff --git a/JavaPOS/KeyBoardDriver/src/main/java/de/javapos/example/JposDriverInstanceFactoryImpl.java b/JavaPOS/KeyBoardDriver/src/main/java/de/javapos/example/JposDriverInstanceFactoryImpl.java
new file mode 100755 (executable)
index 0000000..c35aa6e
--- /dev/null
@@ -0,0 +1,48 @@
+package de.javapos.example;\r
+\r
+import java.lang.reflect.Constructor;\r
+import jpos.JposConst;\r
+import jpos.JposException;\r
+import jpos.config.JposEntry;\r
+\r
+/**\r
+ * Retrieve the device HW driver using this instance factory.\r
+ * @author \r
+ */\r
+public class JposDriverInstanceFactoryImpl implements JposDriverInstanceFactory\r
+{      \r
+       \r
+    /**\r
+     * @input_parameters: \r
+     */ \r
+       @Override\r
+       public <E> E createInstance(String logicalName, JposEntry entry, Class<E> typeClass) throws JposException \r
+       {\r
+       if (entry.getPropertyValue("driverClass") == null)\r
+        {\r
+            throw new JposException(JposConst.JPOS_E_NOSERVICE, "Missing driverClass JposEntry");\r
+        }      \r
+       E driverInstance = null;\r
+        try\r
+        {\r
+            String serviceClassName = (String)entry.getPropertyValue("driverClass");\r
+            Class<?> serviceClass = Class.forName(serviceClassName);\r
+            Class<?>[] params = new Class<?>[0];\r
+            Constructor<?> ctor = serviceClass.getConstructor(params);\r
+            if (typeClass.isInstance(ctor.newInstance((Object[])params)) )\r
+            {\r
+               //This cast is correct (IMHO) because we are checking the right type\r
+               //with the method isInstance.\r
+               //Why must I declare this local variable with SuppressWarnings? This is weird...\r
+               @SuppressWarnings("unchecked") E aux = (E)ctor.newInstance((Object[])params);\r
+               driverInstance = aux;\r
+            }\r
+        }\r
+        catch(Exception e)\r
+        {\r
+               throw new JposException(JposConst.JPOS_E_NOSERVICE, "Could not create " +\r
+                       "the driver instance for device with logicalName= " + logicalName, e);\r
+        }   \r
+        return driverInstance;\r
+       }\r
+}\r
diff --git a/JavaPOS/KeyBoardDriver/src/main/java/de/javapos/example/JposServiceInstanceFactoryImpl.java b/JavaPOS/KeyBoardDriver/src/main/java/de/javapos/example/JposServiceInstanceFactoryImpl.java
new file mode 100755 (executable)
index 0000000..fc50f86
--- /dev/null
@@ -0,0 +1,43 @@
+package de.javapos.example;\r
+\r
+import java.lang.reflect.Constructor;\r
+import jpos.JposConst;\r
+import jpos.JposException;\r
+import jpos.config.JposEntry;\r
+import jpos.loader.JposServiceInstance;\r
+import jpos.loader.JposServiceInstanceFactory;\r
+\r
+/**\r
+ * Instance factory to get the JPOS device services\r
+ * @author \r
+ */\r
+public class JposServiceInstanceFactoryImpl implements JposServiceInstanceFactory\r
+{    \r
+    /**\r
+     * @input_parameters: \r
+     * entry: (for jpos.xml and jpos.properties must be serviceClass)\r
+     * logicalName: device's name (in jpos.xml or jpos.properties file, jpos.xml file by default)\r
+     */\r
+    public JposServiceInstance createInstance(String logicalName, JposEntry entry) throws JposException\r
+    {\r
+        if(!entry.hasPropertyWithName(JposEntry.SERVICE_CLASS_PROP_NAME))\r
+        {\r
+            throw new JposException(JposConst.JPOS_E_NOSERVICE, "The JposEntry does not contain the 'serviceClass' property");\r
+        }\r
+        JposServiceInstance serviceInstance = null;\r
+        try\r
+        {\r
+            String serviceClassName = (String)entry.getPropertyValue(JposEntry.SERVICE_CLASS_PROP_NAME);\r
+            Class<?> serviceClass = Class.forName(serviceClassName);\r
+            Class<?>[] params = new Class<?>[0];\r
+            Constructor<?> ctor = serviceClass.getConstructor(params);\r
+            serviceInstance = (JposServiceInstance)ctor.newInstance((Object[])params);\r
+        }\r
+        catch(Exception e)\r
+        {\r
+            throw new JposException(JposConst.JPOS_E_NOSERVICE, "Could not create " +\r
+                       "the service instance with logicalName= " + logicalName, e);\r
+        }\r
+        return serviceInstance;\r
+    }\r
+}\r
diff --git a/JavaPOS/KeyBoardDriver/src/main/java/de/javapos/example/MyPOSKeyboard.java b/JavaPOS/KeyBoardDriver/src/main/java/de/javapos/example/MyPOSKeyboard.java
new file mode 100755 (executable)
index 0000000..bf41f09
--- /dev/null
@@ -0,0 +1,410 @@
+package de.javapos.example;
+import de.javapos.example.hardware.BaseKeyBoardDriver;
+import de.javapos.example.queue.JposEventQueue;
+import de.javapos.example.queue.JposEventQueueImpl;
+import jpos.JposConst;
+import jpos.JposException;
+import jpos.POSKeyboardConst;
+import jpos.loader.JposServiceLoader;
+import jpos.loader.JposServiceManager;
+import jpos.services.EventCallbacks;
+import jpos.services.POSKeyboardService112;
+import jpos.config.JposEntry;
+import jpos.config.JposEntryRegistry;
+import jpos.events.JposEvent;
+public class MyPOSKeyboard implements POSKeyboardService112, JposConst, POSKeyboardConst
+{
+       private static final int deviceVersion12  = 1002000;
+       private String logicalname;
+       private EventCallbacks callbacks = null;
+       private JposEntryRegistry jposEntryRegistry = null;
+       private JposEntry jposEntry = null;
+       private String device;
+       private int maxEvents;
+       private BaseKeyBoardDriver deviceDriver;
+       private JposDriverInstanceFactory jposDriverFactory;
+       private JposEventQueue jposEventQueue;
+       
+       @Override
+       public int getCapPowerReporting() throws JposException {
+               // TODO Auto-generated method stub
+               return 0;
+       }
+
+       @Override
+       public int getPowerNotify() throws JposException {
+               // TODO Auto-generated method stub
+               return 0;
+       }
+
+       @Override
+       public int getPowerState() throws JposException {
+               // TODO Auto-generated method stub
+               return 0;
+       }
+
+       @Override
+       public void setPowerNotify(int arg0) throws JposException {
+               // TODO Auto-generated method stub
+               
+       }
+
+       @Override
+       public void clearInput() throws JposException {
+               // TODO Auto-generated method stub
+               
+       }
+
+       @Override
+       public boolean getAutoDisable() throws JposException {
+               // TODO Auto-generated method stub
+               return false;
+       }
+
+       @Override
+       public boolean getCapKeyUp() throws JposException {
+               // TODO Auto-generated method stub
+               return false;
+       }
+
+       @Override
+       public int getDataCount() throws JposException {
+               // TODO Auto-generated method stub
+               return 0;
+       }
+
+       @Override
+       public boolean getDataEventEnabled() throws JposException {
+               // TODO Auto-generated method stub
+               return false;
+       }
+
+       @Override
+       public int getEventTypes() throws JposException {
+               // TODO Auto-generated method stub
+               return 0;
+       }
+
+       @Override
+       public int getPOSKeyData() throws JposException {
+               // TODO Auto-generated method stub
+               return 0;
+       }
+
+       @Override
+       public int getPOSKeyEventType() throws JposException {
+               // TODO Auto-generated method stub
+               return 0;
+       }
+
+       @Override
+       public void setAutoDisable(boolean arg0) throws JposException {
+               // TODO Auto-generated method stub
+               
+       }
+
+       @Override
+       public void setDataEventEnabled(boolean arg0) throws JposException {
+               // TODO Auto-generated method stub
+               
+       }
+
+       @Override
+       public void setEventTypes(int arg0) throws JposException {
+               // TODO Auto-generated method stub
+               
+       }
+
+       @Override
+       public void checkHealth(int arg0) throws JposException {
+               // TODO Auto-generated method stub
+               
+       }
+
+       @Override
+       public void claim(int arg0) throws JposException {
+               // TODO Auto-generated method stub
+               
+       }
+
+       @Override
+       public void close() throws JposException {
+               // TODO Auto-generated method stub
+               
+       }
+
+       @Override
+       public void directIO(int arg0, int[] arg1, Object arg2)
+                       throws JposException {
+               // TODO Auto-generated method stub
+               
+       }
+
+       @Override
+       public String getCheckHealthText() throws JposException {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       @Override
+       public boolean getClaimed() throws JposException {
+               // TODO Auto-generated method stub
+               return false;
+       }
+
+       @Override
+       public boolean getDeviceEnabled() throws JposException {
+               // TODO Auto-generated method stub
+               return false;
+       }
+
+       @Override
+       public String getDeviceServiceDescription() throws JposException {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       @Override
+       public int getDeviceServiceVersion() throws JposException {
+               return this.deviceVersion12;
+       }
+
+       @Override
+       public boolean getFreezeEvents() throws JposException {
+               // TODO Auto-generated method stub
+               return false;
+       }
+
+       @Override
+       public String getPhysicalDeviceDescription() throws JposException {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       @Override
+       public String getPhysicalDeviceName() throws JposException {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       @Override
+       public int getState() throws JposException {
+               // TODO Auto-generated method stub
+               return 0;
+       }
+
+       @Override
+       public void open(String paramString, EventCallbacks paramEventCallbacks) throws JposException {
+               this.logicalname = paramString;
+               
+               //La clase EventCallbacks se crea en la clase POSKeyboard, y contiene 
+               //los objectos listeners generados en nuestro wrapper
+               //Esos objectos lo que contienen son punteros a funciones (en Java 
+               //realmente todo son punteros) conocidas como callbacks
+               //
+               //  this.dataListener = new DataListener() {
+        //    @Override
+               //        public void dataOccurred(final DataEvent dataEvent) {
+               //               JPosScaleWrapper.this.processDataOccurredOccurred(dataEvent);  <--- Esto es el "puntero" a funcion que será lo que se almacene en la clase EventCallbacs (se almacena el objecto DataListener que implementa la callback o puntero a funcion) ya a nivel Jpos (se introduce en el nivel Jpos algo creado en un nivel superior, es decir, en nuestro Wrapper)
+               //        }
+               //  }
+               //  this.scale.addDataListener(this.dataListener); <-- addDataListener es un método definido en POSKeyboard que introduce el objeto DataListener en un Vector (al introducir ese objecto lo que está haciendo es pasar el callback, en Java lo han hecho así, en C,C++ por ejemplo podría haberse pasado directamente el puntero a función
+               this.callbacks = paramEventCallbacks; //<---- En este objeto dentro del Vector está el objecto DataListener creado en el Wrapper
+               
+               //Podemos extraer los valores de configuracion del jpos.xml o jpos.properties tal como sigue:
+               //(Wincord usa la clase OSServiceConfiguration para hacer lo mismo)
+               JposServiceManager localJposServiceManager = JposServiceLoader.getManager();
+               //Esto contiene todo el jpos.xml o el jpos.properties correctamente ordenado y parseado
+               this.jposEntryRegistry = localJposServiceManager.getEntryRegistry();
+               //Así podemos obtener toda la configuracion localizada en el jpos.xml o .properties 
+               //para un determinado dispostivo
+               //cuyo nombre pasamos aqui como parametro de entrada.
+               //NOTA: Roberto lo que hacia era en la Factoria hacer esto mismo (recuperar 
+               //el jposEntryRegistry y el jposEntry
+               //y pasarselo directamente al constructor. Mi constructor no hace nada 
+               //(no lo he implementado, al menos todavia)
+               //En mi caso el constructor no hace eso y tengo que recuperarlo aquí
+               //(keine Ahnung was ist besser)
+               this.jposEntry = this.jposEntryRegistry.getJposEntry(paramString);
+               
+               
+               //Aqui comienzo a leer toda la posible configuracion para cumplir con un Keyboard POS.
+               //Finalmente de este modo podemos ir obteniendo la configuracion de ese 
+               //dispositivo pasado los campos
+               String str = readJposConfiguration(this.jposEntry,this.jposEntryRegistry);
+               if ( str != null)
+               {
+                       //En caso de devolver un string, este string es el mensaje de error.
+                       throw new JposException(JPOS_E_ILLEGAL, str);
+               }
+               
+               //Recuperamos el codigo Java que lee eventos HW del teclado y los almacena en el 
+               //DataEvent. Si hubiera que modificar el driver podria hacerse creando un nuevo
+               //interfaz que extiende de BaseKeyBoardDriver y aqui deberiamos aniadir algo
+               //que hiciera cast al nuevo interfaz que extiende de BaseKeyBoardDriver. De esta forma
+               //si hay que aniadir algo al driver no hay que modificar casi nada del codigo. 
+               //Ademas si queremos cambiar el driver lo unico que hay que hacer es crear una nueva
+               //clase que implemente el interfaz BaseKeyBoardDriver y poner el nombre de la clase
+               //en el jpos.xml o en el jpos.properties en el campo driverClass que es donde he definido
+               //que se ponga el nombre de la clase que implementa el driver. En Wincord era en dcalClass.
+               //Por ejemplo yo ahora tendria que aniadir un campos driverClass al jpos.xml de la N2A
+               //con la clase de.javapos.example.hardware.KeyBoardDeviceLinux
+               //Lo que no me gusta es que la factoria si se cambiara debe hacerse aquí en el codigo :S
+               //TODO: poner la factoria tambien como un campo en el jpos.xml y extraerla por reflexión.
+               this.jposDriverFactory = new JposDriverInstanceFactoryImpl();
+               this.deviceDriver = this.jposDriverFactory.createInstance(paramString, this.jposEntry, 
+                                                                                                                                       BaseKeyBoardDriver.class);
+               
+               //Crear la cola donde almacenamos eventos estilo FIFO.
+               //Esto tambien puede hacerser en jpos.xml y queda todo como un puzle LOL
+               //TODO: poner la cola de eventos en el jpos.xml
+               this.jposEventQueue = new JposEventQueueImpl(this.callbacks);
+               this.deviceDriver.addEventListener(this.jposEventQueue);
+               
+               
+       }
+       
+       private String readJposConfiguration(JposEntry jposEntry, JposEntryRegistry jposEntryRegistry)
+       {
+               String str;
+               final String device = "device";
+               final String maxEvents = "maxEvents";
+               final String keyTable = "keyTable";
+           JposEntry tableJposKey;
+               
+               //Primero: obtener el dispositivo de caracteres.
+               if ( jposEntry.hasPropertyWithName(device) ){
+                       //Chequeamos que lo que estamos leyendo es un String (deberia ser algo como /dev/wn_javapos_kbd0)
+                       if (String.class == jposEntry.getPropertyType(device))
+                       {
+                               this.device = (String)jposEntry.getPropertyValue(device);
+                       }else
+                               return "open-readJposConfiguration(): illegal device name.";
+               }else
+                       return "open-readJposConfiguration(): A property called 'device' with " +
+                                       "the path of the character device of the keyboard is needed";
+               
+               
+               //Segundo: obtener el numero maximo de eventos.
+               if ( jposEntry.hasPropertyWithName(maxEvents) ){
+                       if ((str = (String)jposEntry.getPropertyValue(maxEvents)) != null)
+                       {
+                               try
+                               {
+                                       this.maxEvents = Integer.decode(str).intValue();
+                               }
+                               catch (NumberFormatException localNumberFormatException)
+                               {
+                                       return "open-readJposConfiguration(): illegal jpos property maxEvents '" + 
+                                                       str + "is not a number";
+                               }
+                       }
+               }else
+                       return "open-readJposConfiguration(): A property called 'maxEvents' with is needed";
+               
+               
+               //Tercero: obtener la tabla de caracteres del teclado (si existe) puede ser de Dia o de Wincor
+               //PASO DE HACER ESTO AHORA, ME ABURRE LOL.
+               if ( jposEntry.hasPropertyWithName(keyTable)){
+                       if (String.class == jposEntry.getPropertyType(keyTable)){
+                               str = (String)jposEntry.getPropertyValue(keyTable);
+                               tableJposKey=jposEntryRegistry.getJposEntry(str);
+                       }else
+                               return "open-readJposConfiguration(): illegal jpos property keyTable '" + 
+                                               str + "is not a String";
+                       
+                       /*PASO DE HACER ESTO DE MOMENTO, PARSEAR ESO ME ABURRE LOL*/
+                       
+                       
+               }
+               
+               return null;
+       }
+
+       @Override
+       public void release() throws JposException {
+               // TODO Auto-generated method stub
+               
+       }
+       
+
+       @Override
+       public void setDeviceEnabled(boolean deviceEnable) throws JposException {
+               this.deviceDriver.enable();
+               
+       }
+
+       @Override
+       public void setFreezeEvents(boolean arg0) throws JposException {
+               // TODO Auto-generated method stub
+               
+       }
+
+       @Override
+       public void deleteInstance() throws JposException {
+               // TODO Auto-generated method stub
+               
+       }
+
+       @Override
+       public boolean getCapCompareFirmwareVersion() throws JposException {
+               // TODO Auto-generated method stub
+               return false;
+       }
+
+       @Override
+       public boolean getCapUpdateFirmware() throws JposException {
+               // TODO Auto-generated method stub
+               return false;
+       }
+
+       @Override
+       public void compareFirmwareVersion(String firmwareFileName, int[] result)
+                       throws JposException {
+               // TODO Auto-generated method stub
+               
+       }
+
+       @Override
+       public void updateFirmware(String firmwareFileName) throws JposException {
+               // TODO Auto-generated method stub
+               
+       }
+
+       @Override
+       public boolean getCapStatisticsReporting() throws JposException {
+               // TODO Auto-generated method stub
+               return false;
+       }
+
+       @Override
+       public boolean getCapUpdateStatistics() throws JposException {
+               // TODO Auto-generated method stub
+               return false;
+       }
+
+       @Override
+       public void resetStatistics(String statisticsBuffer) throws JposException {
+               // TODO Auto-generated method stub
+               
+       }
+
+       @Override
+       public void retrieveStatistics(String[] statisticsBuffer)
+                       throws JposException {
+               // TODO Auto-generated method stub
+               
+       }
+
+       @Override
+       public void updateStatistics(String statisticsBuffer) throws JposException {
+               // TODO Auto-generated method stub
+               
+       }
+       
+       
+       
+       
+}
\ No newline at end of file
diff --git a/JavaPOS/KeyBoardDriver/src/main/java/de/javapos/example/ThreadSafe.java b/JavaPOS/KeyBoardDriver/src/main/java/de/javapos/example/ThreadSafe.java
new file mode 100755 (executable)
index 0000000..fa2c197
--- /dev/null
@@ -0,0 +1,5 @@
+package de.javapos.example;
+
+public @interface ThreadSafe {
+
+}
diff --git a/JavaPOS/KeyBoardDriver/src/main/java/de/javapos/example/hardware/BaseKeyBoardDriver.java b/JavaPOS/KeyBoardDriver/src/main/java/de/javapos/example/hardware/BaseKeyBoardDriver.java
new file mode 100755 (executable)
index 0000000..b4f8a9d
--- /dev/null
@@ -0,0 +1,52 @@
+/**
+ * 
+ */
+package de.javapos.example.hardware;
+
+import de.javapos.example.queue.JposEventQueue;
+import jpos.JposException;
+
+/**
+ * @author
+ *
+ */
+public interface BaseKeyBoardDriver {
+       
+       public boolean isOpened();
+
+       public void close() throws JposException;
+    
+       public void claim() throws JposException;
+       
+       public void claim(int paramInt) throws JposException;
+
+       public void release() throws JposException;
+       
+       public boolean isClaimed();
+       
+       public void enable() throws JposException;
+       
+       public void disable() throws JposException;
+       
+       public boolean isEnabled();
+       
+       public void addEventListener(JposEventQueue jposEventQueue) throws JposException;
+       
+       public void removeEventListener(JposEventQueue jposEventQueue);
+       
+       public boolean write(byte[] paramArrayOfByte, int paramInt1, int paramInt2, 
+                       int paramInt3) throws JposException;
+       
+       public int read(byte[] paramArrayOfByte, int paramInt1, int paramInt2, 
+               int paramInt3) throws JposException;
+       
+       public int writeRead(byte[] paramArrayOfByte1, int paramInt1, 
+                       int paramInt2, byte[] paramArrayOfByte2, int paramInt3, int paramInt4, 
+                       int paramInt5) throws JposException;
+       
+       public String getDescription(int paramInt);
+               
+       public void flush(int paramInt) throws JposException;
+       
+       public void device(String device) throws JposException;
+}
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
new file mode 100755 (executable)
index 0000000..1a0dab1
--- /dev/null
@@ -0,0 +1,239 @@
+package de.javapos.example.hardware;
+
+import java.io.DataInputStream;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.RejectedExecutionException;
+import java.util.concurrent.Semaphore;
+import jpos.JposConst;
+import jpos.JposException;
+import org.apache.log4j.Logger;
+import de.javapos.example.ThreadSafe;
+import de.javapos.example.queue.JposEventQueue;
+
+public class KeyBoardDeviceLinux implements BaseKeyBoardDriver {
+       private static final Logger logger = Logger.getLogger(KeyBoardDeviceLinux.class);
+       //value EV_KEY from include/linux/input.h
+       private static final int EV_KEY = 1;
+       private Semaphore mutex = new Semaphore(1, true);
+       private JposEventQueue eventQueue;
+       private final ExecutorService exec = Executors.newSingleThreadExecutor();
+       private DataInputStream device;
+       private boolean isClaimed;
+       private boolean autoDisable;
+       
+       @Override
+       public boolean isOpened() {
+               // TODO Auto-generated method stub
+               return false;
+       }
+
+       @Override
+       public void close() throws JposException {
+               // TODO Auto-generated method stub
+
+       }
+
+       
+       /**
+        * 
+        * @throws JposException
+        */
+       @Override
+       public void claim() throws JposException {
+               this.claim(0);
+       }
+
+       @Override
+       public void claim(int paramInt) throws JposException {
+
+
+       }
+
+       @Override
+       public void release() throws JposException {
+               // TODO Auto-generated method stub
+
+       }
+
+       @Override
+       public boolean isClaimed() {
+               return this.isClaimed;
+       }
+
+       /**
+        * 
+        * NO OLVIDAR try/finally PARA DEJAR EL DISPOSITIVO CORRECTAMENTE
+        * @throws JposException
+        * @throws RejectedExecutionException if this task cannot be
+     * accepted for execution. CUIDADO RUNTIME NO OLVIDAR try/finally PARA DEJAR BIEN EL DISPOSITIVO
+        */
+       @Override
+       public void enable() throws JposException {
+               if (this.device == null) {
+                       throw new JposException(JposConst.JPOSERR, "There is not an assigned device", 
+                                       new NullPointerException("The device field has null value"));
+               }
+               //Mirar en capitulo 8? como hacer que no se encolen mas tareas
+               //(por si se llama varias veces a enable ¿sin querer?)
+               //me da a mí que en este caso es una chorrada usar Executor... :(
+               //En el Executor hay que cambiar la Policy (si se puede) y usar: {@link ThreadPoolExecutor.DiscardPolicy}
+               //Por defecto usa una que lanza excepcion RunTime si no pueden añadirse nuevas tareas :(
+               this.exec.execute(new HardwareLoop(this.device));
+       }
+
+       @Override
+       public void disable() throws JposException {
+               this.exec.shutdownNow();
+       }
+
+       @Override
+       public boolean isEnabled() {
+               return this.exec.isTerminated();
+       }
+
+       @Override
+       public void addEventListener(JposEventQueue jposEventQueue)
+                       throws JposException {
+               this.eventQueue = jposEventQueue;
+
+       }
+
+       @Override
+       public void removeEventListener(JposEventQueue jposEventQueue) {
+               // TODO Auto-generated method stub
+
+       }
+
+       @Override
+       public boolean write(byte[] paramArrayOfByte, int paramInt1, int paramInt2,
+                       int paramInt3) throws JposException {
+               // TODO Auto-generated method stub
+               return false;
+       }
+
+       @Override
+       public int read(byte[] paramArrayOfByte, int paramInt1, int paramInt2,
+                       int paramInt3) throws JposException {
+               // TODO Auto-generated method stub
+               return 0;
+       }
+
+       @Override
+       public int writeRead(byte[] paramArrayOfByte1, int paramInt1,
+                       int paramInt2, byte[] paramArrayOfByte2, int paramInt3,
+                       int paramInt4, int paramInt5) throws JposException {
+               // TODO Auto-generated method stub
+               return 0;
+       }
+
+       @Override
+       public String getDescription(int paramInt) {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       @Override
+       public void flush(int paramInt) throws JposException {
+               // TODO Auto-generated method stub
+
+       }
+       
+       
+       /**
+        * 
+        * NO OLVIDAR try/finally PARA DEJAR EL DISPOSITIVO CORRECTAMENTE
+        * @throws JposException
+        */
+       @Override
+       public void device(String device) throws JposException {
+               try {
+                       this.device = new DataInputStream(new FileInputStream(device));
+               } catch (FileNotFoundException e) {
+                       throw new JposException(JposConst.JPOS_E_NOHARDWARE, "Device not found.",e);
+               }
+       }
+       
+       @ThreadSafe
+       private class HardwareLoop implements Runnable {
+               private final DataInputStream device;
+               
+               private HardwareLoop (DataInputStream device) {
+                       this.device = device;
+               }
+               
+               @Override
+               public void run() {
+                       byte []buffer = new byte[16];
+                       short code = 0;
+                       short type = 0;
+                       int value = 0;
+                       int ch1 = 0;
+                       int ch2 = 0;
+                       int ch3 = 0;
+                       int ch4 = 0;
+                       
+                       try {
+                               while (!Thread.currentThread().isInterrupted()) {
+                                       //using command: evtest /dev/input/event4
+                                       this.device.readFully(buffer);
+                                       ch1 = buffer[11];
+                               ch2 = buffer[10];
+                               code = (short)((ch1 << 8) + (ch2 << 0));
+                               
+                               ch1 = buffer[9];
+                               ch2 = buffer[8];
+                               type = (short)((ch1 << 8) + (ch2 << 0));
+                               
+                               
+                               ch1 = buffer[15];
+                               ch2 = buffer[14];;
+                               ch3 = buffer[13];
+                               ch4 = buffer[12];
+                               value = ((ch1 << 24) + (ch2 << 16) + (ch3 << 8) + (ch4 << 0));
+                               
+                               
+                               if (type == KeyBoardDeviceLinux.EV_KEY) {
+                                       System.out.println("type: " + type + " code: " + code + " value: " + value);
+                               }
+                               }
+                       } catch (IOException e) {
+                               logger.error("KeyBoardDeviceLinux:", e);
+                       } finally {
+                               try {
+                                       this.device.close();
+                                       //SI EL HILO MUERE ¿DEBERÍA DEJAR EL ESTADO DEL DISPOSITIVO LOGICO JAVAPOS
+                                       //EN UN MODO CONSISTENTE?
+                               } catch (IOException e1) {
+                                       logger.warn("KeyBoardDeviceLinux:", e1);
+                               }
+                       }
+               }
+       }
+
+       
+       public static void main(String[] param) throws InterruptedException
+       {
+               //Because I do not have a POS I am going to use the keyboard of my computer.
+               //see: /dev/input/by-path/
+               //And the Keyborad scancode is for USB devices.
+               String device ="/dev/input/event4";
+               
+               KeyBoardDeviceLinux driver = new KeyBoardDeviceLinux();
+               
+               System.out.println("Main test of KeyBoardDeviceLinux class");
+               try {
+                       driver.device(device);
+                       driver.enable();
+                       Thread.sleep(5000);
+                       driver.disable();
+                       System.out.println("End test of KeyBoardDeviceLinux class");
+               } catch (JposException e) {
+                       e.getOrigException().printStackTrace();
+                       e.printStackTrace();
+               }
+       }
+}
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
new file mode 100755 (executable)
index 0000000..91ef58c
--- /dev/null
@@ -0,0 +1,12 @@
+package de.javapos.example.queue;
+
+import jpos.events.JposEvent;
+
+public interface JposEventQueue {
+       
+       public void inputAvailable(JposEvent input);
+       
+       public void errorOccurred(JposEvent error);
+       
+       public void statusUpdateOccurred(JposEvent status);
+}
\ No newline at end of file
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
new file mode 100755 (executable)
index 0000000..3b09787
--- /dev/null
@@ -0,0 +1,63 @@
+package de.javapos.example.queue;
+
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
+import jpos.events.JposEvent;
+import jpos.services.EventCallbacks;
+
+public class JposEventQueueImpl implements JposEventQueue {
+       private final EventCallbacks callbacks;
+       //§JLS Item 16: Favor composition over inheritance
+       //Java Concurrency in Practice 4.4.2
+       //Not sure if this may be called "Composition" LOL
+       private final BlockingQueue<JposEvent> linkedBlockingQueue = new LinkedBlockingQueue<JposEvent>();
+       
+       public JposEventQueueImpl (EventCallbacks callbacks) {
+               this.callbacks = callbacks;
+       }
+       
+       @Override
+       public void inputAvailable(JposEvent input) {
+               try {
+                       this.linkedBlockingQueue.put(input);
+               } catch (InterruptedException e) {
+                       //Java Concurrency in Practice 5.4: Restore the interrupt.
+                       //restore interrupted status. Because we do not know where this code is going to be used.
+                       //TODO: After reading Java Concurrency in Practice chapter 7 you must decide
+                       //if you should throw the interrupt exception or just restore the interrupt
+                       //as I am doing right now. In the meanwhile just restoring the interrupt.
+                       //EN MI OPIONION SERIA MEJOR NO COGER LA EXCEPCION AQUI Y PONER throws EN EL INTERFAZ
+                       //JposEventQueue
+                       Thread.currentThread().interrupt();
+               }
+               
+       }
+
+       @Override
+       public void errorOccurred(JposEvent error) {
+               try {
+                       this.linkedBlockingQueue.put(error);
+               } catch (InterruptedException e) {
+                       //Java Concurrency in Practice 5.4: Restore the interrupt.
+                       //restore interrupted status. Because we do not know where this code is going to be used.
+                       //TODO: After reading Java Concurrency in Practice chapter 7 you must decide
+                       //if you should throw the interrupt exception or just restore the interrupt
+                       //as I am doing right now. In the meanwhile just restoring the interrupt.
+                       Thread.currentThread().interrupt();
+               }
+       }
+
+       @Override
+       public void statusUpdateOccurred(JposEvent status) {
+               try {
+                       this.linkedBlockingQueue.put(status);
+               } catch (InterruptedException e) {
+                       //Java Concurrency in Practice 5.4: Restore the interrupt.
+                       //restore interrupted status. Because we do not know where this code is going to be used.
+                       //TODO: After reading Java Concurrency in Practice chapter 7 you must decide
+                       //if you should throw the interrupt exception or just restore the interrupt
+                       //as I am doing right now. In the meanwhile just restoring the interrupt.
+                       Thread.currentThread().interrupt();
+               }       
+       }
+}
diff --git a/JavaPOS/KeyBoardDriver/src/main/java/es/dia/pos/n2a/gus/jpos/BaseKeyBoardDriver.java b/JavaPOS/KeyBoardDriver/src/main/java/es/dia/pos/n2a/gus/jpos/BaseKeyBoardDriver.java
deleted file mode 100644 (file)
index ef44764..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-/**
- * 
- */
-package es.dia.pos.n2a.gus.jpos;
-
-import jpos.JposException;
-
-/**
- * @author
- *
- */
-public interface BaseKeyBoardDriver extends Runnable {
-       
-       public boolean isOpened();
-
-       public void close() throws JposException;
-    
-       public void claim() throws JposException;
-       
-       public void claim(int paramInt) throws JposException;
-
-       public void release() throws JposException;
-       
-       public boolean isClaimed();
-       
-       public void enable() throws JposException;
-       
-       public void disable() throws JposException;
-       
-       public boolean isEnabled();
-       
-       public void addEventListener(DCALEventListener paramDCALEventListener) throws JposException;
-       
-       public void removeEventListener(DCALEventListener paramDCALEventListener);
-       
-       public boolean write(byte[] paramArrayOfByte, int paramInt1, int paramInt2, 
-                       int paramInt3) throws JposException;
-       
-       public int read(byte[] paramArrayOfByte, int paramInt1, int paramInt2, 
-               int paramInt3) throws JposException;
-       
-       public int writeRead(byte[] paramArrayOfByte1, int paramInt1, 
-                       int paramInt2, byte[] paramArrayOfByte2, int paramInt3, int paramInt4, 
-                       int paramInt5) throws JposException;
-       
-       public String getDescription(int paramInt);
-               
-       public void flush(int paramInt) throws JposException;
-}
diff --git a/JavaPOS/KeyBoardDriver/src/main/java/es/dia/pos/n2a/gus/jpos/EventQueue.java b/JavaPOS/KeyBoardDriver/src/main/java/es/dia/pos/n2a/gus/jpos/EventQueue.java
deleted file mode 100644 (file)
index dc880ea..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-package es.dia.pos.n2a.gus.jpos;\r
-\r
-\r
-\r
-\r
-/**\r
- * Instance factory to get the JPOS device services\r
- * @author\r
- */\r
-public class EventQueue extends Thread\r
-{\r
-       //Esto se ejectua en el constructor que hay por defecto (y que no se ve en este caso, \r
-        //si quisiera podria hacerlo tambien en ese constructor pero así queda mas ordenado)\r
-        private boolean isEnabled = false;\r
-        \r
-        \r
-        public void run() {\r
-\r
-                \r
-        }       \r
-        \r
-        /*private void enable ()\r
-        {\r
-                threadEventSpool = new Thread(this);\r
-                threadEventSpool.start();\r
-                threadEventSpool.setName("Thread-GUSPOSKeyboard");\r
-        }*/\r
-}\r
diff --git a/JavaPOS/KeyBoardDriver/src/main/java/es/dia/pos/n2a/gus/jpos/JposDriverInstanceFactory.java b/JavaPOS/KeyBoardDriver/src/main/java/es/dia/pos/n2a/gus/jpos/JposDriverInstanceFactory.java
deleted file mode 100644 (file)
index 4de9b91..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-/**
- * 
- */
-package es.dia.pos.n2a.gus.jpos;
-
-import jpos.JposException;
-import jpos.config.JposEntry;
-
-/**
- * @author
- *
- */
-public interface JposDriverInstanceFactory {
-
-       /**
-        * 
-        * @param logicalName 
-        * @param jposEntry
-        * @param entry
-        * @return
-        * @throws JposException
-        */
-       public <E> E createInstance(String logicalName, JposEntry entry, Class<E> pruebaClass) throws JposException;
-}
diff --git a/JavaPOS/KeyBoardDriver/src/main/java/es/dia/pos/n2a/gus/jpos/JposDriverInstanceFactoryImpl.java b/JavaPOS/KeyBoardDriver/src/main/java/es/dia/pos/n2a/gus/jpos/JposDriverInstanceFactoryImpl.java
deleted file mode 100644 (file)
index 48b56d4..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-package es.dia.pos.n2a.gus.jpos;\r
-\r
-\r
-import java.lang.reflect.Constructor;\r
-\r
-import jpos.JposConst;\r
-import jpos.JposException;\r
-import jpos.config.JposEntry;\r
-\r
-/**\r
- * Retrieve the device HW driver using this instance factory.\r
- * @author \r
- */\r
-public class JposDriverInstanceFactoryImpl implements JposDriverInstanceFactory\r
-{      \r
-       \r
-    /**\r
-     * @input_parameters: \r
-     */ \r
-       @Override\r
-       public <E> E createInstance(String logicalName, JposEntry entry, Class<E> typeClass) throws JposException \r
-       {\r
-       if (entry.getPropertyValue("driverClass") == null)\r
-        {\r
-            throw new JposException(JposConst.JPOS_E_NOSERVICE, "Missing driverClass JposEntry");\r
-        }      \r
-       E driverInstance = null;\r
-        try\r
-        {\r
-            String serviceClassName = (String)entry.getPropertyValue("driverClass");\r
-            Class<?> serviceClass = Class.forName(serviceClassName);\r
-            Class<?>[] params = new Class<?>[0];\r
-            Constructor<?> ctor = serviceClass.getConstructor(params);\r
-            if (typeClass.isInstance(ctor.newInstance((Object[])params)) )\r
-            {\r
-               //This cast is correct (IMHO) because we are checking the right type\r
-               //with the method isInstance.\r
-               //Why must I declare this local variable with SuppressWarnings? This is weird...\r
-               @SuppressWarnings("unchecked") E aux = (E)ctor.newInstance((Object[])params);\r
-               driverInstance = aux;\r
-            }\r
-        }\r
-        catch(Exception e)\r
-        {\r
-               throw new JposException(JposConst.JPOS_E_NOSERVICE, "Could not create " +\r
-                       "the driver instance for device with logicalName= " + logicalName, e);\r
-        }   \r
-        return driverInstance;\r
-       }\r
-}\r
diff --git a/JavaPOS/KeyBoardDriver/src/main/java/es/dia/pos/n2a/gus/jpos/JposServiceInstanceFactoryImpl.java b/JavaPOS/KeyBoardDriver/src/main/java/es/dia/pos/n2a/gus/jpos/JposServiceInstanceFactoryImpl.java
deleted file mode 100644 (file)
index 941a2e6..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-package es.dia.pos.n2a.gus.jpos;\r
-\r
-\r
-import java.lang.reflect.Constructor;\r
-\r
-import jpos.JposConst;\r
-import jpos.JposException;\r
-import jpos.config.JposEntry;\r
-import jpos.loader.JposServiceInstance;\r
-import jpos.loader.JposServiceInstanceFactory;\r
-\r
-/**\r
- * Instance factory to get the JPOS device services\r
- * @author \r
- */\r
-public class JposServiceInstanceFactoryImpl implements JposServiceInstanceFactory\r
-{    \r
-    /**\r
-     * @input_parameters: \r
-     * entry: (for jpos.xml and jpos.properties must be serviceClass)\r
-     * logicalName: device's name (in jpos.xml or jpos.properties file, jpos.xml file by default)\r
-     */\r
-    public JposServiceInstance createInstance(String logicalName, JposEntry entry) throws JposException\r
-    {\r
-        if(!entry.hasPropertyWithName(JposEntry.SERVICE_CLASS_PROP_NAME))\r
-        {\r
-            throw new JposException(JposConst.JPOS_E_NOSERVICE, "The JposEntry does not contain the 'serviceClass' property");\r
-        }\r
-        JposServiceInstance serviceInstance = null;\r
-        try\r
-        {\r
-            String serviceClassName = (String)entry.getPropertyValue(JposEntry.SERVICE_CLASS_PROP_NAME);\r
-            Class<?> serviceClass = Class.forName(serviceClassName);\r
-            Class<?>[] params = new Class<?>[0];\r
-            Constructor<?> ctor = serviceClass.getConstructor(params);\r
-            serviceInstance = (JposServiceInstance)ctor.newInstance((Object[])params);\r
-        }\r
-        catch(Exception e)\r
-        {\r
-            throw new JposException(JposConst.JPOS_E_NOSERVICE, "Could not create " +\r
-                       "the service instance with logicalName= " + logicalName, e);\r
-        }\r
-        return serviceInstance;\r
-    }\r
-}\r
diff --git a/JavaPOS/KeyBoardDriver/src/main/java/es/dia/pos/n2a/gus/jpos/KBDDeviceLinux.java b/JavaPOS/KeyBoardDriver/src/main/java/es/dia/pos/n2a/gus/jpos/KBDDeviceLinux.java
deleted file mode 100644 (file)
index 3b4b70a..0000000
+++ /dev/null
@@ -1,162 +0,0 @@
-/**
- * 
- */
-package es.dia.pos.n2a.gus.jpos;
-
-import jpos.JposException;
-
-/**
- * @author
- *
- */
-public class KBDDeviceLinux implements BaseKeyBoardDriver {
-
-       /* (non-Javadoc)
-        * @see es.dia.pos.n2a.gus.jpos.KeyBoardDriver#isOpened()
-        */
-       @Override
-       public boolean isOpened() {
-               // TODO Auto-generated method stub
-               return false;
-       }
-
-       /* (non-Javadoc)
-        * @see es.dia.pos.n2a.gus.jpos.KeyBoardDriver#close()
-        */
-       @Override
-       public void close() throws JposException {
-               // TODO Auto-generated method stub
-
-       }
-
-       /* (non-Javadoc)
-        * @see es.dia.pos.n2a.gus.jpos.KeyBoardDriver#claim()
-        */
-       @Override
-       public void claim() throws JposException {
-               // TODO Auto-generated method stub
-
-       }
-
-       /* (non-Javadoc)
-        * @see es.dia.pos.n2a.gus.jpos.KeyBoardDriver#claim(int)
-        */
-       @Override
-       public void claim(int paramInt) throws JposException {
-               // TODO Auto-generated method stub
-
-       }
-
-       /* (non-Javadoc)
-        * @see es.dia.pos.n2a.gus.jpos.KeyBoardDriver#release()
-        */
-       @Override
-       public void release() throws JposException {
-               // TODO Auto-generated method stub
-
-       }
-
-       /* (non-Javadoc)
-        * @see es.dia.pos.n2a.gus.jpos.KeyBoardDriver#isClaimed()
-        */
-       @Override
-       public boolean isClaimed() {
-               // TODO Auto-generated method stub
-               return false;
-       }
-
-       /* (non-Javadoc)
-        * @see es.dia.pos.n2a.gus.jpos.KeyBoardDriver#enable()
-        */
-       @Override
-       public void enable() throws JposException {
-               // TODO Auto-generated method stub
-
-       }
-
-       /* (non-Javadoc)
-        * @see es.dia.pos.n2a.gus.jpos.KeyBoardDriver#disable()
-        */
-       @Override
-       public void disable() throws JposException {
-               // TODO Auto-generated method stub
-
-       }
-
-       /* (non-Javadoc)
-        * @see es.dia.pos.n2a.gus.jpos.KeyBoardDriver#isEnabled()
-        */
-       @Override
-       public boolean isEnabled() {
-               // TODO Auto-generated method stub
-               return false;
-       }
-
-       /* (non-Javadoc)
-        * @see es.dia.pos.n2a.gus.jpos.KeyBoardDriver#write(byte[], int, int, int)
-        */
-       @Override
-       public boolean write(byte[] paramArrayOfByte, int paramInt1, int paramInt2,
-                       int paramInt3) throws JposException {
-               // TODO Auto-generated method stub
-               return false;
-       }
-
-       /* (non-Javadoc)
-        * @see es.dia.pos.n2a.gus.jpos.KeyBoardDriver#read(byte[], int, int, int)
-        */
-       @Override
-       public int read(byte[] paramArrayOfByte, int paramInt1, int paramInt2,
-                       int paramInt3) throws JposException {
-               // TODO Auto-generated method stub
-               return 0;
-       }
-
-       /* (non-Javadoc)
-        * @see es.dia.pos.n2a.gus.jpos.KeyBoardDriver#writeRead(byte[], int, int, byte[], int, int, int)
-        */
-       @Override
-       public int writeRead(byte[] paramArrayOfByte1, int paramInt1,
-                       int paramInt2, byte[] paramArrayOfByte2, int paramInt3,
-                       int paramInt4, int paramInt5) throws JposException {
-               // TODO Auto-generated method stub
-               return 0;
-       }
-
-       /* (non-Javadoc)
-        * @see es.dia.pos.n2a.gus.jpos.KeyBoardDriver#getDescription(int)
-        */
-       @Override
-       public String getDescription(int paramInt) {
-               // TODO Auto-generated method stub
-               return null;
-       }
-
-       /* (non-Javadoc)
-        * @see es.dia.pos.n2a.gus.jpos.KeyBoardDriver#flush(int)
-        */
-       @Override
-       public void flush(int paramInt) throws JposException {
-               // TODO Auto-generated method stub
-
-       }
-
-       @Override
-       public void addEventListener(DCALEventListener paramDCALEventListener)
-                       throws JposException {
-               // TODO Auto-generated method stub
-               
-       }
-
-       @Override
-       public void removeEventListener(DCALEventListener paramDCALEventListener) {
-               // TODO Auto-generated method stub
-               
-       }
-
-       @Override
-       public void run() {
-               // TODO Auto-generated method stub
-               
-       }
-}
diff --git a/JavaPOS/KeyBoardDriver/src/main/java/es/dia/pos/n2a/gus/jpos/POSKeyboard.java b/JavaPOS/KeyBoardDriver/src/main/java/es/dia/pos/n2a/gus/jpos/POSKeyboard.java
deleted file mode 100644 (file)
index 123b4e7..0000000
+++ /dev/null
@@ -1,346 +0,0 @@
-package es.dia.pos.n2a.gus.jpos;
-
-import java.io.FileInputStream;
-import jpos.JposConst;
-import jpos.JposException;
-import jpos.POSKeyboardConst;
-import jpos.config.simple.SimpleEntryRegistry;
-import jpos.loader.JposServiceLoader;
-import jpos.loader.JposServiceManager;
-import jpos.services.EventCallbacks;
-import jpos.services.POSKeyboardService17;
-import jpos.config.JposEntry;
-import jpos.config.JposEntryRegistry;
-import jpos.events.DataEvent;
-import jpos.events.DataListener;
-public class POSKeyboard implements POSKeyboardService17, JposConst, POSKeyboardConst
-{
-       private String logicalname;
-       private EventCallbacks callbacks = null;
-       private JposEntryRegistry jposEntryRegistry = null;
-       private JposEntry jposEntry = null;
-       private String device;
-       private int maxEvents;
-       private BaseKeyBoardDriver deviceDriver;
-       private JposDriverInstanceFactory jposDriverFactory;
-       
-       @Override
-       public int getCapPowerReporting() throws JposException {
-               // TODO Auto-generated method stub
-               return 0;
-       }
-
-       @Override
-       public int getPowerNotify() throws JposException {
-               // TODO Auto-generated method stub
-               return 0;
-       }
-
-       @Override
-       public int getPowerState() throws JposException {
-               // TODO Auto-generated method stub
-               return 0;
-       }
-
-       @Override
-       public void setPowerNotify(int arg0) throws JposException {
-               // TODO Auto-generated method stub
-               
-       }
-
-       @Override
-       public void clearInput() throws JposException {
-               // TODO Auto-generated method stub
-               
-       }
-
-       @Override
-       public boolean getAutoDisable() throws JposException {
-               // TODO Auto-generated method stub
-               return false;
-       }
-
-       @Override
-       public boolean getCapKeyUp() throws JposException {
-               // TODO Auto-generated method stub
-               return false;
-       }
-
-       @Override
-       public int getDataCount() throws JposException {
-               // TODO Auto-generated method stub
-               return 0;
-       }
-
-       @Override
-       public boolean getDataEventEnabled() throws JposException {
-               // TODO Auto-generated method stub
-               return false;
-       }
-
-       @Override
-       public int getEventTypes() throws JposException {
-               // TODO Auto-generated method stub
-               return 0;
-       }
-
-       @Override
-       public int getPOSKeyData() throws JposException {
-               // TODO Auto-generated method stub
-               return 0;
-       }
-
-       @Override
-       public int getPOSKeyEventType() throws JposException {
-               // TODO Auto-generated method stub
-               return 0;
-       }
-
-       @Override
-       public void setAutoDisable(boolean arg0) throws JposException {
-               // TODO Auto-generated method stub
-               
-       }
-
-       @Override
-       public void setDataEventEnabled(boolean arg0) throws JposException {
-               // TODO Auto-generated method stub
-               
-       }
-
-       @Override
-       public void setEventTypes(int arg0) throws JposException {
-               // TODO Auto-generated method stub
-               
-       }
-
-       @Override
-       public void checkHealth(int arg0) throws JposException {
-               // TODO Auto-generated method stub
-               
-       }
-
-       @Override
-       public void claim(int arg0) throws JposException {
-               // TODO Auto-generated method stub
-               
-       }
-
-       @Override
-       public void close() throws JposException {
-               // TODO Auto-generated method stub
-               
-       }
-
-       @Override
-       public void directIO(int arg0, int[] arg1, Object arg2)
-                       throws JposException {
-               // TODO Auto-generated method stub
-               
-       }
-
-       @Override
-       public String getCheckHealthText() throws JposException {
-               // TODO Auto-generated method stub
-               return null;
-       }
-
-       @Override
-       public boolean getClaimed() throws JposException {
-               // TODO Auto-generated method stub
-               return false;
-       }
-
-       @Override
-       public boolean getDeviceEnabled() throws JposException {
-               // TODO Auto-generated method stub
-               return false;
-       }
-
-       @Override
-       public String getDeviceServiceDescription() throws JposException {
-               // TODO Auto-generated method stub
-               return null;
-       }
-
-       @Override
-       public int getDeviceServiceVersion() throws JposException {
-               // TODO Auto-generated method stub
-               return 0;
-       }
-
-       @Override
-       public boolean getFreezeEvents() throws JposException {
-               // TODO Auto-generated method stub
-               return false;
-       }
-
-       @Override
-       public String getPhysicalDeviceDescription() throws JposException {
-               // TODO Auto-generated method stub
-               return null;
-       }
-
-       @Override
-       public String getPhysicalDeviceName() throws JposException {
-               // TODO Auto-generated method stub
-               return null;
-       }
-
-       @Override
-       public int getState() throws JposException {
-               // TODO Auto-generated method stub
-               return 0;
-       }
-
-       @Override
-       public void open(String paramString, EventCallbacks paramEventCallbacks) throws JposException {
-               this.logicalname = paramString;
-               
-               //La clase EventCallbacks se crea en la clase POSKeyboard, y contiene 
-               //los objectos listeners generados en nuestro wrapper
-               //Esos objectos lo que contienen son punteros a funciones (en Java 
-               //realmente todo son punteros) conocidas como callbacks
-               //
-               //  this.dataListener = new DataListener() {
-        //    @Override
-               //        public void dataOccurred(final DataEvent dataEvent) {
-               //               JPosScaleWrapper.this.processDataOccurredOccurred(dataEvent);  <--- Esto es el "puntero" a funcion que será lo que se almacene en la clase EventCallbacs (se almacena el objecto DataListener que implementa la callback o puntero a funcion) ya a nivel Jpos (se introduce en el nivel Jpos algo creado en un nivel superior, es decir, en nuestro Wrapper)
-               //        }
-               //  }
-               //  this.scale.addDataListener(this.dataListener); <-- addDataListener es un método definido en POSKeyboard que introduce el objeto DataListener en un Vector (al introducir ese objecto lo que está haciendo es pasar el callback, en Java lo han hecho así, en C,C++ por ejemplo podría haberse pasado directamente el puntero a función
-               this.callbacks = paramEventCallbacks; //<---- En este objeto dentro del Vector está el objecto DataListener creado en el Wrapper
-               
-               //Podemos extraer los valores de configuracion del jpos.xml o jpos.properties tal como sigue:
-               //(Wincord usa la clase OSServiceConfiguration para hacer lo mismo)
-               JposServiceManager localJposServiceManager = JposServiceLoader.getManager();
-               //Esto contiene todo el jpos.xml o el jpos.properties correctamente ordenado y parseado
-               this.jposEntryRegistry = localJposServiceManager.getEntryRegistry();
-               //Así podemos obtener toda la configuracion localizada en el jpos.xml o .properties 
-               //para un determinado dispostivo
-               //cuyo nombre pasamos aqui como parametro de entrada.
-               //NOTA: Roberto lo que hacia era en la Factoria hacer esto mismo (recuperar 
-               //el jposEntryRegistry y el jposEntry
-               //y pasarselo directamente al constructor. Mi constructor no hace nada 
-               //(no lo he implementado, al menos todavia)
-               //En mi caso el constructor no hace eso y tengo que recuperarlo aquí
-               //(keine Ahnung was ist besser)
-               this.jposEntry = this.jposEntryRegistry.getJposEntry(paramString);
-               
-               
-               //Aqui comienzo a leer toda la posible configuracion para cumplir con un Keyboard POS.
-               //Finalmente de este modo podemos ir obteniendo la configuracion de ese 
-               //dispositivo pasado los campos
-               String str = readJposConfiguration(this.jposEntry,this.jposEntryRegistry);
-               if ( str != null)
-               {
-                       //En caso de devolver un string, este string es el mensaje de error.
-                       throw new JposException(JPOS_E_ILLEGAL, str);
-               }
-               
-               //Recuperamos el codigo Java que lee eventos HW del teclado y los almacena en el 
-               //DataEvent. Si hubiera que modificar el driver podria hacerse creando un nuevo
-               //interfaz que extiende de BaseKeyBoardDriver y aqui deberiamos aniadir algo
-               //que hiciera cast al nuevo interfaz que extiende de BaseKeyBoardDriver. De esta forma
-               //si hay que aniadir algo al driver no hay que modificar casi nada del codigo. 
-               //Ademas si queremos cambiar el driver lo unico que hay que hacer es crear una nueva
-               //clase que implemente el interfaz BaseKeyBoardDriver y poner el nombre de la clase
-               //en el jpos.xml o en el jpos.properties en el campo driverClass que es donde he definido
-               //que se ponga el nombre de la clase que implementa el driver. En Wincord era en dcalClass.
-               //Por ejemplo yo ahora tendria que aniadir un campos driverClass al jpos.xml de la N2A
-               //con la clase es.dia.pos.n2a.gus.jpos.GUSKBDDeviceLinux
-               //Lo que no me gusta es que la factoria si se cambiara debe hacerse aquí en el codigo :S
-               this.jposDriverFactory = new JposDriverInstanceFactoryImpl();
-               BaseKeyBoardDriver instanceHWDriver = this.jposDriverFactory.createInstance(paramString, 
-                               this.jposEntry, BaseKeyBoardDriver.class);
-               
-       }
-       
-       private String readJposConfiguration(JposEntry jposEntry, JposEntryRegistry jposEntryRegistry)
-       {
-               String str;
-               final String device = "device";
-               final String maxEvents = "maxEvents";
-               final String keyTable = "keyTable";
-           JposEntry tableJposKey;
-               
-               //Primero: obtener el dispositivo de caracteres.
-               if ( jposEntry.hasPropertyWithName(device) ){
-                       //Chequeamos que lo que estamos leyendo es un String (deberia ser algo como /dev/wn_javapos_kbd0)
-                       if (String.class == jposEntry.getPropertyType(device))
-                       {
-                               this.device = (String)jposEntry.getPropertyValue(device);
-                       }else
-                               return "open-readJposConfiguration(): illegal device name.";
-               }else
-                       return "open-readJposConfiguration(): A property called 'device' with " +
-                                       "the path of the character device of the keyboard is needed";
-               
-               
-               //Segundo: obtener el numero maximo de eventos.
-               if ( jposEntry.hasPropertyWithName(maxEvents) ){
-                       if ((str = (String)jposEntry.getPropertyValue(maxEvents)) != null)
-                       {
-                               try
-                               {
-                                       this.maxEvents = Integer.decode(str).intValue();
-                               }
-                               catch (NumberFormatException localNumberFormatException)
-                               {
-                                       return "open-readJposConfiguration(): illegal jpos property maxEvents '" + 
-                                                       str + "is not a number";
-                               }
-                       }
-               }else
-                       return "open-readJposConfiguration(): A property called 'maxEvents' with is needed";
-               
-               
-               //Tercero: obtener la tabla de caracteres del teclado (si existe) puede ser de Dia o de Wincor
-               //PASO DE HACER ESTO AHORA, ME ABURRE LOL.
-               if ( jposEntry.hasPropertyWithName(keyTable)){
-                       if (String.class == jposEntry.getPropertyType(keyTable)){
-                               str = (String)jposEntry.getPropertyValue(keyTable);
-                               tableJposKey=jposEntryRegistry.getJposEntry(str);
-                       }else
-                               return "open-readJposConfiguration(): illegal jpos property keyTable '" + 
-                                               str + "is not a String";
-                       
-                       /*PASO DE HACER ESTO DE MOMENTO, PARSEAR ESO ME ABURRE LOL*/
-                       
-                       
-               }
-               
-               return null;
-       }
-
-       @Override
-       public void release() throws JposException {
-               // TODO Auto-generated method stub
-               
-       }
-       
-
-       @Override
-       public void setDeviceEnabled(boolean arg0) throws JposException {
-               // TODO Auto-generated method stub
-               
-       }
-
-       @Override
-       public void setFreezeEvents(boolean arg0) throws JposException {
-               // TODO Auto-generated method stub
-               
-       }
-
-       @Override
-       public void deleteInstance() throws JposException {
-               // TODO Auto-generated method stub
-               
-       }
-       
-       
-       
-       
-}
\ No newline at end of file
diff --git a/JavaPOS/KeyBoardDriver/src/main/resources/jpos.xml b/JavaPOS/KeyBoardDriver/src/main/resources/jpos.xml
new file mode 100755 (executable)
index 0000000..69daae3
--- /dev/null
@@ -0,0 +1,143 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<JposEntries xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="jpos.xsd">
+
+    <!-- Wincor KeyBoard  -->
+    <JposEntry logicalName="WN_KB2">
+        <creation factoryClass="com.wn.retail.jpos17.WNJposServiceInstanceFactory" serviceClass="com.wn.retail.jpos17.WNPOSKeyboard" />
+        <vendor name="Wincor Nixdorf" url="http://www.wincor-nixdorf.com" />
+        <jpos category="POSKeyboard" version="1.7" />
+        <product description="TA61 POS Keyboard, JPOS1.7" name="Wincor Nixdorf Services for JavaPOS(TM) Standard" url="http://www.wincor-nixdorf.com" />
+        <!--
+               Other non JavaPOS required property (mostly vendor properties and bus
+                       specific properties i.e. RS232 )
+        -->
+        <prop name="dcalClass" type="String" value="com.wn.retail.jpos17.dcal.KBDDeviceLinux, KBD" />
+        <prop name="posKeyDataMode" type="String" value="0" />
+        <prop name="keyTable" type="String" value="TableTA61" />
+        <prop name="openMode" type="String" value="process" />
+    </JposEntry>
+
+    <!-- My Custom KeyBoard  -->
+    <JposEntry logicalName="myPOSKeyBoard">
+        <creation factoryClass="de.javapos.example.JposServiceInstanceFactoryImpl" serviceClass="de.javapos.example.MyPOSKeyboard"/>
+        <vendor name="Gustavo Martin Morcuende" url="http://www.gumartinm.name"/>
+        <jpos category="POSKeyboard" version="1.12"/>
+        <product description="Jpos Service for TA61 POS Keyboard, JPOS1.12" name="Services for JavaPOS(TM) Standard" url="http://www.gumartinm.name"/>
+        <prop name="device" type="String" value="/dev/input/event5"/>
+        <prop name="maxEvents" type="String" value="1024"/>
+        <!--   <prop name="keyTable" type="String" value="scancodes_to_WN_KB"/> -->
+        <prop name="keyTable" type="String" value="WN.KeyTranslation.TableTA61"/>
+        <!-- timeout absurdamente grande, ¡esto es JavaTM! -->
+        <prop name="checkTimeout" type="String" value="5000"/>
+    </JposEntry>
+
+    <!--KeyBoard map keys -->
+    <JposEntry logicalName="WN.KeyTranslation.TableTA61">
+        <creation factoryClass="&lt;none&gt;" serviceClass="&lt;none&gt;"/>
+        <vendor name="WincorNixdorf" url="http://www.wincor-nixdorf.com"/>
+        <jpos category="POSKeyboard" version="1.7"/>
+        <product description="Reference Entry for regular entries" name="ReferenceEntry" url="&lt;none&gt;"/>
+        <!--Other non JavaPOS required property (mostly vendor properties and bus specific properties i.e. RS232 )-->
+        <prop name="59" type="String" value="7143498=0x0000102c"/>
+        <prop name="58" type="String" value="7012430=0x0000102b"/>
+        <prop name="57" type="String" value="5308432=0x00001029"/>
+        <prop name="56" type="String" value="5242905=0x00001028"/>
+        <prop name="55" type="String" value="5177368=0x00001027"/>
+        <prop name="54" type="String" value="5832748=0x00001026"/>
+        <prop name="53" type="String" value="5046322=0x00001025"/>
+        <prop name="52" type="String" value="851996=0x00001024"/>
+        <prop name="51" type="String" value="6488145=0x00000033"/>
+        <prop name="50" type="String" value="2228305=0x00000033"/>
+        <prop name="49" type="String" value="6422608=0x00000032"/>
+        <prop name="48" type="String" value="2621520=0x00000032"/>
+        <prop name="47" type="String" value="6357071=0x00000031"/>
+        <prop name="46" type="String" value="2293839=0x00000031"/>
+        <prop name="45" type="String" value="2228561=0x00001023"/>
+        <prop name="44" type="String" value="2621776=0x00001022"/>
+        <prop name="43" type="String" value="2294095=0x00001021"/>
+        <prop name="42" type="String" value="4980774=0x0000101f"/>
+        <prop name="41" type="String" value="4915237=0x0000101e"/>
+        <prop name="40" type="String" value="4849700=0x0000101d"/>
+        <prop name="39" type="String" value="4784151=0x0000101c"/>
+        <prop name="38" type="String" value="4718627=0x0000101b"/>
+        <prop name="37" type="String" value="4653090=0x0000101a"/>
+        <prop name="36" type="String" value="6684749=0x00000036"/>
+        <prop name="35" type="String" value="2555981=0x00000036"/>
+        <prop name="34" type="String" value="6619212=0x00000035"/>
+        <prop name="33" type="String" value="786508=0x00000035"/>
+        <prop name="32" type="String" value="6553675=0x00000034"/>
+        <prop name="31" type="String" value="2424907=0x00000034"/>
+        <prop name="referenceEntryDescription" type="String" value="key table definition for TA61 (POSKeyboard)"/>
+        <prop name="30" type="String" value="2556237=0x00001019"/>
+        <prop name="referenceEntryDevCat" type="String" value="POSKeyboard"/>
+        <prop name="29" type="String" value="2097209=0x00001018"/>
+        <prop name="28" type="String" value="2425163=0x00001017"/>
+        <prop name="27" type="String" value="4587553=0x00001015"/>
+        <prop name="26" type="String" value="4522002=0x00001014"/>
+        <prop name="25" type="String" value="4456480=0x00001013"/>
+        <prop name="24" type="String" value="4390958=0x00001012"/>
+        <prop name="23" type="String" value="4325424=0x00001011"/>
+        <prop name="22" type="String" value="4259870=0x00001010"/>
+        <prop name="21" type="String" value="6881353=0x00000039"/>
+        <prop name="20" type="String" value="2162761=0x00000039"/>
+        <prop name="9" type="String" value="7733313=0x00001009"/>
+        <prop name="8" type="String" value="7667776=0x00001008"/>
+        <prop name="7" type="String" value="7602239=0x00001007"/>
+        <prop name="6" type="String" value="7536702=0x00001006"/>
+        <prop name="5" type="String" value="7471165=0x00001005"/>
+        <prop name="4" type="String" value="7405628=0x00001004"/>
+        <prop name="3" type="String" value="7340091=0x00001003"/>
+        <prop name="2" type="String" value="524302=0x00001002"/>
+        <prop name="1" type="String" value="1769473=0x00001001"/>
+        <prop name="19" type="String" value="6815816=0x00000038"/>
+        <prop name="18" type="String" value="2490440=0x00000038"/>
+        <prop name="17" type="String" value="6750279=0x00000037"/>
+        <prop name="16" type="String" value="2359367=0x00000037"/>
+        <prop name="15" type="String" value="2163017=0x0000100f"/>
+        <prop name="14" type="String" value="2490696=0x0000100e"/>
+        <prop name="13" type="String" value="2359623=0x0000100d"/>
+        <prop name="12" type="String" value="7929924=0x0000100c"/>
+        <prop name="11" type="String" value="7864387=0x0000100b"/>
+        <prop name="10" type="String" value="7798850=0x0000100a"/>
+        <prop name="71" type="String" value="5111857=0x00001035"/>
+        <prop name="70" type="String" value="5898261=0x00001034"/>
+        <prop name="69" type="String" value="5767213=0x00001033"/>
+        <prop name="68" type="String" value="5701649=0x00001032"/>
+        <prop name="67" type="String" value="5636143=0x00001031"/>
+        <prop name="66" type="String" value="5570582=0x00001030"/>
+        <prop name="65" type="String" value="7209043=0x0000102f"/>
+        <prop name="64" type="String" value="3014739=0x0000102f"/>
+        <prop name="63" type="String" value="5439519=0x0000102e"/>
+        <prop name="62" type="String" value="5373971=0x0000102d"/>
+        <prop name="61" type="String" value="6291538=0x00000030"/>
+        <prop name="60" type="String" value="2949202=0x00000030"/>
+    </JposEntry>
+
+       <!-- Wincor Key -->
+    <JposEntry logicalName="WN_KL">
+        <creation factoryClass="com.wn.retail.jpos17.WNJposServiceInstanceFactory" serviceClass="com.wn.retail.jpos17.WNKeylock" />
+        <vendor name="Wincor Nixdorf" url="http://www.wincor-nixdorf.com" />
+        <jpos category="Keylock" version="1.7" />
+        <product description="Keylock of TAxx POS Keyboard, JPOS1.7" name="Wincor Nixdorf Services for JavaPOS(TM) Standard" url="http://www.wincor-nixdorf.com" />
+        <!--
+            Other non JavaPOS required property (mostly vendor properties and bus specific properties i.e. RS232 )
+        -->
+        <prop name="uses" type="String" value="POSKeyboard.WN_KB1p" />
+        <prop name="dcalClass" type="String" value="com.wn.retail.jpos17.dcal.KBDDeviceLinux, LOCK" />
+        <prop name="keylocktype" type="String" value="lock" />
+        <prop name="getDMIInfo" type="String" value="on" />
+    </JposEntry>
+    
+    <!--Custom Key (Keylock)  -->
+    <JposEntry logicalName="myKeyLock">
+        <creation factoryClass="de.javapos.example.JposServiceInstanceFactoryImpl" serviceClass="de.javapos.example.MyKeylock"/>
+        <vendor name="Gustavo Martin Morcuende" url="http://www.gumartinm.name"/>
+        <jpos category="Keylock" version="1.7"/>
+        <product description="Jpos Service for TA61 POS Keylock, JPOS1.12" name="Services for JavaPOS(TM) Standard" url="http://www.gumartinm.name"/>
+        <prop name="device" type="String" value="/dev/input/event5"/>
+        <prop name="maxEvents" type="String" value="1024"/>
+        <prop name="checkTimeout" type="String" value="5000"/>
+    </JposEntry>
+
+</JposEntries>