DeviceMain.cpp 2.24 KB
Newer Older
gladish's avatar
gladish committed
1 2
#include "DeviceMain.h"

Brendan Long's avatar
Brendan Long committed
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
#include "AllJoynHelper.h"
#include "Common/Log.h"

namespace
{
  DSB_DECLARE_LOGNAME(DeviceMain);
}

static std::string BuildBusObjectPath(const std::string& name)
{
  std::string encodedName;
  bridge::AllJoynHelper::EncodeBusObjectName(name, encodedName);
  return "/" + encodedName;
}

bridge::DeviceMain::DeviceMain(BridgeDevice& parent)
  : ajn::BusObject(BuildBusObjectPath(m_parent.GetAdapterDevice()->GetName()).c_str(), false)
  , m_parent(parent)
  , m_indexForSignal(1)
gladish's avatar
gladish committed
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
  , m_indexForMethod(1)
  , m_registeredOnAllJoyn(false)
{
}

bridge::DeviceMain::~DeviceMain()
{
  Shutdown();
}

void
bridge::DeviceMain::Shutdown()
{
}

QStatus
Brendan Long's avatar
Brendan Long committed
38
bridge::DeviceMain::Initialize()
gladish's avatar
gladish committed
39 40
{
  QStatus st = ER_OK;
Brendan Long's avatar
Brendan Long committed
41 42 43 44 45 46 47 48

  st = CreateMethodsAndSignals();
  if (st != ER_OK)
    return st;

  st = AddInterface(*m_interfaceDescription);
  if (st != ER_OK)
  {
49
    DSBLOG_WARN("Failed to add interface to bus object: %s", QCC_StatusText(st));
Brendan Long's avatar
Brendan Long committed
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
    return st;
  }

  for (std::map<std::string, DeviceMethod*>::iterator i = m_deviceMethods.begin(); i != m_deviceMethods.end(); ++i)
  {
    const char* methodName = i->first.c_str();
    const ajn::InterfaceDescription::Member* member = m_interfaceDescription->GetMember(methodName);
    if (!member) {
      DSBLOG_WARN("Failed to find InterfaceDescriptionMember for %s", methodName);
      return ER_INVALID_DATA;
    }

    st = AddMethodHandler(member, static_cast<ajn::MessageReceiver::MethodHandler>(&DeviceMain::AJMethod));
    if (st != ER_OK)
    {
65
      DSBLOG_WARN("Failed to add method handler: %s", QCC_StatusText(st));
Brendan Long's avatar
Brendan Long committed
66 67 68 69 70 71 72
      return st;
    }
  }

  st = m_parent.GetBusAttachment().RegisterBusObject(*this);
  if (st != ER_OK)
  {
73
    DSBLOG_WARN("Failed to register bus object: %s", QCC_StatusText(st));
Brendan Long's avatar
Brendan Long committed
74 75 76 77
    return st;
  }

  m_registeredOnAllJoyn = true;
gladish's avatar
gladish committed
78 79 80 81 82 83 84 85 86 87
  return st;
}

bool
bridge::DeviceMain::IsMethodNameUnique(std::string const& name)
{
  return m_deviceMethods.find(name) != m_deviceMethods.end();
}

bool
88
bridge::DeviceMain::IsSignalNameUnique(std::string const&)
gladish's avatar
gladish committed
89 90 91 92 93
{
  // TODO:
  return false;
}

Brendan Long's avatar
Brendan Long committed
94 95 96 97
QStatus
bridge::DeviceMain::CreateMethodsAndSignals()
{
  // TODO
98
  DSBLOG_NOT_IMPLEMENTED();
Brendan Long's avatar
Brendan Long committed
99 100 101 102 103 104 105
  return ER_NOT_IMPLEMENTED;
}

void
bridge::DeviceMain::AJMethod(const ajn::InterfaceDescription::Member*, ajn::Message&)
{
}