Imported Upstream version 0.9.2
[platform/upstream/iotivity.git] / resource / examples / groupserver.cpp
index c4b069d..fd32467 100644 (file)
@@ -33,6 +33,12 @@ namespace PH = std::placeholders;
 OCResourceHandle resourceHandle;
 std::vector< OCResourceHandle > resourceHandleVector;
 
+static void printUsage()
+{
+    std::cout<<"Usage: groupclient <0|1>\n";
+    std::cout<<"ConnectivityType: Default \n";
+    std::cout<<"ConnectivityType 0: IP\n";
+}
 void foundResource(std::shared_ptr< OCResource > resource)
 {
 
@@ -80,6 +86,43 @@ int main(int argc, char* argv[])
 {
     ostringstream requestURI;
 
+    OCConnectivityType connectivityType = CT_ADAPTER_IP;
+
+    if(argc == 2)
+    {
+        try
+        {
+            std::size_t inputValLen;
+            int optionSelected = 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(exception& e)
+        {
+            std::cout << "Invalid input argument. Using IP as connectivity type" << std::endl;
+        }
+    }
+    else
+    {
+        printUsage();
+
+    }
+
     PlatformConfig config
     { OC::ServiceType::InProc, ModeType::Both, "0.0.0.0", 0, OC::QualityOfService::LowQos };
 
@@ -100,10 +143,10 @@ int main(int argc, char* argv[])
 
         cout << "registerResource is called." << endl;
 
-        requestURI << OC_MULTICAST_DISCOVERY_URI << "?rt=core.light";
+        requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
 
         OCPlatform::findResource("", requestURI.str(),
-                                 OC_ALL, &foundResource);
+                                 connectivityType, &foundResource);
 
         OCPlatform::bindInterfaceToResource(resourceHandle, GROUP_INTERFACE);
         OCPlatform::bindInterfaceToResource(resourceHandle, DEFAULT_INTERFACE);