X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=service%2Fresource-container%2Fsrc%2FResourceContainerImpl.cpp;h=099acd56c0a7faf0890b7c2a6d9ba3e638e0a125;hb=refs%2Ftags%2Fsubmit%2Ftizen_4.0%2F20171010.021147;hp=c6a27d19714fee0a69f9a524e5dac7bcc2cd8a3e;hpb=8945accc6fbae437bc06c8ebf207d4b029f8566d;p=platform%2Fupstream%2Fiotivity.git diff --git a/service/resource-container/src/ResourceContainerImpl.cpp b/service/resource-container/src/ResourceContainerImpl.cpp index c6a27d1..099acd5 100644 --- a/service/resource-container/src/ResourceContainerImpl.cpp +++ b/service/resource-container/src/ResourceContainerImpl.cpp @@ -68,71 +68,67 @@ namespace OIC 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 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::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(); - OIC_LOG(INFO, CONTAINER_TAG, "Resource container started."); } void ResourceContainerImpl::stopContainer() { 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 >::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()) @@ -149,13 +145,17 @@ namespace OIC } if (m_config) + { delete m_config; + } } - void ResourceContainerImpl::activateBundle(RCSBundleInfo *bundleInfo) + void ResourceContainerImpl::activateBundle(shared_ptr bundleInfo) { activationLock.lock(); - BundleInfoInternal *bundleInfoInternal = (BundleInfoInternal *) bundleInfo; + + shared_ptr bundleInfoInternal = + std::static_pointer_cast(bundleInfo); if (bundleInfoInternal->isLoaded()) { @@ -164,11 +164,13 @@ namespace OIC activationLock.unlock(); } - void ResourceContainerImpl::deactivateBundle(RCSBundleInfo *bundleInfo) + void ResourceContainerImpl::deactivateBundle(shared_ptr bundleInfo) { - if (((BundleInfoInternal *) bundleInfo)->isActivated()) + shared_ptr bundleInfoInternal = + std::static_pointer_cast(bundleInfo); + if (bundleInfoInternal->isActivated()) { - deactivateBundle(bundleInfo->getID()); + deactivateBundle(bundleInfoInternal->getID()); } } @@ -176,11 +178,17 @@ 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()); @@ -201,48 +209,52 @@ namespace OIC } // loads the bundle - void ResourceContainerImpl::registerBundle(RCSBundleInfo *bundleInfo) + void ResourceContainerImpl::registerBundle(shared_ptr bundleInfo) { OIC_LOG_V(INFO, CONTAINER_TAG, "Registering bundle: (%s)", std::string(bundleInfo->getPath()).c_str()); + shared_ptr bundleInfoInternal = + std::static_pointer_cast(bundleInfo); if (has_suffix(bundleInfo->getPath(), ".jar")) { #if(JAVA_SUPPORT) - ((BundleInfoInternal *) bundleInfo)->setJavaBundle(true); - ((BundleInfoInternal *) bundleInfo)->setSoBundle(false); + bundleInfoInternal->setJavaBundle(true); + bundleInfoInternal->setSoBundle(false); registerJavaBundle(bundleInfo); #else // android .jar library - ((BundleInfoInternal *) bundleInfo)->setSoBundle(false); - ((BundleInfoInternal *) bundleInfo)->setJavaBundle(false); + bundleInfoInternal->setSoBundle(false); + bundleInfoInternal->setJavaBundle(false); registerExtBundle(bundleInfo); #endif } - else if(has_suffix(bundleInfo->getPath(), ".so")) + else if (has_suffix(bundleInfo->getPath(), ".so")) { - ((BundleInfoInternal *) bundleInfo)->setSoBundle(true); - ((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 *) bundleInfo)->setSoBundle(false); - ((BundleInfoInternal *) bundleInfo)->setJavaBundle(false); + else + { + bundleInfoInternal->setSoBundle(false); + bundleInfoInternal->setJavaBundle(false); registerExtBundle(bundleInfo); } } - void ResourceContainerImpl::unregisterBundle(RCSBundleInfo *bundleInfo) + void ResourceContainerImpl::unregisterBundle(shared_ptr bundleInfo) { - BundleInfoInternal *bundleInfoInternal = (BundleInfoInternal *) bundleInfo; + shared_ptr bundleInfoInternal = + std::static_pointer_cast(bundleInfo); if (bundleInfoInternal->isLoaded() && !bundleInfoInternal->isActivated()) { if (bundleInfoInternal->getSoBundle()) { unregisterBundleSo(bundleInfo->getID()); } - else if(bundleInfoInternal->getJavaBundle()) + else if (bundleInfoInternal->getJavaBundle()) { #if(JAVA_SUPPORT) unregisterBundleJava(bundleInfo->getID()); @@ -258,7 +270,7 @@ namespace OIC 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) @@ -267,7 +279,6 @@ namespace OIC } else { - delete m_bundles[id]; m_bundles.erase(id); } } @@ -287,7 +298,8 @@ namespace OIC registrationLock.lock(); if (m_mapResources.find(strUri) == m_mapResources.end()) { - if (strInterface.empty()) { + if (strInterface.empty()) + { strInterface = "oic.if.baseline"; } @@ -318,7 +330,8 @@ namespace OIC strResourceType).c_str()); discoverInputResource(strUri); } - else{ + else + { OIC_LOG_V(INFO, CONTAINER_TAG, "Resource has no input (%s)", std::string(strUri + ", " + strResourceType).c_str()); @@ -392,7 +405,8 @@ namespace OIC { m_config->getResourceConfiguration(bundleId, configOutput); } - else{ + else + { OIC_LOG_V(DEBUG, CONTAINER_TAG, "no config present "); } } @@ -402,6 +416,8 @@ namespace OIC { 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() @@ -409,16 +425,16 @@ namespace OIC { 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, %d attributes",strResourceUri.c_str(), attr.size()); + 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); } @@ -429,15 +445,16 @@ namespace OIC RCSResourceAttributes attr; std::list 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, %d attributes",strResourceUri.c_str(), attributes.size()); + 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(); @@ -452,7 +469,7 @@ namespace OIC } OIC_LOG_V(INFO, CONTAINER_TAG, "Calling handleSetAttributeRequest"); - m_mapResources[strResourceUri]->handleSetAttributesRequest(attr); + m_mapResources[strResourceUri]->handleSetAttributesRequest(attr, queryParams); }; boost::thread setThread(setFunction); setThread.timed_join(boost::posix_time::seconds(BUNDLE_SET_GET_WAIT_SEC)); @@ -493,7 +510,9 @@ namespace OIC if (m_bundles.find(bundleId) != m_bundles.end()) { if (!m_bundles[bundleId]->isActivated()) + { activateBundle(m_bundles[bundleId]); + } else { OIC_LOG(ERROR, CONTAINER_TAG, "Bundle already started"); @@ -512,7 +531,9 @@ namespace OIC if (m_bundles.find(bundleId) != m_bundles.end()) { if (m_bundles[bundleId]->isActivated()) + { deactivateBundle(m_bundles[bundleId]); + } else { OIC_LOG(ERROR, CONTAINER_TAG, "Bundle not activated"); @@ -534,11 +555,13 @@ namespace OIC (void) bundleUri; if (m_bundles.find(bundleId) != m_bundles.end()) + { OIC_LOG(ERROR, CONTAINER_TAG, "BundleId already exist"); + } else { - BundleInfoInternal *bundleInfo = new BundleInfoInternal(); + shared_ptr bundleInfo = std::make_shared(); bundleInfo->setID(bundleId); bundleInfo->setPath(bundlePath); bundleInfo->setActivatorName(activator); @@ -546,8 +569,8 @@ namespace OIC { 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]); } OIC_LOG_V(INFO, CONTAINER_TAG, "Add Bundle: (%s)", @@ -563,12 +586,16 @@ namespace OIC 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 bundleInfo = m_bundles[bundleId]; if (bundleInfo->isActivated()) + { deactivateBundle(bundleInfo); + } if (bundleInfo->isLoaded()) + { unregisterBundle(bundleInfo); + } } else { @@ -582,12 +609,12 @@ namespace OIC OIC_LOG_V(INFO, CONTAINER_TAG, "list bundles (%d)", m_bundles.size()); std::list > ret; - for (std::map< std::string, BundleInfoInternal * >::iterator it = m_bundles.begin(); + for (std::map< std::string, shared_ptr >::iterator it = m_bundles.begin(); it != m_bundles.end(); ++it) { { std::unique_ptr bundleInfo(new BundleInfoInternal); - (bundleInfo)->setBundleInfo(it->second); + bundleInfo->setBundleInfo(it->second); ret.push_back(std::move(bundleInfo)); } } @@ -605,11 +632,17 @@ namespace OIC 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); } @@ -624,7 +657,8 @@ namespace OIC 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()); + 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]->getSoBundle()) @@ -653,16 +687,18 @@ namespace OIC } - void ResourceContainerImpl::registerSoBundle(RCSBundleInfo *bundleInfo) + void ResourceContainerImpl::registerSoBundle(shared_ptr bundleInfo) { OIC_LOG_V(DEBUG, CONTAINER_TAG, "Register SO bundle"); - const char *error; + 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 = + std::static_pointer_cast(bundleInfo); + void *bundleHandle = NULL; bundleHandle = dlopen(bundleInfo->getPath().c_str(), RTLD_LAZY); if ((error = dlerror()) != NULL) @@ -672,7 +708,8 @@ namespace OIC if (bundleHandle != NULL) { - OIC_LOG_V(DEBUG, CONTAINER_TAG, "Activator name %s", bundleInfoInternal->getActivatorName().c_str()); + OIC_LOG_V(DEBUG, CONTAINER_TAG, "Activator name %s", + bundleInfoInternal->getActivatorName().c_str()); bundleActivator = (activator_t *) dlsym(bundleHandle, ("" + bundleInfoInternal->getActivatorName() @@ -681,8 +718,10 @@ namespace OIC { 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() + else + { + OIC_LOG_V(DEBUG, CONTAINER_TAG, "Looked up %s", ("" + + bundleInfoInternal->getActivatorName() + "_externalActivateBundle").c_str()); } bundleDeactivator = @@ -693,8 +732,10 @@ namespace OIC { 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() + else + { + OIC_LOG_V(DEBUG, CONTAINER_TAG, "Looked up %s", ("" + + bundleInfoInternal->getActivatorName() + "_externalDeactivateBundle").c_str()); } resourceCreator = @@ -705,8 +746,10 @@ namespace OIC { 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() + else + { + OIC_LOG_V(DEBUG, CONTAINER_TAG, "Looked up %s", ("" + + bundleInfoInternal->getActivatorName() + "_externalCreateResource").c_str()); } resourceDestroyer = @@ -717,8 +760,10 @@ namespace OIC { 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() + else + { + OIC_LOG_V(DEBUG, CONTAINER_TAG, "Looked up %s", ("" + + bundleInfoInternal->getActivatorName() + "_externalDestroyResource").c_str()); } @@ -729,14 +774,14 @@ namespace OIC } 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 @@ -749,13 +794,17 @@ namespace OIC OIC_LOG_V(DEBUG, CONTAINER_TAG, "Register SO bundle finished"); } - void ResourceContainerImpl::registerExtBundle(RCSBundleInfo *bundleInfo){ + void ResourceContainerImpl::registerExtBundle(shared_ptr 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()); - m_bundles[bundleInfo->getID()] = ((BundleInfoInternal *)bundleInfo); + shared_ptr bundleInfoInternal = + std::static_pointer_cast(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; @@ -782,7 +831,7 @@ namespace OIC OIC_LOG(ERROR, CONTAINER_TAG, "Activation unsuccessful."); } - BundleInfoInternal *bundleInfoInternal = (BundleInfoInternal *) m_bundles[bundleId]; + shared_ptr bundleInfoInternal = m_bundles[bundleId]; bundleInfoInternal->setActivated(true); } @@ -802,11 +851,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 @@ -895,7 +943,7 @@ namespace OIC void ResourceContainerImpl::addSoBundleResource(const std::string &bundleId, resourceInfo newResourceInfo) { - resourceCreator_t *resourceCreator; + resourceCreator_t *resourceCreator = nullptr; resourceCreator = m_bundles[bundleId]->getResourceCreator(); @@ -939,7 +987,7 @@ namespace OIC activateJavaBundle(id); #endif } - else if(m_bundles[id]->getSoBundle()) + else if (m_bundles[id]->getSoBundle()) { activateSoBundle (id); } @@ -954,7 +1002,7 @@ namespace OIC return m_bundleVM[bundleId]; } - void ResourceContainerImpl::registerJavaBundle(RCSBundleInfo *bundleInfo) + void ResourceContainerImpl::registerJavaBundle(shared_ptr bundleInfo) { OIC_LOG_V(INFO, CONTAINER_TAG, "Registering Java bundle (%s)", std::string(bundleInfo->getID()).c_str()); @@ -963,7 +1011,9 @@ namespace OIC JavaVMInitArgs vm_args; JavaVMOption options[3]; - BundleInfoInternal *bundleInfoInternal = (BundleInfoInternal *) bundleInfo; + shared_ptr bundleInfoInternal = + std::static_pointer_cast(bundleInfo); + if (FILE *file = fopen(bundleInfo->getPath().c_str(), "r")) { @@ -985,7 +1035,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()); @@ -994,7 +1044,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, @@ -1074,7 +1124,7 @@ namespace OIC bundleInfoInternal->setLoaded(true); - m_bundles[bundleInfo->getID()] = ((BundleInfoInternal *)bundleInfo); + m_bundles[bundleInfo->getID()] = bundleInfoInternal; OIC_LOG(INFO, CONTAINER_TAG, "Bundle registered"); @@ -1087,7 +1137,7 @@ namespace OIC 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); @@ -1114,7 +1164,7 @@ namespace OIC OIC_LOG(INFO, CONTAINER_TAG, "Deactivating java bundle"); JavaVM *vm = getJavaVM(bundleId); - BundleInfoInternal *bundleInfoInternal = (BundleInfoInternal *) m_bundles[bundleId]; + shared_ptrbundleInfoInternal = m_bundles[bundleId]; JNIEnv *env; int envStat = vm->GetEnv((void **) &env, JNI_VERSION_1_4); @@ -1145,7 +1195,6 @@ namespace OIC m_bundleVM[id]->DestroyJavaVM(); - delete m_bundles[id]; m_bundles.erase(id); } #endif