Soft Sensor Manager - Apply changed C.A. API
authorMinji Park <minjii.park@samsung.com>
Thu, 2 Apr 2015 09:07:01 +0000 (18:07 +0900)
committerUze Choi <uzchoi@samsung.com>
Mon, 6 Apr 2015 11:10:02 +0000 (11:10 +0000)
Modify ResourceFinder to find resources and check presence status with connectivity type options

Change-Id: Ieeab82369f40c05ec0cae68f6395cd9a8e415cf7
Signed-off-by: Minji Park <minjii.park@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/633
Reviewed-by: Uze Choi <uzchoi@samsung.com>
Tested-by: Uze Choi <uzchoi@samsung.com>
service/soft-sensor-manager/SSMCore/src/SensorProcessor/ResourceFinder.cpp

index 569d58d..206e967 100644 (file)
@@ -72,11 +72,21 @@ void CResourceFinder::presenceHandler(OCStackResult result, const unsigned int n
     OCStackResult ret = OC_STACK_ERROR;
     intptr_t *pMessage = NULL;
 
+    std::ostringstream requestURI;
+
     switch (result)
     {
         case OC_STACK_OK:
-            ret = OC::OCPlatform::findResource("",
-                                               "coap://" + hostAddress + ":6298" + "/oc/core?rt=SoftSensorManager.Sensor", OC_ALL,
+            requestURI << "coap://" << hostAddress << ":" << OC_MULTICAST_PORT <<
+                       "/oc/core?rt=SoftSensorManager.Sensor";
+
+            ret = OC::OCPlatform::findResource("", requestURI.str(), OC_ETHERNET,
+                                               std::bind(&CResourceFinder::onResourceFound, this, std::placeholders::_1));
+
+            if (ret != OC_STACK_OK)
+                SSM_CLEANUP_ASSERT(SSM_E_FAIL);
+
+            ret = OC::OCPlatform::findResource("", requestURI.str(), OC_WIFI,
                                                std::bind(&CResourceFinder::onResourceFound, this, std::placeholders::_1));
 
             if (ret != OC_STACK_OK)
@@ -117,17 +127,31 @@ SSMRESULT CResourceFinder::startResourceFinder()
     SSMRESULT res = SSM_E_FAIL;
     OCStackResult ret = OC_STACK_ERROR;
 
-    ret = OC::OCPlatform::findResource("",
-                                       "coap://224.0.1.187:6298/oc/core?rt=SoftSensorManager.Sensor", OC_ALL,
+    std::ostringstream requestURI;
+    requestURI << OC_WELL_KNOWN_QUERY << "?rt=SoftSensorManager.Sensor";
+
+    ret = OC::OCPlatform::findResource("", requestURI.str(), OC_ETHERNET,
+                                       std::bind(&CResourceFinder::onResourceFound, this, std::placeholders::_1));
+
+    if (ret != OC_STACK_OK)
+        SSM_CLEANUP_ASSERT(SSM_E_FAIL);
+
+    ret = OC::OCPlatform::findResource("", requestURI.str(), OC_WIFI,
                                        std::bind(&CResourceFinder::onResourceFound, this, std::placeholders::_1));
 
     if (ret != OC_STACK_OK)
         SSM_CLEANUP_ASSERT(SSM_E_FAIL);
 
-    ret = OC::OCPlatform::subscribePresence(m_multicastPresenceHandle, "coap://224.0.1.187",
-                                            "SoftSensorManager.Sensor", OC_ALL,
-                                            std::bind(&CResourceFinder::presenceHandler, this, std::placeholders::_1,
-                                                    std::placeholders::_2, std::placeholders::_3));
+    ret = OC::OCPlatform::subscribePresence(m_multicastPresenceHandle, OC_MULTICAST_IP,
+                                            "SoftSensorManager.Sensor", OC_ETHERNET, std::bind(&CResourceFinder::presenceHandler, this,
+                                                    std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
+
+    if (ret != OC_STACK_OK)
+        SSM_CLEANUP_ASSERT(SSM_E_FAIL);
+
+    ret = OC::OCPlatform::subscribePresence(m_multicastPresenceHandle, OC_MULTICAST_IP,
+                                            "SoftSensorManager.Sensor", OC_WIFI, std::bind(&CResourceFinder::presenceHandler, this,
+                                                    std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
 
     if (ret != OC_STACK_OK)
         SSM_CLEANUP_ASSERT(SSM_E_FAIL);
@@ -168,13 +192,13 @@ SSMRESULT CResourceFinder::stopObserveResource(IN ISSMResource *pSensor)
 
 void CResourceFinder::onExecute(IN void *pArg)
 {
-    SSMRESULT res = SSM_E_FAIL;
-    OCStackResult ret = OC_STACK_ERROR;
-    OC::QueryParamsMap queryParams;
+    SSMRESULT           res = SSM_E_FAIL;
+    OCStackResult       ret = OC_STACK_ERROR;
+    OC::QueryParamsMap  queryParams;
     OICResourceHandler *pResourceHandler = NULL;
-    intptr_t                 *pMessage =  reinterpret_cast<intptr_t *>(pArg);
+    intptr_t           *pMessage =  reinterpret_cast<intptr_t *>(pArg);
     std::shared_ptr< OC::OCResource > *pResource = NULL;
-    OC::OCPlatform::OCPresenceHandle presenceHandle = NULL;
+    OC::OCPlatform::OCPresenceHandle   presenceHandle = NULL;
 
     std::string resourceHostAddress = "";
     std::string resourceFullPath = "";
@@ -195,9 +219,8 @@ void CResourceFinder::onExecute(IN void *pArg)
 
             m_mapResources[resourceHostAddress].push_back(resourceFullPath);
 
-            ret = pResource->get()->get(queryParams,
-                                        std::bind(&OICResourceHandler::onGetResourceProfile, pResourceHandler,
-                                                  std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
+            ret = pResource->get()->get(queryParams, std::bind(&OICResourceHandler::onGetResourceProfile,
+                                        pResourceHandler, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
 
             if (ret != OC_STACK_OK)
                 SSM_CLEANUP_ASSERT(SSM_E_FAIL);
@@ -209,9 +232,15 @@ void CResourceFinder::onExecute(IN void *pArg)
                 m_mapResourcePresenceHandles.end())
             {
                 ret = OC::OCPlatform::subscribePresence(presenceHandle, ((ISSMResource *)pMessage[1])->ip,
-                                                        "SoftSensorManager.Sensor", OC_ALL,
-                                                        std::bind(&CResourceFinder::presenceHandler, this, std::placeholders::_1,
-                                                                std::placeholders::_2, std::placeholders::_3));
+                                                        "SoftSensorManager.Sensor", OC_ETHERNET, std::bind(&CResourceFinder::presenceHandler, this,
+                                                                std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
+
+                if (ret != OC_STACK_OK)
+                    SSM_CLEANUP_ASSERT(SSM_E_FAIL);
+
+                ret = OC::OCPlatform::subscribePresence(presenceHandle, ((ISSMResource *)pMessage[1])->ip,
+                                                        "SoftSensorManager.Sensor", OC_WIFI, std::bind(&CResourceFinder::presenceHandler, this,
+                                                                std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
 
                 if (ret != OC_STACK_OK)
                     SSM_CLEANUP_ASSERT(SSM_E_FAIL);
@@ -228,8 +257,8 @@ void CResourceFinder::onExecute(IN void *pArg)
             if (m_mapResourcePresenceHandles.find(((OICResourceHandler *)pMessage[1])->m_SSMResource.ip) !=
                 m_mapResourcePresenceHandles.end())
             {
-                ret = OC::OCPlatform::unsubscribePresence(
-                          m_mapResourcePresenceHandles[((OICResourceHandler *)pMessage[1])->m_SSMResource.ip]);
+                ret = OC::OCPlatform::unsubscribePresence(m_mapResourcePresenceHandles[((
+                            OICResourceHandler *)pMessage[1])->m_SSMResource.ip]);
 
                 if (ret != OC_STACK_OK)
                     SSM_CLEANUP_ASSERT(SSM_E_FAIL);
@@ -265,5 +294,4 @@ void CResourceFinder::onTerminate(IN void *pArg)
     }
 
     delete[] pMessage;
-}
-
+}
\ No newline at end of file