#include "IpSourcePort.h"

namespace cosi {

namespace library {

namespace onchipcommunication {

std::string IpSourcePort::ComponentName="OCP-PE";
std::string IpSourcePort::ComponentType="IP";

std::string IpSourcePort::GetComponentName(){
	return ComponentName ;

}

std::string IpSourcePort::GetComponentType(){
	return ComponentType ;
}

IpSourcePort::IpSourcePort(int Width, double Fclk,
		cosi::library::onchipcommunication::Technology pTech) {

	mPorts.AddPort("P1", "OCP",
			cosi::quantity::onchipcommunication::Interface::OUT) ;
	mPorts["P1"].SetSpeed(Fclk) ;
	mPorts["P1"].SetWidth(Width) ;
	mParam = new cosi::quantity::onchipcommunication::NodeParameter();
	mParam->SetTechnology(pTech) ;
}

IpSourcePort::~IpSourcePort() {
}

cosi::commstruct::onchipcommunication::PlatformInstance* IpSourcePort::GetPlatformInstance(
		int V, Position pP) {
	cosi::commstruct::onchipcommunication::PlatformInstance
			* RetVal = new cosi::commstruct::onchipcommunication::PlatformInstance("");
	RetVal->AddVertex(V) ;
	(*RetVal)[V].PRJ(Name)Set(Name(ComponentName));
	(*RetVal)[V].PRJ(Type)Set(Type(ComponentType));
	(*RetVal)[V].PRJ(Ports)Set(mPorts);
	(*RetVal)[V].PRJ(Position)Set(pP);
	(*RetVal)[V].PRJ(NodeParameter)Set(*mParam);

	double Area = GetArea() ;
	double L = sqrt(Area) ;
	double Xl, Xr, Yt, Yb;
	Xl = pP.GetX() - L/2;
	Xr = pP.GetX() + L/2;
	Yt = pP.GetY() + L/2;
	Yb = pP.GetY() - L/2;

	cosi::quantity::onchipcommunication::IpGeometry G;
	G.IsAny(true);
	(*RetVal)[V].PRJ(IpGeometry)Set(G);

	return RetVal ;
}

cosi::commstruct::onchipcommunication::Implementation* IpSourcePort::GetImplementationInstance(
		int V, Position pP, TransferTable pT) {

	cosi::commstruct::onchipcommunication::Implementation
			* RetVal = new cosi::commstruct::onchipcommunication::Implementation("");
	RetVal->AddVertex(V) ;
	(*RetVal)[V].PRJ(Name)Set(Name(ComponentName));
	(*RetVal)[V].PRJ(Type)Set(Type(ComponentType));
	(*RetVal)[V].PRJ(Ports)Set(mPorts);
	(*RetVal)[V].PRJ(Position)Set(pP);
	(*RetVal)[V].PRJ(NodeParameter)Set(*mParam);
	(*RetVal)[V].PRJ(TransferTable)Set(pT);

	double Area = GetArea() ;

	double L = sqrt(Area) ;

	double Xl, Xr, Yt, Yb;
	Xl = pP.GetX() - L/2;
	Xr = pP.GetX() + L/2;
	Yt = pP.GetY() + L/2;
	Yb = pP.GetY() - L/2;

	cosi::quantity::onchipcommunication::IpGeometry G;
	G.IsAny(true) ;
	(*RetVal)[V].PRJ(IpGeometry)Set(G);

	return RetVal ;

}

double IpSourcePort::GetArea() {
	return 0 ;
}

double IpSourcePort::GetStaticPower() {
	return 0 ;
}

double IpSourcePort::GetDynamicPower(
		std::map< std::string , CommoditySet > pCommodities) {
	return 0 ;

}

}

}

}
