Extended RcsReousrceAttributes to support update of multiple attributes at once
authorMarkus Jung <markus.jung@samsung.com>
Thu, 12 Nov 2015 00:14:23 +0000 (09:14 +0900)
committerUze Choi <uzchoi@samsung.com>
Tue, 17 Nov 2015 05:28:10 +0000 (05:28 +0000)
Change-Id: Ibfe08f0d0228a126754e03c091681fcdd3be6d59
Signed-off-by: Markus Jung <markus.jung85@gmail.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/4159
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
service/resource-container/android/resource-container/src/main/java/org/iotivity/service/resourcecontainer/AndroidBundleResource.java
service/resource-container/android/resource-container/src/main/java/org/iotivity/service/resourcecontainer/RcsBundleInfo.java
service/resource-container/android/resource-container/src/main/java/org/iotivity/service/resourcecontainer/RcsResourceAttributes.java
service/resource-encapsulation/src/serverBuilder/src/RCSResourceObject.cpp

index 4320004..3494fc7 100644 (file)
@@ -23,7 +23,7 @@ package org.iotivity.service.resourcecontainer;
 import java.util.HashMap;
 import java.util.Set;
 import android.content.Context;
-
+import android.util.Log;
 
 /**
  * Basic BundleResource that should be used as a base class by a bundle
@@ -32,154 +32,171 @@ import android.content.Context;
  * specific messages.
  */
 public abstract class AndroidBundleResource {
-       protected String m_name, m_uri, m_resourceType, m_address;
-
-       protected RcsResourceAttributes m_attributes = new RcsResourceAttributes();
-       
-       protected Context m_context;
-       
-       public AndroidBundleResource(){
-           initAttributes();
-       }
-       
-       public AndroidBundleResource(Context context){
-           this();
-           this.m_context = context;
-       }
-
-       /**
-        * Initialize the internal attribute structure.
-        */
-       protected abstract void initAttributes();
-
-       /**
-        * Set the attribute (map to a send command for the according protocol)
-        * 
-        * @param key
-        *            name of the attribute to be set
-        * @param value
-        *            new value of the attribute
-        */
-       protected final void setAttribute(String key, RcsValue value) {
-               m_attributes.put(key, value);
-       }
-
-       /**
-        * Set the attribute (map to a send command for the according protocol)
-        * 
-        * @param key
-        *            name of the attribute to be set
-        * @param value
-        *            new value of the attribute
-        */
-       public abstract void handleSetAttributesRequest(RcsResourceAttributes value);
-
-       /**
-        * Retrieve the attribute (only data)
-        * 
-        * @param key
-        *            name of the attribute to be read
-        * @return Value of the attribute
-        */
-       protected final RcsValue getAttribute(String key) {
-               return m_attributes.get(key);
-       }
-       
-       /**
-        * Retrieve the attribute (map to read command)
-        * 
-        * @param key
-        *            name of the attribute to be set
-        * @param value
-        *            new value of the attribute
-        */
-       public abstract RcsResourceAttributes handleGetAttributesRequest();
-
-       /**
-        * Attribute keys provided through by the bundle resource.
-        * 
-        * @return Name of attribute keys as string array
-        */
-       public String[] getAttributeKeys() {
-               Set<String> keys = m_attributes.keySet();
-               return keys.toArray(new String[keys.size()]);
-       }
-
-       /**
-        * Setter for the uri property
-        * 
-        * @param uri
-        *            URI of the resource
-        */
-       public void setURI(String uri) {
-               this.m_uri = uri;
-       }
-
-       /**
-        * Returns the URI of the resource
-        * 
-        * @return Resource URI
-        */
-       public String getURI() {
-               return m_uri;
+    protected String                m_name, m_uri, m_resourceType, m_address;
+
+    protected RcsResourceAttributes m_attributes = new RcsResourceAttributes();
+
+    protected Context               m_context;
+
+    public AndroidBundleResource() {
+        initAttributes();
+    }
+
+    public AndroidBundleResource(Context context) {
+        this();
+        this.m_context = context;
+    }
+
+    /**
+     * Initialize the internal attribute structure.
+     */
+    protected abstract void initAttributes();
+
+    /**
+     * Set the attribute (map to a send command for the according protocol)
+     * 
+     * @param key
+     *            name of the attribute to be set
+     * @param value
+     *            new value of the attribute
+     */
+    protected final void setAttribute(String key, RcsValue value) {
+        m_attributes.put(key, value);
+    }
+
+    /**
+     * Set the attribute (map to a send command for the according protocol)
+     * 
+     * @param key
+     *            name of the attribute to be set
+     * @param value
+     *            new value of the attribute
+     */
+    protected final void setAttributes(RcsResourceAttributes value) {
+        m_attributes.put(value);
+    }
+
+    /**
+     * Set the attribute (map to a send command for the according protocol)
+     * 
+     * @param key
+     *            name of the attribute to be set
+     * @param value
+     *            new value of the attribute
+     */
+    public abstract void handleSetAttributesRequest(RcsResourceAttributes value);
+
+    /**
+     * Retrieve the attribute (only data)
+     * 
+     * @param key
+     *            name of the attribute to be read
+     * @return Value of the attribute
+     */
+    protected final RcsValue getAttribute(String key) {
+        return m_attributes.get(key);
+    }
+
+    protected final RcsResourceAttributes getAttributes() {
+        RcsResourceAttributes ret = new RcsResourceAttributes(this.m_attributes);             
+        return ret;
+    }
+
+    /**
+     * Retrieve the attribute (map to read command)
+     * 
+     * @param key
+     *            name of the attribute to be set
+     * @param value
+     *            new value of the attribute
+     */
+    public abstract RcsResourceAttributes handleGetAttributesRequest();
+
+    /**
+     * Attribute keys provided through by the bundle resource.
+     * 
+     * @return Name of attribute keys as string array
+     */
+    public String[] getAttributeKeys() {
+           Set<String> keys = m_attributes.keySet();
+           return keys.toArray(new String[keys.size()]);
        }
 
-       /**
-        * Sets the resource type property
-        * 
-        * @param resourceType
-        *            OIC resource type
-        */
-       public void setResourceType(String resourceType) {
-               this.m_resourceType = resourceType;
-       }
-
-       /**
-        * Getter for the resource type
-        * 
-        * @return OIC resource type
-        */
-       public String getResourceType() {
-               return m_resourceType;
-       }
-
-       /**
-        * Sets the technology specific address information (e.g., ZigBee short or
-        * long identifier)
-        * 
-        * @param address
-        *            Resource address
-        */
-       public void setAddress(String address) {
-               this.m_address = address;
-       }
-
-       /**
-        * Returns the technology specific address information
-        * 
-        * @return Resource address
-        */
-       public String getAddress() {
-               return m_address;
-       }
-
-       /**
-        * Sets the name property of the resource
-        * 
-        * @param name
-        *            Resource name
-        */
-       public void setName(String name) {
-               this.m_name = name;
-       }
-
-       /**
-        * Returns the name property of the resource
-        * 
-        * @return Resource name
-        */
-       public String getName() {
-               return m_name;
-       }
+    /**
+     * Setter for the uri property
+     * 
+     * @param uri
+     *            URI of the resource
+     */
+    public void setURI(String uri) {
+        this.m_uri = uri;
+    }
+
+    /**
+     * Returns the URI of the resource
+     * 
+     * @return Resource URI
+     */
+    public String getURI() {
+        return m_uri;
+    }
+
+    /**
+     * Sets the resource type property
+     * 
+     * @param resourceType
+     *            OIC resource type
+     */
+    public void setResourceType(String resourceType) {
+        this.m_resourceType = resourceType;
+    }
+
+    /**
+     * Getter for the resource type
+     * 
+     * @return OIC resource type
+     */
+    public String getResourceType() {
+        return m_resourceType;
+    }
+
+    /**
+     * Sets the technology specific address information (e.g., ZigBee short or
+     * long identifier)
+     * 
+     * @param address
+     *            Resource address
+     */
+    public void setAddress(String address) {
+        this.m_address = address;
+    }
+
+    /**
+     * Returns the technology specific address information
+     * 
+     * @return Resource address
+     */
+    public String getAddress() {
+        return m_address;
+    }
+
+    /**
+     * Sets the name property of the resource
+     * 
+     * @param name
+     *            Resource name
+     */
+    public void setName(String name) {
+        this.m_name = name;
+    }
+
+    /**
+     * Returns the name property of the resource
+     * 
+     * @return Resource name
+     */
+    public String getName() {
+        return m_name;
+    }
 
 }
index f782a5b..952239f 100644 (file)
@@ -34,7 +34,7 @@ public class RcsBundleInfo {
     private final String mLibraryPath;
     private final String mVersion;
 
-    private RcsBundleInfo(String id, String path, String activatorName, 
+    private RcsBundleInfo(String id, String path, String activatorName,
             String libraryPath, String version) {
         mId = id;
         mPath = path;
@@ -45,9 +45,9 @@ public class RcsBundleInfo {
 
     /**
      * API for getting the Id of the bundle
-     *
+     * 
      * @return string - Id of the bundle
-     *
+     * 
      */
     public String getID() {
         return mId;
@@ -55,9 +55,9 @@ public class RcsBundleInfo {
 
     /**
      * API for getting the path of the bundle
-     *
+     * 
      * @return path - path of the bundle
-     *
+     * 
      */
     public String getPath() {
         return mPath;
@@ -65,9 +65,9 @@ public class RcsBundleInfo {
 
     /**
      * API for setting the Activator name for the bundle
-     *
+     * 
      * @return string - Name of the activator
-     *
+     * 
      */
     public String getActivatorName() {
         return mActivatorName;
@@ -75,9 +75,9 @@ public class RcsBundleInfo {
 
     /**
      * API for getting the library path for the bundle
-     *
+     * 
      * @return string - Library path in string form
-     *
+     * 
      */
     public String getLibraryPath() {
         return mLibraryPath;
@@ -85,9 +85,9 @@ public class RcsBundleInfo {
 
     /**
      * API for getting the version of the bundle
-     *
+     * 
      * @return string - version of the bundle
-     *
+     * 
      */
     public String getVersion() {
         return mVersion;
index f3611b1..219a9a6 100644 (file)
@@ -63,6 +63,12 @@ public final class RcsResourceAttributes extends RcsObject {
             mCache.put(key, lockedAttrs.get(key));
         }
     }
+    
+    public RcsResourceAttributes(RcsResourceAttributes attrs){
+        for (final String key : attrs.keySet()) {
+            mCache.put(key, attrs.get(key));
+        }
+    }
 
     /**
      * Returns a unmodifiable Set view of the keys contained in this attributes.
@@ -232,5 +238,14 @@ public final class RcsResourceAttributes extends RcsObject {
         esnureAllExtracted();
         return mCache.hashCode();
     }
+    
+    /**
+     * Updates all properties provided as parameter.
+     */
+    public void put(RcsResourceAttributes attrs){
+        for (final String key : attrs.keySet()) {
+            mCache.put(key, attrs.get(key));
+        }
+    }
 
 }
index 49425a5..b74de4b 100644 (file)
@@ -480,7 +480,6 @@ namespace OIC
             assert(request != nullptr);
 
             auto attrs = getAttributesFromOCRequest(request);
-            OC_LOG(INFO, "RESOURCE_OBJECT", ("handleRequestGet " + request->getResourceUri()).c_str());
             return sendResponse(*this, request, invokeHandler(attrs, request, m_getRequestHandler));
         }