UpperTesterPort_GN.partC 3.97 KB
Newer Older
garciay's avatar
garciay committed
#include "UpperTesterLayer.hh"
#include "loggers.hh"

//=============================================================================
namespace LibItsGeoNetworking__TestSystem {

UpperTesterPort::UpperTesterPort(const char *par_port_name)
garciay's avatar
garciay committed
	: UpperTesterPort_BASE(par_port_name), _cfg_params(), _layer_params(), _layer(NULL), _time_key("UpperTesterPort::outgoing_send")
garciay's avatar
garciay committed
    loggers::get_instance().log("UpperTesterPort::UpperTesterPort");

}

UpperTesterPort::~UpperTesterPort()
{
garciay's avatar
garciay committed
    if (_layer != NULL) {
      delete _layer;
    }
garciay's avatar
garciay committed
void UpperTesterPort::set_parameter(const char * parameter_name, const char * parameter_value)
garciay's avatar
garciay committed
    loggers::get_instance().log("UpperTesterPort::set_parameter: %s=%s", parameter_name, parameter_value);
    _cfg_params.insert(std::pair<std::string, std::string>(std::string(parameter_name), std::string(parameter_value)));
    _cfg_params.log();
}

/*void UpperTesterPort::Handle_Fd_Event(int fd, boolean is_readable,
	boolean is_writable, boolean is_error) {}*/

void UpperTesterPort::Handle_Fd_Event_Error(int /*fd*/)
{

}

void UpperTesterPort::Handle_Fd_Event_Writable(int /*fd*/)
{

}

void UpperTesterPort::Handle_Fd_Event_Readable(int /*fd*/)
{

}

/*void UpperTesterPort::Handle_Timeout(double time_since_last_call) {}*/

garciay's avatar
garciay committed
void UpperTesterPort::user_map(const char * system_port)
garciay's avatar
garciay committed
    loggers::get_instance().log(">>> UpperTesterPort::user_map: %s", system_port);
    // Build layer stack
    Params::iterator it = _cfg_params.find(std::string("params"));
    if (it != _cfg_params.end()) {
      loggers::get_instance().log("UpperTesterPort::user_map: %s", it->second.c_str());
      _layer = LayerStackBuilder::GetInstance()->createLayerStack(it->second.c_str());
    if (static_cast<UpperTesterLayer *>(_layer) == NULL) {
      loggers::get_instance().error("UpperTesterPort::user_map: Invalid stack configuration: %s", it->second.c_str());
    }
      static_cast<UpperTesterLayer *>(_layer)->addUpperPort(this);
    } else {
      loggers::get_instance().error("UpperTesterPort::user_map: No layers defined in configuration file");
    }
garciay's avatar
garciay committed
void UpperTesterPort::user_unmap(const char * system_port)
garciay's avatar
garciay committed
    loggers::get_instance().log(">>> UpperTesterPort::user_unmap: %s", system_port);
    if (_layer != NULL) {
      delete _layer;
      _layer = NULL;
    }
}

void UpperTesterPort::user_start()
{

}

void UpperTesterPort::user_stop()
{

}

garciay's avatar
garciay committed
void UpperTesterPort::outgoing_send(const LibItsGeoNetworking__TypesAndValues::UtGnInitialize& send_par)
garciay's avatar
garciay committed
    loggers::get_instance().log_msg(">>> UppertesterPort::outgoing_send: ", send_par);
garciay's avatar
garciay committed
    
    float duration;
    loggers::get_instance().set_start_time(_time_key);
    static_cast<UpperTesterLayer *>(_layer)->sendMsg(send_par, _layer_params);
    loggers::get_instance().set_stop_time(_time_key, duration);
garciay's avatar
garciay committed
void UpperTesterPort::outgoing_send(const LibItsGeoNetworking__TypesAndValues::UtGnChangePosition& send_par)
garciay's avatar
garciay committed
    loggers::get_instance().log_msg(">>> UppertesterPort::outgoing_send: ", send_par);
    
    float duration;
    loggers::get_instance().set_start_time(_time_key);
    static_cast<UpperTesterLayer *>(_layer)->sendMsg(send_par, _layer_params);
    loggers::get_instance().set_stop_time(_time_key, duration);
}

void UpperTesterPort::outgoing_send(const LibItsGeoNetworking__TypesAndValues::UtGnTrigger& /*send_par*/)
{

}

garciay's avatar
garciay committed
void UpperTesterPort::outgoing_send(const LibItsGeoNetworking__TypesAndValues::UtAutoInteropTrigger& send_par)
{

}

garciay's avatar
garciay committed
void UpperTesterPort::receiveMsg (const Base_Type& p_ind, const Params& p_params) {
    loggers::get_instance().log_msg(">>> UpperTesterPort::receive_msg: ", p_ind);
    // Sanity check
    if (!p_ind.is_bound()) {
      return;
    }

garciay's avatar
garciay committed
    //loggers::get_instance().log("UpperTesterPort::receive_msg: %s", p_ind.get_descriptor()->name);
    if (std::string(p_ind.get_descriptor()->name).compare("@LibItsGeoNetworking_TypesAndValues.UtGnResults") == 0) { // TODO To be refined
     incoming_message((LibItsGeoNetworking__TypesAndValues::UtGnResults&)p_ind);
    }
garciay's avatar
garciay committed
}

} /* end of namespace */