Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If bus object already exists for another interface, reuse it instead … #2

Merged
merged 2 commits into from
Aug 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/BridgeRT/BridgeDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,20 @@ bool BridgeDevice::IsBusObjectPathUnique(std::string &path)
}
}

alljoyn_busobject BridgeDevice::GetBusObject(std::string &path)
{
auto index = m_deviceProperties.find(path);
if (m_deviceProperties.end() == index)
{
return nullptr;
}
else
{
auto prop = m_deviceProperties.at(path);
return prop->GetBusObject();
}
}

QStatus BridgeDevice::InitializeAllJoyn()
{
QStatus status = ER_OK;
Expand Down
1 change: 1 addition & 0 deletions src/BridgeRT/BridgeDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ namespace BridgeRT
std::string GetBusObjectPath(_In_ IAdapterProperty ^adapterProperty);
bool IsEqual(_In_ IAdapterDevice ^device);
bool IsBusObjectPathUnique(std::string &path);
alljoyn_busobject GetBusObject(std::string &path);
inline DWORD GetUniqueIdForInterface()
{
return m_uniqueIdForInterfaces++;
Expand Down
38 changes: 16 additions & 22 deletions src/BridgeRT/DeviceProperty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,28 +84,20 @@ QStatus DeviceProperty::Initialize(IAdapterProperty ^deviceProperty, PropertyInt
AllJoynHelper::EncodeBusObjectName(m_deviceProperty->Name, tempString);
m_AJBusObjectPath = "/" + tempString;

if (!parent->IsBusObjectPathUnique(m_AJBusObjectPath))
alljoyn_busobject bus = parent->GetBusObject(m_AJBusObjectPath);
if (bus == nullptr)
{
DWORD id = 0;
string tempPath;
do
// create alljoyn bus object and register it
m_AJBusObject = alljoyn_busobject_create(m_AJBusObjectPath.c_str(), QCC_FALSE, &callbacks, this);
if (NULL == m_AJBusObject)
{
tempPath = m_AJBusObjectPath;
std::ostringstream tmp;
tmp << ++id;
tempPath += '/';
tempPath += tmp.str();
} while (!parent->IsBusObjectPathUnique(tempPath));

m_AJBusObjectPath = tempPath;
status = ER_OUT_OF_MEMORY;
goto leave;
}
}

// create alljoyn bus object and register it
m_AJBusObject = alljoyn_busobject_create(m_AJBusObjectPath.c_str(), QCC_FALSE, &callbacks, this);
if (NULL == m_AJBusObject)
else
{
status = ER_OUT_OF_MEMORY;
goto leave;
m_AJBusObject = bus;
}

status = alljoyn_busobject_addinterface(m_AJBusObject, propertyInterface->GetInterfaceDescription());
Expand All @@ -124,11 +116,13 @@ QStatus DeviceProperty::Initialize(IAdapterProperty ^deviceProperty, PropertyInt
{
goto leave;
}

status = alljoyn_busattachment_registerbusobject(parent->GetBusAttachment(), m_AJBusObject);
if (ER_OK != status)
if (bus == nullptr)
{
goto leave;
status = alljoyn_busattachment_registerbusobject(parent->GetBusAttachment(), m_AJBusObject);
if (ER_OK != status)
{
goto leave;
}
}
m_registeredOnAllJoyn = true;

Expand Down