resource-encapsulation: fix prevent issue for container
authorMinji Park <minjii.park@samsung.com>
Mon, 3 Aug 2015 11:35:54 +0000 (20:35 +0900)
committerMadan Lanka <lanka.madan@samsung.com>
Mon, 3 Aug 2015 14:14:07 +0000 (14:14 +0000)
- fix prevent issues
- modify unit test SConscript for executing unit test with TEST=1 option

Change-Id: I226bd2cdfb1f040d209bb5e35e08b812be456793
Signed-off-by: Minji Park <minjii.park@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/2070
Reviewed-by: Hun-je Yeon <hunje.yeon@samsung.com>
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Markus Jung <markus.jung@samsung.com>
Reviewed-by: Madan Lanka <lanka.madan@samsung.com>
Tested-by: Madan Lanka <lanka.madan@samsung.com>
service/resource-encapsulation/src/resourceContainer/examples/HueSampleBundle/src/HueLight.cpp
service/resource-encapsulation/src/resourceContainer/examples/HueSampleBundle/src/HueSampleBundleActivator.cpp
service/resource-encapsulation/src/resourceContainer/examples/SoftSensorSampleBundle/src/SoftSensorBundleActivator.cpp
service/resource-encapsulation/src/resourceContainer/src/BundleInfoInternal.cpp
service/resource-encapsulation/src/resourceContainer/src/BundleResource.cpp
service/resource-encapsulation/src/resourceContainer/src/Configuration.cpp
service/resource-encapsulation/src/resourceContainer/src/ResourceContainerImpl.cpp
service/resource-encapsulation/src/resourceContainer/unittests/SConscript

index 2232caf..f378b10 100644 (file)
@@ -27,7 +27,7 @@ using namespace OIC::Service;
 
 HueLight::HueLight()
 {
-
+    m_connector = nullptr;
 }
 
 HueLight::HueLight(HueConnector *connector, std::string address)
@@ -39,7 +39,7 @@ HueLight::HueLight(HueConnector *connector, std::string address)
 
 HueLight::~HueLight()
 {
-
+    m_connector = nullptr;
 }
 
 void HueLight::initAttributes()
index 714cd57..ab7f40b 100644 (file)
@@ -30,10 +30,14 @@ HueSampleBundleActivator *bundle;
 
 HueSampleBundleActivator::HueSampleBundleActivator()
 {
+    m_pResourceContainer = nullptr;
+    m_connector = nullptr;
 }
 
 HueSampleBundleActivator::~HueSampleBundleActivator()
 {
+    m_pResourceContainer = nullptr;
+    m_connector = nullptr;
 }
 
 void HueSampleBundleActivator::activateBundle(ResourceContainerBundleAPI *resourceContainer,
index c45cb7b..2647188 100644 (file)
@@ -26,10 +26,12 @@ SoftSensorBundleActivator *bundle;
 
 SoftSensorBundleActivator::SoftSensorBundleActivator()
 {
+    m_pResourceContainer = nullptr;
 }
 
 SoftSensorBundleActivator::~SoftSensorBundleActivator()
 {
+    m_pResourceContainer = nullptr;
 }
 
 void SoftSensorBundleActivator::activateBundle(ResourceContainerBundleAPI *resourceContainer,
index 6b026d9..6adef62 100644 (file)
@@ -29,16 +29,22 @@ namespace OIC
         {
             m_activator = nullptr;
             m_deactivator = nullptr;
+            m_resourceCreator = nullptr;
+            m_resourceDestroyer = nullptr;
             m_bundleHandle = nullptr;
 
             m_loaded = false;
             m_activated = false;
+            m_java_bundle = false;
+            m_id = 0;
         }
 
         BundleInfoInternal::~BundleInfoInternal()
         {
             m_activator = nullptr;
             m_deactivator = nullptr;
+            m_resourceCreator = nullptr;
+            m_resourceDestroyer = nullptr;
             m_bundleHandle = nullptr;
         }
 
@@ -205,9 +211,15 @@ namespace OIC
 
         void BundleInfoInternal::setBundleInfo(RCSBundleInfo *bundleInfo)
         {
-            m_ID = bundleInfo->getID();
-            m_path = bundleInfo->getPath();
-            m_version = bundleInfo->getPath();
+            BundleInfoInternal *source = (BundleInfoInternal *)bundleInfo;
+            m_ID = source->getID();
+            m_path = source->getPath();
+            m_version = source->getVersion();
+            m_loaded = source->isLoaded();
+            m_activated = source->isActivated();
+            m_java_bundle = source->getJavaBundle();
+            m_activator = source->getBundleActivator();
+            m_bundleHandle = source->getBundleHandle();
         }
     }
 }
