QStatus AllJoynBusObjectManager::TryRegisterBusObject(_Inout_ alljoyn_busattachment busAttachment, _In_ const alljoyn_busobject busObject, _In_ const bool secure)
{
    PCSTR objectPath = alljoyn_busobject_getpath(busObject);

    // To register this BusObject, it must first be created using GetBusObject so that a reference exists in BusAttachmentMap.
    if (!AllJoynBusObjectManager::BusObjectExists(busAttachment, objectPath))
    {
        return ER_BUS_OBJ_NOT_FOUND;
    }

    if (!AllJoynBusObjectManager::BusObjectIsRegistered(busAttachment, busObject))
    {
        if (secure)
        {
            RETURN_IF_QSTATUS_ERROR(alljoyn_busattachment_registerbusobject_secure(busAttachment, busObject));
        }
        else
        {
            RETURN_IF_QSTATUS_ERROR(alljoyn_busattachment_registerbusobject(busAttachment, busObject));
        }
        std::tuple<alljoyn_busobject, bool, int>& busObjectEntry = (*AllJoynBusObjectManager::BusAttachmentMap[busAttachment])[objectPath];

        // Record that the BusObject in this entry has been registered with its associated BusAttachment.
        std::get<1>(busObjectEntry) = true;
        return ER_OK;
    }
    return ER_OK;
}
_Check_return_ int32 TypeConversionHelpers::GetDictionaryTypeSignatures(_In_ PCSTR signature, _Out_ std::vector<char>* keySignature, _Out_ std::vector<char>* valueSignature)
{
    if ((strlen(signature) < 3) || (signature[0] != 'a') || (signature[1] != '{'))
    {
        return ER_BUS_BAD_SIGNATURE;
    }

    // Skip past the opening "a{".
    signature += 2;
    RETURN_IF_QSTATUS_ERROR(AppendNextCompleteType(signature, keySignature));
    signature += keySignature->size();
    RETURN_IF_QSTATUS_ERROR(AppendNextCompleteType(signature, valueSignature));
    keySignature->push_back('\0');
    valueSignature->push_back('\0');
    return ER_OK;
}
QStatus AllJoynBusObjectManager::GetBusObject(_In_ const alljoyn_busattachment busAttachment, _In_ const PCSTR objectPath, _Out_ alljoyn_busobject* busObject)
{
    // Ensure thread safety when creating BusObjects so that for each BusAttachment there is
    // at most one BusObject with any given ObjectPath.
    std::unique_lock<std::mutex> lock(AllJoynBusObjectManager::ModifyBusObjectMap);

    if (AllJoynBusObjectManager::BusObjectExists(busAttachment, objectPath))
    {
        std::tuple<alljoyn_busobject, bool, int>& busObjectEntry = (*AllJoynBusObjectManager::BusAttachmentMap[busAttachment])[objectPath];
        *busObject = std::get<0>(busObjectEntry);

        // Increment the reference counter for this entry.
        std::get<2>(busObjectEntry)++;
        return ER_OK;
    }
    // If a matching BusObject does not exist, create and save one.
    RETURN_IF_QSTATUS_ERROR(AllJoynBusObjectManager::CreateBusObject(objectPath, busObject));
    return AllJoynBusObjectManager::SaveBusObject(busAttachment, objectPath, *busObject);
}