jpos.POSPower Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of javapos-controls Show documentation
Show all versions of javapos-controls Show documentation
JavaPOS Device Controls Library
//////////////////////////////////////////////////////////////////////
//
// The JavaPOS library source code is now under the CPL license, which
// is an OSS Apache-like license. The complete license is located at:
// http://www.ibm.com/developerworks/library/os-cpl.html
//
//////////////////////////////////////////////////////////////////////
//------------------------------------------------------------------------------
//
// This software is provided "AS IS". The JavaPOS working group (including
// each of the Corporate members, contributors and individuals) MAKES NO
// REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE SOFTWARE,
// EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
// WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NON-INFRINGEMENT. The JavaPOS working group shall not be liable for
// any damages suffered as a result of using, modifying or distributing this
// software or its derivatives.Permission to use, copy, modify, and distribute
// the software and its documentation for any purpose is hereby granted.
//
// POSPower.java - A JavaPOS 1.6.0 device control
//
//------------------------------------------------------------------------------
package jpos;
import jpos.events.*;
import jpos.services.*;
import java.util.Vector;
import jpos.loader.*;
public class POSPower
implements POSPowerControl16, JposConst
{
//--------------------------------------------------------------------------
// Variables
//--------------------------------------------------------------------------
// Static Data
protected static final String deviceControlDescription =
"JavaPOS POSPower Device Control";
protected static final int deviceControlVersion = 1006000; // 1.6.0
protected static final int deviceVersion15 = 1005000; // 1.5.0
protected static final int deviceVersion16 = 1006000; // 1.6.0
// Instance Data
protected JposServiceConnection serviceConnection;
protected int serviceVersion;
protected POSPowerService15 service15;
protected POSPowerService16 service16;
protected Vector directIOListeners;
protected Vector statusUpdateListeners;
//--------------------------------------------------------------------------
// Constructor
//--------------------------------------------------------------------------
public POSPower()
{
serviceConnection = null;
service15 = null;
service16 = null;
directIOListeners = new Vector();
statusUpdateListeners = new Vector();
}
//--------------------------------------------------------------------------
// Capabilities
//--------------------------------------------------------------------------
public boolean getCapFanAlarm()
throws JposException
{
try
{
return service15.getCapFanAlarm();
}
catch(JposException je)
{
throw je;
}
catch(Exception e)
{
throw new JposException(JPOS_E_CLOSED, "Control not opened", e);
}
}
public boolean getCapHeatAlarm()
throws JposException
{
try
{
return service15.getCapHeatAlarm();
}
catch(JposException je)
{
throw je;
}
catch(Exception e)
{
throw new JposException(JPOS_E_CLOSED, "Control not opened", e);
}
}
public int getCapPowerReporting()
throws JposException
{
try
{
return service15.getCapPowerReporting();
}
catch(JposException je)
{
throw je;
}
catch(Exception e)
{
throw new JposException(JPOS_E_CLOSED, "Control not opened", e);
}
}
public boolean getCapQuickCharge()
throws JposException
{
try
{
return service15.getCapQuickCharge();
}
catch(JposException je)
{
throw je;
}
catch(Exception e)
{
throw new JposException(JPOS_E_CLOSED, "Control not opened", e);
}
}
public boolean getCapShutdownPOS()
throws JposException
{
try
{
return service15.getCapShutdownPOS();
}
catch(JposException je)
{
throw je;
}
catch(Exception e)
{
throw new JposException(JPOS_E_CLOSED, "Control not opened", e);
}
}
public int getCapUPSChargeState()
throws JposException
{
try
{
return service15.getCapUPSChargeState();
}
catch(JposException je)
{
throw je;
}
catch(Exception e)
{
throw new JposException(JPOS_E_CLOSED, "Control not opened", e);
}
}
//--------------------------------------------------------------------------
// Properties
//--------------------------------------------------------------------------
public String getCheckHealthText()
throws JposException
{
try
{
return service15.getCheckHealthText();
}
catch(JposException je)
{
throw je;
}
catch(Exception e)
{
throw new JposException(JPOS_E_CLOSED, "Control not opened", e);
}
}
public boolean getClaimed()
throws JposException
{
try
{
return service15.getClaimed();
}
catch(JposException je)
{
throw je;
}
catch(Exception e)
{
throw new JposException(JPOS_E_CLOSED, "Control not opened", e);
}
}
public String getDeviceControlDescription()
{
return deviceControlDescription;
}
public int getDeviceControlVersion()
{
return deviceControlVersion;
}
public boolean getDeviceEnabled()
throws JposException
{
try
{
return service15.getDeviceEnabled();
}
catch(JposException je)
{
throw je;
}
catch(Exception e)
{
throw new JposException(JPOS_E_CLOSED, "Control not opened", e);
}
}
public void setDeviceEnabled(boolean deviceEnabled)
throws JposException
{
try
{
service15.setDeviceEnabled(deviceEnabled);
}
catch(JposException je)
{
throw je;
}
catch(Exception e)
{
throw new JposException(JPOS_E_CLOSED, "Control not opened", e);
}
}
public String getDeviceServiceDescription()
throws JposException
{
try
{
return service15.getDeviceServiceDescription();
}
catch(JposException je)
{
throw je;
}
catch(Exception e)
{
throw new JposException(JPOS_E_CLOSED, "Control not opened", e);
}
}
public int getDeviceServiceVersion()
throws JposException
{
try
{
return service15.getDeviceServiceVersion();
}
catch(JposException je)
{
throw je;
}
catch(Exception e)
{
throw new JposException(JPOS_E_CLOSED, "Control not opened", e);
}
}
public boolean getFreezeEvents()
throws JposException
{
try
{
return service15.getFreezeEvents();
}
catch(JposException je)
{
throw je;
}
catch(Exception e)
{
throw new JposException(JPOS_E_CLOSED, "Control not opened", e);
}
}
public void setFreezeEvents(boolean freezeEvents)
throws JposException
{
try
{
service15.setFreezeEvents(freezeEvents);
}
catch(JposException je)
{
throw je;
}
catch(Exception e)
{
throw new JposException(JPOS_E_CLOSED, "Control not opened", e);
}
}
public String getPhysicalDeviceDescription()
throws JposException
{
try
{
return service15.getPhysicalDeviceDescription();
}
catch(JposException je)
{
throw je;
}
catch(Exception e)
{
throw new JposException(JPOS_E_CLOSED, "Control not opened", e);
}
}
public String getPhysicalDeviceName()
throws JposException
{
try
{
return service15.getPhysicalDeviceName();
}
catch(JposException je)
{
throw je;
}
catch(Exception e)
{
throw new JposException(JPOS_E_CLOSED, "Control not opened", e);
}
}
public int getState()
{
try
{
return service15.getState();
}
catch(Exception e)
{
return JPOS_S_CLOSED;
}
}
public int getEnforcedShutdownDelayTime()
throws JposException
{
try
{
return service15.getEnforcedShutdownDelayTime();
}
catch(JposException je)
{
throw je;
}
catch(Exception e)
{
throw new JposException(JPOS_E_CLOSED, "Control not opened", e);
}
}
public void setEnforcedShutdownDelayTime(int delay)
throws JposException
{
try
{
service15.setEnforcedShutdownDelayTime(delay);
}
catch(JposException je)
{
throw je;
}
catch(Exception e)
{
throw new JposException(JPOS_E_CLOSED, "Control not opened", e);
}
}
public int getPowerFailDelayTime()
throws JposException
{
try
{
return service15.getPowerFailDelayTime();
}
catch(JposException je)
{
throw je;
}
catch(Exception e)
{
throw new JposException(JPOS_E_CLOSED, "Control not opened", e);
}
}
public int getPowerNotify()
throws JposException
{
try
{
return service15.getPowerNotify();
}
catch(JposException je)
{
throw je;
}
catch(Exception e)
{
throw new JposException(JPOS_E_CLOSED, "Control not opened", e);
}
}
public void setPowerNotify(int powerNotify)
throws JposException
{
try
{
service15.setPowerNotify(powerNotify);
}
catch(JposException je)
{
throw je;
}
catch(Exception e)
{
throw new JposException(JPOS_E_CLOSED, "Control not opened", e);
}
}
public int getPowerState()
throws JposException
{
try
{
return service15.getPowerState();
}
catch(JposException je)
{
throw je;
}
catch(Exception e)
{
throw new JposException(JPOS_E_CLOSED, "Control not opened", e);
}
}
public boolean getQuickChargeMode()
throws JposException
{
try
{
return service15.getQuickChargeMode();
}
catch(JposException je)
{
throw je;
}
catch(Exception e)
{
throw new JposException(JPOS_E_CLOSED, "Control not opened", e);
}
}
public int getQuickChargeTime()
throws JposException
{
try
{
return service15.getQuickChargeTime();
}
catch(JposException je)
{
throw je;
}
catch(Exception e)
{
throw new JposException(JPOS_E_CLOSED, "Control not opened", e);
}
}
public int getUPSChargeState()
throws JposException
{
try
{
return service15.getUPSChargeState();
}
catch(JposException je)
{
throw je;
}
catch(Exception e)
{
throw new JposException(JPOS_E_CLOSED, "Control not opened", e);
}
}
//--------------------------------------------------------------------------
// Methods
//--------------------------------------------------------------------------
public void claim(int timeout)
throws JposException
{
try
{
service15.claim(timeout);
}
catch(JposException je)
{
throw je;
}
catch(Exception e)
{
throw new JposException(JPOS_E_CLOSED, "Control not opened", e);
}
}
public synchronized void close()
throws JposException
{
try
{
service15.close();
}
catch(JposException je)
{
throw je;
}
catch(Exception e)
{
throw new JposException(JPOS_E_CLOSED,
"Service not open",
e);
}
try
{
serviceConnection.disconnect();
}
catch(Exception e)
{
throw new JposException(JPOS_E_NOSERVICE,
"Unable to free service connection",
e);
}
finally
{
service15 = null;
service16 = null;
}
}
public void checkHealth(int level)
throws JposException
{
try
{
service15.checkHealth(level);
}
catch(JposException je)
{
throw je;
}
catch(Exception e)
{
throw new JposException(JPOS_E_CLOSED, "Control not opened", e);
}
}
public void directIO(int command, int[] data, Object object)
throws JposException
{
try
{
service15.directIO(command, data, object);
}
catch(JposException je)
{
throw je;
}
catch(Exception e)
{
throw new JposException(JPOS_E_CLOSED, "Control not opened", e);
}
}
public synchronized void open(String logicalDeviceName)
throws JposException
{
// Make sure the control is not already open
if(service15 != null)
{
throw new JposException(JPOS_E_ILLEGAL,
"Device control already open");
}
// Use JCL to get a connection to the device service
try
{
serviceConnection = JposServiceLoader.findService(logicalDeviceName);
serviceConnection.connect();
}
catch(JposException je)
{
throw je;
}
catch(Exception e)
{
throw new JposException(JPOS_E_NOSERVICE,
"Could not connect to service",
e);
}
// Get an instance of the minimum service level supported
try
{
service15 = (POSPowerService15)serviceConnection.getService();
}
catch(Exception e)
{
throw new JposException(JPOS_E_NOSERVICE,
"Could not get service instance",
e);
}
// Get service version
try
{
serviceVersion = service15.getDeviceServiceVersion();
}
catch(Exception e)
{
throw new JposException(JPOS_E_NOSERVICE,
"Could not get service version information",
e);
}
// Make sure that the service actually conforms to the interfaces it
// claims to.
if(serviceVersion >= deviceVersion16)
{
try
{
service16 = (POSPowerService16)service15;
}
catch(Exception e)
{
throw new JposException(JPOS_E_NOSERVICE,
"Service does not fully implement POSPowerDevice16 interface",
e);
}
}
// Create callback subclass and attach it to the device service
POSPowerCallbacks callbacks = this.new POSPowerCallbacks();
service15.open(logicalDeviceName, callbacks);
}
public void release()
throws JposException
{
try
{
service15.release();
}
catch(JposException je)
{
throw je;
}
catch(Exception e)
{
throw new JposException(JPOS_E_CLOSED, "Control not opened", e);
}
}
public void shutdownPOS()
throws JposException
{
try
{
service15.shutdownPOS();
}
catch(JposException je)
{
throw je;
}
catch(Exception e)
{
throw new JposException(JPOS_E_CLOSED, "Control not opened", e);
}
}
//--------------------------------------------------------------------------
// Event Listener Methods
//--------------------------------------------------------------------------
public void addDirectIOListener(DirectIOListener l)
{
synchronized(directIOListeners)
{
directIOListeners.addElement(l);
}
}
public void removeDirectIOListener(DirectIOListener l)
{
synchronized(directIOListeners)
{
directIOListeners.removeElement(l);
}
}
public void addStatusUpdateListener(StatusUpdateListener l)
{
synchronized(statusUpdateListeners)
{
statusUpdateListeners.addElement(l);
}
}
public void removeStatusUpdateListener(StatusUpdateListener l)
{
synchronized(statusUpdateListeners)
{
statusUpdateListeners.removeElement(l);
}
}
//--------------------------------------------------------------------------
// EventCallbacks inner class
//--------------------------------------------------------------------------
protected class POSPowerCallbacks implements EventCallbacks
{
public BaseControl getEventSource()
{
return (BaseControl)POSPower.this;
}
public void fireDataEvent(DataEvent e)
{
}
public void fireDirectIOEvent(DirectIOEvent e)
{
synchronized(POSPower.this.directIOListeners)
{
// deliver the event to all registered listeners
for(int x = 0; x < directIOListeners.size(); x++)
{
((DirectIOListener)directIOListeners.elementAt(x)).directIOOccurred(e);
}
}
}
public void fireErrorEvent(ErrorEvent e)
{
}
public void fireOutputCompleteEvent(OutputCompleteEvent e)
{
}
public void fireStatusUpdateEvent(StatusUpdateEvent e)
{
synchronized(POSPower.this.statusUpdateListeners)
{
// deliver the event to all registered listeners
for(int x = 0; x < statusUpdateListeners.size(); x++)
{
((StatusUpdateListener)statusUpdateListeners.elementAt(x)).statusUpdateOccurred(e);
}
}
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy