Fix issue with multicast prescence subscriptions
authorMandeep Shetty <mandeep.shetty@intel.com>
Tue, 21 Apr 2015 23:19:40 +0000 (16:19 -0700)
committerUze Choi <uzchoi@samsung.com>
Wed, 22 Apr 2015 12:48:40 +0000 (12:48 +0000)
After registering for a multicast presence, the callback handler URI,
that is searched for isn't completley formed, so callbacks don't happen.

Made uri format consistent across unicast and multicast.
Updated C++ sample app presenceclient.cpp for multicast presence cases.
Also removed repeat test case in presenceclient.cpp PrintUsage().
Updated 2 files in the service directory for multicast presence cases.
Added test in C sample occlient.cpp for a multicast presence
subscription.
Modified OCPlatform.h::subscribePresence() documentation to inform api
users of the expected format.

Change-Id: Ic1a262566f605dd0882e563b4ee2d03bd21016be
Signed-off-by: Charlie Lenahan <charlie.lenahan@intel.com>
Signed-off-by: Mandeep Shetty <mandeep.shetty@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/787
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Sashi Penta <sashi.kumar.penta@intel.com>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
Tested-by: Uze Choi <uzchoi@samsung.com>
resource/csdk/stack/samples/linux/SimpleClientServer/occlient.cpp
resource/csdk/stack/samples/linux/SimpleClientServer/occlient.h
resource/csdk/stack/src/ocstack.c
resource/examples/presenceclient.cpp
resource/include/OCPlatform.h
service/notification-manager/NotificationManager/src/hosting.c
service/soft-sensor-manager/SSMCore/src/SensorProcessor/ResourceFinder.cpp

index ec5f88b..cc473d0 100644 (file)
@@ -95,13 +95,14 @@ static void PrintUsage()
             "filter");
     OC_LOG(INFO, TAG, "-t 14 :  Discover Resources and Initiate Nonconfirmable presence with "\
             "2 filters");
+    OC_LOG(INFO, TAG, "-t 15 :  Discover Resources and Initiate Nonconfirmable multicast presence.");
 #endif
 
-    OC_LOG(INFO, TAG, "-t 15 :  Discover Resources and Initiate Nonconfirmable Observe Requests "\
+    OC_LOG(INFO, TAG, "-t 16 :  Discover Resources and Initiate Nonconfirmable Observe Requests "\
             "then cancel immediately with High QOS");
-    OC_LOG(INFO, TAG, "-t 16 :  Discover Resources and Initiate Nonconfirmable Get Request and "\
+    OC_LOG(INFO, TAG, "-t 17 :  Discover Resources and Initiate Nonconfirmable Get Request and "\
             "add  vendor specific header options");
-    OC_LOG(INFO, TAG, "-t 17 :  Discover Devices");
+    OC_LOG(INFO, TAG, "-t 18 :  Discover Devices");
 }
 
 OCStackResult InvokeOCDoResource(std::ostringstream &query,
@@ -395,6 +396,7 @@ OCStackApplicationResult discoveryReqCB(void* ctx, OCDoHandle handle,
             case TEST_OBS_PRESENCE:
             case TEST_OBS_PRESENCE_WITH_FILTER:
             case TEST_OBS_PRESENCE_WITH_FILTERS:
+            case TEST_OBS_MULTICAST_PRESENCE:
                 InitPresence();
                 break;
 #endif
@@ -468,6 +470,17 @@ int InitPresence()
                     presenceCB, NULL, 0);
         }
     }
+    if(TEST_CASE == TEST_OBS_MULTICAST_PRESENCE)
+    {
+        if(result == OC_STACK_OK)
+        {
+            std::ostringstream multicastPresenceQuery;
+            multicastPresenceQuery.str("");
+            multicastPresenceQuery << "coap://" << OC_MULTICAST_PREFIX << OC_PRESENCE_URI;
+            result = InvokeOCDoResource(multicastPresenceQuery, OC_REST_PRESENCE, OC_LOW_QOS,
+                    presenceCB, NULL, 0);
+        }
+    }
     return result;
 }
 #endif