index ed09139..942a516 100644 (file)
@@ -29,12 +29,12 @@ namespace OIC
     {
         BundleResource::BundleResource()
         {
-
+            m_pNotiReceiver = nullptr;
         }
 
         BundleResource::~BundleResource()
         {
-
+            m_pNotiReceiver = nullptr;
         }
 
         void BundleResource::registerObserver(NotificationReceiver *pNotiReceiver)
@@ -45,23 +45,27 @@ namespace OIC
         std::list< string > BundleResource::getAttributeNames()
         {
             std::list< string > ret;
-            for (RCSResourceAttributes::iterator it = m_resourceAttributes.begin(); it != m_resourceAttributes.end(); ++it){
+            for (RCSResourceAttributes::iterator it = m_resourceAttributes.begin();
+                 it != m_resourceAttributes.end(); ++it)
+            {
                 ret.push_back(it->key());
             }
             return ret;
         }
 
-        RCSResourceAttributes& BundleResource::getAttributes(){
+        RCSResourceAttributes &BundleResource::getAttributes()
+        {
             return m_resourceAttributes;
         }
 
-        void BundleResource::setAttribute(std::string key, RCSResourceAttributes::Value&& value)
+        void BundleResource::setAttribute(std::string key, RCSResourceAttributes::Value &&value)
         {
             cout << "Bundle resource set attribute " << value.toString() << "|" << endl;
             m_resourceAttributes[key] = value;
         }
 
-        RCSResourceAttributes::Value BundleResource::getAttribute(const std::string& key){
+        RCSResourceAttributes::Value BundleResource::getAttribute(const std::string &key)
+        {
             cout << "Bundle resource get attribute " << m_resourceAttributes.at(key).toString() << "|" << endl;
             return m_resourceAttributes.at(key);
         }
index 4cd8a3f..9130b69 100644 (file)
@@ -269,13 +269,16 @@ namespace OIC
 
             int length = readlink("/proc/self/exe", buffer, 2047);
 
-            buffer[length] = '\0';
+            if (length > 0 && length < 2047)
+            {
+                buffer[length] = '\0';
 
-            strPath = strrchr(buffer, '/');
+                strPath = strrchr(buffer, '/');
 
-            *strPath = '\0';
+                *strPath = '\0';
 
-            pPath->append(buffer);
+                pPath->append(buffer);
+            }
         }
     }
 }
index f9b504d..09d40c3 100644 (file)
@@ -88,7 +88,8 @@ namespace OIC
             info_logger() << "Resource container without Java support" << endl;
 #endif
 
-            if(!configFile.empty()){
+            if (!configFile.empty())
+            {
                 m_config = new Configuration(configFile);
 
                 if (m_config->isLoaded())
@@ -122,7 +123,8 @@ namespace OIC
                     error_logger() << "Container started with invalid configfile path" << endl;
                 }
             }
-            else{
+            else
+            {
                 info_logger() << "No configuration file for the container provided" << endl;
             }
         }
@@ -391,8 +393,8 @@ namespace OIC
             return &m_instance;
         }
 
-        RCSResourceObject::Ptr ResourceContainerImpl::buildResourceObject(const std::string & strUri,
-                const std::string & strResourceType)
+        RCSResourceObject::Ptr ResourceContainerImpl::buildResourceObject(const std::string &strUri,
+                const std::string &strResourceType)
         {
             return RCSResourceObject::Builder(strUri, strResourceType, "DEFAULT_INTERFACE").setObservable(
                        true).setDiscoverable(true).build();
@@ -428,7 +430,8 @@ namespace OIC
             }
         }
 
-        void ResourceContainerImpl::addBundle(const std::string &bundleId, const std::string &bundleUri, const std::string &bundlePath,
+        void ResourceContainerImpl::addBundle(const std::string &bundleId, const std::string &bundleUri,
+                                              const std::string &bundlePath,
                                               std::map< string, string > params)
         {
             if (m_bundles.find(bundleId) != m_bundles.end())
@@ -481,13 +484,14 @@ namespace OIC
                 {
                     RCSBundleInfo *bundleInfo = RCSBundleInfo::build();
                     ((BundleInfoInternal *) bundleInfo)->setBundleInfo((RCSBundleInfo *) it->second);
-                    ret.push_back(it->second);
+                    ret.push_back(bundleInfo);
                 }
             }
             return ret;
         }
 
-        void ResourceContainerImpl::addResourceConfig(const std::string &bundleId, const std::string &resourceUri,
+        void ResourceContainerImpl::addResourceConfig(const std::string &bundleId,
+                const std::string &resourceUri,
                 std::map< string, string > params)
         {
             if (m_bundles.find(bundleId) != m_bundles.end())
@@ -514,7 +518,8 @@ namespace OIC
             }
         }
 
-        void ResourceContainerImpl::removeResourceConfig(const std::string &bundleId, const std::string &resourceUri)
+        void ResourceContainerImpl::removeResourceConfig(const std::string &bundleId,
+                const std::string &resourceUri)
         {
             if (m_bundles.find(bundleId) != m_bundles.end())
             {
@@ -645,7 +650,8 @@ namespace OIC
             }
         }
 
-        void ResourceContainerImpl::removeSoBundleResource(const std::string &bundleId, const std::string &resourceUri)
+        void ResourceContainerImpl::removeSoBundleResource(const std::string &bundleId,
+                const std::string &resourceUri)
         {
             if (m_mapResources.find(resourceUri) != m_mapResources.end())
             {
index e245815..fb5f856 100644 (file)
@@ -175,3 +175,11 @@ Command("./ResourceContainerInvalidConfig.xml","./ResourceContainerInvalidConfig
 Ignore("./ResourceContainerInvalidConfig.xml", "./ResourceContainerInvalidConfig.xml")
 Command("./TestBundleJava/hue-0.1-jar-with-dependencies.jar","./TestBundleJava/hue-0.1-jar-with-dependencies.jar", Copy("$TARGET", "$SOURCE"))
 Ignore("./TestBundleJava/hue-0.1-jar-with-dependencies.jar", "./TestBundleJava/hue-0.1-jar-with-dependencies.jar")
+
+if env.get('TEST') == '1':
+       target_os = env.get('TARGET_OS')
+       if target_os == 'linux':
+               from tools.scons.RunTest import *
+               run_test(container_gtest_env,
+                       '',
+                       'service/resource-encapsulation/src/resourceContainer/unittests/container_test')
\ No newline at end of file