Update IPCA to use new OCPlatform::start/stop().
authorSoemin Tjong <stjong@microsoft.com>
Wed, 29 Mar 2017 00:49:30 +0000 (17:49 -0700)
committerDan Mihai <Daniel.Mihai@microsoft.com>
Thu, 6 Apr 2017 13:03:02 +0000 (13:03 +0000)
https://jira.iotivity.org/browse/IOT-1966

This allows the IoTivity stack to shut down gracefully after
applications call IPCAClose().

Change-Id: Ie800577f157e4ce2a6b7086495501cda8fe133d4
Signed-off-by: Soemin Tjong <stjong@microsoft.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/18379
Tested-by: jenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: Dan Mihai <Daniel.Mihai@microsoft.com>
resource/IPCA/src/callback.cpp
resource/IPCA/src/ocfframework.cpp
resource/IPCA/unittests/mockOC.cpp

index 9414123..cf78c3a 100644 (file)
@@ -412,6 +412,7 @@ void Callback::CompleteAndRemoveExpiredCallbackInfo(std::vector<CallbackInfo::Pt
             // RemoveCallbackInfo().
             if (entry.second->markedToBeRemoved == true)
             {
+                m_expiredCallbacksInprogress++;
                 cbInfoList.push_back(entry.second);
                 continue;
             }
@@ -481,7 +482,7 @@ void Callback::CompleteAndRemoveExpiredCallbackInfo(std::vector<CallbackInfo::Pt
                     break;
 
                 default:
-                    assert(false); // check the filter code above to match the handling here.
+                    // The rest of the callback types are nop.
                     break;
             }
         }
index 643229e..b979a0d 100644 (file)
@@ -206,17 +206,20 @@ IPCAStatus OCFFramework::Start(const IPCAAppInfoInternal& appInfo, bool isUnitTe
     PlatformConfig Configuration {
                         ServiceType::InProc,
                         ModeType::Both,  // Server mode is required for security provisioning.
-                        "0.0.0.0", // By setting to "0.0.0.0", it binds to all available interfaces
-                        0,         // Uses randomly available port
-                        QualityOfService::NaQos,
                         &ps};
 
     OCPlatform::Configure(Configuration);
 
+    if (OCPlatform::start() != OC_STACK_OK)
+    {
+        OIC_LOG(FATAL, TAG, "Failed OCPlatform::start()");
+        return IPCA_FAIL;
+    }
+
     // Initialize the database that will be used for provisioning
     if (OCSecure::provisionInit("") != OC_STACK_OK)
     {
-        OIC_LOG_V(FATAL, TAG, "Failed provisionInit()");
+        OIC_LOG(FATAL, TAG, "Failed provisionInit()");
         return IPCA_FAIL;
     }
 
@@ -298,12 +301,14 @@ IPCAStatus OCFFramework::Start(const IPCAAppInfoInternal& appInfo, bool isUnitTe
 IPCAStatus OCFFramework::Stop(InputPinCallbackHandle passwordInputCallbackHandle,
                               DisplayPinCallbackHandle passwordDisplayCallbackHandle)
 {
+    IPCAStatus status = IPCA_OK;
+
     std::lock_guard<std::mutex> lock(m_startStopMutex);
 
     if (m_isStarted == false)
     {
         // not started yet.
-        return IPCA_OK;
+        return status;
     }
 
     CleanupRequestAccessDevices();
@@ -311,7 +316,6 @@ IPCAStatus OCFFramework::Stop(InputPinCallbackHandle passwordInputCallbackHandle
     OCSecure::deregisterInputPinCallback(passwordInputCallbackHandle);
     OCSecure::deregisterDisplayPinCallback(passwordDisplayCallbackHandle);
 
-
     m_isStopping = true;
 
     m_workerThreadCV.notify_all();
@@ -320,17 +324,21 @@ IPCAStatus OCFFramework::Stop(InputPinCallbackHandle passwordInputCallbackHandle
         m_workerThread.join();
     }
 
-// @future: OCFFramework can't shut down because there's no cancellation for all underlying apis
-// like OCPlatform::findResource, etc.
-#if 0
+    if (OCPlatform::stop() != OC_STACK_OK)
+    {
+        assert(false);
+        status = IPCA_FAIL;
+        OIC_LOG(ERROR, TAG, "Failed OCPlatform::stop()");
+    }
+
+    std::lock_guard<std::recursive_mutex> ocfFrameworkLock(m_OCFFrameworkMutex);
     m_OCFDevices.clear();
     m_OCFDevicesIndexedByDeviceURI.clear();
-#endif
 
     m_isStopping = false;
     m_isStarted = false;
 
-    return IPCA_OK;
+    return status;
 }
 
 void OCFFramework::WorkerThread(OCFFramework* ocfFramework)
index 349331f..e94a6da 100644 (file)
@@ -133,6 +133,16 @@ void OCPlatform::Configure(const PlatformConfig& config)
     g_platformConfig = config;\r
 }\r
 \r
+OCStackResult OCPlatform::start()\r
+{\r
+    return OC_STACK_OK;\r
+}\r
+\r
+OCStackResult OCPlatform::stop()\r
+{\r
+    return OC_STACK_OK;\r
+}\r
+\r
 OCStackResult OCPlatform::setPropertyValue(OCPayloadType type, const std::string& tag,\r
                                        const std::string& value)\r
 {\r