Fix an exception handling issue in con-client app.
authorJihun Ha <jihun.ha@samsung.com>
Tue, 3 Feb 2015 08:12:37 +0000 (17:12 +0900)
committerUze Choi <uzchoi@samsung.com>
Wed, 4 Feb 2015 08:25:48 +0000 (08:25 +0000)
Though con-client app do not discover configuration,
diagnostics, and factorySet collection resources in
a network, the con-client app can be proceded.
And even when a response for any GET/PUT request indicates
a bad request, it is correctly delivered to the app.

Reference issue ID : [IOT-291]

Change-Id: Ic101013daa6efea9639295553022fd67f58c925e
Signed-off-by: Jihun Ha <jihun.ha@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/271
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
service/things-manager/sampleapp/linux/configuration/con-client.cpp [changed mode: 0644->0755]
service/things-manager/sampleapp/linux/configuration/con-server.cpp [changed mode: 0644->0755]
service/things-manager/sdk/src/ThingsConfiguration.cpp [changed mode: 0644->0755]
service/things-manager/sdk/src/ThingsDiagnostics.cpp [changed mode: 0644->0755]

old mode 100644 (file)
new mode 100755 (executable)
index 278c3e2..fbf4493
@@ -35,6 +35,8 @@ using namespace OIC;
 int g_Steps = 0;
 int isWaiting = 0; //0: none to wait, 1: wait for the response of "getConfigurationValue"
 
+const int SUCCESS_RESPONSE = 0;
+
 static ThingsManager* g_thingsmanager;
 
 OCResourceHandle configurationCollectionHandle;
@@ -62,35 +64,61 @@ typedef std::function<
 typedef std::string ConfigurationName;
 typedef std::string ConfigurationValue;
 
+void timeCheck(int timeSec)
+{
+    sleep(timeSec);
+    isWaiting = 0;
+}
+
 void onReboot(const HeaderOptions& headerOptions, const OCRepresentation& rep, const int eCode)
 {
-    std::cout << "\tResource URI: " << rep.getUri() << std::endl;
+    isWaiting = 0;
 
-    std::cout << "\t\tReboot:" << rep.getValue< std::string >("value") << std::endl;
+    if (eCode != SUCCESS_RESPONSE)
+    {
+        return ;
+    }
 
-    isWaiting = 0;
+    std::cout << "\tResource URI: " << rep.getUri() << std::endl;
+    std::cout << "\t\tReboot:" << rep.getValue< std::string >("value") << std::endl;
 }
 
 void onFactoryReset(const HeaderOptions& headerOptions, const OCRepresentation& rep,
         const int eCode)
 {
-    std::cout << "\tResource URI: " << rep.getUri() << std::endl;
+    isWaiting = 0;
+
+    if (eCode != SUCCESS_RESPONSE)
+    {
+       return ;
+    }
 
+    std::cout << "\tResource URI: " << rep.getUri() << std::endl;
     std::cout << "\t\tFactoryReset:" << rep.getValue< std::string >("value") << std::endl;
-    isWaiting = 0;
 }
 
 void onUpdate(const HeaderOptions& headerOptions, const OCRepresentation& rep, const int eCode)
 {
-    std::cout << "\tResource URI: " << rep.getUri() << std::endl;
+    isWaiting = 0;
 
-    std::cout << "\t\tvalue:" << rep.getValue< std::string >("value") << std::endl;
+    if (eCode != SUCCESS_RESPONSE)
+    {
+        return ;
+    }
 
-    isWaiting = 0;
+    std::cout << "\tResource URI: " << rep.getUri() << std::endl;
+    std::cout << "\t\tvalue:" << rep.getValue< std::string >("value") << std::endl;
 }
 
 void onGet(const HeaderOptions& headerOptions, const OCRepresentation& rep, const int eCode)
 {
+    isWaiting = 0;
+
+    if (eCode != SUCCESS_RESPONSE)
+    {
+        return ;
+    }
+
     std::cout << "\tResource URI: " << rep.getUri() << std::endl;
 
     if (rep.hasAttribute("value"))
@@ -109,8 +137,6 @@ void onGet(const HeaderOptions& headerOptions, const OCRepresentation& rep, cons
         else if (oit->hasAttribute("link"))
             std::cout << "\t\tlink:" << oit->getValue< std::string >("link") << std::endl;
     }
-
-    isWaiting = 0;
 }
 
 // Callback to found collection resource
@@ -153,9 +179,7 @@ void onFoundCollectionResource(std::vector< std::shared_ptr< OCResource > > reso
         //log(e.what());
     }
 
-    if (g_configurationCollection != NULL && g_diagnosticsCollection != NULL
-            && g_setCollection != NULL)
-        isWaiting = 0;
+    isWaiting = 0;
 }
 
 // Callback to found resources
