1 25 package org.ofbiz.pos.device; 26 27 import jpos.BaseControl; 28 import jpos.JposException; 29 30 import org.ofbiz.base.util.Debug; 31 import org.ofbiz.pos.event.MenuEvents; 32 import org.ofbiz.pos.screen.PosScreen; 33 34 40 public abstract class GenericDevice implements JposDevice { 41 42 public static final String module = GenericDevice.class.getName(); 43 44 protected BaseControl control = null; 45 protected String deviceName = null; 46 protected int timeout = -1; 47 48 public GenericDevice(String deviceName, int timeout) { 49 this.deviceName = deviceName; 50 this.timeout = timeout; 51 } 52 53 public void open() throws JposException { 54 if (deviceName != null && control != null) { 55 if (!"[NOT IMPLEMENTED]".equals(deviceName) && !"[DISABLED]".equals(deviceName)) { 56 control.open(deviceName); 57 control.claim(timeout); 58 this.enable(true); 59 this.initialize(); 60 } 61 } else { 62 Debug.logWarning("No device named [" + deviceName + "] available", module); 63 } 64 } 65 66 public void close() throws JposException { 67 control.release(); 68 control.close(); 69 control = null; 70 } 71 72 public boolean isEnabled() { 73 try { 74 return control.getDeviceEnabled(); 75 } catch (JposException e) { 76 Debug.logError(e, module); 77 return false; 78 } 79 } 80 81 public void enable(boolean enable) { 82 try { 83 control.setDeviceEnabled(enable); 84 } catch (JposException e) { 85 Debug.logError(e, module); 86 } 87 } 88 89 protected void callEnter() { 90 MenuEvents.triggerEnter(PosScreen.currentScreen, null); 92 MenuEvents.triggerClear(PosScreen.currentScreen); 93 } 94 95 protected abstract void initialize() throws JposException; 96 } 97 | Popular Tags |