Modify logs in resource container using OC_LOG
authorMinji Park <minjii.park@samsung.com>
Mon, 14 Sep 2015 12:45:25 +0000 (21:45 +0900)
committerMadan Lanka <lanka.madan@samsung.com>
Tue, 15 Sep 2015 05:49:14 +0000 (05:49 +0000)
- add error logs in container
- modify existing logs using OC_LOG
- define common strings for bundle configuration in seperate header

Change-Id: Ib702cab1c62fe0d9038f86d99ca8f278eb4a19ed
Signed-off-by: Minji Park <minjii.park@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/2513
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Markus Jung <markus.jung@samsung.com>
Reviewed-by: Madan Lanka <lanka.madan@samsung.com>
service/resource-encapsulation/src/resourceContainer/include/InternalTypes.h [new file with mode: 0644]
service/resource-encapsulation/src/resourceContainer/src/BaseActivator.cpp
service/resource-encapsulation/src/resourceContainer/src/Configuration.cpp
service/resource-encapsulation/src/resourceContainer/src/JavaBundleResource.cpp
service/resource-encapsulation/src/resourceContainer/src/ResourceContainerImpl.cpp
service/resource-encapsulation/src/resourceContainer/src/SoftSensorResource.cpp

diff --git a/service/resource-encapsulation/src/resourceContainer/include/InternalTypes.h b/service/resource-encapsulation/src/resourceContainer/include/InternalTypes.h
new file mode 100644 (file)
index 0000000..580f118
--- /dev/null
@@ -0,0 +1,53 @@
+//******************************************************************
+//
+// Copyright 2015 Samsung Electronics All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+#ifndef RC_INTERNALTYPES_H_
+#define RC_INTERNALTYPES_H_
+
+#include "logger.h"
+
+namespace OIC
+{
+    namespace Service
+    {
+        constexpr char CONTAINER_TAG[] = "RESOURCE_CONTAINER";
+
+        constexpr char BUNDLE_TAG[] = "bundle";
+        constexpr char BUNDLE_ID[] = "id";
+        constexpr char BUNDLE_PATH[] = "path";
+        constexpr char BUNDLE_VERSION[] = "version";
+        constexpr char BUNDLE_ACTIVATOR[] = "activator";
+        constexpr char BUNDLE_LIBRARY_PATH[] = "libraryPath";
+
+        constexpr char INPUT_RESOURCE[] = "input";
+        constexpr char INPUT_RESOURCE_URI[] = "resourceUri";
+        constexpr char INPUT_RESOURCE_TYPE[] = "resourceType";
+        constexpr char INPUT_RESOURCE_ATTRIBUTENAME[] = "name";
+
+        constexpr char OUTPUT_RESOURCES_TAG[] = "resources";
+        constexpr char OUTPUT_RESOURCE_INFO[] = "resourceInfo";
+        constexpr char OUTPUT_RESOURCE_NAME[] = "name";
+        constexpr char OUTPUT_RESOURCE_URI[] = "resourceUri";
+        constexpr char OUTPUT_RESOURCE_TYPE[] = "resourceType";
+        constexpr char OUTPUT_RESOURCE_ADDR[] = "address";
+    }
+}
+
+#endif /* RC_INTERNALTYPES_H_ */
index 992b673..69917fc 100644 (file)
 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 #include "ResourceContainerImpl.h"
 #if(JAVA_SUPPORT)
