/* ----------------------------------------------------------------------------
 * This file was automatically generated by SWIG (http://www.swig.org).
 * Version 2.0.11
 *
 * Do not make changes to this file unless you know what you are doing--modify
 * the SWIG interface file instead.
 * ----------------------------------------------------------------------------- */

package pt.gov.cartaodecidadao;
import java.util.*;
public class PTEID_ReaderContext extends PTEID_Object {
  private long swigCPtr;

  protected PTEID_ReaderContext(long cPtr, boolean cMemoryOwn) {
    super(pteidlibJava_WrapperJNI.PTEID_ReaderContext_SWIGUpcast(cPtr), cMemoryOwn);
    swigCPtr = cPtr;
  }

  protected static long getCPtr(PTEID_ReaderContext obj) {
    return (obj == null) ? 0 : obj.swigCPtr;
  }

  protected void finalize() {
    delete();
  }

  public synchronized void delete() {
    if (swigCPtr != 0) {
      if (swigCMemOwn) {
        swigCMemOwn = false;
        pteidlibJava_WrapperJNI.delete_PTEID_ReaderContext(swigCPtr);
      }
      swigCPtr = 0;
    }
    super.delete();
  }

	private static int		m_counter = 0;							// static counter to keep the nr of SetEventCallback we've done
	private static HashMap	m_CallbackContainer = new HashMap();	// static map to keep the data for each callback
	
	//------------------------------------------------------------
	// this function is called from C++ wrapper side as callback function.
	// It will receive the key in the map, from which it can recover
	// the callback helper class. This helper class contains the callback object
	// and the data object for this callback.
	// As such, the callback class will call, via the interface function of the callback object,
	// the Java application. The data object is passed as an argument.
	// In the application, this data from the dataobject can be read for whatever reason.
	//------------------------------------------------------------
	public static void doJavaCallBack( int iKey, long lRet, long ulState )
	{
		Integer key = new Integer(iKey);
		CallbackHelper callbackHelper = (CallbackHelper)m_CallbackContainer.get( key );
		callbackHelper.m_callbackObject.getEvent(lRet, ulState, callbackHelper.m_callbackData);
	}

  public PTEID_ReaderContext(PTEID_FileType fileType, String fileName) {
    this(pteidlibJava_WrapperJNI.new_PTEID_ReaderContext__SWIG_0(fileType.swigValue(), fileName), true);
  }

  public PTEID_ReaderContext(PTEID_FileType fileType, PTEID_ByteArray data) {
    this(pteidlibJava_WrapperJNI.new_PTEID_ReaderContext__SWIG_1(fileType.swigValue(), PTEID_ByteArray.getCPtr(data), data), true);
  }

  public PTEID_ReaderContext(PTEID_RawData_Eid data) {
    this(pteidlibJava_WrapperJNI.new_PTEID_ReaderContext__SWIG_2(PTEID_RawData_Eid.getCPtr(data), data), true);
  }

  public String getName() throws PTEID_Exception {
    return pteidlibJava_WrapperJNI.PTEID_ReaderContext_getName(swigCPtr, this);
  }

  public boolean isCardPresent() throws PTEID_Exception {
    return pteidlibJava_WrapperJNI.PTEID_ReaderContext_isCardPresent(swigCPtr, this);
  }

  public void releaseCard(boolean bAllReference) throws PTEID_Exception {
    pteidlibJava_WrapperJNI.PTEID_ReaderContext_releaseCard__SWIG_0(swigCPtr, this, bAllReference);
  }

  public void releaseCard() throws PTEID_Exception {
    pteidlibJava_WrapperJNI.PTEID_ReaderContext_releaseCard__SWIG_1(swigCPtr, this);
  }

  public boolean isCardChanged(PTEID_ulwrapper ulOldId) throws PTEID_Exception {
	  long pID = pteidlibJava_WrapperJNI.new_ulongp();				// get a C++ ptr
	  pteidlibJava_WrapperJNI.ulongp_assign(pID,ulOldId.m_long);
	  boolean retval = pteidlibJava_WrapperJNI.PTEID_ReaderContext_isCardChanged(swigCPtr, this, pID);
	  ulOldId.m_long = pteidlibJava_WrapperJNI.ulongp_value(pID);
	  pteidlibJava_WrapperJNI.delete_ulongp(pID);
	  return retval;
}

  public PTEID_CardType getCardType() throws PTEID_Exception {
    return PTEID_CardType.swigToEnum(pteidlibJava_WrapperJNI.PTEID_ReaderContext_getCardType(swigCPtr, this));
  }

  public PTEID_Card getCard() throws PTEID_Exception {
    return new PTEID_Card(pteidlibJava_WrapperJNI.PTEID_ReaderContext_getCard(swigCPtr, this), false);
  }

  public PTEID_EIDCard getEIDCard() throws PTEID_Exception {
    return new PTEID_EIDCard(pteidlibJava_WrapperJNI.PTEID_ReaderContext_getEIDCard(swigCPtr, this), false);
  }

  public long SetEventCallback(Callback callback, Object pvRef) throws PTEID_Exception { 
	m_counter++;
	Integer key = new Integer(m_counter);
	m_CallbackContainer.put(key, new CallbackHelper(callback, pvRef));
	long result = pteidlibJava_WrapperJNI.PTEID_ReaderContext_SetEventCallback(swigCPtr, this, 0, m_counter);
	return result; 
}

  public void StopEventCallback(long ulHandle) throws PTEID_Exception { 
    pteidlibJava_WrapperJNI.PTEID_ReaderContext_StopEventCallback(swigCPtr, this, ulHandle);
    
	Set CallbackContainerKeys = m_CallbackContainer.keySet();
	Iterator itr = CallbackContainerKeys.iterator();
	
	while (itr.hasNext())
	{
		Integer		   key		= (Integer)itr.next();
		CallbackHelper cbHelper = (CallbackHelper)m_CallbackContainer.get(key);
		
		if (cbHelper.m_handle == ulHandle)
		{
			m_CallbackContainer.remove(key);
			break;
		}
	}
}

  public void BeginTransaction() throws PTEID_Exception {
    pteidlibJava_WrapperJNI.PTEID_ReaderContext_BeginTransaction(swigCPtr, this);
  }

  public void EndTransaction() throws PTEID_Exception {
    pteidlibJava_WrapperJNI.PTEID_ReaderContext_EndTransaction(swigCPtr, this);
  }

  public boolean isVirtualReader() throws PTEID_Exception {
    return pteidlibJava_WrapperJNI.PTEID_ReaderContext_isVirtualReader(swigCPtr, this);
  }

}
