From: gumartinm Date: Thu, 29 Mar 2012 15:12:07 +0000 (+0200) Subject: Many modifications in my JavaPOS key board driver. X-Git-Url: https://git.gumartinm.name/?a=commitdiff_plain;h=bcbba3b80046d46d4269e6494158a656ef0d5730;p=JavaForFun Many modifications in my JavaPOS key board driver. --- diff --git a/JavaPOS/KeyBoardDriver/pom.xml b/JavaPOS/KeyBoardDriver/pom.xml index dda8b95..b556c53 100644 --- a/JavaPOS/KeyBoardDriver/pom.xml +++ b/JavaPOS/KeyBoardDriver/pom.xml @@ -1,7 +1,7 @@ 4.0.0 - es.dia.pos.n2a + de.javapos.example javapos-keyboard-driver 1.0 javapos-keyboard-driver @@ -17,5 +17,10 @@ jpos-controls 1.12.2 + + log4j + log4j + 1.2.15 + 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 index 0000000..d6cc664 --- /dev/null +++ b/JavaPOS/KeyBoardDriver/src/main/java/de/javapos/example/JposDriverInstanceFactory.java @@ -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 createInstance(String logicalName, JposEntry entry, Class 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 index 0000000..c35aa6e --- /dev/null +++ b/JavaPOS/KeyBoardDriver/src/main/java/de/javapos/example/JposDriverInstanceFactoryImpl.java @@ -0,0 +1,48 @@ +package de.javapos.example; + +import java.lang.reflect.Constructor; +import jpos.JposConst; +import jpos.JposException; +import jpos.config.JposEntry; + +/** + * Retrieve the device HW driver using this instance factory. + * @author + */ +public class JposDriverInstanceFactoryImpl implements JposDriverInstanceFactory +{ + + /** + * @input_parameters: + */ + @Override + public E createInstance(String logicalName, JposEntry entry, Class typeClass) throws JposException + { + if (entry.getPropertyValue("driverClass") == null) + { + throw new JposException(JposConst.JPOS_E_NOSERVICE, "Missing driverClass JposEntry"); + } + E driverInstance = null; + try + { + String serviceClassName = (String)entry.getPropertyValue("driverClass"); + Class serviceClass = Class.forName(serviceClassName); + Class[] params = new Class[0]; + Constructor ctor = serviceClass.getConstructor(params); + if (typeClass.isInstance(ctor.newInstance((Object[])params)) ) + { + //This cast is correct (IMHO) because we are checking the right type + //with the method isInstance. + //Why must I declare this local variable with SuppressWarnings? This is weird... + @SuppressWarnings("unchecked") E aux = (E)ctor.newInstance((Object[])params); + driverInstance = aux; + } + } + catch(Exception e) + { + throw new JposException(JposConst.JPOS_E_NOSERVICE, "Could not create " + + "the driver instance for device with logicalName= " + logicalName, e); + } + return driverInstance; + } +} 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 index 0000000..fc50f86 --- /dev/null +++ b/JavaPOS/KeyBoardDriver/src/main/java/de/javapos/example/JposServiceInstanceFactoryImpl.java @@ -0,0 +1,43 @@ +package de.javapos.example; + +import java.lang.reflect.Constructor; +import jpos.JposConst; +import jpos.JposException; +import jpos.config.JposEntry; +import jpos.loader.JposServiceInstance; +import jpos.loader.JposServiceInstanceFactory; + +/** + * Instance factory to get the JPOS device services + * @author + */ +public class JposServiceInstanceFactoryImpl implements JposServiceInstanceFactory +{ + /** + * @input_parameters: + * entry: (for jpos.xml and jpos.properties must be serviceClass) + * logicalName: device's name (in jpos.xml or jpos.properties file, jpos.xml file by default) + */ + public JposServiceInstance createInstance(String logicalName, JposEntry entry) throws JposException + { + if(!entry.hasPropertyWithName(JposEntry.SERVICE_CLASS_PROP_NAME)) + { + throw new JposException(JposConst.JPOS_E_NOSERVICE, "The JposEntry does not contain the 'serviceClass' property"); + } + JposServiceInstance serviceInstance = null; + try + { + String serviceClassName = (String)entry.getPropertyValue(JposEntry.SERVICE_CLASS_PROP_NAME); + Class serviceClass = Class.forName(serviceClassName); + Class[] params = new Class[0]; + Constructor ctor = serviceClass.getConstructor(params); + serviceInstance = (JposServiceInstance)ctor.newInstance((Object[])params); + } + catch(Exception e) + { + throw new JposException(JposConst.JPOS_E_NOSERVICE, "Could not create " + + "the service instance with logicalName= " + logicalName, e); + } + return serviceInstance; + } +} 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 index 0000000..bf41f09 --- /dev/null +++ b/JavaPOS/KeyBoardDriver/src/main/java/de/javapos/example/MyPOSKeyboard.java @@ -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 index 0000000..fa2c197 --- /dev/null +++ b/JavaPOS/KeyBoardDriver/src/main/java/de/javapos/example/ThreadSafe.java @@ -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 index 0000000..b4f8a9d --- /dev/null +++ b/JavaPOS/KeyBoardDriver/src/main/java/de/javapos/example/hardware/BaseKeyBoardDriver.java @@ -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 index 0000000..1a0dab1 --- /dev/null +++ b/JavaPOS/KeyBoardDriver/src/main/java/de/javapos/example/hardware/KeyBoardDeviceLinux.java @@ -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 index 0000000..91ef58c --- /dev/null +++ b/JavaPOS/KeyBoardDriver/src/main/java/de/javapos/example/queue/JposEventQueue.java @@ -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 index 0000000..3b09787 --- /dev/null +++ b/JavaPOS/KeyBoardDriver/src/main/java/de/javapos/example/queue/JposEventQueueImpl.java @@ -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 linkedBlockingQueue = new LinkedBlockingQueue(); + + 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 index ef44764..0000000 --- a/JavaPOS/KeyBoardDriver/src/main/java/es/dia/pos/n2a/gus/jpos/BaseKeyBoardDriver.java +++ /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 index dc880ea..0000000 --- a/JavaPOS/KeyBoardDriver/src/main/java/es/dia/pos/n2a/gus/jpos/EventQueue.java +++ /dev/null @@ -1,28 +0,0 @@ -package es.dia.pos.n2a.gus.jpos; - - - - -/** - * Instance factory to get the JPOS device services - * @author - */ -public class EventQueue extends Thread -{ - //Esto se ejectua en el constructor que hay por defecto (y que no se ve en este caso, - //si quisiera podria hacerlo tambien en ese constructor pero así queda mas ordenado) - private boolean isEnabled = false; - - - public void run() { - - - } - - /*private void enable () - { - threadEventSpool = new Thread(this); - threadEventSpool.start(); - threadEventSpool.setName("Thread-GUSPOSKeyboard"); - }*/ -} 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 index 4de9b91..0000000 --- a/JavaPOS/KeyBoardDriver/src/main/java/es/dia/pos/n2a/gus/jpos/JposDriverInstanceFactory.java +++ /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 createInstance(String logicalName, JposEntry entry, Class 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 index 48b56d4..0000000 --- a/JavaPOS/KeyBoardDriver/src/main/java/es/dia/pos/n2a/gus/jpos/JposDriverInstanceFactoryImpl.java +++ /dev/null @@ -1,50 +0,0 @@ -package es.dia.pos.n2a.gus.jpos; - - -import java.lang.reflect.Constructor; - -import jpos.JposConst; -import jpos.JposException; -import jpos.config.JposEntry; - -/** - * Retrieve the device HW driver using this instance factory. - * @author - */ -public class JposDriverInstanceFactoryImpl implements JposDriverInstanceFactory -{ - - /** - * @input_parameters: - */ - @Override - public E createInstance(String logicalName, JposEntry entry, Class typeClass) throws JposException - { - if (entry.getPropertyValue("driverClass") == null) - { - throw new JposException(JposConst.JPOS_E_NOSERVICE, "Missing driverClass JposEntry"); - } - E driverInstance = null; - try - { - String serviceClassName = (String)entry.getPropertyValue("driverClass"); - Class serviceClass = Class.forName(serviceClassName); - Class[] params = new Class[0]; - Constructor ctor = serviceClass.getConstructor(params); - if (typeClass.isInstance(ctor.newInstance((Object[])params)) ) - { - //This cast is correct (IMHO) because we are checking the right type - //with the method isInstance. - //Why must I declare this local variable with SuppressWarnings? This is weird... - @SuppressWarnings("unchecked") E aux = (E)ctor.newInstance((Object[])params); - driverInstance = aux; - } - } - catch(Exception e) - { - throw new JposException(JposConst.JPOS_E_NOSERVICE, "Could not create " + - "the driver instance for device with logicalName= " + logicalName, e); - } - return driverInstance; - } -} 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 index 941a2e6..0000000 --- a/JavaPOS/KeyBoardDriver/src/main/java/es/dia/pos/n2a/gus/jpos/JposServiceInstanceFactoryImpl.java +++ /dev/null @@ -1,45 +0,0 @@ -package es.dia.pos.n2a.gus.jpos; - - -import java.lang.reflect.Constructor; - -import jpos.JposConst; -import jpos.JposException; -import jpos.config.JposEntry; -import jpos.loader.JposServiceInstance; -import jpos.loader.JposServiceInstanceFactory; - -/** - * Instance factory to get the JPOS device services - * @author - */ -public class JposServiceInstanceFactoryImpl implements JposServiceInstanceFactory -{ - /** - * @input_parameters: - * entry: (for jpos.xml and jpos.properties must be serviceClass) - * logicalName: device's name (in jpos.xml or jpos.properties file, jpos.xml file by default) - */ - public JposServiceInstance createInstance(String logicalName, JposEntry entry) throws JposException - { - if(!entry.hasPropertyWithName(JposEntry.SERVICE_CLASS_PROP_NAME)) - { - throw new JposException(JposConst.JPOS_E_NOSERVICE, "The JposEntry does not contain the 'serviceClass' property"); - } - JposServiceInstance serviceInstance = null; - try - { - String serviceClassName = (String)entry.getPropertyValue(JposEntry.SERVICE_CLASS_PROP_NAME); - Class serviceClass = Class.forName(serviceClassName); - Class[] params = new Class[0]; - Constructor ctor = serviceClass.getConstructor(params); - serviceInstance = (JposServiceInstance)ctor.newInstance((Object[])params); - } - catch(Exception e) - { - throw new JposException(JposConst.JPOS_E_NOSERVICE, "Could not create " + - "the service instance with logicalName= " + logicalName, e); - } - return serviceInstance; - } -} 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 index 3b4b70a..0000000 --- a/JavaPOS/KeyBoardDriver/src/main/java/es/dia/pos/n2a/gus/jpos/KBDDeviceLinux.java +++ /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 index 123b4e7..0000000 --- a/JavaPOS/KeyBoardDriver/src/main/java/es/dia/pos/n2a/gus/jpos/POSKeyboard.java +++ /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 index 0000000..69daae3 --- /dev/null +++ b/JavaPOS/KeyBoardDriver/src/main/resources/jpos.xml @@ -0,0 +1,143 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +