void SimulatorRemoteResourceImpl::observe(ObserveType type,
        ObserveNotificationCallback callback)
{
    VALIDATE_CALLBACK(callback)

    std::lock_guard<std::mutex> lock(m_observeLock);
    if (m_observeState)
    {
        throw SimulatorException(SIMULATOR_ERROR, "Resource is already being observed!");
    }

    OC::ObserveCallback observeCallback = std::bind(
            [](const OC::HeaderOptions & headerOptions, const OC::OCRepresentation & ocRep,
               const int errorCode, const int sqNum, std::string id, ObserveNotificationCallback callback)
    {
        SIM_LOG(ILogger::INFO, "Observe response received..." << "\n" << getPayloadString(ocRep));

        SimulatorResourceModelSP resourceModel(
            new  SimulatorResourceModel(SimulatorResourceModel::build(ocRep)));
        callback(id, static_cast<SimulatorResult>(errorCode), resourceModel, sqNum);
    }, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4,
    m_id, callback);

    OC::ObserveType observeType = OC::ObserveType::Observe;
    if (type == ObserveType::OBSERVE_ALL)
        observeType = OC::ObserveType::ObserveAll;

    try
    {
        OCStackResult ocResult = m_ocResource->observe(observeType, OC::QueryParamsMap(), observeCallback);
        if (OC_STACK_OK != ocResult)
            throw SimulatorException(static_cast<SimulatorResult>(ocResult), OC::OCException::reason(ocResult));

        SIM_LOG(ILogger::INFO, "OBSERVE request sent");
    }
    catch (OC::OCException &e)
    {
        throw SimulatorException(static_cast<SimulatorResult>(e.code()), e.reason());
    }

    m_observeState = true;
}
Exemple #2
0
void FormEditor::slotQrcFileChangedExternally(const QString &path)
{
    QDesignerIntegration *designerIntegration = qobject_cast<QDesignerIntegration *>(integration());
    if (!designerIntegration)
        return;

    QDesignerIntegration::ResourceFileWatcherBehaviour behaviour = designerIntegration->resourceFileWatcherBehaviour();
    if (behaviour == QDesignerIntegration::NoWatcher) {
        return;
    } else if (behaviour == QDesignerIntegration::PromptAndReload) {
        QMessageBox::StandardButton button = dialogGui()->message(topLevel(), QDesignerDialogGuiInterface::FileChangedMessage, QMessageBox::Warning,
                tr("Resource File Changed"),
                tr("The file \"%1\" has changed outside Designer. Do you want to reload it?").arg(path),
                QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);

        if (button != QMessageBox::Yes)
            return;
    }

    resourceModel()->reload(path);
}