Esempio n. 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;
        }
Esempio n. 2
0
        void RCSSeparateResponse::set()
        {
            assert(m_request.getOCRequest());

            auto resObj = m_request.getResourceObject().lock();
            if (!resObj)
            {
                throw RCSBadRequestException{ "ResourceObject is unspecified(or destroyed)!" };
            }

            if (m_done) throw RCSBadRequestException{ "The response is already set!" };

            auto ocRequest = m_request.getOCRequest();
            auto response = std::make_shared< OC::OCResourceResponse >();

            response->setRequestHandle(ocRequest->getRequestHandle());
            response->setResourceHandle(ocRequest->getResourceHandle());

            response->setResponseResult(OC_EH_OK);

            // TODO the response should be different by the request interface.
            response->setResourceRepresentation(
                    RCSRepresentation::toOCRepresentation(resObj->toRepresentation()));

            invokeOCFunc(OC::OCPlatform::sendResponse, response);

            m_done = true;
        }
Esempio n. 3
0
        void discoverResource(const std::string& host, const std::string& resourceURI,
                OCConnectivityType connectivityType, DiscoverCallback callback)
        {
            typedef OCStackResult (*FindResource)(const std::string&, const std::string&,
                    OCConnectivityType, OC::FindCallback);

            invokeOCFunc(static_cast< FindResource >(OC::OCPlatform::findResource),
                    host, resourceURI, connectivityType, static_cast < OC::FindCallback >(
                        std::bind(std::move(callback),
                                std::bind(&PrimitiveResource::create, std::placeholders::_1))));
        }
Esempio n. 4
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);
        }
Esempio n. 5
0
        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;
        }