Resource container update, API seperation (container, bundle)
authorMarkus Jung <markus.jung@samsung.com>
Mon, 6 Jul 2015 03:27:20 +0000 (12:27 +0900)
committerUze Choi <uzchoi@samsung.com>
Mon, 6 Jul 2015 04:23:04 +0000 (04:23 +0000)
Update on resource container. Bundle templates for c++ or Java-based protocol
bridge bundles. Common XML-based configuration.
Separated APIs and project skeletons for container and bundle templates.

Change-Id: Iacf3cc7bc860cfa42c2a50ed901ac7b786741a52
Signed-off-by: Markus Jung <markus.jung@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/1512
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
44 files changed:
service/resource-manipulation/modules/resourceContainer/SConscript
service/resource-manipulation/modules/resourceContainer/bundle-api/include/BundleActivator.h [moved from service/resource-manipulation/modules/resourceContainer/include/BundleActivator.h with 100% similarity]
service/resource-manipulation/modules/resourceContainer/bundle-api/include/BundleResource.h [moved from service/resource-manipulation/modules/resourceContainer/include/BundleResource.h with 56% similarity]
service/resource-manipulation/modules/resourceContainer/bundle-api/include/NotificationReceiver.h [moved from service/resource-manipulation/modules/resourceContainer/include/SoftSensorResource.h with 60% similarity]
service/resource-manipulation/modules/resourceContainer/bundle-api/include/ProtocolBridgeConnector.h [moved from service/resource-manipulation/modules/resourceContainer/include/ProtocolBridgeConnector.h with 100% similarity]
service/resource-manipulation/modules/resourceContainer/bundle-api/include/ProtocolBridgeResource.h [moved from service/resource-manipulation/modules/resourceContainer/include/ProtocolBridgeResource.h with 95% similarity]
service/resource-manipulation/modules/resourceContainer/bundle-api/include/ResourceContainerBundleAPI.h [moved from service/resource-manipulation/modules/resourceContainer/include/ResourceContainerBundleAPI.h with 60% similarity]
service/resource-manipulation/modules/resourceContainer/bundle-api/include/SoftSensorResource.h [new file with mode: 0644]
service/resource-manipulation/modules/resourceContainer/bundle-java-api/pom.xml [new file with mode: 0644]
service/resource-manipulation/modules/resourceContainer/bundle-java-api/src/main/java/org/iotivity/resourcecontainer/bundle/api/BaseActivator.java [new file with mode: 0644]
service/resource-manipulation/modules/resourceContainer/bundle-java-api/src/main/java/org/iotivity/resourcecontainer/bundle/api/BundleActivator.java [new file with mode: 0644]
service/resource-manipulation/modules/resourceContainer/bundle-java-api/src/main/java/org/iotivity/resourcecontainer/bundle/api/BundleResource.java [new file with mode: 0644]
service/resource-manipulation/modules/resourceContainer/bundle-java-api/src/main/java/org/iotivity/resourcecontainer/bundle/api/ProtocolBridgeConnector.java [new file with mode: 0644]
service/resource-manipulation/modules/resourceContainer/bundle-java-api/src/main/java/org/iotivity/resourcecontainer/bundle/api/ResourceConfig.java [new file with mode: 0644]
service/resource-manipulation/modules/resourceContainer/examples/HueJavaSampleBundle/hue/pom.xml [new file with mode: 0644]
service/resource-manipulation/modules/resourceContainer/examples/HueJavaSampleBundle/hue/src/main/java/org/iotivity/bundle/hue/HueBundleActivator.java [new file with mode: 0644]
service/resource-manipulation/modules/resourceContainer/examples/HueJavaSampleBundle/hue/src/main/java/org/iotivity/bundle/hue/HueConnector.java [new file with mode: 0644]
service/resource-manipulation/modules/resourceContainer/examples/HueJavaSampleBundle/hue/src/main/java/org/iotivity/bundle/hue/HueLightResource.java [new file with mode: 0644]
service/resource-manipulation/modules/resourceContainer/examples/HueSampleBundle/include/HueLight.h
service/resource-manipulation/modules/resourceContainer/examples/HueSampleBundle/include/HueSampleBundleActivator.h
service/resource-manipulation/modules/resourceContainer/examples/HueSampleBundle/src/HueLight.cpp
service/resource-manipulation/modules/resourceContainer/examples/HueSampleBundle/src/HueSampleBundleActivator.cpp
service/resource-manipulation/modules/resourceContainer/examples/ResourceContainerConfig.xml
service/resource-manipulation/modules/resourceContainer/examples/SampleBundle/include/DiscomfortIndexSensor.h
service/resource-manipulation/modules/resourceContainer/examples/SampleBundle/include/DiscomfortIndexSensorResource.h
service/resource-manipulation/modules/resourceContainer/examples/SampleBundle/include/SampleBundle.h
service/resource-manipulation/modules/resourceContainer/examples/SampleBundle/src/DiscomfortIndexSensor.cpp
service/resource-manipulation/modules/resourceContainer/examples/SampleBundle/src/DiscomfortIndexSensorResource.cpp
service/resource-manipulation/modules/resourceContainer/examples/SampleBundle/src/SampleBundle.cpp
service/resource-manipulation/modules/resourceContainer/include/BundleInfo.h
service/resource-manipulation/modules/resourceContainer/include/Configuration.h [deleted file]
service/resource-manipulation/modules/resourceContainer/include/ResourceContainer.h
service/resource-manipulation/modules/resourceContainer/include/internal/BundleInfoInternal.h [moved from service/resource-manipulation/modules/resourceContainer/include/BundleInfoInternal.h with 74% similarity]
service/resource-manipulation/modules/resourceContainer/include/internal/Configuration.h [new file with mode: 0644]
service/resource-manipulation/modules/resourceContainer/include/internal/JavaBundleResource.h [new file with mode: 0644]
service/resource-manipulation/modules/resourceContainer/include/internal/ResourceContainerImpl.h [moved from service/resource-manipulation/modules/resourceContainer/include/ResourceContainerImpl.h with 61% similarity]
service/resource-manipulation/modules/resourceContainer/include/internal/org_iotivity_resourcecontainer_bundle_api_BaseActivator.h [new file with mode: 0644]
service/resource-manipulation/modules/resourceContainer/src/BaseActivator.cpp [new file with mode: 0644]
service/resource-manipulation/modules/resourceContainer/src/BundleInfoInternal.cpp
service/resource-manipulation/modules/resourceContainer/src/BundleResource.cpp
service/resource-manipulation/modules/resourceContainer/src/Configuration.cpp
service/resource-manipulation/modules/resourceContainer/src/ContainerTest.cpp
service/resource-manipulation/modules/resourceContainer/src/JavaBundleResource.cpp [new file with mode: 0644]
service/resource-manipulation/modules/resourceContainer/src/ResourceContainerImpl.cpp

index 1441c73..6bd2641 100644 (file)
@@ -36,10 +36,14 @@ target_os = env.get('TARGET_OS')
 resource_container_env.AppendUnique(
        CPPPATH = [
                env.get('SRC_DIR')+'/extlibs', 
-               'include', 
+               'include',
+               'include/internal',
+               'bundle-api/include',
                'src',
                '../serverBuilder/include',
-               '../common/primitiveResource/include'
+               '../common/primitiveResource/include',
+               '/usr/lib/jvm/java-7-openjdk-i386/include',
+               '/usr/lib/jvm/java-7-openjdk-i386/include/linux'
        ])
 
 if target_os not in ['windows', 'winrt']:
@@ -51,9 +55,10 @@ if target_os == 'android':
     resource_container_env.AppendUnique(CXXFLAGS = ['-frtti', '-fexceptions'])
     resource_container_env.PrependUnique(LIBS = ['gnustl_shared', 'compatibility', 'log'])
        
-#resource_container_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
+resource_container_env.AppendUnique(LIBPATH = ['/usr/lib/jvm/java-7-openjdk-i386/jre/lib/i386/server/'])
 resource_container_env.PrependUnique(LIBS = ['server_builder', 'service_common', 'oc','octbstack', 'oc_logger', 'oc_logger_core', 'connectivity_abstraction'])
-resource_container_env.AppendUnique(LIBS = ['dl'])
+resource_container_env.AppendUnique(LIBS = ['dl', 'jvm'])      
+
 
 ######################################################################
 # Source files and Targets
@@ -64,19 +69,9 @@ res_container_shared = resource_container_env.SharedLibrary('ResContainerLib', r
 
 resource_container_env.InstallTarget([res_container_static,res_container_shared], 'libResContainer')
 
-#resource_container_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
-
-#containertestapp = resource_container_env.Program('ContainerTest', res_container_src)
-#Alias("containertest", containertestapp)
-#env.AppendTarget('containertest')
-
-#Go to build sample apps
-#SConscript('resource-container/examples/SHPBundle/SConscript')
-
 ######################################################################
 # build Sample Resource Bundle
 ######################################################################
-#SConscript('resource-container/examples/SampleBundle/SConscript')
 
 sample_resource_bundle_env = resource_container_env.Clone()
 sample_resource_bundle_env.AppendUnique(CCFLAGS = ['-fPIC'])
@@ -105,9 +100,9 @@ hue_resource_bundle_env.AppendUnique(CPPPATH = [
                HUE_RESOURCE_BUNDLE_DIR + 'include',
                'include/'
                ])              
-               
+       
 hue_resource_bundle_env.PrependUnique(LIBS = ['curl'])
-               
+       
 hue_resource_bundle_src = [ Glob(HUE_RESOURCE_BUNDLE_DIR + 'src/*.cpp'), Glob('src/*.cpp')]
 
 HueBundle = hue_resource_bundle_env.SharedLibrary('HueBundle', hue_resource_bundle_src)
@@ -118,7 +113,7 @@ hue_resource_bundle_env.InstallTarget(HueBundle, 'libHueBundle')
 # Build Container Test
 ######################################################################
 containertest_env = resource_container_env.Clone();
-#containertest_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
+containertest_env.AppendUnique(LINKFLAGS=["-rdynamic"])
 
 # Copy test configuration
 Command("examples/ResourceContainerConfig.xml","examples/ResourceContainerConfig.xml", Copy("$TARGET", "$SOURCE"))
 #ifndef BUNDLERESOURCE_H_
 #define BUNDLERESOURCE_H_
 
+#include <list>
+#include <string>
 #include <map>
 #include <vector>
-#include <string>
+
+#include "NotificationReceiver.h"
 
 using namespace std;
 
@@ -33,19 +36,25 @@ namespace OIC
     {
         class BundleResource
         {
-        public:
-            BundleResource();
-            virtual ~BundleResource();
-
-            // TODO use type variant mechanism
-            virtual void getAttribute(string attributeName) = 0;
-            virtual void setAttribute(string attributeName, string value) = 0;
-            virtual void initAttributes() = 0;
-
-        public:
-            string m_name, m_uri, m_resourceType, m_address;
-            map< string, vector< map< string, string > > > m_mapResourceProperty;
-            map< string, string > m_mapAttributes;
+            public:
+                BundleResource();
+                virtual ~BundleResource();
+
+                // TODO use type variant mechanism
+                virtual string getAttribute(string attributeName);
+                virtual void setAttribute(string attributeName, string value);
+                std::list<string> getAttributeNames();
+                virtual void initAttributes() = 0;
+
+                void registerObserver(NotificationReceiver *pNotiReceiver);
+
+            public:
+                string m_name, m_uri, m_resourceType, m_address;
+                map< string, vector< map< string, string > > > m_mapResourceProperty;
+
+            private:
+                map< string, string > m_mapAttributes;
+                NotificationReceiver *m_pNotiReceiver;
         };
     }
 }
 //
 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 
-#ifndef SOFTSENSORRESOURCE_H_
-#define SOFTSENSORRESOURCE_H_
+#ifndef NOTIFICATIONRECEIVER_H_
+#define NOTIFICATIONRECEIVER_H_
 
-#include "BundleResource.h"
+#include <string>
 
 namespace OIC
 {
     namespace Service
     {
-        class SoftSensorResource: public BundleResource
+        class NotificationReceiver
         {
-        public:
-            struct SensorData
-            {
-                string sensorName;
-                vector< map< string, string > > data;
-            };
+            public:
+                NotificationReceiver() {};
+                ~NotificationReceiver() {};
 
-            SoftSensorResource();
-            virtual ~SoftSensorResource();
-
-            virtual void setInputAttributes(vector< SensorData > inputs) = 0;
-
-            int inputCount;
-            map< string, SensorData > m_mapStoredInputData;
-            SensorData m_outputs;
+                virtual void onNotificationReceived(std::string strResourceUri) = 0;
         };
     }
 }
@@ -34,7 +34,7 @@ namespace OIC
         public:
             ProtocolBridgeResource();
             virtual ~ProtocolBridgeResource();
-            virtual void getAttribute(string attributeName) = 0;
+            virtual string getAttribute(string attributeName) = 0;
             virtual void setAttribute(string attributeName, string value) = 0;
         };
     }
@@ -28,6 +28,7 @@
 #include "ResourceContainer.h"
 #include "BundleInfo.h"
 #include "Configuration.h"
+#include "NotificationReceiver.h"
 #include "BundleResource.h"
 
 using namespace OIC::Service;