@@ -165,8 +189,6 @@ void onFoundCandidateCollection(std::vector< std::shared_ptr< OCResource > > res
     std::string resourceURI;
     std::string hostAddress;
 
-    static bool flagForCon = false, flagForDiag = false, flagForSet = false;
-
     try
     {
         // Do some operations with resource object.
@@ -194,7 +216,6 @@ void onFoundCandidateCollection(std::vector< std::shared_ptr< OCResource > > res
                     {
                         if (resource->uri() == "/oic/con")
                         {
-                            flagForCon = true;
                             OCPlatform::bindResource(configurationCollectionHandle,
                                     foundResourceHandle);
                             if (g_configurationResource == NULL)
@@ -202,7 +223,6 @@ void onFoundCandidateCollection(std::vector< std::shared_ptr< OCResource > > res
                         }
                         else if (resource->uri() == "/oic/diag")
                         {
-                            flagForDiag = true;
                             OCPlatform::bindResource(diagnosticsCollectionHandle,
                                     foundResourceHandle);
                             if (g_diagnosticsResource == NULL)
@@ -210,7 +230,6 @@ void onFoundCandidateCollection(std::vector< std::shared_ptr< OCResource > > res
                         }
                         else if (resource->uri() == "/factorySet")
                         {
-                            flagForSet = true;
                             OCPlatform::bindResource(setCollectionHandle, foundResourceHandle);
                             if (g_setResource == NULL)
                                 g_setResource = resource;
@@ -239,8 +258,7 @@ void onFoundCandidateCollection(std::vector< std::shared_ptr< OCResource > > res
         //log(e.what());
     }
 
-    if (flagForCon && flagForDiag && flagForSet)
-        isWaiting = 0;
+    isWaiting = 0;
 }
 
 int main(int argc, char* argv[])
@@ -361,6 +379,10 @@ int main(int argc, char* argv[])
             g_thingsmanager->findCandidateResources(types, &onFoundCandidateCollection, 5);
 
             isWaiting = 1;
+
+            thread t(&timeCheck, 5);
+            t.join();       // After 5 seconds, isWaiting value will be 0.
+            t.~thread();
         }
         else if (g_Steps == 2) // make a group with found things
         {
@@ -372,8 +394,12 @@ int main(int argc, char* argv[])
             g_thingsmanager->findCandidateResources(types, &onFoundCollectionResource, 5);
 
             std::cout << "Finding Collection resource... " << std::endl;
+
             isWaiting = 1;
 
+            thread t(&timeCheck, 5);
+            t.join();       // After 5 seconds, isWaiting value will be 0.
+            t.~thread();
         }
         else if (g_Steps == 3)
         {
@@ -396,6 +422,12 @@ int main(int argc, char* argv[])
             ConfigurationName name = "region";
             ConfigurationValue value = "U.S.A (new region)";
 
+            if(g_configurationCollection == NULL)
+            {
+                std::cout<<"Note that you first create a group to use this command." << std::endl;
+                continue;
+            }
+
             std::cout << "For example, change region resource's value" << std::endl;
             std::cout << g_configurationCollection->uri() << std::endl;
 
@@ -413,6 +445,12 @@ int main(int argc, char* argv[])
 
             ConfigurationName name = "region";
 
+            if(g_configurationCollection == NULL)
+            {
+                std::cout<<"Note that you first create a group to use this command." << std::endl;
+                continue;
+            }
+
             std::cout << "For example, get region resource's value" << std::endl;
 
             std::vector< ConfigurationName > configurations;
@@ -426,6 +464,12 @@ int main(int argc, char* argv[])
         else if (g_Steps == 6)
         {
             // factory reset
+            if(g_diagnosticsCollection == NULL)
+            {
+                std::cout<<"Note that you first create a group to use this command." << std::endl;
+                continue;
+            }
+
             if (g_thingsmanager->factoryReset(g_diagnosticsCollection, &onFactoryReset)
                     != OC_STACK_ERROR)
                 isWaiting = 1;
@@ -433,6 +477,12 @@ int main(int argc, char* argv[])
         else if (g_Steps == 7)
         {
             // reboot
+            if(g_diagnosticsCollection == NULL)
+            {
+                std::cout<<"Note that you first create a group to use this command." << std::endl;
+                continue;
+            }
+
             if (g_thingsmanager->reboot(g_diagnosticsCollection, &onReboot) != OC_STACK_ERROR)
                 isWaiting = 1;
         }
@@ -446,4 +496,3 @@ int main(int argc, char* argv[])
 
     return 0;
 }
-
old mode 100644 (file)
new mode 100755 (executable)
index c83c7a0..9bf8cb8
@@ -252,38 +252,36 @@ OCEntityHandlerResult entityHandlerForResource(std::shared_ptr< OCResourceReques
 // callback handler on GET request
 void onBootstrap(const HeaderOptions& headerOptions, const OCRepresentation& rep, const int eCode)
 {
-    if (eCode == SUCCESS_RESPONSE)
-    {
-        std::cout << "\n\nGET request was successful" << std::endl;
-        std::cout << "\tResource URI: " << rep.getUri() << std::endl;
-
-        defaultRegionValue = rep.getValue< std::string >("regionValue");
-        defaultTimeValue = rep.getValue< std::string >("timeValue");
-        defaultCurrentTimeValue = rep.getValue< std::string >("currentTimeValue");
-        defaultNetworkValue = rep.getValue< std::string >("networkValue");
-        defaultIPAddressValue = rep.getValue< std::string >("IPAddressValue");
-        defaultSecurityValue = rep.getValue< std::string >("securityValue");
-        defaultModeValue = rep.getValue< std::string >("modeValue");
-        defaultConfigurationValue = rep.getValue< std::string >("configurationValue");
-        defaultFactorySetValue = rep.getValue< std::string >("factorySetValue");
-
-        std::cout << "\tregionValue : " << defaultRegionValue << std::endl;
-        std::cout << "\ttimeValue : " << defaultTimeValue << std::endl;
-        std::cout << "\tcurrentTimeValue : " << defaultCurrentTimeValue << std::endl;
-        std::cout << "\tnetworkValue : " << defaultNetworkValue << std::endl;
-        std::cout << "\tIPAddressValue : " << defaultIPAddressValue << std::endl;
-        std::cout << "\tsecurityValue : " << defaultSecurityValue << std::endl;
-        std::cout << "\tmodeValue : " << defaultModeValue << std::endl;
-        std::cout << "\tconfigurationValue : " << defaultConfigurationValue << std::endl;
-        std::cout << "\tfactorySetValue : " << defaultFactorySetValue << std::endl;
+    isWaiting = 0;
 
-    }
-    else
+    if (eCode != SUCCESS_RESPONSE)
     {
         std::cout << "onGET Response error: " << eCode << std::endl;
-        std::exit(-1);
+        return ;
     }
-    isWaiting = 0;
+
+    std::cout << "\n\nGET request was successful" << std::endl;
+    std::cout << "\tResource URI: " << rep.getUri() << std::endl;
+
+    defaultRegionValue = rep.getValue< std::string >("regionValue");
+    defaultTimeValue = rep.getValue< std::string >("timeValue");
+    defaultCurrentTimeValue = rep.getValue< std::string >("currentTimeValue");
+    defaultNetworkValue = rep.getValue< std::string >("networkValue");
+    defaultIPAddressValue = rep.getValue< std::string >("IPAddressValue");
+    defaultSecurityValue = rep.getValue< std::string >("securityValue");
+    defaultModeValue = rep.getValue< std::string >("modeValue");
+    defaultConfigurationValue = rep.getValue< std::string >("configurationValue");
+    defaultFactorySetValue = rep.getValue< std::string >("factorySetValue");
+
+    std::cout << "\tregionValue : " << defaultRegionValue << std::endl;
+    std::cout << "\ttimeValue : " << defaultTimeValue << std::endl;
+    std::cout << "\tcurrentTimeValue : " << defaultCurrentTimeValue << std::endl;
+    std::cout << "\tnetworkValue : " << defaultNetworkValue << std::endl;
+    std::cout << "\tIPAddressValue : " << defaultIPAddressValue << std::endl;
+    std::cout << "\tsecurityValue : " << defaultSecurityValue << std::endl;
+    std::cout << "\tmodeValue : " << defaultModeValue << std::endl;
+    std::cout << "\tconfigurationValue : " << defaultConfigurationValue << std::endl;
+    std::cout << "\tfactorySetValue : " << defaultFactorySetValue << std::endl;
 }
 
 int main()
old mode 100644 (file)
new mode 100755 (executable)
index 5a4777f..8b29e2e
@@ -31,7 +31,6 @@ using namespace OC;
 
 namespace OIC
 {
-    const int SUCCESS_RESPONSE = 0;
     int cnt = 0;
 
     std::map< std::string, ConfigurationRequestEntry > configurationRequestTable;
@@ -152,6 +151,13 @@ namespace OIC
     void ThingsConfiguration::onDeleteActionSet(const HeaderOptions& headerOptions,
             const OCRepresentation& rep, const int eCode, std::string conf)
     {
+        if (eCode != OC_STACK_OK)
+        {
+            std::cout << "onPut Response error: " << eCode << std::endl;
+            getCallback(conf)(headerOptions, rep, eCode);
+            return ;
+        }
+
         std::shared_ptr < OCResource > resource = getResource(conf);
 
         std::cout << __func__ << std::endl;
@@ -178,186 +184,181 @@ namespace OIC
     void ThingsConfiguration::onGetChildInfoForUpdate(const HeaderOptions& headerOptions,
             const OCRepresentation& rep, const int eCode, std::string conf)
     {
-        if (eCode == SUCCESS_RESPONSE)
+        if (eCode != OC_STACK_OK)
         {
-            std::cout << "GET request was successful" << std::endl;
-
-            std::cout << "\tResource URI: " << rep.getUri() << std::endl;
+            std::cout << "onPut Response error: " << eCode << std::endl;
+            getCallback(conf)(headerOptions, rep, eCode);
+            return ;
+        }
 
-            std::vector < OCRepresentation > children = rep.getChildren();
-            for (auto oit = children.begin(); oit != children.end(); ++oit)
-            {
-                std::cout << "\t\tChild Resource URI: " << oit->getUri() << std::endl;
-            }
+        std::cout << "GET request was successful" << std::endl;
 
-            // Get information by using configuration name(conf)
-            std::shared_ptr < OCResource > resource = getResource(conf);
-            std::string actionstring = conf;
-            std::string uri = getUriByConfigurationName(conf);
-            std::string attr = getAttributeByConfigurationName(conf);
+        std::cout << "\tResource URI: " << rep.getUri() << std::endl;
 
-            if (uri == "")
-                return;
+        std::vector < OCRepresentation > children = rep.getChildren();
+        for (auto oit = children.begin(); oit != children.end(); ++oit)
+        {
+            std::cout << "\t\tChild Resource URI: " << oit->getUri() << std::endl;
+        }
 
-            if (resource)
-            {
-                // In this nest, we create a new action set of which name is the configuration name.
-                // Required information consists of a host address, URI, attribute key, and
-                // attribute value.
-                ActionSet *newActionSet = new ActionSet();
-                newActionSet->actionsetName = conf;
+        // Get information by using configuration name(conf)
+        std::shared_ptr < OCResource > resource = getResource(conf);
+        std::string actionstring = conf;
+        std::string uri = getUriByConfigurationName(conf);
+        std::string attr = getAttributeByConfigurationName(conf);
 
-                for (auto oit = children.begin(); oit != children.end(); ++oit)
-                {
-                    Action *newAction = new Action();
+        if (uri == "")
+            return;
 
-                    // oit->getUri() includes a host address as well as URI.
-                    // We should split these to each other and only use the host address to create
-                    // a child resource's URI. Note that the collection resource and its child
-                    // resource are located in same host.
-                    newAction->target = getHostFromURI(oit->getUri()) + uri;
+        if (resource)
+        {
+            // In this nest, we create a new action set of which name is the configuration name.
+            // Required information consists of a host address, URI, attribute key, and
+            // attribute value.
+            ActionSet *newActionSet = new ActionSet();
+            newActionSet->actionsetName = conf;
 
-                    Capability *newCapability = new Capability();
-                    newCapability->capability = attr;
-                    newCapability->status = getUpdateVal(conf);
+            for (auto oit = children.begin(); oit != children.end(); ++oit)
+            {
+                Action *newAction = new Action();
 
-                    newAction->listOfCapability.push_back(newCapability);
-                    newActionSet->listOfAction.push_back(newAction);
-                }
+                // oit->getUri() includes a host address as well as URI.
+                // We should split these to each other and only use the host address to create
+                // a child resource's URI. Note that the collection resource and its child
+                // resource are located in same host.
+                newAction->target = getHostFromURI(oit->getUri()) + uri;
 
-                // Request to create a new action set by using the above actionSet
-                g_groupmanager->addActionSet(resource, newActionSet,
-                        std::function<
-                                void(const HeaderOptions& headerOptions,
-                                        const OCRepresentation& rep, const int eCode) >(
-                                std::bind(&ThingsConfiguration::onCreateActionSet, this,
-                                        std::placeholders::_1, std::placeholders::_2,
-                                        std::placeholders::_3, conf)));
+                Capability *newCapability = new Capability();
+                newCapability->capability = attr;
+                newCapability->status = getUpdateVal(conf);
 
-                free(newActionSet);
+                newAction->listOfCapability.push_back(newCapability);
+                newActionSet->listOfAction.push_back(newAction);
             }
 
-        }
-        else
-        {
-            std::cout << "onPut Response error: " << eCode << std::endl;
-            std::exit(-1);
+            // Request to create a new action set by using the above actionSet
+            g_groupmanager->addActionSet(resource, newActionSet,
+                    std::function<
+                            void(const HeaderOptions& headerOptions,
+                                    const OCRepresentation& rep, const int eCode) >(
+                            std::bind(&ThingsConfiguration::onCreateActionSet, this,
+                                    std::placeholders::_1, std::placeholders::_2,
+                                    std::placeholders::_3, conf)));
+
+            free(newActionSet);
         }
     }
 
     void ThingsConfiguration::onGetChildInfoForGet(const HeaderOptions& headerOptions,
             const OCRepresentation& rep, const int eCode, std::string conf)
     {
-        if (eCode == SUCCESS_RESPONSE)
+        if (eCode != OC_STACK_OK)
         {
-            std::cout << "GET request was successful" << std::endl;
-            std::cout << "\tResource URI: " << rep.getUri() << std::endl;
+            std::cout << "onGet Response error: " << eCode << std::endl;
+            getCallback(conf)(headerOptions, rep, eCode);
+            return ;
+        }
 
-            std::shared_ptr< OCResource > resource, tempResource;
-            std::vector < std::shared_ptr< OCResource > > p_resources;
-            std::vector < std::string > m_if;
-            std::string uri = getUriByConfigurationName(conf);
+        std::cout << "GET request was successful" << std::endl;
+        std::cout << "\tResource URI: " << rep.getUri() << std::endl;
 
-            if (uri == "")
-                return;
+        std::shared_ptr< OCResource > resource, tempResource;
+        std::vector < std::shared_ptr< OCResource > > p_resources;
+        std::vector < std::string > m_if;
+        std::string uri = getUriByConfigurationName(conf);
 
-            if (uri == "/oic/con" || uri == "/factoryset" || uri == "/factoryset/oic/con")
-                m_if.push_back(BATCH_INTERFACE);
-            else
-                m_if.push_back(DEFAULT_INTERFACE);
+        if (uri == "")
+            return;
 
-            std::vector < OCRepresentation > children = rep.getChildren();
-            for (auto oit = children.begin(); oit != children.end(); ++oit)
-            {
-                std::cout << "\t\tChild Resource URI: " << oit->getUri() << std::endl;
+        if (uri == "/oic/con" || uri == "/factoryset" || uri == "/factoryset/oic/con")
+            m_if.push_back(BATCH_INTERFACE);
+        else
+            m_if.push_back(DEFAULT_INTERFACE);
 
-                // Using a host address and child URIs, we can dynamically create resource objects.
-                // Note that the child resources have not found before, we have no resource objects.
-                // For this reason, we create the resource objects.
+        std::vector < OCRepresentation > children = rep.getChildren();
+        for (auto oit = children.begin(); oit != children.end(); ++oit)
+        {
+            std::cout << "\t\tChild Resource URI: " << oit->getUri() << std::endl;
 
-                std::string host = getHostFromURI(oit->getUri());
-                tempResource = OCPlatform::constructResourceObject(host, uri, true,
-                        oit->getResourceTypes(), m_if);
+            // Using a host address and child URIs, we can dynamically create resource objects.
+            // Note that the child resources have not found before, we have no resource objects.
+            // For this reason, we create the resource objects.
 
-                p_resources.push_back(tempResource);
-            }
+            std::string host = getHostFromURI(oit->getUri());
+            tempResource = OCPlatform::constructResourceObject(host, uri, true,
+                    oit->getResourceTypes(), m_if);
 
-            // Send GET messages to the child resources in turn.
-            for (unsigned int i = 0; i < p_resources.size(); ++i)
+            p_resources.push_back(tempResource);
+        }
+
+        // Send GET messages to the child resources in turn.
+        for (unsigned int i = 0; i < p_resources.size(); ++i)
+        {
+            resource = p_resources.at(i);
+            if (resource)
             {
-                resource = p_resources.at(i);
-                if (resource)
+                try
                 {
-                    try
+                    if (isSimpleResource(resource))
                     {
-                        if (isSimpleResource(resource))
-                        {
-                            QueryParamsMap test;
-                            resource->get(test, getCallback(conf));
-                        }
-                        else
-                        {
-                            QueryParamsMap test;
-                            resource->get(resource->getResourceTypes().at(0), BATCH_INTERFACE, test,
-                                    getCallback(conf));
-                        }
+                        QueryParamsMap test;
+                        resource->get(test, getCallback(conf));
                     }
-                    catch (OCException& e)
+                    else
                     {
-                        std::cout << e.reason() << std::endl;
+                        QueryParamsMap test;
+                        resource->get(resource->getResourceTypes().at(0), BATCH_INTERFACE, test,
+                                getCallback(conf));
                     }
-
                 }
+                catch (OCException& e)
+                {
+                    std::cout << e.reason() << std::endl;
+                }
+
             }
         }
-        else
-        {
-            std::cout << "onPut Response error: " << eCode << std::endl;
-            std::exit(-1);
-        }
     }
 
     void ThingsConfiguration::onCreateActionSet(const HeaderOptions& headerOptions,
             const OCRepresentation& rep, const int eCode, std::string conf)
     {
-        if (eCode == SUCCESS_RESPONSE)
+        if (eCode != OC_STACK_OK)
         {
-            std::cout << "PUT request was successful" << std::endl;
-
-            std::shared_ptr < OCResource > resource = getResource(conf);
-            if (resource)
-            {
-                // Now, it is time to execute the action set.
-                g_groupmanager->executeActionSet(resource, conf,
-                        std::function<
-                                void(const HeaderOptions& headerOptions,
-                                        const OCRepresentation& rep, const int eCode) >(
-                                std::bind(&ThingsConfiguration::onExecuteForGroupAction, this,
-                                        std::placeholders::_1, std::placeholders::_2,
-                                        std::placeholders::_3, conf)));
-            }
+            std::cout << "onPut Response error: " << eCode << std::endl;
+            getCallback(conf)(headerOptions, rep, eCode);
+            return ;
         }
-        else
+
+        std::cout << "PUT request was successful" << std::endl;
+
+        std::shared_ptr < OCResource > resource = getResource(conf);
+        if (resource)
         {
-            std::cout << "onPut Response error: " << eCode << std::endl;
-            std::exit(-1);
+            // Now, it is time to execute the action set.
+            g_groupmanager->executeActionSet(resource, conf,
+                    std::function<
+                            void(const HeaderOptions& headerOptions,
+                                    const OCRepresentation& rep, const int eCode) >(
+                            std::bind(&ThingsConfiguration::onExecuteForGroupAction, this,
+                                    std::placeholders::_1, std::placeholders::_2,
+                                    std::placeholders::_3, conf)));
         }
     }
 
     void ThingsConfiguration::onExecuteForGroupAction(const HeaderOptions& headerOptions,
             const OCRepresentation& rep, const int eCode, std::string conf)
     {
-        if (eCode == SUCCESS_RESPONSE)
-        {
-            std::cout << "PUT request was successful" << std::endl;
-
-            getCallback(conf)(headerOptions, rep, eCode);
-        }
-        else
+        if (eCode != OC_STACK_OK)
         {
             std::cout << "onPut Response error: " << eCode << std::endl;
-            std::exit(-1);
+            getCallback(conf)(headerOptions, rep, eCode);
+            return ;
         }
+
+        std::cout << "PUT request was successful" << std::endl;
+
+        getCallback(conf)(headerOptions, rep, eCode);
     }
 
     bool ThingsConfiguration::isSimpleResource(std::shared_ptr< OCResource > resource)
@@ -386,34 +387,31 @@ namespace OIC
     void ThingsConfiguration::onGet(const HeaderOptions& headerOptions, const OCRepresentation& rep,
             const int eCode, std::string conf)
     {
-        if (eCode == SUCCESS_RESPONSE)
+        if (eCode != OC_STACK_OK)
         {
-            std::cout << "Get request was successful" << std::endl;
-
+            std::cout << "onGet Response error: " << eCode << std::endl;
             getCallback(conf)(headerOptions, rep, eCode);
+            return ;
         }
-        else
-        {
-            std::cout << "onPut Response error: " << eCode << std::endl;
-            std::exit(-1);
-        }
+
+        std::cout << "Get request was successful" << std::endl;
+
+        getCallback(conf)(headerOptions, rep, eCode);
     }
 
     void ThingsConfiguration::onPut(const HeaderOptions& headerOptions, const OCRepresentation& rep,
             const int eCode, std::string conf)
     {
-        if (eCode == SUCCESS_RESPONSE)
-        {
-            std::cout << "PUT request was successful" << std::endl;
-
-            // Callback
-            getCallback(conf)(headerOptions, rep, eCode);
-        }
-        else
+        if (eCode != OC_STACK_OK)
         {
             std::cout << "onPut Response error: " << eCode << std::endl;
-            std::exit(-1);
+            getCallback(conf)(headerOptions, rep, eCode);
+            return;
         }
+
+        std::cout << "PUT request was successful" << std::endl;
+
+        getCallback(conf)(headerOptions, rep, eCode);
     }
 
     OCStackResult ThingsConfiguration::updateConfigurations(std::shared_ptr< OCResource > resource,
@@ -546,16 +544,14 @@ namespace OIC
     void ThingsConfiguration::onGetBootstrapInformation(const HeaderOptions& headerOptions,
             const OCRepresentation& rep, const int eCode)
     {
-        if (eCode == SUCCESS_RESPONSE)
+        if (eCode != OC_STACK_OK)
         {
+            std::cout << "onGET Response error: " << eCode << std::endl;
             g_bootstrapCallback(headerOptions, rep, eCode);
+            return;
         }
 
-        else
-        {
-            std::cout << "onGET Response error: " << eCode << std::endl;
-            std::exit(-1);
-        }
+        g_bootstrapCallback(headerOptions, rep, eCode);
     }
 
     void ThingsConfiguration::onFoundBootstrapServer(
old mode 100644 (file)
new mode 100755 (executable)
index 7eccc62..b4032a3
@@ -31,8 +31,6 @@ using namespace OC;
 
 namespace OIC
 {
-    const int SUCCESS_RESPONSE = 0;
-
     std::map< std::string, DiagnosticsRequestEntry > diagnosticsRequestTable;
 
     ThingsDiagnostics* ThingsDiagnostics::thingsDiagnosticsInstance = NULL;
@@ -149,131 +147,127 @@ namespace OIC
     void ThingsDiagnostics::onGetChildInfoForUpdate(const HeaderOptions& headerOptions,
             const OCRepresentation& rep, const int eCode, std::string diag)
     {
-        if (eCode == SUCCESS_RESPONSE)
+        if (eCode != OC_STACK_OK)
         {
-            std::cout << "GET request was successful" << std::endl;
+            std::cout << "onGet Response error: " << eCode << std::endl;
+            getCallback(diag)(headerOptions, rep, eCode);
+            return ;
+        }
 
-            std::cout << "\tResource URI: " << rep.getUri() << std::endl;
+        std::cout << "GET request was successful" << std::endl;
 
-            std::vector < OCRepresentation > children = rep.getChildren();
-            for (auto oit = children.begin(); oit != children.end(); ++oit)
-            {
-                std::cout << "\t\tChild Resource URI: " << oit->getUri() << std::endl;
-            }
+        std::cout << "\tResource URI: " << rep.getUri() << std::endl;
 
-            // Get information by using diagnostics name(diag)
-            std::shared_ptr < OCResource > resource = getResource(diag);
-            std::string actionstring = diag;
-            std::string uri = getUriByDiagnosticsName(diag);
-            std::string attr = getAttributeByDiagnosticsName(diag);
+        std::vector < OCRepresentation > children = rep.getChildren();
+        for (auto oit = children.begin(); oit != children.end(); ++oit)
+        {
+            std::cout << "\t\tChild Resource URI: " << oit->getUri() << std::endl;
+        }
+
+        // Get information by using diagnostics name(diag)
+        std::shared_ptr < OCResource > resource = getResource(diag);
+        std::string actionstring = diag;
+        std::string uri = getUriByDiagnosticsName(diag);
+        std::string attr = getAttributeByDiagnosticsName(diag);
+
+        if (uri == "")
+            return;
 
-            if (uri == "")
-                return;
+        if (resource)
+        {
+            // In this nest, we create a new action set of which name is the dignostics name.
+            // Required information consists of a host address, URI, attribute key, and
+            // attribute value.
+            ActionSet *newActionSet = new ActionSet();
+            newActionSet->actionsetName = diag;
 
-            if (resource)
+            for (auto oit = children.begin(); oit != children.end(); ++oit)
             {
-                // In this nest, we create a new action set of which name is the dignostics name.
-                // Required information consists of a host address, URI, attribute key, and
-                // attribute value.
-                ActionSet *newActionSet = new ActionSet();
-                newActionSet->actionsetName = diag;
-
-                for (auto oit = children.begin(); oit != children.end(); ++oit)
-                {
-                    Action *newAction = new Action();
-
-                    // oit->getUri() includes a host address as well as URI.
-                    // We should split these to each other and only use the host address to create
-                    // a child resource's URI. Note that the collection resource and its child
-                    // resource are located in same host.
-                    newAction->target = getHostFromURI(oit->getUri()) + uri;
-
-                    Capability *newCapability = new Capability();
-                    newCapability->capability = attr;
-                    newCapability->status = getUpdateVal(diag);
-
-                    newAction->listOfCapability.push_back(newCapability);
-                    newActionSet->listOfAction.push_back(newAction);
-                }
-
-                // Request to create a new action set by using the above actionSet
-                g_groupmanager->addActionSet(resource, newActionSet,
-                        std::function<
-                                void(const HeaderOptions& headerOptions,
-                                        const OCRepresentation& rep, const int eCode) >(
-                                std::bind(&ThingsDiagnostics::onCreateActionSet, this,
-                                        std::placeholders::_1, std::placeholders::_2,
-                                        std::placeholders::_3, diag)));
-
-                free(newActionSet);
+                Action *newAction = new Action();
+
+                // oit->getUri() includes a host address as well as URI.
+                // We should split these to each other and only use the host address to create
+                // a child resource's URI. Note that the collection resource and its child
+                // resource are located in same host.
+                newAction->target = getHostFromURI(oit->getUri()) + uri;
 
+                Capability *newCapability = new Capability();
+                newCapability->capability = attr;
+                newCapability->status = getUpdateVal(diag);
+
+                newAction->listOfCapability.push_back(newCapability);
+                newActionSet->listOfAction.push_back(newAction);
             }
 
-        }
-        else
-        {
-            std::cout << "onPut Response error: " << eCode << std::endl;
-            std::exit(-1);
+            // Request to create a new action set by using the above actionSet
+            g_groupmanager->addActionSet(resource, newActionSet,
+                    std::function<
+                            void(const HeaderOptions& headerOptions,
+                                    const OCRepresentation& rep, const int eCode) >(
+                            std::bind(&ThingsDiagnostics::onCreateActionSet, this,
+                                    std::placeholders::_1, std::placeholders::_2,
+                                    std::placeholders::_3, diag)));
+
+            free(newActionSet);
+
         }
     }
 
     void ThingsDiagnostics::onCreateActionSet(const HeaderOptions& headerOptions,
             const OCRepresentation& rep, const int eCode, std::string diag)
     {
-        if (eCode == SUCCESS_RESPONSE)
+        if (eCode != OC_STACK_OK)
         {
-            std::cout << "PUT request was successful" << std::endl;
-
-            std::shared_ptr < OCResource > resource = getResource(diag);
-            if (resource)
-            {
-                // Now, it is time to execute the action set.
-                g_groupmanager->executeActionSet(resource, diag,
-                        std::function<
-                                void(const HeaderOptions& headerOptions,
-                                        const OCRepresentation& rep, const int eCode) >(
-                                std::bind(&ThingsDiagnostics::onExecuteForGroupAction, this,
-                                        std::placeholders::_1, std::placeholders::_2,
-                                        std::placeholders::_3, diag)));
-            }
+            std::cout << "onPut Response error: " << eCode << std::endl;
+            getCallback(diag)(headerOptions, rep, eCode);
+            return ;
         }
-        else
+
+        std::cout << "PUT request was successful" << std::endl;
+
+        std::shared_ptr < OCResource > resource = getResource(diag);
+        if (resource)
         {
-            std::cout << "onPut Response error: " << eCode << std::endl;
-            std::exit(-1);
+            // Now, it is time to execute the action set.
+            g_groupmanager->executeActionSet(resource, diag,
+                    std::function<
+                            void(const HeaderOptions& headerOptions,
+                                    const OCRepresentation& rep, const int eCode) >(
+                            std::bind(&ThingsDiagnostics::onExecuteForGroupAction, this,
+                                    std::placeholders::_1, std::placeholders::_2,
+                                    std::placeholders::_3, diag)));
         }
     }
 
     void ThingsDiagnostics::onExecuteForGroupAction(const HeaderOptions& headerOptions,
             const OCRepresentation& rep, const int eCode, std::string diag)
     {
-        if (eCode == SUCCESS_RESPONSE)
-        {
-            std::cout << "PUT request was successful" << std::endl;
-
-            getCallback(diag)(headerOptions, rep, eCode);
-        }
-        else
+        if (eCode != OC_STACK_OK)
         {
             std::cout << "onPut Response error: " << eCode << std::endl;
-            std::exit(-1);
+            getCallback(diag)(headerOptions, rep, eCode);
+            return ;
         }
+
+        std::cout << "PUT request was successful" << std::endl;
+
+        getCallback(diag)(headerOptions, rep, eCode);
     }
 
     void ThingsDiagnostics::onPut(const HeaderOptions& headerOptions, const OCRepresentation& rep,
             const int eCode, std::string diag)
     {
-        if (eCode == SUCCESS_RESPONSE)
-        {
-            std::cout << "PUT request was successful" << std::endl;
-
-            getCallback(diag)(headerOptions, rep, eCode);
-        }
-        else
+        if (eCode != OC_STACK_OK)
         {
             std::cout << "onPut Response error: " << eCode << std::endl;
-            std::exit(-1);
+            getCallback(diag)(headerOptions, rep, eCode);
+            return ;
         }
+
+        std::cout << "PUT request was successful" << std::endl;
+
+        getCallback(diag)(headerOptions, rep, eCode);
+
     }
 
     bool ThingsDiagnostics::isSimpleResource(std::shared_ptr< OCResource > resource)