-    #include <jni.h>
-    #include "org_iotivity_resourcecontainer_bundle_api_BaseActivator.h"
-    #include "JavaBundleResource.h"
-    #include "ResourceContainerImpl.h"
-
-    using namespace OIC::Service;
-
-    std::map< string, JavaBundleResource* > java_resources;
-
-    /*
-     * Class:     org_iotivity_resourcecontainer_bundle_api_BaseActivator
-     * Method:    registerJavaResource
-     * Signature: (Lorg/iotivity/resourcecontainer/bundle/api/BundleResource;[Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
-     */
-    JNIEXPORT void JNICALL Java_org_iotivity_resourcecontainer_bundle_api_BaseActivator_registerJavaResource
-    (JNIEnv *env, jobject obj, jobject bundleResource, jobjectArray attributes, jstring bundleId, jstring uri, jstring resourceType, jstring res_name)
-    {
-        //return;
-        //static std::map<jobject, JavaBundleResource > javaBundles;
-        const char *str_bundleId = env->GetStringUTFChars(bundleId, 0);
-        const char *str_uri = env->GetStringUTFChars(uri, 0);
-        const char *str_resourceType = env->GetStringUTFChars(resourceType, 0);
-        const char *str_res_name = env->GetStringUTFChars(res_name, 0);
-
-        JavaBundleResource *javaBundleResource = new JavaBundleResource(env, obj, bundleResource, str_bundleId, attributes);
-        ResourceContainerImpl *container = ResourceContainerImpl::getImplInstance();
-
-        javaBundleResource->m_uri = string(str_uri, strlen(str_uri));
-        javaBundleResource->m_resourceType = string(str_resourceType, strlen(str_resourceType));
-        javaBundleResource->m_name = string(str_res_name, strlen(str_res_name));
-        container->registerResource(javaBundleResource);
-
-        java_resources[str_uri] = javaBundleResource;
-
-    }
-
-    /*
-     * Class:     org_iotivity_resourcecontainer_bundle_api_BaseActivator
-     * Method:    unregisterJavaResource
-     * Signature: (Lorg/iotivity/resourcecontainer/bundle/api/BundleResource;)V
-     */
-    JNIEXPORT void JNICALL Java_org_iotivity_resourcecontainer_bundle_api_BaseActivator_unregisterJavaResource
-    (JNIEnv *env, jobject obj, jobject bundleResource, jstring uri)
-    {
-        const char *str_uri = env->GetStringUTFChars(uri, 0);
-
-        if(java_resources[str_uri] != NULL)
-        {
-            ResourceContainerImpl *container = ResourceContainerImpl::getImplInstance();
-            container->unregisterResource(java_resources[str_uri]);
-            java_resources.erase(str_uri);
-        }
-    }
-
-    /*
-     * Class:     org_iotivity_resourcecontainer_bundle_api_BaseActivator
-     * Method:    getNumberOfConfiguredResources
-     * Signature: (Ljava/lang/String;)I
-     */
-    JNIEXPORT jint JNICALL Java_org_iotivity_resourcecontainer_bundle_api_BaseActivator_getNumberOfConfiguredResources(
-            JNIEnv *env, jobject obj, jstring bundleId)
-    {
-
-        const char *str_bundleId = env->GetStringUTFChars(bundleId, 0);
-
-        ResourceContainerImpl *container = ResourceContainerImpl::getImplInstance();
-        vector< resourceInfo > resourceConfig;
-        container->getResourceConfiguration(str_bundleId, &resourceConfig);
-
-        return resourceConfig.size();
-    }
+#include <jni.h>
+#include "org_iotivity_resourcecontainer_bundle_api_BaseActivator.h"
+#include "JavaBundleResource.h"
+#include "ResourceContainerImpl.h"
 
