std::string ParticipantIdStorage::getProviderParticipantId(const std::string& domain,
                                                           const std::string& interfaceName,
                                                           const std::string& defaultValue,
                                                           const std::string& authenticationToken)
{
    // Access the persistence file through a threadsafe QSettings object
    QSettings settings(QString::fromStdString(filename), QSettings::IniFormat);

    // Arrange the provider ids by authentication token
    std::string authToken =
            (!authenticationToken.empty()) ? authenticationToken : std::string("default");
    std::string providerKey = createProviderKey(domain, interfaceName, authToken);

    // Lookup the participant id
    std::string participantId;
    QVariant value = settings.value(QString::fromStdString(providerKey));

    if (!value.isValid()) {
        // Persist a new participant Id, using the defaultValue if possible
        participantId = (!defaultValue.empty()) ? defaultValue : Util::createUuid().toStdString();
        settings.setValue(
                QString::fromStdString(providerKey), QString::fromStdString(participantId));
        settings.sync();
    } else {
        participantId = value.toString().toStdString();
    }

    return participantId;
}
void ParticipantIdStorage::setProviderParticipantId(const std::string& domain,
                                                    const std::string& interfaceName,
                                                    const std::string& participantId,
                                                    const std::string& authenticationToken)
{
    // Access the persistence file through a threadsafe QSettings object
    QSettings settings(QString::fromStdString(filename), QSettings::IniFormat);

    std::string providerKey = createProviderKey(domain, interfaceName, authenticationToken);
    settings.setValue(QString::fromStdString(providerKey), QString::fromStdString(participantId));
    settings.sync();
}
Example #3
0
void ParticipantIdStorage::setProviderParticipantId(const std::string& domain,
                                                    const std::string& interfaceName,
                                                    std::uint32_t majorVersion,
                                                    const std::string& participantId)
{
    assert(!domain.empty());
    assert(!interfaceName.empty());
    assert(!participantId.empty());

    bool fileNeedsUpdate = false;
    std::string providerKey = createProviderKey(domain, interfaceName, majorVersion);
    StorageItem item{providerKey, participantId};
    {
        WriteLocker lockAccessToStorage(storageMutex);
        auto retVal = storage.insert(std::move(item));
        fileNeedsUpdate = retVal.second;
    }

    if (fileNeedsUpdate) {
        writeStoreToFile();
    }
}
Example #4
0
std::string ParticipantIdStorage::getProviderParticipantId(const std::string& domain,
                                                           const std::string& interfaceName,
                                                           std::uint32_t majorVersion,
                                                           const std::string& defaultValue)
{
    assert(!domain.empty());
    assert(!interfaceName.empty());

    const std::string providerKey = createProviderKey(domain, interfaceName, majorVersion);
    MultiIndexContainer::const_iterator value;

    {
        ReadLocker lockAccessToStorage(storageMutex);
        value = storage.template get<participantIdStorageTags::read>().find(providerKey);
    }

    if (value != storage.cend()) {
        return value->participantId;
    } else {
        return (!defaultValue.empty()) ? defaultValue : util::createUuid();
    }
}