Changed OCDOResource's handle param to take NULL
authorErich Keane <erich.keane@intel.com>
Mon, 23 Feb 2015 22:40:13 +0000 (14:40 -0800)
committerSashi Penta <sashi.kumar.penta@intel.com>
Fri, 27 Feb 2015 01:41:04 +0000 (01:41 +0000)
Most calls to OCDoResource were ignoring the handle parameter's
out value, so this call formalizes that a NULL is an acceptable value
for this parameter.  The callers that were using this (as highlighted
by Static Code Analaysis) without using the handle parameter were all
switched to use this new NULL functionality.

Change-Id: I9fc047c080499d1283ffc2cba32addd0f5689c77
Signed-off-by: Erich Keane <erich.keane@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/400
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Sachin Agrawal <sachin.agrawal@intel.com>
Reviewed-by: Sashi Penta <sashi.kumar.penta@intel.com>
resource/csdk/stack/include/ocstack.h
resource/csdk/stack/samples/linux/SimpleClientServer/occlient.cpp
resource/csdk/stack/samples/linux/SimpleClientServer/occlientbasicops.cpp
resource/csdk/stack/samples/linux/SimpleClientServer/occlientcoll.cpp
resource/csdk/stack/samples/linux/SimpleClientServer/occlientslow.cpp
resource/csdk/stack/src/ocstack.c
resource/src/InProcClientWrapper.cpp

index 0cbeea1..f8296b7 100644 (file)
@@ -455,7 +455,11 @@ OCStackResult OCProcess();
  * URI).
  *
  * @param handle             - @ref OCDoHandle to refer to the request sent out on behalf of
- *                             calling this API.
+ *                             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 method             - @ref OCMethod to perform on the resource
  * @param requiredUri        - URI of the resource to interact with
  * @param referenceUri       - URI of the reference resource
