[IOT-2912] cpp provisioning 65/23565/6
authorOleksandr Dmytrenko <o.dmytrenko@samsung.com>
Thu, 30 Nov 2017 16:42:02 +0000 (18:42 +0200)
committerRandeep Singh <randeep.s@samsung.com>
Tue, 2 Jan 2018 05:44:52 +0000 (05:44 +0000)
cpp provisioning refactoing

Bug: https://jira.iotivity.org/browse/IOT-2912
Change-Id: Ic80a6a9df54d1f6930ea779ad0a95dcd5b843c1c
Signed-off-by: Oleksandr Dmytrenko <o.dmytrenko@samsung.com>
java/jni/JniOcProvisioning.cpp
resource/include/OCProvisioningManager.hpp
resource/provisioning/examples/provisioningclient.cpp
resource/provisioning/src/OCProvisioningManager.cpp

index 6b58ed9..25bef26 100644 (file)
@@ -335,7 +335,8 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcProvisioning_setDisplayNumListen
 
     try
     {
-        OCStackResult result = OCSecure::registerDisplayNumCallback(displayMutualVerifNumCB);
+        OC::DisplayNumContext *displayNumContext = new OC::DisplayNumContext(displayMutualVerifNumCB);
+        OCStackResult result = OCSecure::registerDisplayNumCallback(displayNumContext);
         if (OC_STACK_OK != result)
         {
             ThrowOcException(result, "Failed to set Listner");
@@ -420,7 +421,8 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcProvisioning_setConfirmNumListen
 
     try
     {
-        OCStackResult result = OCSecure::registerUserConfirmCallback(confirmMutualVerifNumCB);
+        OC::UserConfirmNumContext* userConfirmNumContext = new OC::UserConfirmNumContext(confirmMutualVerifNumCB);
+        OCStackResult result = OCSecure::registerUserConfirmCallback(userConfirmNumContext);
         if (OC_STACK_OK != result)
         {
             ThrowOcException(result, "Failed to set Listner");
index 9cca654..bbcee44 100644 (file)
@@ -468,7 +468,7 @@ namespace OC
              * @param displayNumCB Callback which is to be registered.
              * @return  OC_STACK_OK in case of success and other value otherwise.
              */
-            static OCStackResult registerDisplayNumCallback(DisplayNumCB displayNumCB);
+            static OCStackResult registerDisplayNumCallback(void *ctx);
 
              /**
              * API to De-register Callback for displaying verifNum in verification Just-Works
@@ -482,7 +482,7 @@ namespace OC
              *@param userConfirmCB Callback which is to be registered.
              * @return  OC_STACK_OK in case of success and other value otherwise.
              */
-            static OCStackResult registerUserConfirmCallback(UserConfirmNumCB userConfirmCB);
+            static OCStackResult registerUserConfirmCallback(void* ctx);
 
              /**
              * API to De-register Callback for getting user confirmation in verification Just-Works
index 0cd2671..65b4c51 100644 (file)
@@ -769,13 +769,15 @@ int main(void)
             std::cout << "!!Error - registerInputPinCallback failed." << std::endl;
         }
 
-        result = OCSecure::registerDisplayNumCallback(displayMutualVerifNumCB);
+        OC::DisplayNumContext *displayNumContext = new OC::DisplayNumContext(displayMutualVerifNumCB);
+        result = OCSecure::registerDisplayNumCallback(displayNumContext);
         if (result != OC_STACK_OK)
         {
             std::cout<< "!!Error - setDisplayVerifNumCB failed."<<std::endl;
         }
 
-        result = OCSecure::registerUserConfirmCallback(confirmMutualVerifNumCB);
+        OC::UserConfirmNumContext* userConfirmNumContext = new OC::UserConfirmNumContext(confirmMutualVerifNumCB);
+        result = OCSecure::registerUserConfirmCallback(userConfirmNumContext);
         if (result != OC_STACK_OK)
         {
             std::cout<< "!!Error - setConfirmVerifNumCB failed."<<std::endl;
index 5dfb632..cbd1cce 100644 (file)
@@ -837,11 +837,11 @@ namespace OC
         return res;
     }
 
-    OCStackResult OCSecure::registerDisplayNumCallback(DisplayNumCB displayNumCB)
+    OCStackResult OCSecure::registerDisplayNumCallback(void *ctx)
     {
-        if(!displayNumCB)
+        if(!ctx)
         {
-            oclog() << "Failed to register callback for display.";
+            oclog() << "Failed set context";
             return OC_STACK_INVALID_CALLBACK;
         }
 
@@ -855,9 +855,8 @@ namespace OC
         auto cLock = OCPlatform_impl::Instance().csdkLock().lock();
         if (cLock)
         {
-            DisplayNumContext* context = new DisplayNumContext(displayNumCB);
             std::lock_guard<std::recursive_mutex> lock(*cLock);
-            SetDisplayNumCB(static_cast<void*>(context), &OCSecure::displayNumCallbackWrapper);
+            SetDisplayNumCB(ctx, &OCSecure::displayNumCallbackWrapper);
             result = OC_STACK_OK;
         }
         else
@@ -906,11 +905,11 @@ namespace OC
         return res;
     }
 
-    OCStackResult OCSecure::registerUserConfirmCallback(UserConfirmNumCB userConfirmCB)
+    OCStackResult OCSecure::registerUserConfirmCallback(void* ctx)
     {
-        if(!userConfirmCB)
+        if(!ctx)
         {
-            oclog() << "Failed to set callback for confirming verifying callback.";
+            oclog() << "Failed to set context";
             return OC_STACK_INVALID_CALLBACK;
         }
 
@@ -924,9 +923,8 @@ namespace OC
         auto cLock = OCPlatform_impl::Instance().csdkLock().lock();
         if (cLock)
         {
-            UserConfirmNumContext* context = new UserConfirmNumContext(userConfirmCB);
             std::lock_guard<std::recursive_mutex> lock(*cLock);
-            SetUserConfirmCB(static_cast<void*>(context), &OCSecure::confirmUserCallbackWrapper);
+            SetUserConfirmCB(ctx, &OCSecure::confirmUserCallbackWrapper);
             result = OC_STACK_OK;
         }
         else