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

namespace be.portugal.eid {

using System;
using System.Runtime.InteropServices;

public class PTEID_ReaderContext : PTEID_Object {
  private HandleRef swigCPtr;

  internal PTEID_ReaderContext(IntPtr cPtr, bool cMemoryOwn) : base(pteidlib_dotNetPINVOKE.PTEID_ReaderContextUpcast(cPtr), cMemoryOwn) {
    swigCPtr = new HandleRef(this, cPtr);
  }

  internal static HandleRef getCPtr(PTEID_ReaderContext obj) {
    return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
  }

  ~PTEID_ReaderContext() {
    Dispose();
  }

  public override void Dispose() {
    lock(this) {
      if(swigCPtr.Handle != IntPtr.Zero && swigCMemOwn) {
        swigCMemOwn = false;
        pteidlib_dotNetPINVOKE.delete_PTEID_ReaderContext(swigCPtr);
      }
      swigCPtr = new HandleRef(null, IntPtr.Zero);
      GC.SuppressFinalize(this);
      base.Dispose();
    }
  }

  public PTEID_ReaderContext(PTEID_FileType fileType, string fileName) : this(pteidlib_dotNetPINVOKE.new_PTEID_ReaderContext__SWIG_0((int)fileType, fileName), true) {
    if (pteidlib_dotNetPINVOKE.SWIGPendingException.Pending) throw pteidlib_dotNetPINVOKE.SWIGPendingException.Retrieve();
  }

  public PTEID_ReaderContext(PTEID_FileType fileType, PTEID_ByteArray data) : this(pteidlib_dotNetPINVOKE.new_PTEID_ReaderContext__SWIG_1((int)fileType, PTEID_ByteArray.getCPtr(data)), true) {
    if (pteidlib_dotNetPINVOKE.SWIGPendingException.Pending) throw pteidlib_dotNetPINVOKE.SWIGPendingException.Retrieve();
  }

  public PTEID_ReaderContext(PTEID_RawData_Eid data) : this(pteidlib_dotNetPINVOKE.new_PTEID_ReaderContext__SWIG_2(PTEID_RawData_Eid.getCPtr(data)), true) {
    if (pteidlib_dotNetPINVOKE.SWIGPendingException.Pending) throw pteidlib_dotNetPINVOKE.SWIGPendingException.Retrieve();
  }

  public PTEID_ReaderContext(PTEID_RawData_Sis data) : this(pteidlib_dotNetPINVOKE.new_PTEID_ReaderContext__SWIG_3(PTEID_RawData_Sis.getCPtr(data)), true) {
    if (pteidlib_dotNetPINVOKE.SWIGPendingException.Pending) throw pteidlib_dotNetPINVOKE.SWIGPendingException.Retrieve();
  }

  public string getName() {
    string ret = pteidlib_dotNetPINVOKE.PTEID_ReaderContext_getName(swigCPtr);
    if (pteidlib_dotNetPINVOKE.SWIGPendingException.Pending) throw pteidlib_dotNetPINVOKE.SWIGPendingException.Retrieve();
    return ret;
  }

  public bool isCardPresent() {
    bool ret = pteidlib_dotNetPINVOKE.PTEID_ReaderContext_isCardPresent(swigCPtr);
    if (pteidlib_dotNetPINVOKE.SWIGPendingException.Pending) throw pteidlib_dotNetPINVOKE.SWIGPendingException.Retrieve();
    return ret;
  }

  public void releaseCard(bool bAllReference) {
    pteidlib_dotNetPINVOKE.PTEID_ReaderContext_releaseCard__SWIG_0(swigCPtr, bAllReference);
    if (pteidlib_dotNetPINVOKE.SWIGPendingException.Pending) throw pteidlib_dotNetPINVOKE.SWIGPendingException.Retrieve();
  }

  public void releaseCard() {
    pteidlib_dotNetPINVOKE.PTEID_ReaderContext_releaseCard__SWIG_1(swigCPtr);
    if (pteidlib_dotNetPINVOKE.SWIGPendingException.Pending) throw pteidlib_dotNetPINVOKE.SWIGPendingException.Retrieve();
  }

  public bool isCardChanged(ref uint ulOldId) {
    bool ret = pteidlib_dotNetPINVOKE.PTEID_ReaderContext_isCardChanged(swigCPtr, ref ulOldId);
    if (pteidlib_dotNetPINVOKE.SWIGPendingException.Pending) throw pteidlib_dotNetPINVOKE.SWIGPendingException.Retrieve();
    return ret;
  }

  public PTEID_CardType getCardType() {
    PTEID_CardType ret = (PTEID_CardType)pteidlib_dotNetPINVOKE.PTEID_ReaderContext_getCardType(swigCPtr);
    if (pteidlib_dotNetPINVOKE.SWIGPendingException.Pending) throw pteidlib_dotNetPINVOKE.SWIGPendingException.Retrieve();
    return ret;
  }

  public PTEID_Card getCard() { 
	PTEID_CardType cardType=getCardType();

	switch(cardType)
	{
	case PTEID_CardType.PTEID_CARDTYPE_EID:			
	case PTEID_CardType.PTEID_CARDTYPE_KIDS:
	case PTEID_CardType.PTEID_CARDTYPE_FOREIGNER:
		return getEIDCard();			

	case PTEID_CardType.PTEID_CARDTYPE_SIS:			
		return getSISCard();			

    default:										
		throw new PTEID_ExCardTypeUnknown();
	}
}

