Using ResourceAttributes class for BundleResource and added a container sample client.
authorMarkus Jung <markus.jung@samsung.com>
Sun, 19 Jul 2015 04:57:28 +0000 (13:57 +0900)
committerUze Choi <uzchoi@samsung.com>
Sun, 19 Jul 2015 09:11:00 +0000 (09:11 +0000)
Change-Id: Id759249d912e1c5ab275e2c0cd608bf4cf1ada18
Signed-off-by: Markus Jung <markus.jung@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/1734
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Hun-je Yeon <hunje.yeon@samsung.com>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
20 files changed:
service/resource-manipulation/src/resourceContainer/SConscript
service/resource-manipulation/src/resourceContainer/bundle-api/include/BundleResource.h
service/resource-manipulation/src/resourceContainer/bundle-api/include/ProtocolBridgeResource.h
service/resource-manipulation/src/resourceContainer/bundle-api/include/SoftSensorResource.h
service/resource-manipulation/src/resourceContainer/bundle-java-api/src/main/java/org/iotivity/resourcecontainer/bundle/api/BundleResource.java
service/resource-manipulation/src/resourceContainer/examples/HueJavaSampleBundle/hue/src/main/java/org/iotivity/bundle/hue/HueBundleActivator.java
service/resource-manipulation/src/resourceContainer/examples/HueJavaSampleBundle/hue/src/main/java/org/iotivity/bundle/hue/HueLightResource.java
service/resource-manipulation/src/resourceContainer/examples/HueSampleBundle/include/HueLight.h
service/resource-manipulation/src/resourceContainer/examples/HueSampleBundle/src/HueLight.cpp
service/resource-manipulation/src/resourceContainer/examples/HueSampleBundle/src/HueSampleBundleActivator.cpp
service/resource-manipulation/src/resourceContainer/examples/ResourceContainerConfig.xml
service/resource-manipulation/src/resourceContainer/examples/SoftSensorSampleBundle/include/DiscomfortIndexSensorResource.h
service/resource-manipulation/src/resourceContainer/examples/SoftSensorSampleBundle/src/DiscomfortIndexSensorResource.cpp
service/resource-manipulation/src/resourceContainer/include/JavaBundleResource.h
service/resource-manipulation/src/resourceContainer/src/BaseActivator.cpp
service/resource-manipulation/src/resourceContainer/src/BundleResource.cpp
service/resource-manipulation/src/resourceContainer/src/ContainerSampleClient.cpp [new file with mode: 0644]
service/resource-manipulation/src/resourceContainer/src/JavaBundleResource.cpp
service/resource-manipulation/src/resourceContainer/unittests/ResourceContainerTest.cpp
service/resource-manipulation/src/resourceContainer/unittests/SConscript

index 0fdca4e..bc345c7 100644 (file)
@@ -125,8 +125,9 @@ ss_resource_bundle_env.AppendUnique(CPPPATH = [
                '../../include',
                ])              
                
+ss_resource_bundle_env.PrependUnique(LIBS = ['ResContainerLib'])
 
-ss_resource_bundle_src = [ Glob(SS_RESOURCE_BUNDLE_DIR + 'src/*.cpp'), Glob('src/*.cpp')]
+ss_resource_bundle_src = [ Glob(SS_RESOURCE_BUNDLE_DIR + 'src/*.cpp')]
 
 SoftSensorBundle = ss_resource_bundle_env.SharedLibrary('SoftSensorBundle', ss_resource_bundle_src)
 ss_resource_bundle_env.InstallTarget(SoftSensorBundle, 'libSoftSensorBundle')
@@ -157,31 +158,42 @@ else:
                        'include/'
                        ])              
                
-       hue_resource_bundle_env.PrependUnique(LIBS = ['curl'])
+       hue_resource_bundle_env.PrependUnique(LIBS = ['curl', 'ResContainerLib'])
                
-       hue_resource_bundle_src = [ Glob(HUE_RESOURCE_BUNDLE_DIR + 'src/*.cpp'), Glob('src/*.cpp')]
+       hue_resource_bundle_src = [ Glob(HUE_RESOURCE_BUNDLE_DIR + 'src/*.cpp')]
        
        HueBundle = hue_resource_bundle_env.SharedLibrary('HueBundle', hue_resource_bundle_src)
        hue_resource_bundle_env.InstallTarget(HueBundle, 'libHueBundle')
-lib_env = conf2.Finish()
+       lib_env = conf2.Finish()
 
 ######################################################################
 # build resource container unit tests
 ######################################################################
-#SConscript('unittests/SConscript')
+SConscript('unittests/SConscript')
 
 ######################################################################
-# Build Container Test
+# Build Container Sample
 ######################################################################
-containertest_env = resource_container_env.Clone();
-containertest_env.AppendUnique(LINKFLAGS=["-rdynamic"])
+containersample_env = resource_container_env.Clone();
+containersample_env.AppendUnique(LINKFLAGS=["-rdynamic"])
 
 # Copy test configuration
 Command("examples/ResourceContainerConfig.xml","examples/ResourceContainerConfig.xml", Copy("$TARGET", "$SOURCE"))
 Ignore("examples/ResourceContainerConfig.xml", "examples/ResourceContainerConfig.xml")
 
-
 containersampleapp_src =  [res_container_src , 'src/ContainerSample.cpp']
-containersampleapp = containertest_env.Program('ContainerSample',containersampleapp_src)
+containersampleapp = containersample_env.Program('ContainerSample',containersampleapp_src)
 Alias("containersample", containersampleapp)
 env.AppendTarget('containersample')
