resourceContainer->getResourceConfiguration(m_bundleId, &resourceConfig);
for (vector< resourceInfo >::iterator itor = resourceConfig.begin();
- itor != resourceConfig.end(); itor++)
+ itor != resourceConfig.end(); itor++)
{
createResource(*itor);
}
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);
}
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;
}
extern "C" void externalActivateBundle(ResourceContainerBundleAPI *resourceContainer,
- std::string bundleId)
+ std::string bundleId)
{
bundle = new HueSampleBundleActivator();
bundle->activateBundle(resourceContainer, bundleId);
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;;
}
}
{
activateSoBundle(id);
}
- m_bundles[id]->setActivated(true);
info_logger() << "Bundle activated: " << m_bundles[id]->getID() << endl;
{
deactivateSoBundle(id);
}
- m_bundles[id]->setActivated(false);
}
// loads the bundle
{
error_logger() << error << endl;
}
+ else
+ {
+ m_bundles.erase(id);
+ }
}
void ResourceContainerImpl::registerResource(BundleResource *resource)
{
m_mapServers[strUri] = server;
m_mapResources[strUri] = resource;
+ m_mapBundleResources[resource->m_bundleId].push_back(strUri);
resource->registerObserver(this);
{
m_mapServers[strUri].reset();
m_mapResources.erase(m_mapResources.find(strUri));
+ m_mapBundleResources[resource->m_bundleId].remove(strUri);
}
}
{
std::list< string > ret;
- for (map <string, BundleResource *>::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;
env->CallVoidMethod(bundleInfoInternal->getJavaBundleActivatorObject(),
bundleInfoInternal->getJavaBundleActivatorMethod());
+
+ m_bundles[bundleId]->setActivated(true);
}
void ResourceContainerImpl::activateSoBundle(string bundleId)
env->CallVoidMethod(bundleInfoInternal->getJavaBundleActivatorObject(),
bundleInfoInternal->getJavaBundleDeactivatorMethod());
+
+ m_bundles[bundleId]->setActivated(false);
}
void ResourceContainerImpl::deactivateSoBundle(string id)