index c37ac29..0b2b8b8 100644 (file)
@@ -56,6 +56,7 @@ typedef enum {
     TEST_OBS_PRESENCE,
     TEST_OBS_PRESENCE_WITH_FILTER,
     TEST_OBS_PRESENCE_WITH_FILTERS,
+    TEST_OBS_MULTICAST_PRESENCE,
 #endif
     TEST_OBS_REQ_NON_CANCEL_IMM,
     TEST_GET_REQ_NON_WITH_VENDOR_HEADER_OPTIONS,
index 39bc5a5..f8b1787 100644 (file)
@@ -857,7 +857,8 @@ static OCStackResult HandlePresenceResponse(const CARemoteEndpoint_t* endPoint,
     }
     else
     {
-        snprintf(fullUri, MAX_URI_LENGTH, "%s%s", OC_MULTICAST_IP, endPoint->resourceUri);
+        snprintf(fullUri, MAX_URI_LENGTH, "coap://%s:%u%s", OC_MULTICAST_IP, OC_MULTICAST_PORT,
+                                                endPoint->resourceUri);
         cbNode = GetClientCB(NULL, 0, NULL, fullUri);
         if(cbNode)
         {
index 18d1bee..968ffa5 100644 (file)
@@ -63,11 +63,6 @@ void printUsage()
               << std::endl;
     std::cout << "-t 6 : Discover Resources and Initiate Multicast Presence with two Filters"
             << std::endl;
-    std::cout << "-t 4 : Discover Resources and Initiate Multicast Presence" << std::endl;
-    std::cout << "-t 5 : Discover Resources and Initiate Multicast Presence with Filter"
-              << std::endl;
-    std::cout << "-t 6 : Discover Resources and Initiate Multicast Presence with two Filters"
-                  << std::endl;
     std::cout<<"ConnectivityType: Default WIFI" << std::endl;
     std::cout << "-c 0 : Send message over ETHERNET interface" << std::endl;
     std::cout << "-c 1 : Send message over WIFI interface" << std::endl;
@@ -279,10 +274,13 @@ int main(int argc, char* argv[]) {
         OCPlatform::OCPresenceHandle presenceHandle = nullptr;
         OCStackResult result = OC_STACK_OK;
 
+        std::ostringstream multicastPresenceURI;
+        multicastPresenceURI << "coap://" << OC_MULTICAST_PREFIX;
+
         if(TEST_CASE == TEST_MULTICAST_PRESENCE_NORMAL)
         {
             result = OCPlatform::subscribePresence(presenceHandle,
-                    OC_MULTICAST_IP, connectivityType, presenceHandler);
+                    multicastPresenceURI.str(), connectivityType, presenceHandler);
 
             if(result == OC_STACK_OK)
             {
@@ -295,7 +293,7 @@ int main(int argc, char* argv[]) {
         }
         else if(TEST_CASE == TEST_MULTICAST_PRESENCE_WITH_FILTER)
         {
-            result = OCPlatform::subscribePresence(presenceHandle, OC_MULTICAST_IP, "core.light",
+            result = OCPlatform::subscribePresence(presenceHandle, multicastPresenceURI.str(), "core.light",
                     connectivityType, &presenceHandler);
             if(result == OC_STACK_OK)
             {
@@ -309,7 +307,7 @@ int main(int argc, char* argv[]) {
         }
         else if(TEST_CASE == TEST_MULTICAST_PRESENCE_WITH_FILTERS)
         {
-            result = OCPlatform::subscribePresence(presenceHandle, OC_MULTICAST_IP, "core.light",
+            result = OCPlatform::subscribePresence(presenceHandle, multicastPresenceURI.str(), "core.light",
                     connectivityType, &presenceHandler);
             if(result == OC_STACK_OK)
             {
@@ -321,7 +319,7 @@ int main(int argc, char* argv[]) {
             }
             std::cout << "\"core.light\"." << std::endl;
 
-            result = OCPlatform::subscribePresence(presenceHandle, OC_MULTICAST_IP, "core.fan",
+            result = OCPlatform::subscribePresence(presenceHandle, multicastPresenceURI.str(), "core.fan",
                     connectivityType, &presenceHandler);
             if(result == OC_STACK_OK)
             {
index 4d17d9d..d894295 100644 (file)
@@ -380,6 +380,7 @@ namespace OC
         *               request.  It can be used to unsubscribe from these events in the future.
         *               It will be set upon successful return of this method.
         * @param host - The IP address/addressable name of the server to subscribe to.
+        *               This should be in the format coap://address:port
         * @param connectivityType - @ref OCConnectivityType type of connectivity indicating the
         *                           interface. Example: OC_WIFI, OC_ETHERNET, OC_ALL
         * @param resourceType - a resource type specified as a filter for subscription callbacks.
index d3cc3b9..e7531b7 100755 (executable)
@@ -351,7 +351,7 @@ OCStackResult OICStartCoordinate()
 
     s_mirrorResourceList = createMirrorResourceList();
     s_requestHandleList = createRequestHandleList();
-    result = requestPresence(OC_DEFAULT_ADDRESS);
+    result = requestPresence(OC_MULTICAST_PREFIX);
     if(result != OC_STACK_OK)
     {
         return OC_STACK_ERROR;
@@ -422,7 +422,7 @@ OCStackResult requestPresence(char *sourceResourceAddress)
     cbData.cd = NULL;
 
     char queryUri[OIC_STRING_MAX_VALUE] = { '\0' };
-    sprintf(queryUri, "%s%s", sourceResourceAddress , OC_PRESENCE_URI);
+    sprintf(queryUri, "coap://%s%s", sourceResourceAddress , OC_PRESENCE_URI);
     OC_LOG_V(DEBUG, HOSTING_TAG, "initializePresenceForCoordinating Query : %s", queryUri);
 
     result = OCDoResource(&handle, OC_REST_PRESENCE, queryUri, 0, 0, OC_ETHERNET, OC_LOW_QOS, &cbData, NULL, 0);
index 48ba5d0..c44d242 100644 (file)
@@ -130,6 +130,9 @@ SSMRESULT CResourceFinder::startResourceFinder()
     std::ostringstream requestURI;
     requestURI << OC_WELL_KNOWN_QUERY << "?rt=SSManager.Sensor";
 
+    std::ostringstream multicastPresenceURI;
+    multicastPresenceURI << "coap://" << OC_MULTICAST_PREFIX;
+
     ret = OC::OCPlatform::findResource("", requestURI.str(), OC_WIFI,
                                        std::bind(&CResourceFinder::onResourceFound, this, std::placeholders::_1));
 
@@ -142,14 +145,14 @@ SSMRESULT CResourceFinder::startResourceFinder()
     if (ret != OC_STACK_OK)
         SSM_CLEANUP_ASSERT(SSM_E_FAIL);
 
-    ret = OC::OCPlatform::subscribePresence(m_multicastPresenceHandle, OC_MULTICAST_IP,
+    ret = OC::OCPlatform::subscribePresence(m_multicastPresenceHandle, multicastPresenceURI.str(),
                                             "SSManager.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);
 
-    ret = OC::OCPlatform::subscribePresence(m_multicastPresenceHandle, OC_MULTICAST_IP,
+    ret = OC::OCPlatform::subscribePresence(m_multicastPresenceHandle, multicastPresenceURI.str(),
                                             "SSManager.Sensor", OC_ETHERNET, std::bind(&CResourceFinder::presenceHandler, this,
                                                     std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));