Update a condition to decide if ownership transfer succeeds in easy setup
authorJihun Ha <jihun.ha@samsung.com>
Fri, 30 Dec 2016 05:22:14 +0000 (14:22 +0900)
committerUze Choi <uzchoi@samsung.com>
Fri, 30 Dec 2016 07:52:50 +0000 (07:52 +0000)
In a case of duplicate request of ownership transfer, PM result and hasError are
returned to OC_STACK_DUPLICATE_REQUEST and 0(false). This case should be
considered as one of error cases.

Change-Id: I660d2985c6b661fd4366e68fa76c5a8e3e939e2e
Signed-off-by: Jihun Ha <jihun.ha@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/16023
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
service/easy-setup/mediator/richsdk/src/EnrolleeSecurity.cpp

index a2d28cc..165939f 100755 (executable)
@@ -195,6 +195,9 @@ namespace OIC
         void EnrolleeSecurity::MultipleOwnershipTransferCb(OC::PMResultList_t *result, int hasError)
         {
             OIC_LOG(DEBUG, ENROLEE_SECURITY_TAG, "MultipleOwnershipTransferCb IN");
+
+            OTMResult = false;
+
             if (hasError)
             {
                 OIC_LOG_V(ERROR, ENROLEE_SECURITY_TAG, "MultipleOwnershipTransferCb is failed with code(%d)", hasError);
@@ -203,14 +206,27 @@ namespace OIC
             }
             else
             {
-                OIC_LOG(DEBUG, ENROLEE_SECURITY_TAG, "MultipleOwnershipTransfer is succeeded");
                 for (unsigned int i = 0; i < result->size(); i++)
                 {
-                    OIC_LOG_V(DEBUG, ENROLEE_SECURITY_TAG, "Result is = %d for device", result->at(i).res);
-                }
+                    std::string uuid;
+                    convertUUIDToString(result->at(i).deviceId.id, uuid);
 
+                    if(m_ocResource != NULL && m_ocResource->sid() == uuid)
+                    {
+                        if( OC_STACK_OK == result->at(i).res )
+                        {
+                            OIC_LOG(DEBUG, ENROLEE_SECURITY_TAG, "MultipleOwnershipTransferCb is succeeded");
+                            OIC_LOG_V(DEBUG, ENROLEE_SECURITY_TAG, "Result is = %d for device %s", result->at(i).res, uuid.c_str());
+                            OTMResult = true;
+                        }
+                        else
+                        {
+                            OIC_LOG_V(ERROR, ENROLEE_SECURITY_TAG, "OwnershipTransfer is failed with code(%d)", hasError);
+                            OTMResult = false;
+                        }
+                    }
+                }
                 delete result;
-                OTMResult = true;
                 m_cond.notify_all();
             }
         }
@@ -219,6 +235,9 @@ namespace OIC
         void EnrolleeSecurity::ownershipTransferCb(OC::PMResultList_t *result, int hasError)
         {
             OIC_LOG(DEBUG, ENROLEE_SECURITY_TAG, "ownershipTransferCb IN");
+
+            OTMResult = false;
+
             if (hasError)
             {
                 OIC_LOG_V(ERROR, ENROLEE_SECURITY_TAG, "OwnershipTransfer is failed with code(%d)", hasError);
@@ -226,12 +245,26 @@ namespace OIC
             }
             else
             {
-                OIC_LOG(DEBUG, ENROLEE_SECURITY_TAG, "OwnershipTransfer is succeeded");
                 for (unsigned int i = 0; i < result->size(); i++)
                 {
-                    OIC_LOG_V(DEBUG, ENROLEE_SECURITY_TAG, "Result is = %d for device", result->at(i).res);
+                    std::string uuid;
+                    convertUUIDToString(result->at(i).deviceId.id, uuid);
+
+                    if(m_ocResource != NULL && m_ocResource->sid() == uuid)
+                    {
+                        if( OC_STACK_OK == result->at(i).res )
+                        {
+                            OIC_LOG(DEBUG, ENROLEE_SECURITY_TAG, "OwnershipTransfer is succeeded");
+                            OIC_LOG_V(DEBUG, ENROLEE_SECURITY_TAG, "Result is = %d for device %s", result->at(i).res, uuid.c_str());
+                            OTMResult = true;
+                        }
+                        else
+                        {
+                            OIC_LOG_V(ERROR, ENROLEE_SECURITY_TAG, "OwnershipTransfer is failed with code(%d)", hasError);
+                            OTMResult = false;
+                        }
+                    }
                 }
-                OTMResult = true;
             }
 
             delete result;