Exemplo n.º 1
0
void /*OCRepPayload */ *create_payload(struct things_resource_s *res, char *query)
{
	//    To provide identical pattern for handling the result
	//       allocating new memory for the payload to delete later
	OCRepPayload *payload = OCRepPayloadClone((OCRepPayload *)(res->rep->payload));
	THINGS_LOG_D(TAG, "Query : %s", query);

	if (query == NULL || (query != NULL && strlen(query) < 1)
		|| strstr(query, OIC_INTERFACE_ACTUATOR) != NULL || strstr(query, OIC_INTERFACE_SENSOR) != NULL) {
		THINGS_LOG_D(TAG, "Including properties & its values only");
		// Do nothing..
	} else if (strstr(query, OIC_INTERFACE_BASELINE)) {
		THINGS_LOG_D(TAG, "Including all the properties & its values");

		uint8_t index = 0;
		uint8_t number_of_interfaces = 0;
		uint8_t number_of_resource_type = 0;

		OCGetNumberOfResourceInterfaces((OCResourceHandle) res->resource_handle, &number_of_interfaces);

		THINGS_LOG_D(TAG, "@@  IF # : %d ", number_of_interfaces);
		//2.a Find interface type(s) & insert it/them into payload
		for (index = 0; index < number_of_interfaces; index++) {
			const char *interface = OCGetResourceInterfaceName((OCResourceHandle) res->resource_handle, index);
			THINGS_LOG_D(TAG, "=====>  IF : %s ", interface);
			OCRepPayloadAddInterface(payload, interface);
		}

		//3.a Find resource type & insert it into payload
		OCGetNumberOfResourceTypes((OCResourceHandle) res->resource_handle, &number_of_resource_type);
		THINGS_LOG_D(TAG, "@@  RT # : %d ", number_of_resource_type);
		for (index = 0; index < number_of_resource_type; index++) {
			const char *rt = OCGetResourceTypeName((OCResourceHandle) res->resource_handle, index);
			THINGS_LOG_D(TAG, "=====>  RT : %s ", rt);
			OCRepPayloadAddResourceType(payload, rt);
		}
	} else if (strstr(query, OC_RSRVD_INTERFACE_BATCH)) {
		THINGS_LOG_D(TAG, "Batch only supported by Collection Resource");
	} else if (strstr(query, OC_RSRVD_INTERFACE_LL)) {
		THINGS_LOG_D(TAG, "Link-List only supported by Collection Resource");
	} else {
		THINGS_LOG_D(TAG, "Not supporting Interface type : %s", query);
	}

	return payload;
}
Exemplo n.º 2
0
bool is_supporting_resource_type(struct things_resource_s *res, char *query)
{
	THINGS_LOG_D(TAG, THINGS_FUNC_ENTRY);
	bool result = false;
	uint8_t number_of_resource_type = 0;

	OCGetNumberOfResourceTypes((OCResourceHandle) res->resource_handle, &number_of_resource_type);

	THINGS_LOG_D(TAG, "@@  RT # : %d ", number_of_resource_type);
	//2.a Find resource type(s) & insert it/them into payload
	for (uint8_t index = 0; index < number_of_resource_type; index++) {
		const char *rtype = OCGetResourceTypeName((OCResourceHandle) res->resource_handle, index);

		// THINGS_LOG_D(TAG, "Supporting rtype :: %s(%s)", query, rtype);
		if (strstr(query, rtype) != NULL) {
			// THINGS_LOG_D(TAG, "Confirm rtype.");
			result = true;
			break;
		}
	}
	THINGS_LOG_D(TAG, THINGS_FUNC_EXIT);
	return result;
}
Exemplo n.º 3
0
OCRDPayload *OCRDPublishPayloadCreate(OCResourceHandle resourceHandles[], uint8_t nHandles,
                                      uint64_t ttl)
{
    OCTagsPayload *tagsPayload = NULL;
    OCLinksPayload *linksPayload = NULL;
    OCStringLL *rt = NULL;
    OCStringLL *itf = NULL;
    OCStringLL *mt = NULL;
    OCResourceProperty p = OC_RES_PROP_NONE;
    uint8_t ins = 0;

    OCRDPayload *rdPayload = OCRDPayloadCreate();
    if (!rdPayload)
    {
        return NULL;
    }

    const unsigned char *id = (const unsigned char *) OCGetServerInstanceIDString();
    tagsPayload = OCCopyTagsResources(NULL, id, ttl);
    if (!tagsPayload)
    {
        goto exit;
    }

    for (uint8_t j = 0; j < nHandles; j++)
    {
        OCResourceHandle handle = resourceHandles[j];
        if (handle)
        {
            rt = NULL;
            itf = NULL;
            mt = NULL;
            ins = 0;
            const char *uri = OCGetResourceUri(handle);
            uint8_t numElement = 0;
            if (OC_STACK_OK == OCGetNumberOfResourceTypes(handle, &numElement))
            {
                OCStackResult res = CreateStringLL(numElement, handle, OCGetResourceTypeName, &rt);
                if (OC_STACK_OK != res || !rt)
                {
                    goto exit;
                }
            }

            if (OC_STACK_OK == OCGetNumberOfResourceInterfaces(handle, &numElement))
            {
                OCStackResult res = CreateStringLL(numElement, handle, OCGetResourceInterfaceName,
                                                   &itf);
                if (OC_STACK_OK != res || !itf)
                {
                    goto exit;
                }
            }

            p = OCGetResourceProperties(handle);
            p = (OCResourceProperty) ((p & OC_DISCOVERABLE) | (p & OC_OBSERVABLE));

            OCStackResult res = OCGetResourceIns(handle, &ins);
            if (OC_STACK_OK != res)
            {
                goto exit;
            }

            mt = (OCStringLL *)OICCalloc(1, sizeof(OCStringLL));
            if (!mt)
            {
                goto exit;
            }
            mt->value = OICStrdup(DEFAULT_MESSAGE_TYPE);
            if (!mt->value)
            {
                goto exit;
            }

            if (!linksPayload)
            {
                linksPayload = OCCopyLinksResources(uri, NULL, rt, itf, p, NULL,
                                                    NULL, ins, ttl, mt);;
                if (!linksPayload)
                {
                    goto exit;
                }
            }
            else
            {
                OCLinksPayload *temp = linksPayload;
                while (temp->next)
                {
                    temp = temp->next;
                }
                temp->next = OCCopyLinksResources(uri, NULL, rt, itf, p, NULL,
                                                  NULL, ins, ttl, mt);
                if (!temp->next)
                {
                    goto exit;
                }
            }
            OCFreeOCStringLL(rt);
            OCFreeOCStringLL(itf);
            OCFreeOCStringLL(mt);
        }
    }

    rdPayload->rdPublish = OCCopyCollectionResource(tagsPayload, linksPayload);
    if (!rdPayload->rdPublish)
    {
        goto exit;
    }

    return rdPayload;

exit:
    if (rt)
    {
        OCFreeOCStringLL(rt);
    }
    if (itf)
    {
        OCFreeOCStringLL(itf);
    }
    if (mt)
    {
        OCFreeOCStringLL(mt);
    }
    if (tagsPayload)
    {
        OCFreeTagsResource(tagsPayload);
    }
    if (linksPayload)
    {
        OCFreeLinksResource(linksPayload);
    }
    OCRDPayloadDestroy(rdPayload);
    return NULL;
}
Exemplo n.º 4
0
int get_num_of_res_types(struct things_resource_s *res)
{
	uint8_t num = 0;
	OCGetNumberOfResourceTypes((OCResourceHandle) res->resource_handle, &num);
	return (int)num;
}