Imported Upstream version 0.9.1
[platform/upstream/iotivity.git] / resource / examples / groupserver.cpp
old mode 100755 (executable)
new mode 100644 (file)
index 4cebd44..c4b069d
@@ -67,20 +67,19 @@ void foundResource(std::shared_ptr< OCResource > resource)
                     cout << "\tresource Error!" << endl;
                 }
             }
-
-            // p_platform.bindResource(resourceHandle, foundResourceHandle);
-
         }
     }
     catch (std::exception& e)
     {
-        std::cout << "" << std::endl;
+        std::cout << "Exception in foundResource:"<< e.what() << std::endl;
     }
 
 }
 
-int main()
+int main(int argc, char* argv[])
 {
+    ostringstream requestURI;
+
     PlatformConfig config
     { OC::ServiceType::InProc, ModeType::Both, "0.0.0.0", 0, OC::QualityOfService::LowQos };
 
@@ -101,29 +100,44 @@ int main()
 
         cout << "registerResource is called." << endl;
 
-        OCPlatform::findResource("", "coap://224.0.1.187/oc/core?rt=core.light", &foundResource);
+        requestURI << OC_MULTICAST_DISCOVERY_URI << "?rt=core.light";
+
+        OCPlatform::findResource("", requestURI.str(),
+                                 OC_ALL, &foundResource);
+
         OCPlatform::bindInterfaceToResource(resourceHandle, GROUP_INTERFACE);
         OCPlatform::bindInterfaceToResource(resourceHandle, DEFAULT_INTERFACE);
 
         int selectedMenu;
-        while (true)
+        bool isRun = true;
+        while (isRun)
         {
+            cout << endl << "0 :: Quit 1 :: UNREGISTER RESOURCES\n" << endl;
             std::cin >> selectedMenu;
 
-            if (selectedMenu == 1)
+            switch(selectedMenu)
             {
+            case 0:
+                isRun = false;
+                break;
+            case 1:
+                std::cout << "Unregistering resources" << std::endl;
                 for (unsigned int i = 0; i < resourceHandleVector.size(); ++i)
                 {
                     OCPlatform::unregisterResource(resourceHandleVector.at(i));
                 }
+                break;
+            default:
+                cout << "Invalid option" << endl;
             }
 
         }
     }
     catch (OCException& e)
     {
-
+        oclog() << "Exception in main: "<< e.what();
     }
 
     return 0;
 }
+