Align resource container Java bundle APIs with new naming scheme
authorMinji Park <minjii.park@samsung.com>
Fri, 25 Sep 2015 04:29:39 +0000 (13:29 +0900)
committerMadan Lanka <lanka.madan@samsung.com>
Mon, 28 Sep 2015 06:56:30 +0000 (06:56 +0000)
Updating Java bundle resource to follow the new naming scheme (handleSetAttributeRequest,
handleGetAttributeRequest). Latest changes in the resource container APIs
are now also updated in the Java related code.

Change-Id: I7b28c830c2dc6f2dd1c7ad31405851b6d94def54
Signed-off-by: Markus Jung <markus.jung@samsung.com>
Signed-off-by: Minji Park <minjii.park@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/3031
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Hun-je Yeon <hunje.yeon@samsung.com>
Reviewed-by: Madan Lanka <lanka.madan@samsung.com>
service/resource-encapsulation/src/resourceContainer/bundle-java-api/src/main/java/org/iotivity/resourcecontainer/bundle/api/BaseActivator.java
service/resource-encapsulation/src/resourceContainer/bundle-java-api/src/main/java/org/iotivity/resourcecontainer/bundle/api/BundleResource.java
service/resource-encapsulation/src/resourceContainer/examples/ContainerSample.cpp
service/resource-encapsulation/src/resourceContainer/examples/HueJavaSampleBundle/hue/src/main/java/org/iotivity/bundle/hue/HueBundleActivator.java
service/resource-encapsulation/src/resourceContainer/examples/HueJavaSampleBundle/hue/src/main/java/org/iotivity/bundle/hue/HueLightResource.java
service/resource-encapsulation/src/resourceContainer/examples/HueSampleBundle/src/HueSampleBundleActivator.cpp
service/resource-encapsulation/src/resourceContainer/examples/ResourceContainerConfig.xml
service/resource-encapsulation/src/resourceContainer/include/JavaBundleResource.h
service/resource-encapsulation/src/resourceContainer/src/BaseActivator.cpp
service/resource-encapsulation/src/resourceContainer/src/JavaBundleResource.cpp
service/resource-encapsulation/src/resourceContainer/src/ResourceContainerImpl.cpp

