Resource container skeleton for resource manipulation layer
authorMarkus Jung <markus.jung@samsung.com>
Fri, 5 Jun 2015 05:48:50 +0000 (14:48 +0900)
committerUze Choi <uzchoi@samsung.com>
Fri, 5 Jun 2015 07:40:59 +0000 (07:40 +0000)
First draft of the resource container skeleton, including several
header files and the folder structure.

Change-Id: Ieab184524b6a30424b1a30295f3192efc5b41680
Signed-off-by: Markus Jung <markus.jung@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/1200
Reviewed-by: Uze Choi <uzchoi@samsung.com>
Tested-by: Uze Choi <uzchoi@samsung.com>
12 files changed:
service/basis/resourceContainer/SConscript [new file with mode: 0644]
service/basis/resourceContainer/examples/SampleBundle/include/SampleBundle.h [new file with mode: 0644]
service/basis/resourceContainer/examples/SampleBundle/src/SampleBundle.cpp [new file with mode: 0644]
service/basis/resourceContainer/include/BundleActivator.h [new file with mode: 0644]
service/basis/resourceContainer/include/BundleInfo.h [new file with mode: 0644]
service/basis/resourceContainer/include/BundleInfoInternal.h [new file with mode: 0644]
service/basis/resourceContainer/include/ResourceContainer.h [new file with mode: 0644]
service/basis/resourceContainer/include/ResourceContainerInternal.h [new file with mode: 0644]
service/basis/resourceContainer/src/BundleActivator.cpp [new file with mode: 0644]
service/basis/resourceContainer/src/BundleInfo.cpp [new file with mode: 0644]
service/basis/resourceContainer/src/ContainerTest.cpp [new file with mode: 0644]
service/basis/resourceContainer/src/ResourceContainerInternal.cpp [new file with mode: 0644]

