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

namespace SLNet {

using System;
using System.Runtime.InteropServices;

public class TransportInterface : IDisposable {
  private HandleRef swigCPtr;
  protected bool swigCMemOwn;

  internal TransportInterface(IntPtr cPtr, bool cMemoryOwn) {
    swigCMemOwn = cMemoryOwn;
    swigCPtr = new HandleRef(this, cPtr);
  }

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

  ~TransportInterface() {
    Dispose();
  }

  public virtual void Dispose() {
    lock(this) {
      if (swigCPtr.Handle != IntPtr.Zero) {
        if (swigCMemOwn) {
          swigCMemOwn = false;
          SLikeNetPINVOKE.delete_TransportInterface(swigCPtr);
        }
        swigCPtr = new HandleRef(null, IntPtr.Zero);
      }
      GC.SuppressFinalize(this);
    }
  }

  public virtual bool Start(ushort port, bool serverMode) {
    bool ret = SLikeNetPINVOKE.TransportInterface_Start(swigCPtr, port, serverMode);
    return ret;
  }

  public virtual void Stop() {
    SLikeNetPINVOKE.TransportInterface_Stop(swigCPtr);
  }

  public virtual void CloseConnection(SystemAddress systemAddress) {
    SLikeNetPINVOKE.TransportInterface_CloseConnection(swigCPtr, SystemAddress.getCPtr(systemAddress));
    if (SLikeNetPINVOKE.SWIGPendingException.Pending) throw SLikeNetPINVOKE.SWIGPendingException.Retrieve();
  }

  public virtual Packet Receive() {
    IntPtr cPtr = SLikeNetPINVOKE.TransportInterface_Receive(swigCPtr);
    Packet ret = (cPtr == IntPtr.Zero) ? null : new Packet(cPtr, false);
    return ret;
  }

  public virtual void DeallocatePacket(Packet packet) {
    SLikeNetPINVOKE.TransportInterface_DeallocatePacket(swigCPtr, Packet.getCPtr(packet));
  }

  public virtual SystemAddress HasNewIncomingConnection() {
    SystemAddress ret = new SystemAddress(SLikeNetPINVOKE.TransportInterface_HasNewIncomingConnection(swigCPtr), true);
    return ret;
  }

  public virtual SystemAddress HasLostConnection() {
    SystemAddress ret = new SystemAddress(SLikeNetPINVOKE.TransportInterface_HasLostConnection(swigCPtr), true);
    return ret;
  }

  public virtual CommandParserInterface GetCommandParser() {
    IntPtr cPtr = SLikeNetPINVOKE.TransportInterface_GetCommandParser(swigCPtr);
    CommandParserInterface ret = (cPtr == IntPtr.Zero) ? null : new CommandParserInterface(cPtr, false);
    return ret;
  }

  public void Send(SystemAddress systemAddress, byte[] inByteArray) {
    SLikeNetPINVOKE.TransportInterface_Send(swigCPtr, SystemAddress.getCPtr(systemAddress), inByteArray);
    if (SLikeNetPINVOKE.SWIGPendingException.Pending) throw SLikeNetPINVOKE.SWIGPendingException.Retrieve();
  }

}

}
