/*
 * File         : Status.java
 * Author       : Sang Lim, Sung-Hoon Ko, Xinying Li, Bryan Carpenter
 * Created      : Thu Apr  9 12:22:15 1998
 * Revision     : $Revision: 1.12 $
 * Updated      : $Date: 1999/09/16 18:24:01 $
 * Copyright: Northeast Parallel Architectures Center
 *            at Syracuse University 1998
 */

package mpi;

public class Status {

  public int index;
  public int source;
  public int tag;

  protected int count; 
  protected int object_count;

  public Status() { init_handle(); }
  protected Status(long _handle) { handle = _handle;}

  private native void init_handle();

  /**
   * Get the number of received entries.
   * <p>
   * <table>
   * <tr><td><tt> datatype </tt></td><td> datatype of each item in receive
   *                                      buffer </tr>
   * <tr><td><em> returns: </em></td><td> number of received entries </tr>
   * </table>
   * <p>
   * Java binding of the MPI operation <tt>MPI_GET_COUNT</tt>.
   */

  public int Get_count(Datatype datatype) throws MPIException {
    if (datatype.isObject()) {
      return object_count;
    }
    else { return get_count(datatype); }
  }

  private native int get_count(Datatype datatype);

  /**
   * Test if communication was cancelled.
   * <p>
   * <table>
   * <tr><td><em> returns: </em></td><td> true if the operation was
   *                                      succesfully cancelled,
   *                                      false otherwise
   * </table>
   * <p>
   * Java binding of the MPI operation <tt>MPI_TEST_CANCELLED</tt>.
   */

  public native boolean Test_cancelled() throws MPIException ;

  /**
   * Retrieve number of basic elements from status.
   * <p>
   * <table>
   * <tr><td><tt> datatype </tt></td><td> datatype used by receive
   *                                      operation </tr>
   * <tr><td><em> returns: </em></td><td> number of received basic
   *                                      elements </tr>
   * </table>
   * <p>
   * Java binding of the MPI operation <tt>MPI_GET_ELEMENTS</tt>.
   */

  public int Get_elements(Datatype datatype) throws MPIException {
    if(datatype.isObject()) {
      return MPI.UNDEFINED;
    }
    else return get_elements(datatype);      
  }

  private native int get_elements(Datatype datatype);

  public native void finalize() ;

  private static native void init(); 

  protected long handle;

  static {
    init();
  }          

}

// Things to do
//
//   Mend `Get_elements' for the Object case.
//
//   Why do we need a separate `object_count' field?


