Imported Upstream version 0.9.2
[platform/upstream/iotivity.git] / resource / examples / roomclient.cpp
index fdba60d..2765dfe 100644 (file)
@@ -41,6 +41,12 @@ int observe_count()
     return ++oc;
 }
 
+static void printUsage()
+{
+    std::cout << "Usage roomclient <0|1>" << std::endl;
+    std::cout<<"connectivityType: Default" << std::endl;
+    std::cout << "connectivityType 0: IP" << std::endl;
+}
 // Forward declaration
 void putRoomRepresentation(std::shared_ptr<OCResource> resource);
 void onPut(const HeaderOptions& headerOptions, const OCRepresentation& rep, const int eCode);
@@ -215,7 +221,6 @@ void foundResource(std::shared_ptr<OCResource> resource)
     }
     catch(std::exception& e)
     {
-        std::cerr << "Exception in foundResource: "<< e.what() <<std::endl;
         //log(e.what());
     }
 }
@@ -224,6 +229,41 @@ int main(int argc, char* argv[]) {
 
     std::ostringstream requestURI;
 
+    OCConnectivityType connectivityType = CT_ADAPTER_IP;
+    if(argc == 2)
+    {
+        try
+        {
+            std::size_t inputValLen;
+            int optionSelected = std::stoi(argv[1], &inputValLen);
+
+            if(inputValLen == strlen(argv[1]))
+            {
+                if(optionSelected == 0)
+                {
+                    std::cout << "Using IP."<< std::endl;
+                    connectivityType = CT_ADAPTER_IP;
+                }
+                else
+                {
+                    std::cout << "Invalid connectivity type selected. Using default IP"<< std::endl;
+                }
+            }
+            else
+            {
+                std::cout << "Invalid connectivity type selected. Using default IP" << std::endl;
+            }
+        }
+        catch(std::exception& e)
+        {
+            std::cout << "Invalid input argument. Using IP as connectivity type" << std::endl;
+        }
+    }
+    else
+    {
+        std::cout << "Default input argument. Using IP as Default connectivity type" << std::endl;
+        printUsage();
+    }
 
     // Create PlatformConfig object
     PlatformConfig cfg {
@@ -239,9 +279,9 @@ int main(int argc, char* argv[]) {
     try
     {
         // Find all resources
-        requestURI << OC_MULTICAST_DISCOVERY_URI;
+        requestURI << OC_RSRVD_WELL_KNOWN_URI;
 
-        OCPlatform::findResource("", requestURI.str(), OC_ALL, &foundResource);
+        OCPlatform::findResource("", requestURI.str(), connectivityType, &foundResource);
         std::cout<< "Finding Resource... " <<std::endl;
 
         // A condition variable will free the mutex it is given, then do a non-