* @return void
*/
virtual void deactivateBundle();
+
+ virtual void createResource(resourceInfo resourceInfo) = 0;
+
+ virtual void destroyResource(BundleResource *pBundleResource) = 0;
};
}
}
{
class HueSampleBundleActivator: public BundleActivator
{
- public:
- HueSampleBundleActivator();
- ~HueSampleBundleActivator();
-
- void activateBundle(ResourceContainerBundleAPI *resourceContainer,
- std::string bundleId);
- void deactivateBundle();
-
- void createResource(resourceInfo);
- void destroyResource(BundleResource *);
-
- std::string m_bundleId;
- ResourceContainerBundleAPI *m_pResourceContainer;
- std::vector< BundleResource * > m_vecResources;
- private:
- HueConnector* m_connector;
+ public:
+ HueSampleBundleActivator();
+ ~HueSampleBundleActivator();
+
+ void activateBundle(ResourceContainerBundleAPI *resourceContainer,
+ std::string bundleId);
+ void deactivateBundle();
+
+ void createResource(resourceInfo resourceInfo);
+ void destroyResource(BundleResource *pBundleResource);
+
+ std::string m_bundleId;
+ ResourceContainerBundleAPI *m_pResourceContainer;
+ std::vector< BundleResource * > m_vecResources;
+ private:
+ HueConnector *m_connector;
};
}
}
-#endif /* SAMPLEBUNDLE_H_ */
+#endif /* HUESAMPLEBUNDLEACTIVATOR_H_ */
{
std::cout << "HueSampleBundle::deactivateBundle called" << std::endl;
- for (std::vector< BundleResource * >::iterator itor = m_vecResources.begin();
- itor != m_vecResources.end(); itor++)
+ for (unsigned int i = 0; i < m_vecResources.size(); i++)
{
- destroyResource(*itor);
+ destroyResource(m_vecResources.at(i));
}
+
+ delete m_connector;
}
void HueSampleBundleActivator::createResource(resourceInfo resourceInfo)
}
}
-void HueSampleBundleActivator::destroyResource(BundleResource *resource)
+void HueSampleBundleActivator::destroyResource(BundleResource *pBundleResource)
{
- std::cout << "HueSampleBundle::destroyResource called" << resource->m_uri << std::endl;
+ std::cout << "HueSampleBundle::destroyResource called" << pBundleResource->m_uri << std::endl;
std::vector< BundleResource * >::iterator itor;
- itor = std::find(m_vecResources.begin(), m_vecResources.end(), resource);
+ itor = std::find(m_vecResources.begin(), m_vecResources.end(), pBundleResource);
if (itor != m_vecResources.end())
{
- m_pResourceContainer->unregisterResource(resource);
+ m_pResourceContainer->unregisterResource(pBundleResource);
+ m_vecResources.erase(itor);
}
//TODO
// check
//delete resource;
-
}
extern "C" void externalActivateBundle(ResourceContainerBundleAPI *resourceContainer,
extern "C" void externalDeactivateBundle()
{
bundle->deactivateBundle();
+ delete bundle;
+}
+
+extern "C" void externalCreateResource(resourceInfo resourceInfo)
+{
+ bundle->createResource(resourceInfo);
+}
+
+extern "C" void externalDestroyResource(BundleResource *pBundleResource)
+{
+ bundle->destroyResource(pBundleResource);
}
</bundle>
<bundle>
<id>oic.bundle.hueJavaSample</id>
- <path>../../../../../../../../service/resource-manipulation/modules/resourceContainer/examples/HueJavaSampleBundle/hue/target/hue-0.1-SNAPSHOT-jar-with-dependencies.jar </path>
+ <path>../../../../../../../../service/resource-manipulation/src/resourceContainer/examples/HueJavaSampleBundle/hue/target/hue-0.1-jar-with-dependencies.jar</path>
<libraryPath>.</libraryPath>
<uri>/hueJava</uri>
<activator>org.iotivity.bundle.hue.HueBundleActivator</activator>
void activateBundle(ResourceContainerBundleAPI *resourceContainer, std::string bundleId);
void deactivateBundle();
- void createResource(resourceInfo);
- void destroyResource(BundleResource *);
+ void createResource(resourceInfo resourceInfo);
+ void destroyResource(BundleResource *pBundleResource);
std::string m_bundleId;
ResourceContainerBundleAPI *m_pResourceContainer;
{
std::cout << "SoftSensorSampleBundle::deactivateBundle called" << std::endl;
- for (std::vector<BundleResource *>::iterator itor = m_vecResources.begin();
- itor != m_vecResources.end(); itor++)
+ for (unsigned int i = 0; i < m_vecResources.size(); i++)
{
- destroyResource(*itor);
+ destroyResource(m_vecResources.at(i));
}
-
- m_vecResources.clear();
}
void SoftSensorBundleActivator::createResource(resourceInfo resourceInfo)
{
std::cout << "SoftSensorSampleBundle::createResource called" << std::endl;
- static int discomfortIndexSensorCount = 1;
+ if (resourceInfo.resourceType == "oic.softsensor")
+ {
+ static int discomfortIndexSensorCount = 1;
- std::vector< std::map< std::string, std::string > >::iterator itor_vec;
- std::map< std::string, std::string >::iterator itor_map;
- std::vector <std::string> inputs;
+ std::vector< std::map< std::string, std::string > >::iterator itor_vec;
+ std::map< std::string, std::string >::iterator itor_map;
+ std::vector <std::string> inputs;
- for (itor_vec = resourceInfo.resourceProperty["input"].begin();
- itor_vec != resourceInfo.resourceProperty["input"].end(); itor_vec++)
- {
- for (itor_map = (*itor_vec).begin(); itor_map != (*itor_vec).end(); itor_map++)
+ for (itor_vec = resourceInfo.resourceProperty["input"].begin();
+ itor_vec != resourceInfo.resourceProperty["input"].end(); itor_vec++)
{
- inputs.push_back(itor_map->second);
+ for (itor_map = (*itor_vec).begin(); itor_map != (*itor_vec).end(); itor_map++)
+ {
+ inputs.push_back(itor_map->second);
+ }
}
- }
- std::cout << "SoftSensorSampleBundle::creating new discomfort index sensor " << std::endl;
- // create DISensor resource
- DiscomfortIndexSensorResource *newResource = new DiscomfortIndexSensorResource(inputs);
+ std::cout << "SoftSensorSampleBundle::creating new discomfort index sensor " << std::endl;
+ // create DISensor resource
+ DiscomfortIndexSensorResource *newResource = new DiscomfortIndexSensorResource(inputs);
- newResource->m_bundleId = m_bundleId;
+ newResource->m_bundleId = m_bundleId;
+ newResource->m_uri = "/softsensor/discomfortIndex/" + std::to_string(
+ discomfortIndexSensorCount++);
+ newResource->m_resourceType = resourceInfo.resourceType;
+ newResource->m_mapResourceProperty = resourceInfo.resourceProperty;
- newResource->m_uri = "/softsensor/discomfortIndex/" + std::to_string(
- discomfortIndexSensorCount++);
- newResource->m_resourceType = resourceInfo.resourceType;
- newResource->m_mapResourceProperty = resourceInfo.resourceProperty;
+ // setting input Attributes count
+ newResource->inputCount = newResource->m_mapResourceProperty["input"].size();
- // setting input Attributes count
- newResource->inputCount = newResource->m_mapResourceProperty["input"].size();
-
- m_pResourceContainer->registerResource(newResource);
- m_vecResources.push_back(newResource);
+ m_pResourceContainer->registerResource(newResource);
+ m_vecResources.push_back(newResource);
+ }
}
void SoftSensorBundleActivator::destroyResource(BundleResource *resource)
if (itor != m_vecResources.end())
{
m_pResourceContainer->unregisterResource(resource);
+ m_vecResources.erase(itor);
}
-
- //TODO
- /*std::cout << "Clearing up memory.\n";*/
}
extern "C" void externalActivateBundle(ResourceContainerBundleAPI *resourceContainer,
extern "C" void externalDeactivateBundle()
{
bundle->deactivateBundle();
+ delete bundle;
+}
+
+extern "C" void externalCreateResource(resourceInfo resourceInfo)
+{
+ bundle->createResource(resourceInfo);
+}
+
+extern "C" void externalDestroyResource(BundleResource *pBundleResource)
+{
+ bundle->destroyResource(pBundleResource);
}
using namespace std;
using namespace OIC::Service;
-namespace OIC{
- namespace Service{
-
+namespace OIC
+{
+ namespace Service
+ {
typedef void activator_t(ResourceContainerBundleAPI *, std::string bundleId);
typedef void deactivator_t(void);
+ typedef void resourceCreator_t(resourceInfo resourceInfo);
+ typedef void resourceDestroyer_t(BundleResource *pBundleResource);
class BundleInfoInternal: public BundleInfo
{
void setBundleDeactivator(deactivator_t *);
deactivator_t *getBundleDeactivator();
+ void setResourceCreator(resourceCreator_t *);
+ resourceCreator_t *getResourceCreator();
+
+ void setResourceDestroyer(resourceDestroyer_t *);
+ resourceDestroyer_t *getResourceDestroyer();
+
void setBundleHandle(void *);
void *getBundleHandle();
void setJavaBundle(bool javaBundle);
bool getJavaBundle();
- void setBundleInfo(BundleInfo* bundleInfo);
+ void setBundleInfo(BundleInfo *bundleInfo);
private:
bool m_loaded, m_activated, m_java_bundle;
int m_id;
activator_t *m_activator;
deactivator_t *m_deactivator;
+ resourceCreator_t *m_resourceCreator;
+ resourceDestroyer_t *m_resourceDestroyer;
void *m_bundleHandle;
string m_activator_name;
jmethodID m_java_activator, m_java_deactivator;
void activateSoBundle(string bundleId);
void deactivateJavaBundle(string bundleId);
void deactivateSoBundle(string bundleId);
+ void addSoBundleResource(string bundleId, resourceInfo newResourceInfo);
+ void removeSoBundleResource(string bundleId, string resourceUri);
};
}
}
return m_deactivator;
}
+ void BundleInfoInternal::setResourceCreator(resourceCreator_t *resourceCreator)
+ {
+ m_resourceCreator = resourceCreator;
+ }
+
+ resourceCreator_t *BundleInfoInternal::getResourceCreator()
+ {
+ return m_resourceCreator;
+ }
+
+ void BundleInfoInternal::setResourceDestroyer(resourceDestroyer_t *resourceDestroyer)
+ {
+ m_resourceDestroyer = resourceDestroyer;
+ }
+
+ resourceDestroyer_t *BundleInfoInternal::getResourceDestroyer()
+ {
+ return m_resourceDestroyer;
+ }
+
void BundleInfoInternal::setBundleHandle(void *handle)
{
m_bundleHandle = handle;
return m_activator_name;
}
- void BundleInfoInternal::setLibraryPath(string libpath){
+ void BundleInfoInternal::setLibraryPath(string libpath)
+ {
m_library_path = libpath;
}
- string BundleInfoInternal::getLibraryPath(){
+ string BundleInfoInternal::getLibraryPath()
+ {
return m_library_path;
}
string strKey, strValue;
- try
+ if (m_loaded)
{
- //cout << "Name of first node is: " << m_xmlDoc.first_node()->name() << endl;
-
- for (bundle = m_xmlDoc.first_node()->first_node("bundle"); bundle; bundle = bundle->next_sibling())
+ try
{
- std::map< std::string, std::string > bundleMap;
- //cout << "Bundle: " << bundle->name() << endl;
- for (subItem = bundle->first_node(); subItem; subItem = subItem->next_sibling())
- {
- strKey = subItem->name();
- strValue = subItem->value();
+ //cout << "Name of first node is: " << m_xmlDoc.first_node()->name() << endl;
- if (strlen(subItem->value()) > 0)
+ for (bundle = m_xmlDoc.first_node()->first_node("bundle"); bundle; bundle = bundle->next_sibling())
+ {
+ std::map< std::string, std::string > bundleMap;
+ //cout << "Bundle: " << bundle->name() << endl;
+ for (subItem = bundle->first_node(); subItem; subItem = subItem->next_sibling())
{
- bundleMap.insert(std::make_pair(trim_both(strKey), trim_both(strValue)));
- //cout << strKey << " " << strValue << endl;
+ strKey = subItem->name();
+ strValue = subItem->value();
+
+ if (strlen(subItem->value()) > 0)
+ {
+ bundleMap.insert(std::make_pair(trim_both(strKey), trim_both(strValue)));
+ //cout << strKey << " " << strValue << endl;
+ }
}
+ configOutput->push_back(bundleMap);
}
- configOutput->push_back(bundleMap);
- }
- }
- catch (rapidxml::parse_error &e)
- {
- cout << "xml parsing failed !!" << endl;
- cout << e.what() << endl;
+ }
+ catch (rapidxml::parse_error &e)
+ {
+ cout << "xml parsing failed !!" << endl;
+ cout << e.what() << endl;
+ }
}
}
string strBundleId, strPath, strVersion;
- try
+ if (m_loaded)
{
- std::map< std::string, std::string > bundleConfigMap;
-
- // <bundle>
- for (bundle = m_xmlDoc.first_node()->first_node("bundle"); bundle; bundle = bundle->next_sibling())
+ try
{
- // <id>
- strBundleId = bundle->first_node("id")->value();
+ std::map< std::string, std::string > bundleConfigMap;
- if (!strBundleId.compare(bundleId))
+ // <bundle>
+ for (bundle = m_xmlDoc.first_node()->first_node("bundle"); bundle; bundle = bundle->next_sibling())
{
- bundleConfigMap.insert(std::make_pair("id", trim_both(strBundleId)));
+ // <id>
+ strBundleId = bundle->first_node("id")->value();
- // <path>
- strPath = bundle->first_node("path")->value();
- bundleConfigMap.insert(std::make_pair("path", trim_both(strPath)));
+ if (!strBundleId.compare(bundleId))
+ {
+ bundleConfigMap.insert(std::make_pair("id", trim_both(strBundleId)));
+
+ // <path>
+ strPath = bundle->first_node("path")->value();
+ bundleConfigMap.insert(std::make_pair("path", trim_both(strPath)));
- // <version>
- strVersion = bundle->first_node("version")->value();
- bundleConfigMap.insert(std::make_pair("version", trim_both(strVersion)));
+ // <version>
+ strVersion = bundle->first_node("version")->value();
+ bundleConfigMap.insert(std::make_pair("version", trim_both(strVersion)));
- configOutput->push_back(bundleConfigMap);
+ configOutput->push_back(bundleConfigMap);
- break;
+ break;
+ }
}
}
- }
- catch (rapidxml::parse_error &e)
- {
- cout << "xml parsing failed !!" << endl;
- cout << e.what() << endl;
+ catch (rapidxml::parse_error &e)
+ {
+ cout << "xml parsing failed !!" << endl;
+ cout << e.what() << endl;
+ }
}
}
string strBundleId;
string strKey, strValue;
- try
+ if (m_loaded)
{
- // <bundle>
- for (bundle = m_xmlDoc.first_node()->first_node("bundle"); bundle; bundle = bundle->next_sibling())
+ try
{
- // <id>
- strBundleId = bundle->first_node("id")->value();
-
- if (!strBundleId.compare(bundleId))
+ // <bundle>
+ for (bundle = m_xmlDoc.first_node()->first_node("bundle"); bundle; bundle = bundle->next_sibling())
{
- // <resourceInfo>
- for (resource = bundle->first_node("resources")->first_node("resourceInfo"); resource;
- resource = resource->next_sibling())
- {
- resourceInfo tempResourceInfo;
+ // <id>
+ strBundleId = bundle->first_node("id")->value();
- for (item = resource->first_node(); item; item = item->next_sibling())
+ if (!strBundleId.compare(bundleId))
+ {
+ // <resourceInfo>
+ for (resource = bundle->first_node("resources")->first_node("resourceInfo"); resource;
+ resource = resource->next_sibling())
{
- strKey = item->name();
- strValue = item->value();
+ resourceInfo tempResourceInfo;
- if (!strKey.compare("name"))
- tempResourceInfo.name = trim_both(strValue);
+ for (item = resource->first_node(); item; item = item->next_sibling())
+ {
+ strKey = item->name();
+ strValue = item->value();
- else if (!strKey.compare("uri"))
- tempResourceInfo.uri = trim_both(strValue);
+ if (!strKey.compare("name"))
+ tempResourceInfo.name = trim_both(strValue);
- else if (!strKey.compare("address"))
- tempResourceInfo.address = trim_both(strValue);
+ else if (!strKey.compare("uri"))
+ tempResourceInfo.uri = trim_both(strValue);
- else if (!strKey.compare("resourceType"))
- tempResourceInfo.resourceType = trim_both(strValue);
+ else if (!strKey.compare("address"))
+ tempResourceInfo.address = trim_both(strValue);
- else
- {
- for (subItem = item->first_node(); subItem; subItem = subItem->next_sibling())
+ else if (!strKey.compare("resourceType"))
+ tempResourceInfo.resourceType = trim_both(strValue);
+
+ else
{
- map< string, string > propertyMap;
+ for (subItem = item->first_node(); subItem; subItem = subItem->next_sibling())
+ {
+ map< string, string > propertyMap;
- strKey = subItem->name();
+ strKey = subItem->name();
- for (subItem2 = subItem->first_node(); subItem2; subItem2 = subItem2->next_sibling())
- {
- string newStrKey = subItem2->name();
- string newStrValue = subItem2->value();
+ for (subItem2 = subItem->first_node(); subItem2; subItem2 = subItem2->next_sibling())
+ {
+ string newStrKey = subItem2->name();
+ string newStrValue = subItem2->value();
- propertyMap[trim_both(newStrKey)] = trim_both(newStrValue);
- }
+ propertyMap[trim_both(newStrKey)] = trim_both(newStrValue);
+ }
- tempResourceInfo.resourceProperty[trim_both(strKey)].push_back(propertyMap);
+ tempResourceInfo.resourceProperty[trim_both(strKey)].push_back(propertyMap);
+ }
}
}
+ configOutput->push_back(tempResourceInfo);
}
- configOutput->push_back(tempResourceInfo);
}
}
}
- }
- catch (rapidxml::parse_error &e)
- {
- std::cout << "xml parsing failed !!" << std::endl;
- std::cout << e.what() << std::endl;
+ catch (rapidxml::parse_error &e)
+ {
+ std::cout << "xml parsing failed !!" << std::endl;
+ std::cout << e.what() << std::endl;
+ }
}
}
ResourceContainer *container = ResourceContainer::getInstance();
container->startContainer("examples/ResourceContainerConfig.xml");
+ /*so bundle add test*/
+ cout << "++++++++++++++++++++++++++" << endl;
+ cout << "+++ Test for SO Bundle +++" << endl;
+ cout << "++++++++++++++++++++++++++" << endl;
+ cout << "Press enter to add SO bundle " << endl;
+ getchar();
+ std::map<string, string> bundleParams;
+ container->addBundle("oic.bundle.hueSample", "", "libHueBundle.so", bundleParams);
+
std::list<BundleInfo *> bundles = container->listBundles();
std::list<BundleInfo *>::iterator bundleIt;
+ cout << "\t>>> bundle list size : " << bundles.size() << endl;
for (bundleIt = bundles.begin(); bundleIt != bundles.end(); bundleIt++)
{
- BundleInfo *bi = *bundleIt;
- info_logger() << "Available bundle: " << bi->getID() << endl;
+ cout << "\t>>> bundle Id : " << (*bundleIt)->getID().c_str() << endl;
+ }
+
+ cout << "\nPress enter to start SO bundle " << endl;
+ getchar();
+ container->startBundle("oic.bundle.hueSample");
+
+ std::map<string, string> resourceParams;
+ cout << "Press enter to add SO bundle resource " << endl;
+ getchar();
+ resourceParams["resourceType"] = "oic.light.control";
+ resourceParams["address"] = "http://192.168.0.2/api/newdeveloper/lights/1";
+ container->addResourceConfig("oic.bundle.hueSample", "", resourceParams);
+ container->addResourceConfig("oic.bundle.hueSample", "", resourceParams);
+
+ std::list<string> resources = container->listBundleResources("oic.bundle.hueSample");
+ std::list<string>::iterator resourceIt;
+ cout << "\t>>> resource list size : " << resources.size() << endl;
+ for (resourceIt = resources.begin(); resourceIt != resources.end(); resourceIt++)
+ {
+ cout << "\t>>> resource uri : " << (*resourceIt).c_str() << endl;
+ }
+
+ cout << "\nPress enter to remove SO bundle resource " << endl;
+ getchar();
+ container->removeResourceConfig("oic.bundle.hueSample", "/hue/light/1");
+
+ resources = container->listBundleResources("oic.bundle.hueSample");
+ cout << "\t>>> resource list size : " << resources.size() << endl;
+ for (resourceIt = resources.begin(); resourceIt != resources.end(); resourceIt++)
+ {
+ cout << "\t>>> resource uri : " << (*resourceIt).c_str() << endl;
}
- cout << "Press enter to stop all bundles " << endl;
+ cout << "\nPress enter to stop SO Bundle " << endl;
getchar();
+ container->stopBundle("oic.bundle.hueSample");
+ cout << "Press enter to test remove SO Bundle " << endl;
+ getchar();
+ container->removeBundle("oic.bundle.hueSample");
+
+ bundles = container->listBundles();
+ cout << "\t>>> bundle list size : " << bundles.size() << endl;
for (bundleIt = bundles.begin(); bundleIt != bundles.end(); bundleIt++)
{
- BundleInfo *bi = *bundleIt;
- info_logger() << "Stopping bundle: " << bi->getID() << endl;
- container->stopBundle(bi->getID());
+ cout << "\t>>> bundle Id : " << (*bundleIt)->getID().c_str() << endl;
}
- cout << "Press enter to restart all bundles " << endl;
+ /*java bundle add test*/
+ cout << "\n++++++++++++++++++++++++++++" << endl;
+ cout << "+++ Test for JAVA Bundle +++" << endl;
+ cout << "++++++++++++++++++++++++++++" << endl;
+ cout << "Press enter to add java bundle " << endl;
getchar();
+ bundleParams["libraryPath"] = ".";
+ bundleParams["activator"] = "org.iotivity.bundle.hue.HueBundleActivator";
+ container->addBundle("oic.bundle.hueJavaSample", "/hueJava",
+ "../../../../../../../../service/resource-manipulation/src/resourceContainer/examples/HueJavaSampleBundle/hue/target/hue-0.1-jar-with-dependencies.jar",
+ bundleParams);
+ bundles = container->listBundles();
+ cout << "\t>>> bundle list size : " << bundles.size() << endl;
for (bundleIt = bundles.begin(); bundleIt != bundles.end(); bundleIt++)
{
- BundleInfo *bi = *bundleIt;
- info_logger() << "Starting bundle: " << bi->getID() << endl;
- container->startBundle(bi->getID());
+ cout << "\t>>> bundle Id : " << (*bundleIt)->getID().c_str() << endl;
}
- cout << "Press enter to stop container " << endl;
+ cout << "\nPress enter to start java bundle " << endl;
+ getchar();
+ container->startBundle("oic.bundle.hueJavaSample");
+
+ cout << "Press enter to stop java Bundle " << endl;
+ getchar();
+ container->stopBundle("oic.bundle.hueJavaSample");
+
+ cout << "Press enter to test remove java Bundle " << endl;
+ getchar();
+ container->removeBundle("oic.bundle.hueJavaSample");
+
+ bundles = container->listBundles();
+ cout << "\t>>> bundle list size : " << bundles.size() << endl;
+ for (bundleIt = bundles.begin(); bundleIt != bundles.end(); bundleIt++)
+ {
+ cout << "\t>>> bundle Id : " << (*bundleIt)->getID().c_str() << endl;
+ }
+
+ cout << "\nPress enter to stop container " << endl;
getchar();
container->stopContainer();
+
cout << "Container stopped. Bye" << endl;
}
}
else
{
- error_logger() << "Container started with invalid configfile path" << endl;;
+ error_logger() << "Container started with invalid configfile path" << endl;
}
}
deactivateBundle(bundleInfo);
unregisterBundle(bundleInfo);
}
+
+ delete m_config;
}
void ResourceContainerImpl::activateBundle(BundleInfo *bundleInfo)
{
info_logger() << "Registering bundle: " << bundleInfo->getPath() << endl;
- m_bundles[bundleInfo->getID()] = ((BundleInfoInternal *) bundleInfo);
-
if (has_suffix(bundleInfo->getPath(), ".jar"))
{
((BundleInfoInternal *) bundleInfo)->setJavaBundle(true);
}
else
{
+ delete m_bundles[id];
m_bundles.erase(id);
}
}
info_logger() << "Destroying JVM" << endl;
m_bundleVM[id]->DestroyJavaVM();
+
+ delete m_bundles[id];
+ m_bundles.erase(id);
}
void ResourceContainerImpl::registerResource(BundleResource *resource)
{
-
string strUri = resource->m_uri;
string strResourceType = resource->m_resourceType;
ResourceObject::Ptr server = nullptr;
string strUri = resource->m_uri;
string strResourceType = resource->m_resourceType;
+ info_logger() << "Unregistration of resource " << resource->m_uri << "," << resource->m_resourceType
+ << endl;
+
if (m_mapServers.find(strUri) != m_mapServers.end())
{
m_mapServers[strUri].reset();
void ResourceContainerImpl::getBundleConfiguration(std::string bundleId,
configInfo *configOutput)
{
- m_config->getBundleConfiguration(bundleId, (configInfo *) configOutput);
+ if (m_config)
+ {
+ m_config->getBundleConfiguration(bundleId, (configInfo *) configOutput);
+ }
}
void ResourceContainerImpl::getResourceConfiguration(std::string bundleId,
std::vector< resourceInfo > *configOutput)
{
- m_config->getResourceConfiguration(bundleId, configOutput);
+ if (m_config)
+ {
+ m_config->getResourceConfiguration(bundleId, configOutput);
+ }
}
RCSGetResponse ResourceContainerImpl::getRequestHandler(
void ResourceContainerImpl::startBundle(string bundleId)
{
- activateBundle(m_bundles[bundleId]);
+ if (m_bundles.find(bundleId) != m_bundles.end())
+ activateBundle(m_bundles[bundleId]);
}
void ResourceContainerImpl::stopBundle(string bundleId)
{
- deactivateBundle(m_bundles[bundleId]);
+ if (m_bundles.find(bundleId) != m_bundles.end())
+ deactivateBundle(m_bundles[bundleId]);
}
void ResourceContainerImpl::addBundle(string bundleId, string bundleUri, string bundlePath,
std::map< string, string > params)
{
- // To be implemented
+ if (m_bundles.find(bundleId) != m_bundles.end())
+ error_logger() << "BundleId already exist" << endl;
+
+ else
+ {
+ BundleInfo *bundleInfo = BundleInfo::build();
+ bundleInfo->setID(bundleId);
+ bundleInfo->setPath(bundlePath);
+ if (params.find("activator") != params.end())
+ {
+ string activatorName = params["activator"];
+ std::replace(activatorName.begin(), activatorName.end(), '.', '/');
+ ((BundleInfoInternal *)bundleInfo)->setActivatorName(activatorName);
+ ((BundleInfoInternal *)bundleInfo)->setLibraryPath(params["libraryPath"]);
+ }
+ if (params.find("activator") != params.end())
+ {
+ string activatorName = params["activator"];
+ std::replace(activatorName.begin(), activatorName.end(), '.', '/');
+ ((BundleInfoInternal *)bundleInfo)->setActivatorName(activatorName);
+ ((BundleInfoInternal *)bundleInfo)->setLibraryPath(params["libraryPath"]);
+ }
+
+ info_logger() << "Add Bundle:" << bundleInfo->getID().c_str() << ";" <<
+ bundleInfo->getPath().c_str() <<
+ endl;
+
+ registerBundle(bundleInfo);
+ }
}
void ResourceContainerImpl::removeBundle(string bundleId)
{
- // To be implemented
+ if (m_bundles.find(bundleId) != m_bundles.end())
+ {
+ BundleInfoInternal *bundleInfo = m_bundles[bundleId];
+ if (bundleInfo->isActivated())
+ deactivateBundle(bundleInfo);
+
+ if (bundleInfo->isLoaded())
+ unregisterBundle(bundleInfo);
+ }
+ else
+ {
+ error_logger() << "Bundle with ID \'" << bundleId << "\' is not registered." << endl;
+ }
}
std::list< BundleInfo * > ResourceContainerImpl::listBundles()
void ResourceContainerImpl::addResourceConfig(string bundleId, string resourceUri,
std::map< string, string > params)
{
- // To be implemented
+ if (m_bundles.find(bundleId) != m_bundles.end())
+ {
+ if (!m_bundles[bundleId]->getJavaBundle())
+ {
+ resourceInfo newResourceInfo;
+ newResourceInfo.uri = resourceUri;
+
+ if (params.find("name") != params.end())
+ newResourceInfo.name = params["name"];
+ if (params.find("resourceType") != params.end())
+ newResourceInfo.resourceType = params["resourceType"];
+ if (params.find("address") != params.end())
+ newResourceInfo.address = params["address"];
+
+ addSoBundleResource(bundleId, newResourceInfo);
+ }
+ }
+ else
+ {
+ error_logger() << "Bundle with ID \'" << bundleId << "\' is not registered." << endl;
+ }
}
void ResourceContainerImpl::removeResourceConfig(string bundleId, string resourceUri)
{
- // To be implemented
+ if (m_bundles.find(bundleId) != m_bundles.end())
+ {
+ if (!m_bundles[bundleId]->getJavaBundle())
+ {
+ removeSoBundleResource(bundleId, resourceUri);
+ }
+ }
+ else
+ {
+ error_logger() << "Bundle with ID \'" << bundleId << "\' is not registered." << endl;
+ }
}
std::list< string > ResourceContainerImpl::listBundleResources(string bundleId)
if (FILE *file = fopen(bundleInfo->getPath().c_str(), "r"))
{
fclose(file);
- info_logger() << "Resource bundle " << bundleInfo->getPath() << " available." << endl;
+ info_logger() << "Resource bundle " << bundleInfo->getPath().c_str() << " available." << endl;
//return true;
}
else
{
- error_logger() << "Resource bundle " << bundleInfo->getPath() << " not available" << endl;
+ error_logger() << "Resource bundle " << bundleInfo->getPath().c_str() << " not available" << endl;
return;
}
bundleInfoInternal->setJavaBundleActivatorObject(bundleActivator);
bundleInfoInternal->setLoaded(true);
+
+ m_bundles[bundleInfo->getID()] = ((BundleInfoInternal *)bundleInfo);
+
info_logger() << "Bundle registered" << endl;
}
activator_t *bundleActivator = NULL;
deactivator_t *bundleDeactivator = NULL;
+ resourceCreator_t *resourceCreator = NULL;
+ resourceDestroyer_t *resourceDestroyer = NULL;
//sstream << bundleInfo.path << std::ends;
bundleActivator = (activator_t *) dlsym(bundleHandle, "externalActivateBundle");
bundleDeactivator = (deactivator_t *) dlsym(bundleHandle,
"externalDeactivateBundle");
+ resourceCreator = (resourceCreator_t *)dlsym(bundleHandle, "externalCreateResource");
+ resourceDestroyer = (resourceDestroyer_t *)dlsym(bundleHandle, "externalDestroyResource");
+
if ((error = dlerror()) != NULL)
{
error_logger() << error << endl;
{
((BundleInfoInternal *) bundleInfo)->setBundleActivator(bundleActivator);
((BundleInfoInternal *) bundleInfo)->setBundleDeactivator(bundleDeactivator);
+ ((BundleInfoInternal *) bundleInfo)->setResourceCreator(resourceCreator);
+ ((BundleInfoInternal *) bundleInfo)->setResourceDestroyer(resourceDestroyer);
((BundleInfoInternal *) bundleInfo)->setLoaded(true);
((BundleInfoInternal *) bundleInfo)->setBundleHandle(bundleHandle);
+
+ m_bundles[bundleInfo->getID()] = ((BundleInfoInternal *)bundleInfo);
}
}
else
}
}
+ void ResourceContainerImpl::addSoBundleResource(string bundleId, resourceInfo newResourceInfo)
+ {
+ resourceCreator_t *resourceCreator;
+
+ resourceCreator = m_bundles[bundleId]->getResourceCreator();
+
+ if (resourceCreator != NULL)
+ {
+ resourceCreator(newResourceInfo);
+ }
+ else
+ {
+ error_logger() << "addResource unsuccessful." << endl;
+ }
+ }
+
+ void ResourceContainerImpl::removeSoBundleResource(string bundleId, string resourceUri)
+ {
+ if (m_mapResources.find(resourceUri) != m_mapResources.end())
+ {
+ resourceDestroyer_t *resourceDestroyer = m_bundles[bundleId]->getResourceDestroyer();
+
+ if (resourceDestroyer != NULL)
+ {
+ resourceDestroyer(m_mapResources[resourceUri]);
+ }
+ else
+ {
+ error_logger() << "removeResource unsuccessful." << endl;
+ }
+ }
+ }
}
}
void activateBundle(ResourceContainerBundleAPI *resourceContainer, std::string bundleId);
void deactivateBundle();
+
+ void createResource(resourceInfo resourceInfo);
+ void destroyResource(BundleResource *pBundleResource);
};
#endif /* TESTBUNDLE_H_ */
std::cout << "TestBundleActivator::deactivateBundle .. " << std::endl;
}
+void TestBundleActivator::createResource(resourceInfo resourceInfo)
+{
+ std::cout << "TestBundleActivator::createResource .. " << std::endl;
+}
+
+void TestBundleActivator::destroyResource(BundleResource *pBundleResource)
+{
+ std::cout << "TestBundleActivator::destroyResource .. " << std::endl;
+}
+
extern "C" void externalActivateBundle(ResourceContainerBundleAPI *resourceContainer,
std::string bundleId)
{
bundle->deactivateBundle();
}
}
+
+extern "C" void externalCreateResource(resourceInfo resourceInfo)
+{
+ bundle->createResource(resourceInfo);
+}
+
+extern "C" void externalDestroyResource(BundleResource *pBundleResource)
+{
+ bundle->destroyResource(pBundleResource);
+}