From: bg.chun Date: Fri, 6 Jan 2017 02:04:46 +0000 (+0900) Subject: [IOT-1704]Apply new api OCDoRequest() to samples. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=59670f056dc34e7de6573b51d9d70fdc713dc04e;p=contrib%2Fiotivity.git [IOT-1704]Apply new api OCDoRequest() to samples. Apply new api OCDoRequest() to samples. And remove deprecated api OCDoResource(). related with below commit [IOT-1704]Deprecate OCDoResource and add OCDoRequest https://gerrit.iotivity.org/gerrit/#/c/16725/ Change-Id: I762b4e4c00caa1d52b471e46f2a0e7299402a7f7 Signed-off-by: bg.chun Reviewed-on: https://gerrit.iotivity.org/gerrit/16183 Tested-by: jenkins-iotivity Reviewed-by: Dave Thaler Reviewed-by: Dan Mihai Reviewed-by: Jaehong Jo Reviewed-by: Ashok Babu Channa --- diff --git a/resource/csdk/stack/samples/linux/SimpleClientServer/occlient.cpp b/resource/csdk/stack/samples/linux/SimpleClientServer/occlient.cpp index 63245e6..39d8d59 100644 --- a/resource/csdk/stack/samples/linux/SimpleClientServer/occlient.cpp +++ b/resource/csdk/stack/samples/linux/SimpleClientServer/occlient.cpp @@ -167,9 +167,12 @@ OCStackResult InvokeOCDoResource(std::ostringstream &query, 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); + OCPayload* payload = (method == OC_REST_PUT) ? putPayload() : NULL; + + ret = OCDoRequest(&handle, method, query.str().c_str(), remoteAddr, + payload, (ConnType), qos, &cbData, options, numOptions); + + OCPayloadDestroy(payload); if (ret != OC_STACK_OK) { @@ -788,9 +791,9 @@ int InitPlatformDiscovery(OCQualityOfService qos) cbData.context = (void*)DEFAULT_CONTEXT_VALUE; cbData.cd = NULL; - ret = OCDoResource(NULL, OC_REST_DISCOVER, szQueryUri, NULL, 0, CT_DEFAULT, - (qos == OC_HIGH_QOS) ? OC_HIGH_QOS : OC_LOW_QOS, - &cbData, NULL, 0); + ret = OCDoRequest(NULL, OC_REST_DISCOVER, szQueryUri, NULL, 0, CT_DEFAULT, + (qos == OC_HIGH_QOS) ? OC_HIGH_QOS : OC_LOW_QOS, + &cbData, NULL, 0); if (ret != OC_STACK_OK) { OIC_LOG(ERROR, TAG, "OCStack device error"); @@ -813,9 +816,9 @@ int InitDeviceDiscovery(OCQualityOfService qos) cbData.context = (void*)DEFAULT_CONTEXT_VALUE; cbData.cd = NULL; - ret = OCDoResource(NULL, OC_REST_DISCOVER, szQueryUri, NULL, 0, CT_DEFAULT, - (qos == OC_HIGH_QOS) ? OC_HIGH_QOS : OC_LOW_QOS, - &cbData, NULL, 0); + ret = OCDoRequest(NULL, OC_REST_DISCOVER, szQueryUri, NULL, 0, CT_DEFAULT, + (qos == OC_HIGH_QOS) ? OC_HIGH_QOS : OC_LOW_QOS, + &cbData, NULL, 0); if (ret != OC_STACK_OK) { OIC_LOG(ERROR, TAG, "OCStack device error"); @@ -838,9 +841,9 @@ int InitIntrospectionDiscovery(OCQualityOfService qos) cbData.context = (void*)DEFAULT_CONTEXT_VALUE; cbData.cd = NULL; - ret = OCDoResource(NULL, OC_REST_DISCOVER, szQueryUri, NULL, 0, CT_DEFAULT, - (qos == OC_HIGH_QOS) ? OC_HIGH_QOS : OC_LOW_QOS, - &cbData, NULL, 0); + ret = OCDoRequest(NULL, OC_REST_DISCOVER, szQueryUri, NULL, 0, CT_DEFAULT, + (qos == OC_HIGH_QOS) ? OC_HIGH_QOS : OC_LOW_QOS, + &cbData, NULL, 0); if (ret != OC_STACK_OK) { OIC_LOG(ERROR, TAG, "OCStack device error"); @@ -861,9 +864,9 @@ int InitDiscovery(OCQualityOfService qos) cbData.context = (void*)DEFAULT_CONTEXT_VALUE; cbData.cd = NULL; - ret = OCDoResource(NULL, OC_REST_DISCOVER, szQueryUri, NULL, 0, CT_DEFAULT, - (qos == OC_HIGH_QOS) ? OC_HIGH_QOS : OC_LOW_QOS, - &cbData, NULL, 0); + ret = OCDoRequest(NULL, OC_REST_DISCOVER, szQueryUri, NULL, 0, CT_DEFAULT, + (qos == OC_HIGH_QOS) ? OC_HIGH_QOS : OC_LOW_QOS, + &cbData, NULL, 0); if (ret != OC_STACK_OK) { OIC_LOG(ERROR, TAG, "OCStack resource error"); diff --git a/resource/csdk/stack/samples/linux/SimpleClientServer/occlientbasicops.cpp b/resource/csdk/stack/samples/linux/SimpleClientServer/occlientbasicops.cpp index a37f64a..13bc01c 100644 --- a/resource/csdk/stack/samples/linux/SimpleClientServer/occlientbasicops.cpp +++ b/resource/csdk/stack/samples/linux/SimpleClientServer/occlientbasicops.cpp @@ -119,9 +119,12 @@ OCStackResult InvokeOCDoResource(std::ostringstream &query, 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); + OCPayload* payload = (method == OC_REST_PUT || method == OC_REST_POST) ? putPayload() : NULL; + + ret = OCDoRequest(NULL, method, query.str().c_str(), dest, + payload, CT_DEFAULT, qos, &cbData, options, numOptions); + + OCPayloadDestroy(payload); if (ret != OC_STACK_OK) { @@ -367,8 +370,8 @@ int InitDiscovery() cbData.context = (void*)DEFAULT_CONTEXT_VALUE; cbData.cd = NULL; - ret = OCDoResource(NULL, OC_REST_DISCOVER, queryUri, 0, 0, CT_DEFAULT, - OC_LOW_QOS, &cbData, NULL, 0); + ret = OCDoRequest(NULL, OC_REST_DISCOVER, queryUri, 0, 0, CT_DEFAULT, + OC_LOW_QOS, &cbData, NULL, 0); if (ret != OC_STACK_OK) { OIC_LOG(ERROR, TAG, "OCStack resource error"); diff --git a/resource/csdk/stack/samples/linux/SimpleClientServer/occlientcoll.cpp b/resource/csdk/stack/samples/linux/SimpleClientServer/occlientcoll.cpp index 3dd9110..5063181 100644 --- a/resource/csdk/stack/samples/linux/SimpleClientServer/occlientcoll.cpp +++ b/resource/csdk/stack/samples/linux/SimpleClientServer/occlientcoll.cpp @@ -270,9 +270,9 @@ int InitGetRequestToUnavailableResource(OCClientResponse * clientResponse) cbData.context = (void*)DEFAULT_CONTEXT_VALUE; cbData.cd = NULL; - ret = OCDoResource(NULL, OC_REST_GET, getQuery.str().c_str(), - &clientResponse->devAddr, 0, ConnType, OC_LOW_QOS, - &cbData, NULL, 0); + ret = OCDoRequest(NULL, OC_REST_GET, getQuery.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"); @@ -296,9 +296,9 @@ int InitObserveRequest(OCClientResponse * clientResponse) 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); + ret = OCDoRequest(&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"); @@ -326,11 +326,13 @@ int InitPutRequest(OCClientResponse * clientResponse) OIC_LOG_V(INFO, TAG, "PUT payload from client = "); OCPayload* payload = putPayload(); OIC_LOG_PAYLOAD(INFO, payload); + + ret = OCDoRequest(NULL, OC_REST_PUT, getQuery.str().c_str(), + &clientResponse->devAddr, payload, ConnType, + OC_LOW_QOS, &cbData, NULL, 0); + 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"); @@ -353,9 +355,9 @@ int InitGetRequest(OCClientResponse * clientResponse) cbData.cb = getReqCB; cbData.context = (void*)DEFAULT_CONTEXT_VALUE; cbData.cd = NULL; - ret = OCDoResource(NULL, OC_REST_GET, getQuery.str().c_str(), - &clientResponse->devAddr, 0, ConnType, OC_LOW_QOS, - &cbData, NULL, 0); + ret = OCDoRequest(NULL, OC_REST_GET, getQuery.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"); @@ -375,9 +377,9 @@ int InitDiscovery() cbData.cb = discoveryReqCB; cbData.context = (void*)DEFAULT_CONTEXT_VALUE; cbData.cd = NULL; - ret = OCDoResource(NULL, OC_REST_DISCOVER, szQueryUri, NULL, 0, ConnType, - OC_LOW_QOS, - &cbData, NULL, 0); + ret = OCDoRequest(NULL, OC_REST_DISCOVER, szQueryUri, NULL, 0, ConnType, + OC_LOW_QOS, + &cbData, NULL, 0); if (ret != OC_STACK_OK) { OIC_LOG(ERROR, TAG, "OCStack resource error"); diff --git a/resource/csdk/stack/samples/linux/SimpleClientServer/occlientslow.cpp b/resource/csdk/stack/samples/linux/SimpleClientServer/occlientslow.cpp index aa45b6c..c4b762b 100644 --- a/resource/csdk/stack/samples/linux/SimpleClientServer/occlientslow.cpp +++ b/resource/csdk/stack/samples/linux/SimpleClientServer/occlientslow.cpp @@ -104,9 +104,12 @@ OCStackResult InvokeOCDoResource(std::ostringstream &query, cbData.context = (void*)DEFAULT_CONTEXT_VALUE; cbData.cd = NULL; - ret = OCDoResource(NULL, method, query.str().c_str(), dest, - (method == OC_REST_PUT) ? putPayload() : NULL, - adapterType, qos, &cbData, options, numOptions); + OCPayload* payload = (method == OC_REST_PUT) ? putPayload() : NULL; + + ret = OCDoRequest(NULL, method, query.str().c_str(), dest, + payload, adapterType, qos, &cbData, options, numOptions); + + OCPayloadDestroy(payload); if (ret != OC_STACK_OK) { @@ -250,8 +253,8 @@ int InitDiscovery() cbData.context = (void*)DEFAULT_CONTEXT_VALUE; cbData.cd = NULL; - ret = OCDoResource(NULL, OC_REST_DISCOVER, queryUri, 0, 0, CT_DEFAULT, - OC_LOW_QOS, &cbData, NULL, 0); + ret = OCDoRequest(NULL, OC_REST_DISCOVER, queryUri, 0, 0, CT_DEFAULT, + OC_LOW_QOS, &cbData, NULL, 0); if (ret != OC_STACK_OK) { OIC_LOG(ERROR, TAG, "OCStack resource error"); diff --git a/resource/csdk/stack/samples/linux/SimpleClientServer/ocremoteaccessclient.cpp b/resource/csdk/stack/samples/linux/SimpleClientServer/ocremoteaccessclient.cpp index 39627df..7090bef 100644 --- a/resource/csdk/stack/samples/linux/SimpleClientServer/ocremoteaccessclient.cpp +++ b/resource/csdk/stack/samples/linux/SimpleClientServer/ocremoteaccessclient.cpp @@ -110,17 +110,20 @@ OCStackResult InvokeOCDoResource(std::ostringstream &query, cbData.context = (void*)DEFAULT_CONTEXT_VALUE; cbData.cd = NULL; - OCStackResult ret = OCDoResource( - &handle, - method, - query.str().c_str(), - &responseAddr, - (method == OC_REST_PUT) ? putPayload() : NULL, - CT_ADAPTER_REMOTE_ACCESS, - qos, - &cbData, - options, - numOptions); + 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) { @@ -424,17 +427,16 @@ int InitDiscovery(OCQualityOfService qos) dest.flags = OC_DEFAULT_FLAGS; strncpy (dest.addr, remoteServerJabberID, MAX_ADDR_STR_SIZE - 1); - OCStackResult ret = OCDoResource(NULL, - OC_REST_GET, - MULTICAST_RESOURCE_DISCOVERY_QUERY, - &dest, - NULL, - CT_ADAPTER_REMOTE_ACCESS, - (qos == OC_HIGH_QOS) ? OC_HIGH_QOS : OC_LOW_QOS, - &cbData, - NULL, - 0 - ); + OCStackResult ret = OCDoRequest(NULL, + OC_REST_GET, + MULTICAST_RESOURCE_DISCOVERY_QUERY, + &dest, + NULL, + CT_ADAPTER_REMOTE_ACCESS, + (qos == OC_HIGH_QOS) ? OC_HIGH_QOS : OC_LOW_QOS, + &cbData, + NULL, + 0); if (ret != OC_STACK_OK) { diff --git a/resource/csdk/stack/samples/linux/secure/occlientbasicops.cpp b/resource/csdk/stack/samples/linux/secure/occlientbasicops.cpp index 005e386..b1916f5 100644 --- a/resource/csdk/stack/samples/linux/secure/occlientbasicops.cpp +++ b/resource/csdk/stack/samples/linux/secure/occlientbasicops.cpp @@ -124,9 +124,12 @@ OCStackResult InvokeOCDoResource(std::ostringstream &query, cbData.context = NULL; cbData.cd = NULL; - ret = OCDoResource(NULL, method, query.str().c_str(), dest, - (method == OC_REST_PUT || method == OC_REST_POST) ? putPayload() : NULL, - ocConnType, qos, &cbData, options, numOptions); + OCPayload* payload = (method == OC_REST_PUT || method == OC_REST_POST) ? putPayload() : NULL; + + ret = OCDoRequest(NULL, method, query.str().c_str(), dest, + payload, ocConnType, qos, &cbData, options, numOptions); + + OCPayloadDestroy(payload); if (ret != OC_STACK_OK) { @@ -327,8 +330,8 @@ int InitDiscovery() (UnicastDiscovery) ? "Unicast" : "Multicast", queryUri); - ret = OCDoResource(NULL, OC_REST_DISCOVER, queryUri, 0, 0, CT_DEFAULT, - OC_LOW_QOS, &cbData, NULL, 0); + ret = OCDoRequest(NULL, OC_REST_DISCOVER, queryUri, 0, 0, CT_DEFAULT, + OC_LOW_QOS, &cbData, NULL, 0); if (ret != OC_STACK_OK) { OIC_LOG(ERROR, TAG, "OCStack resource error"); diff --git a/resource/csdk/stack/samples/linux/secure/occlientdirectpairing.cpp b/resource/csdk/stack/samples/linux/secure/occlientdirectpairing.cpp index 4442997..d5f3928 100644 --- a/resource/csdk/stack/samples/linux/secure/occlientdirectpairing.cpp +++ b/resource/csdk/stack/samples/linux/secure/occlientdirectpairing.cpp @@ -61,8 +61,8 @@ static char DISCOVERY_QUERY[] = "%s/oic/res"; //Secure Virtual Resource database for Iotivity Client application //It contains Client's Identity and the PSK credentials //of other devices which the client trusts -static char CRED_FILE[] = "oic_svr_db_client_directpairing.dat"; - +static char CRED_FILE[] = "oic_svr_db_client_directpairing.dat"; + static const OCDPDev_t *discoveredDevs = NULL; static const OCDPDev_t *pairedDevs = NULL; @@ -335,8 +335,8 @@ int DeviceDiscovery() /* Start a discovery query*/ OIC_LOG_V(INFO, TAG, "Resource Discovery : %s\n", queryUri); - ret = OCDoResource(NULL, OC_REST_DISCOVER, queryUri, 0, 0, CT_DEFAULT, - OC_LOW_QOS, &cbData, NULL, 0); + ret = OCDoRequest(NULL, OC_REST_DISCOVER, queryUri, 0, 0, CT_DEFAULT, + OC_LOW_QOS, &cbData, NULL, 0); if (ret != OC_STACK_OK) { OIC_LOG(ERROR, TAG, "OCStack resource error"); @@ -400,8 +400,8 @@ OCStackResult SendGetRequest(OCDPDev_t* peer) cbData.cd = NULL; OIC_LOG(INFO, TAG, "Request to /a/light "); - ret = OCDoResource(&handle, OC_REST_GET, szQueryUri, - &endpoint, NULL, peer->connType, OC_LOW_QOS, &cbData, NULL, 0); + ret = OCDoRequest(&handle, OC_REST_GET, szQueryUri, + &endpoint, NULL, peer->connType, OC_LOW_QOS, &cbData, NULL, 0); if (ret != OC_STACK_OK) { OIC_LOG_V(ERROR, TAG, "OCDoResource returns error %d with method %d", ret, OC_REST_GET); @@ -412,13 +412,13 @@ OCStackResult SendGetRequest(OCDPDev_t* peer) FILE* client_fopen(const char *path, const char *mode) { - if (0 == strcmp(path, OC_SECURITY_DB_DAT_FILE_NAME)) - { + if (0 == strcmp(path, OC_SECURITY_DB_DAT_FILE_NAME)) + { return fopen(CRED_FILE, mode); - } - else - { - return fopen(path, mode); + } + else + { + return fopen(path, mode); } } @@ -533,8 +533,8 @@ void *CLInterface(void *data) OIC_LOG(ERROR, TAG, "Invalid PIN"); continue; } - sscanf(input, "%8s", pinNumber); - printf("\n"); + sscanf(input, "%8s", pinNumber); + printf("\n"); ret = DoDirectPairing(peer, pmSel, pinNumber); if (OC_STACK_OK != ret) diff --git a/resource/csdk/stack/samples/tizen/SimpleClientServer/occlient.cpp b/resource/csdk/stack/samples/tizen/SimpleClientServer/occlient.cpp index fe1f95f..ef6d77f 100644 --- a/resource/csdk/stack/samples/tizen/SimpleClientServer/occlient.cpp +++ b/resource/csdk/stack/samples/tizen/SimpleClientServer/occlient.cpp @@ -161,9 +161,12 @@ OCStackResult InvokeOCDoResource(std::ostringstream &query, cbData.context = (void*)DEFAULT_CONTEXT_VALUE; cbData.cd = NULL; - ret = OCDoResource(&handle, method, query.str().c_str(), remoteAddr, - (method == OC_REST_PUT) ? putPayload() : NULL, - (g_connType), qos, &cbData, options, numOptions); + OCPayload* payload = (method == OC_REST_PUT) ? putPayload() : NULL; + + ret = OCDoRequest(&handle, method, query.str().c_str(), remoteAddr, + payload, (g_connType), qos, &cbData, options, numOptions); + + OCPayloadDestroy(payload); if (ret != OC_STACK_OK) { @@ -728,9 +731,9 @@ int InitPlatformDiscovery(OCQualityOfService qos) cbData.context = (void*)DEFAULT_CONTEXT_VALUE; cbData.cd = NULL; - ret = OCDoResource(NULL, OC_REST_DISCOVER, szQueryUri, NULL, 0, CT_DEFAULT, - (qos == OC_HIGH_QOS) ? OC_HIGH_QOS : OC_LOW_QOS, - &cbData, NULL, 0); + ret = OCDoRequest(NULL, OC_REST_DISCOVER, szQueryUri, NULL, 0, CT_DEFAULT, + (qos == OC_HIGH_QOS) ? OC_HIGH_QOS : OC_LOW_QOS, + &cbData, NULL, 0); if (ret != OC_STACK_OK) { cout << "\nOCStack device error"; @@ -753,9 +756,9 @@ int InitDeviceDiscovery(OCQualityOfService qos) cbData.context = (void*)DEFAULT_CONTEXT_VALUE; cbData.cd = NULL; - ret = OCDoResource(NULL, OC_REST_DISCOVER, szQueryUri, NULL, 0, CT_DEFAULT, - (qos == OC_HIGH_QOS) ? OC_HIGH_QOS : OC_LOW_QOS, - &cbData, NULL, 0); + ret = OCDoRequest(NULL, OC_REST_DISCOVER, szQueryUri, NULL, 0, CT_DEFAULT, + (qos == OC_HIGH_QOS) ? OC_HIGH_QOS : OC_LOW_QOS, + &cbData, NULL, 0); if (ret != OC_STACK_OK) { cout << "\nOCStack device error"; @@ -776,9 +779,9 @@ int InitDiscovery(OCQualityOfService qos) cbData.context = (void*)DEFAULT_CONTEXT_VALUE; cbData.cd = NULL; - ret = OCDoResource(NULL, OC_REST_DISCOVER, szQueryUri, NULL, 0, CT_DEFAULT, - (qos == OC_HIGH_QOS) ? OC_HIGH_QOS : OC_LOW_QOS, - &cbData, NULL, 0); + ret = OCDoRequest(NULL, OC_REST_DISCOVER, szQueryUri, NULL, 0, CT_DEFAULT, + (qos == OC_HIGH_QOS) ? OC_HIGH_QOS : OC_LOW_QOS, + &cbData, NULL, 0); if (ret != OC_STACK_OK) { cout << "\nOCStack resource error";