Jira Issue-964: Add more types for OCEntityHandlerResult 91/8991/2
authorHabib Virji <habib.virji@samsung.com>
Tue, 28 Jun 2016 10:09:09 +0000 (11:09 +0100)
committerZiran Sun <ziran.sun@samsung.com>
Wed, 29 Jun 2016 09:54:37 +0000 (09:54 +0000)
OCEntityHandlerResult includes more type that matches with
CAResponseResult_t.

This patch does not modify the return value of the exisitng code
and neither changes the enum value of the existing code.
It appends to the existing list based on the CoAP return values.

Change-Id: I2be12bb5f80ab751c9afc4e89c48446479c8f565
Signed-off-by: Habib Virji <habib.virji@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/8991
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Phil Coval <philippe.coval@osg.samsung.com>
Reviewed-by: Dwarkaprasad Dayama <dwarka.dayama@samsung.com>
Reviewed-by: Ziran Sun <ziran.sun@samsung.com>
resource/csdk/stack/include/octypes.h
resource/csdk/stack/src/ocserverrequest.c
resource/unittests/OCResourceResponseTest.cpp

index 96b8177..3428b35 100644 (file)
@@ -849,11 +849,21 @@ typedef enum
 {
     OC_EH_OK = 0,
     OC_EH_ERROR,
-    OC_EH_RESOURCE_CREATED,
-    OC_EH_RESOURCE_DELETED,
-    OC_EH_SLOW,
-    OC_EH_FORBIDDEN,
-    OC_EH_RESOURCE_NOT_FOUND
+    OC_EH_RESOURCE_CREATED, // 2.01
+    OC_EH_RESOURCE_DELETED, // 2.02
+    OC_EH_SLOW, // 2.05
+    OC_EH_FORBIDDEN, // 4.03
+    OC_EH_RESOURCE_NOT_FOUND, // 4.04
+    OC_EH_VALID,   // 2.03
+    OC_EH_CHANGED, // 2.04
+    OC_EH_CONTENT, // 2.05
+    OC_EH_BAD_REQ, // 4.00
+    OC_EH_UNAUTHORIZED_REQ, // 4.01
+    OC_EH_BAD_OPT, // 4.02
+    OC_EH_METHOD_NOT_ALLOWED, // 4.05
+    OC_EH_NOT_ACCEPTABLE, // 4.06
+    OC_EH_INTERNAL_SERVER_ERROR, // 5.00
+    OC_EH_RETRANSMIT_TIMEOUT // 5.04
 } OCEntityHandlerResult;
 
 /**
index 0526e9d..9ee0395 100644 (file)
@@ -421,49 +421,67 @@ void FindAndDeleteServerRequest(OCServerRequest * serverRequest)
 
 CAResponseResult_t ConvertEHResultToCAResult (OCEntityHandlerResult result, OCMethod method)
 {
-    CAResponseResult_t caResult;
+    CAResponseResult_t caResult = CA_BAD_REQ;
 
     switch (result)
     {
-        case OC_EH_OK:
-           switch (method)
-           {
-               case OC_REST_PUT:
-               case OC_REST_POST:
-                   // This Response Code is like HTTP 204 "No Content" but only used in
-                   // response to POST and PUT requests.
-                   caResult = CA_CHANGED;
-                   break;
-               case OC_REST_GET:
-                   // This Response Code is like HTTP 200 "OK" but only used in response to
-                   // GET requests.
-                   caResult = CA_CONTENT;
-                   break;
-               default:
-                   // This should not happen but,
-                   // give it a value just in case but output an error
-                   caResult = CA_CONTENT;
-                   OIC_LOG_V(ERROR, TAG, "Unexpected OC_EH_OK return code for method [%d].", method);
-           }
+        // Successful Client Request
+        case OC_EH_RESOURCE_CREATED: // 2.01
+            if (method == OC_REST_POST || method == OC_REST_PUT)
+            {
+                caResult = CA_CREATED;
+            }
             break;
-        case OC_EH_ERROR:
-            caResult = CA_BAD_REQ;
+        case OC_EH_RESOURCE_DELETED: // 2.02
+            if (method == OC_REST_POST || method == OC_REST_DELETE)
+            {
+                caResult = CA_DELETED;
+            }
             break;
-        case OC_EH_RESOURCE_CREATED:
-            caResult = CA_CREATED;
+        case OC_EH_SLOW: // 2.05
+            caResult = CA_CONTENT;
+            break;
+        case OC_EH_OK: // 2.04/2.05
+            if (method == OC_REST_POST || method == OC_REST_PUT)
+            {
+                caResult = CA_CHANGED;
+            }
+            else if (method == OC_REST_GET)
+            {
+                caResult = CA_CONTENT;
+            }
             break;
-        case OC_EH_RESOURCE_DELETED:
-            caResult = CA_DELETED;
+        case OC_EH_VALID: // 2.03
+            caResult = CA_VALID;
             break;
-        case OC_EH_SLOW:
-            caResult = CA_CONTENT;
+        case OC_EH_CHANGED: // 2.04
+            caResult = CA_CHANGED;
             break;
-        case OC_EH_FORBIDDEN:
+        // Unsuccessful Client Request
+        case OC_EH_UNAUTHORIZED_REQ: // 4.01
             caResult = CA_UNAUTHORIZED_REQ;
             break;
-        case OC_EH_RESOURCE_NOT_FOUND:
+        case OC_EH_BAD_OPT: // 4.02
+            caResult = CA_BAD_OPT;
+            break;
+        case OC_EH_FORBIDDEN: // 4.03
+            caResult = CA_FORBIDDEN_REQ;
+            break;
+        case OC_EH_RESOURCE_NOT_FOUND: // 4.04
             caResult = CA_NOT_FOUND;
             break;
+        case OC_EH_METHOD_NOT_ALLOWED: // 4.05
+            caResult = CA_METHOD_NOT_ALLOWED;
+            break;
+        case OC_EH_NOT_ACCEPTABLE: // 4.06
+            caResult = CA_NOT_ACCEPTABLE;
+            break;
+        case OC_EH_INTERNAL_SERVER_ERROR: // 5.00
+            caResult = CA_INTERNAL_SERVER_ERROR;
+            break;
+        case OC_EH_RETRANSMIT_TIMEOUT: // 5.04
+            caResult = CA_RETRANSMIT_TIMEOUT;
+            break;
         default:
             caResult = CA_BAD_REQ;
             break;
@@ -756,7 +774,6 @@ OCStackResult HandleAggregateResponse(OCEntityHandlerResponse * ehResponse)
                     (OCRepPayload*)newPayload);
         }
 
-
         (serverRequest->numResponses)--;
 
         if(serverRequest->numResponses == 0)
@@ -777,4 +794,3 @@ OCStackResult HandleAggregateResponse(OCEntityHandlerResponse * ehResponse)
 exit:
     return stackRet;
 }
-
index 3b9e711..ca6a9f1 100644 (file)
@@ -37,6 +37,12 @@ namespace OCResourceResponseTest
         int setCode = 200;
         EXPECT_NO_THROW(response.setErrorCode(setCode));
         EXPECT_EQ(setCode, response.getErrorCode());
+        setCode = 500;
+        EXPECT_NO_THROW(response.setErrorCode(setCode));
+        EXPECT_EQ(setCode, response.getErrorCode());
+        setCode = 400;
+        EXPECT_NO_THROW(response.setErrorCode(setCode));
+        EXPECT_EQ(setCode, response.getErrorCode());
     }
 
     TEST(NewResourceUriTest, SetGetNewResourceUriValidUri)