@@ -36,20 +37,18 @@ namespace OIC
 {
     namespace Service
     {
-        class ResourceContainerBundleAPI: public Configuration
+        class ResourceContainerBundleAPI: public Configuration, public NotificationReceiver
         {
-        public:
-            typedef std::map< std::string, std::string > configInfo;
-            ResourceContainerBundleAPI();
-            virtual ~ResourceContainerBundleAPI();
-            virtual void registerResource(BundleResource *resource) = 0;
-            virtual void unregisterResource(BundleResource *resource) = 0;
-            virtual void getCommonConfiguration(configInfo *configOutput) = 0;
-            virtual void getBundleConfiguration(std::string bundleId, configInfo *configOutput) = 0;
-            virtual void getResourceConfiguration(std::string bundleId,
-                    std::vector< resourceInfo > *configOutput) = 0;
+            public:
+                ResourceContainerBundleAPI();
+                virtual ~ResourceContainerBundleAPI();
+                virtual void registerResource(BundleResource *resource) = 0;
+                virtual void unregisterResource(BundleResource *resource) = 0;
+                virtual void getBundleConfiguration(std::string bundleId, configInfo *configOutput) = 0;
+                virtual void getResourceConfiguration(std::string bundleId,
+                                                      std::vector< resourceInfo > *configOutput) = 0;
 
-            static ResourceContainerBundleAPI *getInstance();
+                static ResourceContainerBundleAPI *getInstance();
         };
     }
 }
diff --git a/service/resource-manipulation/modules/resourceContainer/bundle-api/include/SoftSensorResource.h b/service/resource-manipulation/modules/resourceContainer/bundle-api/include/SoftSensorResource.h
new file mode 100644 (file)
index 0000000..277529e
--- /dev/null
@@ -0,0 +1,55 @@
+//******************************************************************
+//
+// Copyright 2015 Samsung Electronics All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+#ifndef SOFTSENSORRESOURCE_H_
+#define SOFTSENSORRESOURCE_H_
+
+#include "BundleResource.h"
+
+namespace OIC
+{
+    namespace Service
+    {
+        class SoftSensorResource: public BundleResource
+        {
+            public:
+                struct SensorData
+                {
+                    string sensorName;
+                    vector< map< string, string > > data;
+                };
+
+                SoftSensorResource();
+                virtual ~SoftSensorResource();
+
+                virtual string getAttribute(string attributeName) = 0;
+                virtual void setAttribute(string attributeName, string value) = 0;
+
+                virtual void setInputAttribute(SensorData inputs) = 0;
+
+                int inputCount;
+                vector<string> m_vecInputAttributes;
+                map< string, SensorData > m_mapStoredInputData;
+                SensorData m_outputs;
+        };
+    }
+}
+
+#endif
diff --git a/service/resource-manipulation/modules/resourceContainer/bundle-java-api/pom.xml b/service/resource-manipulation/modules/resourceContainer/bundle-java-api/pom.xml
new file mode 100644 (file)
index 0000000..4150b61
--- /dev/null
@@ -0,0 +1,64 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.iotivity.resourcecontainer</groupId>
+  <artifactId>bundle-api</artifactId>
+  <packaging>jar</packaging>
+  <version>1.0</version>
+  <name>resource-container-api</name>
+  <url>http://maven.apache.org</url>
+  <dependencies>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>3.8.1</version>
+      <scope>test</scope>
+    </dependency>    
+    <dependency>
+      <groupId>org.apache.maven.plugins</groupId>
+      <artifactId>maven-shade-plugin</artifactId>
+      <version>2.4</version>
+      <type>maven-plugin</type>
+    </dependency>
+  </dependencies>
+  <build>
+       <pluginManagement>
+       <plugins>
+               <plugin>
+                       <groupId>org.apache.maven.plugins</groupId>
+                       <artifactId>maven-assmembly-plugin</artifactId>
+                       <version>2.5.5</version>
+               </plugin>
+       </plugins>            
+      </pluginManagement>
+     <plugins>      
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <version>3.3</version>
+        <configuration>
+          <source>1.6</source>
+          <target>1.6</target>
+        </configuration>
+      </plugin>
+    
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-assembly-plugin</artifactId>
+        <version>2.5.5</version>  
+        <configuration>
+               <descriptorRefs>
+                       <descriptorRef>jar-with-dependencies</descriptorRef>
+               </descriptorRefs>
+        </configuration>      
+      </plugin> 
+    </plugins>
+  </build>
+  <repositories>
+       <repository>
+               <id>repo1</id>
+               <name>Repo1</name>
+               <url>http://repo1.maven.rog</url>               
+       </repository>
+  </repositories>
+</project>
diff --git a/service/resource-manipulation/modules/resourceContainer/bundle-java-api/src/main/java/org/iotivity/resourcecontainer/bundle/api/BaseActivator.java b/service/resource-manipulation/modules/resourceContainer/bundle-java-api/src/main/java/org/iotivity/resourcecontainer/bundle/api/BaseActivator.java
new file mode 100644 (file)
index 0000000..6b51830
--- /dev/null
@@ -0,0 +1,62 @@
+package org.iotivity.resourcecontainer.bundle.api;
+
+import java.util.List;
+import java.util.Vector;
+
+public class BaseActivator implements BundleActivator
+{
+       private String bundleId;
+       
+       public BaseActivator(String bundleId){  
+               this.bundleId = bundleId;
+       }
+       
+       static{
+               try{                    
+                       System.loadLibrary("ResContainerLib");          
+               }
+               catch(Exception e){
+                       e.printStackTrace();
+               }
+       }
+               
+    public void activateBundle(){
+       
+    }
+    
+    public void deactivateBundle(){
+       
+    }  
+    
+    public void registerResource(BundleResource resource){             
+       registerJavaResource(resource, resource.getAttributeKeys(), bundleId, resource.getURI(), resource.getResourceType(), resource.getName());       
+    }
+    
+    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;
+    }
+    
+    public void unregisterResource(BundleResource resource){
+       
+    }
+    
+    public native void registerJavaResource(BundleResource resource, String[] attributes, String bundleId, String uri, String resourceType, String name);
+    
+    public native void unregisterJavaResource(BundleResource resource);
+    
+    public native int getNumberOfConfiguredResources(String bundleId);
+    
+    public native String[] getConfiguredResourceParams(String bundleId, int resId); 
+        
+}
+
diff --git a/service/resource-manipulation/modules/resourceContainer/bundle-java-api/src/main/java/org/iotivity/resourcecontainer/bundle/api/BundleActivator.java b/service/resource-manipulation/modules/resourceContainer/bundle-java-api/src/main/java/org/iotivity/resourcecontainer/bundle/api/BundleActivator.java
new file mode 100644 (file)
index 0000000..3984892
--- /dev/null
@@ -0,0 +1,13 @@
+package org.iotivity.resourcecontainer.bundle.api;
+
+
+import java.util.List;
+
+public interface BundleActivator 
+{
+    public void activateBundle();
+    public void deactivateBundle();
+    public void registerResource(BundleResource resource);
+    public void unregisterResource(BundleResource resource);
+    public List<ResourceConfig> getConfiguredBundleResources();
+}
diff --git a/service/resource-manipulation/modules/resourceContainer/bundle-java-api/src/main/java/org/iotivity/resourcecontainer/bundle/api/BundleResource.java b/service/resource-manipulation/modules/resourceContainer/bundle-java-api/src/main/java/org/iotivity/resourcecontainer/bundle/api/BundleResource.java
new file mode 100644 (file)
index 0000000..30d2640
--- /dev/null
@@ -0,0 +1,53 @@
+package org.iotivity.resourcecontainer.bundle.api;
+
+
+import java.util.HashMap;
+import java.util.Set;
+
+public abstract class BundleResource 
+{      
+       protected String m_name, m_uri, m_resourceType, m_address;
+       
+       protected HashMap<String, String> m_attributes;         
+       
+       protected abstract void initAttributes();
+       public abstract void setAttribute(String key, String value);
+       public abstract String getAttribute(String key);
+       public String[] getAttributeKeys(){
+               Set<String> keys = m_attributes.keySet();
+               return keys.toArray(new String[keys.size()]);           
+       }
+       
+       public void setURI(String uri){
+               this.m_uri = uri;
+       }
+       
+       public String getURI(){
+               return m_uri;
+       }
+       
+       public void setResourceType(String resourceType){
+               this.m_resourceType = resourceType;
+       }
+       
+       public String getResourceType(){
+               return m_resourceType;
+       }
+       
+       public void setAddress(String address){
+               this.m_address = address;
+       }
+       
+       public String getAddress(){
+               return m_address;
+       }
+       
+       public void setName(String name){
+               this.m_name = name;
+       }
+       
+       public String getName(){
+               return m_name;
+       }
+
+}
diff --git a/service/resource-manipulation/modules/resourceContainer/bundle-java-api/src/main/java/org/iotivity/resourcecontainer/bundle/api/ProtocolBridgeConnector.java b/service/resource-manipulation/modules/resourceContainer/bundle-java-api/src/main/java/org/iotivity/resourcecontainer/bundle/api/ProtocolBridgeConnector.java
new file mode 100644 (file)
index 0000000..c0e5007
--- /dev/null
@@ -0,0 +1,7 @@
+package org.iotivity.resourcecontainer.bundle.api;
+
+
+public interface ProtocolBridgeConnector {
+       public void connect();
+    public void disconnect();
+}
diff --git a/service/resource-manipulation/modules/resourceContainer/bundle-java-api/src/main/java/org/iotivity/resourcecontainer/bundle/api/ResourceConfig.java b/service/resource-manipulation/modules/resourceContainer/bundle-java-api/src/main/java/org/iotivity/resourcecontainer/bundle/api/ResourceConfig.java
new file mode 100644 (file)
index 0000000..3379102
--- /dev/null
@@ -0,0 +1,58 @@
+package org.iotivity.resourcecontainer.bundle.api;
+
+
+public class ResourceConfig {
+       private String m_name, m_uri, m_resourceType, m_address;
+       
+       public ResourceConfig(){
+               
+       }
+       
+       public ResourceConfig(String[] params){
+               m_name = params[0];
+               m_uri = params[1];
+               m_resourceType = params[2];
+               m_address = params[3];
+       }
+
+       public String getM_name() {
+               return m_name;
+       }
+
+       public void setM_name(String m_name) {
+               this.m_name = m_name;
+       }
+
+       public String getM_uri() {
+               return m_uri;
+       }
+
+       public void setM_uri(String m_uri) {
+               this.m_uri = m_uri;
+       }
+
+       public String getM_resourceType() {
+               return m_resourceType;
+       }
+
+       public void setM_resourceType(String m_resourceType) {
+               this.m_resourceType = m_resourceType;
+       }
+
+       public String getM_address() {
+               return m_address;
+       }
+
+       public void setM_address(String m_address) {
+               this.m_address = m_address;
+       }
+
+       @Override
+       public String toString() {
+               return "ResourceConfig [m_name=" + m_name + ", m_uri=" + m_uri
+                               + ", m_resourceType=" + m_resourceType + ", m_address="
+                               + m_address + "]";
+       }
+       
+       
+}
diff --git a/service/resource-manipulation/modules/resourceContainer/examples/HueJavaSampleBundle/hue/pom.xml b/service/resource-manipulation/modules/resourceContainer/examples/HueJavaSampleBundle/hue/pom.xml
new file mode 100644 (file)
index 0000000..d3e9902
--- /dev/null
@@ -0,0 +1,76 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.iotivity.bundles</groupId>
+  <artifactId>hue</artifactId>
+  <packaging>jar</packaging>
+  <version>1.0-SNAPSHOT</version>
+  <name>hue</name>
+  <url>http://maven.apache.org</url>
+  <dependencies>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>3.8.1</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+               <groupId>org.apache.httpcomponents</groupId>
+               <artifactId>httpclient</artifactId>
+               <version>4.5</version>
+               <scope>compile</scope>
+    </dependency>
+    <dependency>
+               <groupId>org.iotivity.resourcecontainer</groupId>
+               <artifactId>bundle-api</artifactId>
+               <version>1.0</version>
+               <scope>compile</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven.plugins</groupId>
+      <artifactId>maven-shade-plugin</artifactId>
+      <version>2.4</version>
+      <type>maven-plugin</type>
+    </dependency>
+  </dependencies>
+  <build>
+       <pluginManagement>
+       <plugins>
+               <plugin>
+                       <groupId>org.apache.maven.plugins</groupId>
+                       <artifactId>maven-assmembly-plugin</artifactId>
+                       <version>2.5.5</version>
+               </plugin>
+       </plugins>            
+      </pluginManagement>
+     <plugins>      
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <version>3.3</version>
+        <configuration>
+          <source>1.6</source>
+          <target>1.6</target>
+        </configuration>
+      </plugin>
+    
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-assembly-plugin</artifactId>
+        <version>2.5.5</version>  
+        <configuration>
+               <descriptorRefs>
+                       <descriptorRef>jar-with-dependencies</descriptorRef>
+               </descriptorRefs>
+        </configuration>      
+      </plugin> 
+    </plugins>
+  </build>
+  <repositories>
+       <repository>
+               <id>repo1</id>
+               <name>Repo1</name>
+               <url>http://repo1.maven.rog</url>               
+       </repository>
+  </repositories>
+</project>
diff --git a/service/resource-manipulation/modules/resourceContainer/examples/HueJavaSampleBundle/hue/src/main/java/org/iotivity/bundle/hue/HueBundleActivator.java b/service/resource-manipulation/modules/resourceContainer/examples/HueJavaSampleBundle/hue/src/main/java/org/iotivity/bundle/hue/HueBundleActivator.java
new file mode 100644 (file)
index 0000000..31b48f5
--- /dev/null
@@ -0,0 +1,36 @@
+package org.iotivity.bundle.hue;
+
+import java.util.List;
+
+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.getM_name(), config.getM_uri(), config.getM_resourceType(), config.getM_address());          
+               registerResource(hueLightResource);     
+       }       
+    }
+    
+    public void deactivateBundle(){
+       System.out.println("Deactivate bundle called.");
+    }     
+    
+    // test call
+    public static void main(String[] args){
+       HueBundleActivator activator = new HueBundleActivator("oic.hue.bundle");        
+    }
+}
diff --git a/service/resource-manipulation/modules/resourceContainer/examples/HueJavaSampleBundle/hue/src/main/java/org/iotivity/bundle/hue/HueConnector.java b/service/resource-manipulation/modules/resourceContainer/examples/HueJavaSampleBundle/hue/src/main/java/org/iotivity/bundle/hue/HueConnector.java
new file mode 100644 (file)
index 0000000..9826294
--- /dev/null
@@ -0,0 +1,64 @@
+package org.iotivity.bundle.hue;
+
+import java.io.IOException;
+
+import org.apache.http.HttpEntity;
+import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.entity.ContentType;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.util.EntityUtils;
+import org.iotivity.resourcecontainer.bundle.api.ProtocolBridgeConnector;
+
+public class HueConnector implements ProtocolBridgeConnector{
+       public void connect(){
+               
+       }
+       
+       public void disconnect(){
+               
+       }
+       
+       public void transmit(String target, String payload){                            
+               try {
+                       CloseableHttpClient httpclient = HttpClients.createDefault();
+                       HttpPost httpPost = new HttpPost(target);
+                       //httpPost.setHeader("content-type","application/json");
+                       StringEntity stringEntity = new StringEntity(payload, ContentType.create("application/json", "UTF-8"));
+                       httpPost.setEntity(stringEntity);
+                       
+                       CloseableHttpResponse response1;
+                       response1 = httpclient.execute(httpPost);
+                       // The underlying HTTP connection is still held by the response object
+                       // to allow the response content to be streamed directly from the network socket.
+                       // In order to ensure correct deallocation of system resources
+                       // the user MUST call CloseableHttpResponse#close() from a finally clause.
+                       // Please note that if response content is not fully consumed the underlying
+                       // connection cannot be safely re-used and will be shut down and discarded
+                       // by the connection manager. 
+                       try {                      
+                           HttpEntity entity1 = response1.getEntity();
+                           // do something useful with the response body
+                           // and ensure it is fully consumed
+                           EntityUtils.consume(entity1);
+                       } finally {
+                           response1.close();
+                       }               
+                       
+               } catch (ClientProtocolException e) {
+                       // TODO Auto-generated catch block
+                       e.printStackTrace();
+               } catch (IOException e) {
+                       // TODO Auto-generated catch block
+                       e.printStackTrace();
+               }       
+       }
+       
+       public String read(String target){
+               return "";
+       }
+
+}
diff --git a/service/resource-manipulation/modules/resourceContainer/examples/HueJavaSampleBundle/hue/src/main/java/org/iotivity/bundle/hue/HueLightResource.java b/service/resource-manipulation/modules/resourceContainer/examples/HueJavaSampleBundle/hue/src/main/java/org/iotivity/bundle/hue/HueLightResource.java
new file mode 100644 (file)
index 0000000..15c4af1
--- /dev/null
@@ -0,0 +1,70 @@
+package org.iotivity.bundle.hue;
+
+import java.util.HashMap;
+
+import org.iotivity.resourcecontainer.bundle.api.BundleResource;
+
+/**
+ * This class maps a Philips Hue light to OIC light resource
+ * @author iotivity
+ */
+public class HueLightResource extends BundleResource 
+{      
+       private HueConnector m_hueConnector;
+       
+       public HueLightResource(){
+               initAttributes();
+               m_resourceType = "oic.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 void setAttribute(String key, String value){
+               System.out.println("Set attribute called - key: " + key + ", value: " + value + " transmitting now.");
+               
+               if("on-off".equals(value)){
+                       m_hueConnector.transmit(m_address + "/state", "{\"on\":" + value + "}");
+           }
+
+           if("dim".equals(value)){           
+               m_hueConnector.transmit(m_address + "/state", "{\"bri\":" + value + "}");
+           }
+
+           if("color".equals(value)){
+               m_hueConnector.transmit(m_address + "/state", "{\"hue\":" + value + "}");               
+           }   
+           m_attributes.put(key, value);
+       }
+       
+       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 "";
+       }
+
+       @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 34269b2..675972e 100644 (file)
@@ -37,7 +37,7 @@ namespace OIC
             HueLight();
             HueLight(HueConnector* connector, std::string address);
             virtual ~HueLight();
