#include "DiameterPort.h"

#include <iostream>

#include "Logger/Logger.h"
#include "LowerTestAdapter.h"

using namespace t3devlib;
using namespace std;

DiameterPort::DiameterPort (PortId& portId) 
:Port(portId) {
  Logger::Instance().LogInfo("DiameterPort::DiameterPort");
  LowerTestAdapter::Instance().RegisterDiameterPort(this);  
}

DiameterPort::~DiameterPort() {
    Logger::Instance().LogInfo("~DiameterPort::DiameterPort");
}

bool DiameterPort::Map (const PortId& connectedPortId)
{
  m_connectedPorts.push_back(&connectedPortId);
  return true; 
} 
 
bool DiameterPort::Unmap (const PortId& connectedPortId) { 

  //TODO: remove from m_connectedPorts
  return true; 
}

bool DiameterPort::Send (const ComponentId& from,const Bitstring& bsMsg)
{
  return true;
}

const t3devlib::PortId& DiameterPort::GetConnectedPort(const ComponentId *pComponentId)
{
  std::list<const PortId *>::iterator it;
  for(it = m_connectedPorts.begin(); it != m_connectedPorts.end(); it++) {
    if(&((*it)->GetComponentId()) == pComponentId) {
		Logger::Instance().LogInfo((*it)->GetName());
      return **it;
    }
  }
}
