Imported Upstream version 0.9.2
[platform/upstream/iotivity.git] / resource / examples / garageclient.cpp
index c64528d..5a5af3f 100644 (file)
@@ -34,6 +34,13 @@ const int SUCCESS_RESPONSE = 0;
 std::shared_ptr<OCResource> curResource;
 std::mutex curResourceLock;
 
+static void printUsage()
+{
+    std::cout<<"Usage: garageclient <0|1> \n";
+    std::cout<<"ConnectivityType: Default IP\n";
+    std::cout<<"ConnectivityType 0: IP \n";
+}
+
 class Garage
 {
 public:
@@ -288,6 +295,44 @@ 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
+    {
+        printUsage();
+        std::cout << "Invalid input argument. Using IP as connectivity type" << std::endl;
+    }
+
     // Create PlatformConfig object
     PlatformConfig cfg {
         OC::ServiceType::InProc,
@@ -301,10 +346,10 @@ int main(int argc, char* argv[]) {
     try
     {
         // Find all resources
-        requestURI << OC_MULTICAST_DISCOVERY_URI << "?rt=core.garage";
+        requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.garage";
 
         OCPlatform::findResource("", requestURI.str(),
-                OC_ALL, &foundResource);
+                connectivityType, &foundResource);
 
         std::cout<< "Finding Resource... " <<std::endl;