diff --git a/service/basis/resourceContainer/SConscript b/service/basis/resourceContainer/SConscript
new file mode 100644 (file)
index 0000000..8c9d587
--- /dev/null
@@ -0,0 +1,94 @@
+#******************************************************************
+#
+# Copyright 2014 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.
+#
+#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+##
+# things_manager project build script
+##
+import os
+Import('env')
+
+# Add third party libraries
+lib_env = env.Clone()
+SConscript(env.get('SRC_DIR') + '/service/third_party_libs.scons', exports = 'lib_env')
+
+resource_container_env = lib_env.Clone()
+target_os = env.get('TARGET_OS')
+######################################################################
+# Build flags
+######################################################################
+resource_container_env.AppendUnique(CPPPATH = [env.get('SRC_DIR')+'/extlibs', 'include', 'src'])
+
+if target_os not in ['windows', 'winrt']:
+    resource_container_env.AppendUnique(CXXFLAGS = ['-std=c++0x', '-Wall'])
+    if target_os != 'android':
+        resource_container_env.AppendUnique(CXXFLAGS = ['-pthread'])
+
+if target_os == 'android':
+    resource_container_env.AppendUnique(CXXFLAGS = ['-frtti', '-fexceptions'])
+    resource_container_env.PrependUnique(LIBS = ['gnustl_shared', 'compatibility', 'log'])
+    
+resource_container_env.AppendUnique(LIBS = ['dl'])
+
+######################################################################
+# Source files and Targets
+######################################################################
+res_container_src = env.Glob('src/*.cpp')
+res_container_static = resource_container_env.StaticLibrary('ResContainerLib', res_container_src)
+res_container_shared = resource_container_env.SharedLibrary('ResContainerLib', res_container_src)
+
+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'])
+
+SAMPLE_RESOURCE_BUNDLE_DIR = 'examples/SampleBundle/'
+sample_resource_bundle_env.AppendUnique(CPPPATH = [
+               SAMPLE_RESOURCE_BUNDLE_DIR + 'include',
+               'include/'
+               ])
+
+sample_resource_bundle_src = [ Glob(SAMPLE_RESOURCE_BUNDLE_DIR + 'src/*.cpp'), Glob('src/*.cpp')]
+
+SampleBundle = sample_resource_bundle_env.SharedLibrary('SampleBundle', sample_resource_bundle_src)
+sample_resource_bundle_env.InstallTarget(SampleBundle, 'libSampleBundle')
+
+######################################################################
+# Build Container Test
+######################################################################
+containertest_env = resource_container_env.Clone();
+containertest_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
+
+containertestapp = containertest_env.Program('ContainerTest', res_container_src)
+Alias("containertest", containertestapp)
+env.AppendTarget('containertest')
\ No newline at end of file
diff --git a/service/basis/resourceContainer/examples/SampleBundle/include/SampleBundle.h b/service/basis/resourceContainer/examples/SampleBundle/include/SampleBundle.h
new file mode 100644 (file)
index 0000000..bb0a6db
--- /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 SAMPLEBUNDLE_H_
+#define SAMPLEBUNDLE_H_
+
+#include <vector>
+
+#include "ResourceContainer.h"
+#include "BundleActivator.h"
+
+using namespace RC;
+
+class SampleBundle: public BundleActivator
+{
+    public:
+        SampleBundle();
+        ~SampleBundle();
+
+        void activateBundle(ResourceContainerInternal resourceContainer);
+        void deactivateBundle();
+
+        void createResource();
+        void destroyResource();
+
+        ResourceContainerInternal m_ResourceContainer;
+        std::vector<Resource *> m_vecResources;
+};
+
+
+class SampleBundleResource: public Resource
+{
+    public:
+        SampleBundleResource();
+        ~SampleBundleResource();
+};
+
+#endif /* SAMPLEBUNDLE_H_ */
diff --git a/service/basis/resourceContainer/examples/SampleBundle/src/SampleBundle.cpp b/service/basis/resourceContainer/examples/SampleBundle/src/SampleBundle.cpp
new file mode 100644 (file)
index 0000000..c294e95
--- /dev/null
@@ -0,0 +1,90 @@
+//******************************************************************
+//
+// 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 "SampleBundle.h"
+
+using namespace RC;
+
+SampleBundle *bundle;
+
+SampleBundle::SampleBundle()
+{
+}
+
+SampleBundle::~SampleBundle()
+{
+}
+
+void SampleBundle::activateBundle(ResourceContainerInternal resourceContainer)
+{
+    std::cout << "SampleBundle::activateBundle called" << std::endl;
+
+    m_ResourceContainer = resourceContainer;
+
+    // parse configuration, instantiate resource and register resources
+    ConfigParam configParam = m_ResourceContainer.getConfiguration(CONFIG_RESOURCES, "oic.bundle.sample");
+
+    std::cout << "Resource Information" << std::endl;
+    for (int i = 0; i < configParam.size(); i++)
+    {
+        for (map <string, string>::iterator itor = configParam[i].begin(); itor != configParam[i].end();
+             itor++)
+
+            cout << "key : " << itor->first << " | value : " << itor->second << endl;
+    }
+
+    // createResource();
+}
+
+void SampleBundle::deactivateBundle()
+{
+    std::cout << "SampleBundle::deactivateBundle called" << std::endl;
+    // unregister resources
+}
+
+void SampleBundle::createResource()
+{
+    //std::cout << "SampleBundle::createResource called" << std::endl;
+    //SampleBundleResource *newResource = new SampleBundleResource();
+    //m_vecResources.push_back(newResource);
+    //std::cout << "resourceContainer.registerResource()" << std::endl;
+}
+
+void SampleBundle::destroyResource()
+{
+    //std::cout << "SampleBundle::destroyResource called" << std::endl;
+    //std::cout << "resourceContainer.unregisterResource()" << std::endl;
+}
+
+extern "C" void externalActivateBundle(ResourceContainerInternal resourceContainer)
+{
+    printf("External activate\n");
+    bundle = new SampleBundle();
+    bundle->activateBundle(resourceContainer);
+}
+
+extern "C" void externalDeactivateBundle()
+{
+    if (!bundle)
+    {
+        bundle->deactivateBundle();
+    }
+    printf("External deactivate\n");
+}
\ No newline at end of file
diff --git a/service/basis/resourceContainer/include/BundleActivator.h b/service/basis/resourceContainer/include/BundleActivator.h
new file mode 100644 (file)
index 0000000..0fa4bad
--- /dev/null
@@ -0,0 +1,39 @@
+//******************************************************************
+//
+// 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 RESOURCEBUNDLE_H_
+#define RESOURCEBUNDLE_H_
+
+#include "ResourceContainerInternal.h"
+
+using namespace RC;
+
+namespace RC{
+       class BundleActivator {
+
+       public:
+               BundleActivator();
+               virtual ~BundleActivator();
+               virtual void activateBundle(ResourceContainerInternal resourceContainer);
+               virtual void deactivateBundle();
+       };
+}
+
+#endif /* RESOURCEBUNDLE_H_ */
diff --git a/service/basis/resourceContainer/include/BundleInfo.h b/service/basis/resourceContainer/include/BundleInfo.h
new file mode 100644 (file)
index 0000000..d207bce
--- /dev/null
@@ -0,0 +1,50 @@
+//******************************************************************
+//
+// 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 BUNDLEINFO_H_
+#define BUNDLEINFO_H_
+
+#include <string>
+
+using namespace std;
+
+namespace RC{
+       /*
+        * Describes a bundle with resources, that can be loaded dynamically.
+        */
+       class BundleInfo {
+               public:
+                       BundleInfo();
+                       virtual ~BundleInfo();
+                       void setName(string name);
+                       string getName();
+                       void setPath(string path);
+                       string getPath();
+                       void setVersion(string version);
+                       string getVersion();
+                       virtual int getId() = 0; // will be set by container
+                       static BundleInfo* createBundleInfo();
+               private:
+                       string m_name, m_path, m_version;
+       };
+}
+
+#endif /* BUNDLEINFO_H_ */
diff --git a/service/basis/resourceContainer/include/BundleInfoInternal.h b/service/basis/resourceContainer/include/BundleInfoInternal.h
new file mode 100644 (file)
index 0000000..70c1426
--- /dev/null
@@ -0,0 +1,58 @@
+//******************************************************************
+//
+// 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 BUNDLEINFOINTERNAL_H_
+#define BUNDLEINFOINTERNAL_H_
+
+#include <string>
+#include "BundleInfo.h"
+
+using namespace std;
+using namespace RC;
+
+namespace RC{
+       /*
+        * Adds resource container specific flags to the bundle info class.
+        */
+       class BundleInfoInternal : public BundleInfo {
+               public:
+                       BundleInfoInternal();
+                       BundleInfoInternal(BundleInfo* info);
+                       virtual ~BundleInfoInternal();
+                       void setName(string name);
+                       string getName();
+                       void setPath(string path);
+                       string getPath();
+                       void setVersion(string version);
+
+                       void setLoaded(bool loaded);
+                       bool isLoaded();
+                       void setActivated(bool activated);
+                       bool isActivated();
+                       int getId();
+                       void setId(int id);
+               private:
+                       bool m_loaded, m_activated;
+                       int m_id;
+       };
+}
+
+#endif /* BUNDLEINFOINTERNAL_H_ */
diff --git a/service/basis/resourceContainer/include/ResourceContainer.h b/service/basis/resourceContainer/include/ResourceContainer.h
new file mode 100644 (file)
index 0000000..76b74f2
--- /dev/null
@@ -0,0 +1,108 @@
+//******************************************************************
+//
+// 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 RESOURCECONTAINER_H_
+#define RESOURCECONTAINER_H_
+
+#include <iostream>
+#include <string>
+#include <vector>
+#include <map>
+
+#include "rapidxml/rapidxml.hpp"
+#include "rapidxml/rapidxml_print.hpp"
+
+using namespace std;
+
+namespace RC
+{
+    /*
+     * Describes a bundle with resources, that can be loaded dynamically.
+     */
+    class BundleInfo
+    {
+        public:
+            BundleInfo();
+            virtual ~BundleInfo();
+        public:
+            string id, name, path, version;
+
+    };
+
+    // Will be provided by the resource builder
+    class Resource
+    {
+
+    };
+
+    class ResourceContainer
+    {
+        public:
+            ResourceContainer();
+            virtual ~ResourceContainer();
+            virtual void init() = 0;
+            virtual void registerBundle(BundleInfo bundleinfo) = 0;
+            virtual void activateBundle(string id) = 0;
+            virtual void activateBundleByName(string name) = 0;
+            virtual void deactivateBundle(string id) = 0 ;
+            virtual void deactivateBundleByName(string id) = 0;
+            virtual vector<Resource *> listBundleResources(string id) = 0;
+    };
+
+    typedef vector < map < std::string, std::string > > ConfigParam;
+    typedef enum { CONFIG_COMMON, CONFIG_BUNDLES, CONFIG_RESOURCES } ConfigKey;
+
+    class ResourceContainerInternal : public ResourceContainer
+    {
+        public:
+            ResourceContainerInternal();
+            virtual ~ResourceContainerInternal();
+            void registerResource(Resource *resource);
+            void unregisterResource(Resource *resource);
+
+            ConfigParam getConfiguration(string configKey);
+            ConfigParam getConfiguration(ConfigKey configKey, string id = "");
+
+            void init();
+            void registerBundle(BundleInfo bundleinfo);
+            void activateBundle(string id);
+            void activateBundleByName(string name);
+            void deactivateBundle(string id);
+            void deactivateBundleByName(string name);
+            vector<Resource *> listBundleResources(string id);
+
+        private:
+            void getConfigDocument(std::string pathConfigFile, std::string *pConfigData);
+            void getConfigBundleData(rapidxml::xml_node< char > *configData, string BundleId,
+                                     ConfigParam *pConfigOutput);
+            void getConfigResourceData(rapidxml::xml_node< char > *configData, string BundleId,
+                                       ConfigParam *pConfigOutput);
+            void getCurrentPath(std::string *path);
+    };
+
+    // TBD
+    class InputPropertyDescriptor
+    {
+
+    };
+}
+
+
+#endif /* RESOURCECONTAINER_H_ */
diff --git a/service/basis/resourceContainer/include/ResourceContainerInternal.h b/service/basis/resourceContainer/include/ResourceContainerInternal.h
new file mode 100644 (file)
index 0000000..0a89743
--- /dev/null
@@ -0,0 +1,46 @@
+//******************************************************************
+//
+// 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 RESOURCECONTAINERINTERNAL_H_
+#define RESOURCECONTAINERINTERNAL_H_
+
+#include "ResourceContainer.h"
+
+using namespace RC;
+
+namespace RC{
+       class ResourceContainerInternal: public ResourceContainer {
+               public:
+                       ResourceContainerInternal();
+                       virtual ~ResourceContainerInternal();
+                       void registerResource(Resource* resource);
+                       void unregisterResource(Resource* resource);
+                       ConfigParam getConfiguration(string configKey);
+                       void init();
+                       void registerBundle(BundleInfo* bundleinfo);
+                       void activateBundle(string id);
+                       void activateBundleByName(string name);
+                       void deactivateBundle(string id);
+                       void deactivateBundleByName(string id);
+                       vector<Resource*> listBundleResources(string id);
+       };
+}
+
+#endif //RESOURCECONTAINERINTERNAL_H_
diff --git a/service/basis/resourceContainer/src/BundleActivator.cpp b/service/basis/resourceContainer/src/BundleActivator.cpp
new file mode 100644 (file)
index 0000000..72f1b42
--- /dev/null
@@ -0,0 +1,41 @@
+//******************************************************************
+//
+// 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 "BundleActivator.h"
+#include "ResourceContainer.h"
+
+using namespace RC;
+
+BundleActivator::BundleActivator(){
+
+}
+
+
+BundleActivator::~BundleActivator(){
+
+}
+
+void BundleActivator::activateBundle(ResourceContainerInternal resourceContainer){
+
+}
+
+void BundleActivator::deactivateBundle(){
+
+}
diff --git a/service/basis/resourceContainer/src/BundleInfo.cpp b/service/basis/resourceContainer/src/BundleInfo.cpp
new file mode 100644 (file)
index 0000000..097a3bf
--- /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.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+#include "BundleInfo.h"
+#include "BundleInfoInternal.h"
+
+namespace RC{
+       BundleInfo::BundleInfo(){
+
+       }
+
+       BundleInfo::~BundleInfo(){
+
+       }
+
+       void BundleInfo::setName(string name){
+               m_name = name;
+       }
+
+       string BundleInfo::getName(){
+               return m_name;
+       }
+
+       void BundleInfo::setPath(string path){
+               m_path = path;
+       }
+       string BundleInfo::getPath(){
+               return m_path;
+       }
+
+       void BundleInfo::setVersion(string version){
+               m_version = version;
+       }
+
+       string BundleInfo::getVersion(){
+               return m_version;
+       }
+
+       BundleInfo* BundleInfo::createBundleInfo(){
+               BundleInfoInternal* newBundleInfo = new BundleInfoInternal();
+               return newBundleInfo;
+       }
+}
diff --git a/service/basis/resourceContainer/src/ContainerTest.cpp b/service/basis/resourceContainer/src/ContainerTest.cpp
new file mode 100644 (file)
index 0000000..919ab76
--- /dev/null
@@ -0,0 +1,38 @@
+//******************************************************************
+//
+// 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 "ResourceContainerInternal.h"
+#include "BundleInfo.h"
+
+using namespace RC;
+
+int main(){
+       printf("Test\n");
+       BundleInfo* bundleInfo = BundleInfo::createBundleInfo();
+       bundleInfo->setPath("/home/iotivity/development/iotivity-mj-rc/iotivity-mj/out/linux/x86/release/service/resource-container/libSampleBundle.so");
+       bundleInfo->setVersion("1.0");
+       bundleInfo->setName("Sample Bundle");
+
+       ResourceContainerInternal container;
+       container.registerBundle(bundleInfo);
+
+       //bundleInfo.path = "/";
+       //bundleInfo.version = "1.0";
+}
diff --git a/service/basis/resourceContainer/src/ResourceContainerInternal.cpp b/service/basis/resourceContainer/src/ResourceContainerInternal.cpp
new file mode 100644 (file)
index 0000000..dca0c5a
--- /dev/null
@@ -0,0 +1,361 @@
+//******************************************************************
+//
+// 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 "ResourceContainerInternal.h"
+#include "BundleActivator.h"
+#include <dlfcn.h>
+#include <iostream>
+
+#include <dlfcn.h>
+#include <unistd.h>
+#include <string.h>
+#include <iostream>
+#include <fstream>
+
+
+using namespace std;
+
+static inline std::string trim_both(const std::string &str)
+{
+    int npos = str.find_first_not_of(" \t\v\n\r");
+
+    if (npos == -1)
+    {
+        return "";
+    }
+
+    unsigned int n = (unsigned int) npos;
+    std::string tempString = n == std::string::npos ? str : str.substr(n, str.length());
+
+    n = tempString.find_last_not_of(" \t\v\n\r");
+
+    return n == std::string::npos ? tempString : tempString.substr(0, n + 1);
+}
+
+namespace RC {
+
+       ResourceContainerInternal::ResourceContainerInternal() {
+               // TODO Auto-generated constructor stub
+
+       }
+
+       ResourceContainerInternal::~ResourceContainerInternal() {
+               // TODO Auto-generated destructor stub
+       }
+
+       void ResourceContainerInternal::init() {
+
+       }
+
+       // loads the bundle
+       void ResourceContainerInternal::registerBundle(BundleInfo* bundleInfo) {
+
+               cout << "\nRegistering bundle: " << bundleInfo->getPath() << "\n";
+               char* error;
+
+               typedef void (*activator_t)(ResourceContainerInternal *);
+               activator_t bundleActivator = NULL;
+
+               //sstream << bundleInfo.path << std::ends;
+
+               void *hModule = NULL;
+               hModule = dlopen(bundleInfo->getPath().c_str(), RTLD_LAZY);
+
+               if (hModule != NULL) {
+                       bundleActivator = (activator_t) dlsym(hModule,
+                                       "externalActivateBundle");
+                       if ((error = dlerror()) != NULL) {
+                               fprintf(stderr, "%s\n", error);
+                       }
+               } else {
+                       if ((error = dlerror()) != NULL) {
+                               fprintf(stderr, "%s\n", error);
+                       }
+               }
+
+               if (bundleActivator != NULL) {
+                       bundleActivator(this);
+               } else {
+                       //Unload module and return error
+                       printf("load unsuccessful.\n");
+               }
+       }
+
+       void ResourceContainerInternal::activateBundle(string id) {
+
+       }
+
+       void ResourceContainerInternal::activateBundleByName(string name) {
+
+       }
+
+       void ResourceContainerInternal::deactivateBundle(string id) {
+
+       }
+
+       void ResourceContainerInternal::deactivateBundleByName(string id) {
+
+       }
+
+       vector<Resource*> ResourceContainerInternal::listBundleResources(string id) {
+
+       }
+
+       void ResourceContainerInternal::registerResource(Resource* resource) {
+
+       }
+
+       void ResourceContainerInternal::unregisterResource(Resource* resource) {
+
+       }
+
+        ConfigParam getConfiguration(string configKey) {}
+
+           ConfigParam ResourceContainerInternal::getConfiguration(ConfigKey configKey, string id)
+           {
+               string pathXMLFile;
+               string strConfigData;
+               ConfigParam configOutput;
+
+               rapidxml::xml_document< char > xmlDoc;
+
+               rapidxml::xml_node< char > *root;
+               rapidxml::xml_node< char > *item;
+               rapidxml::xml_node< char > *subItem;
+
+               string strKey, strValue;
+
+               // TODO: temporary path and config file name
+               getCurrentPath(&pathXMLFile);
+               pathXMLFile.append("/");
+               pathXMLFile.append("ResourceContainerConfig.xml");
+
+               getConfigDocument(pathXMLFile, &strConfigData);
+
+               try
+               {
+                   xmlDoc.parse< 0 >((char *) strConfigData.c_str());
+
+                   // <container>
+                   root = xmlDoc.first_node();
+
+                   if (!root)
+                   {
+                       throw rapidxml::parse_error("No Root Element", 0);
+                   }
+
+                   switch (configKey)
+                   {
+                       case CONFIG_COMMON:
+                           for (item = root->first_node(); item; item = item->next_sibling())
+                           {
+                               strKey = item->name();
+                               strValue = item->value();
+
+                               if (!strKey.compare("config"))
+                               {
+                                   for (subItem = item->first_node(); subItem; subItem = subItem->next_sibling())
+                                   {
+                                       strKey = subItem->name();
+                                       strValue = subItem->value();
+
+                                       map < string, string > mapCommonConfig;
+                                       mapCommonConfig[trim_both(strKey)] = trim_both(strValue);
+
+                                       configOutput.push_back(mapCommonConfig);
+                                   }
+                                   break;
+                               }
+                           }
+                           break;
+
+                       case CONFIG_BUNDLES:
+                           getConfigBundleData(root, id, &configOutput);
+                           break;
+
+                       case CONFIG_RESOURCES:
+                           getConfigResourceData(root, id, &configOutput);
+                           break;
+
+                       default:
+                           assert(0);
+                   }
+               }
+               catch (rapidxml::parse_error &e)
+               {
+                   cout << "xml parsing failed !!" << endl;
+                   cout << e.what() << endl;
+               }
+
+               return configOutput;
+           }
+
+           void ResourceContainerInternal::getConfigDocument(std::string pathConfigFile,
+                   std::string *pConfigData)
+           {
+               std::basic_ifstream< char > xmlFile(pathConfigFile.c_str());
+
+               if (!xmlFile.fail())
+               {
+                   xmlFile.seekg(0, std::ios::end);
+                   unsigned int size = (unsigned int)xmlFile.tellg();
+                   xmlFile.seekg(0);
+
+                   std::vector< char > xmlData(size + 1);
+                   xmlData[size] = 0;
+
+                   xmlFile.read(&xmlData.front(), (std::streamsize) size);
+                   xmlFile.close();
+                   *pConfigData = std::string(xmlData.data());
+               }
+               else
+               {
+                   std::cout << "Configuration File load failed !!" << std::endl;
+               }
+           }
+
+           void ResourceContainerInternal::getConfigBundleData(rapidxml::xml_node< char > *rootData,
+                   string bundleId, ConfigParam *pConfigOutput)
+           {
+               rapidxml::xml_node< char > *item;
+               rapidxml::xml_node< char > *subItem;
+
+               string strKey, strValue;
+
+               try
+               {
+                   for (item = rootData->first_node(); item; item = item->next_sibling())
+                   {
+                       strKey = item->name();
+                       strValue = item->value();
+
+                       // <bundle>
+                       if (!strKey.compare("bundle"))
+                       {
+                           for (subItem = item->first_node(); subItem; subItem = subItem->next_sibling())
+                           {
+                               strKey = subItem->name();
+                               strValue = subItem->value();
+
+                               if (!bundleId.empty())
+                               {
+                                   if (!strKey.compare("bundleID") && strValue.compare(bundleId))
+                                       break;
+                               }
+
+                               // bundle info except resource data
+                               if (strKey.compare("resources"))
+                               {
+                                   map < string, string > mapBundleConfig;
+                                   mapBundleConfig[trim_both(strKey)] = trim_both(strValue);
+
+                                   pConfigOutput->push_back(mapBundleConfig);
+                               }
+                           }
+                       }
+                   }
+               }
+               catch (rapidxml::parse_error &e)
+               {
+                   cout << "xml parsing failed !!" << endl;
+                   cout << e.what() << endl;
+               }
+           }
+
+           void ResourceContainerInternal::getConfigResourceData(rapidxml::xml_node< char > *rootData,
+                   string bundleId, ConfigParam *pConfigOutput)
+           {
+               rapidxml::xml_node< char > *item;
+               rapidxml::xml_node< char > *subItem;
+               rapidxml::xml_node< char > *subItem2;
+               rapidxml::xml_node< char > *subItem3;
+
+               string strKey, strValue;
+
+               try
+               {
+                   for (item = rootData->first_node(); item; item = item->next_sibling())
+                   {
+                       strKey = item->name();
+                       strValue = item->value();
+
+                       // <bundle>
+                       if (!strKey.compare("bundle"))
+                       {
+                           for (subItem = item->first_node(); subItem; subItem = subItem->next_sibling())
+                           {
+                               strKey = subItem->name();
+                               strValue = subItem->value();
+
+                               if (!strKey.compare("bundleID") && strValue.compare(bundleId))
+                                   break;
+
+                               // <resources>
+                               if (!strKey.compare("resources"))
+                               {
+                                   for (subItem2 = subItem->first_node(); subItem2; subItem2 = subItem2->next_sibling())
+                                   {
+                                       strKey = subItem2->name();
+                                       strValue = subItem2->value();
+
+                                       // <resourceInfo>
+                                       if (!strKey.compare("resourceInfo"))
+                                       {
+                                           map <string, string> mapResourceInfo;
+
+                                           for (subItem3 = subItem2->first_node(); subItem3; subItem3 = subItem3->next_sibling())
+                                           {
+                                               strKey = subItem3->name();
+                                               strValue = subItem3->value();
+
+                                               mapResourceInfo[trim_both(strKey)] = trim_both(strValue);
+                                           }
+
+                                           pConfigOutput->push_back(mapResourceInfo);
+                                       }
+                                   }
+                               }
+                           }
+                       }
+                   }
+               }
+               catch (rapidxml::parse_error &e)
+               {
+                   cout << "xml parsing failed !!" << endl;
+                   cout << e.what() << endl;
+               }
+           }
+
+           void ResourceContainerInternal::getCurrentPath(std::string *path)
+           {
+               char        buffer[2048];
+               char    *strPath = NULL;
+
+               int length = readlink("/proc/self/exe", buffer, 2047);
+
+               buffer[length] = '\0';
+
+               strPath = strrchr(buffer, '/');
+
+               *strPath = '\0';
+
+               path->append(buffer);
+           }
+}