-    /*
-     * Class:     org_iotivity_resourcecontainer_bundle_api_BaseActivator
-     * Method:    getConfiguredResourceParams
-     * Signature: (Ljava/lang/String;I)[Ljava/lang/String;
-     */
-    JNIEXPORT jobjectArray JNICALL Java_org_iotivity_resourcecontainer_bundle_api_BaseActivator_getConfiguredResourceParams(
-            JNIEnv *env, jobject obj, jstring bundleId, jint resourceId)
+using namespace OIC::Service;
+
+std::map< string, JavaBundleResource * > java_resources;
+
+/*
+ * Class:     org_iotivity_resourcecontainer_bundle_api_BaseActivator
+ * Method:    registerJavaResource
+ * Signature: (Lorg/iotivity/resourcecontainer/bundle/api/BundleResource;[Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
+ */
+JNIEXPORT void JNICALL
+Java_org_iotivity_resourcecontainer_bundle_api_BaseActivator_registerJavaResource
+(JNIEnv *env, jobject obj, jobject bundleResource, jobjectArray attributes, jstring bundleId,
+ jstring uri, jstring resourceType, jstring res_name)
+{
+    const char *str_bundleId = env->GetStringUTFChars(bundleId, 0);
+    const char *str_uri = env->GetStringUTFChars(uri, 0);
+    const char *str_resourceType = env->GetStringUTFChars(resourceType, 0);
+    const char *str_res_name = env->GetStringUTFChars(res_name, 0);
+
+    JavaBundleResource *javaBundleResource = new JavaBundleResource(env, obj, bundleResource,
+            str_bundleId, attributes);
+    ResourceContainerImpl *container = ResourceContainerImpl::getImplInstance();
+
+    javaBundleResource->m_uri = string(str_uri, strlen(str_uri));
+    javaBundleResource->m_resourceType = string(str_resourceType, strlen(str_resourceType));
+    javaBundleResource->m_name = string(str_res_name, strlen(str_res_name));
+    container->registerResource(javaBundleResource);
+
+    java_resources[str_uri] = javaBundleResource;
+
+}
+
+/*
+ * Class:     org_iotivity_resourcecontainer_bundle_api_BaseActivator
+ * Method:    unregisterJavaResource
+ * Signature: (Lorg/iotivity/resourcecontainer/bundle/api/BundleResource;)V
+ */
+JNIEXPORT void JNICALL
+Java_org_iotivity_resourcecontainer_bundle_api_BaseActivator_unregisterJavaResource
+(JNIEnv *env, jobject obj, jobject bundleResource, jstring uri)
+{
+    (void)obj;
+    (void)bundleResource;
+    const char *str_uri = env->GetStringUTFChars(uri, 0);
+
+    if (java_resources[str_uri] != NULL)
     {
-
-        jobjectArray ret;
-        const char *str_bundleId = env->GetStringUTFChars(bundleId, 0);
-
         ResourceContainerImpl *container = ResourceContainerImpl::getImplInstance();
-        vector< resourceInfo > resourceConfig;
-        container->getResourceConfiguration(str_bundleId, &resourceConfig);
-        resourceInfo conf = resourceConfig[resourceId];
-        ret = (jobjectArray) env->NewObjectArray(4, env->FindClass("java/lang/String"),
-                env->NewStringUTF(""));
-
-        env->SetObjectArrayElement(ret, 0, env->NewStringUTF(conf.name.c_str()));
-        env->SetObjectArrayElement(ret, 1, env->NewStringUTF(conf.uri.c_str()));
-        env->SetObjectArrayElement(ret, 2, env->NewStringUTF(conf.resourceType.c_str()));
-        env->SetObjectArrayElement(ret, 3, env->NewStringUTF(conf.address.c_str()));
-        return ret;
+        container->unregisterResource(java_resources[str_uri]);
+        java_resources.erase(str_uri);
     }
-#endif
+}
+
+/*
+ * Class:     org_iotivity_resourcecontainer_bundle_api_BaseActivator
+ * Method:    getNumberOfConfiguredResources
+ * Signature: (Ljava/lang/String;)I
+ */
+JNIEXPORT jint JNICALL
+Java_org_iotivity_resourcecontainer_bundle_api_BaseActivator_getNumberOfConfiguredResources(
+    JNIEnv *env, jobject obj, jstring bundleId)
+{
+    (void)obj;
+    const char *str_bundleId = env->GetStringUTFChars(bundleId, 0);
+
+    ResourceContainerImpl *container = ResourceContainerImpl::getImplInstance();
+    vector< resourceInfo > resourceConfig;
+    container->getResourceConfiguration(str_bundleId, &resourceConfig);
+
+    return resourceConfig.size();
+}
+
+/*
+ * Class:     org_iotivity_resourcecontainer_bundle_api_BaseActivator
+ * Method:    getConfiguredResourceParams
+ * Signature: (Ljava/lang/String;I)[Ljava/lang/String;
+ */
+JNIEXPORT jobjectArray JNICALL
+Java_org_iotivity_resourcecontainer_bundle_api_BaseActivator_getConfiguredResourceParams(
+    JNIEnv *env, jobject obj, jstring bundleId, jint resourceId)
+{
+    (void)obj;
+    jobjectArray ret;
+    const char *str_bundleId = env->GetStringUTFChars(bundleId, 0);
+
+    ResourceContainerImpl *container = ResourceContainerImpl::getImplInstance();
+    vector< resourceInfo > resourceConfig;
+    container->getResourceConfiguration(str_bundleId, &resourceConfig);
+    resourceInfo conf = resourceConfig[resourceId];
+    ret = (jobjectArray) env->NewObjectArray(4, env->FindClass("java/lang/String"),
+            env->NewStringUTF(""));
+
+    env->SetObjectArrayElement(ret, 0, env->NewStringUTF(conf.name.c_str()));
+    env->SetObjectArrayElement(ret, 1, env->NewStringUTF(conf.uri.c_str()));
+    env->SetObjectArrayElement(ret, 2, env->NewStringUTF(conf.resourceType.c_str()));
+    env->SetObjectArrayElement(ret, 3, env->NewStringUTF(conf.address.c_str()));
+    return ret;
+}
+#endif
\ No newline at end of file
index 6737a8b..2af71f6 100644 (file)
 
 #include <stdexcept>
 #include <utility>
