/*
 * $Id: HostCommand.java,v 1.4 2000/06/15 13:55:51 yamauchi Exp $
 *     (M\pi)^2 : HostCommand : Host Command object
 *	Copyright 1999 By YAMAUCHI Hitoshi 山内 斉 
 *	@author YAMAUCHI Hitoshi 山内 斉
 *	
 * original source HostComm.h
 *
 *	Host からのコマンドを伝える
 * 
 * 1999年8月23日(月)
 */

package jp.ac.tohoku.is.archi.mpi2.obj;

import  java.io.Serializable;
import	jp.ac.tohoku.is.archi.mpi2.host.*;
import	jp.ac.tohoku.is.archi.mpi2.sysparam.*;
import	jp.ac.tohoku.is.archi.mpi2.util.*;

public final class HostCommand 
implements Mpi2Enum, HostConstants, Encodable // Serializable
{
    /*
     * コマンド
     */
    private int mHostCommand;
    

    /**
     * constructor
     */
    public HostCommand()
    {
	this.mHostCommand = ELSE_HostComm;
    }
    public HostCommand(HostCommand rhs)
    {
	this.mHostCommand = rhs.mHostCommand;
    }
    public HostCommand(int hostcommand)
    {
	this.mHostCommand = hostcommand;
    }

    // status 
    public void setCommand(int hostcommand) 	
    { 
	this.mHostCommand = hostcommand;
    }
    public int getCommand() 
    { 
	return(this.mHostCommand);	
    }
    
    // misc
    public String toString() 
    {
	String [] hcom = { 
	    "End Radiosity stage",
	    "End PrepareShading stage",
	    "End RayTrace stage",
	    "Issue Barrier sync",
	    "Suspend Generate new rays",
	    "Resume  Generate new rays",
	    "Send Patch descriptions to host",
	    "Warning! : null host command",
	};
	return(hcom[this.mHostCommand]);
    }

    // タグを返す
    public static int getTAG() 
    {
	return(TAG_HOST_COM);	
    }

    /*
     * Implements Encodable
     */
    public int sizeInDouble() 
    {
	// int mHostCommand;
	return(1);
    }
    public void encodeInDouble(double[] array, int offset) 
    {
	array[offset] = (double)(this.mHostCommand);
    }

    /*
     * Implements ObjectDecoder
     */
    private static class HostCommandObjectDecoder implements ObjectDecoder 
    {
    	public int sizeInDouble() 
	{
	    return(1);
	}
    	public Object decodeFromDouble(double[] array, int offset)
	{
	    return(new HostCommand((int)(array[offset]))); 
	}
    }
    private final static ObjectDecoder mODInstance 
    	= new HostCommandObjectDecoder();
    public static ObjectDecoder getObjectDecoder() 
    {
	return(mODInstance);
    }
}
