Add Set display pin callback method for server to display
authorAshwini Kumar <k.ashwini@samsung.com>
Thu, 24 Sep 2015 12:06:33 +0000 (17:36 +0530)
committerSachin Agrawal <sachin.agrawal@intel.com>
Thu, 1 Oct 2015 23:49:50 +0000 (23:49 +0000)
PIN for RANDOM_PIN provisioning

Note: this change can be picked for 1.0.0-dev

Change-Id: I7fc9b2ff66205c27fc6f41ebc0cadb4cd592abab
Signed-off-by: Ashwini Kumar <k.ashwini@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/3047
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Sachin Agrawal <sachin.agrawal@intel.com>
resource/include/OCProvisioningManager.h
resource/provisioning/src/OCProvisioningManager.cpp
resource/provisioning/unittests/OCProvisioningTest.cpp

index 5c63ace..adecd89 100644 (file)
@@ -147,7 +147,13 @@ namespace OC
             static OCStackResult getDevInfoFromNetwork(unsigned short timeout,
                     DeviceList_t &ownedDevList,
                     DeviceList_t &unownedDevList);
-
+            /**
+             * Server API to register callback to display stack generated PIN.
+             *
+             * @param[in] GeneratePinCallback Method to display generated PIN.
+             * @return OC_STACK_OK in case of success and other value otherwise.
+             */
+            static OCStackResult setDisplayPinCB(GeneratePinCallback);
     };
 
     /**
index 25c5fd0..8040a99 100644 (file)
@@ -204,6 +204,31 @@ namespace OC
         return result;
     }
 
+    OCStackResult OCSecure::setDisplayPinCB(GeneratePinCallback displayPin)
+    {
+        if(!displayPin)
+        {
+            oclog() <<"displayPin can't be null";
+            return OC_STACK_INVALID_PARAM;
+        }
+
+        OCStackResult result = OC_STACK_OK;
+        auto cLock = OCPlatform_impl::Instance().csdkLock().lock();
+
+        if(cLock)
+        {
+            std::lock_guard<std::recursive_mutex> lock(*cLock);
+            SetGeneratePinCB(displayPin);
+        }
+        else
+        {
+            oclog() <<"Mutex not found";
+            result = OC_STACK_ERROR;
+        }
+
+        return result;
+    }
+
     void OCSecureResource::callbackWrapper(void* ctx, int nOfRes, OCProvisionResult_t *arr, bool hasError)
     {
         PMResultList_t *results = nullptr;
index 6d3c5da..cbbc9bc 100644 (file)
@@ -129,6 +129,11 @@ namespace OCProvisioningTest
                     owned, unowned));
     }
 
+    TEST(SetDisplayPinCBTest, SetDisplayPinCBTestNullCB)
+    {
+        EXPECT_EQ(OC_STACK_INVALID_PARAM, OCSecure::setDisplayPinCB(nullptr));
+    }
+
     TEST(ProvisionAclTest, ProvisionAclTestNullAcl)
     {
         OCSecureResource device;