+#include "InternalTypes.h"
 
-namespace
-{
-    const std::string INPUT_RESOURCE = std::string("input");
-}
 
 namespace OIC
 {
@@ -93,7 +90,7 @@ namespace OIC
             {
                 try
                 {
-                    for (bundle = m_xmlDoc.first_node()->first_node("bundle"); bundle; bundle =
+                    for (bundle = m_xmlDoc.first_node()->first_node(BUNDLE_TAG); bundle; bundle =
                              bundle->next_sibling())
                     {
                         std::map< std::string, std::string > bundleMap;
@@ -115,8 +112,8 @@ namespace OIC
                 }
                 catch (rapidxml::parse_error &e)
                 {
-                    cout << "xml parsing failed !!" << endl;
-                    cout << e.what() << endl;
+                    OC_LOG_V(ERROR, CONTAINER_TAG, "xml parsing failed !!");
+                    OC_LOG_V(ERROR, CONTAINER_TAG, e.what());
                 }
             }
         }
@@ -134,24 +131,24 @@ namespace OIC
                     std::map< std::string, std::string > bundleConfigMap;
 
                     // <bundle>
-                    for (bundle = m_xmlDoc.first_node()->first_node("bundle"); bundle; bundle =
+                    for (bundle = m_xmlDoc.first_node()->first_node(BUNDLE_TAG); bundle; bundle =
                              bundle->next_sibling())
                     {
                         // <id>
-                        strBundleId = bundle->first_node("id")->value();
+                        strBundleId = bundle->first_node(BUNDLE_ID)->value();
 
                         if (!strBundleId.compare(bundleId))
                         {
-                            bundleConfigMap.insert(std::make_pair("id", trim_both(strBundleId)));
+                            bundleConfigMap.insert(std::make_pair(BUNDLE_ID, trim_both(strBundleId)));
 
                             // <path>
-                            strPath = bundle->first_node("path")->value();
-                            bundleConfigMap.insert(std::make_pair("path", trim_both(strPath)));
+                            strPath = bundle->first_node(BUNDLE_PATH)->value();
+                            bundleConfigMap.insert(std::make_pair(BUNDLE_PATH, trim_both(strPath)));
 
                             // <version>
-                            strVersion = bundle->first_node("version")->value();
+                            strVersion = bundle->first_node(BUNDLE_VERSION)->value();
                             bundleConfigMap.insert(
-                                std::make_pair("version", trim_both(strVersion)));
+                                std::make_pair(BUNDLE_VERSION, trim_both(strVersion)));
 
                             configOutput->push_back(bundleConfigMap);
 
@@ -161,8 +158,8 @@ namespace OIC
                 }
                 catch (rapidxml::parse_error &e)
                 {
-                    cout << "xml parsing failed !!" << endl;
-                    cout << e.what() << endl;
+                    OC_LOG_V(ERROR, CONTAINER_TAG, "xml parsing failed !!");
+                    OC_LOG_V(ERROR, CONTAINER_TAG, e.what());
                 }
             }
         }
@@ -182,17 +179,17 @@ namespace OIC
                 try
                 {
                     // <bundle>
-                    for (bundle = m_xmlDoc.first_node()->first_node("bundle"); bundle; bundle =
+                    for (bundle = m_xmlDoc.first_node()->first_node(BUNDLE_TAG); bundle; bundle =
                              bundle->next_sibling())
                     {
                         // <id>
-                        strBundleId = bundle->first_node("id")->value();
+                        strBundleId = bundle->first_node(BUNDLE_ID)->value();
 
                         if (!strBundleId.compare(bundleId))
                         {
                             // <resourceInfo>
-                            for (resource = bundle->first_node("resources")->first_node(
-                                                "resourceInfo"); resource; resource = resource->next_sibling())
+                            for (resource = bundle->first_node(OUTPUT_RESOURCES_TAG)->first_node(OUTPUT_RESOURCE_INFO);
+                                 resource; resource = resource->next_sibling())
                             {
                                 resourceInfo tempResourceInfo;
 
@@ -202,16 +199,16 @@ namespace OIC
                                     strKey = item->name();
                                     strValue = item->value();
 
-                                    if (!strKey.compare("name"))
+                                    if (!strKey.compare(OUTPUT_RESOURCE_NAME))
                                         tempResourceInfo.name = trim_both(strValue);
 
-                                    else if (!strKey.compare("uri"))
+                                    else if (!strKey.compare(OUTPUT_RESOURCE_URI))
                                         tempResourceInfo.uri = trim_both(strValue);
 
-                                    else if (!strKey.compare("address"))
+                                    else if (!strKey.compare(OUTPUT_RESOURCE_ADDR))
                                         tempResourceInfo.address = trim_both(strValue);
 
-                                    else if (!strKey.compare("resourceType"))
+                                    else if (!strKey.compare(OUTPUT_RESOURCE_TYPE))
                                         tempResourceInfo.resourceType = trim_both(strValue);
 
                                     else
@@ -250,8 +247,8 @@ namespace OIC
                 }
                 catch (rapidxml::parse_error &e)
                 {
-                    std::cout << "xml parsing failed !!" << std::endl;
-                    std::cout << e.what() << std::endl;
+                    OC_LOG_V(ERROR, CONTAINER_TAG, "xml parsing failed !!");
+                    OC_LOG_V(ERROR, CONTAINER_TAG, e.what());
                 }
             }
         }
@@ -280,14 +277,14 @@ namespace OIC
                 }
                 catch (rapidxml::parse_error &e)
                 {
-                    std::cout << "xml parsing failed !!" << std::endl;
-                    std::cout << e.what() << std::endl;
+                    OC_LOG_V(ERROR, CONTAINER_TAG, "xml parsing failed !!");
+                    OC_LOG_V(ERROR, CONTAINER_TAG, e.what());
                 }
             }
             else
             {
-                std::cout << "Configuration File load failed !!" << std::endl;
+                OC_LOG_V(ERROR, CONTAINER_TAG, "Configuration File load failed !!");
             }
         }
     }
