Update C++ samples to work after WiFi/Ethernet adapter merge.
authorMandeep Shetty <mandeep.shetty@intel.com>
Mon, 4 May 2015 23:07:46 +0000 (16:07 -0700)
committerErich Keane <erich.keane@intel.com>
Tue, 5 May 2015 15:31:34 +0000 (15:31 +0000)
The merge of ethernet and wifi includes a check in the adapter for whether
a request is going out to a multicast or unicast endpoint.
The decision for whether it is a multicast or unicast request is made on
the basis of whether the group endpoint is set or the remote endpoint.

The C stack creates a group endpoint if the connectivity type is
OC_ALL or a remote endpoint otherwise. But all connectivity types are mapped
to CA_IPV4. To ensure that a group endpoint is created for multicastm the C++
samples should make the findResource() call with OC_ALL.
The new constant is the multicast resource discovery uri

Change-Id: I8933a92a18ec920cf9b4b7dd994a6cbd82cb1c44
Signed-off-by: Mandeep Shetty <mandeep.shetty@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/898
Reviewed-by: Sakthivel Samidurai <sakthivel.samidurai@intel.com>
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Erich Keane <erich.keane@intel.com>
resource/csdk/stack/include/octypes.h
resource/examples/fridgeclient.cpp
resource/examples/garageclient.cpp
resource/examples/groupclient.cpp
resource/examples/groupserver.cpp
resource/examples/presenceclient.cpp
resource/examples/roomclient.cpp
resource/examples/simpleclient.cpp
resource/examples/simpleclientHQ.cpp
resource/examples/simpleclientserver.cpp
resource/examples/threadingsample.cpp