index 11e3310..b8e2e88 100644 (file)
@@ -24,114 +24,130 @@ import java.util.List;
 import java.util.Vector;
 
 /**
- * The BaseActivator implements the native interface to the resource container. 
- * It loads the resource container library and provies native methods
- * that can be used to register and unregister resources.
+ * The BaseActivator implements the native interface to the resource container.
+ * It loads the resource container library and provies native methods that can
+ * be used to register and unregister resources.
  */
 public class BaseActivator implements BundleActivator {
-    private String bundleId;
-    private Vector<BundleResource> bundleResources = new Vector<BundleResource>();
-
-    /**
-     * Creates an instance of the BaseActivator
-     * @param bundleId unique bundle identifier (e.g., oic.bundle.hue)
-     */
-    public BaseActivator(String bundleId) {
-        this.bundleId = bundleId;
-        
-    }
-
-    static {
-        try {
-            System.loadLibrary("ResContainerLib");
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-    }
-
-    /**
-     * Bundle activation needs to be provided by the subclass.
-     */
-    public void activateBundle() {
-
-    }
-
-    /**
-     * Deactivates the bundle and unregisters its resources.
-     */
-    public void deactivateBundle() {
-        System.out.println("Deactivating bundle (Base Activator).");
-        for(BundleResource bundleResource : bundleResources){
-            unregisterResource(bundleResource);
-        }
-    }
-
-    /**
-     * Registers a bundle resource at the resource container.
-     * @param resource bundle resource instance that should be made available as OIC resource 
-     */
-    public void registerResource(BundleResource resource) {
-        bundleResources.add(resource);
-        registerJavaResource(resource, resource.getAttributeKeys(), bundleId,
-                resource.getURI(), resource.getResourceType(),
-                resource.getName());
-    }
-
-    /**
-     * Wrapper to retrieve the resource configuration of the bundle resources.
-     * @return List of resource configurations.     
-     */
-    public List<ResourceConfig> getConfiguredBundleResources() {
-        int configuredResources = getNumberOfConfiguredResources(bundleId);
-
-        Vector<ResourceConfig> configs = new Vector<ResourceConfig>();
-
-        for (int i = 0; i < configuredResources; i++) {
-            String[] resourceParams = getConfiguredResourceParams(bundleId, i);
-            ResourceConfig config = new ResourceConfig(resourceParams);
-            configs.add(config);
-
-        }
-        return configs;
-    }
-
-    /**
-     * Unregisters a resource from the resource container.
-     */
-    public void unregisterResource(BundleResource resource) {
-        bundleResources.remove(resource);
-        unregisterJavaResource(resource, resource.getURI());
-    }
-
-    /**
-     * Native method that calls to the resource container.
-     * @param attributes String array of attribute names
-     * @param bundleId unique bundle identifier
-     * @param uri Uri that should be used to register the resource
-     */
-    private native void registerJavaResource(BundleResource resource,
-            String[] attributes, String bundleId, String uri,
-            String resourceType, String name);
-
-    /**
-     * Native method that calls to the resource container.
-     * @param resource 
-     * @param uri
-     */
-    private native void unregisterJavaResource(BundleResource resource, String uri);
-
-    /**
-     * Native method to retrieve the number of configured resources.
-     * @param bundleId unique bundle identifier
-     */
-    private native int getNumberOfConfiguredResources(String bundleId);
-
-    /**
-     * Native method to retrieve the configured resource parameters.
-     * @param bundleId unique bundle identifier 
-     * @param resId get the resource params for a certain resource
-     */
-    private native String[] getConfiguredResourceParams(String bundleId,
-            int resId);
+       private String bundleId;
+       private Vector<BundleResource> bundleResources = new Vector<BundleResource>();
+
+       /**
+        * Creates an instance of the BaseActivator
+        * 
+        * @param bundleId
+        *            unique bundle identifier (e.g., oic.bundle.hue)
+        */
+       public BaseActivator(String bundleId) {
+               this.bundleId = bundleId;
+       }
+
+       static {
+               try {
+                       System.loadLibrary("rcs_container");
+               } catch (Exception e) {
+                       e.printStackTrace();
+               }
+       }
+
+       /**
+        * Bundle activation needs to be provided by the subclass.
+        */
+       public void activateBundle() {
+
+       }
+
+       /**
+        * Deactivates the bundle and unregisters its resources.
+        */
+       public void deactivateBundle() {
+               System.out.println("Deactivating bundle (Base Activator).");
+               for (BundleResource bundleResource : bundleResources) {
+                       unregisterResource(bundleResource);
+               }
+       }
+
+       /**
+        * Registers a bundle resource at the resource container.
+        * 
+        * @param resource
+        *            bundle resource instance that should be made available as OIC
+        *            resource
+        */
+       public void registerResource(BundleResource resource) {
+               bundleResources.add(resource);
+               registerJavaResource(resource, resource.getAttributeKeys(), bundleId,
+                               resource.getURI(), resource.getResourceType(),
+                               resource.getName());
+       }
+
+       /**
+        * Wrapper to retrieve the resource configuration of the bundle resources.
+        * 
+        * @return List of resource configurations.
+        */
+       public List<ResourceConfig> getConfiguredBundleResources() {
+               int configuredResources = getNumberOfConfiguredResources(bundleId);
+
+               Vector<ResourceConfig> configs = new Vector<ResourceConfig>();
+
+               for (int i = 0; i < configuredResources; i++) {
+                       String[] resourceParams = getConfiguredResourceParams(bundleId, i);
+                       ResourceConfig config = new ResourceConfig(resourceParams);
+                       configs.add(config);
+
+               }
+               return configs;
+       }
+
+       /**
+        * Unregisters a resource from the resource container.
+        */
+       public void unregisterResource(BundleResource resource) {
+               bundleResources.remove(resource);
+               unregisterJavaResource(resource, resource.getURI());
+       }
+
+       /**
+        * Native method that calls to the resource container.
+        * 
+        * @param attributes
+        *            String array of attribute names
+        * @param bundleId
+        *            unique bundle identifier
+        * @param uri
+        *            Uri that should be used to register the resource
+        */
+       private native void registerJavaResource(BundleResource resource,
+                       String[] attributes, String bundleId, String uri,
+                       String resourceType, String name);
+
+       /**
+        * Native method that calls to the resource container.
+        * 
+        * @param resource
+        * @param uri
+        */
+       private native void unregisterJavaResource(BundleResource resource,
+                       String uri);
+
+       /**
+        * Native method to retrieve the number of configured resources.
+        * 
+        * @param bundleId
+        *            unique bundle identifier
+        */
+       private native int getNumberOfConfiguredResources(String bundleId);
+
+       /**
+        * Native method to retrieve the configured resource parameters.
+        * 
+        * @param bundleId
+        *            unique bundle identifier
+        * @param resId
+        *            get the resource params for a certain resource
+        */
+       private native String[] getConfiguredResourceParams(String bundleId,
+                       int resId);
 
 }
index 411a428..a4ed5e6 100644 (file)
@@ -24,107 +24,149 @@ import java.util.HashMap;
 import java.util.Set;
 
 /**
- * Basic BundleResource that should be used as a base class
- * by a bundle resources. A concrete technology has 
- * to override the setAttribute and getAttribute method
- * and map the according reads and writes to the technology specific 
- * messages.
+ * Basic BundleResource that should be used as a base class by a bundle
+ * resources. A concrete technology has to override the setAttribute and
+ * getAttribute method and map the according reads and writes to the technology
+ * specific messages.
  */
 public abstract class BundleResource {
-    protected String m_name, m_uri, m_resourceType, m_address;
-
-    protected HashMap<String, String> m_attributes;
-
-    /**
-     * 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
-     */
-    public abstract void setAttribute(String key, String value);
-
-    /**
-     * Retrieve the attribute (map to read command for the according protocol)
-     * @param key name of the attribute to be read
-     * @return Value of the attribute
-     */
-    public abstract String getAttribute(String key);     
-
-    /**
-     * 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;
-    }
-
-    /**
-     * 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;
-    }
+       protected String m_name, m_uri, m_resourceType, m_address;
+
+       protected HashMap<String, String> m_attributes = new HashMap<String, String>();
+
+       /**
+        * 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, String 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 handleSetAttributeRequest(String key, String value);
+
+       /**
+        * Retrieve the attribute (only data)
+        * 
+        * @param key
+        *            name of the attribute to be read
+        * @return Value of the attribute
+        */
+       protected final String 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 String handleGetAttributeRequest(String key);
+
+       /**
+        * 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;
+       }
+
+       /**
+        * 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 3d9febc..af2dae4 100644 (file)
@@ -149,11 +149,11 @@ int main()
     getchar();
     bundleParams["libraryPath"] = ".";
     std::string activator = "org.iotivity.bundle.hue.HueBundleActivator";
-    container->addBundle("oic.bundle.hueJavaSample", "/hueJava",
-                         "../../../../../../../../service/resource-encapsulation/src/resourceContainer/" \
-                         "examples/HueJavaSampleBundle/hue/target/hue-0.1-jar-with-dependencies.jar",
-                         activator,
-                         bundleParams);
+    container->addBundle("oic.bundle.hueJavaSample2", "/hueJava",
+                 "../../../../../../../../service/resource-encapsulation/src/resourceContainer/" \
+                 "examples/HueJavaSampleBundle/hue/target/hue-0.1-jar-with-dependencies.jar",
+                 activator,
+                 bundleParams);
 
     bundles = container->listBundles();
     cout << "\t>>> bundle list size : " << bundles.size() << endl;
@@ -164,15 +164,15 @@ int main()
 
     cout << "\nPress enter to start java bundle " << endl;
     getchar();
-    container->startBundle("oic.bundle.hueJavaSample");
+    container->startBundle("oic.bundle.hueJavaSample2");
 
     cout << "Press enter to stop java Bundle " << endl;
     getchar();
-    container->stopBundle("oic.bundle.hueJavaSample");
+    container->stopBundle("oic.bundle.hueJavaSample2");
 
     cout << "Press enter to test remove java Bundle " << endl;
     getchar();
-    container->removeBundle("oic.bundle.hueJavaSample");
+    container->removeBundle("oic.bundle.hueJavaSample2");
 
     bundles = container->listBundles();
     cout << "\t>>> bundle list size : " << bundles.size() << endl;
index 7be201f..6fc1fe8 100644 (file)
@@ -6,35 +6,35 @@ import org.iotivity.resourcecontainer.bundle.api.BaseActivator;
 import org.iotivity.resourcecontainer.bundle.api.ResourceConfig;
 
 public class HueBundleActivator extends BaseActivator {
-    private HueConnector connector;
-
-    public HueBundleActivator(String bundleId) {
-        super(bundleId);
-    }
-
-    public void activateBundle() {
-        super.activateBundle();
-        connector = new HueConnector();
-        List<ResourceConfig> resourceConfig = getConfiguredBundleResources();
-
-        for (ResourceConfig config : resourceConfig) {
-
-            HueLightResource hueLightResource = new HueLightResource(connector,
-                    config.getName(), config.getURI(),
-                    config.getResourceType(), config.getAddress());
-            
-            System.out.println("Registration of HueLightresource");
-            registerResource(hueLightResource);
-        }
-    }
-
-    public void deactivateBundle() {
-        System.out.println("Deactivate bundle called.");
-        super.deactivateBundle();
-    }
-
-    // test call
-    public static void main(String[] args) {
-        HueBundleActivator activator = new HueBundleActivator("oic.hue.bundle");
-    }
+       private HueConnector connector;
+
+       public HueBundleActivator(String bundleId) {
+               super(bundleId);
+       }
+
+       public void activateBundle() {
+               super.activateBundle();
+               connector = new HueConnector();
+               List<ResourceConfig> resourceConfig = getConfiguredBundleResources();
+
+               for (ResourceConfig config : resourceConfig) {
+
+                       HueLightResource hueLightResource = new HueLightResource(connector,
+                                       config.getName(), config.getURI(),
+                                       config.getResourceType(), config.getAddress());
+
+                       System.out.println("Registration of Hue light resource " + config);
+                       registerResource(hueLightResource);
+               }
+       }
+
+       public void deactivateBundle() {
+               System.out.println("Deactivate bundle called.");
+               super.deactivateBundle();
+       }
+
+       // test call
+       public static void main(String[] args) {
+               HueBundleActivator activator = new HueBundleActivator("oic.hue.bundle");
+       }
 }
index 32f3fd5..d65b5a7 100644 (file)
@@ -10,67 +10,65 @@ import org.iotivity.resourcecontainer.bundle.api.BundleResource;
  * @author iotivity
  */
 public class HueLightResource extends BundleResource {
-    private HueConnector m_hueConnector;
+       private HueConnector m_hueConnector;
 
-    public HueLightResource() {
-        initAttributes();
-        m_resourceType = "oic.light.control";
-       
-    }
+       public HueLightResource() {
+               initAttributes();
+               m_resourceType = "oic.r.light.control";
 
-    public HueLightResource(HueConnector hueConnector, String name, String uri,
-            String resourceType, String address) {
-        this();
-        this.m_hueConnector = hueConnector;
-        m_name = name;
-        m_uri = uri;
-        m_resourceType = resourceType;
-        m_address = address;        
-    }
+       }
 
-    protected void initAttributes() {
-        m_attributes = new HashMap<String, String>();
-        m_attributes.put("on-off", "true");
-        m_attributes.put("color", "0");
-        m_attributes.put("dim", "0");
-    }
+       public HueLightResource(HueConnector hueConnector, String name, String uri,
+                       String resourceType, String address) {
+               this();
+               this.m_hueConnector = hueConnector;
+               m_name = name;
+               m_uri = uri;
+               m_resourceType = resourceType;
+               m_address = address;
+       }
 
-    public void setAttribute(String key, String value) {
-        System.out.println("Set attribute called - key: " + key + ", value: "
-                + value + " transmitting now.");
+       protected void initAttributes() {
+               m_attributes.put("on-off", "true");
+               m_attributes.put("color", "0");
+               m_attributes.put("dim", "0");
+       }
 
-        if ("on-off".equals(value)) {
-            m_hueConnector.transmit(m_address + "/state", "{\"on\":" + value
-                    + "}");
-        }
+       public void handleSetAttributeRequest(String key, String value) {
+               System.out.println("Set attribute called - key: " + key + ", value: "
+                               + value + " transmitting now.");
 
-        if ("dim".equals(value)) {
-            m_hueConnector.transmit(m_address + "/state", "{\"bri\":" + value
-                    + "}");
-        }
+               if ("on-off".equals(value)) {
+                       m_hueConnector.transmit(m_address + "/state", "{\"on\":" + value
+                                       + "}");
+               }
 
-        if ("color".equals(value)) {
-            m_hueConnector.transmit(m_address + "/state", "{\"hue\":" + value
-                    + "}");
-        }
-        m_attributes.put(key, value);
-    }
+               if ("dim".equals(value)) {
+                       m_hueConnector.transmit(m_address + "/state", "{\"bri\":" + value
+                                       + "}");
+               }
 
-    public String getAttribute(String key) {
-        
-        // map key to hue address
-        // read from Hue gateway, parse resource representation and return
-        // attribute
-        //m_hueConnector.read(m_address);
-        return m_attributes.get(key);
-    }     
+               if ("color".equals(value)) {
+                       m_hueConnector.transmit(m_address + "/state", "{\"hue\":" + value
+                                       + "}");
+               }
+               this.setAttribute(key, value);
+       }
 
-    @Override
-    public String toString() {
-        return "HueLightResource [m_hueConnector=" + m_hueConnector
-                + ", m_name=" + m_name + ", m_uri=" + m_uri
-                + ", m_resourceType=" + m_resourceType + ", m_address="
-                + m_address + ", m_attributes=" + m_attributes + "]";
-    }
+       public String handleGetAttributeRequest(String key) {
+               // map key to hue address
+               // read from Hue gateway, parse resource representation and return
+               // attribute
+               // m_hueConnector.read(m_address);
+               return this.getAttribute(key);
+       }
+
+       @Override
+       public String toString() {
+               return "HueLightResource [m_hueConnector=" + m_hueConnector
+                               + ", m_name=" + m_name + ", m_uri=" + m_uri
+                               + ", m_resourceType=" + m_resourceType + ", m_address="
+                               + m_address + ", m_attributes=" + m_attributes + "]";
+       }
 
 }
index 2cb696f..903f6ba 100644 (file)
@@ -80,7 +80,6 @@ void HueSampleBundleActivator::createResource(resourceInfo resourceInfo)
         static int lightCount = 1;
         BundleResource::Ptr hueLight = std::make_shared< HueLight >(m_connector, resourceInfo.address);
         resourceInfo.uri = "/hue/light/" + std::to_string(lightCount++);
-        std::cout << "Registering resource " << resourceInfo.uri << std::endl;
         hueLight->m_bundleId = m_bundleId;
         hueLight->m_uri = resourceInfo.uri;
         hueLight->m_resourceType = resourceInfo.resourceType;
index a8548a1..347e737 100644 (file)
@@ -85,7 +85,7 @@
             </resourceInfo>       
         </resources>
     </bundle>
-    <!--
+
     <bundle>
         <id>oic.bundle.hueJavaSample</id>       
         <path>../../../../../../../../service/resource-encapsulation/src/resourceContainer/examples/HueJavaSampleBundle/hue/target/hue-0.1-jar-with-dependencies.jar</path>
         <resources>
             <resourceInfo>
                 <name>light</name>
-                <uri>light/1</uri>
+                <resourceUri>/hueJava/light/1</resourceUri>
                 <resourceType>oic.r.light</resourceType>
                 <address>http://192.168.0.2/api/newdeveloper/lights/1</address>
             </resourceInfo>       
         </resources>
     </bundle>
-    -->
+
 </container>
\ No newline at end of file
index 54cb40e..0dc750b 100644 (file)
@@ -42,19 +42,23 @@ namespace OIC
                     jobjectArray attributes);
             virtual ~JavaBundleResource();
 
-            virtual RCSResourceAttributes& getAttributes();
+            void handleSetAttributeRequest(const std::string& key,
+                    RCSResourceAttributes::Value&&);
 
-            virtual void setAttribute(std::string key, RCSResourceAttributes::Value&&);
+            RCSResourceAttributes::Value handleGetAttributeRequest(const std::string& key);
+
+            virtual void handleSetAttributesRequest(RCSResourceAttributes &attrs);
+
+            virtual RCSResourceAttributes& handleGetAttributesRequest();
 
-            virtual RCSResourceAttributes::Value getAttribute(const std::string& key);
             virtual void initAttributes();
         private:
             // needs to be a GlobalRef
-            jobject bundleResource;
-            jobjectArray attributes;
-            jclass bundleResourceClass;
-            jmethodID attributeSetter;
-            jmethodID attributeGetter;
+            jobject m_bundleResource;
+            jobjectArray m_attributes;
+            jclass m_bundleResourceClass;
+            jmethodID m_attributeSetRequestHandler;
+            jmethodID m_attributeGetRequestHandler;
             string m_bundleId;
         };
     }