-}
+}
\ No newline at end of file
index a799dce..d4adf66 100644 (file)
 
 
 #if(JAVA_SUPPORT)
-    #include "JavaBundleResource.h"
-    #include <jni.h>
-    #include <string.h>
+#include "JavaBundleResource.h"
 
-    #include <iostream>
+#include <jni.h>
+#include <string.h>
+#include <iostream>
+#include "InternalTypes.h"
 
-    using namespace OIC::Service;
-    using namespace std;
+using namespace OIC::Service;
+using namespace std;
 
-    #include "oc_logger.hpp"
 
-    using OC::oc_log_stream;
-    using namespace OIC::Service;
+JavaBundleResource::JavaBundleResource()
+{
 
-    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("JavaBundleResource");
-        return os;
-    };
-
-    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("JavaBundleResource");
-        return os;
-    };
-
-    JavaBundleResource::JavaBundleResource()
-    {
+}
 
-    }
+void JavaBundleResource::initAttributes()
+{
 
-    void JavaBundleResource::initAttributes()
-    {
+}
 
-    }
+JavaBundleResource::JavaBundleResource(JNIEnv *env, jobject obj, jobject bundleResource,
+                                       string bundleId, jobjectArray attributes)
+{
+    (void) obj;
+    int stringCount = env->GetArrayLength(attributes);
 
-    JavaBundleResource::JavaBundleResource(JNIEnv *env, jobject obj, jobject bundleResource,
-            string bundleId, jobjectArray attributes)
+    for (int i = 0; i < stringCount; i++)
     {
-        int stringCount = env->GetArrayLength(attributes);
-
-        for (int i = 0; i < stringCount; i++)
-        {
-            jstring str = (jstring) env->GetObjectArrayElement(attributes, i);
-            const char *rawString = env->GetStringUTFChars(str, 0);
-            string s(rawString, strlen(rawString));
-            BundleResource::setAttribute(s, "");
-        }
+        jstring str = (jstring) env->GetObjectArrayElement(attributes, i);
+        const char *rawString = env->GetStringUTFChars(str, 0);
+        string s(rawString, strlen(rawString));
+        BundleResource::setAttribute(s, "");
+    }
 
-        m_bundleId = bundleId;
+    m_bundleId = bundleId;
 
-        this->bundleResource = env->NewGlobalRef(bundleResource);
+    this->bundleResource = env->NewGlobalRef(bundleResource);
 
-        bundleResourceClass = env->GetObjectClass(bundleResource);
+    bundleResourceClass = env->GetObjectClass(bundleResource);
 
-        attributeSetter = env->GetMethodID(bundleResourceClass, "setAttribute",
-                "(Ljava/lang/String;Ljava/lang/String;)V");
+    attributeSetter = env->GetMethodID(bundleResourceClass, "setAttribute",
+                                       "(Ljava/lang/String;Ljava/lang/String;)V");
 
-        attributeGetter = env->GetMethodID(bundleResourceClass, "getAttribute",
-                "(Ljava/lang/String;)Ljava/lang/String;");
+    attributeGetter = env->GetMethodID(bundleResourceClass, "getAttribute",
+                                       "(Ljava/lang/String;)Ljava/lang/String;");
 
-    }
+}
 
