From c98c653ca4aeab2e0a359041468795c2d3860cf8 Mon Sep 17 00:00:00 2001 From: Ashwini Kumar Date: Thu, 24 Sep 2015 17:36:33 +0530 Subject: [PATCH] Add Set display pin callback method for server to display PIN for RANDOM_PIN provisioning Note: this change can be picked for 1.0.0-dev Change-Id: I7fc9b2ff66205c27fc6f41ebc0cadb4cd592abab Signed-off-by: Ashwini Kumar Reviewed-on: https://gerrit.iotivity.org/gerrit/3047 Tested-by: jenkins-iotivity Reviewed-by: Sachin Agrawal --- resource/include/OCProvisioningManager.h | 8 ++++++- .../provisioning/src/OCProvisioningManager.cpp | 25 ++++++++++++++++++++++ .../provisioning/unittests/OCProvisioningTest.cpp | 5 +++++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/resource/include/OCProvisioningManager.h b/resource/include/OCProvisioningManager.h index 5c63ace..adecd89 100644 --- a/resource/include/OCProvisioningManager.h +++ b/resource/include/OCProvisioningManager.h @@ -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); }; /** diff --git a/resource/provisioning/src/OCProvisioningManager.cpp b/resource/provisioning/src/OCProvisioningManager.cpp index 25c5fd0..8040a99 100644 --- a/resource/provisioning/src/OCProvisioningManager.cpp +++ b/resource/provisioning/src/OCProvisioningManager.cpp @@ -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 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; diff --git a/resource/provisioning/unittests/OCProvisioningTest.cpp b/resource/provisioning/unittests/OCProvisioningTest.cpp index 6d3c5da..cbbc9bc 100644 --- a/resource/provisioning/unittests/OCProvisioningTest.cpp +++ b/resource/provisioning/unittests/OCProvisioningTest.cpp @@ -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; -- 2.7.4