} OCEntityHandlerResult processGetRequest (PIPluginBase * plugin, OCEntityHandlerRequest *ehRequest, OCRepPayload **payload) { if (!plugin || !ehRequest || !payload) { return OC_EH_ERROR; } uint32_t attributeListIndex = 0; OCStackResult stackResult = OC_STACK_OK; PIResource_Zigbee * piResource = NULL; AttributeList attributeList = { 0, (CIECommandMask) 0, .list[0] = { NULL, NULL, OIC_ATTR_NULL, ZB_NULL, { .i = 0 } } }; stackResult = GetResourceFromHandle(plugin, (PIResource**) (&piResource), ehRequest->resource); if (stackResult != OC_STACK_OK) { OC_LOG (ERROR, TAG, "Failed to get resource from handle"); return OC_EH_ERROR; } stackResult = getZigBeeAttributesForOICResource ( piResource->header.piResource.resourceTypeName, &attributeList); if(stackResult != OC_STACK_OK) { OC_LOG_V (ERROR, TAG, "Failed to fetch attributes for %s", piResource->header.piResource.resourceTypeName); return OC_EH_ERROR; } *payload = OCRepPayloadCreate();
/** * Entity handler callback that fills the resPayload of the entityHandlerRequest. */ OCEntityHandlerResult PluginInterfaceEntityHandler(OCEntityHandlerFlag flag, OCEntityHandlerRequest * entityHandlerRequest, void* callbackParam) { if (!entityHandlerRequest) { OIC_LOG (ERROR, TAG, "Invalid request pointer"); return OC_EH_ERROR; } OCEntityHandlerResult ehResult = OC_EH_ERROR; OCStackResult result = OC_STACK_ERROR; PIPluginBase * plugin = (PIPluginBase *) callbackParam; OCEntityHandlerResponse * response = (OCEntityHandlerResponse *) OICCalloc(1, sizeof(*response)); if (!response) { return OC_EH_ERROR; } OCRepPayload* payload = (OCRepPayload *) entityHandlerRequest->payload; if (flag & OC_REQUEST_FLAG) { if (plugin->processEHRequest) { ehResult = plugin->processEHRequest(plugin, entityHandlerRequest, &payload); } } // If the result isn't an error or forbidden, send response if (!((ehResult == OC_EH_ERROR) || (ehResult == OC_EH_FORBIDDEN))) { // Format the response. Note this requires some info about the request response->requestHandle = entityHandlerRequest->requestHandle; response->resourceHandle = entityHandlerRequest->resource; response->ehResult = ehResult; response->payload = (OCPayload*) payload; // Indicate that response is NOT in a persistent buffer response->persistentBufferFlag = 0; result = OCDoResponse(response); if (result != OC_STACK_OK) { OIC_LOG_V(ERROR, TAG, "Error sending response %u", result); ehResult = OC_EH_ERROR; } } else { OIC_LOG_V(ERROR, TAG, "Error handling request %u", ehResult); PIResource * piResource = NULL; result = GetResourceFromHandle(plugin, &piResource, response->resourceHandle); OIC_LOG_V(ERROR, TAG, "Deleting resource \"%s\" because of failed request.", piResource->uri); result = DeleteResource(plugin, piResource); if(result != OC_STACK_OK) { OIC_LOG_V(ERROR, TAG, "Failed to delete resource after failed request."); ehResult = OC_EH_ERROR; } } OCPayloadDestroy(response->payload); OICFree(response); return ehResult; }