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;
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;
/**
* 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);
/**
* 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
* - ::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);
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:
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;
}
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));
}
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));
}
#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)
{
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);
}
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)
{
// 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);
}
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)
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)
{
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)
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
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());
}
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));
}
"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));
}
"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));
}
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));
}
"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
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)