void ResourceContainerImpl::startContainer(const std::string &configFile)
{
- OC_LOG(INFO, CONTAINER_TAG, "Starting resource container.");
+ OIC_LOG(INFO, CONTAINER_TAG, "Starting resource container.");
#if (JAVA_SUPPORT)
- OC_LOG(INFO, CONTAINER_TAG, "Resource container has Java support.");
+ OIC_LOG(INFO, CONTAINER_TAG, "Resource container has Java support.");
#else
- OC_LOG(INFO, CONTAINER_TAG, "Resource container without Java support.");
+ OIC_LOG(INFO, CONTAINER_TAG, "Resource container without Java support.");
#endif
activationLock.lock();
- if (!configFile.empty())
+ try
{
- m_config = new Configuration(configFile);
-
- if (m_config->isLoaded())
+ 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())
{
- 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(), '.', '/');
- ((BundleInfoInternal *) bundleInfo)->setActivatorName(activatorName);
- ((BundleInfoInternal *) 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]);
+ }
- OC_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
{
- OC_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
- {
- OC_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++)
+ OIC_LOG(INFO, CONTAINER_TAG, "Resource container started.");
+ }
+ catch (...)
{
- 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 failed starting.");
}
activationLock.unlock();
}
void ResourceContainerImpl::stopContainer()
{
- OC_LOG(INFO, CONTAINER_TAG, "Stopping resource container.");
+ OIC_LOG(INFO, CONTAINER_TAG, "Stopping resource container.");
- for (std::map< std::string, BundleInfoInternal * >::iterator it = m_bundles.begin();
+ for (std::map< std::string, shared_ptr<BundleInfoInternal> >::iterator it = m_bundles.begin();
it != m_bundles.end(); ++it)
{
- BundleInfoInternal *bundleInfo = it->second;
- deactivateBundle(bundleInfo);
- unregisterBundle(bundleInfo);
+ deactivateBundle(it->second);
+ unregisterBundle(it->second);
}
if (!m_mapServers.empty())
}
if (m_config)
+ {
delete m_config;
+ }
}
- void ResourceContainerImpl::activateBundle(RCSBundleInfo *bundleInfo)
+ void ResourceContainerImpl::activateBundle(shared_ptr<RCSBundleInfo> bundleInfo)
{
activationLock.lock();
- BundleInfoInternal *bundleInfoInternal = (BundleInfoInternal *) bundleInfo;
+
+ shared_ptr<BundleInfoInternal> bundleInfoInternal =
+ std::static_pointer_cast<BundleInfoInternal>(bundleInfo);
if (bundleInfoInternal->isLoaded())
{
activationLock.unlock();
}
- void ResourceContainerImpl::deactivateBundle(RCSBundleInfo *bundleInfo)
+ void ResourceContainerImpl::deactivateBundle(shared_ptr<RCSBundleInfo> bundleInfo)
{
- if (((BundleInfoInternal *) bundleInfo)->isActivated())
+ shared_ptr<BundleInfoInternal> bundleInfoInternal =
+ std::static_pointer_cast<BundleInfoInternal>(bundleInfo);
+ if (bundleInfoInternal->isActivated())
{
- deactivateBundle(bundleInfo->getID());
+ deactivateBundle(bundleInfoInternal->getID());
}
}
void ResourceContainerImpl::activateBundle(const std::string &id)
{
- OC_LOG_V(INFO, CONTAINER_TAG, "Activating bundle: (%s)",
+ 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();
- OC_LOG_V(INFO, CONTAINER_TAG, "Bundle activated: (%s)",
+ OIC_LOG_V(INFO, CONTAINER_TAG, "Bundle activated: (%s)",
std::string(m_bundles[id]->getID()).c_str());
}
}
// loads the bundle
- void ResourceContainerImpl::registerBundle(RCSBundleInfo *bundleInfo)
+ void ResourceContainerImpl::registerBundle(shared_ptr<RCSBundleInfo> bundleInfo)
{
- OC_LOG_V(INFO, CONTAINER_TAG, "Registering bundle: (%s)",
+ OIC_LOG_V(INFO, CONTAINER_TAG, "Registering bundle: (%s)",
std::string(bundleInfo->getPath()).c_str());
+ shared_ptr<BundleInfoInternal> bundleInfoInternal =
+ std::static_pointer_cast<BundleInfoInternal>(bundleInfo);
if (has_suffix(bundleInfo->getPath(), ".jar"))
{
#if(JAVA_SUPPORT)
- ((BundleInfoInternal *) bundleInfo)->setJavaBundle(true);
+ bundleInfoInternal->setJavaBundle(true);
+ bundleInfoInternal->setSoBundle(false);
registerJavaBundle(bundleInfo);
+#else
+ // android .jar library
+ bundleInfoInternal->setSoBundle(false);
+ bundleInfoInternal->setJavaBundle(false);
+ registerExtBundle(bundleInfo);
#endif
}
- else
+ else if (has_suffix(bundleInfo->getPath(), ".so"))
{
- ((BundleInfoInternal *) bundleInfo)->setJavaBundle(false);
+ bundleInfoInternal->setSoBundle(true);
+ bundleInfoInternal->setJavaBundle(false);
registerSoBundle(bundleInfo);
}
+ // other cases might be for example .apk for android, which are loaded in the wrapper
+ else
+ {
+ bundleInfoInternal->setSoBundle(false);
+ bundleInfoInternal->setJavaBundle(false);
+ registerExtBundle(bundleInfo);
+ }
}
- void ResourceContainerImpl::unregisterBundle(RCSBundleInfo *bundleInfo)
+ void ResourceContainerImpl::unregisterBundle(shared_ptr<RCSBundleInfo> bundleInfo)
{
- BundleInfoInternal *bundleInfoInternal = (BundleInfoInternal *) bundleInfo;
+ shared_ptr<BundleInfoInternal> bundleInfoInternal =
+ std::static_pointer_cast<BundleInfoInternal>(bundleInfo);
if (bundleInfoInternal->isLoaded() && !bundleInfoInternal->isActivated())
{
- if (!bundleInfoInternal->getJavaBundle())
+ if (bundleInfoInternal->getSoBundle())
{
unregisterBundleSo(bundleInfo->getID());
}
- else
+ else if (bundleInfoInternal->getJavaBundle())
{
#if(JAVA_SUPPORT)
unregisterBundleJava(bundleInfo->getID());
{
void *bundleHandle = m_bundles[id]->getBundleHandle();
- OC_LOG_V(INFO, CONTAINER_TAG, "Unregister bundle: (%s)",
+ OIC_LOG_V(INFO, CONTAINER_TAG, "Unregister bundle: (%s)",
std::string(m_bundles[id]->getID()).c_str());
- const char *error;
+ const char *error = NULL;
dlclose(bundleHandle);
if ((error = dlerror()) != NULL)
{
- OC_LOG_V(ERROR, CONTAINER_TAG, "Error (%s)", error);
+ OIC_LOG_V(ERROR, CONTAINER_TAG, "Error (%s)", error);
}
else
{
- delete m_bundles[id];
m_bundles.erase(id);
}
}
- void ResourceContainerImpl::registerResource(BundleResource::Ptr resource)
+ int ResourceContainerImpl::registerResource(BundleResource::Ptr resource)
{
string strUri = resource->m_uri;
string strResourceType = resource->m_resourceType;
+ string strInterface = resource->m_interface;
RCSResourceObject::Ptr server = nullptr;
+ int ret = EINVAL;
- OC_LOG_V(INFO, CONTAINER_TAG, "Registration of resource (%s)" ,
- std::string(strUri + ", " + strResourceType).c_str());
+ OIC_LOG_V(INFO, CONTAINER_TAG, "Registration of resource (%s)" ,
+ std::string(strUri + ", " + strResourceType + "," +
+ resource->m_bundleId).c_str());
registrationLock.lock();
if (m_mapResources.find(strUri) == m_mapResources.end())
{
- server = buildResourceObject(strUri, strResourceType);
+ if (strInterface.empty())
+ {
+ strInterface = "oic.if.baseline";
+ }
+
+ server = buildResourceObject(strUri, strResourceType, strInterface);
if (server != nullptr)
{
std::bind(&ResourceContainerImpl::setRequestHandler, this,
std::placeholders::_1, std::placeholders::_2));
- OC_LOG_V(INFO, CONTAINER_TAG, "Registration finished (%s)",
- std::string(strUri + ", " +
- strResourceType).c_str());
+ OIC_LOG_V(INFO, CONTAINER_TAG, "Registration finished (%s)",
+ std::string(strUri + ", " +
+ strResourceType).c_str());
- if (m_config->isHasInput(resource->m_bundleId))
+ if (m_config && m_config->isHasInput(resource->m_bundleId))
{
+ OIC_LOG_V(INFO, CONTAINER_TAG, "Resource has input (%s)",
+ std::string(strUri + ", " +
+ strResourceType).c_str());
discoverInputResource(strUri);
}
+ else
+ {
+ OIC_LOG_V(INFO, CONTAINER_TAG, "Resource has no input (%s)",
+ std::string(strUri + ", " +
+ strResourceType).c_str());
+ }
+ OIC_LOG_V(INFO, CONTAINER_TAG, "Registration finished (%s)",
+ std::string(strUri + ", " +
+ strResourceType).c_str());
// to get notified if bundle resource attributes are updated
- resource->registerObserver((NotificationReceiver *) this);
+ resource->registerObserver(this);
+ ret = 0;
}
}
else
{
- OC_LOG_V(ERROR, CONTAINER_TAG, "resource with (%s)",
+ OIC_LOG_V(ERROR, CONTAINER_TAG, "resource with (%s)",
std::string(strUri + " already exists.").c_str());
+ ret = -EEXIST;
}
registrationLock.unlock();
+
+ return ret;
}
void ResourceContainerImpl::unregisterResource(BundleResource::Ptr resource)
string strUri = resource->m_uri;
string strResourceType = resource->m_resourceType;
- OC_LOG_V(INFO, CONTAINER_TAG, "Unregistration of resource (%s)",
+ OIC_LOG_V(INFO, CONTAINER_TAG, "Unregistration of resource (%s)",
std::string(resource->m_uri + ", " +
resource->m_resourceType).c_str());
- if (m_config->isHasInput(resource->m_bundleId))
+ if (m_config && m_config->isHasInput(resource->m_bundleId))
{
+ OIC_LOG_V(INFO, CONTAINER_TAG, "Calling undiscover (%s)",
+ std::string(resource->m_uri + ", " +
+ resource->m_resourceType).c_str());
undiscoverInputResource(strUri);
}
if (m_mapServers.find(strUri) != m_mapServers.end())
{
+ OIC_LOG_V(INFO, CONTAINER_TAG, "Resetting server (%s)",
+ std::string(resource->m_uri + ", " +
+ resource->m_resourceType).c_str());
m_mapServers[strUri].reset();
m_mapResources.erase(m_mapResources.find(strUri));
+
+ OIC_LOG_V(INFO, CONTAINER_TAG, "Remove bundle resource (%s)",
+ std::string(resource->m_uri + ", " +
+ resource->m_resourceType).c_str());
m_mapBundleResources[resource->m_bundleId].remove(strUri);
}
}
{
m_config->getResourceConfiguration(bundleId, configOutput);
}
+ else
+ {
+ OIC_LOG_V(DEBUG, CONTAINER_TAG, "no config present ");
+ }
}
RCSGetResponse ResourceContainerImpl::getRequestHandler(const RCSRequest &request,
{
RCSResourceAttributes attr;
std::string strResourceUri = request.getResourceUri();
+ const std::map< std::string, std::string > &queryParams = request.getQueryParams();
+
+ OIC_LOG_V(INFO, CONTAINER_TAG, "Container get request for %s",strResourceUri.c_str());
if (m_mapServers.find(strResourceUri) != m_mapServers.end()
&& m_mapResources.find(strResourceUri) != m_mapResources.end())
{
if (m_mapResources[strResourceUri])
{
- auto getFunction = [this, &attr, &strResourceUri]()
+ auto getFunction = [this, &attr, &strResourceUri, queryParams]()
{
- attr = m_mapResources[strResourceUri]->handleGetAttributesRequest();
+ attr = m_mapResources[strResourceUri]->handleGetAttributesRequest(queryParams);
};
boost::thread getThread(getFunction);
getThread.timed_join(boost::posix_time::seconds(BUNDLE_SET_GET_WAIT_SEC));
}
}
+ OIC_LOG_V(INFO, CONTAINER_TAG, "Container get request for %s finished, %zu attributes",strResourceUri.c_str(), attr.size());
return RCSGetResponse::create(std::move(attr), 200);
}
RCSResourceAttributes attr;
std::list<std::string> lstAttributes;
std::string strResourceUri = request.getResourceUri();
+ const std::map< std::string, std::string > &queryParams = request.getQueryParams();
+
+ OIC_LOG_V(INFO, CONTAINER_TAG, "Container set request for %s, %zu attributes",strResourceUri.c_str(), attributes.size());
if (m_mapServers.find(strResourceUri) != m_mapServers.end()
&& m_mapResources.find(strResourceUri) != m_mapResources.end())
{
if (m_mapResources[strResourceUri])
{
- auto setFunction = [this, &lstAttributes, &strResourceUri, &attributes, &attr]()
+ auto setFunction = [this, &lstAttributes, &strResourceUri, &attributes, &attr, queryParams]()
{
lstAttributes = m_mapResources[strResourceUri]->getAttributeNames();
}
}
- m_mapResources[strResourceUri]->handleSetAttributesRequest(attr);
+ OIC_LOG_V(INFO, CONTAINER_TAG, "Calling handleSetAttributeRequest");
+ m_mapResources[strResourceUri]->handleSetAttributesRequest(attr, queryParams);
};
boost::thread setThread(setFunction);
setThread.timed_join(boost::posix_time::seconds(BUNDLE_SET_GET_WAIT_SEC));
void ResourceContainerImpl::onNotificationReceived(const std::string &strResourceUri)
{
- OC_LOG_V(INFO, CONTAINER_TAG,
+ OIC_LOG_V(INFO, CONTAINER_TAG,
"notification from (%s)", std::string(strResourceUri + ".").c_str());
if (m_mapServers.find(strResourceUri) != m_mapServers.end())
}
RCSResourceObject::Ptr ResourceContainerImpl::buildResourceObject(const std::string &strUri,
- const std::string &strResourceType)
+ const std::string &strResourceType, const std::string &strInterface)
{
return RCSResourceObject::Builder(strUri, strResourceType,
- "oic.if.baseline").setObservable(
+ strInterface).setObservable(
true).setDiscoverable(true).build();
}
void ResourceContainerImpl::startBundle(const std::string &bundleId)
{
+ OIC_LOG_V(INFO, CONTAINER_TAG, "startBundle %s",bundleId.c_str());
if (m_bundles.find(bundleId) != m_bundles.end())
{
if (!m_bundles[bundleId]->isActivated())
+ {
activateBundle(m_bundles[bundleId]);
+ }
else
{
- OC_LOG(ERROR, CONTAINER_TAG, "Bundle already started");
+ OIC_LOG(ERROR, CONTAINER_TAG, "Bundle already started");
}
}
else
{
- OC_LOG_V(ERROR, CONTAINER_TAG, "Bundle with ID \'(%s)",
+ OIC_LOG_V(ERROR, CONTAINER_TAG, "Bundle with ID \'(%s)",
std::string(bundleId + "\' is not registered.").c_str());
}
}
void ResourceContainerImpl::stopBundle(const std::string &bundleId)
{
+ OIC_LOG_V(INFO, CONTAINER_TAG, "stopBundle %s",bundleId.c_str());
if (m_bundles.find(bundleId) != m_bundles.end())
{
if (m_bundles[bundleId]->isActivated())
+ {
deactivateBundle(m_bundles[bundleId]);
+ }
else
{
- OC_LOG(ERROR, CONTAINER_TAG, "Bundle not activated");
+ OIC_LOG(ERROR, CONTAINER_TAG, "Bundle not activated");
}
}
else
{
- OC_LOG_V(ERROR, CONTAINER_TAG, "Bundle with ID \'(%s)",
+ OIC_LOG_V(ERROR, CONTAINER_TAG, "Bundle with ID \'(%s)",
std::string(bundleId + "\' is not registered.").c_str());
}
}
void ResourceContainerImpl::addBundle(const std::string &bundleId,
- const std::string &bundleUri, const std::string &bundlePath,
- const std::string &activator, std::map< string, string > params)
+ const std::string &bundleUri,
+ const std::string &bundlePath,
+ const std::string &activator,
+ std::map< string, string > params)
{
(void) bundleUri;
if (m_bundles.find(bundleId) != m_bundles.end())
- OC_LOG(ERROR, CONTAINER_TAG, "BundleId already exist");
+ {
+ OIC_LOG(ERROR, CONTAINER_TAG, "BundleId already exist");
+ }
else
{
- BundleInfoInternal *bundleInfo = new BundleInfoInternal();
+ shared_ptr<BundleInfoInternal> bundleInfo = std::make_shared<BundleInfoInternal>();
bundleInfo->setID(bundleId);
bundleInfo->setPath(bundlePath);
bundleInfo->setActivatorName(activator);
{
string activatorName = activator; // modify activator for Java bundle
std::replace(activatorName.begin(), activatorName.end(), '.', '/');
- ((BundleInfoInternal *) bundleInfo)->setActivatorName(activatorName);
- ((BundleInfoInternal *)bundleInfo)->setLibraryPath(params[BUNDLE_LIBRARY_PATH]);
+ bundleInfo->setActivatorName(activatorName);
+ bundleInfo->setLibraryPath(params[BUNDLE_LIBRARY_PATH]);
}
- OC_LOG_V(INFO, CONTAINER_TAG, "Add Bundle: (%s)",
+ OIC_LOG_V(INFO, CONTAINER_TAG, "Add Bundle: (%s)",
std::string(bundleInfo->getID() + "; " +
bundleInfo->getPath()).c_str());
void ResourceContainerImpl::removeBundle(const std::string &bundleId)
{
+ OIC_LOG_V(INFO, CONTAINER_TAG, "removeBundle %s",bundleId.c_str());
if (m_bundles.find(bundleId) != m_bundles.end())
{
- BundleInfoInternal *bundleInfo = m_bundles[bundleId];
+ shared_ptr<BundleInfoInternal> bundleInfo = m_bundles[bundleId];
if (bundleInfo->isActivated())
+ {
deactivateBundle(bundleInfo);
+ }
if (bundleInfo->isLoaded())
+ {
unregisterBundle(bundleInfo);
+ }
}
else
{
- OC_LOG_V(ERROR, CONTAINER_TAG, "Bundle with ID \'(%s)",
- std::string(bundleId + "\' is not registered.").c_str());
+ OIC_LOG_V(ERROR, CONTAINER_TAG, "Bundle with ID \'(%s)",
+ std::string(bundleId + "\' is not ced.").c_str());
}
}
- std::list< RCSBundleInfo * > ResourceContainerImpl::listBundles()
+ std::list<std::unique_ptr<RCSBundleInfo>> ResourceContainerImpl::listBundles()
{
- std::list< RCSBundleInfo * > ret;
- for (std::map< std::string, BundleInfoInternal * >::iterator it = m_bundles.begin();
+ OIC_LOG_V(INFO, CONTAINER_TAG,
+ "list bundles (%d)", m_bundles.size());
+ std::list<std::unique_ptr<RCSBundleInfo> > ret;
+ for (std::map< std::string, shared_ptr<BundleInfoInternal> >::iterator it = m_bundles.begin();
it != m_bundles.end(); ++it)
{
{
- BundleInfoInternal *bundleInfo = new BundleInfoInternal();
- (bundleInfo)->setBundleInfo(it->second);
- ret.push_back((RCSBundleInfo *) bundleInfo);
+ std::unique_ptr<BundleInfoInternal> bundleInfo(new BundleInfoInternal);
+ bundleInfo->setBundleInfo(it->second);
+ ret.push_back(std::move(bundleInfo));
}
}
return ret;
newResourceInfo.uri = resourceUri;
if (params.find(OUTPUT_RESOURCE_NAME) != params.end())
+ {
newResourceInfo.name = params[OUTPUT_RESOURCE_NAME];
+ }
if (params.find(OUTPUT_RESOURCE_TYPE) != params.end())
+ {
newResourceInfo.resourceType = params[OUTPUT_RESOURCE_TYPE];
+ }
if (params.find(OUTPUT_RESOURCE_ADDR) != params.end())
+ {
newResourceInfo.address = params[OUTPUT_RESOURCE_ADDR];
+ }
addSoBundleResource(bundleId, newResourceInfo);
}
}
else
{
- OC_LOG_V(ERROR, CONTAINER_TAG, "Bundle with ID \'(%s)",
+ OIC_LOG_V(ERROR, CONTAINER_TAG, "Bundle with ID \'(%s)",
std::string(bundleId + "\' is not registered.").c_str());
}
}
void ResourceContainerImpl::removeResourceConfig(const std::string &bundleId,
const std::string &resourceUri)
{
+ OIC_LOG_V(INFO, CONTAINER_TAG, "removeResourceConfig %s, %s",bundleId.c_str(),
+ resourceUri.c_str());
if (m_bundles.find(bundleId) != m_bundles.end())
{
- if (!m_bundles[bundleId]->getJavaBundle())
+ if (m_bundles[bundleId]->getSoBundle())
{
removeSoBundleResource(bundleId, resourceUri);
}
}
else
{
- OC_LOG_V(ERROR, CONTAINER_TAG, "Bundle with ID \'(%s)",
+ OIC_LOG_V(ERROR, CONTAINER_TAG, "Bundle with ID \'(%s)",
std::string(bundleId + "\' is not registered.").c_str());
}
}
std::list< string > ResourceContainerImpl::listBundleResources(const std::string &bundleId)
{
+ OIC_LOG_V(INFO, CONTAINER_TAG, "listBundleResources %s",bundleId.c_str());
std::list < string > ret;
if (m_mapBundleResources.find(bundleId) != m_mapBundleResources.end())
}
- void ResourceContainerImpl::registerSoBundle(RCSBundleInfo *bundleInfo)
+ void ResourceContainerImpl::registerSoBundle(shared_ptr<RCSBundleInfo> bundleInfo)
{
- const char *error;
+ OIC_LOG_V(DEBUG, CONTAINER_TAG, "Register SO bundle");
+ const char *error = NULL;
activator_t *bundleActivator = NULL;
deactivator_t *bundleDeactivator = NULL;
resourceCreator_t *resourceCreator = NULL;
resourceDestroyer_t *resourceDestroyer = NULL;
- BundleInfoInternal *bundleInfoInternal = (BundleInfoInternal *) bundleInfo;
+ shared_ptr<BundleInfoInternal> bundleInfoInternal =
+ std::static_pointer_cast<BundleInfoInternal>(bundleInfo);
+
void *bundleHandle = NULL;
bundleHandle = dlopen(bundleInfo->getPath().c_str(), RTLD_LAZY);
+ if ((error = dlerror()) != NULL)
+ {
+ OIC_LOG_V(ERROR, CONTAINER_TAG, "Error while loading .so bundle: (%s)", error);
+ }
if (bundleHandle != NULL)
{
+ OIC_LOG_V(DEBUG, CONTAINER_TAG, "Activator name %s",
+ bundleInfoInternal->getActivatorName().c_str());
bundleActivator =
(activator_t *) dlsym(bundleHandle,
("" + bundleInfoInternal->getActivatorName()
+ "_externalActivateBundle").c_str());
+ if ((error = dlerror()) != NULL)
+ {
+ OIC_LOG_V(ERROR, CONTAINER_TAG, "Error while loading .so bundle: (%s)", error);
+ }
+ else
+ {
+ OIC_LOG_V(DEBUG, CONTAINER_TAG, "Looked up %s", ("" +
+ bundleInfoInternal->getActivatorName()
+ + "_externalActivateBundle").c_str());
+ }
bundleDeactivator =
(deactivator_t *) dlsym(bundleHandle,
("" + bundleInfoInternal->getActivatorName()
+ "_externalDeactivateBundle").c_str());
+ if ((error = dlerror()) != NULL)
+ {
+ OIC_LOG_V(ERROR, CONTAINER_TAG, "Error while loading .so bundle: (%s)", error);
+ }
+ else
+ {
+ OIC_LOG_V(DEBUG, CONTAINER_TAG, "Looked up %s", ("" +
+ bundleInfoInternal->getActivatorName()
+ + "_externalDeactivateBundle").c_str());
+ }
resourceCreator =
(resourceCreator_t *) dlsym(bundleHandle,
("" + bundleInfoInternal->getActivatorName()
+ "_externalCreateResource").c_str());
+ if ((error = dlerror()) != NULL)
+ {
+ OIC_LOG_V(ERROR, CONTAINER_TAG, "Error while loading .so bundle: (%s)", error);
+ }
+ else
+ {
+ OIC_LOG_V(DEBUG, CONTAINER_TAG, "Looked up %s", ("" +
+ bundleInfoInternal->getActivatorName()
+ + "_externalCreateResource").c_str());
+ }
resourceDestroyer =
(resourceDestroyer_t *) dlsym(bundleHandle,
("" + bundleInfoInternal->getActivatorName()
+ "_externalDestroyResource").c_str());
+ if ((error = dlerror()) != NULL)
+ {
+ OIC_LOG_V(ERROR, CONTAINER_TAG, "Error while loading .so bundle: (%s)", error);
+ }
+ else
+ {
+ OIC_LOG_V(DEBUG, CONTAINER_TAG, "Looked up %s", ("" +
+ bundleInfoInternal->getActivatorName()
+ + "_externalDestroyResource").c_str());
+ }
if ((error = dlerror()) != NULL)
{
- OC_LOG_V(ERROR, CONTAINER_TAG, "Error : (%s)", error);
+ OIC_LOG_V(ERROR, CONTAINER_TAG, "Error : (%s)", error);
}
else
{
- ((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);
+ bundleInfoInternal->setBundleActivator(bundleActivator);
+ bundleInfoInternal->setBundleDeactivator(bundleDeactivator);
+ bundleInfoInternal->setResourceCreator(resourceCreator);
+ bundleInfoInternal->setResourceDestroyer(resourceDestroyer);
+ bundleInfoInternal->setLoaded(true);
+ bundleInfoInternal->setBundleHandle(bundleHandle);
+
+ m_bundles[bundleInfo->getID()] = bundleInfoInternal;
}
}
else
{
if ((error = dlerror()) != NULL)
{
- OC_LOG_V(ERROR, CONTAINER_TAG, "Error : (%s)", error);
+ OIC_LOG_V(ERROR, CONTAINER_TAG, "Error : (%s)", error);
}
}
+ OIC_LOG_V(DEBUG, CONTAINER_TAG, "Register SO bundle finished");
+ }
+
+ void ResourceContainerImpl::registerExtBundle(shared_ptr<RCSBundleInfo> bundleInfo)
+ {
+ OIC_LOG_V(INFO, CONTAINER_TAG, "Registering ext bundle (%s)",
+ std::string(bundleInfo->getID()).c_str());
+ OIC_LOG_V(INFO, CONTAINER_TAG, "Activator name (%s)",
+ std::string(bundleInfo->getActivatorName()).c_str());
+
+ shared_ptr<BundleInfoInternal> bundleInfoInternal =
+ std::static_pointer_cast<BundleInfoInternal>(bundleInfo);
+
+ m_bundles[bundleInfo->getID()] = bundleInfoInternal;
+ // in this case at least the resource configuration needs to be loaded
+ // in order to mark potential input resources for soft sensors
+ std::vector< resourceInfo > temp;
+ OIC_LOG_V(INFO, CONTAINER_TAG, "Loading resource config(%s)",
+ std::string(bundleInfo->getID()).c_str());
+ getResourceConfiguration(bundleInfo->getID(),
+ &temp);
+
+ OIC_LOG(INFO, CONTAINER_TAG, "Bundle registered");
}
void ResourceContainerImpl::activateSoBundle(const std::string &bundleId)
else
{
//Unload module and return error
- OC_LOG(ERROR, CONTAINER_TAG, "Activation unsuccessful.");
+ OIC_LOG(ERROR, CONTAINER_TAG, "Activation unsuccessful.");
}
- BundleInfoInternal *bundleInfoInternal = (BundleInfoInternal *) m_bundles[bundleId];
+ shared_ptr<BundleInfoInternal> bundleInfoInternal = m_bundles[bundleId];
bundleInfoInternal->setActivated(true);
}
auto foundDiscoverResource = m_mapDiscoverResourceUnits.find(outputResourceUri);
if (foundDiscoverResource != m_mapDiscoverResourceUnits.end())
{
+ OIC_LOG(DEBUG, CONTAINER_TAG, "Erase discover resource.");
m_mapDiscoverResourceUnits.erase(foundDiscoverResource);
+ OIC_LOG(DEBUG, CONTAINER_TAG, "Erase discover resource done.");
}
}
void ResourceContainerImpl::discoverInputResource(const std::string &outputResourceUri)
{
+ 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,
+ outputResourceUri, &info);
+ map< string, vector< map< string, string > > > resourceProperty = info.resourceProperty;
try
{
}
catch (std::out_of_range &e)
{
+ OIC_LOG_V(DEBUG, CONTAINER_TAG, "No input resource %s", outputResourceUri.c_str());
return;
}
std::string type = makeValue(INPUT_RESOURCE_TYPE);
std::string attributeName = makeValue(INPUT_RESOURCE_ATTRIBUTENAME);
+
+ OIC_LOG_V(DEBUG, CONTAINER_TAG, "Start discovery: %s, %s, %s", uri.c_str(),
+ type.c_str(), attributeName.c_str());
DiscoverResourceUnit::Ptr newDiscoverUnit = std::make_shared
< DiscoverResourceUnit > (outputResourceUri);
newDiscoverUnit->startDiscover(
DiscoverResourceUnit::DiscoverResourceInfo(uri, type,
attributeName),
std::bind(&SoftSensorResource::onUpdatedInputResource,
- std::static_pointer_cast< SoftSensorResource > (foundOutputResource->second),
+ std::static_pointer_cast< SoftSensorResource >
+ (foundOutputResource->second),
std::placeholders::_1, std::placeholders::_2));
auto foundDiscoverResource = m_mapDiscoverResourceUnits.find(
{
deactivator_t *bundleDeactivator = m_bundles[id]->getBundleDeactivator();
- OC_LOG_V(INFO, CONTAINER_TAG, "De-activating bundle: (%s)", std::string(
+ OIC_LOG_V(INFO, CONTAINER_TAG, "De-activating bundle: (%s)", std::string(
m_bundles[id]->getID()).c_str());
if (bundleDeactivator != NULL)
else
{
//Unload module and return error
- OC_LOG(ERROR, CONTAINER_TAG, "De-activation unsuccessful.");
+ OIC_LOG(ERROR, CONTAINER_TAG, "De-activation unsuccessful.");
}
}
void ResourceContainerImpl::addSoBundleResource(const std::string &bundleId,
resourceInfo newResourceInfo)
{
- resourceCreator_t *resourceCreator;
+ resourceCreator_t *resourceCreator = nullptr;
resourceCreator = m_bundles[bundleId]->getResourceCreator();
}
else
{
- OC_LOG(ERROR, CONTAINER_TAG, "addResource unsuccessful.");
+ OIC_LOG(ERROR, CONTAINER_TAG, "addResource unsuccessful.");
}
}
}
else
{
- OC_LOG(ERROR, CONTAINER_TAG, "removeResource unsuccessful.");
+ OIC_LOG(ERROR, CONTAINER_TAG, "removeResource unsuccessful.");
}
}
}
void ResourceContainerImpl::activateBundleThread(const std::string &id)
{
- OC_LOG_V(INFO, CONTAINER_TAG, "Activating bundle: (%s)",
+ OIC_LOG_V(INFO, CONTAINER_TAG, "Activating bundle: (%s)",
std::string(m_bundles[id]->getID()).c_str());
if (m_bundles[id]->getJavaBundle())
activateJavaBundle(id);
#endif
}
- else
+ else if (m_bundles[id]->getSoBundle())
{
activateSoBundle (id);
}
- OC_LOG_V(INFO, CONTAINER_TAG, "Bundle activated: (%s)",
+ OIC_LOG_V(INFO, CONTAINER_TAG, "Bundle activated: (%s)",
std::string(m_bundles[id]->getID()).c_str());
}
return m_bundleVM[bundleId];
}
- void ResourceContainerImpl::registerJavaBundle(RCSBundleInfo *bundleInfo)
+ void ResourceContainerImpl::registerJavaBundle(shared_ptr<RCSBundleInfo> bundleInfo)
{
- OC_LOG_V(INFO, CONTAINER_TAG, "Registering Java bundle (%s)",
+ OIC_LOG_V(INFO, CONTAINER_TAG, "Registering Java bundle (%s)",
std::string(bundleInfo->getID()).c_str());
JavaVM *jvm;
JNIEnv *env;
JavaVMInitArgs vm_args;
JavaVMOption options[3];
- BundleInfoInternal *bundleInfoInternal = (BundleInfoInternal *) bundleInfo;
+ shared_ptr<BundleInfoInternal> bundleInfoInternal =
+ std::static_pointer_cast<BundleInfoInternal>(bundleInfo);
+
if (FILE *file = fopen(bundleInfo->getPath().c_str(), "r"))
{
fclose(file);
- OC_LOG_V(INFO, CONTAINER_TAG, "Resource bundle (%s)",
+ OIC_LOG_V(INFO, CONTAINER_TAG, "Resource bundle (%s)",
std::string(bundleInfo->getPath() +
" available.").c_str());
}
else
{
- OC_LOG_V(ERROR, CONTAINER_TAG, "Resource bundle (%s)",
+ OIC_LOG_V(ERROR, CONTAINER_TAG, "Resource bundle (%s)",
std::string(bundleInfo->getPath() + " not available.").c_str());
return;
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);
- OC_LOG(INFO, CONTAINER_TAG,
+ OIC_LOG(INFO, CONTAINER_TAG,
std::string("Configured classpath: ").append(classpath).c_str());
options[1].optionString = classpath;
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;
- OC_LOG(INFO, CONTAINER_TAG,
+ OIC_LOG(INFO, CONTAINER_TAG,
std::string("Configured library path: ").append(libraryPath).c_str());
vm_args.version = JNI_VERSION_1_4;
if (res < 0)
{
- OC_LOG(ERROR, CONTAINER_TAG, "cannot create JavaVM.");
+ OIC_LOG(ERROR, CONTAINER_TAG, "cannot create JavaVM.");
return;
}
else
{
- OC_LOG(INFO, CONTAINER_TAG, "JVM successfully created.");
+ OIC_LOG(INFO, CONTAINER_TAG, "JVM successfully created.");
}
m_bundleVM.insert(std::pair< string, JavaVM * >(bundleInfo->getID(), jvm));
const char *className = bundleInfoInternal->getActivatorName().c_str();
- OC_LOG_V(INFO, CONTAINER_TAG, "Looking up class: (%s)", std::string(
+ OIC_LOG_V(INFO, CONTAINER_TAG, "Looking up class: (%s)", std::string(
bundleInfoInternal->getActivatorName() + "|").c_str());
jclass bundleActivatorClass = env->FindClass(className);
if (bundleActivatorClass == NULL)
{
- OC_LOG_V(ERROR, CONTAINER_TAG, "Cannot register bundle (%s)",
+ OIC_LOG_V(ERROR, CONTAINER_TAG, "Cannot register bundle (%s)",
std::string( bundleInfoInternal->getID()
- + " bundle activator(" + bundleInfoInternal->getActivatorName()
+ + " bundle activator(" +
+ bundleInfoInternal->getActivatorName()
+ ") not found ").c_str());
return;
}
if (activateMethod == NULL)
{
- OC_LOG_V(ERROR, CONTAINER_TAG, "Cannot register bundle (%s)",
+ OIC_LOG_V(ERROR, CONTAINER_TAG, "Cannot register bundle (%s)",
std::string( bundleInfoInternal->getID()
+ " activate bundle method not found ").c_str());
return;
if (deactivateMethod == NULL)
{
- OC_LOG_V(ERROR, CONTAINER_TAG, "Cannot register bundle (%s)",
+ OIC_LOG_V(ERROR, CONTAINER_TAG, "Cannot register bundle (%s)",
std::string( bundleInfoInternal->getID()
+ " deactivate bundle method not found ").c_str());
return;
bundleInfoInternal->setLoaded(true);
- m_bundles[bundleInfo->getID()] = ((BundleInfoInternal *)bundleInfo);
+ m_bundles[bundleInfo->getID()] = bundleInfoInternal;
- OC_LOG(INFO, CONTAINER_TAG, "Bundle registered");
+ OIC_LOG(INFO, CONTAINER_TAG, "Bundle registered");
}
+
+
void ResourceContainerImpl::activateJavaBundle(string bundleId)
{
- OC_LOG(INFO, CONTAINER_TAG, "Activating java bundle");
+ OIC_LOG(INFO, CONTAINER_TAG, "Activating java bundle");
JavaVM *vm = getJavaVM(bundleId);
- BundleInfoInternal *bundleInfoInternal = (BundleInfoInternal *) m_bundles[bundleId];
+ bundleInfoInternal = m_bundles[bundleId];
JNIEnv *env;
int envStat = vm->GetEnv((void **) &env, JNI_VERSION_1_4);
{
if (vm->AttachCurrentThread((void **) &env, NULL) != 0)
{
- OC_LOG(ERROR, CONTAINER_TAG, "Failed to attach ");
+ OIC_LOG(ERROR, CONTAINER_TAG, "Failed to attach ");
}
}
else if (envStat == JNI_EVERSION)
{
- OC_LOG(ERROR, CONTAINER_TAG, "Env: version not supported ");
+ OIC_LOG(ERROR, CONTAINER_TAG, "Env: version not supported ");
}
env->CallVoidMethod(bundleInfoInternal->getJavaBundleActivatorObject(),
void ResourceContainerImpl::deactivateJavaBundle(string bundleId)
{
- OC_LOG(INFO, CONTAINER_TAG, "Deactivating java bundle");
+ OIC_LOG(INFO, CONTAINER_TAG, "Deactivating java bundle");
JavaVM *vm = getJavaVM(bundleId);
- BundleInfoInternal *bundleInfoInternal = (BundleInfoInternal *) m_bundles[bundleId];
+ shared_ptr<BundleInfoInternal>bundleInfoInternal = m_bundles[bundleId];
JNIEnv *env;
int envStat = vm->GetEnv((void **) &env, JNI_VERSION_1_4);
{
if (vm->AttachCurrentThread((void **) &env, NULL) != 0)
{
- OC_LOG(ERROR, CONTAINER_TAG, "Failed to attach ");
+ OIC_LOG(ERROR, CONTAINER_TAG, "Failed to attach ");
}
}
else if (envStat == JNI_EVERSION)
{
- OC_LOG(ERROR, CONTAINER_TAG, "Env: version not supported ");
+ OIC_LOG(ERROR, CONTAINER_TAG, "Env: version not supported ");
}
env->CallVoidMethod(bundleInfoInternal->getJavaBundleActivatorObject(),
void ResourceContainerImpl::unregisterBundleJava(string id)
{
- OC_LOG_V(INFO, CONTAINER_TAG, "Unregister Java bundle: (%s)", std::string(
+ OIC_LOG_V(INFO, CONTAINER_TAG, "Unregister Java bundle: (%s)", std::string(
m_bundles[id]->getID()).c_str());
- OC_LOG(INFO, CONTAINER_TAG, "Destroying JVM");
+ OIC_LOG(INFO, CONTAINER_TAG, "Destroying JVM");
m_bundleVM[id]->DestroyJavaVM();
- delete m_bundles[id];
m_bundles.erase(id);
}
#endif