  public PTEID_EIDCard getEIDCard() { 
	PTEID_CardType cardType=getCardType();

	switch(cardType)
	{
	case PTEID_CardType.PTEID_CARDTYPE_EID:			
		PTEID_EIDCard ret = new PTEID_EIDCard(pteidlib_dotNetPINVOKE.PTEID_ReaderContext_getEIDCard(swigCPtr), false);	
		if (pteidlib_dotNetPINVOKE.SWIGPendingException.Pending) throw pteidlib_dotNetPINVOKE.SWIGPendingException.Retrieve();
		return ret;

	case PTEID_CardType.PTEID_CARDTYPE_KIDS:			
		return getKidsCard();		

	case PTEID_CardType.PTEID_CARDTYPE_FOREIGNER:		
		return getForeignerCard();	

    default:										
		throw new PTEID_ExCardBadType();
	}
}

  public PTEID_KidsCard getKidsCard() {
    PTEID_KidsCard ret = new PTEID_KidsCard(pteidlib_dotNetPINVOKE.PTEID_ReaderContext_getKidsCard(swigCPtr), false);
    if (pteidlib_dotNetPINVOKE.SWIGPendingException.Pending) throw pteidlib_dotNetPINVOKE.SWIGPendingException.Retrieve();
    return ret;
  }

  public PTEID_ForeignerCard getForeignerCard() {
    PTEID_ForeignerCard ret = new PTEID_ForeignerCard(pteidlib_dotNetPINVOKE.PTEID_ReaderContext_getForeignerCard(swigCPtr), false);
    if (pteidlib_dotNetPINVOKE.SWIGPendingException.Pending) throw pteidlib_dotNetPINVOKE.SWIGPendingException.Retrieve();
    return ret;
  }

  public PTEID_SISCard getSISCard() {
    PTEID_SISCard ret = new PTEID_SISCard(pteidlib_dotNetPINVOKE.PTEID_ReaderContext_getSISCard(swigCPtr), false);
    if (pteidlib_dotNetPINVOKE.SWIGPendingException.Pending) throw pteidlib_dotNetPINVOKE.SWIGPendingException.Retrieve();
    return ret;
  }

  public uint SetEventCallback(PTEID_SetEventDelegate callback, IntPtr pvRef) { 
	pteidlib_dotNetPINVOKE.CUSTOM_SetEventHelper.countRef++;	
	IntPtr ptrCount = new IntPtr(pteidlib_dotNetPINVOKE.CUSTOM_SetEventHelper.countRef);

	//We add the references to the hash table
	pteidlib_dotNetPINVOKE.CUSTOM_SetEventHelper.delegateRef callbackRef =  new pteidlib_dotNetPINVOKE.CUSTOM_SetEventHelper.delegateRef();
	callbackRef.functionRef = callback;
	callbackRef.ptrRef = pvRef;
	callbackRef.handleRef = 0;
	pteidlib_dotNetPINVOKE.CUSTOM_SetEventHelper.delegateRefs.Add(pteidlib_dotNetPINVOKE.CUSTOM_SetEventHelper.countRef,callbackRef);

	//We call the SetEvent with the internal reference (countRef)
	uint ulRslt = pteidlib_dotNetPINVOKE.PTEID_ReaderContext_SetEventCallback(swigCPtr, 0, ptrCount);
	if (pteidlib_dotNetPINVOKE.SWIGPendingException.Pending) 
	{
		pteidlib_dotNetPINVOKE.CUSTOM_SetEventHelper.delegateRefs.Remove(callbackRef);
		throw pteidlib_dotNetPINVOKE.SWIGPendingException.Retrieve();
	}
	else
	{
		callbackRef.handleRef = ulRslt;
	}

	return ulRslt; 
}

  public void StopEventCallback(uint ulHandle) { 
	pteidlib_dotNetPINVOKE.PTEID_ReaderContext_StopEventCallback(swigCPtr, ulHandle);
	if (pteidlib_dotNetPINVOKE.SWIGPendingException.Pending) throw pteidlib_dotNetPINVOKE.SWIGPendingException.Retrieve();
	
	//Remove ulHandle from delegateRefs 
	foreach(pteidlib_dotNetPINVOKE.CUSTOM_SetEventHelper.delegateRef callbackRef in pteidlib_dotNetPINVOKE.CUSTOM_SetEventHelper.delegateRefs.Values )
    {
      if(callbackRef.handleRef==ulHandle)
      {
          pteidlib_dotNetPINVOKE.CUSTOM_SetEventHelper.delegateRefs.Remove(callbackRef);
          break;
      }
    }	
}

  public void BeginTransaction() {
    pteidlib_dotNetPINVOKE.PTEID_ReaderContext_BeginTransaction(swigCPtr);
    if (pteidlib_dotNetPINVOKE.SWIGPendingException.Pending) throw pteidlib_dotNetPINVOKE.SWIGPendingException.Retrieve();
  }

  public void EndTransaction() {
    pteidlib_dotNetPINVOKE.PTEID_ReaderContext_EndTransaction(swigCPtr);
    if (pteidlib_dotNetPINVOKE.SWIGPendingException.Pending) throw pteidlib_dotNetPINVOKE.SWIGPendingException.Retrieve();
  }

  public bool isVirtualReader() {
    bool ret = pteidlib_dotNetPINVOKE.PTEID_ReaderContext_isVirtualReader(swigCPtr);
    if (pteidlib_dotNetPINVOKE.SWIGPendingException.Pending) throw pteidlib_dotNetPINVOKE.SWIGPendingException.Retrieve();
    return ret;
  }

}

}
