/*
 * $Id: PEStat.h,v 1.2 2000/05/19 20:35:50 yamauchi Exp $
 *------------------------------------------------------------
 *	PEStat.h Processing Element status class
 *	1996/8/18 
 *	(C) Copyright YAMAUCHI Hitoshi 山内 斉
 */
#ifndef _PEStat_h
#define _PEStat_h 1

// PE の状態を伝える
enum PEStat_e {
    PESt_Idle_e,
    PESt_BUSY_e,
    PESt_Ack_e,			// for acknowledge
    PESt_ELSE_e
};

// PE からの host への要求
enum PEReq_e {
    PEReq_Request_StopGenRays_e,   // システムに ray の発生停止を要求
    PEReq_Request_ResumeGenRays_e, // システムに ray の発生再開を要求
    PEReq_ELSE_e
};

class PEStatClass {
protected:
    enum PEStat_e mPEStat;
    enum PEReq_e  mPEReq;
    int  mSrcRank;

public:
    // 初期状態は busy で request はない
    PEStatClass(void)
    {
	this->mPEStat = PESt_BUSY_e;
	this->mPEReq  = PEReq_ELSE_e;
	this->mSrcRank = -1;
    }
//     PEStatClass(enum PEStat_e stat, enum PEReq_e req, int srcRank)
//     {
// 	this->mPEStat  = stat;
// 	this->mPEReq   = req;
// 	this->mSrcRank = srcRank;
//     }
    PEStatClass(const PEStatClass& rhs)
    {
	this->mPEStat 	= rhs.mPEStat;
	this->mPEReq	= rhs.mPEReq;
	this->mSrcRank	= rhs.mSrcRank;
    }
    const PEStatClass &operator=(const PEStatClass& rhs)
    {
	if(this != &rhs)
	{
	    this->mPEStat	= rhs.mPEStat;
	    this->mPEReq	= rhs.mPEReq;
	    this->mSrcRank	= rhs.mSrcRank;
	}
	return(*this);
    }

    // status 
    void setBusy(int srcRank)
    { 
	this->mPEStat 	= PESt_BUSY_e;	
	this->mPEReq 	= PEReq_ELSE_e;	
	this->mSrcRank 	= srcRank;
    }
    void setIdle(int srcRank) 	
    { 
	this->mPEStat 	= PESt_Idle_e;	
    	this->mPEReq	= PEReq_ELSE_e;	
	this->mSrcRank 	= srcRank;
    }    
    void setAck(int srcRank) 	
    { 
	this->mPEStat 	= PESt_Ack_e;	
    	this->mPEReq	= PEReq_ELSE_e;	
	this->mSrcRank 	= srcRank;
    }    
    enum PEStat_e getStat(void) const { return(this->mPEStat);	}

    // request to host
    void setStopGenRay(int srcRank) 	
    { 
	this->mPEStat 	= PESt_ELSE_e;	
    	this->mPEReq 	= PEReq_Request_StopGenRays_e;	
	this->mSrcRank 	= srcRank;
    }    
    void setResumeGenRay(int srcRank) 	
    { 
	this->mPEStat 	= PESt_ELSE_e;	
    	this->mPEReq 	= PEReq_Request_ResumeGenRays_e;	
	this->mSrcRank 	= srcRank;
    }    
    enum PEReq_e getRequest(void) const { return(this->mPEReq);	}

    int getSrcRank(void) const 		{ return(this->mSrcRank);	}

    // misc
    void print(void) const 
    {
	static const char *pStat[] = { "I", "B", "A", "-", NULL };
	static const char *pReq[] =  { "s", "r", "-", NULL };
	cout << pStat[this->mPEStat] << ":" << pReq[this->mPEReq];
    }
public:
    // タグを返す
    static communication_tags_e getTAG(void) 
    {
	return(TAG_PE_STATUS_e);	
    }
};

#endif				// _PEStat_h
