AdapterControlPort_Pki.partC 3.38 KB
Newer Older
Yann Garcia's avatar
Yann Garcia committed
#include <TTCN3.hh>

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

#include "http_layer.hh"

//=============================================================================
namespace LibItsPki__TestSystem {

  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) {}*/

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

  }

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

  }

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

  }

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

  void AdapterControlPort::user_map(const char * system_port)
  {
    loggers::get_instance().log(">>> AdapterControlPort::user_map: %s", system_port);

  }

  void AdapterControlPort::user_unmap(const char * system_port)
  {
    loggers::get_instance().log(">>> AdapterControlPort::user_unmap: %s", system_port);

  }

  void AdapterControlPort::user_start()
  {

  }

  void AdapterControlPort::user_stop()
  {

  }

  void AdapterControlPort::outgoing_send(const LibItsPki__TypesAndValues::AcGnPrimitive& send_par)
  {
    loggers::get_instance().log_msg(">>> AdapterControlPort::outgoing_send: ", send_par);

  }

  void AdapterControlPort::outgoing_send(const LibItsCommon__TypesAndValues::AcSecPrimitive& send_par)
  {
    loggers::get_instance().log_msg(">>> AdapterControlPort::outgoing_send: ", send_par);

    // Register this object for AdapterControlPort
    http_layer* p = registration<http_layer>::get_instance().get_item(std::string("HTTP"));
    if (p != NULL) {
      loggers::get_instance().log("AdapterControlPort::outgoing_send: Got HTTP layer %p", p);
      LibItsCommon__TypesAndValues::AdapterControlResults response;
      response.acSecResponse() = BOOLEAN(true);
      if (send_par.ischosen(LibItsCommon__TypesAndValues::AcSecPrimitive::ALT_acEnableSecurity)) {
        loggers::get_instance().log("AdapterControlPort::outgoing_send: Enable secured mode");
        std::string str(static_cast<const char*>(send_par.acEnableSecurity().certificateId()));
        if (p->enable_secured_mode(str, send_par.acEnableSecurity().enforceSecurity()) == -1) {
          response.acSecResponse() = BOOLEAN(false);
        }
      } else if (send_par.ischosen(LibItsCommon__TypesAndValues::AcSecPrimitive::ALT_acDisableSecurity)) {
        loggers::get_instance().log("AdapterControlPort::outgoing_send: Disable secured mode");
        if (p->disable_secured_mode() == -1) {
          response.acSecResponse() = BOOLEAN(false);
        }
      } else {
        response.acSecResponse() = BOOLEAN(false);
      }
      // 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");
    }
  }

} /* end of namespace */