+
+######################################################################
+# Build Container Sample Client
+######################################################################
+containersampleclient_env = resource_container_env.Clone();
+containersampleclient_env.AppendUnique(LINKFLAGS=["-rdynamic"])
+containersampleclient_src =  [res_container_src , 'src/ContainerSampleClient.cpp']
+containersampleclientapp = containersample_env.Program('ContainerSampleClient',containersampleclient_src)
+Alias("containersampleclient", containersampleclientapp)
+env.AppendTarget('containersampleclient')
+
+
index d2e4db4..93be008 100644 (file)
@@ -27,6 +27,7 @@
 #include <vector>
 
 #include "NotificationReceiver.h"
+#include "ResourceAttributes.h"
 
 using namespace std;
 
@@ -64,7 +65,7 @@ namespace OIC
                 *
                 * @todo use type variant mechanism
                 */
-                virtual string getAttribute(string attributeName);
+                //virtual string getAttribute(string attributeName);
 
                 /**
                 * Execute the logic of bundle to set the value of attribute
@@ -75,7 +76,7 @@ namespace OIC
                 *
                 * @return void
                 */
-                virtual void setAttribute(string attributeName, string value);
+                //virtual void setAttribute(string attributeName, string value);
 
                 /**
                 * Return the list of attribute names of the resource
@@ -100,14 +101,23 @@ namespace OIC
                 */
                 void registerObserver(NotificationReceiver *pNotiReceiver);
 
+                virtual ResourceAttributes& getAttributes();
+
+                virtual void setAttribute(std::string key, ResourceAttributes::Value&&);
+
+                virtual ResourceAttributes::Value getAttribute(const std::string& key);
+
+
             public:
                 string m_bundleId;
                 string m_name, m_uri, m_resourceType, m_address;
                 map< string, vector< map< string, string > > > m_mapResourceProperty;
 
             private:
-                map< string, string > m_mapAttributes;
+                //map< string, string > m_mapAttributes;
                 NotificationReceiver *m_pNotiReceiver;
+                ResourceAttributes m_resourceAttributes;
+
         };
     }
 }
index 98ef4e1..c140b68 100644 (file)
@@ -50,27 +50,11 @@ namespace OIC
                 */
                 virtual ~ProtocolBridgeResource();
 
-                /**
-                * Execute the logic of bundle to get the value of attribute
-                *
-                * @param attributeName - name of attribute to get
-                *
-                * @return string - return value of the attribute
-                *
-                * @todo use type variant mechanism
-                */
-                virtual string getAttribute(string attributeName) = 0;
+                virtual ResourceAttributes& getAttributes()=0;
 
-                /**
-                * Execute the logic of bundle to set the value of attribute
-                *
-                * @param attributeName - name of attribute to set
-                *
-                * @param value - value of attribute to set
-                *
-                * @return void
-                */
-                virtual void setAttribute(string attributeName, string value) = 0;
+                virtual void setAttribute(std::string key, ResourceAttributes::Value&&)=0;
+
+                virtual ResourceAttributes::Value getAttribute(const std::string& key)=0;
         };
     }
 }
index 5f7f820..edaf16b 100644 (file)
@@ -62,7 +62,7 @@ namespace OIC
                 *
                 * @todo use type variant mechanism
                 */
-                virtual string getAttribute(string attributeName) = 0;
+                virtual ResourceAttributes::Value getAttribute(string attributeName) = 0;
 
                 /**
                 * Execute the logic of bundle to set the value of attribute
@@ -73,7 +73,7 @@ namespace OIC
                 *
                 * @return void
                 */
-                virtual void setAttribute(string attributeName, string value) = 0;
+                virtual void setAttribute(string attributeName, ResourceAttributes::Value value) = 0;
 
                 /**
                 * Set Input data to update output value of the soft sensor
index 5f66bfd..68bab81 100644 (file)
@@ -52,7 +52,7 @@ public abstract class BundleResource {
      * @param key name of the attribute to be read
      * @return Value of the attribute
      */
-    public abstract String getAttribute(String key);
+    public abstract String getAttribute(String key);     
 
     /**
      * Attribute keys provided through by the bundle resource.
index 43d67a6..7be201f 100644 (file)
@@ -22,6 +22,8 @@ public class HueBundleActivator extends BaseActivator {
             HueLightResource hueLightResource = new HueLightResource(connector,
                     config.getName(), config.getURI(),
                     config.getResourceType(), config.getAddress());
+            
+            System.out.println("Registration of HueLightresource");
             registerResource(hueLightResource);
         }
     }
index bc6814f..32f3fd5 100644 (file)
@@ -15,6 +15,7 @@ public class HueLightResource extends BundleResource {
     public HueLightResource() {
         initAttributes();
         m_resourceType = "oic.light.control";
+       
     }
 
     public HueLightResource(HueConnector hueConnector, String name, String uri,
@@ -24,7 +25,7 @@ public class HueLightResource extends BundleResource {
         m_name = name;
         m_uri = uri;
         m_resourceType = resourceType;
-        m_address = address;
+        m_address = address;        
     }
 
     protected void initAttributes() {
@@ -56,13 +57,13 @@ public class HueLightResource extends BundleResource {
     }
 
     public String getAttribute(String key) {
-        System.out.println("Get attribute called - key: " + key);
+        
         // map key to hue address
         // read from Hue gateway, parse resource representation and return
         // attribute
-        m_hueConnector.read(m_address);
-        return "";
-    }
+        //m_hueConnector.read(m_address);
+        return m_attributes.get(key);
+    }     
 
     @Override
     public String toString() {
index 675972e..b1b36cf 100644 (file)
@@ -37,14 +37,16 @@ namespace OIC
             HueLight();
             HueLight(HueConnector* connector, std::string address);
             virtual ~HueLight();
-            string getAttribute(string attributeName);
-            void setAttribute(string attributeName, string value);
             virtual void initAttributes();
+            virtual ResourceAttributes& getAttributes();
+
+            virtual void setAttribute(std::string key, ResourceAttributes::Value&&);
+
+            virtual ResourceAttributes::Value getAttribute(const std::string& key);
         private:
             std::string m_address;
             HueConnector* m_connector;
-        };
-    }
+        };}
 }
 
 #endif /* HUEGATEWAYCLIENT_H_ */
