Exemple #1
0
    OCRepresentation getRoomRepresentation(void)
    {
        m_roomRep.clearChildren();

        m_roomRep.addChild(getLightRepresentation());
        m_roomRep.addChild(getFanRepresentation());
        return m_roomRep;
    }
    OCRepresentation parseGetSetCallback(OCClientResponse* clientResponse)
    {
        if(clientResponse->payload == nullptr ||
                (
                    clientResponse->payload->type != PAYLOAD_TYPE_DEVICE &&
                    clientResponse->payload->type != PAYLOAD_TYPE_PLATFORM &&
                    clientResponse->payload->type != PAYLOAD_TYPE_REPRESENTATION
                )
          )
        {
            //OCPayloadDestroy(clientResponse->payload);
            return OCRepresentation();
        }

        MessageContainer oc;
        oc.setPayload(clientResponse->payload);
        //OCPayloadDestroy(clientResponse->payload);

        std::vector<OCRepresentation>::const_iterator it = oc.representations().begin();
        if(it == oc.representations().end())
        {
            return OCRepresentation();
        }

        // first one is considered the root, everything else is considered a child of this one.
        OCRepresentation root = *it;
        ++it;

        std::for_each(it, oc.representations().end(),
                [&root](const OCRepresentation& repItr)
                {root.addChild(repItr);});
        return root;

    }
    OCRepresentation parseRDResponseCallback(OCClientResponse* clientResponse)
    {
        if (nullptr == clientResponse || nullptr == clientResponse->payload ||
                    PAYLOAD_TYPE_RD != clientResponse->payload->type)
        {
            return OCRepresentation();
        }

        MessageContainer oc;
        oc.setPayload(clientResponse->payload);

        std::vector<OCRepresentation>::const_iterator it = oc.representations().begin();
        if (it == oc.representations().end())
        {
            return OCRepresentation();
        }

        // first one is considered the root, everything else is considered a child of this one.
        OCRepresentation root = *it;
        root.setDevAddr(clientResponse->devAddr);
        root.setUri(clientResponse->resourceUri);
        ++it;

        std::for_each(it, oc.representations().end(),
                [&root](const OCRepresentation& repItr)
                {root.addChild(repItr);});
        return root;

    }
OCRepresentation parseGetSetCallback(OCClientResponse* clientResponse)
{
    if(clientResponse->resJSONPayload == nullptr || clientResponse->resJSONPayload[0] == '\0')
    {
        return OCRepresentation();
    }

    MessageContainer oc;
    oc.setJSONRepresentation(clientResponse->resJSONPayload);

    std::vector<OCRepresentation>::const_iterator it = oc.representations().begin();
    if(it == oc.representations().end())
    {
        return OCRepresentation();
    }

    // first one is considered the root, everything else is considered a child of this one.
    OCRepresentation root = *it;
    ++it;

    std::for_each(it, oc.representations().end(),
                  [&root](const OCRepresentation& repItr)
    {
        root.addChild(repItr);
    });
    return root;

}
/*
* Class:     org_iotivity_base_OcRepresentation
* Method:    addChild
* Signature: (Lorg/iotivity/base/OcRepresentation;)V
*/
JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_addChild
(JNIEnv *env, jobject thiz, jobject jOcRepresentation)
{
    LOGD("OcRepresentation_addChild");
    OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
    if (!rep) return;

    OCRepresentation *child = JniOcRepresentation::getOCRepresentationPtr(env, jOcRepresentation);
    if (!child) return;

    rep->addChild(*child);
}