Update a way of user interaction in con-server application
authorJihun Ha <jihun.ha@samsung.com>
Wed, 25 Mar 2015 12:04:51 +0000 (21:04 +0900)
committerUze Choi <uzchoi@samsung.com>
Thu, 26 Mar 2015 03:24:02 +0000 (03:24 +0000)
If an user hits a "enter" key, the application will give a menu
to the user, again.

Reference: [IOT-335]

Change-Id: Ie32b6f705b76e7ab455f3208d08f8c8be14dc685
Signed-off-by: Jihun Ha <jihun.ha@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/571
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
service/things-manager/sampleapp/linux/configuration/con-client.cpp

index 5e84817..5099ae1 100755 (executable)
@@ -262,6 +262,7 @@ void onFoundCandidateResource(std::vector< std::shared_ptr< OCResource > > resou
 
 int main(int argc, char* argv[])
 {
+    std::string str_steps;
 
     //**************************************************************
     // STEP 0
@@ -290,8 +291,21 @@ int main(int argc, char* argv[])
         cout << "(6) Reboot (for the group)" << std::endl;
         cout << "(10) Show Configuration Units" << std::endl;
 
-        cin >> g_Steps;
-        //
+        try
+        {
+            std::getline (std::cin, str_steps);
+
+            if(str_steps == "")
+                continue;
+            else
+                g_Steps = std::stoi(str_steps);
+        }
+        catch(std::invalid_argument&)
+        {
+            std::cout << "Please put a digit, not string" << std::endl;
+            continue;
+        }
+
         if (g_Steps == 0)
             break;
         else if (g_Steps == 1)