Esempio n. 1
0
        void HostingObject::dataChangedCB(const RCSResourceAttributes & attributes)
        {
            if (attributes.empty())
            {
                return;
            }

            std::unique_lock<std::mutex> lock(mutexForCB);
            if (mirroredServer == nullptr)
            {
                try
                {
                    mirroredServer = createMirroredServer(this->remoteObject);
                } catch (const RCSException & e)
                {
                    OIC_HOSTING_LOG(DEBUG,
                                "[HostingObject::dataChangedCB]createMirroredServer Exception:%s",
                                e.what());
                    return;
                }
            }
            lock.unlock();

            RCSResourceObject::LockGuard guard(mirroredServer);
            mirroredServer->getAttributes() = std::move(attributes);
        }
Esempio n. 2
0
void HostingObject::dataChangedCB(const RCSResourceAttributes & attributes, RemoteObjectPtr rObject)
{
    if(attributes.empty())
    {
        return;
    }

    if(mirroredServer == nullptr)
    {
        try
        {
            mirroredServer = createMirroredServer(rObject);
        }catch(PlatformException &e)
        {
            OIC_HOSTING_LOG(DEBUG,
                        "[HostingObject::dataChangedCB]createMirroredServer PlatformException:%s",
                        e.what());
            mirroredServer = nullptr;
            return;
        }
    }

    RCSResourceAttributes rData;
    {
        RCSResourceObject::LockGuard guard(mirroredServer);
        rData = mirroredServer->getAttributes();
    }
    if(rData.empty() || rData != attributes)
    {
        {
            RCSResourceObject::LockGuard guard(mirroredServer);
            for(auto it = rData.begin(); ; ++it)
            {
                if(it == rData.end())
                {
                    break;
                }
                mirroredServer->removeAttribute(it->key());
            }

            for(auto it = attributes.begin();; ++it)
            {
                if(it == attributes.end())
                {
                    break;
                }
                mirroredServer->setAttribute(it->key(), it->value());
            }
        }
    }
}