-    JavaBundleResource::~JavaBundleResource()
-    {
+JavaBundleResource::~JavaBundleResource()
+{
 
-    }
+}
 
-    RCSResourceAttributes& JavaBundleResource::getAttributes(){
-        return BundleResource::getAttributes();
-    }
+RCSResourceAttributes &JavaBundleResource::getAttributes()
+{
+    return BundleResource::getAttributes();
+}
 
-    RCSResourceAttributes::Value JavaBundleResource::getAttribute(const std::string& attributeName)
-    {
-        JavaVM* vm = ResourceContainerImpl::getImplInstance()->getJavaVM(m_bundleId);
+RCSResourceAttributes::Value JavaBundleResource::getAttribute(const std::string &attributeName)
+{
+    JavaVM *vm = ResourceContainerImpl::getImplInstance()->getJavaVM(m_bundleId);
 
-        JNIEnv * env;
-        int envStat = vm->GetEnv((void **) &env, JNI_VERSION_1_4);
+    JNIEnv *env;
+    int envStat = vm->GetEnv((void **) &env, JNI_VERSION_1_4);
 
-        if (envStat == JNI_EDETACHED)
-        {
-            if (vm->AttachCurrentThread((void**) &env, NULL) != 0)
-            {
-                error_logger() << "Failed to attach " << endl;
-            }
-        }
-        else if (envStat == JNI_EVERSION)
+    if (envStat == JNI_EDETACHED)
+    {
+        if (vm->AttachCurrentThread((void **) &env, NULL) != 0)
         {
-            error_logger() << "Env: version not supported " << endl;
+            OC_LOG_V(ERROR, CONTAINER_TAG, "[JavaBundleResource::getAttribute] Failed to attach ");
         }
+    }
+    else if (envStat == JNI_EVERSION)
+    {
+        OC_LOG_V(ERROR, CONTAINER_TAG, "[JavaBundleResource::getAttribute] Env: version not supported");
+    }
 
-        jstring attrName = env->NewStringUTF(attributeName.c_str());
+    jstring attrName = env->NewStringUTF(attributeName.c_str());
 
-        jstring returnString = (jstring) env->CallObjectMethod(bundleResource, attributeGetter,
-                attrName);
+    jstring returnString = (jstring) env->CallObjectMethod(bundleResource, attributeGetter,
+                           attrName);
 
-        const char *js = env->GetStringUTFChars(returnString, NULL);
-        std::string val(js);
-        RCSResourceAttributes::Value newVal = val;
-        env->ReleaseStringUTFChars(returnString, js);
-        BundleResource::setAttribute(attributeName, newVal.toString());
-        return BundleResource::getAttribute(attributeName);
-    }
+    const char *js = env->GetStringUTFChars(returnString, NULL);
+    std::string val(js);
+    RCSResourceAttributes::Value newVal = val;
+    env->ReleaseStringUTFChars(returnString, js);
+    BundleResource::setAttribute(attributeName, newVal.toString());
+    return BundleResource::getAttribute(attributeName);
+}
 
