Commit 0e77dcc5 authored by Brendan Long's avatar Brendan Long Committed by Brendan Long

Fill in most of DeviceMain.

parent b0429f75
......@@ -369,16 +369,16 @@ bridge::AllJoynHelper::EncodeStringForRootServiceName(std::string const& s, std:
t = TrimChar(t, '.');
}
void
bridge::AllJoynHelper::EncodeStringForAppName(std::string const& s, std::string &t)
std::string
bridge::AllJoynHelper::EncodeStringForAppName(std::string const& s)
{
t.clear();
std::string t;
for (char ch : s)
{
if (std::isalnum(ch))
t += ch;
}
return t;
}
std::string
......
......@@ -35,7 +35,7 @@ namespace bridge
static void EncodeStringForInterfaceName(std::string const& s, std::string& encoded);
static void EncodeStringForServiceName(std::string const& s, std::string &encoded);
static void EncodeStringForRootServiceName(std::string const& s, std::string &encoded);
static void EncodeStringForAppName(std::string const& s, std::string &encodeString);
static std::string EncodeStringForAppName(std::string const& s);
static std::string TrimChar(std::string const& s, char c);
};
......
......@@ -305,9 +305,12 @@ bridge::DeviceSystemBridge::UpdateDevice(shared_ptr<IAdapterDevice> const& dev,
QStatus
bridge::DeviceSystemBridge::CreateDevice(shared_ptr<IAdapterDevice> const& dev)
{
shared_ptr<BridgeDevice> newDevice(new BridgeDevice());
if (!dev.get())
return ER_BAD_ARG_1;
shared_ptr<BridgeDevice> newDevice(new BridgeDevice(dev, m_adapter));
QStatus st = newDevice->Initialize(dev);
QStatus st = newDevice->Initialize();
if (st == ER_OK)
m_deviceList.insert(std::make_pair(GetKey(dev), newDevice));
......
#include "Bridge/BridgeDevice.h"
#include "BridgeDevice.h"
#include "AllJoynHelper.h"
bridge::BridgeDevice::BridgeDevice(const shared_ptr<IAdapterDevice>& dev, const shared_ptr<IAdapter>& adapter)
: m_parent(dev)
, m_busAttachment(AllJoynHelper::EncodeStringForAppName(adapter->GetExposedApplicationName()).c_str(), true)
{
}
bridge::BridgeDevice::~BridgeDevice()
{
Shutdown();
}
QStatus
bridge::BridgeDevice::Shutdown()
......@@ -8,7 +21,7 @@ bridge::BridgeDevice::Shutdown()
}
QStatus
bridge::BridgeDevice::Initialize(shared_ptr<IAdapterDevice> const&)
bridge::BridgeDevice::Initialize()
{
QStatus st = ER_OK;
return st;
......
#pragma once
#include "Bridge/IAdapter.h"
#include <alljoyn/Status.h>
#include <alljoyn/BusAttachment.h>
namespace bridge
{
class BridgeDevice
{
public:
BridgeDevice(const shared_ptr<IAdapterDevice>&, const shared_ptr<IAdapter>&);
virtual ~BridgeDevice();
QStatus Shutdown();
QStatus Initialize(shared_ptr<IAdapterDevice> const& dev);
QStatus Initialize();
ajn::BusAttachment& GetBusAttachment()
{
return m_busAttachment;
}
shared_ptr<IAdapterDevice> GetAdapterDevice()
{
return m_parent;
}
private:
shared_ptr<IAdapterDevice> m_parent;
ajn::BusAttachment m_busAttachment;
};
}
#include "DeviceMain.h"
bridge::DeviceMain::DeviceMain()
: m_indexForSignal(1)
#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)
, m_indexForMethod(1)
, m_registeredOnAllJoyn(false)
{
......@@ -18,9 +35,46 @@ bridge::DeviceMain::Shutdown()
}
QStatus
bridge::DeviceMain::Initialize(shared_ptr<BridgeDevice> const&)
bridge::DeviceMain::Initialize()
{
QStatus st = ER_OK;
st = CreateMethodsAndSignals();
if (st != ER_OK)
return st;
st = AddInterface(*m_interfaceDescription);
if (st != ER_OK)
{
DSBLOG_WARN("Failed to add interface to bus object: %d", st);
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)
{
DSBLOG_WARN("Failed to add method handler: %d", st);
return st;
}
}
st = m_parent.GetBusAttachment().RegisterBusObject(*this);
if (st != ER_OK)
{
DSBLOG_WARN("Failed to register bus object: %d", st);
return st;
}
m_registeredOnAllJoyn = true;
return st;
}
......@@ -37,3 +91,14 @@ bridge::DeviceMain::IsSignalNameUnique(std::string const&)
return false;
}
QStatus
bridge::DeviceMain::CreateMethodsAndSignals()
{
// TODO
return ER_NOT_IMPLEMENTED;
}
void
bridge::DeviceMain::AJMethod(const ajn::InterfaceDescription::Member*, ajn::Message&)
{
}
......@@ -12,20 +12,17 @@ namespace bridge
class DeviceMethod;
class DeviceSignal;
class DeviceMain
class DeviceMain : private ajn::BusObject
{
DeviceMain();
DeviceMain(BridgeDevice& parent);
virtual ~DeviceMain();
QStatus Initialize(shared_ptr<BridgeDevice> const& parent);
QStatus Initialize();
bool IsMethodNameUnique(std::string const& name);
bool IsSignalNameUnique(std::string const& name);
void HandleSignal(IAdapterSignal const& adapterSignal);
inline shared_ptr<ajn::BusObject> GetBusObject() const
{ return m_busObject; }
inline int GetIndexForMethod()
{ return m_indexForMethod++; }
......@@ -34,15 +31,15 @@ namespace bridge
private:
void Shutdown();
QStatus CreateMethodsAndSignals();
void AJMethod(const ajn::InterfaceDescription::Member*, ajn::Message&);
private:
BridgeDevice& m_parent;
int m_indexForSignal;
int m_indexForMethod;
shared_ptr<ajn::BusObject> m_busObject;
std::unique_ptr<ajn::InterfaceDescription> m_interfaceDescrtipion;
std::string m_busObjectPath;
std::unique_ptr<ajn::InterfaceDescription> m_interfaceDescription;
std::string m_interfaceName;
std::shared_ptr<BridgeDevice> m_parent;
std::map<std::string, DeviceMethod* > m_deviceMethods;
std::map<std::string, DeviceSignal* > m_deviceSignals;
bool m_registeredOnAllJoyn;
......
#include "DeviceMethod.h"
bridge::DeviceMethod::DeviceMethod()
bridge::DeviceMethod::DeviceMethod(DeviceMain& dev)
: m_parent(dev)
{
}
......@@ -15,7 +16,7 @@ bridge::DeviceMethod::InvokeMethod(ajn::Message const&, ajn::MsgArg*, size_t)
}
QStatus
bridge::DeviceMethod::Initialize(shared_ptr<DeviceMain> const&, shared_ptr<IAdapterMethod> const&)
bridge::DeviceMethod::Initialize(shared_ptr<IAdapterMethod> const&)
{
return ER_NOT_IMPLEMENTED;
}
......
......@@ -14,10 +14,10 @@ namespace bridge
class DeviceMethod
{
public:
DeviceMethod();
DeviceMethod(DeviceMain&);
virtual ~DeviceMethod();
QStatus Initialize(shared_ptr<DeviceMain> const& parent, shared_ptr<IAdapterMethod> const& adapterMethod);
QStatus Initialize(shared_ptr<IAdapterMethod> const& adapterMethod);
uint32_t InvokeMethod(ajn::Message const& msg, ajn::MsgArg* outArgs, size_t numOutArgs);
inline std::string const& GetName() const
......@@ -28,11 +28,11 @@ namespace bridge
QStatus BuildSignature(AdapterValueVector const& valueList, std::string& sig, std::string& parameterNames);
private:
DeviceMain& m_parent;
std::string m_exposedName;
std::string m_inSignature;
std::string m_outSignature;
std::string m_parameterNames;
shared_ptr<DeviceMain> m_parent;
};
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment