From: Minji Park Date: Thu, 9 Jul 2015 11:02:06 +0000 (+0900) Subject: Update Resource Container X-Git-Tag: 1.2.0+RC1~1430^2~53 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=eeba1a71bc58ab50382764399edf97e007c42795;p=platform%2Fupstream%2Fiotivity.git Update Resource Container - modify Bundle Resource and samples - update container for checking config file loaded and listresources Change-Id: Ib37cfcfd1f4f24ce9573d744abaed057e0b813ae Signed-off-by: Minji Park Reviewed-on: https://gerrit.iotivity.org/gerrit/1595 Reviewed-by: Uze Choi Tested-by: Uze Choi --- diff --git a/service/resource-manipulation/modules/resourceContainer/bundle-api/include/BundleResource.h b/service/resource-manipulation/modules/resourceContainer/bundle-api/include/BundleResource.h index f45682a..d2e4db4 100644 --- a/service/resource-manipulation/modules/resourceContainer/bundle-api/include/BundleResource.h +++ b/service/resource-manipulation/modules/resourceContainer/bundle-api/include/BundleResource.h @@ -101,6 +101,7 @@ namespace OIC void registerObserver(NotificationReceiver *pNotiReceiver); public: + string m_bundleId; string m_name, m_uri, m_resourceType, m_address; map< string, vector< map< string, string > > > m_mapResourceProperty; diff --git a/service/resource-manipulation/modules/resourceContainer/examples/HueSampleBundle/src/HueSampleBundleActivator.cpp b/service/resource-manipulation/modules/resourceContainer/examples/HueSampleBundle/src/HueSampleBundleActivator.cpp index 9e37e6e..808ee6e 100644 --- a/service/resource-manipulation/modules/resourceContainer/examples/HueSampleBundle/src/HueSampleBundleActivator.cpp +++ b/service/resource-manipulation/modules/resourceContainer/examples/HueSampleBundle/src/HueSampleBundleActivator.cpp @@ -50,7 +50,7 @@ void HueSampleBundleActivator::activateBundle(ResourceContainerBundleAPI *resour resourceContainer->getResourceConfiguration(m_bundleId, &resourceConfig); for (vector< resourceInfo >::iterator itor = resourceConfig.begin(); - itor != resourceConfig.end(); itor++) + itor != resourceConfig.end(); itor++) { createResource(*itor); } @@ -61,7 +61,7 @@ void HueSampleBundleActivator::deactivateBundle() std::cout << "HueSampleBundle::deactivateBundle called" << std::endl; for (std::vector< BundleResource * >::iterator itor = m_vecResources.begin(); - itor != m_vecResources.end(); itor++) + itor != m_vecResources.end(); itor++) { destroyResource(*itor); } @@ -74,9 +74,10 @@ void HueSampleBundleActivator::createResource(resourceInfo resourceInfo) if (resourceInfo.resourceType == "oic.light.control") { static int lightCount = 1; - HueLight* hueLight = new HueLight(m_connector, resourceInfo.address); + HueLight *hueLight = new HueLight(m_connector, resourceInfo.address); resourceInfo.uri = "/hue/light/" + std::to_string(lightCount++); std::cout << "Registering resource " << resourceInfo.uri << std::endl; + hueLight->m_bundleId = m_bundleId; hueLight->m_uri = resourceInfo.uri; hueLight->m_resourceType = resourceInfo.resourceType; hueLight->m_name = resourceInfo.name; @@ -112,7 +113,7 @@ void HueSampleBundleActivator::destroyResource(BundleResource *resource) } extern "C" void externalActivateBundle(ResourceContainerBundleAPI *resourceContainer, - std::string bundleId) + std::string bundleId) { bundle = new HueSampleBundleActivator(); bundle->activateBundle(resourceContainer, bundleId); diff --git a/service/resource-manipulation/modules/resourceContainer/examples/SoftSensorSampleBundle/src/SoftSensorBundleActivator.cpp b/service/resource-manipulation/modules/resourceContainer/examples/SoftSensorSampleBundle/src/SoftSensorBundleActivator.cpp index c59ada1..8fd8a55 100644 --- a/service/resource-manipulation/modules/resourceContainer/examples/SoftSensorSampleBundle/src/SoftSensorBundleActivator.cpp +++ b/service/resource-manipulation/modules/resourceContainer/examples/SoftSensorSampleBundle/src/SoftSensorBundleActivator.cpp @@ -85,6 +85,8 @@ void SoftSensorBundleActivator::createResource(resourceInfo resourceInfo) // create DISensor resource DiscomfortIndexSensorResource *newResource = new DiscomfortIndexSensorResource(inputs); + newResource->m_bundleId = m_bundleId; + newResource->m_uri = "/softsensor/discomfortIndex/" + std::to_string( discomfortIndexSensorCount++); newResource->m_resourceType = resourceInfo.resourceType; diff --git a/service/resource-manipulation/modules/resourceContainer/include/internal/ResourceContainerImpl.h b/service/resource-manipulation/modules/resourceContainer/include/internal/ResourceContainerImpl.h index afaf1e7..b89dca3 100644 --- a/service/resource-manipulation/modules/resourceContainer/include/internal/ResourceContainerImpl.h +++ b/service/resource-manipulation/modules/resourceContainer/include/internal/ResourceContainerImpl.h @@ -95,6 +95,7 @@ namespace OIC map< std::string, BundleInfoInternal * > m_bundles; // map< std::string, ResourceObject::Ptr > m_mapServers; // map< std::string, BundleResource * > m_mapResources; // + map< std::string, list > m_mapBundleResources; //> string m_configFile; Configuration *m_config = NULL; map m_bundleVM; diff --git a/service/resource-manipulation/modules/resourceContainer/src/BundleInfoInternal.cpp b/service/resource-manipulation/modules/resourceContainer/src/BundleInfoInternal.cpp index eb07d02..f79bd27 100644 --- a/service/resource-manipulation/modules/resourceContainer/src/BundleInfoInternal.cpp +++ b/service/resource-manipulation/modules/resourceContainer/src/BundleInfoInternal.cpp @@ -30,6 +30,9 @@ namespace OIC m_activator = nullptr; m_deactivator = nullptr; m_bundleHandle = nullptr; + + m_loaded = false; + m_activated = false; } BundleInfoInternal::~BundleInfoInternal() @@ -178,7 +181,8 @@ namespace OIC return m_java_activator_object; } - void BundleInfoInternal::setBundleInfo(BundleInfo* bundleInfo){ + void BundleInfoInternal::setBundleInfo(BundleInfo *bundleInfo) + { m_ID = bundleInfo->getID(); m_path = bundleInfo->getPath(); m_version = bundleInfo->getPath(); diff --git a/service/resource-manipulation/modules/resourceContainer/src/ResourceContainerImpl.cpp b/service/resource-manipulation/modules/resourceContainer/src/ResourceContainerImpl.cpp index cb3a496..ff86b83 100644 --- a/service/resource-manipulation/modules/resourceContainer/src/ResourceContainerImpl.cpp +++ b/service/resource-manipulation/modules/resourceContainer/src/ResourceContainerImpl.cpp @@ -83,26 +83,34 @@ namespace OIC info_logger() << "Starting resource container" << endl; m_config = new Configuration(configFile); - configInfo bundles; - m_config->getConfiguredBundles(&bundles); - for (int i = 0; i < bundles.size(); i++) + if (m_config->isLoaded()) { - BundleInfo *bundleInfo = BundleInfo::build(); - bundleInfo->setPath(bundles[i]["path"]); - bundleInfo->setVersion(bundles[i]["version"]); - bundleInfo->setID(bundles[i]["id"]); - if (!bundles[i]["activator"].empty()) + configInfo bundles; + m_config->getConfiguredBundles(&bundles); + + for (int i = 0; i < bundles.size(); i++) { - string activatorName = bundles[i]["activator"]; - std::replace(activatorName.begin(), activatorName.end(), '.', '/'); - ((BundleInfoInternal *) bundleInfo)->setActivatorName(activatorName); + BundleInfo *bundleInfo = BundleInfo::build(); + bundleInfo->setPath(bundles[i]["path"]); + bundleInfo->setVersion(bundles[i]["version"]); + bundleInfo->setID(bundles[i]["id"]); + if (!bundles[i]["activator"].empty()) + { + string activatorName = bundles[i]["activator"]; + std::replace(activatorName.begin(), activatorName.end(), '.', '/'); + ((BundleInfoInternal *) bundleInfo)->setActivatorName(activatorName); + } + info_logger() << "Init Bundle:" << bundles[i]["id"] << ";" << bundles[i]["path"] + << endl; + registerBundle(bundleInfo); + activateBundle(bundleInfo); } - info_logger() << "Init Bundle:" << bundles[i]["id"] << ";" << bundles[i]["path"] - << endl; - registerBundle(bundleInfo); - activateBundle(bundleInfo); + } + else + { + error_logger() << "Container started with invalid configfile path" << endl;; } } @@ -149,7 +157,6 @@ namespace OIC { activateSoBundle(id); } - m_bundles[id]->setActivated(true); info_logger() << "Bundle activated: " << m_bundles[id]->getID() << endl; @@ -166,7 +173,6 @@ namespace OIC { deactivateSoBundle(id); } - m_bundles[id]->setActivated(false); } // loads the bundle @@ -208,6 +214,10 @@ namespace OIC { error_logger() << error << endl; } + else + { + m_bundles.erase(id); + } } void ResourceContainerImpl::registerResource(BundleResource *resource) @@ -226,6 +236,7 @@ namespace OIC { m_mapServers[strUri] = server; m_mapResources[strUri] = resource; + m_mapBundleResources[resource->m_bundleId].push_back(strUri); resource->registerObserver(this); @@ -251,6 +262,7 @@ namespace OIC { m_mapServers[strUri].reset(); m_mapResources.erase(m_mapResources.find(strUri)); + m_mapBundleResources[resource->m_bundleId].remove(strUri); } } @@ -380,10 +392,9 @@ namespace OIC { std::list< string > ret; - for (map ::iterator itor = m_mapResources.begin(); - itor != m_mapResources.end(); itor++) + if (m_mapBundleResources.find(bundleId) != m_mapBundleResources.end()) { - ret.push_back(itor->first); + ret = m_mapBundleResources[bundleId]; } return ret; @@ -531,6 +542,8 @@ namespace OIC env->CallVoidMethod(bundleInfoInternal->getJavaBundleActivatorObject(), bundleInfoInternal->getJavaBundleActivatorMethod()); + + m_bundles[bundleId]->setActivated(true); } void ResourceContainerImpl::activateSoBundle(string bundleId) @@ -574,6 +587,8 @@ namespace OIC env->CallVoidMethod(bundleInfoInternal->getJavaBundleActivatorObject(), bundleInfoInternal->getJavaBundleDeactivatorMethod()); + + m_bundles[bundleId]->setActivated(false); } void ResourceContainerImpl::deactivateSoBundle(string id)