Add OCDoHandle parameter on resource-directory function
authorhyuna0213.jo <hyuna0213.jo@samsung.com>
Mon, 13 Feb 2017 02:32:40 +0000 (11:32 +0900)
committerHabib Virji <habib.virji@samsung.com>
Mon, 13 Feb 2017 14:01:17 +0000 (14:01 +0000)
this parameter is used to refer to the request sent out on behalf
of calling this API.

Change-Id: I7032f9e5afea6ecba44cb09e39c6bd654b59e5a9
Signed-off-by: hyuna0213.jo <hyuna0213.jo@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/17205
Tested-by: jenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: Habib Virji <habib.virji@samsung.com>
cloud/samples/client/thin_light/thin_room_light.cpp
resource/csdk/resource-directory/include/rd_client.h
resource/csdk/resource-directory/samples/rd_publishingClient.cpp
resource/csdk/resource-directory/src/RDClient.cpp
resource/csdk/resource-directory/src/rd_client.c
resource/csdk/resource-directory/unittests/rdtests.cpp
service/notification/src/provider/NSProviderResource.c

index a7ada69..e3001a0 100644 (file)
@@ -516,7 +516,7 @@ void PublishResources(string host)
         cout << "Publishing device info failed" << endl;
     }
 
-    res = OCRDPublish(host.c_str(), CT_ADAPTER_TCP, NULL, 0, &cbData, OC_LOW_QOS);
+    res = OCRDPublish(nullptr, host.c_str(), CT_ADAPTER_TCP, NULL, 0, &cbData, OC_LOW_QOS);
     if (res != OC_STACK_OK)
     {
         cout << "Unable to publish default resources to cloud" << endl;
@@ -524,7 +524,7 @@ void PublishResources(string host)
 
     cout << "Publishing user resources" << endl;
 
-    res = OCRDPublish(host.c_str(), CT_ADAPTER_TCP, resourceHandles, 1, &cbData, OC_LOW_QOS);
+    res = OCRDPublish(nullptr, host.c_str(), CT_ADAPTER_TCP, resourceHandles, 1, &cbData, OC_LOW_QOS);
     if (res != OC_STACK_OK)
     {
         cout << "Unable to publish user resources to cloud" << endl;
index 84ef0b7..998118c 100644 (file)
@@ -43,51 +43,71 @@ extern "C" {
 /**
  * Discover Local RD across the network.
  *
- * @param connectivityType Type of connectivity indicating the interface.
- * @param cbBiasFactor Asynchronous callback function that is invoked by the stack when
- *                     response is received. The callback is generated for each response
- *                     received.
- * @param qos Quality of service.
+ * @param handle            To refer to the request sent out on behalf of
+ *                          calling this API. This handle can be used to cancel this operation
+ *                          via the OCCancel API.
+ *                          @note: This reference is handled internally, and should not be free'd by
+ *                          the consumer.  A NULL handle is permitted in the event where the caller
+ *                          has no use for the return value.
+ * @param connectivityType  Type of connectivity indicating the interface.
+ * @param cbBiasFactor      Asynchronous callback function that is invoked by the stack when
+ *                          response is received. The callback is generated for each response
+ *                          received.
+ * @param qos               Quality of service.
  *
  * @return ::OC_STACK_OK on success, some other value upon failure.
  */
-OCStackResult OCRDDiscover(OCConnectivityType connectivityType, OCCallbackData *cbBiasFactor,
-                           OCQualityOfService qos);
+OCStackResult OCRDDiscover(OCDoHandle *handle, OCConnectivityType connectivityType,
+                           OCCallbackData *cbBiasFactor, OCQualityOfService qos);
 
 /**
  * Publish RD resource to Resource Directory.
  *
- * @param host The address of the RD.
- * @param connectivityType Type of connectivity indicating the interface.
- * @param resourceHandles This is the resource handle which we need to register to RD.
- * @param nHandles The counts of resource handle.
- * @param cbData Asynchronous callback function that is invoked by the stack when
- *               response is received. The callback is generated for each response
- *               received.
- * @param qos Quality of service.
+ * @param handle            To refer to the request sent out on behalf of
+ *                          calling this API. This handle can be used to cancel this operation
+ *                          via the OCCancel API.
+ *                          @note: This reference is handled internally, and should not be free'd by
+ *                          the consumer.  A NULL handle is permitted in the event where the caller
+ *                          has no use for the return value.
+ * @param host              The address of the RD.
+ * @param connectivityType  Type of connectivity indicating the interface.
+ * @param resourceHandles   This is the resource handle which we need to register to RD.
+ * @param nHandles          The counts of resource handle.
+ * @param cbData            Asynchronous callback function that is invoked by the stack when
+ *                          response is received. The callback is generated for each response
+ *                          received.
+ * @param qos               Quality of service.
  *
  * @return ::OC_STACK_OK on success, some other value upon failure.
  */
-OCStackResult OCRDPublish(const char *host, OCConnectivityType connectivityType,
+OCStackResult OCRDPublish(OCDoHandle *handle, const char *host,
+                          OCConnectivityType connectivityType,
                           OCResourceHandle *resourceHandles, uint8_t nHandles,
                           OCCallbackData *cbData, OCQualityOfService qos);
 
 /**
  * Publish RD resource to Resource Directory with a specific id.
  *
- * @param host The address of the RD.
- * @param id An unique identifier of publishing device.
- * @param connectivityType Type of connectivity indicating the interface.
- * @param resourceHandles This is the resource handle which we need to register to RD.
- * @param nHandles The counts of resource handle.
- * @param cbData Asynchronous callback function that is invoked by the stack when
- *               response is received. The callback is generated for each response
- *               received.
- * @param qos Quality of service.
+ * @param handle            To refer to the request sent out on behalf of
+ *                          calling this API. This handle can be used to cancel this operation
+ *                          via the OCCancel API.
+ *                          @note: This reference is handled internally, and should not be free'd by
+ *                          the consumer.  A NULL handle is permitted in the event where the caller
+ *                          has no use for the return value.
+ * @param host              The address of the RD.
+ * @param id                An unique identifier of publishing device.
+ * @param connectivityType  Type of connectivity indicating the interface.
+ * @param resourceHandles   This is the resource handle which we need to register to RD.
+ * @param nHandles          The counts of resource handle.
+ * @param cbData            Asynchronous callback function that is invoked by the stack when
+ *                          response is received. The callback is generated for each response
+ *                          received.
+ * @param qos               Quality of service.
  *
  * @return ::OC_STACK_OK on success, some other value upon failure.
  */
-OCStackResult OCRDPublishWithDeviceId(const char *host, const unsigned char *id,
+OCStackResult OCRDPublishWithDeviceId(OCDoHandle *handle, const char *host,
+                                      const unsigned char *id,
                                       OCConnectivityType connectivityType,
                                       OCResourceHandle *resourceHandles, uint8_t nHandles,
                                       OCCallbackData *cbData, OCQualityOfService qos);
@@ -95,33 +115,46 @@ OCStackResult OCRDPublishWithDeviceId(const char *host, const unsigned char *id,
 /**
  * Delete RD resource from Resource Directory.
  *
- * @param host The address of the RD.
- * @param connectivityType Type of connectivity indicating the interface.
- * @param resourceHandles This is the resource handle which we need to delete to RD.
- * @param nHandles The counts of resource handle.
- * @param cbData Asynchronous callback function that is invoked by the stack when
- *               response is received. The callback is generated for each response
- *               received.
- * @param qos Quality of service.
+ * @param handle            To refer to the request sent out on behalf of
+ *                          calling this API. This handle can be used to cancel this operation
+ *                          via the OCCancel API.
+ *                          @note: This reference is handled internally, and should not be free'd by
+ *                          the consumer.  A NULL handle is permitted in the event where the caller
+ *                          has no use for the return value.
+ * @param host              The address of the RD.
+ * @param connectivityType  Type of connectivity indicating the interface.
+ * @param resourceHandles   This is the resource handle which we need to delete to RD.
+ * @param nHandles          The counts of resource handle.
+ * @param cbData            Asynchronous callback function that is invoked by the stack when
+ *                          response is received. The callback is generated for each response
+ *                          received.
+ * @param qos               Quality of service.
  *
  * @return ::OC_STACK_OK on success, some other value upon failure.
  */
-OCStackResult OCRDDelete(const char *host, OCConnectivityType connectivityType,
+OCStackResult OCRDDelete(OCDoHandle *handle, const char *host,
+                         OCConnectivityType connectivityType,
                          OCResourceHandle *resourceHandles, uint8_t nHandles,
                          OCCallbackData *cbData, OCQualityOfService qos);
 
 /**
  * Delete RD resource from Resource Directory.
  *
- * @param host The address of the RD.
- * @param id An unique identifier of publishing device.
- * @param connectivityType Type of connectivity indicating the interface.
- * @param resourceHandles This is the resource handle which we need to delete to RD.
- * @param nHandles The counts of resource handle.
- * @param cbData Asynchronous callback function that is invoked by the stack when
- *               response is received. The callback is generated for each response
- *               received.
- * @param qos Quality of service.
+ * @param handle            To refer to the request sent out on behalf of
+ *                          calling this API. This handle can be used to cancel this operation
+ *                          via the OCCancel API.
+ *                          @note: This reference is handled internally, and should not be free'd by
+ *                          the consumer.  A NULL handle is permitted in the event where the caller
+ *                          has no use for the return value.
+ * @param host              The address of the RD.
+ * @param id                An unique identifier of publishing device.
+ * @param connectivityType  Type of connectivity indicating the interface.
+ * @param resourceHandles   This is the resource handle which we need to delete to RD.
+ * @param nHandles          The counts of resource handle.
+ * @param cbData            Asynchronous callback function that is invoked by the stack when
+ *                          response is received. The callback is generated for each response
+ *                          received.
+ * @param qos               Quality of service.
  *
  * @return
  *   - ::OC_STACK_OK on success
@@ -129,7 +162,8 @@ OCStackResult OCRDDelete(const char *host, OCConnectivityType connectivityType,
  *   - ::OC_STACK_INVALID_URI generated URI exceeds MAX_URI_LENGTH try fewer resourceHandles
  *   - some other value upon failure.
  */
-OCStackResult OCRDDeleteWithDeviceId(const char *host, const unsigned char *id,
+OCStackResult OCRDDeleteWithDeviceId(OCDoHandle *handle, const char *host,
+                                     const unsigned char *id,
                                      OCConnectivityType connectivityType,
                                      OCResourceHandle *resourceHandles, uint8_t nHandles,
                                      OCCallbackData *cbData, OCQualityOfService qos);
index df9d418..851bcd5 100644 (file)
@@ -143,7 +143,7 @@ int main()
                 cbData.cb = &handleDiscoveryCB;;
                 cbData.cd = NULL;
                 cbData.context = (void*) DEFAULT_CONTEXT_VALUE;
-                OCRDDiscover(CT_ADAPTER_IP, &cbData, OC_LOW_QOS);
+                OCRDDiscover(nullptr, CT_ADAPTER_IP, &cbData, OC_LOW_QOS);
                 break;
             }
             case 2:
@@ -153,7 +153,7 @@ int main()
                 cbData.cd = NULL;
                 cbData.context = (void*) DEFAULT_CONTEXT_VALUE;
                 std::string address = rdAddress.str();
-                OCRDPublish(address.c_str(), CT_ADAPTER_IP, handles,
+                OCRDPublish(nullptr, address.c_str(), CT_ADAPTER_IP, handles,
                             2, &cbData, OC_LOW_QOS);
                 break;
             }
index 93cfc0e..9d0397a 100644 (file)
@@ -126,7 +126,7 @@ OCStackResult RDClient::publishResourceToRD(const std::string& host,
     if (cLock)
     {
         std::lock_guard<std::recursive_mutex> lock(*cLock);
-        result = OCRDPublish(host.c_str(), connectivityType, &resourceHandles[0],
+        result = OCRDPublish(nullptr, host.c_str(), connectivityType, &resourceHandles[0],
                              resourceHandles.size(), &cbdata, static_cast<OCQualityOfService>(qos));
     }
 
@@ -186,7 +186,7 @@ OCStackResult RDClient::deleteResourceFromRD(const std::string& host,
     if (cLock)
     {
         std::lock_guard<std::recursive_mutex> lock(*cLock);
-        result = OCRDDelete(host.c_str(), connectivityType, &resourceHandles[0],
+        result = OCRDDelete(nullptr, host.c_str(), connectivityType, &resourceHandles[0],
                             resourceHandles.size(), &cbdata, static_cast<OCQualityOfService>(qos));
     }
 
index c8041c0..66284ba 100644 (file)
@@ -33,8 +33,8 @@
 
 #ifdef RD_CLIENT
 
-OCStackResult OCRDDiscover(OCConnectivityType connectivityType, OCCallbackData *cbBiasFactor,
-                           OCQualityOfService qos)
+OCStackResult OCRDDiscover(OCDoHandle *handle, OCConnectivityType connectivityType,
+                           OCCallbackData *cbBiasFactor, OCQualityOfService qos)
 {
     if (!cbBiasFactor || !cbBiasFactor->cb)
     {
@@ -47,7 +47,7 @@ OCStackResult OCRDDiscover(OCConnectivityType connectivityType, OCCallbackData *
     snprintf(queryUri, MAX_URI_LENGTH, "coap://%s%s", OC_MULTICAST_PREFIX, OC_RSRVD_RD_URI);
     OIC_LOG_V(DEBUG, TAG, "Querying RD: %s\n", queryUri);
 
-    return OCDoResource(NULL, OC_REST_DISCOVER, queryUri, NULL, NULL, connectivityType, qos,
+    return OCDoResource(handle, OC_REST_DISCOVER, queryUri, NULL, NULL, connectivityType, qos,
                         cbBiasFactor, NULL, 0);
 }
 
@@ -113,7 +113,8 @@ exit:
     return cbData->cb(cbData->context, handle, clientResponse);
 }
 
-OCStackResult OCRDPublish(const char *host, OCConnectivityType connectivityType,
+OCStackResult OCRDPublish(OCDoHandle *handle, const char *host,
+                          OCConnectivityType connectivityType,
                           OCResourceHandle *resourceHandles, uint8_t nHandles,
                           OCCallbackData *cbData, OCQualityOfService qos)
 {
@@ -131,7 +132,7 @@ OCStackResult OCRDPublish(const char *host, OCConnectivityType connectivityType,
     // Get Device ID from stack.
     const unsigned char *id = (const unsigned char *) OCGetServerInstanceIDString();
 
-    return OCRDPublishWithDeviceId(host, id, connectivityType, resourceHandles, nHandles,
+    return OCRDPublishWithDeviceId(handle, host, id, connectivityType, resourceHandles, nHandles,
                                    cbData, qos);
 }
 
@@ -263,7 +264,8 @@ static OCRepPayload *RDPublishPayloadCreate(const unsigned char *id,
     return rdPayload;
 }
 
-OCStackResult OCRDPublishWithDeviceId(const char *host, const unsigned char *id,
+OCStackResult OCRDPublishWithDeviceId(OCDoHandle *handle, const char *host,
+                                      const unsigned char *id,
                                       OCConnectivityType connectivityType,
                                       OCResourceHandle *resourceHandles, uint8_t nHandles,
                                       OCCallbackData *cbData, OCQualityOfService qos)
@@ -321,11 +323,12 @@ OCStackResult OCRDPublishWithDeviceId(const char *host, const unsigned char *id,
     rdPublishCbData.context = rdPublishContext;
     rdPublishCbData.cb = RDPublishCallback;
     rdPublishCbData.cd = RDPublishContextDeleter;
-    return OCDoResource(NULL, OC_REST_POST, targetUri, NULL, (OCPayload *)rdPayload,
+    return OCDoResource(handle, OC_REST_POST, targetUri, NULL, (OCPayload *)rdPayload,
                         connectivityType, qos, &rdPublishCbData, NULL, 0);
 }
 
-OCStackResult OCRDDelete(const char *host, OCConnectivityType connectivityType,
+OCStackResult OCRDDelete(OCDoHandle *handle, const char *host,
+                         OCConnectivityType connectivityType,
                          OCResourceHandle *resourceHandles, uint8_t nHandles,
                          OCCallbackData *cbData, OCQualityOfService qos)
 {
@@ -342,11 +345,12 @@ OCStackResult OCRDDelete(const char *host, OCConnectivityType connectivityType,
 
     const unsigned char *id = (const unsigned char *) OCGetServerInstanceIDString();
 
-    return OCRDDeleteWithDeviceId(host, id, connectivityType, resourceHandles, nHandles,
+    return OCRDDeleteWithDeviceId(handle, host, id, connectivityType, resourceHandles, nHandles,
                                   cbData, qos);
 }
 
-OCStackResult OCRDDeleteWithDeviceId(const char *host, const unsigned char *id,
+OCStackResult OCRDDeleteWithDeviceId(OCDoHandle *handle, const char *host,
+                                     const unsigned char *id,
                                      OCConnectivityType connectivityType,
                                      OCResourceHandle *resourceHandles, uint8_t nHandles,
                                      OCCallbackData *cbData, OCQualityOfService qos)
@@ -391,7 +395,7 @@ OCStackResult OCRDDeleteWithDeviceId(const char *host, const unsigned char *id,
     OICStrcatPartial(targetUri, sizeof(targetUri), queryParam, strlen(queryParam));
     OIC_LOG_V(DEBUG, TAG, "Target URI: %s", targetUri);
 
-    return OCDoResource(NULL, OC_REST_DELETE, targetUri, NULL, NULL, connectivityType,
+    return OCDoResource(handle, OC_REST_DELETE, targetUri, NULL, NULL, connectivityType,
                         qos, cbData, NULL, 0);
 }
 #endif
index b3dcbd0..4dfb340 100644 (file)
@@ -139,7 +139,7 @@ TEST_F(RDTests, CreateRDResource)
     cbData.cb = &handleDiscoveryCB;
     cbData.cd = NULL;
     cbData.context = (void*) DEFAULT_CONTEXT_VALUE;
-    EXPECT_EQ(OC_STACK_OK, OCRDDiscover(CT_ADAPTER_IP, &cbData, OC_LOW_QOS));
+    EXPECT_EQ(OC_STACK_OK, OCRDDiscover(NULL, CT_ADAPTER_IP, &cbData, OC_LOW_QOS));
 
     EXPECT_EQ(OC_STACK_OK, OCRDStop());
 }
@@ -200,13 +200,13 @@ TEST_F(RDTests, CreateRDResource)
 TEST_F(RDTests, RDPublishResourceNullAddr)
 {
     itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
-    EXPECT_EQ(OC_STACK_INVALID_IP, OCRDPublish(0, CT_ADAPTER_IP, nullptr, 0, 0, OC_LOW_QOS));
+    EXPECT_EQ(OC_STACK_INVALID_IP, OCRDPublish(NULL, 0, CT_ADAPTER_IP, nullptr, 0, 0, OC_LOW_QOS));
 }
 
 TEST_F(RDTests, RDPublishResourceNullCB)
 {
     itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
-    EXPECT_EQ(OC_STACK_INVALID_CALLBACK, OCRDPublish("127.0.0.1", CT_ADAPTER_IP, nullptr,
+    EXPECT_EQ(OC_STACK_INVALID_CALLBACK, OCRDPublish(NULL, "127.0.0.1", CT_ADAPTER_IP, nullptr,
                                                      0, 0, OC_LOW_QOS));
 }
 
@@ -225,7 +225,7 @@ TEST_F(RDTests, RDPublishResource)
                                             "oic.if.baseline", "/a/light", rdEntityHandler,
                                             NULL, (OC_DISCOVERABLE | OC_OBSERVABLE)));
 
-    EXPECT_EQ(OC_STACK_OK, OCRDPublish("127.0.0.1", CT_ADAPTER_IP, &handle,
+    EXPECT_EQ(OC_STACK_OK, OCRDPublish(NULL, "127.0.0.1", CT_ADAPTER_IP, &handle,
                                        1, &cbData, OC_LOW_QOS));
 }
 
@@ -247,20 +247,20 @@ TEST_F(RDTests, RDPublishMultipleResources)
                                             "oic.if.baseline", "/a/light2", rdEntityHandler,
                                             NULL, (OC_DISCOVERABLE | OC_OBSERVABLE)));
 
-    EXPECT_EQ(OC_STACK_OK, OCRDPublish("127.0.0.1", CT_ADAPTER_IP, handles,
+    EXPECT_EQ(OC_STACK_OK, OCRDPublish(NULL, "127.0.0.1", CT_ADAPTER_IP, handles,
                                        2, &cbData, OC_LOW_QOS));
 }
 
 TEST_F(RDTests, RDDeleteResourceNullAddr)
 {
     itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
-    EXPECT_EQ(OC_STACK_INVALID_IP, OCRDDelete(0, CT_ADAPTER_IP, nullptr, 0, 0, OC_LOW_QOS));
+    EXPECT_EQ(OC_STACK_INVALID_IP, OCRDDelete(NULL, 0, CT_ADAPTER_IP, nullptr, 0, 0, OC_LOW_QOS));
 }
 
 TEST_F(RDTests, RDDeleteResourceNullCB)
 {
     itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
-    EXPECT_EQ(OC_STACK_INVALID_CALLBACK, OCRDDelete("127.0.0.1", CT_ADAPTER_IP, nullptr,
+    EXPECT_EQ(OC_STACK_INVALID_CALLBACK, OCRDDelete(NULL, "127.0.0.1", CT_ADAPTER_IP, nullptr,
                                                     0, 0, OC_LOW_QOS));
 }
 
@@ -273,7 +273,7 @@ TEST_F(RDTests, RDDeleteAllResource)
     cbData.cd = NULL;
     cbData.context = (void*) DEFAULT_CONTEXT_VALUE;
 
-    EXPECT_EQ(OC_STACK_OK, OCRDDelete("127.0.0.1", CT_ADAPTER_IP, nullptr, 0, &cbData,
+    EXPECT_EQ(OC_STACK_OK, OCRDDelete(NULL, "127.0.0.1", CT_ADAPTER_IP, nullptr, 0, &cbData,
                                       OC_LOW_QOS));
 }
 
@@ -292,7 +292,7 @@ TEST_F(RDTests, RDDeleteSpecificResource)
                                             "oic.if.baseline", "/a/light", rdEntityHandler,
                                             NULL, OC_DISCOVERABLE | OC_OBSERVABLE));
 
-    EXPECT_EQ(OC_STACK_OK, OCRDDelete("127.0.0.1", CT_ADAPTER_IP, &handle,
+    EXPECT_EQ(OC_STACK_OK, OCRDDelete(NULL, "127.0.0.1", CT_ADAPTER_IP, &handle,
                                       1, &cbData, OC_LOW_QOS));
 }
 #endif
index 4d1b6cb..686ae33 100644 (file)
@@ -56,7 +56,7 @@ NSResult NSPublishResourceToCloud(char *serverAddress)
     cbData.cd = NULL;
 
     OCResourceHandle resourceHandles[1] = { NotificationResource.handle };
-    OCStackResult res = OCRDPublish(serverAddress, CT_ADAPTER_TCP, resourceHandles, 1,
+    OCStackResult res = OCRDPublish(NULL, serverAddress, CT_ADAPTER_TCP, resourceHandles, 1,
             &cbData, OC_LOW_QOS);
 
     if (res != OC_STACK_OK)