-            void getAttribute(string attributeName);
+            string getAttribute(string attributeName);
             void setAttribute(string attributeName, string value);
             virtual void initAttributes();
         private:
index 3fff8eb..7c3a3e3 100644 (file)
@@ -42,7 +42,7 @@ namespace OIC
                     std::string bundleId);
             void deactivateBundle();
 
-            void createResource(Configuration::resourceInfo);
+            void createResource(resourceInfo);
             void destroyResource(BundleResource *);
 
             std::string m_bundleId;
index 619852d..8fc8379 100644 (file)
@@ -32,27 +32,28 @@ HueLight::HueLight(HueConnector* connector, std::string address){
     m_address = address;
     m_connector = connector;
     initAttributes();
-    std::cout << "Number of Attributes: " << m_mapAttributes.size() << "" << endl;
-
 }
 
 HueLight::~HueLight(){
 
 }
 
-void HueLight::getAttribute(string attributeName){
+string HueLight::getAttribute(string attributeName){
 
 }
 
 void HueLight::initAttributes(){
-    m_mapAttributes.insert(std::pair<string, string>("on-off", "false"));
+    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"));
+    m_mapAttributes.insert(std::pair<string, string>("color", "0"));*/
 }
 
 void HueLight::setAttribute(string attributeName, string value){
     cout << "HueLight::setAttribute setting " << attributeName << " to " << value << std::endl;
-    this->m_mapAttributes[attributeName] = value;
+
 
     if(attributeName == "on-off"){
         m_connector->transmit(this->m_address + "/state", "{\"on\":" + value + "}");
index 120cdb0..e871175 100644 (file)
@@ -45,11 +45,11 @@ void HueSampleBundleActivator::activateBundle(ResourceContainerBundleAPI *resour
     m_bundleId = bundleId;
     m_connector = new HueConnector();
 
-    vector<Configuration::resourceInfo> resourceConfig;
+    vector<resourceInfo> resourceConfig;
 
     resourceContainer->getResourceConfiguration(m_bundleId, &resourceConfig);
 
-    for (vector<Configuration::resourceInfo>::iterator itor = resourceConfig.begin();
+    for (vector<resourceInfo>::iterator itor = resourceConfig.begin();
          itor != resourceConfig.end(); itor++)
     {
         createResource(*itor);
@@ -68,7 +68,7 @@ void HueSampleBundleActivator::deactivateBundle()
 }
 
 
-void HueSampleBundleActivator::createResource(Configuration::resourceInfo resourceInfo)
+void HueSampleBundleActivator::createResource(resourceInfo resourceInfo)
 {
     std::cout << "HueSampleBundle::createResource called" << std::endl;
 
index 4bceb0f..7304ee9 100644 (file)
             </resourceInfo>       
         </resources>
     </bundle>
+    <bundle>
+        <id>oic.bundle.hueJavaSample</id>
+        <path>/home/iotivity/development/iotivity-resource-manipulation/service/resource-manipulation/modules/resourceContainer/examples/HueJavaSampleBundle/hue/target/hue-1.0-SNAPSHOT-jar-with-dependencies.jar</path>
+        <activator>org.iotivity.bundle.hue.HueBundleActivator</activator>
+        <version>1.0.0</version>
+        <resources>
+            <resourceInfo>
+                <name>light</name>
+                               <resourceType>oic.light.control</resourceType>
+                <address>http://192.168.0.2/api/newdeveloper/lights/1</address>
+            </resourceInfo>       
+        </resources>
+    </bundle>
 </container>
index 87d830e..ca45b38 100644 (file)
@@ -55,7 +55,7 @@ namespace DiscomfortIndexSensorName
     {
         private:
 
-            static physicalInput s_PHYSICAL_SOFTSENSORs[PHYSICAL_EA];
+            physicalInput s_PHYSICAL_SOFTSENSORs[PHYSICAL_EA];
 
             class InValue
             {
@@ -70,7 +70,7 @@ namespace DiscomfortIndexSensorName
             InValue m_result;
 
         public:
-            DiscomfortIndexSensor();
+            DiscomfortIndexSensor(vector <string> inputs);
 
             int runLogic(std::vector< SoftSensorResource::SensorData > &sensorData);
             DIResult getInput(std::vector< SoftSensorResource::SensorData > &contextDataList,
index 216b954..016cfe1 100644 (file)
@@ -33,13 +33,14 @@ class DiscomfortIndexSensorResource : public SoftSensorResource
 {
     public:
         DiscomfortIndexSensorResource();
+        DiscomfortIndexSensorResource(vector<string> inputAttributes);
         ~DiscomfortIndexSensorResource();
 
-        void getAttribute(string attributeName);
+        string getAttribute(string attributeName);
         void setAttribute(string attributeName, string value);
         virtual void initAttributes();
 
-        void setInputAttributes(vector < SensorData > inputs);
+        void setInputAttribute(SensorData input);
 
     private:
         DiscomfortIndexSensor *m_pDiscomfortIndexSensor;
index 8a1aad4..6ae3507 100644 (file)
@@ -39,7 +39,7 @@ class SampleBundle: public BundleActivator
         void activateBundle(ResourceContainerBundleAPI *resourceContainer, std::string bundleId);
         void deactivateBundle();
 
-        void createResource(Configuration::resourceInfo);
+        void createResource(resourceInfo);
         void destroyResource(BundleResource *);
 
         std::string m_bundleId;
index ac3fe2f..03e1a59 100644 (file)
@@ -35,21 +35,22 @@ using namespace DiscomfortIndexSensorName;
 char *inputName[2] =
 { (char *)"temperature", (char *)"humidity" };
 
-physicalInput DiscomfortIndexSensor::s_PHYSICAL_SOFTSENSORs[PHYSICAL_EA] =
-{
-    { (char *)"Thing_TempHumSensor", 2, (void *) &inputName },
-    { (char *)"Thing_TempHumSensor1", 2, (void *) &inputName }
-};
-
-DiscomfortIndexSensor::DiscomfortIndexSensor()
+DiscomfortIndexSensor::DiscomfortIndexSensor(vector <string> inputs)
 {
     m_result.m_timestamp = "";
     m_result.m_humidity = "";
     m_result.m_temperature = "";
     m_result.m_discomfortIndex = "";
+
+    for (int i = 0; i < PHYSICAL_EA; i++)
+    {
+        s_PHYSICAL_SOFTSENSORs[i].m_thingName = (char *) inputs.at(i).c_str();
+        s_PHYSICAL_SOFTSENSORs[i].m_inputNum = PHYSICAL_EA;
+        s_PHYSICAL_SOFTSENSORs[i].m_pInputStruct = (void *) &inputName;
+    }
 }
 
-int DiscomfortIndexSensor::runLogic(std::vector< OIC::Service::SoftSensorResource::SensorData > &sensorData)
+int DiscomfortIndexSensor::runLogic(std::vector< SoftSensorResource::SensorData > &sensorData)
 {
     std::cout << "[DiscomfortIndexSensor] DiscomfortIndexSensor::" << __func__ << " is called."
               << std::endl;
@@ -75,7 +76,7 @@ int DiscomfortIndexSensor::runLogic(std::vector< OIC::Service::SoftSensorResourc
 /**
  * Get Input data (temperature, humidity) using resource Client of Iotivity base.
  */
-DIResult DiscomfortIndexSensor::getInput(std::vector< OIC::Service::SoftSensorResource::SensorData >
+DIResult DiscomfortIndexSensor::getInput(std::vector< SoftSensorResource::SensorData >
         &sensorData, InValue *data)
 {
     int result_flag = 0;
@@ -208,10 +209,10 @@ DIResult DiscomfortIndexSensor::makeDiscomfortIndex(InValue *data)
     return SUCCESS;
 }
 
-OIC::Service::SoftSensorResource::SensorData DiscomfortIndexSensor::setOutput(int property_count,
+SoftSensorResource::SensorData DiscomfortIndexSensor::setOutput(int property_count,
         InValue *data)
 {
-    OIC::Service::SoftSensorResource::SensorData out;
+    SoftSensorResource::SensorData out;
 
     std::map < std::string, std::string > output_property;
 
index 1a791a9..9da4766 100644 (file)
 //
 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 
+#include <algorithm>
+
 #include "DiscomfortIndexSensorResource.h"
 
 DiscomfortIndexSensorResource::DiscomfortIndexSensorResource()
 {
-    m_pDiscomfortIndexSensor = new DiscomfortIndexSensor();
+}
+
+DiscomfortIndexSensorResource::DiscomfortIndexSensorResource(vector<string> inputAttributes)
+{
+    m_pDiscomfortIndexSensor = new DiscomfortIndexSensor(inputAttributes);
+    m_vecInputAttributes = inputAttributes;
+    std::cout << "Init attributes" << endl;
     initAttributes();
+    std::cout << "Init attributes finished" << endl;
 }
 
 DiscomfortIndexSensorResource::~DiscomfortIndexSensorResource()
@@ -33,12 +42,13 @@ DiscomfortIndexSensorResource::~DiscomfortIndexSensorResource()
 
 void DiscomfortIndexSensorResource::initAttributes()
 {
-    m_mapAttributes.insert(std::pair<string, string>("temperature", "23"));
-    m_mapAttributes.insert(std::pair<string, string>("humidity", "40"));
-    m_mapAttributes.insert(std::pair<string, string>("discomfortIndex", "5"));
+
+    BundleResource::setAttribute("temperature", "23");
+    BundleResource::setAttribute("humidity", "40");
+    BundleResource::setAttribute("discomfortIndex", "5");
 }
 
-void DiscomfortIndexSensorResource::getAttribute(string attributeName)
+string DiscomfortIndexSensorResource::getAttribute(string attributeName)
 {
     cout << "DiscomfortIndexSensorResource::getAttribute called !!" << endl;
 }
@@ -46,11 +56,40 @@ void DiscomfortIndexSensorResource::getAttribute(string attributeName)
 void DiscomfortIndexSensorResource::setAttribute(string attributeName, string value)
 {
     cout << "DiscomfortIndexSensorResource::setAttribute called !!" << endl;
-
-    m_mapAttributes[attributeName] = value;
 }
 
-void DiscomfortIndexSensorResource::setInputAttributes(vector < SensorData > inputs)
+void DiscomfortIndexSensorResource::setInputAttribute(SensorData input)
 {
-    m_pDiscomfortIndexSensor->runLogic(inputs);
+    vector<string>::iterator itor = std::find(m_vecInputAttributes.begin(), m_vecInputAttributes.end(),
+                                    input.sensorName);
+    std::vector<SensorData> inData;
+
+    if (itor != m_vecInputAttributes.end())
+    {
+        m_mapStoredInputData[input.sensorName] = input;
+
+        if (inputCount == m_mapStoredInputData.size())
+        {
+            for (map< string, SensorData >::iterator mapItor = m_mapStoredInputData.begin();
+                 mapItor != m_mapStoredInputData.end(); mapItor++)
+            {
+                inData.push_back(mapItor->second);
+            }
+
+            m_pDiscomfortIndexSensor->runLogic(inData);
+            m_outputs = m_pDiscomfortIndexSensor->m_output;
+
+            for (int i = 0; i < m_outputs.data.size(); i++)
+            {
+                if (!m_outputs.data.at(i)["name"].compare("temperature"))
+                    BundleResource::setAttribute("temperature",m_outputs.data.at(i)["value"]);
+
+                else if (!m_outputs.data.at(i)["name"].compare("humidity"))
+                    BundleResource::setAttribute("humidity",m_outputs.data.at(i)["value"]);
+
+                else if (!m_outputs.data.at(i)["name"].compare("discomfortIndex"))
+                    BundleResource::setAttribute("discomfortIndex",m_outputs.data.at(i)["value"]);
+            }
+        }
+    }
 }
index 5ed7fa8..9d7677f 100644 (file)
@@ -21,8 +21,6 @@
 #include "SampleBundle.h"
 #include "DiscomfortIndexSensorResource.h"
 
-using namespace OIC::Service;
-
 SampleBundle *bundle;
 
 SampleBundle::SampleBundle()
@@ -41,11 +39,11 @@ void SampleBundle::activateBundle(ResourceContainerBundleAPI *resourceContainer,
     m_pResourceContainer = resourceContainer;
     m_bundleId = bundleId;
 
-    vector<Configuration::resourceInfo> resourceConfig;
+    vector<resourceInfo> resourceConfig;
 
     resourceContainer->getResourceConfiguration(m_bundleId, &resourceConfig);
 
-    for (vector<Configuration::resourceInfo>::iterator itor = resourceConfig.begin();
+    for (vector<resourceInfo>::iterator itor = resourceConfig.begin();
          itor != resourceConfig.end(); itor++)
     {
         createResource(*itor);
@@ -63,22 +61,37 @@ void SampleBundle::deactivateBundle()
     }
 }
 
-// TODO : has to be updated for setting the info
-void SampleBundle::createResource(Configuration::resourceInfo resourceInfo)
+void SampleBundle::createResource(resourceInfo resourceInfo)
 {
     std::cout << "SampleBundle::createResource called" << std::endl;
+
     static int discomfortIndexSensorCount = 0;
-    DiscomfortIndexSensorResource *newResource = new DiscomfortIndexSensorResource();
-    if(!resourceInfo.uri.empty()){
-        newResource->m_uri = resourceInfo.uri;
-    }
-    else{
-        newResource->m_uri = "sampleBundle/discomfortIndex/" + std::to_string(discomfortIndexSensorCount++);
+
+    std::vector< std::map< std::string, std::string > >::iterator itor_vec;
+    std::map< std::string, std::string >::iterator itor_map;
+    std::vector <std::string> inputs;
+
+    for (itor_vec = resourceInfo.resourceProperty["input"].begin();
+         itor_vec != resourceInfo.resourceProperty["input"].end(); itor_vec++)
+    {
+        for (itor_map = (*itor_vec).begin(); itor_map != (*itor_vec).end(); itor_map++)
+        {
+            inputs.push_back(itor_map->second);
+        }
     }
+    std::cout << "SampleBundle::creating new discomfort index sensor " << std::endl;
+    // create DISensor resource
+    DiscomfortIndexSensorResource *newResource = new DiscomfortIndexSensorResource(inputs);
+
+    newResource->m_uri = "/sampleBundle/discomfortIndex/" + std::to_string(
+                             discomfortIndexSensorCount++);
     newResource->m_resourceType = resourceInfo.resourceType;
+    newResource->m_mapResourceProperty = resourceInfo.resourceProperty;
 
-    m_pResourceContainer->registerResource(newResource);
+    // setting input Attributes count
+    newResource->inputCount = newResource->m_mapResourceProperty["input"].size();
 
+    m_pResourceContainer->registerResource(newResource);
     m_vecResources.push_back(newResource);
 }
 
index d8d6036..3d975e8 100644 (file)
@@ -43,7 +43,6 @@ namespace OIC
             virtual string getPath() = 0;
             virtual void setVersion(string version) = 0;
             virtual string getVersion() = 0;
-            virtual int getId() = 0; // will be set by container
             static BundleInfo* createBundleInfo();
         protected:
             string m_ID, m_path, m_version;
diff --git a/service/resource-manipulation/modules/resourceContainer/include/Configuration.h b/service/resource-manipulation/modules/resourceContainer/include/Configuration.h
deleted file mode 100644 (file)
index 20f61ce..0000000
+++ /dev/null
@@ -1,73 +0,0 @@
-//******************************************************************
-//
-// Copyright 2015 Samsung Electronics All Rights Reserved.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//      http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-
-#ifndef CONFIGURATION_H_
-#define CONFIGURATION_H_
-
-#include <unistd.h>
-#include <string.h>
-#include <fstream>
-
-#include "rapidxml/rapidxml.hpp"
-#include "rapidxml/rapidxml_print.hpp"
-
-#include "ResourceContainer.h"
-#include "BundleInfo.h"
-
-using namespace OIC::Service;
-
-namespace OIC
-{
-    namespace Service
-    {
-        class Configuration
-        {
-        public:
-            typedef vector< std::map< std::string, std::string > > configInfo;
-            struct resourceInfo
-            {
-                std::string name;
-                std::string uri;
-                std::string resourceType;
-                std::string address;
-                std::map< std::string, std::vector< std::map< std::string, std::string > > > resourceProperty;
-            };
-
-            Configuration();
-            ~Configuration();
-
-            Configuration(string configFile);
-
-            void getCommonConfiguration(configInfo *configOutput);
-            void getBundleConfiguration(std::string bundleId, configInfo *configOutput);
-            void getResourceConfiguration(std::string bundleId,
-                    std::vector< resourceInfo > *configOutput);
-            void getConfiguredBundles(configInfo *configOutput);
-
-        private:
-            void getConfigDocument(std::string pathConfigFile, std::string *pConfigData);
-            void getCurrentPath(std::string *path);
-
-            string m_pathConfigFile, m_configFile;
-        };
-    }
-}
-
-#endif
index 16643d8..5636d39 100644 (file)
@@ -25,6 +25,7 @@
 #include <string>
 #include <vector>
 #include <map>
+#include <list>
 
 #include "BundleInfo.h"
 
@@ -34,29 +35,28 @@ namespace OIC
 {
     namespace Service
     {
-        // placeholder
-        class Resource
-        {
-
-        };
-
         class ResourceContainer
         {
         public:
             ResourceContainer();
             virtual ~ResourceContainer();
-            virtual void init() = 0;
-            virtual void init(string configFile) = 0;
-            virtual void registerBundle(BundleInfo *bundleinfo) = 0;
-            virtual void unregisterBundle(BundleInfo *bundleinfo) = 0;
-            virtual void unregisterBundle(int id) = 0;
-            virtual void activateBundle(int id) = 0;
-            virtual void deactivateBundle(int id) = 0;
-            virtual void activateBundleByName(string name) = 0;
-            virtual void deactivateBundleByName(string id) = 0;
-            virtual void activateBundle(BundleInfo *bundleInfo) = 0;
-            virtual void deactivateBundle(BundleInfo *bundleInfo) = 0;
-            virtual vector< Resource * > listBundleResources(string id) = 0;
+            //virtual void initializeResourceContainer() = 0;
+            virtual void startContainer(string configFile) = 0;
+            virtual void stopContainer() = 0;
+
+            // list of bundle ids
+            virtual std::list<BundleInfo*> listBundles() = 0;
+            virtual void startBundle(string bundleId) = 0;
+            virtual void stopBundle(string bundleId) = 0;
+
+            // dynamic configuration
+            virtual void addBundle(string bundleId, string bundleUri, string bundlePath, std::map<string, string> params) =0;
+            virtual void removeBundle(string bundleId) = 0;
+
+            virtual void addResourceConfig(string bundleId, string resourceUri, std::map<string, string> params)  = 0;
+            virtual void removeResourceConfig(string bundleId, string resourceUri)  = 0;
+
+            virtual std::list<string> listBundleResources(string bundleId) = 0;
 
             static ResourceContainer *getInstance();
         };
@@ -24,6 +24,7 @@
 #include <string>
 #include "BundleInfo.h"
 #include "ResourceContainerBundleAPI.h"
+#include "jni.h"
 
 using namespace std;
 using namespace OIC::Service;
@@ -51,8 +52,17 @@ namespace OIC{
                 bool isLoaded();
                 void setActivated(bool activated);
                 bool isActivated();
-                int getId();
-                void setId(int id);
+
+                void setActivatorName(string activatorName);
+                string getActivatorName();
+
+                void setJavaBundleActivatorMethod(jmethodID activator);
+                jmethodID getJavaBundleActivatorMethod();
+                void setJavaBundleDeactivatorMethod(jmethodID deactivator);
+                jmethodID getJavaBundleDeactivatorMethod();
+
+                void setJavaBundleActivatorObject(jobject);
+                jobject getJavaBundleActivatorObject();
 
                 void setBundleActivator(activator_t *);
                 activator_t *getBundleActivator();
@@ -63,12 +73,18 @@ namespace OIC{
                 void setBundleHandle(void *);
                 void *getBundleHandle();
 
+                void setJavaBundle(bool javaBundle);
+                bool getJavaBundle();
+
             private:
-                bool m_loaded, m_activated;
+                bool m_loaded, m_activated, m_java_bundle;
                 int m_id;
                 activator_t *m_activator;
                 deactivator_t *m_deactivator;
                 void *m_bundleHandle;
+                string m_activator_name;
+                jmethodID m_java_activator, m_java_deactivator;
+                jobject m_java_activator_object;
         };
     }
 }
diff --git a/service/resource-manipulation/modules/resourceContainer/include/internal/Configuration.h b/service/resource-manipulation/modules/resourceContainer/include/internal/Configuration.h
new file mode 100644 (file)
index 0000000..76aa663
--- /dev/null
@@ -0,0 +1,75 @@
+//******************************************************************
+//
+// Copyright 2015 Samsung Electronics All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+#ifndef CONFIGURATION_H_
+#define CONFIGURATION_H_
+
+#include <unistd.h>
+#include <string.h>
+#include <iostream>
+#include <fstream>
+#include <string>
+#include <vector>
+#include <map>
+
+#include "rapidxml/rapidxml.hpp"
+#include "rapidxml/rapidxml_print.hpp"
+
+using namespace std;
+
+namespace OIC
+{
+    namespace Service
+    {
+        typedef vector< map< string, string > > configInfo;
+        struct resourceInfo
+        {
+            string name;
+            string uri;
+            string resourceType;
+            string address;
+            map< string, vector< map< string, string > > > resourceProperty;
+        };
+        class Configuration
+        {
+            public:
+
+
+
+                Configuration();
+                Configuration(string configFile);
+                ~Configuration();
+
+                void getConfiguredBundles(configInfo *configOutput);
+                void getBundleConfiguration(string bundleId, configInfo *configOutput);
+                void getResourceConfiguration(string bundleId, vector< resourceInfo > *configOutput);
+
+            private:
+                void getConfigDocument(string pathConfigFile);
+                void getCurrentPath(string *pPath);
+
+                string m_pathConfigFile;
+                string m_strConfigData;
+                rapidxml::xml_document< char > m_xmlDoc;
+        };
+    }
+}
+
+#endif /* CONFIGURATION_H_ */
diff --git a/service/resource-manipulation/modules/resourceContainer/include/internal/JavaBundleResource.h b/service/resource-manipulation/modules/resourceContainer/include/internal/JavaBundleResource.h
new file mode 100644 (file)
index 0000000..4937302
--- /dev/null
@@ -0,0 +1,60 @@
+//******************************************************************
+//
+// Copyright 2015 Samsung Electronics All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+#ifndef JAVABUNDLERESOURCE_H_
+#define JAVABUNDLERESOURCE_H_
+
+#include <map>
+#include <vector>
+#include <string>
+#include <jni.h>
+#include "BundleResource.h"
+#include "ResourceContainerImpl.h"
+
+using namespace std;
+
+namespace OIC
+{
+    namespace Service
+    {
+        class JavaBundleResource: public BundleResource
+        {
+        public:
+            JavaBundleResource();
+            JavaBundleResource(JNIEnv *env, jobject obj, jobject bundleResource, string bundleId,
+                    jobjectArray attributes);
+            virtual ~JavaBundleResource();
+
+            string getAttribute(string attributeName);
+            void setAttribute(string attributeName, string value);
+            void initAttributes();
+        private:
+            // needs to be a GlobalRef
+            jobject bundleResource;
+            jobjectArray attributes;
+            jclass bundleResourceClass;
+            jmethodID attributeSetter;
+            jmethodID attributeGetter;
+            string m_bundleId;
+        };
+    }
+}
+
+#endif
 
 #include "PrimitiveRequest.h"
 #include "PrimitiveResponse.h"
-#include "PrimitiveServerResource.h"
+#include "ResourceObject.h"
+
+#include "jni.h"
+#include <map>
 
 using namespace OIC::Service;
 
@@ -43,24 +46,20 @@ namespace OIC
             virtual ~ResourceContainerImpl();
 
             // methods from ResourceContainer
-            void init();
-            void init(string configFile);
-            void activateBundle(int id);
-            void deactivateBundle(int id);
-            void activateBundleByName(string name);
-            void deactivateBundleByName(string id);
+            void startContainer(string configFile);
+            void stopContainer();
+            void activateBundle(string bundleId);
+            void deactivateBundle(string bundleId);
             void activateBundle(BundleInfo *bundleInfo);
             void deactivateBundle(BundleInfo *bundleInfo);
-            vector< Resource * > listBundleResources(string id);
 
             // methods from ResourceContainerBundleAPI
             void registerBundle(BundleInfo *bundleinfo);
             void unregisterBundle(BundleInfo *bundleinfo);
-            void unregisterBundle(int id);
+            void unregisterBundle(string id);
             void registerResource(BundleResource *resource);
             void unregisterResource(BundleResource *resource);
 
-            void getCommonConfiguration(configInfo *configOutput);
             void getBundleConfiguration(std::string bundleId, configInfo *configOutput);
             void getResourceConfiguration(std::string bundleId,
                     std::vector< resourceInfo > *configOutput);
@@ -70,15 +69,41 @@ namespace OIC
 
             PrimitiveSetResponse setRequestHandler(const PrimitiveRequest &request,
                     const ResourceAttributes &attributes);
-
+                       
+                       void onNotificationReceived(std::string strResourceUri);
+                                       
             static ResourceContainerImpl *getImplInstance();
 
+            void addBundle(string bundleId, string bundleUri, string bundlePath, std::map<string, string> params);
+            void removeBundle(string bundleId);
+
+            std::list<BundleInfo*> listBundles();
+
+            void addResourceConfig(string bundleId, string resourceUri, std::map<string, string> params);
+            void removeResourceConfig(string bundleId, string resourceUri);
+
+            std::list<string> listBundleResources(string bundleId);
+
+            void startBundle(string bundleId);
+            void stopBundle(string bundleId);
+
+            JavaVM* getJavaVM(string bundleId);
+
         private:
-            vector< BundleInfoInternal * > m_bundles;
-            map< std::string, PrimitiveServerResource::Ptr > m_mapServers; //<uri, serverPtr>
+            map< std::string, BundleInfoInternal * > m_bundles; // <bundleID, bundleInfo>
+            map< std::string, ResourceObject::Ptr > m_mapServers; //<uri, serverPtr>
             map< std::string, BundleResource * > m_mapResources; //<uri, resourcePtr>
             string m_configFile;
-            Configuration *m_config;
+            Configuration *m_config = NULL;
+            map<string, JavaVM*> m_bundleVM;
+
+            void registerJavaBundle(BundleInfo *bundleInfo);
+            void registerSoBundle(BundleInfo *bundleInfo);
+            void activateJavaBundle(string bundleId);
+            void activateSoBundle(string bundleId);
+            void deactivateJavaBundle(string bundleId);
+            void deactivateSoBundle(string bundleId);
+
         };
     }
 }
diff --git a/service/resource-manipulation/modules/resourceContainer/include/internal/org_iotivity_resourcecontainer_bundle_api_BaseActivator.h b/service/resource-manipulation/modules/resourceContainer/include/internal/org_iotivity_resourcecontainer_bundle_api_BaseActivator.h
new file mode 100644 (file)
index 0000000..ca8469c
--- /dev/null
@@ -0,0 +1,45 @@
+/* DO NOT EDIT THIS FILE - it is machine generated */
+#include <jni.h>
+/* Header for class org_iotivity_resourcecontainer_bundle_api_BaseActivator */
+
+#ifndef _Included_org_iotivity_resourcecontainer_bundle_api_BaseActivator
+#define _Included_org_iotivity_resourcecontainer_bundle_api_BaseActivator
+#ifdef __cplusplus
+extern "C" {
+#endif
+/*
+ * Class:     org_iotivity_resourcecontainer_bundle_api_BaseActivator
+ * Method:    registerJavaResource
+ * Signature: (Lorg/iotivity/resourcecontainer/bundle/api/BundleResource;[Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
+ */
+JNIEXPORT void JNICALL Java_org_iotivity_resourcecontainer_bundle_api_BaseActivator_registerJavaResource
+  (JNIEnv *, jobject, jobject, jobjectArray, jstring, jstring, jstring, jstring);
+
+/*
+ * Class:     org_iotivity_resourcecontainer_bundle_api_BaseActivator
+ * Method:    unregisterJavaResource
+ * Signature: (Lorg/iotivity/resourcecontainer/bundle/api/BundleResource;)V
+ */
+JNIEXPORT void JNICALL Java_org_iotivity_resourcecontainer_bundle_api_BaseActivator_unregisterJavaResource
+  (JNIEnv *, jobject, jobject);
+
+/*
+ * Class:     org_iotivity_resourcecontainer_bundle_api_BaseActivator
+ * Method:    getNumberOfConfiguredResources
+ * Signature: (Ljava/lang/String;)I
+ */
+JNIEXPORT jint JNICALL Java_org_iotivity_resourcecontainer_bundle_api_BaseActivator_getNumberOfConfiguredResources
+  (JNIEnv *, jobject, jstring);
+
+/*
+ * Class:     org_iotivity_resourcecontainer_bundle_api_BaseActivator
+ * Method:    getConfiguredResourceParams
+ * Signature: (Ljava/lang/String;I)[Ljava/lang/String;
+ */
+JNIEXPORT jobjectArray JNICALL Java_org_iotivity_resourcecontainer_bundle_api_BaseActivator_getConfiguredResourceParams
+  (JNIEnv *, jobject, jstring, jint);
+
+#ifdef __cplusplus
+}
+#endif
+#endif
diff --git a/service/resource-manipulation/modules/resourceContainer/src/BaseActivator.cpp b/service/resource-manipulation/modules/resourceContainer/src/BaseActivator.cpp
new file mode 100644 (file)
index 0000000..507e5bb
--- /dev/null
@@ -0,0 +1,101 @@
+//******************************************************************
+//
+// Copyright 2015 Samsung Electronics All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+#include <jni.h>
+#include "org_iotivity_resourcecontainer_bundle_api_BaseActivator.h"
+#include "JavaBundleResource.h"
+#include "ResourceContainerImpl.h"
+
+using namespace OIC::Service;
+
+/*
+ * Class:     org_iotivity_resourcecontainer_bundle_api_BaseActivator
+ * Method:    registerJavaResource
+ * Signature: (Lorg/iotivity/resourcecontainer/bundle/api/BundleResource;[Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
+ */
+JNIEXPORT void JNICALL Java_org_iotivity_resourcecontainer_bundle_api_BaseActivator_registerJavaResource
+  (JNIEnv *env, jobject obj, jobject bundleResource, jobjectArray attributes, jstring bundleId, jstring uri, jstring resourceType, jstring res_name){
+    //return;
+    const char *str_bundleId = env->GetStringUTFChars(bundleId, 0);
+    const char *str_uri = env->GetStringUTFChars(uri, 0);
+    const char *str_resourceType = env->GetStringUTFChars(resourceType, 0);
+    const char *str_res_name = env->GetStringUTFChars(res_name, 0);
+    JavaBundleResource *javaBundleResource = new JavaBundleResource(env, obj, bundleResource, str_bundleId, attributes);
+    ResourceContainerImpl *container = ResourceContainerImpl::getImplInstance();
+
+    javaBundleResource->m_uri = string(str_uri, strlen(str_uri));
+    javaBundleResource->m_resourceType = string(str_resourceType, strlen(str_resourceType));
+    javaBundleResource->m_name = string(str_res_name, strlen(str_res_name));
+    container->registerResource(javaBundleResource);
+
+}
+
+/*
+ * Class:     org_iotivity_resourcecontainer_bundle_api_BaseActivator
+ * Method:    unregisterJavaResource
+ * Signature: (Lorg/iotivity/resourcecontainer/bundle/api/BundleResource;)V
+ */
+JNIEXPORT void JNICALL Java_org_iotivity_resourcecontainer_bundle_api_BaseActivator_unregisterJavaResource
+  (JNIEnv *, jobject, jobject){
+
+}
+
+/*
+ * Class:     org_iotivity_resourcecontainer_bundle_api_BaseActivator
+ * Method:    getNumberOfConfiguredResources
+ * Signature: (Ljava/lang/String;)I
+ */
+JNIEXPORT jint JNICALL Java_org_iotivity_resourcecontainer_bundle_api_BaseActivator_getNumberOfConfiguredResources
+  (JNIEnv *env, jobject obj, jstring bundleId){
+
+    const char *str_bundleId = env->GetStringUTFChars(bundleId, 0);
+
+    ResourceContainerImpl *container = ResourceContainerImpl::getImplInstance();
+    vector<resourceInfo> resourceConfig;
+    container->getResourceConfiguration(str_bundleId, &resourceConfig);
+
+    return resourceConfig.size();
+}
+
+/*
+ * Class:     org_iotivity_resourcecontainer_bundle_api_BaseActivator
+ * Method:    getConfiguredResourceParams
+ * Signature: (Ljava/lang/String;I)[Ljava/lang/String;
+ */
+JNIEXPORT jobjectArray JNICALL Java_org_iotivity_resourcecontainer_bundle_api_BaseActivator_getConfiguredResourceParams
+  (JNIEnv *env, jobject obj, jstring bundleId, jint resourceId){
+
+    jobjectArray ret;
+    const char *str_bundleId = env->GetStringUTFChars(bundleId, 0);
+
+    ResourceContainerImpl *container = ResourceContainerImpl::getImplInstance();
+    vector<resourceInfo> resourceConfig;
+    container->getResourceConfiguration(str_bundleId, &resourceConfig);
+    resourceInfo conf = resourceConfig[resourceId];
+    ret = (jobjectArray) env->NewObjectArray(4,
+            env->FindClass("java/lang/String"),
+            env->NewStringUTF(""));
+
+    env->SetObjectArrayElement(ret, 0, env->NewStringUTF(conf.name.c_str()));
+    env->SetObjectArrayElement(ret, 1, env->NewStringUTF(conf.uri.c_str()));
+    env->SetObjectArrayElement(ret, 2, env->NewStringUTF(conf.resourceType.c_str()));
+    env->SetObjectArrayElement(ret, 3, env->NewStringUTF(conf.address.c_str()));
+    return ret;
+}
index eee04ae..efbc837 100644 (file)
@@ -84,16 +84,6 @@ namespace OIC
             return m_activated;
         }
 
-        int BundleInfoInternal::getId()
-        {
-            return m_id;
-        }
-
-        void BundleInfoInternal::setId(int id)
-        {
-            m_id = id;
-        }
-
         void BundleInfoInternal::setBundleActivator(activator_t *activator)
         {
             m_activator = activator;
@@ -119,9 +109,67 @@ namespace OIC
             m_bundleHandle = handle;
         }
 
-        void *BundleInfoInternal::getBundleHandle()
+        voidBundleInfoInternal::getBundleHandle()
         {
             return m_bundleHandle;
         }
+
+        void BundleInfoInternal::setJavaBundle(bool javaBundle)
+        {
+            m_java_bundle = javaBundle;
+        }
+
+        bool BundleInfoInternal::getJavaBundle()
+        {
+            return m_java_bundle;
+        }
+
+        void BundleInfoInternal::setActivatorName(string activatorName)
+        {
+            m_activator_name = activatorName;
+        }
+
+        string BundleInfoInternal::getActivatorName()
+        {
+            return m_activator_name;
+        }
+
+        void BundleInfoInternal::setJavaBundleActivatorMethod(jmethodID javaBundleActivator)
+        {
+            m_java_activator = javaBundleActivator;
+        }
+
+        jmethodID BundleInfoInternal::getJavaBundleActivatorMethod()
+        {
+            return m_java_activator;
+        }
+
+        void BundleInfoInternal::setJavaBundleDeactivatorMethod(jmethodID javaBundleActivator)
+        {
+            m_java_deactivator = javaBundleActivator;
+        }
+
+        jmethodID BundleInfoInternal::getJavaBundleDeactivatorMethod()
+        {
+            return m_java_deactivator;
+        }
+
+        /*void BundleInfoInternal::setJavaBundleActivatorClass(jclass activator_class)
+        {
+            m_java_activator_class = activator_class;
+        }
+
+        jclass BundleInfoInternal::getJavaBundleActivatorClass()
+        {
+            return m_java_activator_class;
+        }*/
+
+        void BundleInfoInternal::setJavaBundleActivatorObject(jobject activator_object){
+            m_java_activator_object = activator_object;
+        }
+
+        jobject BundleInfoInternal::getJavaBundleActivatorObject(){
+            return m_java_activator_object;
+        }
     }
 }
index d10bec0..564032c 100644 (file)
 
 #include "BundleResource.h"
 #include "Configuration.h"
+#include <list>
+#include <string.h>
 
-
-namespace OIC{
-    namespace Service{
+namespace OIC
+{
+    namespace Service
+    {
         BundleResource::BundleResource()
         {
-            cout << "BundleResource constructor called\n";
+
         }
 
         BundleResource::~BundleResource()
         {
 
         }
+
+        void BundleResource::registerObserver(NotificationReceiver *pNotiReceiver)
+        {
+            m_pNotiReceiver = pNotiReceiver;
+        }
+
+        void BundleResource::setAttribute(string attributeName, string value)
+        {
+            this->m_mapAttributes[attributeName] = value;
+
+            if (m_pNotiReceiver != NULL && !m_uri.empty())
+            {
+                m_pNotiReceiver->onNotificationReceived(m_uri);
+            }
+
+        }
+
+        std::string BundleResource::getAttribute(string attributeName)
+        {
+            return this->m_mapAttributes[attributeName];
+        }
+
+        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;
+        }
+
     }
 }
index 89f96ed..2ef2c01 100644 (file)
@@ -43,103 +43,34 @@ namespace OIC
 
         Configuration::Configuration()
         {
-            // TODO: temporary path and config file name
-            getCurrentPath(&m_pathConfigFile);
-            m_pathConfigFile.append("/");
-            m_pathConfigFile.append("ResourceContainerConfig.xml");
-        }
-
-        Configuration::~Configuration()
-        {
         }
 
         Configuration::Configuration(string configFile)
         {
-            m_configFile = configFile;
+
             getCurrentPath(&m_pathConfigFile);
             m_pathConfigFile.append("/");
-            m_pathConfigFile.append(m_configFile);
+            m_pathConfigFile.append(configFile);
+
+            getConfigDocument(m_pathConfigFile);
         }
 
-        void Configuration::getCommonConfiguration(configInfo *configOutput)
+        Configuration::~Configuration()
         {
-            string strConfigData;
-
-            rapidxml::xml_document< char > xmlDoc;
-
-            rapidxml::xml_node< char > *root;
-            rapidxml::xml_node< char > *item;
-            rapidxml::xml_node< char > *subItem;
-
-            string strKey, strValue;
-
-            getConfigDocument(m_pathConfigFile, &strConfigData);
-
-            try
-            {
-                xmlDoc.parse< 0 >((char *) strConfigData.c_str());
-
-                // <container>
-                root = xmlDoc.first_node();
-
-                if (!root)
-                {
-                    throw rapidxml::parse_error("No Root Element", 0);
-                }
-                std::map< std::string, std::string > bundleMap;
-                for (item = root->first_node(); item; item = item->next_sibling())
-                {
-                    strKey = item->name();
-                    strValue = item->value();
-
-                    // <config>
-                    if (!strKey.compare("config"))
-                    {
-                        for (subItem = item->first_node(); subItem; subItem =
-                                subItem->next_sibling())
-                        {
-                            strKey = subItem->name();
-                            strValue = subItem->value();
-
-                            bundleMap.insert(
-                                    std::make_pair(trim_both(strKey), trim_both(strValue)));
-                        }
-                        break;
-                    }
-                }
-                configOutput->push_back(bundleMap);
-            }
-            catch (rapidxml::parse_error &e)
-            {
-                cout << "xml parsing failed !!" << endl;
-                cout << e.what() << endl;
-            }
         }
 
         void Configuration::getConfiguredBundles(configInfo *configOutput)
         {
-            string strConfigData;
-
-            rapidxml::xml_document< char > xmlDoc;
-
             rapidxml::xml_node< char > *bundle;
             rapidxml::xml_node< char > *subItem;
 
             string strKey, strValue;
 
-            cout << "Opening: " << m_pathConfigFile << endl;
-
-            getConfigDocument(m_pathConfigFile, &strConfigData);
-
-            //cout << strConfigData.c_str() << endl;
             try
             {
-
-                xmlDoc.parse< 0 >((char *) strConfigData.c_str());
                 //cout << "Name of first node is: " << xmlDoc.first_node()->name() << endl;
 
-                for (bundle = xmlDoc.first_node()->first_node("bundle"); bundle;
-                        bundle = bundle->next_sibling())
+                for (bundle = m_xmlDoc.first_node()->first_node("bundle"); bundle; bundle = bundle->next_sibling())
                 {
                     std::map< std::string, std::string > bundleMap;
                     //cout << "Bundle: " << bundle->name() << endl;
@@ -147,12 +78,11 @@ namespace OIC
                     {
                         strKey = subItem->name();
                         strValue = subItem->value();
+
                         if (strlen(subItem->value()) > 0)
                         {
-                            bundleMap.insert(
-                                    std::make_pair(trim_both(strKey), trim_both(strValue)));
+                            bundleMap.insert(std::make_pair(trim_both(strKey), trim_both(strValue)));
                             //cout << strKey << " " << strValue << endl;
-
                         }
                     }
                     configOutput->push_back(bundleMap);
@@ -168,58 +98,36 @@ namespace OIC
 
         void Configuration::getBundleConfiguration(string bundleId, configInfo *configOutput)
         {
-            string strConfigData;
-
-            rapidxml::xml_document< char > xmlDoc;
-
-            rapidxml::xml_node< char > *root;
-            rapidxml::xml_node< char > *item;
-            rapidxml::xml_node< char > *subItem;
-
-            string strKey, strValue;
+            rapidxml::xml_node< char > *bundle;
 
-            getConfigDocument(m_pathConfigFile, &strConfigData);
+            string strBundleId, strPath, strVersion;
 
             try
             {
-                xmlDoc.parse< 0 >((char *) strConfigData.c_str());
+                std::map< std::string, std::string > bundleConfigMap;
 
-                // <container>
-                root = xmlDoc.first_node();
-
-                if (!root)
-                {
-                    throw rapidxml::parse_error("No Root Element", 0);
-                }
-                std::map< std::string, std::string > bundleMap;
-                for (item = root->first_node(); item; item = item->next_sibling())
+                // <bundle>
+                for (bundle = m_xmlDoc.first_node()->first_node("bundle"); bundle; bundle = bundle->next_sibling())
                 {
-                    strKey = item->name();
-                    strValue = item->value();
+                    // <id>
+                    strBundleId = bundle->first_node("id")->value();
+                    bundleConfigMap.insert(std::make_pair("id", trim_both(strBundleId)));
 
-                    // <bundle>
-                    if (!strKey.compare("bundle"))
+                    if (!strBundleId.compare(bundleId))
                     {
-                        for (subItem = item->first_node(); subItem; subItem =
-                                subItem->next_sibling())
-                        {
-                            strKey = subItem->name();
-                            strValue = subItem->value();
+                        // <path>
+                        strPath = bundle->first_node("path")->value();
+                        bundleConfigMap.insert(std::make_pair("id", trim_both(strPath)));
 
-                            if (!strKey.compare("bundleID") && strValue.compare(bundleId))
-                                break;
+                        // <version>
+                        strVersion = bundle->first_node("version")->value();
+                        bundleConfigMap.insert(std::make_pair("id", trim_both(strVersion)));
 
-                            // bundle info (except resource data)
-                            if (strKey.compare("resources"))
-                            {
-                                bundleMap.insert(
-                                        std::make_pair(trim_both(strKey), trim_both(strValue)));
-                            }
-                        }
+                        break;
                     }
                 }
-                configOutput->push_back(bundleMap);
 
+                configOutput->push_back(bundleConfigMap);
             }
             catch (rapidxml::parse_error &e)
             {
@@ -228,124 +136,83 @@ namespace OIC
             }
         }
 
-        void Configuration::getResourceConfiguration(string bundleId,
-                vector< resourceInfo > *configOutput)
+        void Configuration::getResourceConfiguration(std::string bundleId,
+                std::vector< resourceInfo > *configOutput)
         {
-            string strConfigData;
-
-            rapidxml::xml_document< char > xmlDoc;
-
-            rapidxml::xml_node< char > *root;
-            rapidxml::xml_node< char > *item;
-            rapidxml::xml_node< char > *subItem, *subItem2, *subItem3, *subItem4, *subItem5;
+            rapidxml::xml_node< char > *bundle;
+            rapidxml::xml_node< char > *resource;
+            rapidxml::xml_node< char > *item, *subItem, *subItem2;
 
+            string strBundleId;
             string strKey, strValue;
 
-            getConfigDocument(m_pathConfigFile, &strConfigData);
-
             try
             {
-                xmlDoc.parse< 0 >((char *) strConfigData.c_str());
-
-                // <container>
-                root = xmlDoc.first_node();
-
-                if (!root)
-                {
-                    throw rapidxml::parse_error("No Root Element", 0);
-                }
-
-                for (item = root->first_node(); item; item = item->next_sibling())
+                // <bundle>
+                for (bundle = m_xmlDoc.first_node()->first_node("bundle"); bundle; bundle = bundle->next_sibling())
                 {
-                    strKey = item->name();
-                    strValue = item->value();
+                    // <id>
+                    strBundleId = bundle->first_node("id")->value();
 
-                    // <bundle>
-                    if (!strKey.compare("bundle"))
+                    if (!strBundleId.compare(bundleId))
                     {
-                        for (subItem = item->first_node(); subItem; subItem =
-                                subItem->next_sibling())
+                        // <resourceInfo>
+                        for (resource = bundle->first_node("resources")->first_node("resourceInfo"); resource;
+                             resource = resource->next_sibling())
                         {
-                            strKey = subItem->name();
-                            strValue = subItem->value();
-
-                            if (!strKey.compare("bundleID") && strValue.compare(bundleId))
-                                break;
+                            resourceInfo tempResourceInfo;
 
-                            // <resources>
-                            if (!strKey.compare("resources"))
+                            for (item = resource->first_node(); item; item = item->next_sibling())
                             {
-                                for (subItem2 = subItem->first_node(); subItem2;
-                                        subItem2 = subItem2->next_sibling())
-                                {
-                                    strKey = subItem2->name();
-                                    strValue = subItem2->value();
+                                strKey = item->name();
+                                strValue = item->value();
 
-                                    // <resourceInfo> : for 1 resource
-                                    if (!strKey.compare("resourceInfo"))
-                                    {
-                                        resourceInfo tempResourceInfo;
-
-                                        for (subItem3 = subItem2->first_node(); subItem3; subItem3 =
-                                                subItem3->next_sibling())
-                                        {
+                                if (!strKey.compare("name"))
+                                    tempResourceInfo.name = trim_both(strValue);
 
-                                            strKey = subItem3->name();
-                                            strValue = subItem3->value();
+                                else if (!strKey.compare("uri"))
+                                    tempResourceInfo.uri = trim_both(strValue);
 
-                                            if (!strKey.compare("name"))
-                                                tempResourceInfo.name = trim_both(strValue);
+                                else if (!strKey.compare("address"))
+                                    tempResourceInfo.address = trim_both(strValue);
 
-                                            else if (!strKey.compare("uri"))
-                                                tempResourceInfo.uri = trim_both(strValue);
+                                else if (!strKey.compare("resourceType"))
+                                    tempResourceInfo.resourceType = trim_both(strValue);
 
-                                            else if (!strKey.compare("address"))
-                                                tempResourceInfo.address = trim_both(strValue);
-
-                                            else if (!strKey.compare("resourceType"))
-                                                tempResourceInfo.resourceType = trim_both(strValue);
-
-                                            else
-                                            {
-                                                for (subItem4 = subItem3->first_node(); subItem4;
-                                                        subItem4 = subItem4->next_sibling())
-                                                {
-                                                    map< string, string > propertyMap;
-
-                                                    strKey = subItem4->name();
+                                else
+                                {
+                                    for (subItem = item->first_node(); subItem; subItem = subItem->next_sibling())
+                                    {
+                                        map< string, string > propertyMap;
 
-                                                    for (subItem5 = subItem4->first_node();
-                                                            subItem5;
-                                                            subItem5 = subItem5->next_sibling())
-                                                    {
-                                                        string newStrKey = subItem5->name();
-                                                        string newStrValue = subItem5->value();
+                                        strKey = subItem->name();
 
-                                                        propertyMap[trim_both(newStrKey)] =
-                                                                trim_both(newStrValue);
-                                                    }
+                                        for (subItem2 = subItem->first_node(); subItem2; subItem2 = subItem2->next_sibling())
+                                        {
+                                            string newStrKey = subItem2->name();
+                                            string newStrValue = subItem2->value();
 
-                                                    tempResourceInfo.resourceProperty[trim_both(
-                                                            strKey)].push_back(propertyMap);
-                                                }
-                                            }
+                                            propertyMap[trim_both(newStrKey)] = trim_both(newStrValue);
                                         }
-                                        configOutput->push_back(tempResourceInfo);
+
+                                        tempResourceInfo.resourceProperty[trim_both(strKey)].push_back(propertyMap);
                                     }
                                 }
                             }
+                            configOutput->push_back(tempResourceInfo);
                         }
                     }
                 }
             }
             catch (rapidxml::parse_error &e)
             {
-                cout << "xml parsing failed !!" << endl;
-                cout << e.what() << endl;
+                std::cout << "xml parsing failed !!" << std::endl;
+                std::cout << e.what() << std::endl;
             }
+
         }
 
-        void Configuration::getConfigDocument(std::string pathConfigFile, std::string *pConfigData)
+        void Configuration::getConfigDocument(std::string pathConfigFile)
         {
             std::basic_ifstream< char > xmlFile(pathConfigFile.c_str());
 
@@ -360,7 +227,18 @@ namespace OIC
 
                 xmlFile.read(&xmlData.front(), (std::streamsize) size);
                 xmlFile.close();
-                *pConfigData = std::string(xmlData.data());
+                m_strConfigData = std::string(xmlData.data());
+
+                try
+                {
+                    m_xmlDoc.parse< 0 >((char *)m_strConfigData.c_str());
+
+                }
+                catch (rapidxml::parse_error &e)
+                {
+                    std::cout << "xml parsing failed !!" << std::endl;
+                    std::cout << e.what() << std::endl;
+                }
             }
             else
             {
@@ -368,7 +246,7 @@ namespace OIC
             }
         }
 
-        void Configuration::getCurrentPath(std::string *path)
+        void Configuration::getCurrentPath(std::string *pPath)
         {
             char buffer[2048];
             char *strPath = NULL;
@@ -381,7 +259,7 @@ namespace OIC
 
             *strPath = '\0';
 
-            path->append(buffer);
+            pPath->append(buffer);
         }
     }
 }
index d05b2f5..ec5618b 100644 (file)
@@ -25,7 +25,6 @@
 using namespace OIC::Service;
 using OC::oc_log_stream;
 
-
 /* Annother way to create a context: */
 auto info_logger = []() -> boost::iostreams::stream<OC::oc_log_stream> &
 {
@@ -35,6 +34,7 @@ auto info_logger = []() -> boost::iostreams::stream<OC::oc_log_stream> &
     return os;
 };
 
+
 int main()
 {
     info_logger()->set_module("ContainerTest");
@@ -43,11 +43,62 @@ int main()
     info_logger() << "Starting container test." << std::flush;
 
     ResourceContainer *container = ResourceContainer::getInstance();
-    container->init("examples/ResourceContainerConfig.xml");
+    container->startContainer("examples/ResourceContainerConfig.xml");
+
+    std::list<BundleInfo*> bundles = container->listBundles();
+    std::list<BundleInfo*>::iterator bundleIt;
+
+    for(bundleIt = bundles.begin(); bundleIt != bundles.end(); bundleIt++){
+        BundleInfo* bi = *bundleIt;
+        info_logger() << "Available bundle: " << bi->getID() << endl;
+    }
+
+    /*int menu;
+
+    cout << "press \'1\' to test discomfortIndexSensor" << endl;
+    cin >> menu;
+
+    if (menu == 1)
+    {
+        string testingSoftSensor = "/sampleBundle/discomfortIndex/0";
+
+        SoftSensorResource::SensorData Thing_TempHumSensor;
+        SoftSensorResource::SensorData Thing_TempHumSensor1;
+
+        map < string, string > data;
+        data["name"] = "temperature";
+        data["type"] = "int";
+        data["value"] = "25";
+
+        map < string, string > data1;
+        data1["name"] = "humidity";
+        data1["type"] = "int";
+        data1["value"] = "40";
+
+        Thing_TempHumSensor.sensorName = "Thing_TempHumSensor";
+        Thing_TempHumSensor.data.push_back(data);
+        Thing_TempHumSensor.data.push_back(data1);
+
+        Thing_TempHumSensor1.sensorName = "Thing_TempHumSensor1";
+        Thing_TempHumSensor1.data.push_back(data);
+        Thing_TempHumSensor1.data.push_back(data1);
+
+        container->setInputAttribute(testingSoftSensor, Thing_TempHumSensor);
+        container->setInputAttribute(testingSoftSensor, Thing_TempHumSensor1);
+
+        cout << endl << endl;
+
+        // TEST :: change data (change humidity data of Thing_TempHumSensor1)
+        data["value"] = "33";
+        data1["value"] = "80";
+        Thing_TempHumSensor1.data.clear();
+        Thing_TempHumSensor1.data.push_back(data);
+        Thing_TempHumSensor1.data.push_back(data1);
+        container->setInputAttribute(testingSoftSensor, Thing_TempHumSensor1);
+    }*/
 
     while (1)
     {
         ;
     }
 }
-
diff --git a/service/resource-manipulation/modules/resourceContainer/src/JavaBundleResource.cpp b/service/resource-manipulation/modules/resourceContainer/src/JavaBundleResource.cpp
new file mode 100644 (file)
index 0000000..cf7f6bf
--- /dev/null
@@ -0,0 +1,147 @@
+//******************************************************************
+//
+// Copyright 2015 Samsung Electronics All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+#include "JavaBundleResource.h"
+#include <jni.h>
+#include <string.h>
+
+#include <iostream>
+
+using namespace OIC::Service;
+using namespace std;
+
+#include "oc_logger.hpp"
+
+using OC::oc_log_stream;
+using namespace OIC::Service;
+
+auto info_logger = []() -> boost::iostreams::stream<OC::oc_log_stream> &
+{
+    static OC::oc_log_stream ols(oc_make_ostream_logger);
+    static boost::iostreams::stream<OC::oc_log_stream> os(ols);
+    os->set_level(OC_LOG_INFO);
+    os->set_module("JavaBundleResource");
+    return os;
+};
+
+auto error_logger = []() -> boost::iostreams::stream<OC::oc_log_stream> &
+{
+    static OC::oc_log_stream ols(oc_make_ostream_logger);
+    static boost::iostreams::stream<OC::oc_log_stream> os(ols);
+    os->set_level(OC_LOG_ERROR);
+    os->set_module("JavaBundleResource");
+    return os;
+};
+
+JavaBundleResource::JavaBundleResource()
+{
+
+}
+
+void JavaBundleResource::initAttributes()
+{
+
+}
+
+JavaBundleResource::JavaBundleResource(JNIEnv *env, jobject obj, jobject bundleResource,
+        string bundleId, jobjectArray attributes)
+{
+    int stringCount = env->GetArrayLength(attributes);
+
+    for (int i = 0; i < stringCount; i++)
+    {
+        jstring str = (jstring) env->GetObjectArrayElement(attributes, i);
+        const char *rawString = env->GetStringUTFChars(str, 0);
+        string s(rawString, strlen(rawString));
+        BundleResource::setAttribute(s, "");
+    }
+
+    m_bundleId = bundleId;
+
+    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");
+}
+
+JavaBundleResource::~JavaBundleResource()
+{
+
+}
+
+string JavaBundleResource::getAttribute(string attributeName)
+{
+    JavaVM* vm = ResourceContainerImpl::getImplInstance()->getJavaVM(m_bundleId);
+
+    JNIEnv * env;
+    int envStat = vm->GetEnv((void **) &env, JNI_VERSION_1_4);
+
+    if (envStat == JNI_EDETACHED)
+    {
+        if (vm->AttachCurrentThread((void**) &env, NULL) != 0)
+        {
+            error_logger() << "Failed to attach " << endl;
+        }
+    }
+    else if (envStat == JNI_EVERSION)
+    {
+        error_logger() << "Env: version not supported " << endl;
+    }
+
+    jstring attrName = env->NewStringUTF(attributeName.c_str());
+
+    jstring returnString = (jstring) env->CallObjectMethod(bundleResource, attributeGetter,
+            attrName);
+    const char *js = env->GetStringUTFChars(returnString, NULL);
+    std::string value(js);
+    env->ReleaseStringUTFChars(returnString, js);
+    BundleResource::setAttribute(attributeName, value);
+    return value;
+}
+
+void JavaBundleResource::setAttribute(string attributeName, string value)
+{
+    BundleResource::setAttribute(attributeName, value);
+
+    JavaVM* vm = ResourceContainerImpl::getImplInstance()->getJavaVM(m_bundleId);
+
+    JNIEnv * env;
+    int envStat = vm->GetEnv((void **) &env, JNI_VERSION_1_4);
+
+    if (envStat == JNI_EDETACHED)
+    {
+        if (vm->AttachCurrentThread((void**) &env, NULL) != 0)
+        {
+            error_logger() << "Failed to attach " << endl;
+        }
+    }
+    else if (envStat == JNI_EVERSION)
+    {
+        error_logger() << "Env: version not supported " << endl;
+    }
+
+    jstring attrName = env->NewStringUTF(attributeName.c_str());
+    jstring val = env->NewStringUTF(value.c_str());
+
+    env->CallObjectMethod(bundleResource, attributeSetter, attrName, val);
+}
index b9b7c87..5857067 100644 (file)
 #include <string.h>
 #include <iostream>
 #include <fstream>
+#include <jni.h>
 
 #include "oc_logger.hpp"
 
 using OC::oc_log_stream;
 using namespace OIC::Service;
 
-/* Annother way to create a context: */
 auto info_logger = []() -> boost::iostreams::stream<OC::oc_log_stream> &
 {
     static OC::oc_log_stream ols(oc_make_ostream_logger);
@@ -44,7 +44,6 @@ auto info_logger = []() -> boost::iostreams::stream<OC::oc_log_stream> &
     return os;
 };
 
-/* Annother way to create a context: */
 auto error_logger = []() -> boost::iostreams::stream<OC::oc_log_stream> &
 {
     static OC::oc_log_stream ols(oc_make_ostream_logger);
@@ -73,36 +72,119 @@ namespace OIC
             // TODO Auto-generated destructor stub
         }
 
-        void ResourceContainerImpl::init()
+        bool has_suffix(const std::string &str, const std::string &suffix)
         {
-
+            return str.size() >= suffix.size()
+                    && str.compare(str.size() - suffix.size(), suffix.size(), suffix) == 0;
         }
 
-        void ResourceContainerImpl::init(string configFile)
+        void ResourceContainerImpl::startContainer(string configFile)
         {
+            info_logger() << "Starting resource container" << endl;
+
             m_config = new Configuration(configFile);
-            Configuration::configInfo bundles;
+            configInfo bundles;
             m_config->getConfiguredBundles(&bundles);
+
             for (int i = 0; i < bundles.size(); i++)
             {
                 BundleInfo *bundleInfo = BundleInfo::createBundleInfo();
                 bundleInfo->setPath(bundles[i]["path"]);
                 bundleInfo->setVersion(bundles[i]["version"]);
                 bundleInfo->setID(bundles[i]["id"]);
-                cout << "Init Bundle:" << bundles[i]["id"] << ";" << bundles[i]["path"] << endl;
+                if (!bundles[i]["activator"].empty())
+                {
+                    string activatorName = bundles[i]["activator"];
+                    std::replace(activatorName.begin(), activatorName.end(), '.', '/');
+                    ((BundleInfoInternal*) bundleInfo)->setActivatorName(activatorName);
+
+                }
+                info_logger() << "Init Bundle:" << bundles[i]["id"] << ";" << bundles[i]["path"]
+                        << endl;
                 registerBundle(bundleInfo);
                 activateBundle(bundleInfo);
             }
         }
 
-        // loads the bundle
-        void ResourceContainerImpl::registerBundle(BundleInfo *bundleInfo)
+        void ResourceContainerImpl::registerJavaBundle(BundleInfo *bundleInfo)
         {
-            info_logger() << "Registering bundle: " << bundleInfo->getPath() << endl;
+            info_logger() << "Registering Java bundle " << bundleInfo->getID() << endl;
+            JavaVM * jvm;
+            JNIEnv * env;
+            JavaVMInitArgs vm_args;
+            JavaVMOption options[3];
+
+            BundleInfoInternal* bundleInfoInternal = (BundleInfoInternal*) bundleInfo;
+
+            options[0].optionString = "-Djava.compiler=NONE";
+            char classpath[1000];
+            strcpy(classpath, "-Djava.class.path=");
+            strcat(classpath, bundleInfo->getPath().c_str());
+
+            options[1].optionString = classpath;
+
+            options[2].optionString = "-Djava.library.path=.";
+
+            vm_args.version = JNI_VERSION_1_4;
+            vm_args.options = options;
+            vm_args.nOptions = 3;
+            vm_args.ignoreUnrecognized = 1;
+
+            JNI_CreateJavaVM(&jvm, (void **) &env, &vm_args);
+
+            m_bundleVM.insert(std::pair< string, JavaVM * >(bundleInfo->getID(), jvm));
+
+            const char *className = bundleInfoInternal->getActivatorName().c_str();
+
+            jclass bundleActivatorClass = env->FindClass(className);
+
+            if (bundleActivatorClass == NULL)
+            {
+                error_logger() << "Cannot register bundle " << bundleInfoInternal->getID()
+                        << " bundle activator(" << bundleInfoInternal->getActivatorName()
+                        << ") not found " << endl;
+                return;
+            }
+
+            jmethodID activateMethod = env->GetMethodID(bundleActivatorClass, "activateBundle",
+                    "()V");
+
+            if (activateMethod == NULL)
+            {
+                error_logger() << "Cannot register bundle " << bundleInfoInternal->getID()
+                        << " activate bundle method not found " << endl;
+                return;
+            }
+            bundleInfoInternal->setJavaBundleActivatorMethod(activateMethod);
+
+            jmethodID deactivateMethod = env->GetMethodID(bundleActivatorClass, "activateBundle",
+                    "()V");
+
+            if (deactivateMethod == NULL)
+            {
+                error_logger() << "Cannot register bundle " << bundleInfoInternal->getID()
+                        << " deactivate bundle method not found " << endl;
+                return;
+            }
+
+            bundleInfoInternal->setJavaBundleDeactivatorMethod(deactivateMethod);
+
+            jmethodID constructor;
+
+            constructor = env->GetMethodID(bundleActivatorClass, "<init>", "(Ljava/lang/String;)V");
+
+            jstring bundleID = env->NewStringUTF(bundleInfoInternal->getID().c_str());
+
+            jobject bundleActivator = env->NewObject(bundleActivatorClass, constructor, bundleID);
+
+            bundleInfoInternal->setJavaBundleActivatorObject(bundleActivator);
 
-            m_bundles.push_back((BundleInfoInternal *) bundleInfo);
-            ((BundleInfoInternal *) bundleInfo)->setId(m_bundles.size() - 1);
+            bundleInfoInternal->setLoaded(true);
+            info_logger() << "Bundle registered" << endl;
+        }
 
+        void ResourceContainerImpl::registerSoBundle(BundleInfo *bundleInfo)
+        {
             char *error;
 
             activator_t *bundleActivator = NULL;
@@ -139,29 +221,91 @@ namespace OIC
             }
         }
 
-        void ResourceContainerImpl::activateBundle(int id)
+        // loads the bundle
+        void ResourceContainerImpl::registerBundle(BundleInfo *bundleInfo)
+        {
+            info_logger() << "Registering bundle: " << bundleInfo->getPath() << endl;
+
+            m_bundles[bundleInfo->getID()] = ((BundleInfoInternal *) bundleInfo);
+
+            if (has_suffix(bundleInfo->getPath(), ".jar"))
+            {
+                ((BundleInfoInternal *) bundleInfo)->setJavaBundle(true);
+                registerJavaBundle(bundleInfo);
+            }
+            else
+            {
+                ((BundleInfoInternal *) bundleInfo)->setJavaBundle(false);
+                registerSoBundle(bundleInfo);
+            }
+        }
+
+        void ResourceContainerImpl::activateJavaBundle(string bundleId)
         {
-            activator_t *bundleActivator = m_bundles[id]->getBundleActivator();
-            info_logger() << "Activating bundle: " << m_bundles[id]->getID() << ", "
-                    << m_bundles[id]->getId() << endl;
+            info_logger() << "Activating java bundle" << endl;
+            JavaVM* vm = getJavaVM(bundleId);
+            BundleInfoInternal* bundleInfoInternal = (BundleInfoInternal*) m_bundles[bundleId];
+            JNIEnv * env;
+            int envStat = vm->GetEnv((void **) &env, JNI_VERSION_1_4);
+
+            if (envStat == JNI_EDETACHED)
+            {
+                if (vm->AttachCurrentThread((void**) &env, NULL) != 0)
+                {
+                    error_logger() << "Failed to attach " << endl;
+                }
+            }
+            else if (envStat == JNI_EVERSION)
+            {
+                error_logger() << "Env: version not supported " << endl;
+            }
+
+            env->CallVoidMethod(bundleInfoInternal->getJavaBundleActivatorObject(),
+                    bundleInfoInternal->getJavaBundleActivatorMethod());
+        }
+
+        void ResourceContainerImpl::activateSoBundle(string bundleId)
+        {
+            activator_t *bundleActivator = m_bundles[bundleId]->getBundleActivator();
 
             if (bundleActivator != NULL)
             {
-                bundleActivator(this, m_bundles[id]->getID());
-                m_bundles[id]->setActivated(true);
+                bundleActivator(this, m_bundles[bundleId]->getID());
+                m_bundles[bundleId]->setActivated(true);
             }
             else
             {
                 //Unload module and return error
                 error_logger() << "Activation unsuccessful." << endl;
             }
+
+            BundleInfoInternal* bundleInfoInternal = (BundleInfoInternal*) m_bundles[bundleId];
+            bundleInfoInternal->setActivated(true);
+        }
+
+        void ResourceContainerImpl::activateBundle(string id)
+        {
+
+            info_logger() << "Activating bundle: " << m_bundles[id]->getID() << endl;
+
+            if (m_bundles[id]->getJavaBundle())
+            {
+                activateJavaBundle(id);
+            }
+            else
+            {
+                activateSoBundle(id);
+            }
+
+            info_logger() << "Bundle activated: " << m_bundles[id]->getID() << endl;
+
         }
 
         void ResourceContainerImpl::activateBundle(BundleInfo *bundleInfo)
         {
             if (((BundleInfoInternal *) bundleInfo)->isLoaded())
             {
-                activateBundle(bundleInfo->getId());
+                activateBundle(bundleInfo->getID());
             }
         }
 
@@ -169,15 +313,40 @@ namespace OIC
         {
             if (((BundleInfoInternal *) bundleInfo)->isActivated())
             {
-                deactivateBundle(bundleInfo->getId());
+                deactivateBundle(bundleInfo->getID());
+            }
+        }
+
+
+        void ResourceContainerImpl::deactivateJavaBundle(string bundleId)
+        {
+            info_logger() << "Deactivating java bundle" << endl;
+            JavaVM* vm = getJavaVM(bundleId);
+            BundleInfoInternal* bundleInfoInternal = (BundleInfoInternal*) m_bundles[bundleId];
+            JNIEnv * env;
+            int envStat = vm->GetEnv((void **) &env, JNI_VERSION_1_4);
+
+            if (envStat == JNI_EDETACHED)
+            {
+                if (vm->AttachCurrentThread((void**) &env, NULL) != 0)
+                {
+                    error_logger() << "Failed to attach " << endl;
+                }
             }
+            else if (envStat == JNI_EVERSION)
+            {
+                error_logger() << "Env: version not supported " << endl;
+            }
+
+            env->CallVoidMethod(bundleInfoInternal->getJavaBundleActivatorObject(),
+                    bundleInfoInternal->getJavaBundleDeactivatorMethod());
         }
 
-        void ResourceContainerImpl::deactivateBundle(int id)
+        void ResourceContainerImpl::deactivateSoBundle(string id)
         {
+
             deactivator_t *bundleDeactivator = m_bundles[id]->getBundleDeactivator();
-            info_logger() << "De-activating bundle: " << m_bundles[id]->getID() << ", "
-                    << m_bundles[id]->getId() << endl;
+            info_logger() << "De-activating bundle: " << m_bundles[id]->getID() << endl;
 
             if (bundleDeactivator != NULL)
             {
@@ -191,40 +360,41 @@ namespace OIC
             }
         }
 
-        void ResourceContainerImpl::activateBundleByName(string name)
-        {
-
-        }
-
-        void ResourceContainerImpl::deactivateBundleByName(string id)
+        void ResourceContainerImpl::deactivateBundle(string id)
         {
 
+            if (m_bundles[id]->getJavaBundle())
+            {
+                deactivateJavaBundle(id);
+            }
+            else
+            {
+                deactivateSoBundle(id);
+            }
         }
 
-        vector< Resource * > ResourceContainerImpl::listBundleResources(string id)
+        std::list< string > ResourceContainerImpl::listBundleResources(string id)
         {
-            vector< Resource * > ret;
+            std::list< string > ret;
             return ret;
         }
 
         void ResourceContainerImpl::registerResource(BundleResource *resource)
         {
-            cout << "Register resource called. " << resource->m_uri << " "
-                    << resource->m_resourceType << endl;
 
             string strUri = resource->m_uri;
             string strResourceType = resource->m_resourceType;
 
-            PrimitiveServerResource::Ptr server =
-                    PrimitiveServerResource::Builder(strUri, strResourceType, "DEFAULT_INTERFACE").setObservable(
-                            false).setDiscoverable(true).create();
+            info_logger() << "Registration of resource " << strUri << "," << strResourceType
+                    << endl;
+
+            ResourceObject::Ptr server = ResourceObject::Builder(strUri, strResourceType,
+                    "DEFAULT_INTERFACE").setObservable(true).setDiscoverable(true).build();
 
             m_mapServers[strUri] = server;
             m_mapResources[strUri] = resource;
 
-            cout << "Registered resource has " << m_mapResources[strUri]->m_mapAttributes.size()
-                    << " attributes.\n" << endl;
-
+            resource->registerObserver(this);
             server->setGetRequestHandler(
                     std::bind(&ResourceContainerImpl::getRequestHandler, this,
                             std::placeholders::_1, std::placeholders::_2));
@@ -232,6 +402,7 @@ namespace OIC
             server->setSetRequestHandler(
                     std::bind(&ResourceContainerImpl::setRequestHandler, this,
                             std::placeholders::_1, std::placeholders::_2));
+            info_logger() << "Registration finished " << strUri << "," << strResourceType << endl;
         }
 
         PrimitiveGetResponse ResourceContainerImpl::getRequestHandler(
@@ -242,14 +413,10 @@ namespace OIC
             if (m_mapServers.find(request.getResourceUri()) != m_mapServers.end()
                     && m_mapResources.find(request.getResourceUri()) != m_mapResources.end())
             {
-                // temp
-                m_mapResources[request.getResourceUri()]->getAttribute("");
-
-                for (auto i : m_mapResources[request.getResourceUri()]->m_mapAttributes)
+                for (string attrName : m_mapResources[request.getResourceUri()]->getAttributeNames())
                 {
-                    cout << "Setting attribute " << i.first.c_str() << ", " << i.second.c_str()
-                            << endl;
-                    attr[i.first.c_str()] = i.second.c_str();
+                    attr[attrName] = m_mapResources[request.getResourceUri()]->getAttribute(
+                            attrName);
                 }
             }
 
@@ -261,28 +428,17 @@ namespace OIC
         {
             ResourceAttributes attr = attributes;
 
-            cout << "Set request handler resource called.\n";
-
             if (m_mapServers.find(request.getResourceUri()) != m_mapServers.end()
                     && m_mapResources.find(request.getResourceUri()) != m_mapResources.end())
             {
-
-                cout << "Setting the attributes of the resource." << request.getResourceUri()
-                        << " it has "
-                        << m_mapResources[request.getResourceUri()]->m_mapAttributes.size()
-                        << " attributes " << std::endl;
-
-                for (auto i : m_mapResources[request.getResourceUri()]->m_mapAttributes)
+                for (string attrName : m_mapResources[request.getResourceUri()]->getAttributeNames())
                 {
-                    if (!attr[i.first].toString().empty())
+                    if (!attr[attrName].toString().empty())
                     {
-                        cout << "Setting " << i.first << endl;
-                        m_mapResources[request.getResourceUri()]->setAttribute(i.first,
-                                attr[i.first].toString());
+                        m_mapResources[request.getResourceUri()]->setAttribute(attrName,
+                                attr[attrName].toString());
                     }
                 }
-
-                // set m_mapAttributes to attributes
             }
 
             return PrimitiveSetResponse::create(attr);
@@ -290,7 +446,7 @@ namespace OIC
 
         void ResourceContainerImpl::unregisterResource(BundleResource *resource)
         {
-
+            // To be implemented
         }
 
         void ResourceContainerImpl::unregisterBundle(BundleInfo *bundleInfo)
@@ -298,15 +454,15 @@ namespace OIC
             if (((BundleInfoInternal *) bundleInfo)->isLoaded()
                     && !((BundleInfoInternal *) bundleInfo)->isActivated())
             {
-                unregisterBundle(bundleInfo->getId());
+                unregisterBundle(bundleInfo->getID());
             }
         }
 
-        void ResourceContainerImpl::unregisterBundle(int id)
+        void ResourceContainerImpl::unregisterBundle(string id)
         {
             void *bundleHandle = m_bundles[id]->getBundleHandle();
             info_logger() << "Unregister bundle: " << m_bundles[id]->getID() << ", "
-                    << m_bundles[id]->getId() << endl;
+                    << m_bundles[id]->getID() << endl;
             char *error;
             dlclose(bundleHandle);
             if ((error = dlerror()) != NULL)
@@ -317,19 +473,14 @@ namespace OIC
 
         ResourceContainerImpl *ResourceContainerImpl::getImplInstance()
         {
-            ResourceContainerImpl *ret = new ResourceContainerImpl();
-            return ret;
-        }
-
-        void ResourceContainerImpl::getCommonConfiguration(configInfo *configOutput)
-        {
-            m_config->getCommonConfiguration((Configuration::configInfo *) configOutput);
+            static ResourceContainerImpl m_instance;
+            return &m_instance;
         }
 
         void ResourceContainerImpl::getBundleConfiguration(std::string bundleId,
                 configInfo *configOutput)
         {
-            m_config->getBundleConfiguration(bundleId, (Configuration::configInfo *) configOutput);
+            m_config->getBundleConfiguration(bundleId, (configInfo *) configOutput);
         }
 
         void ResourceContainerImpl::getResourceConfiguration(std::string bundleId,
@@ -337,6 +488,65 @@ namespace OIC
         {
             m_config->getResourceConfiguration(bundleId, configOutput);
         }
+
+        void ResourceContainerImpl::onNotificationReceived(std::string strResourceUri)
+        {
+            info_logger() << "ResourceContainerImpl::onNotificationReceived\n\tnotification from "
+                    << strResourceUri << ".\n";
+
+            /*if (m_mapServers.find(strResourceUri) != m_mapServers.end())
+             {
+             //m_mapServers[strResourceUri]->notify();
+             }*/
+        }
+
+        void ResourceContainerImpl::addBundle(string bundleId, string bundleUri, string bundlePath,
+                std::map< string, string > params)
+        {
+            // To be implemented
+        }
+
+        void ResourceContainerImpl::removeBundle(string bundleId)
+        {
+            // To be implemented
+        }
+
+        std::list< BundleInfo* > ResourceContainerImpl::listBundles()
+        {
+            std::list< BundleInfo* > ret;
+            return ret;
+        }
+
+        void ResourceContainerImpl::addResourceConfig(string bundleId, string resourceUri,
+                std::map< string, string > params)
+        {
+            // To be implemented
+        }
+
+        void ResourceContainerImpl::removeResourceConfig(string bundleId, string resourceUri)
+        {
+            // To be implemented
+        }
+
+        void ResourceContainerImpl::startBundle(string bundleId)
+        {
+            activateBundle(m_bundles[bundleId]);
+        }
+
+        void ResourceContainerImpl::stopBundle(string bundleId)
+        {
+            deactivateBundle(m_bundles[bundleId]);
+        }
+
+        void ResourceContainerImpl::stopContainer()
+        {
+            // deactivate all bundles and unload them
+        }
+
+        JavaVM *ResourceContainerImpl::getJavaVM(string bundleId)
+        {
+            return m_bundleVM[bundleId];
+        }
     }
 }