/******************************************************************************
    Copyright (c) 1998-2000 CoWare, Inc.    ALL RIGHTS RESERVED

The following code is derived, directly or indirectly, from the SystemC
source code released by Synopsys, Inc Copyright (c) 1996-2001, Synopsys,
Inc., CoWare, Inc., Frontier Design, Inc. and others. All Rights reserved.
The contents of this file are subject to the restrictions and limitations
set forth in the SystemC Open Source License Version 2.0 (the "License");
You may not use this file except in compliance with such restrictions and
limitations. You may obtain instructions on how to receive a copy of the
License at http://www.systemc.org/.  Software distributed by Contributors
under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
ANY KIND, either express or implied. See the License for the specific
language governing rights and limitations under the License."

******************************************************************************/

/****************************************************************
    CLASS sc_master :  refinable master port.  Does not have 
	  read or write property unlike inmaster/outmaster/inoutmaster
          Partial specializations.

    Authors 
	: Harish Sarin, CoWare Inc. (harish@coware.com)
	: Cesar Quiroz, CoWare Inc. (cesar@coware.com)
	: Vijay Kumar,  CoWare Inc. (vijay@coware.com)

    MODIFICATION LOG 
    Modifier Name & Affiliation:
    Description of Modification:

****************************************************************/

#ifndef SC_MASTER_H
#define SC_MASTER_H

#include <stddef.h>

#include "sc_pport_b.h"

template <class T>
class sc_abstract;

///////////////////////////////////////////////////////////////
template <class T=int, class Protocol=sc_abstract<T> >
class sc_master :public sc_pport_b ,public Protocol::sc_master_protocol {
 public:
        typedef typename Protocol::sc_master_protocol pp;
	sc_master(const char *NAME=0) : sc_object(NAME), sc_pport_b(NAME)  {
	  set_port(this); 
	}
	BIND_STATUS operator () (sc_master<T,Protocol>& p) { return  bind(p); }
	BIND_STATUS operator () (sc_link_mp<T>& link) {	return bind(link); }
	void operator () (){
	  pp::operator()();
	}
	
	typename Protocol::sc_master_protocol* operator -> () { return this; }
        virtual const char * getProtocolType() {
           return typeid(Protocol).name();
        }
};


///////////////////////////////////////////////////////////////
template <class T=int, class Protocol=sc_abstract<T> >
class sc_inoutmaster :public sc_pport_b,public Protocol::sc_inoutm_protocol {
 public:

	sc_inoutmaster(const char *NAME=0) : sc_object(NAME), sc_pport_b(NAME) { set_port(this); }

	BIND_STATUS operator () (sc_inoutmaster<T,Protocol>& p) { return bind(p);	}
	BIND_STATUS operator () (sc_link_mp<T>& link) {	return bind(link); }
	

	operator T () { return read(); }


	sc_inoutmaster<T,Protocol>& operator =(const T& val) {
		write(val);
		return *this;
	}
	
	typename Protocol::sc_inoutm_protocol* operator -> () { return this; }
        virtual const char * getProtocolType() {
           return typeid(Protocol).name();
        }
};

///////////////////////////////////////////////////////////////
template <class T=int, class Protocol=sc_abstract<T> >
class sc_outmaster :public sc_pport_b ,public Protocol::sc_outm_protocol {
 public:

	sc_outmaster(const char *NAME=0) : sc_object(NAME), sc_pport_b(NAME) { set_port(this); }

	BIND_STATUS operator () (sc_inoutmaster<T,Protocol>& p) {return bind(p); }
	BIND_STATUS operator () (sc_outmaster<T,Protocol>& p) { return bind(p);}
	BIND_STATUS operator () (sc_link_mp<T>& link) {	return bind(link); }
	


	sc_outmaster<T,Protocol>& operator =(const T& val) {
		write(val);
		return *this;
	}

	typename Protocol::sc_outm_protocol* operator -> () { return this;  }
         virtual const char * getProtocolType() {
           return typeid(Protocol).name();
        }
};


///////////////////////////////////////////////////////////////
template <class T=int, class Protocol=sc_abstract<T> >
class sc_inmaster :public sc_pport_b ,public Protocol::sc_inm_protocol {
 public:
	sc_inmaster(const char *NAME=0) : sc_object(NAME), sc_pport_b(NAME) { set_port(this); }

	BIND_STATUS operator () (sc_inoutmaster<T,Protocol>& p) {return bind(p); }
	BIND_STATUS operator () (sc_inmaster<T,Protocol>& p) { return bind(p); }
	BIND_STATUS operator () (sc_link_mp<T>& link) {	return bind(link); }
	
	

	operator T () {return read(); }
	
	typename Protocol::sc_inm_protocol* operator -> () { return this; }
        virtual const char * getProtocolType() {
           return typeid(Protocol).name();
        }
};

#endif