index f7921b7..fceaafb 100644 (file)
@@ -36,6 +36,7 @@ extern "C" {
 
 /// Authority + URI string to prefix well known queries
 #define OC_WELL_KNOWN_QUERY                  "224.0.1.187:5683/oc/core"
+#define OC_MULTICAST_DISCOVERY_URI           "/oc/core"
 #define OC_EXPLICIT_DEVICE_DISCOVERY_URI     "224.0.1.187:5683/oc/core/d?rt=core.led"
 /// Multicast address and port string to prefix multicast queries
 #define OC_MULTICAST_PREFIX                  "224.0.1.187:5683"
index e10758f..db03240 100644 (file)
@@ -45,11 +45,11 @@ class ClientFridge
         m_callsMade(0),m_connectivityType(ct)
     {
         std::ostringstream requestURI;
-        requestURI << OC_WELL_KNOWN_QUERY << "?rt=intel.fridge";
+        requestURI << OC_MULTICAST_DISCOVERY_URI << "?rt=intel.fridge";
         std::cout << "Fridge Client has started " <<std::endl;
         FindCallback f (std::bind(&ClientFridge::foundDevice, this, PH::_1));
         OCStackResult result = OCPlatform::findResource(
-                "", requestURI.str(), m_connectivityType, f);
+                "", requestURI.str(), OC_ALL, f);
 
         if(OC_STACK_OK != result)
         {
index c5900e0..680f3c4 100644 (file)
@@ -344,10 +344,10 @@ int main(int argc, char* argv[]) {
     try
     {
         // Find all resources
-        requestURI << OC_WELL_KNOWN_QUERY << "?rt=core.garage";
+        requestURI << OC_MULTICAST_DISCOVERY_URI << "?rt=core.garage";
 
         OCPlatform::findResource("", requestURI.str(),
-                connectivityType, &foundResource);
+                OC_ALL, &foundResource);
 
         std::cout<< "Finding Resource... " <<std::endl;
 
index be06d61..b154491 100644 (file)
@@ -171,7 +171,7 @@ bool isResourceReady()
 int main(int argc, char* argv[])
 {
     ostringstream requestURI;
-    requestURI << OC_WELL_KNOWN_QUERY << "?rt=a.collection";
+    requestURI << OC_MULTICAST_DISCOVERY_URI << "?rt=a.collection";
 
     OCConnectivityType connectivityType = OC_WIFI;
 
@@ -228,7 +228,7 @@ int main(int argc, char* argv[])
         string resourceTypeName = "a.collection";
 
         OCPlatform::findResource("", requestURI.str(),
-                                 connectivityType, &foundResource);
+                                 OC_ALL, &foundResource);
 
         //Non-intensive block until foundResource callback is called by OCPlatform
         //and onGet gets resource.
index 9c46d10..4bfe8be 100644 (file)
@@ -143,10 +143,10 @@ int main(int argc, char* argv[])
 
         cout << "registerResource is called." << endl;
 
-        requestURI << OC_WELL_KNOWN_QUERY << "?rt=core.light";
+        requestURI << OC_MULTICAST_DISCOVERY_URI << "?rt=core.light";
 
         OCPlatform::findResource("", requestURI.str(),
-                                 connectivityType, &foundResource);
+                                 OC_ALL, &foundResource);
 
         OCPlatform::bindInterfaceToResource(resourceHandle, GROUP_INTERFACE);
         OCPlatform::bindInterfaceToResource(resourceHandle, DEFAULT_INTERFACE);
index 968ffa5..eecabc0 100644 (file)
@@ -334,10 +334,10 @@ int main(int argc, char* argv[]) {
         else
         {
             // Find all resources
-            requestURI << OC_WELL_KNOWN_QUERY;
+            requestURI << OC_MULTICAST_DISCOVERY_URI;
 
             result = OCPlatform::findResource("", requestURI.str(),
-                    connectivityType, &foundResource);
+                    OC_ALL, &foundResource);
             if(result == OC_STACK_OK)
             {
                 std::cout << "Finding Resource... " << std::endl;
index c7de0a8..eae63e7 100644 (file)
@@ -279,9 +279,9 @@ int main(int argc, char* argv[]) {
     try
     {
         // Find all resources
-        requestURI << OC_WELL_KNOWN_QUERY;
+        requestURI << OC_MULTICAST_DISCOVERY_URI;
 
-        OCPlatform::findResource("", requestURI.str(), connectivityType, &foundResource);
+        OCPlatform::findResource("", requestURI.str(), OC_ALL, &foundResource);
         std::cout<< "Finding Resource... " <<std::endl;
 
         // A condition variable will free the mutex it is given, then do a non-
index b345368..3480e95 100644 (file)
@@ -485,17 +485,17 @@ int main(int argc, char* argv[]) {
         // makes it so that all boolean values are printed as 'true/false' in this stream
         std::cout.setf(std::ios::boolalpha);
         // Find all resources
-        requestURI << OC_WELL_KNOWN_QUERY << "?rt=core.light";
+        requestURI << OC_MULTICAST_DISCOVERY_URI << "?rt=core.light";
 
         OCPlatform::findResource("", requestURI.str(),
-                connectivityType, &foundResource);
+                OC_ALL, &foundResource);
         std::cout<< "Finding Resource... " <<std::endl;
 
         // Find resource is done twice so that we discover the original resources a second time.
         // These resources will have the same uniqueidentifier (yet be different objects), so that
         // we can verify/show the duplicate-checking code in foundResource(above);
         OCPlatform::findResource("", requestURI.str(),
-                connectivityType, &foundResource);
+                OC_ALL, &foundResource);
         std::cout<< "Finding Resource for second time..." << std::endl;
 
         // A condition variable will free the mutex it is given, then do a non-
index ceddb32..bf20e1c 100644 (file)
@@ -453,17 +453,17 @@ int main(int argc, char* argv[]) {
     try
     {
         // Find all resources
-        requestURI << OC_WELL_KNOWN_QUERY << "?rt=core.light";
+        requestURI << OC_MULTICAST_DISCOVERY_URI << "?rt=core.light";
 
         OCPlatform::findResource("", requestURI.str(),
-                connectivityType, &foundResource, OC::QualityOfService::LowQos);
+                OC_ALL, &foundResource, OC::QualityOfService::LowQos);
         std::cout<< "Finding Resource... " <<std::endl;
 
         // Find resource is done twice so that we discover the original resources a second time.
         // These resources will have the same uniqueidentifier (yet be different objects), so that
         // we can verify/show the duplicate-checking code in foundResource(above);
         OCPlatform::findResource("", requestURI.str(),
-                connectivityType, &foundResource, OC::QualityOfService::LowQos);
+                OC_ALL, &foundResource, OC::QualityOfService::LowQos);
         std::cout<< "Finding Resource for second time... " <<std::endl;
 
         // A condition variable will free the mutex it is given, then do a non-
index 6a5a947..b82e0e1 100644 (file)
@@ -147,12 +147,12 @@ public:
     void start()
     {
         std::ostringstream requestURI;
-        requestURI << OC_WELL_KNOWN_QUERY << "?rt=core.foo";
+        requestURI << OC_MULTICAST_DISCOVERY_URI << "?rt=core.foo";
 
         std::cout<<"Starting Client find:"<<std::endl;
         FindCallback f (std::bind(&ClientWorker::foundResource, this, std::placeholders::_1));
         std::cout<<"result:" <<
-        OCPlatform::findResource("", requestURI.str(), m_connectivityType, f)
+        OCPlatform::findResource("", requestURI.str(), OC_ALL, f)
         << std::endl;
 
         std::cout<<"Finding Resource..."<<std::endl;
index 7ad6f68..b7b5d09 100644 (file)
@@ -285,7 +285,7 @@ void client1()
 {
     std::cout << "in client1\n";
     std::cout<<"result1:" << OCPlatform::findResource("", requestURI.str(),
-            connectivityType, foundResource1)<< std::endl;
+            OC_ALL, foundResource1)<< std::endl;
 
     // A condition variable will free the mutex it is given, then do a non-
     // intensive block until 'notify' is called on it.  In this case, since we
@@ -302,7 +302,7 @@ void client2()
     std::cout << "in client2\n";
     std::cout<<"result2:" << OCPlatform::findResource("",
                 requestURI.str(),
-                connectivityType, foundResource2)<< std::endl;
+                OC_ALL, foundResource2)<< std::endl;
 
     // A condition variable will free the mutex it is given, then do a non-
     // intensive block until 'notify' is called on it.  In this case, since we
@@ -377,7 +377,7 @@ int main(int argc, char* argv[])
         std::cout << "   ConnectivityType : 1 - WIFI" << std::endl;
     }
 
-    requestURI << OC_WELL_KNOWN_QUERY << "?rt=core.foo";
+    requestURI << OC_MULTICAST_DISCOVERY_URI << "?rt=core.foo";
 
     PlatformConfig cfg {
         OC::ServiceType::InProc,