index 69917fc..e5cf71c 100644 (file)
 #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;
+std::map< string, BundleResource::Ptr > java_resources;
 
 /*
  * Class:     org_iotivity_resourcecontainer_bundle_api_BaseActivator
@@ -43,8 +42,8 @@ Java_org_iotivity_resourcecontainer_bundle_api_BaseActivator_registerJavaResourc
     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);
+    BundleResource::Ptr javaBundleResource = std::make_shared< JavaBundleResource >
+            (env, obj, bundleResource, str_bundleId, attributes);
     ResourceContainerImpl *container = ResourceContainerImpl::getImplInstance();
 
     javaBundleResource->m_uri = string(str_uri, strlen(str_uri));
@@ -53,7 +52,6 @@ Java_org_iotivity_resourcecontainer_bundle_api_BaseActivator_registerJavaResourc
     container->registerResource(javaBundleResource);
 
     java_resources[str_uri] = javaBundleResource;
-
 }
 
 /*
index d4adf66..47228ee 100644 (file)
@@ -57,15 +57,15 @@ JavaBundleResource::JavaBundleResource(JNIEnv *env, jobject obj, jobject bundleR
 
     m_bundleId = bundleId;
 
-    this->bundleResource = env->NewGlobalRef(bundleResource);
+    this->m_bundleResource = env->NewGlobalRef(bundleResource);
 
-    bundleResourceClass = env->GetObjectClass(bundleResource);
+    m_bundleResourceClass = env->GetObjectClass(bundleResource);
 
-    attributeSetter = env->GetMethodID(bundleResourceClass, "setAttribute",
-                                       "(Ljava/lang/String;Ljava/lang/String;)V");
+    m_attributeSetRequestHandler = env->GetMethodID(m_bundleResourceClass,
+            "handleSetAttributeRequest", "(Ljava/lang/String;Ljava/lang/String;)V");
 
-    attributeGetter = env->GetMethodID(bundleResourceClass, "getAttribute",
-                                       "(Ljava/lang/String;)Ljava/lang/String;");
+    m_attributeGetRequestHandler = env->GetMethodID(m_bundleResourceClass,
+            "handleGetAttributeRequest", "(Ljava/lang/String;)Ljava/lang/String;");
 
 }
 
@@ -74,12 +74,8 @@ JavaBundleResource::~JavaBundleResource()
 
 }
 
-RCSResourceAttributes &JavaBundleResource::getAttributes()
-{
-    return BundleResource::getAttributes();
-}
-
-RCSResourceAttributes::Value JavaBundleResource::getAttribute(const std::string &attributeName)
+RCSResourceAttributes::Value JavaBundleResource::handleGetAttributeRequest(
+        const std::string &attributeName)
 {
     JavaVM *vm = ResourceContainerImpl::getImplInstance()->getJavaVM(m_bundleId);
 
@@ -90,18 +86,20 @@ RCSResourceAttributes::Value JavaBundleResource::getAttribute(const std::string
     {
         if (vm->AttachCurrentThread((void **) &env, NULL) != 0)
         {
-            OC_LOG_V(ERROR, CONTAINER_TAG, "[JavaBundleResource::getAttribute] Failed to attach ");
+            OC_LOG_V(ERROR, CONTAINER_TAG,
+                    "[JavaBundleResource::handleGetAttributeRequest] Failed to attach ");
         }
     }
     else if (envStat == JNI_EVERSION)
     {
-        OC_LOG_V(ERROR, CONTAINER_TAG, "[JavaBundleResource::getAttribute] Env: version not supported");
+        OC_LOG_V(ERROR, CONTAINER_TAG,
+                "[JavaBundleResource::handleGetAttributeRequest] Env: version not supported");
     }
 
     jstring attrName = env->NewStringUTF(attributeName.c_str());
 
-    jstring returnString = (jstring) env->CallObjectMethod(bundleResource, attributeGetter,
-                           attrName);
+    jstring returnString = (jstring) env->CallObjectMethod(m_bundleResource,
+            m_attributeGetRequestHandler, attrName);
 
     const char *js = env->GetStringUTFChars(returnString, NULL);
     std::string val(js);
@@ -111,7 +109,7 @@ RCSResourceAttributes::Value JavaBundleResource::getAttribute(const std::string
     return BundleResource::getAttribute(attributeName);
 }
 
-void JavaBundleResource::setAttribute(std::string attributeName,
+void JavaBundleResource::handleSetAttributeRequest(const std::string &attributeName,
                                       RCSResourceAttributes::Value &&value)
 {
     JavaVM *vm = ResourceContainerImpl::getImplInstance()->getJavaVM(m_bundleId);
@@ -123,19 +121,39 @@ void JavaBundleResource::setAttribute(std::string attributeName,
     {
         if (vm->AttachCurrentThread((void **) &env, NULL) != 0)
         {
-            OC_LOG_V(ERROR, CONTAINER_TAG, "[JavaBundleResource::setAttribute] Failed to attach ");
+            OC_LOG_V(ERROR, CONTAINER_TAG,
+                    "[JavaBundleResource::handleSetAttributeRequest] Failed to attach ");
         }
     }
     else if (envStat == JNI_EVERSION)
     {
-        OC_LOG_V(ERROR, CONTAINER_TAG, "[JavaBundleResource::setAttribute] Env: version not supported ");
+        OC_LOG_V(ERROR, CONTAINER_TAG,
+                "[JavaBundleResource::handleSetAttributeRequest] Env: version not supported ");
     }
 
     jstring attrName = env->NewStringUTF(attributeName.c_str());
     jstring val = env->NewStringUTF(value.toString().c_str());
 
 
-    env->CallObjectMethod(bundleResource, attributeSetter, attrName, val);
+    env->CallObjectMethod(m_bundleResource, m_attributeSetRequestHandler, attrName, val);
     BundleResource::setAttribute(attributeName, std::move(value));
 }
+
+
+void JavaBundleResource::handleSetAttributesRequest(RCSResourceAttributes &attrs){
+    for (RCSResourceAttributes::iterator it = attrs.begin(); it != attrs.end(); ++it)
+    {
+        handleSetAttributeRequest(it->key(),std::move(it->value()));
+    }
+}
+
+RCSResourceAttributes & JavaBundleResource::handleGetAttributesRequest(){
+    RCSResourceAttributes ret;
+    std::list<string> attrsNames = getAttributeNames();
+    for(std::list<string>::iterator iterator = attrsNames.begin();
+            iterator != attrsNames.end(); ++iterator ){
+        ret[*iterator] = handleGetAttributeRequest(*iterator);
+    }
+    return ret;
+}
 #endif
index cc761ab..364d27d 100644 (file)
@@ -92,8 +92,10 @@ namespace OIC
                                 bundles[i][BUNDLE_LIBRARY_PATH]);
                         }
 
-                        OC_LOG_V(INFO, CONTAINER_TAG, "Init Bundle:(%s)", std::string(bundles[i][BUNDLE_ID] + ";" +
-                                 bundles[i][BUNDLE_PATH]).c_str());
+                        OC_LOG_V(INFO, CONTAINER_TAG, "Init Bundle:(%s)",
+                                 std::string(bundles[i][BUNDLE_ID] + ";" +
+                                             bundles[i][BUNDLE_PATH]).c_str());
+
                         registerBundle(bundleInfo);
                         activateBundle(bundleInfo);
                     }
@@ -284,8 +286,9 @@ namespace OIC
                         std::bind(&ResourceContainerImpl::setRequestHandler, this,
                                   std::placeholders::_1, std::placeholders::_2));
 
-                    OC_LOG_V(INFO, CONTAINER_TAG, "Registration finished (%s)", std::string(strUri + ", " +
-                             strResourceType).c_str());
+                    OC_LOG_V(INFO, CONTAINER_TAG, "Registration finished (%s)",
+                             std::string(strUri + ", " +
+                                         strResourceType).c_str());
 
                     if (m_config->isHasInput(resource->m_bundleId))
                     {
@@ -407,7 +410,8 @@ namespace OIC
 
         void ResourceContainerImpl::onNotificationReceived(const std::string &strResourceUri)
         {
-            OC_LOG_V(INFO, CONTAINER_TAG, "notification from (%s)", std::string(strResourceUri + ".").c_str());
+            OC_LOG_V(INFO, CONTAINER_TAG,
+                     "notification from (%s)", std::string(strResourceUri + ".").c_str());
 
             if (m_mapServers.find(strResourceUri) != m_mapServers.end())
             {
@@ -424,7 +428,8 @@ namespace OIC
         RCSResourceObject::Ptr ResourceContainerImpl::buildResourceObject(const std::string &strUri,
                 const std::string &strResourceType)
         {
-            return RCSResourceObject::Builder(strUri, strResourceType, "oic.if.baseline").setObservable(
+            return RCSResourceObject::Builder(strUri, strResourceType,
+                                              "oic.if.baseline").setObservable(
                        true).setDiscoverable(true).build();
         }
 
@@ -487,8 +492,9 @@ namespace OIC
                     ((BundleInfoInternal *)bundleInfo)->setLibraryPath(params[BUNDLE_LIBRARY_PATH]);
                 }
 
-                OC_LOG_V(INFO, CONTAINER_TAG, "Add Bundle: (%s)", std::string(bundleInfo->getID() + "; " +
-                         bundleInfo->getPath()).c_str());
+                OC_LOG_V(INFO, CONTAINER_TAG, "Add Bundle: (%s)",
+                         std::string(bundleInfo->getID() + "; " +
+                                     bundleInfo->getPath()).c_str());
 
                 registerBundle(bundleInfo);
             }
@@ -819,7 +825,6 @@ namespace OIC
         {
             OC_LOG_V(INFO, CONTAINER_TAG, "Registering Java bundle (%s)",
                      std::string(bundleInfo->getID()).c_str());
-
             JavaVM *jvm;
             JNIEnv *env;
             JavaVMInitArgs vm_args;
@@ -831,8 +836,9 @@ namespace OIC
             {
                 fclose(file);
 
-                OC_LOG_V(INFO, CONTAINER_TAG, "Resource bundle (%s)", std::string(bundleInfo->getPath() +
-                         " available.").c_str());
+                OC_LOG_V(INFO, CONTAINER_TAG, "Resource bundle (%s)",
+                         std::string(bundleInfo->getPath() +
+                                     " available.").c_str());
             }
             else
             {
@@ -848,7 +854,8 @@ namespace OIC
             strcpy(classpath, "-Djava.class.path=");
             strcat(classpath, bundleInfo->getPath().c_str());
 
-            OC_LOG(INFO, CONTAINER_TAG, std::string("Configured classpath: ").append(classpath).c_str());
+            OC_LOG(INFO, CONTAINER_TAG,
+                   std::string("Configured classpath: ").append(classpath).c_str());
 
             options[1].optionString = classpath;
 
@@ -857,7 +864,8 @@ namespace OIC
             strcat(libraryPath, bundleInfo->getLibraryPath().c_str());
             options[2].optionString = libraryPath;
 
-            OC_LOG(INFO, CONTAINER_TAG, std::string("Configured library path: ").append(libraryPath).c_str());
+            OC_LOG(INFO, CONTAINER_TAG,
+                   std::string("Configured library path: ").append(libraryPath).c_str());
 
             vm_args.version = JNI_VERSION_1_4;
             vm_args.options = options;
@@ -903,7 +911,6 @@ namespace OIC
                 OC_LOG_V(ERROR, CONTAINER_TAG, "Cannot register bundle (%s)",
                          std::string( bundleInfoInternal->getID()
                                       + " activate bundle method not found ").c_str());
-
                 return;
             }
             bundleInfoInternal->setJavaBundleActivatorMethod(activateMethod);
@@ -916,7 +923,6 @@ namespace OIC
                 OC_LOG_V(ERROR, CONTAINER_TAG, "Cannot register bundle (%s)",
                          std::string( bundleInfoInternal->getID()
                                       + " deactivate bundle method not found ").c_str());
-
                 return;
             }
 
@@ -936,6 +942,7 @@ namespace OIC
 
             m_bundles[bundleInfo->getID()] = ((BundleInfoInternal *)bundleInfo);
 
+
             OC_LOG(INFO, CONTAINER_TAG, "Bundle registered");
         }