Commit da491bd1 authored by Brendan Long's avatar Brendan Long

devicemethod wip

parent 1b6df488
#pragma once
#include <string>
namespace bridge
{
namespace Constants
{
static const std::string CHANGE_OF_VALUE_SIGNAL("Change_Of_Value");
}
}
......@@ -283,10 +283,10 @@ bridge::AllJoynHelper::EncodeBusObjectName(std::string const& s, std::string &t)
t = TrimChar(t, '/');
}
void
bridge::AllJoynHelper::EncodePropertyOrMethodOrSignalName(std::string const& s, std::string &t)
std::string
bridge::AllJoynHelper::EncodePropertyOrMethodOrSignalName(std::string const& s)
{
t.clear();
std::string t;
bool upperCaseNextChar = true;
bool is1stChar = true;
......@@ -307,6 +307,8 @@ bridge::AllJoynHelper::EncodePropertyOrMethodOrSignalName(std::string const& s,
upperCaseNextChar = true;
}
}
return t;
}
void
......
......@@ -31,7 +31,7 @@ namespace bridge
static QStatus GetSignature(common::Variant::DataType type, std::string& sig);
static void EncodeBusObjectName(std::string const& s, std::string &builtName);
static void EncodePropertyOrMethodOrSignalName(std::string const& s, std::string &builtName);
static std::string EncodePropertyOrMethodOrSignalName(std::string const&);
static void EncodeStringForInterfaceName(std::string const& s, std::string& encoded);
static std::string EncodeStringForServiceName(std::string const&);
static std::string EncodeStringForRootServiceName(std::string const&);
......
......@@ -164,7 +164,28 @@ bridge::BridgeDevice::BuildServiceName()
QStatus
bridge::BridgeDevice::CreateDeviceProperties()
{
DSBLOG_NOT_IMPLEMENTED();
// TODO: VerifyCOVSupport();
for (auto property : m_device->GetProperties())
{
QStatus st;
shared_ptr<PropertyInterface> propertyInterface = GetInterfaceProperty(*property, st);
if (st != ER_OK)
return st;
if (!propertyInterface)
{
DSBLOG_ERROR("GetInterfaceProperty returned ER_OK but propertyInterface is null");
return ER_FAIL;
}
shared_ptr<DeviceProperty> deviceProperty(new DeviceProperty(property, propertyInterface, *this));
st = deviceProperty->Initialize();
if (st != ER_OK)
return st;
m_deviceProperties.insert(std::make_pair(deviceProperty->GetPathName(), deviceProperty));
m_about.AddObject(deviceProperty->GetBusObject(), *deviceProperty->GetPropertyInterface()->GetInterfaceDescription());
}
return ER_OK;
}
......
......@@ -4,6 +4,7 @@
#include "IAdapter.h"
#include "DeviceMain.h"
#include "DeviceProperty.h"
#include "PropertyInterface.h"
#include <alljoyn/BusAttachment.h>
namespace bridge
......@@ -42,6 +43,8 @@ namespace bridge
QStatus ShutdownAllJoyn();
QStatus RegisterSignalHandlers(bool isRegister);
shared_ptr<PropertyInterface> GetInterfaceProperty(IAdapterProperty&, QStatus&);
shared_ptr<IAdapterDevice> m_device;
shared_ptr<IAdapter> m_adapter;
ajn::BusAttachment m_busAttachment;
......
#include "DeviceMain.h"
#include "AdapterConstants.h"
#include "AllJoynHelper.h"
#include "BridgeDevice.h"
#include "DeviceMethod.h"
#include "DeviceSignal.h"
#include "Common/Log.h"
namespace
......@@ -20,6 +23,7 @@ static std::string BuildBusObjectPath(const std::string& name)
bridge::DeviceMain::DeviceMain(BridgeDevice& parent, const shared_ptr<IAdapterDevice>& adapterDevice)
: ajn::BusObject(BuildBusObjectPath(adapterDevice->GetName()).c_str(), false)
, m_parent(parent)
, m_adapterDevice(adapterDevice)
, m_indexForSignal(1)
, m_indexForMethod(1)
, m_interfaceDescription(NULL)
......@@ -59,9 +63,9 @@ bridge::DeviceMain::Initialize()
return st;
}
for (std::map<std::string, DeviceMethod*>::iterator i = m_deviceMethods.begin(); i != m_deviceMethods.end(); ++i)
for (auto i : m_deviceMethods)
{
const char* methodName = i->first.c_str();
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);
......@@ -96,11 +100,9 @@ bridge::DeviceMain::IsMethodNameUnique(std::string const& name)
}
bool
bridge::DeviceMain::IsSignalNameUnique(std::string const&)
bridge::DeviceMain::IsSignalNameUnique(std::string const& name)
{
// TODO:
DSBLOG_NOT_IMPLEMENTED();
return false;
return m_deviceSignals.find(name) != m_deviceSignals.end();
}
QStatus
......@@ -123,7 +125,22 @@ bridge::DeviceMain::CreateMethodsAndSignals()
return st;
}
// TODO: Create methods and signals
for (auto adapterMethod : m_adapterDevice->GetMethods())
{
auto i = m_deviceMethods.insert(std::make_pair(adapterMethod->GetName(), DeviceMethod(*this, adapterMethod)));
st = i.first->second.Initialize();
if (st != ER_OK)
return st;
}
for (auto adapterSignal : m_adapterDevice->GetSignals())
{
// change of value signal only concerns IAdapterProperty hence not this class
if (adapterSignal->GetName() == Constants::CHANGE_OF_VALUE_SIGNAL)
continue;
m_deviceSignals.insert(std::make_pair(adapterSignal->GetName(), DeviceSignal(*this, adapterSignal)));
}
m_interfaceDescription->Activate();
......@@ -133,7 +150,6 @@ bridge::DeviceMain::CreateMethodsAndSignals()
ajn::InterfaceDescription*
bridge::DeviceMain::GetInterfaceDescription()
{
DSBLOG_NOT_IMPLEMENTED();
return m_interfaceDescription;
}
......
......@@ -41,12 +41,13 @@ namespace bridge
private:
BridgeDevice& m_parent;
shared_ptr<IAdapterDevice> m_adapterDevice;
int m_indexForSignal;
int m_indexForMethod;
ajn::InterfaceDescription* m_interfaceDescription;
std::string m_interfaceName;
std::map<std::string, DeviceMethod* > m_deviceMethods;
std::map<std::string, DeviceSignal* > m_deviceSignals;
std::map<std::string, DeviceMethod> m_deviceMethods;
std::map<std::string, DeviceSignal> m_deviceSignals;
bool m_registeredOnAllJoyn;
};
}
......
#include "DeviceMethod.h"
#include "AllJoynHelper.h"
#include "Common/Log.h"
#include "DeviceMain.h"
#include <sstream>
namespace
{
DSB_DECLARE_LOGNAME(DeviceMethod);
}
bridge::DeviceMethod::DeviceMethod(DeviceMain& dev)
: m_parent(dev)
bridge::DeviceMethod::DeviceMethod(DeviceMain& parent, const shared_ptr<IAdapterMethod>& adapterMethod)
: m_parent(parent)
, m_adapterMethod(adapterMethod)
{
}
......@@ -23,23 +28,62 @@ bridge::DeviceMethod::InvokeMethod(ajn::Message const&, ajn::MsgArg*, size_t)
}
QStatus
bridge::DeviceMethod::Initialize(shared_ptr<IAdapterMethod> const&)
bridge::DeviceMethod::Initialize()
{
DSBLOG_NOT_IMPLEMENTED();
return ER_NOT_IMPLEMENTED;
if (!m_adapterMethod.get())
{
DSBLOG_WARN("DeviceMethod has invalid ptr to AdapterMethod");
return ER_INVALID_DATA;
}
QStatus st = SetName(m_adapterMethod->GetName());
if (st != ER_OK)
return st;
st = BuildSignature(m_adapterMethod->GetInputParams(), m_inSignature, m_parameterNames);
if (st != ER_OK)
return st;
st = BuildSignature(m_adapterMethod->GetOutputParams(), m_outSignature, m_parameterNames);
if (st != ER_OK)
return st;
st = m_parent.GetInterfaceDescription()->AddMethod(m_exposedName.c_str(), m_inSignature.c_str(), m_outSignature.c_str(), m_parameterNames.c_str());
if (st != ER_OK)
{
DSBLOG_WARN("Failed to add method %s to interface description: %s", m_exposedName.c_str(), QCC_StatusText(st));
return st;
}
return ER_OK;
}
QStatus
bridge::DeviceMethod::SetName(std::string const&)
bridge::DeviceMethod::SetName(std::string const& name)
{
DSBLOG_NOT_IMPLEMENTED();
return ER_NOT_IMPLEMENTED;
if (name.empty())
return ER_INVALID_DATA;
m_exposedName = AllJoynHelper::EncodePropertyOrMethodOrSignalName(name);
if (!m_parent.IsMethodNameUnique(m_exposedName))
{
m_exposedName += '_';
std::ostringstream tmp;
tmp << m_parent.GetIndexForMethod();
m_exposedName += tmp.str();
}
return ER_OK;
}
QStatus
bridge::DeviceMethod::BuildSignature(AdapterValueVector const&, std::string&, std::string&)
bridge::DeviceMethod::BuildSignature(AdapterValueVector const& adapterValues, std::string& signature, std::string& parameterNames)
{
DSBLOG_NOT_IMPLEMENTED();
signature.clear();
for (auto adapterValue : adapterValues)
{
}
return ER_NOT_IMPLEMENTED;
}
......@@ -14,10 +14,10 @@ namespace bridge
class DeviceMethod
{
public:
DeviceMethod(DeviceMain&);
DeviceMethod(DeviceMain&, shared_ptr<IAdapterMethod> const&);
virtual ~DeviceMethod();
QStatus Initialize(shared_ptr<IAdapterMethod> const& adapterMethod);
QStatus Initialize();
uint32_t InvokeMethod(ajn::Message const& msg, ajn::MsgArg* outArgs, size_t numOutArgs);
inline std::string const& GetName() const
......@@ -29,6 +29,7 @@ namespace bridge
private:
DeviceMain& m_parent;
shared_ptr<IAdapterMethod> m_adapterMethod;
std::string m_exposedName;
std::string m_inSignature;
std::string m_outSignature;
......
#include "DeviceProperty.h"
bridge::DeviceProperty::DeviceProperty()
#include "Common/Log.h"
namespace
{
DSB_DECLARE_LOGNAME(DeviceProperty);
}
bridge::DeviceProperty::DeviceProperty(shared_ptr<IAdapterProperty> adapterProperty, shared_ptr<PropertyInterface> propertyInterface, BridgeDevice& bridgeDevice)
: m_adapterProperty(adapterProperty)
, m_propertyInterface(propertyInterface)
, m_bridgeDevice(bridgeDevice)
{
}
QStatus Initialize()
{
DSBLOG_NOT_IMPLEMENTED();
return ER_NOT_IMPLEMENTED;
}
#ifndef __DEVICE_PROPERTY_H__
#define __DEVICE_PROPERTY_H__
#pragma once
#include "IAdapter.h"
#include "PropertyInterface.h"
#include "alljoyn/BusObject.h"
namespace bridge
{
class DeviceProperty
{
public:
DeviceProperty();
DeviceProperty(shared_ptr<IAdapterProperty>, shared_ptr<PropertyInterface>, BridgeDevice&);
QStatus Initialize();
std::string GetPathName();
ajn::BusObject& GetBusObject();
shared_ptr<PropertyInterface> GetPropertyInterface();
shared_ptr<IAdapterProperty> GetAdapterProperty();
private:
shared_ptr<IAdapterProperty> m_adapterProperty;
shared_ptr<PropertyInterface> m_propertyInterface;
BridgeDevice& m_bridgeDevice;
};
}
#endif
#include "DeviceSignal.h"
bridge::DeviceSignal::DeviceSignal()
bridge::DeviceSignal::DeviceSignal(DeviceMain& parent, const shared_ptr<IAdapterSignal>& adapterSignal)
: m_parent(parent)
, m_adapterSignal(adapterSignal)
{
}
bridge::DeviceSignal::~DeviceSignal()
{
}
std::string
bridge::DeviceSignal::GetName() const
{
return m_exposedName;
}
#ifndef __DEVICE_SIGNAL_H__
#define __DEVICE_SIGNAL_H__
#pragma once
#include <string>
#include "IAdapter.h"
#include "DeviceMain.h"
namespace bridge
{
class DeviceSignal
{
public:
DeviceSignal();
DeviceSignal(DeviceMain&, const shared_ptr<IAdapterSignal>&);
virtual ~DeviceSignal();
std::string GetName() const;
private:
DeviceMain& m_parent;
shared_ptr<IAdapterSignal> m_adapterSignal;
std::string m_exposedName;
std::string m_signature;
std::string m_parameterNames;
};
}
#endif
#include "PropertyInterface.h"
#pragma once
#include "Common/defines.h"
#include <alljoyn/InterfaceDescription.h>
#include <vector>
namespace bridge
{
class BridgeDevice;
class IAdapterProperty;
class PropertyInterface
{
public:
PropertyInterface(BridgeDevice&, const shared_ptr<IAdapterProperty>&);
virtual ~PropertyInterface();
ajn::InterfaceDescription* GetInterfaceDescription();
private:
BridgeDevice& m_bridgeDevice;
shared_ptr<IAdapterProperty> m_adapterProperty;
};
}
......@@ -10,6 +10,7 @@ SRCS=DeviceProviders/AllJoynProvider.cpp \
Bridge/DeviceMethod.cpp \
Bridge/DeviceProperty.cpp \
Bridge/DeviceSignal.cpp \
Bridge/PropertyInterface.cpp \
Common/Log.cpp \
Common/Variant.cpp \
Common/Guid.cpp \
......
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