/* ----------------------------------------------------------------------------
 * 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 org.simgrid.surf;

/**
  * An cpu action created by a Cpu
  * @see CpuModel
  * @see Cpu
  */
public class CpuAction extends Action {
  private long swigCPtr;

  protected CpuAction(long cPtr, boolean cMemoryOwn) {
    super(SurfJNI.CpuAction_SWIGUpcast(cPtr), cMemoryOwn);
    swigCPtr = cPtr;
  }

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

  protected void finalize() {
    delete();
  }

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

  protected void swigDirectorDisconnect() {
    swigCMemOwn = false;
    delete();
  }

  public void swigReleaseOwnership() {
    swigCMemOwn = false;
    SurfJNI.CpuAction_change_ownership(this, swigCPtr, false);
  }

  public void swigTakeOwnership() {
    swigCMemOwn = true;
    SurfJNI.CpuAction_change_ownership(this, swigCPtr, true);
  }

  
  /**
    * CpuAction constructor
    * @param model The model associated
    * @param cost The cost of the action (e.g., flops, bytes)
    * @param failed If the action has failed
    */
  public CpuAction(Model model, double cost, boolean failed) {
    this(SurfJNI.new_CpuAction(Model.getCPtr(model), model, cost, failed), true);
    SurfJNI.CpuAction_director_connect(this, swigCPtr, swigCMemOwn, true);
  }

  
  /**
    * @return The associated cpu
    */
  public Cpu getCpu() {
  long cPtr = SurfJNI.CpuAction_getCpu(swigCPtr, this);
  return (Cpu)Surf.getCpuDirector(cPtr);
}

}