index 59f9e52..3f3a9eb 100644 (file)
@@ -595,7 +595,6 @@ int InitDeviceDiscovery()
 {
     OCStackResult ret;
     OCCallbackData cbData;
-    OCDoHandle handle;
     char szQueryUri[64] = { 0 };
 
     cbData.cb = DeviceDiscoveryReqCB;
@@ -614,12 +613,12 @@ int InitDeviceDiscovery()
 
     if(UNICAST_DISCOVERY)
     {
-        ret = OCDoResource(&handle, OC_REST_GET, szQueryUri, 0, 0, OC_CONNTYPE,
+        ret = OCDoResource(NULL, OC_REST_GET, szQueryUri, 0, 0, OC_CONNTYPE,
                 OC_LOW_QOS, &cbData, NULL, 0);
     }
     else
     {
-        ret = OCDoResource(&handle, OC_REST_GET, szQueryUri, 0, 0, (OC_ALL),
+        ret = OCDoResource(NULL, OC_REST_GET, szQueryUri, 0, 0, (OC_ALL),
                 OC_LOW_QOS, &cbData, NULL, 0);
     }
 
@@ -635,7 +634,6 @@ int InitDiscovery()
 {
     OCStackResult ret;
     OCCallbackData cbData;
-    OCDoHandle handle;
     /* Start a discovery query*/
     char szQueryUri[64] = { 0 };
 
@@ -653,12 +651,12 @@ int InitDiscovery()
     cbData.cd = NULL;
     if(UNICAST_DISCOVERY)
     {
-        ret = OCDoResource(&handle, OC_REST_GET, szQueryUri, 0, 0, OC_CONNTYPE,
+        ret = OCDoResource(NULL, OC_REST_GET, szQueryUri, 0, 0, OC_CONNTYPE,
                 OC_LOW_QOS, &cbData, NULL, 0);
     }
     else
     {
-        ret = OCDoResource(&handle, OC_REST_GET, szQueryUri, 0, 0, (OC_ALL),
+        ret = OCDoResource(NULL, OC_REST_GET, szQueryUri, 0, 0, (OC_ALL),
                 OC_LOW_QOS, &cbData, NULL, 0);
     }
     if (ret != OC_STACK_OK)
index f867cb5..77ab40e 100644 (file)
@@ -87,13 +87,12 @@ OCStackResult InvokeOCDoResource(std::ostringstream &query, OCMethod method,
 {
     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(), 0,
+    ret = OCDoResource(NULL, method, query.str().c_str(), 0,
         (method == OC_REST_PUT || method == OC_REST_POST) ? putPayload.c_str() : NULL,
          connType, qos, &cbData, options, numOptions);
 
@@ -342,7 +341,6 @@ int InitDiscovery()
 {
     OCStackResult ret;
     OCCallbackData cbData;
-    OCDoHandle handle;
     /* Start a discovery query*/
     char szQueryUri[64] = { 0 };
     if (UNICAST_DISCOVERY)
@@ -371,12 +369,12 @@ int InitDiscovery()
     cbData.cd = NULL;
     if (UNICAST_DISCOVERY)
     {
-        ret = OCDoResource(&handle, OC_REST_GET, szQueryUri, 0, 0, OC_CONNTYPE,
+        ret = OCDoResource(NULL, OC_REST_GET, szQueryUri, 0, 0, OC_CONNTYPE,
                 OC_LOW_QOS, &cbData, NULL, 0);
     }
     else
     {
-        ret = OCDoResource(&handle, OC_REST_GET, szQueryUri, 0, 0, (OC_ALL),
+        ret = OCDoResource(NULL, OC_REST_GET, szQueryUri, 0, 0, (OC_ALL),
                 OC_LOW_QOS, &cbData, NULL, 0);
     }
 
index 99bd9cd..8422e37 100644 (file)
@@ -222,7 +222,6 @@ int InitGetRequestToUnavailableResource(OCClientResponse * clientResponse)
 {
     OCStackResult ret;
     OCCallbackData cbData;
-    OCDoHandle handle;
     std::ostringstream getQuery;
     getQuery << "coap://" << getIPAddrTBServer(clientResponse) << ":" <<
             getPortTBServer(clientResponse) << "/SomeUnknownResource";
@@ -230,7 +229,7 @@ int InitGetRequestToUnavailableResource(OCClientResponse * clientResponse)
     cbData.context = (void*)DEFAULT_CONTEXT_VALUE;
     cbData.cd = NULL;
 
-    ret = OCDoResource(&handle, OC_REST_GET, getQuery.str().c_str(), 0, 0, OC_CONNTYPE, OC_LOW_QOS,
+    ret = OCDoResource(NULL, OC_REST_GET, getQuery.str().c_str(), 0, 0, OC_CONNTYPE, OC_LOW_QOS,
             &cbData, NULL, 0);
     if (ret != OC_STACK_OK)
     {
@@ -272,7 +271,6 @@ int InitPutRequest(OCClientResponse * clientResponse)
 {
     OCStackResult ret;
     OCCallbackData cbData;
-    OCDoHandle handle;
     //* Make a PUT query*/
     std::ostringstream getQuery;
     getQuery << "coap://" << getIPAddrTBServer(clientResponse) << ":" <<
@@ -283,7 +281,7 @@ int InitPutRequest(OCClientResponse * clientResponse)
     cbData.cd = NULL;
     OC_LOG_V(INFO, TAG, "PUT payload from client = %s ", putPayload.c_str());
 
-    ret = OCDoResource(&handle, OC_REST_PUT, getQuery.str().c_str(), 0, putPayload.c_str(),
+    ret = OCDoResource(NULL, OC_REST_PUT, getQuery.str().c_str(), 0, putPayload.c_str(),
                         OC_CONNTYPE, OC_LOW_QOS, &cbData, NULL, 0);
     if (ret != OC_STACK_OK)
     {
@@ -297,7 +295,6 @@ int InitGetRequest(OCClientResponse * clientResponse)
 {
     OCStackResult ret;
     OCCallbackData cbData;
-    OCDoHandle handle;
 
     uint8_t remoteIpAddr[4];
     uint16_t remotePortNu;
@@ -317,7 +314,7 @@ int InitGetRequest(OCClientResponse * clientResponse)
     cbData.cb = getReqCB;
     cbData.context = (void*)DEFAULT_CONTEXT_VALUE;
     cbData.cd = NULL;
-    ret = OCDoResource(&handle, OC_REST_GET,
+    ret = OCDoResource(NULL, OC_REST_GET,
             getQuery.str().c_str(), 0, 0, OC_CONNTYPE, OC_LOW_QOS,
             &cbData, NULL, 0);
     if (ret != OC_STACK_OK)
@@ -331,7 +328,6 @@ int InitDiscovery()
 {
     OCStackResult ret;
     OCCallbackData cbData;
-    OCDoHandle handle;
     /* Start a discovery query*/
     char szQueryUri[64] = { 0 };
 
@@ -340,7 +336,7 @@ int InitDiscovery()
     cbData.cb = discoveryReqCB;
     cbData.context = (void*)DEFAULT_CONTEXT_VALUE;
     cbData.cd = NULL;
-    ret = OCDoResource(&handle, OC_REST_GET, szQueryUri, 0, 0, OC_ALL,
+    ret = OCDoResource(NULL, OC_REST_GET, szQueryUri, 0, 0, OC_ALL,
                         OC_LOW_QOS,
             &cbData, NULL, 0);
     if (ret != OC_STACK_OK)
index f9f5eab..3f40b85 100644 (file)
@@ -71,13 +71,12 @@ OCStackResult InvokeOCDoResource(std::ostringstream &query,
 {
     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(), 0,
+    ret = OCDoResource(NULL, method, query.str().c_str(), 0,
             NULL, OC_CONNTYPE, qos, &cbData, options, numOptions);
 
     if (ret != OC_STACK_OK)
@@ -184,7 +183,6 @@ int InitDiscovery()
 {
     OCStackResult ret;
     OCCallbackData cbData;
-    OCDoHandle handle;
     /* Start a discovery query*/
     char szQueryUri[64] = { 0 };
     if (UNICAST_DISCOVERY)
@@ -212,12 +210,12 @@ int InitDiscovery()
     cbData.cd = NULL;
     if(UNICAST_DISCOVERY)
     {
-        ret = OCDoResource(&handle, OC_REST_GET, szQueryUri, 0, 0, OC_CONNTYPE,
+        ret = OCDoResource(NULL, OC_REST_GET, szQueryUri, 0, 0, OC_CONNTYPE,
                 OC_LOW_QOS, &cbData, NULL, 0);
     }
     else
     {
-        ret = OCDoResource(&handle, OC_REST_GET, szQueryUri, 0, 0, OC_ALL,
+        ret = OCDoResource(NULL, OC_REST_GET, szQueryUri, 0, 0, OC_ALL,
                 OC_LOW_QOS, &cbData, NULL, 0);
     }
     if (ret != OC_STACK_OK)
index 95ff875..2bd3591 100644 (file)
@@ -1577,6 +1577,7 @@ OCStackResult OCDoResource(OCDoHandle *handle, OCMethod method, const char *requ
     CAInfo_t requestData;
     CARequestInfo_t requestInfo;
     CAGroupEndpoint_t grpEnd = {0};
+    OCDoHandle resHandle = NULL;
 
     // To track if memory is allocated for additional header options
     uint8_t hdrOptionMemAlloc = 0;
@@ -1662,8 +1663,8 @@ OCStackResult OCDoResource(OCDoHandle *handle, OCMethod method, const char *requ
         goto exit;
     }
 
-    *handle = GenerateInvocationHandle();
-    if(!*handle)
+    resHandle = GenerateInvocationHandle();
+    if(!resHandle)
     {
         result = OC_STACK_NO_MEMORY;
         goto exit;
@@ -1791,13 +1792,18 @@ OCStackResult OCDoResource(OCDoHandle *handle, OCMethod method, const char *requ
         goto exit;
     }
 
-    if((result = AddClientCB(&clientCB, cbData, &token, handle, method,
+    if((result = AddClientCB(&clientCB, cbData, &token, &resHandle, method,
                              requestUri, resourceType)) != OC_STACK_OK)
     {
         result = OC_STACK_NO_MEMORY;
         goto exit;
     }
 
+    if(handle)
+    {
+        *handle = resHandle;
+    }
+
 exit:
     if(newUri != requiredUri)
     {
@@ -1807,9 +1813,11 @@ exit:
     {
         OC_LOG(ERROR, TAG, PCF("OCDoResource error"));
         FindAndDeleteClientCB(clientCB);
+        OCFree(resHandle);
     }
     CADestroyRemoteEndpoint(endpoint);
     OCFree(grpEnd.resourceUri);
+
     if (hdrOptionMemAlloc)
     {
         OCFree(requestData.options);
index 339875c..0fd1176 100644 (file)
@@ -265,8 +265,7 @@ namespace OC
         if(cLock)
         {
             std::lock_guard<std::recursive_mutex> lock(*cLock);
-            OCDoHandle handle;
-            result = OCDoResource(&handle, OC_REST_GET,
+            result = OCDoResource(nullptr, OC_REST_GET,
                                   deviceURI.c_str(),
                                   nullptr, nullptr, connectivityType,
                                   static_cast<OCQualityOfService>(QoS),
@@ -565,13 +564,12 @@ namespace OC
         if(cLock)
         {
             OCHeaderOption options[MAX_HEADER_OPTIONS];
-            OCDoHandle handle;
 
             assembleHeaderOptions(options, headerOptions);
 
             std::lock_guard<std::recursive_mutex> lock(*cLock);
 
-            result = OCDoResource(&handle, OC_REST_DELETE,
+            result = OCDoResource(nullptr, OC_REST_DELETE,
                                   os.str().c_str(), nullptr,
                                   nullptr, connectivityType,
                                   static_cast<OCQualityOfService>(m_cfg.QoS),