index b7643e5..a971ab6 100644 (file)
@@ -41,41 +41,42 @@ HueLight::~HueLight()
 
 }
 
-string HueLight::getAttribute(string attributeName)
-{
-    return BundleResource::getAttribute(attributeName);
+void HueLight::initAttributes(){
+
+    BundleResource::setAttribute("on-off", false);
+    BundleResource::setAttribute("dim", 0);
+    BundleResource::setAttribute("color", 0);
 }
 
-void HueLight::initAttributes()
-{
-    BundleResource::setAttribute("on-off", "false");
-    BundleResource::setAttribute("dim", "0");
-    BundleResource::setAttribute("color", "0");
-    /*m_mapAttributes.insert(std::pair<string, string>("on-off", "false"));
-    m_mapAttributes.insert(std::pair<string, string>("dim", "0"));
-    m_mapAttributes.insert(std::pair<string, string>("color", "0"));*/
+ResourceAttributes& HueLight::getAttributes(){
+    return BundleResource::getAttributes();
 }
 
-void HueLight::setAttribute(string attributeName, string value)
-{
-    cout << "HueLight::setAttribute setting " << attributeName << " to " << value << std::endl;
+ResourceAttributes::Value HueLight::getAttribute(const std::string& key){
+    cout << "HueLight::getAttribute called for " << key <<  " called" << endl;
+    return BundleResource::getAttribute(key);
+}
 
+void HueLight::setAttribute(std::string attributeName, ResourceAttributes::Value&& value){
+    cout << "HueLight::setAttribute setting " << attributeName << " to " << value.toString() << std::endl;
 
     if (attributeName == "on-off")
     {
-        m_connector->transmit(this->m_address + "/state", "{\"on\":" + value + "}");
+        m_connector->transmit(this->m_address + "/state", "{\"on\":" + value.toString() + "}");
     }
 
     if (attributeName == "dim")
     {
-        //m_connector->transmit(this->m_address + "/state", "{\"bri\":" + (value * 2.5) + "}");
-        m_connector->transmit(this->m_address + "/state", "{\"bri\":" + value + "}");
+        // needs conversion * 2.5
+        m_connector->transmit(this->m_address + "/state", "{\"bri\":" + value.toString() + "}");
     }
 
     if (attributeName == "color")
     {
-        //m_connector->transmit(this->m_address+ "/state", "{\"hue\":" + (value * 650)  + "}");
-        m_connector->transmit(this->m_address + "/state", "{\"hue\":" + value   + "}");
+        // needs conversion *650
+        m_connector->transmit(this->m_address+ "/state", "{\"hue\":" + value.toString()   + "}");
     }
+
+    BundleResource::setAttribute(attributeName, std::move(value));
 }
 
index 895c50e..35d7e0b 100644 (file)
@@ -39,7 +39,6 @@ HueSampleBundleActivator::~HueSampleBundleActivator()
 void HueSampleBundleActivator::activateBundle(ResourceContainerBundleAPI *resourceContainer,
         std::string bundleId)
 {
-    std::cout << "HueSampleBundle::activateBundle called" << std::endl;
 
     m_pResourceContainer = resourceContainer;
     m_bundleId = bundleId;
@@ -70,7 +69,6 @@ void HueSampleBundleActivator::deactivateBundle()
 
 void HueSampleBundleActivator::createResource(resourceInfo resourceInfo)
 {
-    std::cout << "HueSampleBundle::createResource called" << std::endl;
 
     if (resourceInfo.resourceType == "oic.light.control")
     {
index 08ae4d3..4d88e4a 100644 (file)
@@ -57,7 +57,7 @@
             </resourceInfo>       
         </resources>
     </bundle>
-    <bundle>
+    <!--<bundle>
         <id>oic.bundle.hueJavaSample</id>
         <path>../../../../../../../../service/resource-manipulation/src/resourceContainer/examples/HueJavaSampleBundle/hue/target/hue-0.1-jar-with-dependencies.jar</path>
         <libraryPath>.</libraryPath>
@@ -72,5 +72,5 @@
                 <address>http://192.168.0.2/api/newdeveloper/lights/1</address>
             </resourceInfo>       
         </resources>
-    </bundle>
+    </bundle>-->
 </container>
index 016cfe1..a07958f 100644 (file)
@@ -36,8 +36,8 @@ class DiscomfortIndexSensorResource : public SoftSensorResource
         DiscomfortIndexSensorResource(vector<string> inputAttributes);
         ~DiscomfortIndexSensorResource();
 
-        string getAttribute(string attributeName);
-        void setAttribute(string attributeName, string value);
+        ResourceAttributes::Value getAttribute(string attributeName);
+        void setAttribute(string attributeName, ResourceAttributes::Value value);
         virtual void initAttributes();
 
         void setInputAttribute(SensorData input);
index 870706c..8be9398 100644 (file)
@@ -45,16 +45,16 @@ void DiscomfortIndexSensorResource::initAttributes()
 
     BundleResource::setAttribute("temperature", "23");
     BundleResource::setAttribute("humidity", "40");
-    BundleResource::setAttribute("discomfortIndex", "5");
+    BundleResource::setAttribute("discomfortIndex","5");
 }
 
-string DiscomfortIndexSensorResource::getAttribute(string attributeName)
+ResourceAttributes::Value DiscomfortIndexSensorResource::getAttribute(string attributeName)
 {
     cout << "DiscomfortIndexSensorResource::getAttribute called !!" << endl;
     return BundleResource::getAttribute(attributeName);
 }
 
-void DiscomfortIndexSensorResource::setAttribute(string attributeName, string value)
+void DiscomfortIndexSensorResource::setAttribute(string attributeName, ResourceAttributes::Value value)
 {
     cout << "DiscomfortIndexSensorResource::setAttribute called !!" << endl;
 }
index 4937302..9df860c 100644 (file)
@@ -42,9 +42,12 @@ namespace OIC
                     jobjectArray attributes);
             virtual ~JavaBundleResource();
 
-            string getAttribute(string attributeName);
-            void setAttribute(string attributeName, string value);
-            void initAttributes();
+            virtual ResourceAttributes& getAttributes();
+
+            virtual void setAttribute(std::string key, ResourceAttributes::Value&&);
+
+            virtual ResourceAttributes::Value getAttribute(const std::string& key);
+            virtual void initAttributes();
         private:
             // needs to be a GlobalRef
             jobject bundleResource;
index c3a2500..fb71bc5 100644 (file)
@@ -25,7 +25,7 @@
 
 using namespace OIC::Service;
 
-std::map<string, JavaBundleResource*> java_resources;
+std::map< string, JavaBundleResource* > java_resources;
 
 /*
  * Class:     org_iotivity_resourcecontainer_bundle_api_BaseActivator
@@ -33,13 +33,15 @@ std::map<string, JavaBundleResource*> java_resources;
  * 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){
+(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();
 
@@ -49,6 +51,7 @@ JNIEXPORT void JNICALL Java_org_iotivity_resourcecontainer_bundle_api_BaseActiva
     container->registerResource(javaBundleResource);
 
     java_resources[str_uri] = javaBundleResource;
+
 }
 
 /*
@@ -57,10 +60,12 @@ JNIEXPORT void JNICALL Java_org_iotivity_resourcecontainer_bundle_api_BaseActiva
  * 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){
+(JNIEnv *env, jobject obj, jobject bundleResource, jstring uri)
+{
     const char *str_uri = env->GetStringUTFChars(uri, 0);
 
-    if(java_resources[str_uri] != NULL){
+    if(java_resources[str_uri] != NULL)
+    {
         ResourceContainerImpl *container = ResourceContainerImpl::getImplInstance();
         container->unregisterResource(java_resources[str_uri]);
         java_resources.erase(str_uri);
@@ -72,13 +77,14 @@ JNIEXPORT void JNICALL Java_org_iotivity_resourcecontainer_bundle_api_BaseActiva
  * Method:    getNumberOfConfiguredResources
  * Signature: (Ljava/lang/String;)I
  */
-JNIEXPORT jint JNICALL Java_org_iotivity_resourcecontainer_bundle_api_BaseActivator_getNumberOfConfiguredResources
-  (JNIEnv *env, jobject obj, jstring bundleId){
+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;
+    vector< resourceInfo > resourceConfig;
     container->getResourceConfiguration(str_bundleId, &resourceConfig);
 
     return resourceConfig.size();
@@ -89,18 +95,18 @@ JNIEXPORT jint JNICALL Java_org_iotivity_resourcecontainer_bundle_api_BaseActiva
  * 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){
+JNIEXPORT jobjectArray JNICALL Java_org_iotivity_resourcecontainer_bundle_api_BaseActivator_getConfiguredResourceParams(
+        JNIEnv *env, jobject obj, jstring bundleId, jint resourceId)
+{
 
     jobjectArray ret;
     const char *str_bundleId = env->GetStringUTFChars(bundleId, 0);
 
     ResourceContainerImpl *container = ResourceContainerImpl::getImplInstance();
-    vector<resourceInfo> resourceConfig;
+    vector< resourceInfo > resourceConfig;
     container->getResourceConfiguration(str_bundleId, &resourceConfig);
     resourceInfo conf = resourceConfig[resourceId];
-    ret = (jobjectArray) env->NewObjectArray(4,
-            env->FindClass("java/lang/String"),
+    ret = (jobjectArray) env->NewObjectArray(4, env->FindClass("java/lang/String"),
             env->NewStringUTF(""));
 
     env->SetObjectArrayElement(ret, 0, env->NewStringUTF(conf.name.c_str()));
index 564032c..3afc29e 100644 (file)
@@ -42,31 +42,28 @@ namespace OIC
             m_pNotiReceiver = pNotiReceiver;
         }
 
-        void BundleResource::setAttribute(string attributeName, string value)
+        std::list< string > BundleResource::getAttributeNames()
         {
-            this->m_mapAttributes[attributeName] = value;
-
-            if (m_pNotiReceiver != NULL && !m_uri.empty())
-            {
-                m_pNotiReceiver->onNotificationReceived(m_uri);
+            std::list< string > ret;
+            for (ResourceAttributes::iterator it = m_resourceAttributes.begin(); it != m_resourceAttributes.end(); ++it){
+                ret.push_back(it->key());
             }
+            return ret;
+        }
 
+        ResourceAttributes& BundleResource::getAttributes(){
+            return m_resourceAttributes;
         }
 
-        std::string BundleResource::getAttribute(string attributeName)
+        void BundleResource::setAttribute(std::string key, ResourceAttributes::Value&& value)
         {
-            return this->m_mapAttributes[attributeName];
+            cout << "Bundle resource set attribute " << value.toString() << "|" << endl;
+            m_resourceAttributes[key] = value;
         }
 
-        std::list< string > BundleResource::getAttributeNames()
-        {
-            std::list< string > ret;
-            for (map< string, string >::iterator it = m_mapAttributes.begin();
-                    it != m_mapAttributes.end(); ++it)
-            {
-                ret.push_back(it->first);
-            }
-            return ret;
+        ResourceAttributes::Value BundleResource::getAttribute(const std::string& key){
+            cout << "Bundle resource get attribute " << m_resourceAttributes.at(key).toString() << "|" << endl;
+            return m_resourceAttributes.at(key);
         }
 
     }
diff --git a/service/resource-manipulation/src/resourceContainer/src/ContainerSampleClient.cpp b/service/resource-manipulation/src/resourceContainer/src/ContainerSampleClient.cpp
new file mode 100644 (file)
index 0000000..e90a6c1
--- /dev/null
@@ -0,0 +1,495 @@
+//******************************************************************
+//
+// Copyright 2014 Intel Mobile Communications GmbH 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.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+// OCClient.cpp : Defines the entry point for the console application.
+//
+#include <string>
+#include <map>
+#include <cstdlib>
+#include <pthread.h>
+#include <mutex>
+#include <condition_variable>
+#include "OCPlatform.h"
+#include "OCApi.h"
+
+using namespace OC;
+
+typedef std::map<OCResourceIdentifier, std::shared_ptr<OCResource>> DiscoveredResourceMap;
+
+DiscoveredResourceMap discoveredResources;
+std::shared_ptr<OCResource> curResource;
+static ObserveType OBSERVE_TYPE_TO_USE = ObserveType::Observe;
+std::mutex curResourceLock;
+
+class Light
+{
+public:
+
+    bool m_on_off;
+    int m_color;
+    int m_dim;
+    std::string m_name;
+
+
+    Light() : m_on_off(false), m_color(0), m_dim(0), m_name("")
+    {
+    }
+};
+
+Light mylight;
+
+int observe_count()
+{
+    static int oc = 0;
+    return ++oc;
+}
+
+void onObserve(const HeaderOptions headerOptions, const OCRepresentation& rep,
+                    const int& eCode, const int& sequenceNumber)
+{
+    try
+    {
+        if(eCode == OC_STACK_OK)
+        {
+            std::cout << "OBSERVE RESULT:"<<std::endl;
+            std::cout << "\tSequenceNumber: "<< sequenceNumber << std::endl;
+            rep.getValue("on-off", mylight.m_on_off);
+            rep.getValue("color", mylight.m_color);
+            rep.getValue("dim", mylight.m_dim);
+            rep.getValue("name", mylight.m_name);
+
+            std::cout << "\ton-off: " << mylight.m_on_off << std::endl;
+            std::cout << "\tcolor: " << mylight.m_color << std::endl;
+            std::cout << "\tdim: " << mylight.m_dim << std::endl;
+
+            if(observe_count() > 10)
+            {
+                std::cout<<"Cancelling Observe..."<<std::endl;
+                OCStackResult result = curResource->cancelObserve();
+
+                std::cout << "Cancel result: "<< result <<std::endl;
+                sleep(10);
+                std::cout << "DONE"<<std::endl;
+                std::exit(0);
+            }
+        }
+        else
+        {
+            std::cout << "onObserve Response error: " << eCode << std::endl;
+            std::exit(-1);
+        }
+    }
+    catch(std::exception& e)
+    {
+        std::cout << "Exception: " << e.what() << " in onObserve" << std::endl;
+    }
+
+}
+
+void onPost2(const HeaderOptions& headerOptions, const OCRepresentation& rep, const int eCode)
+{
+    try
+    {
+        if(eCode == OC_STACK_OK || eCode == OC_STACK_RESOURCE_CREATED)
+        {
+            std::cout << "POST request was successful" << std::endl;
+
+            if(rep.hasAttribute("createduri"))
+            {
+                std::cout << "\tUri of the created resource: "
+                    << rep.getValue<std::string>("createduri") << std::endl;
+            }
+            else
+            {
+                rep.getValue("on-off", mylight.m_on_off);
+                rep.getValue("color", mylight.m_color);
+                rep.getValue("dim", mylight.m_dim);
+
+                std::cout << "\ton-off: " << mylight.m_on_off << std::endl;
+                std::cout << "\tcolor: " << mylight.m_color << std::endl;
+                std::cout << "\tdim: " << mylight.m_dim << std::endl;
+            }
+
+            if (OBSERVE_TYPE_TO_USE == ObserveType::Observe)
+                std::cout << std::endl << "Observe is used." << std::endl << std::endl;
+            else if (OBSERVE_TYPE_TO_USE == ObserveType::ObserveAll)
+                std::cout << std::endl << "ObserveAll is used." << std::endl << std::endl;
+
+            curResource->observe(OBSERVE_TYPE_TO_USE, QueryParamsMap(), &onObserve);
+
+        }
+        else
+        {
+            std::cout << "onPost2 Response error: " << eCode << std::endl;
+            std::exit(-1);
+        }
+    }
+    catch(std::exception& e)
+    {
+        std::cout << "Exception: " << e.what() << " in onPost2" << std::endl;
+    }
+
+}
+
+void onPost(const HeaderOptions& headerOptions, const OCRepresentation& rep, const int eCode)
+{
+    try
+    {
+        if(eCode == OC_STACK_OK || eCode == OC_STACK_RESOURCE_CREATED)
+        {
+            std::cout << "POST request was successful" << std::endl;
+
+            if(rep.hasAttribute("createduri"))
+            {
+                std::cout << "\tUri of the created resource: "
+                    << rep.getValue<std::string>("createduri") << std::endl;
+            }
+            else
+            {
+                rep.getValue("on-off", mylight.m_on_off);
+                rep.getValue("color", mylight.m_color);
+                rep.getValue("dim", mylight.m_dim);
+
+                std::cout << "\ton-off: " << mylight.m_on_off << std::endl;
+                std::cout << "\tcolor: " << mylight.m_color << std::endl;
+                std::cout << "\tdim: " << mylight.m_dim << std::endl;
+            }
+
+            OCRepresentation rep2;
+
+            std::cout << "Posting light representation..." << std::endl;
+
+            mylight.m_on_off = true;
+
+            rep2.setValue("on-off", mylight.m_on_off);
+
+            curResource->post(rep2, QueryParamsMap(), &onPost2);
+        }
+        else
+        {
+            std::cout << "onPost Response error: " << eCode << std::endl;
+            std::exit(-1);
+        }
+    }
+    catch(std::exception& e)
+    {
+        std::cout << "Exception: " << e.what() << " in onPost" << std::endl;
+    }
+}
+
+// Local function to put a different state for this resource
+void postLightRepresentation(std::shared_ptr<OCResource> resource)
+{
+    if(resource)
+    {
+        OCRepresentation rep;
+
+        std::cout << "Posting light representation..."<<std::endl;
+
+        mylight.m_on_off = "false";
+
+        rep.setValue("on-off", mylight.m_on_off);
+
+        // Invoke resource's post API with rep, query map and the callback parameter
+        resource->post(rep, QueryParamsMap(), &onPost);
+    }
+}
+
+// callback handler on PUT request
+void onPut(const HeaderOptions& headerOptions, const OCRepresentation& rep, const int eCode)
+{
+    try
+    {
+        if(eCode == OC_STACK_OK)
+        {
+            std::cout << "PUT request was successful" << std::endl;
+
+            /*rep.getValue("on-off", mylight.m_on_off);
+            rep.getValue("dim", mylight.m_dim);
+            rep.getValue("color", mylight.m_color);
+
+            std::cout << "\ton-off: " << mylight.m_on_off << std::endl;
+            std::cout << "\tcolor: " << mylight.m_color << std::endl;
+            std::cout << "\tdim: " << mylight.m_dim << std::endl;*/
+
+            //postLightRepresentation(curResource);
+        }
+        else
+        {
+            std::cout << "onPut Response error: " << eCode << std::endl;
+            std::exit(-1);
+        }
+    }
+    catch(std::exception& e)
+    {
+        std::cout << "Exception: " << e.what() << " in onPut" << std::endl;
+    }
+}
+
+// Local function to put a different state for this resource
+void putLightRepresentation(std::shared_ptr<OCResource> resource)
+{
+    if(resource)
+    {
+        OCRepresentation rep;
+
+        std::cout << "Putting light representation..."<<std::endl;
+
+        mylight.m_on_off = true;
+
+        std::cout << "Sending request to: " << resource->uri() << std::endl;
+        rep.setValue("on-off", mylight.m_on_off);
+
+        // Invoke resource's put API with rep, query map and the callback parameter
+
+        resource->put(rep, QueryParamsMap(), &onPut);
+    }
+}
+
+// Callback handler on GET request
+void onGet(const HeaderOptions& headerOptions, const OCRepresentation& rep, const int eCode)
+{
+    try
+    {
+        if(eCode == OC_STACK_OK)
+        {
+            std::cout << "GET request was successful" << std::endl;
+            std::cout << "Resource URI: " << rep.getUri() << std::endl;
+
+            std::cout << "Payload: " << rep.getPayload() << std::endl;
+
+            rep.getValue("on-off", mylight.m_on_off);
+            rep.getValue("dim", mylight.m_dim);
+            rep.getValue("color", mylight.m_color);
+
+            std::cout << "\ton-off: " << mylight.m_on_off << std::endl;
+            std::cout << "\tcolor: " << mylight.m_color << std::endl;
+            std::cout << "\tdim: " << mylight.m_dim << std::endl;
+
+            putLightRepresentation(curResource);
+        }
+        else
+        {
+            std::cout << "onGET Response error: " << eCode << std::endl;
+            std::exit(-1);
+        }
+    }
+    catch(std::exception& e)
+    {
+        std::cout << "Exception: " << e.what() << " in onGet" << std::endl;
+    }
+}
+
+// Local function to get representation of light resource
+void getLightRepresentation(std::shared_ptr<OCResource> resource)
+{
+    if(resource)
+    {
+        std::cout << "Getting Light Representation..."<<std::endl;
+        // Invoke resource's get API with the callback parameter
+
+        QueryParamsMap test;
+        std::cout << "Sending request to: " << resource->uri() << std::endl;
+        resource->get(test, &onGet);
+    }
+}
+
+// Callback to found resources
+void foundResource(std::shared_ptr<OCResource> resource)
+{
+    std::cout << "In foundResource\n";
+    std::string resourceURI;
+    std::string hostAddress;
+    try
+    {
+        {
+            std::lock_guard<std::mutex> lock(curResourceLock);
+            if(discoveredResources.find(resource->uniqueIdentifier()) == discoveredResources.end())
+            {
+                std::cout << "Found resource " << resource->uniqueIdentifier() <<
+                    " for the first time on server with ID: "<< resource->sid()<<std::endl;
+                discoveredResources[resource->uniqueIdentifier()] = resource;
+            }
+            else
+            {
+                std::cout<<"Found resource "<< resource->uniqueIdentifier() << " again!"<<std::endl;
+            }
+
+            if(curResource)
+            {
+                std::cout << "Found another resource, ignoring"<<std::endl;
+                return;
+            }
+        }
+
+        // Do some operations with resource object.
+        if(resource)
+        {
+            std::cout<<"DISCOVERED Resource:"<<std::endl;
+            // Get the resource URI
+            resourceURI = resource->uri();
+            std::cout << "\tURI of the resource: " << resourceURI << std::endl;
+
+            // Get the resource host address
+            hostAddress = resource->host();
+            std::cout << "\tHost address of the resource: " << hostAddress << std::endl;
+
+            // Get the resource types
+            std::cout << "\tList of resource types: " << std::endl;
+            for(auto &resourceTypes : resource->getResourceTypes())
+            {
+                std::cout << "\t\t" << resourceTypes << std::endl;
+
+                if(resourceTypes == "oic.light.control")
+                {
+                    curResource = resource;
+                    // Call a local function which will internally invoke get API on the resource pointer
+                    getLightRepresentation(resource);
+                }
+            }
+
+            // Get the resource interfaces
+            std::cout << "\tList of resource interfaces: " << std::endl;
+            for(auto &resourceInterfaces : resource->getResourceInterfaces())
+            {
+                std::cout << "\t\t" << resourceInterfaces << std::endl;
+            }
+        }
+        else
+        {
+            // Resource is invalid
+            std::cout << "Resource is invalid" << std::endl;
+        }
+
+    }
+    catch(std::exception& e)
+    {
+        std::cerr << "Exception in foundResource: "<< e.what() << std::endl;
+    }
+}
+
+void printUsage()
+{
+    std::cout << std::endl;
+    std::cout << "---------------------------------------------------------------------\n";
+    std::cout << "Usage : ContainerSampleClient <ObserveType>" << std::endl;
+    std::cout << "   ObserveType : 1 - Observe" << std::endl;
+    std::cout << "   ObserveType : 2 - ObserveAll" << std::endl;
+    std::cout << "---------------------------------------------------------------------\n\n";
+}
+
+void checkObserverValue(int value)
+{
+    if (value == 1)
+    {
+        OBSERVE_TYPE_TO_USE = ObserveType::Observe;
+        std::cout << "<===Setting ObserveType to Observe===>\n\n";
+    }
+    else if (value == 2)
+    {
+        OBSERVE_TYPE_TO_USE = ObserveType::ObserveAll;
+        std::cout << "<===Setting ObserveType to ObserveAll===>\n\n";
+    }
+    else
+    {
+        std::cout << "<===Invalid ObserveType selected."
+                  <<" Setting ObserveType to Observe===>\n\n";
+    }
+}
+
+static FILE* client_open(const char *path, const char *mode)
+{
+    return fopen("./oic_svr_db_client.json", mode);
+}
+
+int main(int argc, char* argv[]) {
+
+    std::ostringstream requestURI;
+    OCPersistentStorage ps {client_open, fread, fwrite, fclose, unlink };
+    try
+    {
+        printUsage();
+        if (argc == 1)
+        {
+            std::cout << "<===Setting ObserveType to Observe and ConnectivityType to IP===>\n\n";
+        }
+        else if (argc == 2)
+        {
+            checkObserverValue(std::stoi(argv[1]));
+        }
+        else
+        {
+            std::cout << "<===Invalid number of command line arguments===>\n\n";
+            return -1;
+        }
+    }
+    catch(std::exception& )
+    {
+        std::cout << "<===Invalid input arguments===>\n\n";
+        return -1;
+    }
+
+    // Create PlatformConfig object
+    PlatformConfig cfg {
+        OC::ServiceType::InProc,
+        OC::ModeType::Both,
+        "0.0.0.0",
+        0,
+        OC::QualityOfService::LowQos,
+        &ps
+    };
+
+    OCPlatform::Configure(cfg);
+    try
+    {
+        // makes it so that all boolean values are printed as 'true/false' in this stream
+        std::cout.setf(std::ios::boolalpha);
+        // Find all resources
+        requestURI << OC_RSRVD_WELL_KNOWN_URI;// << "?rt=core.light";
+
+        OCPlatform::findResource("", requestURI.str(),
+                CT_DEFAULT, &foundResource);
+        std::cout<< "Finding Resource... " <<std::endl;
+
+        // Find resource is done twice so that we discover the original resources a second time.
+        // These resources will have the same uniqueidentifier (yet be different objects), so that
+        // we can verify/show the duplicate-checking code in foundResource(above);
+        OCPlatform::findResource("", requestURI.str(),
+                CT_DEFAULT, &foundResource);
+        std::cout<< "Finding Resource for second time..." << std::endl;
+
+        // A condition variable will free the mutex it is given, then do a non-
+        // intensive block until 'notify' is called on it.  In this case, since we
+        // don't ever call cv.notify, this should be a non-processor intensive version
+        // of while(true);
+        std::mutex blocker;
+        std::condition_variable cv;
+        std::unique_lock<std::mutex> lock(blocker);
+        cv.wait(lock);
+
+    }catch(OCException& e)
+    {
+        oclog() << "Exception in main: "<<e.what();
+    }
+
+    return 0;
+}
+
+
index cf7f6bf..5400550 100644 (file)
@@ -78,10 +78,13 @@ JavaBundleResource::JavaBundleResource(JNIEnv *env, jobject obj, jobject bundleR
     this->bundleResource = env->NewGlobalRef(bundleResource);
 
     bundleResourceClass = env->GetObjectClass(bundleResource);
+
     attributeSetter = env->GetMethodID(bundleResourceClass, "setAttribute",
             "(Ljava/lang/String;Ljava/lang/String;)V");
+
     attributeGetter = env->GetMethodID(bundleResourceClass, "getAttribute",
-            "(Ljava/lang/String;)Ljava/lang/String");
+            "(Ljava/lang/String;)Ljava/lang/String;");
+
 }
 
 JavaBundleResource::~JavaBundleResource()
@@ -89,7 +92,11 @@ JavaBundleResource::~JavaBundleResource()
 
 }
 
-string JavaBundleResource::getAttribute(string attributeName)
+ResourceAttributes& JavaBundleResource::getAttributes(){
+    return BundleResource::getAttributes();
+}
+
+ResourceAttributes::Value JavaBundleResource::getAttribute(const std::string& attributeName)
 {
     JavaVM* vm = ResourceContainerImpl::getImplInstance()->getJavaVM(m_bundleId);
 
@@ -112,17 +119,17 @@ string JavaBundleResource::getAttribute(string attributeName)
 
     jstring returnString = (jstring) env->CallObjectMethod(bundleResource, attributeGetter,
             attrName);
+
     const char *js = env->GetStringUTFChars(returnString, NULL);
-    std::string value(js);
+    std::string val(js);
+    ResourceAttributes::Value newVal = val;
     env->ReleaseStringUTFChars(returnString, js);
-    BundleResource::setAttribute(attributeName, value);
-    return value;
+    BundleResource::setAttribute(attributeName, newVal.toString());
+    return BundleResource::getAttribute(attributeName);
 }
 
-void JavaBundleResource::setAttribute(string attributeName, string value)
+void JavaBundleResource::setAttribute(std::string attributeName, ResourceAttributes::Value&& value)
 {
-    BundleResource::setAttribute(attributeName, value);
-
     JavaVM* vm = ResourceContainerImpl::getImplInstance()->getJavaVM(m_bundleId);
 
     JNIEnv * env;
@@ -141,7 +148,9 @@ void JavaBundleResource::setAttribute(string attributeName, string value)
     }
 
     jstring attrName = env->NewStringUTF(attributeName.c_str());
-    jstring val = env->NewStringUTF(value.c_str());
+    jstring val = env->NewStringUTF(value.toString().c_str());
+
 
     env->CallObjectMethod(bundleResource, attributeSetter, attrName, val);
+    BundleResource::setAttribute(attributeName, std::move(value));
 }
index 20593e1..d13c4b4 100644 (file)
@@ -62,6 +62,12 @@ class TestBundleResource: public BundleResource
 class ResourceContainerTest: public Test
 {
     public:
+        ~ResourceContainerTest() noexcept(true){
+
+        }
+
+
+    public:
         ResourceContainer *m_pResourceContainer;
 
     protected:
@@ -146,6 +152,12 @@ TEST_F(ResourceContainerTest, BundleStartedWithStartBundleAPI)
 
 class ResourceContainerBundleAPITest: public Test
 {
+
+    public:
+        ~ResourceContainerBundleAPITest() noexcept(true){
+
+        }
+
     public:
         MockRepository mocks;
         ResourceObject *m_pResourceObject;
@@ -249,6 +261,11 @@ TEST_F(ResourceContainerBundleAPITest, BundleResourceConfigurationListParsed)
 class ResourceContainerImplTest: public Test
 {
     public:
+        ~ResourceContainerImplTest() noexcept(true){
+
+        }
+
+    public:
         MockRepository mocks;
         ResourceContainerImpl *m_pResourceContainer;
         BundleInfo *m_pBundleInfo;
index 9c00bc1..daebaad 100644 (file)
@@ -59,6 +59,9 @@ else:
 
 if env.get('LOGGING'):
        env.AppendUnique(CPPDEFINES = ['TB_LOG'])
+       
+       
+
 
 # Add third party libraries
 lib_env = env.Clone()
@@ -105,6 +108,8 @@ container_gtest_env.PrependUnique(CPPPATH = [env.get('SRC_DIR')+'/extlibs/hippom
                                                                         
 container_gtest_env.AppendUnique(LIBPATH = [os.environ['JAVA_LIB']])
 
+container_gtest_env.AppendUnique(CCFLAGS = ['-Wnoexcept'])     
+
 conf = Configure(container_gtest_env)
 if not conf.CheckLib('jvm'):
        print '''