int InitPutRequest(OCClientResponse * clientResponse) { OCStackResult ret; OCCallbackData cbData; //* Make a PUT query*/ std::ostringstream getQuery; getQuery << "coap://" << clientResponse->devAddr.addr << ":" << clientResponse->devAddr.port << "/a/room" << queryInterface[TestType].text; cbData.cb = putReqCB; cbData.context = (void*)DEFAULT_CONTEXT_VALUE; cbData.cd = NULL; OIC_LOG_V(INFO, TAG, "PUT payload from client = "); OCPayload* payload = putPayload(); OIC_LOG_PAYLOAD(INFO, payload); OCPayloadDestroy(payload); ret = OCDoResource(NULL, OC_REST_PUT, getQuery.str().c_str(), &clientResponse->devAddr, putPayload(), ConnType, OC_LOW_QOS, &cbData, NULL, 0); if (ret != OC_STACK_OK) { OIC_LOG(ERROR, TAG, "OCStack resource error"); } return ret; }
int InitObserveRequest(OCClientResponse * clientResponse) { OCStackResult ret; OCCallbackData cbData; OCDoHandle handle; std::ostringstream obsReg; obsReg << getQueryStrForGetPut(); cbData.cb = getReqCB; cbData.context = (void*)DEFAULT_CONTEXT_VALUE; cbData.cd = NULL; OIC_LOG_V(INFO, TAG, "OBSERVE payload from client ="); OCPayload* payload = putPayload(); OIC_LOG_PAYLOAD(INFO, payload); OCPayloadDestroy(payload); ret = OCDoResource(&handle, OC_REST_OBSERVE, obsReg.str().c_str(), &clientResponse->devAddr, 0, ConnType, OC_LOW_QOS, &cbData, NULL, 0); if (ret != OC_STACK_OK) { OIC_LOG(ERROR, TAG, "OCStack resource error"); } else { gObserveDoHandle = handle; } return ret; }
OCStackResult InvokeOCDoResource(std::ostringstream &query, OCDevAddr *remoteAddr, OCMethod method, OCQualityOfService qos, OCClientResponseHandler cb, OCHeaderOption * options, uint8_t numOptions) { OCStackResult ret; OCCallbackData cbData; OCDoHandle handle; cbData.cb = cb; cbData.context = (void*)DEFAULT_CONTEXT_VALUE; cbData.cd = NULL; ret = OCDoResource(&handle, method, query.str().c_str(), remoteAddr, (method == OC_REST_PUT) ? putPayload() : NULL, (ConnType), qos, &cbData, options, numOptions); if (ret != OC_STACK_OK) { OIC_LOG_V(ERROR, TAG, "OCDoResource returns error %d with method %d", ret, method); } #ifdef WITH_PRESENCE else if (method == OC_REST_PRESENCE) { gPresenceHandle = handle; } #endif return ret; }
OCStackResult InvokeOCDoResource(std::ostringstream &query, OCMethod method, const OCDevAddr *dest, OCQualityOfService qos, OCClientResponseHandler cb, OCHeaderOption * options, uint8_t numOptions) { OCStackResult ret; OCCallbackData cbData; cbData.cb = cb; cbData.context = (void*)DEFAULT_CONTEXT_VALUE; cbData.cd = NULL; ret = OCDoResource(NULL, method, query.str().c_str(), dest, (method == OC_REST_PUT || method == OC_REST_POST) ? putPayload() : NULL, CT_DEFAULT, qos, &cbData, options, numOptions); if (ret != OC_STACK_OK) { OC_LOG_V(ERROR, TAG, "OCDoResource returns error %d with method %d", ret, method); } return ret; }
OCStackResult InvokeOCDoResource(std::ostringstream &query, OCMethod method, OCQualityOfService qos, OCClientResponseHandler cb, OCHeaderOption * options, uint8_t numOptions) { OCCallbackData cbData; OCDoHandle handle; cbData.cb = cb; cbData.context = (void*)DEFAULT_CONTEXT_VALUE; cbData.cd = NULL; OCPayload* payload = (method == OC_REST_PUT) ? putPayload() : NULL; OCStackResult ret = OCDoRequest(&handle, method, query.str().c_str(), &responseAddr, payload, CT_ADAPTER_REMOTE_ACCESS, qos, &cbData, options, numOptions); OCPayloadDestroy(payload); if (ret != OC_STACK_OK) { OIC_LOG_V(ERROR, TAG, "OCDoResource returns error %d with method %d", ret, method); } else if (method == OC_REST_OBSERVE || method == OC_REST_OBSERVE_ALL) { gObserveDoHandle = handle; } #ifdef WITH_PRESENCE else if (method == OC_REST_PRESENCE) { gPresenceHandle = handle; } #endif return ret; }