//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+#include "ResourceContainerImpl.h"
+
#include <dlfcn.h>
#include <unistd.h>
#include <string.h>
#include <fstream>
#include <iostream>
-#include <fstream>
#include <stdio.h>
#include <thread>
#include <mutex>
+#include <algorithm>
-#include "ResourceContainerImpl.h"
#include "BundleActivator.h"
-#include "RCSResourceContainer.h"
-#include "BundleInfoInternal.h"
-#include "logger.h"
-#include "oc_logger.hpp"
#include "SoftSensorResource.h"
+#include "InternalTypes.h"
-using OC::oc_log_stream;
using namespace OIC::Service;
-
-namespace
-{
- const std::string INPUT_RESOURCE = std::string("input");
- const std::string INPUT_RESOURCE_URI = std::string("resourceUri");
- const std::string INPUT_RESOURCE_TYPE = std::string("resourceType");
- const std::string INPUT_RESOURCE_ATTRIBUTENAME = std::string("name");
-
- const std::string OUTPUT_RESOURCE_URI = std::string("resourceUri");
-}
-
-auto error_logger = []() -> boost::iostreams::stream<OC::oc_log_stream> &
-{
- static OC::oc_log_stream ols(oc_make_ostream_logger);
- static boost::iostreams::stream<OC::oc_log_stream> os(ols);
- os->set_level(OC_LOG_ERROR);
- os->set_module("ResourceContainerImpl");
- return os;
-};
-
-auto info_logger = []() -> boost::iostreams::stream<OC::oc_log_stream> &
-{
- static OC::oc_log_stream ols(oc_make_ostream_logger);
- static boost::iostreams::stream<OC::oc_log_stream> os(ols);
- os->set_level(OC_LOG_INFO);
- os->set_module("ResourceContainerImpl");
- return os;
-};
-
using namespace std;
-using namespace OIC::Service;
namespace OIC
{
namespace Service
{
-
ResourceContainerImpl::ResourceContainerImpl()
{
m_config = nullptr;
bool has_suffix(const std::string &str, const std::string &suffix)
{
return str.size() >= suffix.size()
- && str.compare(str.size() - suffix.size(), suffix.size(), suffix) == 0;
+ && str.compare(str.size() - suffix.size(), suffix.size(), suffix) == 0;
}
void ResourceContainerImpl::startContainer(const std::string &configFile)
{
- info_logger() << "Starting resource container " << endl;
+ OC_LOG_V(INFO, CONTAINER_TAG, "Starting resource container.");
#if (JAVA_SUPPORT)
- info_logger() << "Resource container has Java support" << endl;
+ OC_LOG_V(INFO, CONTAINER_TAG, "Resource container has Java support.");
#else
- info_logger() << "Resource container without Java support" << endl;
+ OC_LOG_V(INFO, CONTAINER_TAG, "Resource container without Java support.");
#endif
if (!configFile.empty())
for (unsigned int i = 0; i < bundles.size(); i++)
{
RCSBundleInfo *bundleInfo = RCSBundleInfo::build();
- bundleInfo->setPath(bundles[i]["path"]);
- bundleInfo->setVersion(bundles[i]["version"]);
- bundleInfo->setID(bundles[i]["id"]);
- if (!bundles[i]["activator"].empty())
+ 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]["activator"];
+ string activatorName = bundles[i][BUNDLE_ACTIVATOR];
std::replace(activatorName.begin(), activatorName.end(), '.', '/');
((BundleInfoInternal *) bundleInfo)->setActivatorName(activatorName);
((BundleInfoInternal *) bundleInfo)->setLibraryPath(
- bundles[i]["libraryPath"]);
-
+ bundles[i][BUNDLE_LIBRARY_PATH]);
}
- info_logger() << "Init Bundle:" << bundles[i]["id"] << ";"
- << bundles[i]["path"] << endl;
+
+ OC_LOG_V(INFO, CONTAINER_TAG, std::string("Init Bundle:" + bundles[i][BUNDLE_ID] + ";" +
+ bundles[i][BUNDLE_PATH]).c_str());
+
registerBundle(bundleInfo);
auto f = std::bind(&ResourceContainerImpl::activateBundleThread, this,
- bundleInfo);
+ bundleInfo);
boost::thread activator(f);
m_activators.push_back(std::move(activator));
}
else
{
- error_logger() << "Container started with invalid configfile path" << endl;
+ OC_LOG_V(ERROR, CONTAINER_TAG, "Container started with invalid configfile path.");
}
}
else
{
- info_logger() << "No configuration file for the container provided" << endl;
+ OC_LOG_V(INFO, CONTAINER_TAG, "No configuration file for the container provided.");
}
+
vector< boost::thread >::iterator activatorIterator;
for (activatorIterator = m_activators.begin(); activatorIterator != m_activators.end();
- activatorIterator++)
+ activatorIterator++)
{
activatorIterator->timed_join(
- boost::posix_time::seconds(BUNDLE_ACTIVATION_WAIT_SEC)); // wait for bundles to be activated
+ boost::posix_time::seconds(BUNDLE_ACTIVATION_WAIT_SEC)); // wait for bundles to be activated
}
}
void ResourceContainerImpl::stopContainer()
{
- info_logger() << "Stopping resource container.";
+ OC_LOG_V(INFO, CONTAINER_TAG, "Stopping resource container.");
+
for (std::map< std::string, BundleInfoInternal * >::iterator it = m_bundles.begin();
- it != m_bundles.end(); ++it)
+ it != m_bundles.end(); ++it)
{
BundleInfoInternal *bundleInfo = it->second;
deactivateBundle(bundleInfo);
void ResourceContainerImpl::activateBundle(const std::string &id)
{
-
- info_logger() << "Activating bundle: " << m_bundles[id]->getID() << endl;
+ OC_LOG_V(INFO, CONTAINER_TAG, std::string("Activating bundle: " + m_bundles[id]->getID()).c_str());
if (m_bundles[id]->getJavaBundle())
{
activateSoBundle(id);
}
- info_logger() << "Bundle activated: " << m_bundles[id]->getID() << endl;
-
+ OC_LOG_V(INFO, CONTAINER_TAG, std::string("Bundle activated: " + m_bundles[id]->getID()).c_str());
}
void ResourceContainerImpl::deactivateBundle(const std::string &id)
{
-
if (m_bundles[id]->getJavaBundle())
{
#if(JAVA_SUPPORT)
// loads the bundle
void ResourceContainerImpl::registerBundle(RCSBundleInfo *bundleInfo)
{
- info_logger() << "Registering bundle: " << bundleInfo->getPath() << endl;
+ OC_LOG_V(INFO, CONTAINER_TAG, std::string("Registering bundle: " + bundleInfo->getPath()).c_str());
if (has_suffix(bundleInfo->getPath(), ".jar"))
{
void ResourceContainerImpl::unregisterBundleSo(const std::string &id)
{
void *bundleHandle = m_bundles[id]->getBundleHandle();
- info_logger() << "Unregister bundle: " << m_bundles[id]->getID() << ", "
- << m_bundles[id]->getID() << endl;
+
+ OC_LOG_V(INFO, CONTAINER_TAG, std::string("Unregister bundle: " + m_bundles[id]->getID()).c_str());
+
const char *error;
dlclose(bundleHandle);
+
if ((error = dlerror()) != NULL)
{
- error_logger() << error << endl;
+ OC_LOG_V(ERROR, CONTAINER_TAG, error);
}
else
{
void ResourceContainerImpl::registerResource(BundleResource *resource)
{
-
string strUri = resource->m_uri;
string strResourceType = resource->m_resourceType;
RCSResourceObject::Ptr server = nullptr;
- info_logger() << "Registration of resource " << strUri << "," << strResourceType
- << endl;
+ OC_LOG_V(INFO, CONTAINER_TAG, std::string("Registration of resource " + strUri + ", " +
+ strResourceType).c_str());
registrationLock.lock();
if (m_mapResources.find(strUri) == m_mapResources.end())
resource->registerObserver(this);
server->setGetRequestHandler(
- std::bind(&ResourceContainerImpl::getRequestHandler, this,
- std::placeholders::_1, std::placeholders::_2));
+ std::bind(&ResourceContainerImpl::getRequestHandler, this,
+ std::placeholders::_1, std::placeholders::_2));
server->setSetRequestHandler(
- std::bind(&ResourceContainerImpl::setRequestHandler, this,
- std::placeholders::_1, std::placeholders::_2));
+ std::bind(&ResourceContainerImpl::setRequestHandler, this,
+ std::placeholders::_1, std::placeholders::_2));
- info_logger() << "Registration finished " << strUri << "," << strResourceType
- << endl;
+ OC_LOG_V(INFO, CONTAINER_TAG, std::string("Registration finished " + strUri + ", " +
+ strResourceType).c_str());
if (m_config->isHasInput(resource->m_bundleId))
{
}
else
{
- error_logger() << "resource with " << strUri << " already exists." << endl;
+ OC_LOG_V(ERROR, CONTAINER_TAG, std::string("resource with " + strUri + " already exists.").c_str());
}
registrationLock.unlock();
}
string strUri = resource->m_uri;
string strResourceType = resource->m_resourceType;
- info_logger() << "Unregistration of resource " << resource->m_uri << ","
- << resource->m_resourceType << endl;
+ OC_LOG_V(INFO, CONTAINER_TAG, std::string("Unregistration of resource " + resource->m_uri + ", " +
+ resource->m_resourceType).c_str());
if (m_config->isHasInput(resource->m_bundleId))
{
RCSResourceAttributes attr;
if (m_mapServers.find(request.getResourceUri()) != m_mapServers.end()
- && m_mapResources.find(request.getResourceUri()) != m_mapResources.end())
+ && m_mapResources.find(request.getResourceUri()) != m_mapResources.end())
{
auto getFunction = [this, &attr, &request] ()
{
RCSResourceAttributes attr = attributes;
if (m_mapServers.find(request.getResourceUri()) != m_mapServers.end()
- && m_mapResources.find(request.getResourceUri()) != m_mapResources.end())
+ && m_mapResources.find(request.getResourceUri()) != m_mapResources.end())
{
auto setFunction = [this, &attr, &request] ()
{
void ResourceContainerImpl::onNotificationReceived(const std::string &strResourceUri)
{
- info_logger() << "ResourceContainerImpl::onNotificationReceived\n\tnotification from "
- << strResourceUri << ".\n";
+ OC_LOG_V(INFO, CONTAINER_TAG, std::string("onNotificationReceived\n\tnotification from "
+ + strResourceUri + ".").c_str());
if (m_mapServers.find(strResourceUri) != m_mapServers.end())
{
const std::string &strResourceType)
{
return RCSResourceObject::Builder(strUri, strResourceType, "DEFAULT_INTERFACE").setObservable(
- true).setDiscoverable(true).build();
+ true).setDiscoverable(true).build();
}
void ResourceContainerImpl::startBundle(const std::string &bundleId)
if (!m_bundles[bundleId]->isActivated())
activateBundle(m_bundles[bundleId]);
else
- error_logger() << "Bundle already started" << endl;
+ {
+ OC_LOG_V(ERROR, CONTAINER_TAG, "Bundle already started");
+ }
}
else
{
- error_logger() << "Bundle with ID \'" << bundleId << "\' is not registered."
- << endl;
+ OC_LOG_V(ERROR, CONTAINER_TAG,
+ std::string("Bundle with ID \'" + bundleId + "\' is not registered.").c_str());
}
}
if (m_bundles[bundleId]->isActivated())
deactivateBundle(m_bundles[bundleId]);
else
- error_logger() << "Bundle not activated" << endl;
+ {
+ OC_LOG_V(ERROR, CONTAINER_TAG, "Bundle not activated");
+ }
}
else
{
- error_logger() << "Bundle with ID \'" << bundleId << "\' is not registered."
- << endl;
+ OC_LOG_V(ERROR, CONTAINER_TAG,
+ std::string("Bundle with ID \'" + bundleId + "\' is not registered.").c_str());
}
}
void ResourceContainerImpl::addBundle(const std::string &bundleId,
- const std::string &bundleUri, const std::string &bundlePath,
- std::map< string, string > params)
+ const std::string &bundleUri, const std::string &bundlePath,
+ std::map< string, string > params)
{
(void) bundleUri;
+
if (m_bundles.find(bundleId) != m_bundles.end())
- error_logger() << "BundleId already exist" << endl;
+ OC_LOG_V(ERROR, CONTAINER_TAG, "BundleId already exist");
else
{
RCSBundleInfo *bundleInfo = RCSBundleInfo::build();
bundleInfo->setID(bundleId);
bundleInfo->setPath(bundlePath);
- if (params.find("activator") != params.end())
+ if (params.find(BUNDLE_ACTIVATOR) != params.end())
{
- string activatorName = params["activator"];
+ string activatorName = params[BUNDLE_ACTIVATOR];
std::replace(activatorName.begin(), activatorName.end(), '.', '/');
((BundleInfoInternal *) bundleInfo)->setActivatorName(activatorName);
- ((BundleInfoInternal *) bundleInfo)->setLibraryPath(params["libraryPath"]);
+ ((BundleInfoInternal *)bundleInfo)->setLibraryPath(params[BUNDLE_LIBRARY_PATH]);
}
- info_logger() << "Add Bundle:" << bundleInfo->getID().c_str() << ";"
- << bundleInfo->getPath().c_str() << endl;
+ OC_LOG_V(INFO, CONTAINER_TAG, std::string("Add Bundle: " + bundleInfo->getID() + "; " +
+ bundleInfo->getPath()).c_str());
registerBundle(bundleInfo);
}
}
else
{
- error_logger() << "Bundle with ID \'" << bundleId << "\' is not registered."
- << endl;
+ OC_LOG_V(ERROR, CONTAINER_TAG,
+ std::string("Bundle with ID \'" + bundleId + "\' is not registered.").c_str());
}
}
{
std::list< RCSBundleInfo * > ret;
for (std::map< std::string, BundleInfoInternal * >::iterator it = m_bundles.begin();
- it != m_bundles.end(); ++it)
+ it != m_bundles.end(); ++it)
{
{
RCSBundleInfo *bundleInfo = RCSBundleInfo::build();
((BundleInfoInternal *) bundleInfo)->setBundleInfo(
- (RCSBundleInfo *) it->second);
+ (RCSBundleInfo *) it->second);
ret.push_back(bundleInfo);
}
}
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"];
+ 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
{
- error_logger() << "Bundle with ID \'" << bundleId << "\' is not registered."
- << endl;
+ OC_LOG_V(ERROR, CONTAINER_TAG,
+ std::string("Bundle with ID \'" + bundleId + "\' is not registered.").c_str());
}
}
}
else
{
- error_logger() << "Bundle with ID \'" << bundleId << "\' is not registered."
- << endl;
+ OC_LOG_V(ERROR, CONTAINER_TAG,
+ std::string("Bundle with ID \'" + bundleId + "\' is not registered.").c_str());
}
}
resourceCreator_t *resourceCreator = NULL;
resourceDestroyer_t *resourceDestroyer = NULL;
- //sstream << bundleInfo.path << std::ends;
-
void *bundleHandle = NULL;
bundleHandle = dlopen(bundleInfo->getPath().c_str(), RTLD_LAZY);
{
bundleActivator = (activator_t *) dlsym(bundleHandle, "externalActivateBundle");
bundleDeactivator = (deactivator_t *) dlsym(bundleHandle,
- "externalDeactivateBundle");
+ "externalDeactivateBundle");
resourceCreator = (resourceCreator_t *) dlsym(bundleHandle,
- "externalCreateResource");
+ "externalCreateResource");
resourceDestroyer = (resourceDestroyer_t *) dlsym(bundleHandle,
- "externalDestroyResource");
+ "externalDestroyResource");
if ((error = dlerror()) != NULL)
{
- error_logger() << error << endl;
+ OC_LOG_V(ERROR, CONTAINER_TAG, error);
}
else
{
{
if ((error = dlerror()) != NULL)
{
- error_logger() << error << endl;
+ OC_LOG_V(ERROR, CONTAINER_TAG, error);
}
}
}
else
{
//Unload module and return error
- error_logger() << "Activation unsuccessful." << endl;
+ OC_LOG_V(ERROR, CONTAINER_TAG, "Activation unsuccessful.");
}
BundleInfoInternal *bundleInfoInternal = (BundleInfoInternal *) m_bundles[bundleId];
DiscoverResourceUnit::Ptr newDiscoverUnit = std::make_shared
< DiscoverResourceUnit > (outputResourceUri);
newDiscoverUnit->startDiscover(
- DiscoverResourceUnit::DiscoverResourceInfo(uri, type,
- attributeName),
- std::bind(&SoftSensorResource::onUpdatedInputResource,
- (SoftSensorResource*) foundOutputResource->second,
- std::placeholders::_1, std::placeholders::_2));
+ DiscoverResourceUnit::DiscoverResourceInfo(uri, type,
+ attributeName),
+ std::bind(&SoftSensorResource::onUpdatedInputResource,
+ (SoftSensorResource *) foundOutputResource->second,
+ std::placeholders::_1, std::placeholders::_2));
auto foundDiscoverResource = m_mapDiscoverResourceUnits.find(
- outputResourceUri);
+ outputResourceUri);
if (foundDiscoverResource != m_mapDiscoverResourceUnits.end())
{
foundDiscoverResource->second.push_back(newDiscoverUnit);
else
{
m_mapDiscoverResourceUnits.insert(
- std::make_pair(outputResourceUri,
- std::list< DiscoverResourceUnit::Ptr >
- { newDiscoverUnit }));
+ std::make_pair(outputResourceUri,
+ std::list< DiscoverResourceUnit::Ptr >
+ { newDiscoverUnit }));
}
}
}
void ResourceContainerImpl::deactivateSoBundle(const std::string &id)
{
deactivator_t *bundleDeactivator = m_bundles[id]->getBundleDeactivator();
- info_logger() << "De-activating bundle: " << m_bundles[id]->getID() << endl;
+
+ OC_LOG_V(INFO, CONTAINER_TAG, std::string("De-activating bundle: " +
+ m_bundles[id]->getID()).c_str());
if (bundleDeactivator != NULL)
{
else
{
//Unload module and return error
- error_logger() << "De-activation unsuccessful." << endl;
+ OC_LOG_V(ERROR, CONTAINER_TAG, "De-activation unsuccessful.");
}
}
}
else
{
- error_logger() << "addResource unsuccessful." << endl;
+ OC_LOG_V(ERROR, CONTAINER_TAG, "addResource unsuccessful.");
}
}
if (m_mapResources.find(resourceUri) != m_mapResources.end())
{
resourceDestroyer_t *resourceDestroyer =
- m_bundles[bundleId]->getResourceDestroyer();
+ m_bundles[bundleId]->getResourceDestroyer();
if (resourceDestroyer != NULL)
{
}
else
{
- error_logger() << "removeResource unsuccessful." << endl;
+ OC_LOG_V(ERROR, CONTAINER_TAG, "removeResource unsuccessful.");
}
}
}
- void ResourceContainerImpl::activateBundleThread(RCSBundleInfo* rcsBundleInfo)
+ void ResourceContainerImpl::activateBundleThread(RCSBundleInfo *rcsBundleInfo)
{
activateBundle(rcsBundleInfo);
}
#if(JAVA_SUPPORT)
- JavaVM *ResourceContainerImpl::getJavaVM(string bundleId)
- {
- return m_bundleVM[bundleId];
- }
-
- void ResourceContainerImpl::registerJavaBundle(RCSBundleInfo *bundleInfo)
- {
- info_logger() << "Registering Java bundle " << bundleInfo->getID() << endl;
- JavaVM *jvm;
- JNIEnv *env;
- JavaVMInitArgs vm_args;
- JavaVMOption options[3];
-
- BundleInfoInternal *bundleInfoInternal = (BundleInfoInternal *) bundleInfo;
-
- if (FILE *file = fopen(bundleInfo->getPath().c_str(), "r"))
+ JavaVM *ResourceContainerImpl::getJavaVM(string bundleId)
{
- fclose(file);
- info_logger() << "Resource bundle " << bundleInfo->getPath().c_str() << " available." << endl;
- //return true;
+ return m_bundleVM[bundleId];
}
- else
+
+ void ResourceContainerImpl::registerJavaBundle(RCSBundleInfo *bundleInfo)
{
- error_logger() << "Resource bundle " << bundleInfo->getPath().c_str() << " not available" << endl;
- return;
- }
+ OC_LOG_V(INFO, CONTAINER_TAG, std::string("Registering Java bundle " +
+ bundleInfo->getID()).c_str());
- char optionString[] = "-Djava.compiler=NONE";
- options[0].optionString = optionString;
- char classpath[1000];
- strcpy(classpath, "-Djava.class.path=");
- strcat(classpath, bundleInfo->getPath().c_str());
+ JavaVM *jvm;
+ JNIEnv *env;
+ JavaVMInitArgs vm_args;
+ JavaVMOption options[3];
- info_logger() << "Configured classpath: " << classpath << "|" << endl;
+ BundleInfoInternal *bundleInfoInternal = (BundleInfoInternal *) bundleInfo;
- options[1].optionString = classpath;
+ if (FILE *file = fopen(bundleInfo->getPath().c_str(), "r"))
+ {
+ fclose(file);
- char libraryPath[1000];
- strcpy(libraryPath, "-Djava.library.path=");
- strcat(libraryPath, bundleInfo->getLibraryPath().c_str());
- options[2].optionString = libraryPath;
+ OC_LOG_V(INFO, CONTAINER_TAG, std::string("Resource bundle " + bundleInfo->getPath() +
+ " available.").c_str());
+ }
+ else
+ {
+ OC_LOG_V(ERROR, CONTAINER_TAG,
+ std::string("Resource bundle " + bundleInfo->getPath() + " not available.").c_str());
- info_logger() << "Configured library path: " << libraryPath << "|" << endl;
+ return;
+ }
- vm_args.version = JNI_VERSION_1_4;
- vm_args.options = options;
- vm_args.nOptions = 3;
- vm_args.ignoreUnrecognized = 1;
+ char optionString[] = "-Djava.compiler=NONE";
+ options[0].optionString = optionString;
+ char classpath[1000];
+ strcpy(classpath, "-Djava.class.path=");
+ strcat(classpath, bundleInfo->getPath().c_str());
- int res;
- res = JNI_CreateJavaVM(&jvm, (void **) &env, &vm_args);
+ OC_LOG_V(INFO, CONTAINER_TAG, std::string("Configured classpath: ").append(classpath).c_str());
- if (res < 0)
- {
- error_logger() << " cannot create JavaVM." << endl;
- return;
- }
- else
- {
- info_logger() << "JVM successfully created " << endl;
- }
+ options[1].optionString = classpath;
- m_bundleVM.insert(std::pair< string, JavaVM * >(bundleInfo->getID(), jvm));
+ char libraryPath[1000];
+ strcpy(libraryPath, "-Djava.library.path=");
+ strcat(libraryPath, bundleInfo->getLibraryPath().c_str());
+ options[2].optionString = libraryPath;
- const char *className = bundleInfoInternal->getActivatorName().c_str();
+ OC_LOG_V(INFO, CONTAINER_TAG, std::string("Configured library path: ").append(libraryPath).c_str());
- info_logger() << "Looking up class: " << bundleInfoInternal->getActivatorName() << "|" << endl;
+ vm_args.version = JNI_VERSION_1_4;
+ vm_args.options = options;
+ vm_args.nOptions = 3;
+ vm_args.ignoreUnrecognized = 1;
- jclass bundleActivatorClass = env->FindClass(className);
+ int res;
+ res = JNI_CreateJavaVM(&jvm, (void **) &env, &vm_args);
- if (bundleActivatorClass == NULL)
- {
- error_logger() << "Cannot register bundle " << bundleInfoInternal->getID()
- << " bundle activator(" << bundleInfoInternal->getActivatorName()
- << ") not found " << endl;
- return;
- }
+ if (res < 0)
+ {
+ OC_LOG_V(ERROR, CONTAINER_TAG, "cannot create JavaVM.");
+ return;
+ }
+ else
+ {
+ OC_LOG_V(INFO, CONTAINER_TAG, "JVM successfully created.");
+ }
- jmethodID activateMethod = env->GetMethodID(bundleActivatorClass, "activateBundle",
- "()V");
+ m_bundleVM.insert(std::pair< string, JavaVM * >(bundleInfo->getID(), jvm));
- if (activateMethod == NULL)
- {
- error_logger() << "Cannot register bundle " << bundleInfoInternal->getID()
- << " activate bundle method not found " << endl;
- return;
- }
- bundleInfoInternal->setJavaBundleActivatorMethod(activateMethod);
+ const char *className = bundleInfoInternal->getActivatorName().c_str();
- jmethodID deactivateMethod = env->GetMethodID(bundleActivatorClass, "deactivateBundle",
- "()V");
+ OC_LOG_V(INFO, CONTAINER_TAG, std::string("Looking up class: " +
+ bundleInfoInternal->getActivatorName() + "|").c_str());
- if (deactivateMethod == NULL)
- {
- error_logger() << "Cannot register bundle " << bundleInfoInternal->getID()
- << " deactivate bundle method not found " << endl;
- return;
- }
+ jclass bundleActivatorClass = env->FindClass(className);
- bundleInfoInternal->setJavaBundleDeactivatorMethod(deactivateMethod);
+ if (bundleActivatorClass == NULL)
+ {
+ OC_LOG_V(ERROR, CONTAINER_TAG, std::string("Cannot register bundle " + bundleInfoInternal->getID()
+ + " bundle activator(" + bundleInfoInternal->getActivatorName()
+ + ") not found ").c_str());
+ return;
+ }
- jmethodID constructor;
+ jmethodID activateMethod = env->GetMethodID(bundleActivatorClass, "activateBundle",
+ "()V");
- constructor = env->GetMethodID(bundleActivatorClass, "<init>", "(Ljava/lang/String;)V");
+ if (activateMethod == NULL)
+ {
+ OC_LOG_V(ERROR, CONTAINER_TAG, std::string("Cannot register bundle " + bundleInfoInternal->getID()
+ + " activate bundle method not found ").c_str());
- jstring bundleID = env->NewStringUTF(bundleInfoInternal->getID().c_str());
+ return;
+ }
+ bundleInfoInternal->setJavaBundleActivatorMethod(activateMethod);
- jobject bundleActivator = env->NewObject(bundleActivatorClass, constructor, bundleID);
+ jmethodID deactivateMethod = env->GetMethodID(bundleActivatorClass, "deactivateBundle",
+ "()V");
- bundleInfoInternal->setJavaBundleActivatorObject(bundleActivator);
+ if (deactivateMethod == NULL)
+ {
+ OC_LOG_V(ERROR, CONTAINER_TAG, std::string("Cannot register bundle " + bundleInfoInternal->getID()
+ + " deactivate bundle method not found ").c_str());
- bundleInfoInternal->setLoaded(true);
+ return;
+ }
- m_bundles[bundleInfo->getID()] = ((BundleInfoInternal *)bundleInfo);
+ bundleInfoInternal->setJavaBundleDeactivatorMethod(deactivateMethod);
- info_logger() << "Bundle registered" << endl;
- }
+ jmethodID constructor;
- void ResourceContainerImpl::activateJavaBundle(string bundleId)
- {
- info_logger() << "Activating java bundle" << endl;
- JavaVM *vm = getJavaVM(bundleId);
- BundleInfoInternal *bundleInfoInternal = (BundleInfoInternal *) m_bundles[bundleId];
- JNIEnv *env;
- int envStat = vm->GetEnv((void **) &env, JNI_VERSION_1_4);
+ constructor = env->GetMethodID(bundleActivatorClass, "<init>", "(Ljava/lang/String;)V");
- if (envStat == JNI_EDETACHED)
- {
- if (vm->AttachCurrentThread((void **) &env, NULL) != 0)
- {
- error_logger() << "Failed to attach " << endl;
- }
- }
- else if (envStat == JNI_EVERSION)
- {
- error_logger() << "Env: version not supported " << endl;
- }
+ jstring bundleID = env->NewStringUTF(bundleInfoInternal->getID().c_str());
- env->CallVoidMethod(bundleInfoInternal->getJavaBundleActivatorObject(),
- bundleInfoInternal->getJavaBundleActivatorMethod());
+ jobject bundleActivator = env->NewObject(bundleActivatorClass, constructor, bundleID);
- m_bundles[bundleId]->setActivated(true);
- }
+ bundleInfoInternal->setJavaBundleActivatorObject(bundleActivator);
- void ResourceContainerImpl::deactivateJavaBundle(string bundleId)
- {
- info_logger() << "Deactivating java bundle" << endl;
- JavaVM *vm = getJavaVM(bundleId);
- BundleInfoInternal *bundleInfoInternal = (BundleInfoInternal *) m_bundles[bundleId];
- JNIEnv *env;
- int envStat = vm->GetEnv((void **) &env, JNI_VERSION_1_4);
+ bundleInfoInternal->setLoaded(true);
+
+ m_bundles[bundleInfo->getID()] = ((BundleInfoInternal *)bundleInfo);
- if (envStat == JNI_EDETACHED)
+ OC_LOG_V(INFO, CONTAINER_TAG, "Bundle registered");
+ }
+
+ void ResourceContainerImpl::activateJavaBundle(string bundleId)
{
- if (vm->AttachCurrentThread((void **) &env, NULL) != 0)
+ OC_LOG_V(INFO, CONTAINER_TAG, "Activating java bundle");
+
+ JavaVM *vm = getJavaVM(bundleId);
+ BundleInfoInternal *bundleInfoInternal = (BundleInfoInternal *) m_bundles[bundleId];
+ JNIEnv *env;
+ int envStat = vm->GetEnv((void **) &env, JNI_VERSION_1_4);
+
+ if (envStat == JNI_EDETACHED)
{
- error_logger() << "Failed to attach " << endl;
+ if (vm->AttachCurrentThread((void **) &env, NULL) != 0)
+ {
+ OC_LOG_V(ERROR, CONTAINER_TAG, "Failed to attach ");
+ }
}
+ else if (envStat == JNI_EVERSION)
+ {
+ OC_LOG_V(ERROR, CONTAINER_TAG, "Env: version not supported ");
+ }
+
+ env->CallVoidMethod(bundleInfoInternal->getJavaBundleActivatorObject(),
+ bundleInfoInternal->getJavaBundleActivatorMethod());
+
+ m_bundles[bundleId]->setActivated(true);
}
- else if (envStat == JNI_EVERSION)
+
+ void ResourceContainerImpl::deactivateJavaBundle(string bundleId)
{
- error_logger() << "Env: version not supported " << endl;
- }
+ OC_LOG_V(INFO, CONTAINER_TAG, "Deactivating java bundle");
- env->CallVoidMethod(bundleInfoInternal->getJavaBundleActivatorObject(),
- bundleInfoInternal->getJavaBundleDeactivatorMethod());
+ JavaVM *vm = getJavaVM(bundleId);
+ BundleInfoInternal *bundleInfoInternal = (BundleInfoInternal *) m_bundles[bundleId];
+ JNIEnv *env;
+ int envStat = vm->GetEnv((void **) &env, JNI_VERSION_1_4);
- m_bundles[bundleId]->setActivated(false);
- }
+ if (envStat == JNI_EDETACHED)
+ {
+ if (vm->AttachCurrentThread((void **) &env, NULL) != 0)
+ {
+ OC_LOG_V(ERROR, CONTAINER_TAG, "Failed to attach ");
+ }
+ }
+ else if (envStat == JNI_EVERSION)
+ {
+ OC_LOG_V(ERROR, CONTAINER_TAG, "Env: version not supported ");
+ }
- void ResourceContainerImpl::unregisterBundleJava(string id)
- {
- info_logger() << "Unregister Java bundle: " << m_bundles[id]->getID() << ", "
- << m_bundles[id]->getID() << endl;
+ env->CallVoidMethod(bundleInfoInternal->getJavaBundleActivatorObject(),
+ bundleInfoInternal->getJavaBundleDeactivatorMethod());
- info_logger() << "Destroying JVM" << endl;
- m_bundleVM[id]->DestroyJavaVM();
+ m_bundles[bundleId]->setActivated(false);
+ }
- delete m_bundles[id];
- m_bundles.erase(id);
- }
-#endif
- }
+ void ResourceContainerImpl::unregisterBundleJava(string id)
+ {
+ OC_LOG_V(INFO, CONTAINER_TAG, std::string("Unregister Java bundle: " +
+ m_bundles[id]->getID()).c_str());
+
+ OC_LOG_V(INFO, CONTAINER_TAG, "Destroying JVM");
-}
+ m_bundleVM[id]->DestroyJavaVM();
+ delete m_bundles[id];
+ m_bundles.erase(id);
+ }
+#endif
+ }
+}
\ No newline at end of file