Fix for defects detected by static analysis for resource-container
authorMinji Park <minjii.park@samsung.com>
Thu, 17 Dec 2015 03:02:28 +0000 (12:02 +0900)
committerUze Choi <uzchoi@samsung.com>
Mon, 21 Dec 2015 04:15:27 +0000 (04:15 +0000)
modify resource container sample and unittest to fix defects detected

Change-Id: I7c6520d3ca5d4576f4bf1525e42a9f4e983cca87
Signed-off-by: Minji Park <minjii.park@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/4633
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Madan Lanka <lanka.madan@samsung.com>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
service/resource-container/bundle-api/include/BundleActivator.h
service/resource-container/examples/ContainerSample.cpp
service/resource-container/unittests/ResourceContainerTestSimulator.h

index 937bcf6..928a8fb 100644 (file)
@@ -60,14 +60,14 @@ namespace OIC
                 * @return void
                 */
                 virtual void activateBundle(ResourceContainerBundleAPI *resourceContainer,
-                                            std::string bundleId) { };
+                                            std::string bundleId) = 0;
 
                 /**
                 * Deactivate the Bundle to stop working and destroy bundle resources
                 *
                 * @return void
                 */
-                virtual void deactivateBundle() { };
+                virtual void deactivateBundle() = 0;
 
                 /**
                 * Create Bundle Resource instance and register the resource in the container
index e223629..6e57a86 100644 (file)
 
 #include "RCSResourceContainer.h"
 #include "RCSBundleInfo.h"
-#include "oc_logger.hpp"
 #include <iostream>
+#include <string.h>
 
 using namespace std;
 using namespace OIC::Service;
-using OC::oc_log_stream;
 
 #define MAX_PATH 2048
 
-/* Another way to create a context: */
-auto info_logger = []() -> boost::iostreams::stream<OC::oc_log_stream> &
-{
-    static OC::oc_log_stream ols(oc_make_ostream_logger);
-    static boost::iostreams::stream<OC::oc_log_stream> os(ols);
-    return os;
-};
-
 void getCurrentPath(std::string *pPath)
 {
     char buffer[MAX_PATH];
@@ -63,10 +54,7 @@ void getCurrentPath(std::string *pPath)
 
 int main()
 {
-    info_logger()->set_module("ContainerTest");
-    info_logger()->set_level(OC_LOG_INFO);
-
-    info_logger() << "Starting container test." << std::flush;
+    cout << "Starting container test." << endl;
 
     std::string strConfigPath;
     getCurrentPath(&strConfigPath);
@@ -149,10 +137,10 @@ int main()
     bundleParams["libraryPath"] = ".";
     std::string activator = "org.iotivity.bundle.hue.HueBundleActivator";
     container->addBundle("oic.bundle.hueJavaSample2", "/hueJava",
-                 "../../../../../../service/resource-container/" \
-                 "examples/HueJavaSampleBundle/hue/target/hue-0.1-jar-with-dependencies.jar",
-                 activator,
-                 bundleParams);
+                         "../../../../../../service/resource-container/" \
+                         "examples/HueJavaSampleBundle/hue/target/hue-0.1-jar-with-dependencies.jar",
+                         activator,
+                         bundleParams);
 
     bundles = container->listBundles();
     cout << "\t>>> bundle list size : " << bundles.size() << endl;
index 4d2cf9f..ec57f31 100644 (file)
@@ -66,13 +66,20 @@ class ResourceContainerTestSimulator
 
         ~ResourceContainerTestSimulator()
         {
-            if (remoteResource != nullptr && remoteResource->isCaching())
+            try
             {
-                remoteResource->stopCaching();
+                if (remoteResource != nullptr && remoteResource->isCaching())
+                {
+                    remoteResource->stopCaching();
+                }
+                if (remoteResource != nullptr && remoteResource->isMonitoring())
+                {
+                    remoteResource->stopMonitoring();
+                }
             }
-            if (remoteResource != nullptr && remoteResource->isMonitoring())
+            catch (RCSInvalidParameterException &e)
             {
-                remoteResource->stopMonitoring();
+                std::cout << "exception : " << e.what() << std::endl;
             }
         }
 
@@ -150,7 +157,7 @@ class ResourceContainerTestSimulator
                                               std::weak_ptr<ResourceContainerTestSimulator>(shared_from_this())));
                 mutexForDiscovery.lock();
             }
-            catch (std::exception &e)
+            catch (RCSInvalidParameterException &e)
             {
                 std::cout << "exception : " << e.what() << std::endl;
             }