-    void JavaBundleResource::setAttribute(std::string attributeName, RCSResourceAttributes::Value&& value)
-    {
-        JavaVM* vm = ResourceContainerImpl::getImplInstance()->getJavaVM(m_bundleId);
+void JavaBundleResource::setAttribute(std::string attributeName,
+                                      RCSResourceAttributes::Value &&value)
+{
+    JavaVM *vm = ResourceContainerImpl::getImplInstance()->getJavaVM(m_bundleId);
 
-        JNIEnv * env;
-        int envStat = vm->GetEnv((void **) &env, JNI_VERSION_1_4);
+    JNIEnv *env;
+    int envStat = vm->GetEnv((void **) &env, JNI_VERSION_1_4);
 
-        if (envStat == JNI_EDETACHED)
-        {
-            if (vm->AttachCurrentThread((void**) &env, NULL) != 0)
-            {
-                error_logger() << "Failed to attach " << endl;
-            }
-        }
-        else if (envStat == JNI_EVERSION)
+    if (envStat == JNI_EDETACHED)
+    {
+        if (vm->AttachCurrentThread((void **) &env, NULL) != 0)
         {
-            error_logger() << "Env: version not supported " << endl;
+            OC_LOG_V(ERROR, CONTAINER_TAG, "[JavaBundleResource::setAttribute] Failed to attach ");
         }
+    }
+    else if (envStat == JNI_EVERSION)
+    {
+        OC_LOG_V(ERROR, CONTAINER_TAG, "[JavaBundleResource::setAttribute] Env: version not supported ");
+    }
 
-        jstring attrName = env->NewStringUTF(attributeName.c_str());
-        jstring val = env->NewStringUTF(value.toString().c_str());
+    jstring attrName = env->NewStringUTF(attributeName.c_str());
+    jstring val = env->NewStringUTF(value.toString().c_str());
 
 
-        env->CallObjectMethod(bundleResource, attributeSetter, attrName, val);
-        BundleResource::setAttribute(attributeName, std::move(value));
-    }
+    env->CallObjectMethod(bundleResource, attributeSetter, attrName, val);
+    BundleResource::setAttribute(attributeName, std::move(value));
+}
 #endif
index 3fd80b3..8a4d5ae 100644 (file)
 //
 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 
+#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;
@@ -88,16 +54,16 @@ namespace OIC
         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())
@@ -112,24 +78,25 @@ namespace OIC
                     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));
@@ -137,28 +104,30 @@ namespace OIC
                 }
                 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);
@@ -202,8 +171,7 @@ namespace OIC
 
         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())
             {
@@ -216,13 +184,11 @@ namespace OIC
                 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)
@@ -238,7 +204,7 @@ namespace OIC
         // 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"))
             {
@@ -275,13 +241,15 @@ namespace OIC
         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
             {
@@ -292,13 +260,12 @@ namespace OIC
 
         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())
@@ -314,15 +281,15 @@ namespace OIC
                     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))
                     {
@@ -332,7 +299,7 @@ namespace OIC
             }
             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();
         }
@@ -342,8 +309,8 @@ namespace OIC
             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))
             {
@@ -384,7 +351,7 @@ namespace OIC
             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] ()
                 {
@@ -406,7 +373,7 @@ namespace OIC
             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] ()
                 {
@@ -428,8 +395,8 @@ namespace OIC
 
         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())
             {
@@ -447,7 +414,7 @@ namespace OIC
                 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)
@@ -457,12 +424,14 @@ namespace OIC
                 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());
             }
         }
 
@@ -473,38 +442,41 @@ namespace OIC
                 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);
             }
