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 2232cafc90332b55b36b3d2295a333b9023aad35..f378b101c193fc3ce825a25718a8dfb1c96ce8ef 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 714cd57440c240524b3500ba804f7062a97d6fed..ab7f40b985dc07b51c298c5f9327292abb2224b0 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 c45cb7b937b7bd5d0a3745c65b33f4b08c0e2e7d..264718820cc09133c34b308ca4c499a4c5880f73 100644 (file)
@@ -26,10 +26,12 @@ SoftSensorBundleActivator *bundle;
 
 SoftSensorBundleActivator::SoftSensorBundleActivator()
 {
+    m_pResourceContainer = nullptr;
 }
 
 SoftSensorBundleActivator::~SoftSensorBundleActivator()
 {
+    m_pResourceContainer = nullptr;
 }
 
 void SoftSensorBundleActivator::activateBundle(ResourceContainerBundleAPI *resourceContainer,
index 6b026d9980c1b7a7917eff2f34be509d0e3fe4cc..6adef62f79d9760a65010171a2ce82e3f8be72c0 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 ed091399ff1a0f79d01858eed2b63e001e643f98..942a5160a5c84861dab1a36c316ad33dd2faf44d 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 4cd8a3f1abf1a48cc46080ed55b59b677647c1f0..9130b697533c4ba16306d3d50fb260eb018d86cb 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 f9b504d0985345ed4964664b849eb03a60f6f48b..09d40c34ff7290a82ae883d0586ee52007769e10 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 e2458156172e2a8272488cd5d42dbee7fbb3c6c2..fb5f8566ea79b509d66de020e136f74b7587b6c6 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