

#include "config_profile/profile.h"

#include "transport_manager/transport_manager_default.h"
#include "transport_manager/tcp/tcp_transport_adapter.h"
#include "utils/logger.h"

#ifdef BLUETOOTH_SUPPORT
#include "transport_manager/bluetooth/bluetooth_transport_adapter.h"
#endif


#if defined(USB_SUPPORT)
#include "transport_manager/usb/usb_aoa_adapter.h"
#endif  // USB_SUPPORT



namespace transport_manager {
CREATE_LOGGERPTR_GLOBAL(logger_, "TransportManager")

int TransportManagerDefault::Init(resumption::LastState& last_state) {
  LOG4CXX_TRACE(logger_, "enter");
  if (E_SUCCESS != TransportManagerImpl::Init(last_state)) {
    LOG4CXX_TRACE(logger_,
                  "exit with E_TM_IS_NOT_INITIALIZED. Condition: E_SUCCESS != "
                  "TransportManagerImpl::Init()");
    return E_TM_IS_NOT_INITIALIZED;
  }

#ifdef BLUETOOTH_SUPPORT
  transport_adapter::TransportAdapterImpl* ta_bluetooth =
      new transport_adapter::BluetoothTransportAdapter(last_state);
#ifdef TELEMETRY_MONITOR
  if (metric_observer_) {
    ta_bluetooth->SetTelemetryObserver(metric_observer_);
  }
#endif  // TELEMETRY_MONITOR
  AddTransportAdapter(ta_bluetooth);
  ta_bluetooth = NULL;
#endif

  const uint16_t port =
      profile::Profile::instance()->transport_manager_tcp_adapter_port();
  transport_adapter::TransportAdapterImpl* ta_tcp =
      new transport_adapter::TcpTransportAdapter(port, last_state);
#ifdef TELEMETRY_MONITOR
  if (metric_observer_) {
    ta_tcp->SetTelemetryObserver(metric_observer_);
  }
#endif  // TELEMETRY_MONITOR
  AddTransportAdapter(ta_tcp);
  ta_tcp = NULL;


#if defined(USB_SUPPORT)
  transport_adapter::TransportAdapterImpl* ta_usb =
      new transport_adapter::UsbAoaAdapter(last_state);
#ifdef TELEMETRY_MONITOR
  if (metric_observer_) {
    ta_usb->SetTelemetryObserver(metric_observer_);
  }
#endif  // TELEMETRY_MONITOR
  AddTransportAdapter(ta_usb);
  ta_usb = NULL;
#endif  // USB_SUPPORT

  LOG4CXX_TRACE(logger_, "exit with E_SUCCESS");
  return E_SUCCESS;
}

TransportManagerDefault::~TransportManagerDefault() {}

TransportManagerDefault::TransportManagerDefault()
    : TransportManagerImpl() {}

}  //  namespace transport_manager