@@ -523,8 +495,8 @@ namespace OIC
             }
             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());
             }
         }
 
@@ -532,12 +504,12 @@ namespace OIC
         {
             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);
                 }
             }
@@ -554,20 +526,20 @@ namespace OIC
                     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());
             }
         }
 
@@ -583,8 +555,8 @@ namespace OIC
             }
             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());
             }
         }
 
@@ -610,8 +582,6 @@ namespace OIC
             resourceCreator_t *resourceCreator = NULL;
             resourceDestroyer_t *resourceDestroyer = NULL;
 
-            //sstream << bundleInfo.path << std::ends;
-
             void *bundleHandle = NULL;
             bundleHandle = dlopen(bundleInfo->getPath().c_str(), RTLD_LAZY);
 
@@ -619,15 +589,15 @@ namespace OIC
             {
                 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
                 {
@@ -645,7 +615,7 @@ namespace OIC
             {
                 if ((error = dlerror()) != NULL)
                 {
-                    error_logger() << error << endl;
+                    OC_LOG_V(ERROR, CONTAINER_TAG, error);
                 }
             }
         }
@@ -662,7 +632,7 @@ namespace OIC
             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];
@@ -719,14 +689,14 @@ namespace OIC
                         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);
@@ -734,9 +704,9 @@ namespace OIC
                         else
                         {
                             m_mapDiscoverResourceUnits.insert(
-                                    std::make_pair(outputResourceUri,
-                                            std::list< DiscoverResourceUnit::Ptr >
-                                            { newDiscoverUnit }));
+                                std::make_pair(outputResourceUri,
+                                               std::list< DiscoverResourceUnit::Ptr >
+                            { newDiscoverUnit }));
                         }
                     }
                 }
@@ -746,7 +716,9 @@ namespace OIC
         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)
             {
@@ -756,7 +728,7 @@ namespace OIC
             else
             {
                 //Unload module and return error
-                error_logger() << "De-activation unsuccessful." << endl;
+                OC_LOG_V(ERROR, CONTAINER_TAG, "De-activation unsuccessful.");
             }
         }
 
@@ -773,7 +745,7 @@ namespace OIC
             }
             else
             {
-                error_logger() << "addResource unsuccessful." << endl;
+                OC_LOG_V(ERROR, CONTAINER_TAG, "addResource unsuccessful.");
             }
         }
 
@@ -783,7 +755,7 @@ namespace OIC
             if (m_mapResources.find(resourceUri) != m_mapResources.end())
             {
                 resourceDestroyer_t *resourceDestroyer =
-                        m_bundles[bundleId]->getResourceDestroyer();
+                    m_bundles[bundleId]->getResourceDestroyer();
 
                 if (resourceDestroyer != NULL)
                 {
@@ -791,200 +763,209 @@ namespace OIC
                 }
                 else
                 {
-                    error_logger() << "removeResource unsuccessful." << endl;
+                    OC_LOG_V(ERROR, CONTAINER_TAG, "removeResource unsuccessful.");
                 }
             }
         }
 
-        void ResourceContainerImpl::activateBundleThread(RCSBundleInforcsBundleInfo)
+        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
index 6442873..883ed3a 100644 (file)
 #include <algorithm>
 
 using namespace OIC::Service;
+
+namespace
+{
+    const std::string SS_RESOURCE_OUTPUT = std::string("output");
+    const std::string SS_RESOURCE_OUTPUTNAME = std::string("name");
+}
+
 namespace OIC
 {
     namespace Service
@@ -41,9 +48,9 @@ namespace OIC
             std::vector< std::map< std::string, std::string > >::iterator itor;
 
             // initialize output attributes
-            for (itor = m_mapResourceProperty["output"].begin(); itor != m_mapResourceProperty["output"].end();
-                 itor++)
-                BundleResource::setAttribute((*itor)["name"], nullptr);
+            for (itor = m_mapResourceProperty[SS_RESOURCE_OUTPUT].begin();
+                 itor != m_mapResourceProperty[SS_RESOURCE_OUTPUT].end(); itor++)
+                BundleResource::setAttribute((*itor)[SS_RESOURCE_OUTPUTNAME], nullptr);
         }
 
         RCSResourceAttributes &SoftSensorResource::getAttributes()