AdapterControlPort_GN.partC 4.56 KB
Newer Older
garciay's avatar
garciay committed
#include <TTCN3.hh>

#include "loggers.hh"
#include "registration.hh"

#include "GeoNetworkingLayer.hh"

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

garciay's avatar
garciay committed
  AdapterControlPort::AdapterControlPort(const char *par_port_name)
    : AdapterControlPort_BASE(par_port_name), _params()
  {
    loggers::get_instance().log("AdapterControlPort::AdapterControlPort");


  }

  AdapterControlPort::~AdapterControlPort()
  {

  }

  void AdapterControlPort::set_parameter(const char * parameter_name, const char * parameter_value)
  {
    loggers::get_instance().log("AdapterControlPort::set_parameter: %s=%s", parameter_name, parameter_value);

  }

  /*void AdapterControlPort::Handle_Fd_Event(int fd, boolean is_readable,
    boolean is_writable, boolean is_error) {}*/
garciay's avatar
garciay committed
  void AdapterControlPort::Handle_Fd_Event_Error(int /*fd*/)
  {
garciay's avatar
garciay committed
  }
garciay's avatar
garciay committed
  void AdapterControlPort::Handle_Fd_Event_Writable(int /*fd*/)
  {
garciay's avatar
garciay committed
  }
garciay's avatar
garciay committed
  void AdapterControlPort::Handle_Fd_Event_Readable(int /*fd*/)
  {
garciay's avatar
garciay committed
  }
garciay's avatar
garciay committed
  /*void AdapterControlPort::Handle_Timeout(double time_since_last_call) {}*/
garciay's avatar
garciay committed
  void AdapterControlPort::user_map(const char * system_port)
  {
    loggers::get_instance().log(">>> AdapterControlPort::user_map: %s", system_port);
garciay's avatar
garciay committed
  }
garciay's avatar
garciay committed
  void AdapterControlPort::user_unmap(const char * system_port)
  {
    loggers::get_instance().log(">>> AdapterControlPort::user_unmap: %s", system_port);
garciay's avatar
garciay committed
  }
garciay's avatar
garciay committed
  void AdapterControlPort::user_start()
  {
garciay's avatar
garciay committed
  }
garciay's avatar
garciay committed
  void AdapterControlPort::user_stop()
  {
garciay's avatar
garciay committed
  }
garciay's avatar
garciay committed
  void AdapterControlPort::outgoing_send(const LibItsGeoNetworking__TypesAndValues::AcGnPrimitive& send_par)
  {
    loggers::get_instance().log_msg(">>> AdapterControlPort::outgoing_send: ", send_par);
garciay's avatar
garciay committed
    // Register this object for AdapterControlPort
    GeoNetworkingLayer* p = registration<GeoNetworkingLayer>::get_instance().get_item(std::string("GN"));
    if (p != NULL) {
      loggers::get_instance().log("AdapterControlPort::outgoing_send: Got GN layer %p", p);
garciay's avatar
garciay committed
      LibItsGeoNetworking__TypesAndValues::AcGnResponse response;
      response.failure() = LibItsGeoNetworking__TypesAndValues::AcGnResponseFailure(BOOLEAN(false));
garciay's avatar
garciay committed
      if (send_par.ischosen(LibItsGeoNetworking__TypesAndValues::AcGnPrimitive::ALT_startBeaconing)) {
        loggers::get_instance().log("AdapterControlPort::outgoing_send: Start beaconing");
        p->start_beaconing(send_par.startBeaconing().beaconPacket());
garciay's avatar
garciay committed
      } else if (send_par.ischosen(LibItsGeoNetworking__TypesAndValues::AcGnPrimitive::ALT_stopBeaconing)) {
        loggers::get_instance().log("AdapterControlPort::outgoing_send: Stop beaconing");
        p->stop_beaconing();
      } else if (send_par.ischosen(LibItsGeoNetworking__TypesAndValues::AcGnPrimitive::ALT_getLongPosVector)) {
        loggers::get_instance().log("AdapterControlPort::outgoing_send: Get LongPosVector");
        const LibItsGeoNetworking__TypesAndValues::LongPosVector* lpv = p->get_lpv(send_par.getLongPosVector().gnAddress());
        loggers::get_instance().log("AdapterControlPort::outgoing_send: Return value: %p", lpv);
        if (lpv == nullptr) {
          response.failure() = LibItsGeoNetworking__TypesAndValues::AcGnResponseFailure(BOOLEAN(true));
garciay's avatar
garciay committed
        } else {
          response.getLongPosVector() = *lpv;
        }
      } else if (send_par.ischosen(LibItsGeoNetworking__TypesAndValues::AcGnPrimitive::ALT_startPassBeaconing)) {
        loggers::get_instance().log("AdapterControlPort::outgoing_send: Start pass beaconing");
        p->start_pass_beaconing(send_par.startPassBeaconing().beaconHeader());
      } else if (send_par.ischosen(LibItsGeoNetworking__TypesAndValues::AcGnPrimitive::ALT_stopPassBeaconing)) {
        loggers::get_instance().log("AdapterControlPort::outgoing_send: Stop pass beaconing");
        p->stop_pass_beaconing();
garciay's avatar
garciay committed
      } else {
        response.failure() = LibItsGeoNetworking__TypesAndValues::AcGnResponseFailure(BOOLEAN(true));
      }
      // Send response
      loggers::get_instance().log_msg("AdapterControlPort::outgoing_send: Send response: ", response);
      incoming_message(response);
    } else {
      loggers::get_instance().error("AdapterControlPort::outgoing_send: %s not registered", "geoNetworkingPort");
    }
  }
garciay's avatar
garciay committed
  void AdapterControlPort::outgoing_send(const LibItsIpv6OverGeoNetworking__TypesAndValues::AcGn6Primitive& /*send_par*/)
  {
garciay's avatar
garciay committed
  }
garciay's avatar
garciay committed
  void AdapterControlPort::outgoing_send(const LibItsCommon__TypesAndValues::AcGnssPrimitive& /*send_par*/)
  {
garciay's avatar
garciay committed
  }
garciay's avatar
garciay committed
  void AdapterControlPort::outgoing_send(const LibItsCommon__TypesAndValues::AcSecPrimitive& /*send_par*/)
  {
garciay's avatar
garciay committed
  }

} /* end of namespace */