#include "EthernetLink.h"

namespace cosi {

namespace library {

namespace wiredbas {

EthernetLink::EthernetLink(double Speed) {

	ComponentType = "Wire" ;
	ComponentName = "Ethernet-Link" ;

	//Any node
	Name N;
	N.IsBot(false) ;
	N.IsAny(true) ;
	//With EIA-485 interface
	PortInterface P;
	P.SetDirection(PortInterface::INOUT) ;
	P.SetName("Eth") ;
	this->SetSource(N) ;
	this->SetSourceInterface(P) ;
	//Define the destination node
	this->SetDestination(N) ;
	P.SetDirection(PortInterface::INOUT) ;
	this->SetDestinationInterface(P) ;
	this->Directed(true);
	mDelayModel = new cosi::models::wiredbas::EthernetLinkDelay(Speed);
	mCostModel = new cosi::models::wiredbas::EthernetLinkCost;

}

EthernetLink::~EthernetLink() {
	delete mDelayModel;
	delete mCostModel;
}

RealDelay EthernetLink::GetDelay(int Length, WiringPath pPath) {
	return mDelayModel->Get(Length, pPath) ;
}

double EthernetLink::GetDelayValue(int Length, WiringPath pPath) {
	return mDelayModel->GetValue(Length, pPath);
}

double EthernetLink::GetCost(WiringPath pPath) {
	return mCostModel->GetValue(pPath) ;
}

cosi::commstruct::wiredbas::PlatformInstance* EthernetLink::GetPlatformInstance(
		int U, std::string pPortU, int V, std::string pPortV) {

	cosi::commstruct::wiredbas::PlatformInstance * RetVal =
			new cosi::commstruct::wiredbas::PlatformInstance("");
	RetVal->AddVertex(U) ;
	(*RetVal)[U].PRJ(Name)IsAny(true);
	(*RetVal)[U].PRJ(Type)IsAny(true);
	(*RetVal)[U].PRJ(Position)IsAny(true);
	Ports PortU;
	PortU.AddPort(pPortU, GetSourceInterface()) ;
	PortU.BoundTo(pPortU, Edge(U, V)) ;
	(*RetVal)[U].PRJ(Ports)Set(PortU);

	RetVal->AddVertex(V) ;
	(*RetVal)[V].PRJ(Name)IsAny(true);
	(*RetVal)[V].PRJ(Type)IsAny(true);
	(*RetVal)[V].PRJ(Position)IsAny(true);
	Ports PortV;
	PortV.AddPort(pPortV, GetDestinationInterface()) ;
	PortU.BoundTo(pPortV, Edge(U, V)) ;
	(*RetVal)[V].PRJ(Ports)Set(PortV);
	RetVal->AddEdge(U, V) ;
	(*RetVal)[Edge(U,V)].PRJ(Name)SetValue(ComponentName);
	(*RetVal)[Edge(U,V)].PRJ(Type)SetValue(ComponentType);
	(*RetVal)[Edge(U,V)].PRJ(WiringPath)IsAny(true);
	return RetVal;

}

cosi::commstruct::wiredbas::Implementation * EthernetLink::GetImplementationInstance(
		int U, std::string pPortU, int V, std::string pPortV, WiringPath pPath) {
	cosi::commstruct::wiredbas::Implementation * RetVal =
			new cosi::commstruct::wiredbas::Implementation("");
	RetVal->AddVertex(U) ;
	(*RetVal)[U].PRJ(Name)IsAny(true);
	(*RetVal)[U].PRJ(Type)IsAny(true);
	(*RetVal)[U].PRJ(Position)IsAny(true);
	(*RetVal)[U].PRJ(ThreadSet)IsAny(true);
	(*RetVal)[U].PRJ(TransferTable)IsAny(true);
	Ports PortU;
	PortU.AddPort(pPortU, GetSourceInterface()) ;
	PortU.BoundTo(pPortU, Edge(U, V)) ;
	(*RetVal)[U].PRJ(Ports)Set(PortU);

	RetVal->AddVertex(V) ;
	(*RetVal)[V].PRJ(Name)IsAny(true);
	(*RetVal)[V].PRJ(Type)IsAny(true);
	(*RetVal)[V].PRJ(Position)IsAny(true);
	(*RetVal)[U].PRJ(ThreadSet)IsAny(true);
	(*RetVal)[U].PRJ(TransferTable)IsAny(true);
	Ports PortV;
	PortV.AddPort(pPortV, GetDestinationInterface()) ;
	PortV.BoundTo(pPortV, Edge(U, V)) ;
	(*RetVal)[V].PRJ(Ports)Set(PortV);
	RetVal->AddEdge(U, V) ;
	(*RetVal)[Edge(U,V)].PRJ(Name)SetValue(ComponentName);
	(*RetVal)[Edge(U,V)].PRJ(Type)SetValue(ComponentType);
	(*RetVal)[Edge(U,V)].PRJ(WiringPath)Set(pPath);
	return RetVal;
}

}

}

}
