Beispiel #1
0
        RCSResourceObject::Ptr RCSResourceObject::Builder::build()
        {
            OCResourceHandle handle{ nullptr };

            RCSResourceObject::Ptr server {
                new RCSResourceObject{ m_uri, m_properties, std::move(m_resourceAttributes) } };

            OC::EntityHandler entityHandler{ std::bind(&RCSResourceObject::entityHandler,
                    server.get(), std::placeholders::_1) };

            typedef OCStackResult (*RegisterResource)(OCResourceHandle&, std::string&,
                    const std::string&, const std::string&, OC::EntityHandler, uint8_t);

            invokeOCFunc(static_cast<RegisterResource>(OC::OCPlatform::registerResource),
                    handle, m_uri, m_types[0], m_interfaces[0], entityHandler, m_properties);

            std::for_each(m_interfaces.begin() + 1, m_interfaces.end(),
                    [&handle](const std::string& interfaceName){
                invokeOCFunc(OC::OCPlatform::bindInterfaceToResource, handle, interfaceName);
            });

            std::for_each(m_types.begin() + 1, m_types.end(),
                    [&handle](const std::string& typeName){
                invokeOCFunc(OC::OCPlatform::bindTypeToResource, handle, typeName);
            });

            server->m_resourceHandle = handle;
            server->m_interfaces = m_interfaces;
            server->m_types = m_types;

            return server;
        }
 void WaitForPtrBeingUnique()
 {
     while((object && !object.unique()) || (server && !server.unique()))
     {
         std::this_thread::sleep_for(std::chrono::milliseconds{ 100 });
     }
 }
 RCSResourceObject::LockGuard::LockGuard(const RCSResourceObject::Ptr ptr) :
         m_resourceObject(*ptr),
         m_autoNotifyPolicy{ ptr->getAutoNotifyPolicy() },
         m_isOwningLock{ false }
 {
     init();
 }
        RCSResourceObject::Ptr RCSResourceObject::Builder::build()
        {
            OCResourceHandle handle{ nullptr };

            RCSResourceObject::Ptr server {
                new RCSResourceObject{ m_properties, std::move(m_resourceAttributes) } };

            OC::EntityHandler entityHandler{ std::bind(&RCSResourceObject::entityHandler,
                    server.get(), std::placeholders::_1) };

            typedef OCStackResult (*RegisterResource)(OCResourceHandle&, std::string&,
                    const std::string&, const std::string&, OC::EntityHandler, uint8_t);

            invokeOCFunc(static_cast<RegisterResource>(OC::OCPlatform::registerResource),
                    handle, m_uri, m_type, m_interface, entityHandler, m_properties);

            server->m_resourceHandle = handle;

            return server;
        }
Beispiel #5
0
        void RCSResourceObject::bindResource(const RCSResourceObject::Ptr& resource)
        {
            if (!resource || resource.get() == this)
            {
                throw RCSInvalidParameterException("The resource is invalid!");
            }

            invokeOCFunc(OC::OCPlatform::bindResource,
                    m_resourceHandle, resource->m_resourceHandle);

            std::lock_guard< std:: mutex > lock{ m_mutexForBoundResources };
            m_boundResources.push_back(resource);
        }
 void CreateResource()
 {
     server = RCSResourceObject::Builder(RESOURCEURI, RESOURCETYPE, RESOURCEINTERFACE).build();
     server->setAttribute(ATTR_KEY, ATTR_VALUE);
 }