Merge branch '1.1-rel'
[platform/upstream/iotivity.git] / service / resource-container / src / ResourceContainerImpl.cpp
index 29e54c0..5042f0c 100644 (file)
@@ -68,58 +68,53 @@ namespace OIC
 
 
             activationLock.lock();
-            if (!configFile.empty())
-            {
-                m_config = new Configuration(configFile);
-
-                if (m_config->isLoaded())
+            try{
+                if (!configFile.empty())
                 {
-                    configInfo bundles;
-                    m_config->getConfiguredBundles(&bundles);
+                    m_config = new Configuration(configFile);
 
-                    for (unsigned int i = 0; i < bundles.size(); i++)
+                    if (m_config->isLoaded())
                     {
-                        shared_ptr<BundleInfoInternal> bundleInfo(new BundleInfoInternal);
-                        bundleInfo->setPath(bundles[i][BUNDLE_PATH]);
-                        bundleInfo->setVersion(bundles[i][BUNDLE_VERSION]);
-                        bundleInfo->setID(bundles[i][BUNDLE_ID]);
-                        if (!bundles[i][BUNDLE_ACTIVATOR].empty())
+                        configInfo bundles;
+                        m_config->getConfiguredBundles(&bundles);
+
+                        for (unsigned int i = 0; i < bundles.size(); i++)
                         {
-                            string activatorName = bundles[i][BUNDLE_ACTIVATOR];
-                            std::replace(activatorName.begin(), activatorName.end(), '.', '/');
-                            bundleInfo->setActivatorName(activatorName);
-                            bundleInfo->setLibraryPath(bundles[i][BUNDLE_LIBRARY_PATH]);
-                        }
+                            shared_ptr<BundleInfoInternal> bundleInfo(new BundleInfoInternal);
+                            bundleInfo->setPath(bundles[i][BUNDLE_PATH]);
+                            bundleInfo->setVersion(bundles[i][BUNDLE_VERSION]);
+                            bundleInfo->setID(bundles[i][BUNDLE_ID]);
+                            if (!bundles[i][BUNDLE_ACTIVATOR].empty())
+                            {
+                                string activatorName = bundles[i][BUNDLE_ACTIVATOR];
+                                std::replace(activatorName.begin(), activatorName.end(), '.', '/');
+                                bundleInfo->setActivatorName(activatorName);
+                                bundleInfo->setLibraryPath(bundles[i][BUNDLE_LIBRARY_PATH]);
+                            }
 
-                        OIC_LOG_V(INFO, CONTAINER_TAG, "Init Bundle:(%s)",
-                                 std::string(bundles[i][BUNDLE_ID] + ";" +
-                                             bundles[i][BUNDLE_PATH]).c_str());
+                            OIC_LOG_V(INFO, CONTAINER_TAG, "Init Bundle:(%s)",
+                                     std::string(bundles[i][BUNDLE_ID] + ";" +
+                                                 bundles[i][BUNDLE_PATH]).c_str());
 
-                        registerBundle(bundleInfo);
-                        activateBundle(bundleInfo);
+                            registerBundle(bundleInfo);
+                            activateBundle(bundleInfo);
+                        }
+                    }
+                    else
+                    {
+                        OIC_LOG_V(ERROR, CONTAINER_TAG, "Container started with invalid configfile path.");
                     }
                 }
                 else
                 {
-                    OIC_LOG_V(ERROR, CONTAINER_TAG, "Container started with invalid configfile path.");
+                    OIC_LOG_V(INFO, CONTAINER_TAG, "No configuration file for the container provided.");
                 }
-            }
-            else
-            {
-                OIC_LOG_V(INFO, CONTAINER_TAG, "No configuration file for the container provided.");
-            }
-
-            map<std::string, boost::thread >::iterator activatorIterator;
 
-            for (activatorIterator = m_activators.begin(); activatorIterator != m_activators.end();
-                 activatorIterator++)
-            {
-                activatorIterator->second.timed_join(
-                    boost::posix_time::seconds(BUNDLE_ACTIVATION_WAIT_SEC));
-                // wait for bundles to be activated
+                OIC_LOG(INFO, CONTAINER_TAG, "Resource container started.");
+            }catch(...){
+                OIC_LOG(INFO, CONTAINER_TAG, "Resource container failed starting.");
             }
             activationLock.unlock();
-            OIC_LOG(INFO, CONTAINER_TAG, "Resource container started.");
         }
 
         void ResourceContainerImpl::stopContainer()
@@ -178,11 +173,15 @@ namespace OIC
         {
             OIC_LOG_V(INFO, CONTAINER_TAG, "Activating bundle: (%s)",
                      std::string(m_bundles[id]->getID()).c_str());
+
             activationLock.lock();
-            auto f = std::bind(&ResourceContainerImpl::activateBundleThread, this,
-                               id);
-            boost::thread activator(f);
-            activator.timed_join(boost::posix_time::seconds(BUNDLE_SET_GET_WAIT_SEC));
+            try{
+                activateBundleThread(id);
+            }
+            catch(...){
+                OIC_LOG_V(INFO, CONTAINER_TAG, "Activating bundle: (%s) failed",
+                                     std::string(m_bundles[id]->getID()).c_str());
+            }
             activationLock.unlock();
             OIC_LOG_V(INFO, CONTAINER_TAG, "Bundle activated: (%s)",
                      std::string(m_bundles[id]->getID()).c_str());
@@ -817,11 +816,10 @@ namespace OIC
         {
             OIC_LOG_V(DEBUG, CONTAINER_TAG, "Discover input resource %s", outputResourceUri.c_str());
             auto foundOutputResource = m_mapResources.find(outputResourceUri);
-           // auto resourceProperty = foundOutputResource->second->m_mapResourceProperty;
 
             resourceInfo info;
             m_config->getResourceConfiguration(foundOutputResource->second->m_bundleId,
-                    foundOutputResource->second->m_name, &info);
+                outputResourceUri, &info);
             map< string, vector< map< string, string > > > resourceProperty = info.resourceProperty;
 
             try
@@ -1002,7 +1000,7 @@ namespace OIC
             options[0].optionString = optionString;
             char classpath[1000];
             strcpy(classpath, "-Djava.class.path=");
-            strcat(classpath, bundleInfo->getPath().c_str());
+            strncat(classpath, bundleInfo->getPath().c_str(), BUNDLE_PATH_MAXLEN);
 
             OIC_LOG(INFO, CONTAINER_TAG,
                    std::string("Configured classpath: ").append(classpath).c_str());
@@ -1011,7 +1009,7 @@ namespace OIC
 
             char libraryPath[1000];
             strcpy(libraryPath, "-Djava.library.path=");
-            strcat(libraryPath, bundleInfo->getLibraryPath().c_str());
+            strncat(libraryPath, bundleInfo->getLibraryPath().c_str(), BUNDLE_PATH_MAXLEN);
             options[2].optionString = libraryPath;
 
             OIC_LOG(INFO, CONTAINER_TAG,