Protocol-bridge resource template and Hue example bundle
authorMarkus Jung <markus.jung@samsung.com>
Fri, 19 Jun 2015 06:09:43 +0000 (15:09 +0900)
committerUze Choi <uzchoi@samsung.com>
Fri, 19 Jun 2015 07:14:32 +0000 (07:14 +0000)
Added a first draft of the protocol bridge resource template and an example bundle that
illustrates the temmplate for the Philips Hue light. Namespace change to OIC::Service

Change-Id: I6e0a7e4b0db3e17d3032d53ac64bc3c4ac5afbf3
Signed-off-by: Markus Jung <markus.jung@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/1368
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
37 files changed:
service/basis/resourceContainer/SConscript
service/basis/resourceContainer/examples/HueSampleBundle/include/HueConnector.h [new file with mode: 0644]
service/basis/resourceContainer/examples/HueSampleBundle/include/HueLight.h [new file with mode: 0644]
service/basis/resourceContainer/examples/HueSampleBundle/include/HueSampleBundleActivator.h [new file with mode: 0644]
service/basis/resourceContainer/examples/HueSampleBundle/src/HueConnector.cpp [new file with mode: 0644]
service/basis/resourceContainer/examples/HueSampleBundle/src/HueLight.cpp [new file with mode: 0644]
service/basis/resourceContainer/examples/HueSampleBundle/src/HueSampleBundleActivator.cpp [new file with mode: 0644]
service/basis/resourceContainer/examples/ResourceContainerConfig.xml
service/basis/resourceContainer/examples/SampleBundle/include/DiscomfortIndexSensor.h
service/basis/resourceContainer/examples/SampleBundle/include/DiscomfortIndexSensorResource.h
service/basis/resourceContainer/examples/SampleBundle/include/SampleBundle.h
service/basis/resourceContainer/examples/SampleBundle/src/DiscomfortIndexSensor.cpp
service/basis/resourceContainer/examples/SampleBundle/src/DiscomfortIndexSensorResource.cpp
service/basis/resourceContainer/examples/SampleBundle/src/SampleBundle.cpp
service/basis/resourceContainer/include/BundleActivator.h
service/basis/resourceContainer/include/BundleInfo.h
service/basis/resourceContainer/include/BundleInfoInternal.h
service/basis/resourceContainer/include/BundleResource.h
service/basis/resourceContainer/include/Configuration.h
service/basis/resourceContainer/include/ProtocolBridgeConnector.h [new file with mode: 0644]
service/basis/resourceContainer/include/ProtocolBridgeResource.h [new file with mode: 0644]
service/basis/resourceContainer/include/ResourceContainer.h
service/basis/resourceContainer/include/ResourceContainerBundleAPI.h
service/basis/resourceContainer/include/ResourceContainerImpl.h
service/basis/resourceContainer/include/SoftSensorResource.h
service/basis/resourceContainer/src/BundleActivator.cpp
service/basis/resourceContainer/src/BundleInfo.cpp
service/basis/resourceContainer/src/BundleInfoInternal.cpp
service/basis/resourceContainer/src/BundleResource.cpp
service/basis/resourceContainer/src/Configuration.cpp
service/basis/resourceContainer/src/ContainerTest.cpp
service/basis/resourceContainer/src/ProtocolBridgeConnector.cpp [new file with mode: 0644]
service/basis/resourceContainer/src/ProtocolBridgeResource.cpp [new file with mode: 0644]
service/basis/resourceContainer/src/ResourceContainer.cpp
service/basis/resourceContainer/src/ResourceContainerBundleAPI.cpp
service/basis/resourceContainer/src/ResourceContainerImpl.cpp
service/basis/resourceContainer/src/SoftSensorResource.cpp

index 01af0b6..1441c73 100644 (file)
@@ -94,6 +94,27 @@ SampleBundle = sample_resource_bundle_env.SharedLibrary('SampleBundle', sample_r
 sample_resource_bundle_env.InstallTarget(SampleBundle, 'libSampleBundle')
 
 ######################################################################
+# build hue sample bundle
+######################################################################
+
+hue_resource_bundle_env = resource_container_env.Clone()
+hue_resource_bundle_env.AppendUnique(CCFLAGS = ['-fPIC'])
+
+HUE_RESOURCE_BUNDLE_DIR = 'examples/HueSampleBundle/'
+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)
+hue_resource_bundle_env.InstallTarget(HueBundle, 'libHueBundle')
+
+
+######################################################################
 # Build Container Test
 ######################################################################
 containertest_env = resource_container_env.Clone();
diff --git a/service/basis/resourceContainer/examples/HueSampleBundle/include/HueConnector.h b/service/basis/resourceContainer/examples/HueSampleBundle/include/HueConnector.h
new file mode 100644 (file)
index 0000000..7a6ed67
--- /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 HUECONNECTOR_H_
+#define HUECONNECTOR_H_
+
+#include "ProtocolBridgeConnector.h"
+
+using namespace OIC::Service;
+
+namespace OIC
+{
+    namespace Service
+    {
+        class HueConnector: public ProtocolBridgeConnector
+        {
+
+        public:
+            HueConnector();
+            virtual ~HueConnector();
+            void connect();
+            void disconnect();
+            std::string transmit(std::string target, std::string data);
+            std::string read(std::string target);
+        };
+    }
+}
+
+#endif /* HUECONNECTOR_H_ */
diff --git a/service/basis/resourceContainer/examples/HueSampleBundle/include/HueLight.h b/service/basis/resourceContainer/examples/HueSampleBundle/include/HueLight.h
new file mode 100644 (file)
index 0000000..34269b2
--- /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 HUELIGHT_H_
+#define HUELIGHT_H_
+
+#include "ProtocolBridgeResource.h"
+#include "HueConnector.h"
+
+using namespace OIC::Service;
+
+namespace OIC
+{
+    namespace Service
+    {
+        class HueLight: public ProtocolBridgeResource
+        {
+
+        public:
+            HueLight();
+            HueLight(HueConnector* connector, std::string address);
+            virtual ~HueLight();
+            void getAttribute(string attributeName);
+            void setAttribute(string attributeName, string value);
+            virtual void initAttributes();
+        private:
+            std::string m_address;
+            HueConnector* m_connector;
+        };
+    }
+}
+
+#endif /* HUEGATEWAYCLIENT_H_ */
diff --git a/service/basis/resourceContainer/examples/HueSampleBundle/include/HueSampleBundleActivator.h b/service/basis/resourceContainer/examples/HueSampleBundle/include/HueSampleBundleActivator.h
new file mode 100644 (file)
index 0000000..3fff8eb
--- /dev/null
@@ -0,0 +1,57 @@
+//******************************************************************
+//
+// 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 HUESAMPLEBUNDLEACTIVATOR_H_
+#define HUESAMPLEBUNDLEACTIVATOR_H_
+
+#include "ResourceContainerBundleAPI.h"
+#include "BundleActivator.h"
+#include "BundleResource.h"
+#include "HueConnector.h"
+
+using namespace OIC::Service;
+
+namespace OIC
+{
+    namespace Service
+    {
+        class HueSampleBundleActivator: public BundleActivator
+        {
+        public:
+            HueSampleBundleActivator();
+            ~HueSampleBundleActivator();
+
+            void activateBundle(ResourceContainerBundleAPI *resourceContainer,
+                    std::string bundleId);
+            void deactivateBundle();
+
+            void createResource(Configuration::resourceInfo);
+            void destroyResource(BundleResource *);
+
+            std::string m_bundleId;
+            ResourceContainerBundleAPI *m_pResourceContainer;
+            std::vector< BundleResource * > m_vecResources;
+        private:
+            HueConnector* m_connector;
+        };
+    }
+}
+
+#endif /* SAMPLEBUNDLE_H_ */
diff --git a/service/basis/resourceContainer/examples/HueSampleBundle/src/HueConnector.cpp b/service/basis/resourceContainer/examples/HueSampleBundle/src/HueConnector.cpp
new file mode 100644 (file)
index 0000000..96f64bc
--- /dev/null
@@ -0,0 +1,124 @@
+//******************************************************************
+//
+// 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 "HueConnector.h"
+#include <curl/curl.h>
+#include <string.h>
+#include <iostream>
+
+using namespace OIC::Service;
+
+HueConnector::HueConnector(){
+
+}
+
+HueConnector::~HueConnector(){
+
+}
+
+void HueConnector::connect(){
+
+}
+
+void HueConnector::disconnect(){
+
+}
+
+std::string HueConnector::transmit(std::string target, std::string payload){
+    std::cout << "Transmitting to " << target << " "  << payload << endl;
+    CURL *curl;
+    CURLcode res;
+    struct curl_slist *headers = NULL;                      /* http headers to send with request */
+    /* set content type */
+    headers = curl_slist_append(headers, "Accept: application/json");
+    headers = curl_slist_append(headers, "Content-Type: application/json");
+
+    const char *cstr = payload.c_str();
+
+    curl = curl_easy_init();
+
+    if(curl) {
+        curl_easy_setopt(curl, CURLOPT_URL, target.c_str());
+        curl_easy_setopt(curl, CURLOPT_POSTFIELDS, cstr);
+        curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "PUT");
+
+        /* if we don't provide POSTFIELDSIZE, libcurl will strlen() by
+       itself */
+        curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)strlen(cstr));
+
+        curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
+
+        /* Perform the request, res will get the return code */
+        res = curl_easy_perform(curl);
+        /* Check for errors */
+        if(res != CURLE_OK)
+            fprintf(stderr, "curl_easy_perform() failed: %s\n",
+              curl_easy_strerror(res));
+
+        /* always cleanup */
+        curl_easy_cleanup(curl);
+    }
+    return "";
+}
+
+static int writer(char* data, size_t size, size_t nmemb, std::string *buffer_in){
+    buffer_in->append(data, size * nmemb);
+    return size * nmemb;
+}
+
+std::string HueConnector::read(std::string target){
+    std::cout << "Reading from to " << target << endl;
+    CURL *curl;
+    CURLcode res;
+    struct curl_slist *headers = NULL;                      /* http headers to send with request */
+    /* set content type */
+    headers = curl_slist_append(headers, "Accept: application/json");
+    headers = curl_slist_append(headers, "Content-Type: application/json");
+
+
+    curl = curl_easy_init();
+
+    if(curl) {
+        curl_easy_setopt(curl, CURLOPT_URL, target.c_str());
+        curl_easy_setopt(curl, CURLOPT_HTTPGET, 1);
+        curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "PUT");
+
+        curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
+        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writer);
+        std::string response;
+        curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response);
+
+        /* Perform the request, res will get the return code */
+        res = curl_easy_perform(curl);
+        /* Check for errors */
+        if(res != CURLE_OK){
+            fprintf(stderr, "curl_easy_perform() failed: %s\n",
+              curl_easy_strerror(res));
+        }
+        else{
+            cout << "Response is: " << response << endl;
+        }
+
+        /* always cleanup */
+        curl_easy_cleanup(curl);
+    }
+    return "";
+}
+
diff --git a/service/basis/resourceContainer/examples/HueSampleBundle/src/HueLight.cpp b/service/basis/resourceContainer/examples/HueSampleBundle/src/HueLight.cpp
new file mode 100644 (file)
index 0000000..619852d
--- /dev/null
@@ -0,0 +1,71 @@
+//******************************************************************
+//
+// 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 "HueLight.h"
+
+#include <iostream>
+
+using namespace OIC::Service;
+
+HueLight::HueLight(){
+
+}
+
+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){
+
+}
+
+void HueLight::initAttributes(){
+    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"));
+}
+
+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 + "}");
+    }
+
+    if(attributeName == "dim"){
+        //m_connector->transmit(this->m_address + "/state", "{\"bri\":" + (value * 2.5) + "}");
+        m_connector->transmit(this->m_address + "/state", "{\"bri\":" + value + "}");
+    }
+
+    if(attributeName == "color"){
+        //m_connector->transmit(this->m_address+ "/state", "{\"hue\":" + (value * 650)  + "}");
+        m_connector->transmit(this->m_address+ "/state", "{\"hue\":" + value   + "}");
+    }
+}
+
diff --git a/service/basis/resourceContainer/examples/HueSampleBundle/src/HueSampleBundleActivator.cpp b/service/basis/resourceContainer/examples/HueSampleBundle/src/HueSampleBundleActivator.cpp
new file mode 100644 (file)
index 0000000..120cdb0
--- /dev/null
@@ -0,0 +1,120 @@
+//******************************************************************
+//
+// 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 "HueSampleBundleActivator.h"
+#include "HueLight.h"
+
+#include <algorithm>
+#include <vector>
+
+using namespace OIC::Service;
+
+HueSampleBundleActivator *bundle;
+
+HueSampleBundleActivator::HueSampleBundleActivator()
+{
+}
+
+HueSampleBundleActivator::~HueSampleBundleActivator()
+{
+}
+
+void HueSampleBundleActivator::activateBundle(ResourceContainerBundleAPI *resourceContainer,
+                                  std::string bundleId)
+{
+    std::cout << "HueSampleBundle::activateBundle called" << std::endl;
+
+    m_pResourceContainer = resourceContainer;
+    m_bundleId = bundleId;
+    m_connector = new HueConnector();
+
+    vector<Configuration::resourceInfo> resourceConfig;
+
+    resourceContainer->getResourceConfiguration(m_bundleId, &resourceConfig);
+
+    for (vector<Configuration::resourceInfo>::iterator itor = resourceConfig.begin();
+         itor != resourceConfig.end(); itor++)
+    {
+        createResource(*itor);
+    }
+}
+
+void HueSampleBundleActivator::deactivateBundle()
+{
+    std::cout << "HueSampleBundle::deactivateBundle called" << std::endl;
+
+    for (std::vector<BundleResource *>::iterator itor = m_vecResources.begin();
+         itor != m_vecResources.end(); itor++)
+    {
+        destroyResource(*itor);
+    }
+}
+
+
+void HueSampleBundleActivator::createResource(Configuration::resourceInfo resourceInfo)
+{
+    std::cout << "HueSampleBundle::createResource called" << std::endl;
+
+    if(resourceInfo.resourceType == "oic.light.control"){
+        static int lightCount = 1;
+        HueLight* hueLight = new HueLight(m_connector, resourceInfo.address);
+        resourceInfo.uri = "/hue/light/" + std::to_string(lightCount++);
+        std::cout << "Registering resource " << resourceInfo.uri << std::endl;
+        hueLight->m_uri = resourceInfo.uri;
+        hueLight->m_resourceType = resourceInfo.resourceType;
+        hueLight->m_name = resourceInfo.name;
+
+        m_pResourceContainer->registerResource(hueLight);
+        m_vecResources.push_back(hueLight);
+    }
+}
+
+
+void HueSampleBundleActivator::destroyResource(BundleResource *resource)
+{
+    std::cout << "HueSampleBundle::destroyResource called" << std::endl;
+
+    std::vector <BundleResource *>::iterator itor;
+
+    itor = std::find(m_vecResources.begin(), m_vecResources.end(), resource);
+
+    if (itor != m_vecResources.end())
+        m_vecResources.erase(itor);
+
+    // check
+    //delete resource;
+
+    m_pResourceContainer->unregisterResource(resource);
+}
+
+extern "C" void externalActivateBundle(ResourceContainerBundleAPI *resourceContainer,
+                                       std::string bundleId)
+{
+    bundle = new HueSampleBundleActivator();
+    bundle->activateBundle(resourceContainer, bundleId);
+}
+
+extern "C" void externalDeactivateBundle()
+{
+    if (!bundle)
+    {
+        bundle->deactivateBundle();
+    }
+}
index b18d32d..4bceb0f 100644 (file)
@@ -3,7 +3,7 @@
     <bundle>
         <id>oic.bundle.discomfortIndexSensor</id>
         <path>libSampleBundle.so</path>
-        <version>libSampleBundle.so</version>
+        <version>1.0.0</version>
         <resources>
             <resourceInfo>
                 <name>DiscomfortIndexSensor1</name>
             </resourceInfo>       
         </resources>
     </bundle>
+    <bundle>
+        <id>oic.bundle.hueSample</id>
+        <path>libHueBundle.so</path>
+        <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 a30c1f4..87d830e 100644 (file)
@@ -1,6 +1,6 @@
 /******************************************************************
 *
-* Copyright 2014 Samsung Electronics All Rights Reserved.
+* Copyright 2015 Samsung Electronics All Rights Reserved.
 *
 *
 *
 */
 
 #include <iostream>
-#include <vector>
-#include <map>
 
-// temp
-#include "BundleResource.h"
 #include "SoftSensorResource.h"
 
+using namespace OIC::Service;
+
 namespace DiscomfortIndexSensorName
 {
 #define PHYSICAL_EA 2
@@ -74,13 +72,13 @@ namespace DiscomfortIndexSensorName
         public:
             DiscomfortIndexSensor();
 
-            int runLogic(std::vector< RC::SoftSensorResource::SensorData > &sensorData);
-            DIResult getInput(std::vector< RC::SoftSensorResource::SensorData > &contextDataList,
+            int runLogic(std::vector< SoftSensorResource::SensorData > &sensorData);
+            DIResult getInput(std::vector< SoftSensorResource::SensorData > &contextDataList,
                               InValue *data);
             DIResult makeDiscomfortIndex(InValue *data);
-            RC::SoftSensorResource::SensorData setOutput(int property_count, InValue *data);
+            SoftSensorResource::SensorData setOutput(int property_count, InValue *data);
 
-            RC::SoftSensorResource::SensorData m_output;
+            SoftSensorResource::SensorData m_output;
     };
 };
 
index 3364037..216b954 100644 (file)
 #ifndef DISCOMFORTINDEXSENSORRESOURCE_H_
 #define DISCOMFORTINDEXSENSORRESOURCE_H_
 
-#include "BundleResource.h"
+#include <iostream>
+
+#include "SoftSensorResource.h"
 #include "DiscomfortIndexSensor.h"
 
 using namespace DiscomfortIndexSensorName;
-using namespace RC;
+using namespace OIC::Service;
 
 class DiscomfortIndexSensorResource : public SoftSensorResource
 {
@@ -33,10 +35,11 @@ class DiscomfortIndexSensorResource : public SoftSensorResource
         DiscomfortIndexSensorResource();
         ~DiscomfortIndexSensorResource();
 
-        void onGetRequest(std::map <std::string, std::string> *attributes);
-        void onSetRequest(std::map <std::string, std::string> attributes);
+        void getAttribute(string attributeName);
+        void setAttribute(string attributeName, string value);
+        virtual void initAttributes();
 
-        void onInputDataReceived(std::vector <SensorData> inputs);
+        void setInputAttributes(vector < SensorData > inputs);
 
     private:
         DiscomfortIndexSensor *m_pDiscomfortIndexSensor;
index f241a7b..8a1aad4 100644 (file)
@@ -28,7 +28,7 @@
 #include "BundleActivator.h"
 #include "BundleResource.h"
 
-using namespace RC;
+using namespace OIC::Service;
 
 class SampleBundle: public BundleActivator
 {
index f4b94ab..ac3fe2f 100644 (file)
@@ -1,6 +1,6 @@
 /******************************************************************
  *
- * Copyright 2014 Samsung Electronics All Rights Reserved.
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
  *
  *
  *
@@ -49,7 +49,7 @@ DiscomfortIndexSensor::DiscomfortIndexSensor()
     m_result.m_discomfortIndex = "";
 }
 
-int DiscomfortIndexSensor::runLogic(std::vector< RC::SoftSensorResource::SensorData > &sensorData)
+int DiscomfortIndexSensor::runLogic(std::vector< OIC::Service::SoftSensorResource::SensorData > &sensorData)
 {
     std::cout << "[DiscomfortIndexSensor] DiscomfortIndexSensor::" << __func__ << " is called."
               << std::endl;
@@ -75,7 +75,7 @@ int DiscomfortIndexSensor::runLogic(std::vector< RC::SoftSensorResource::SensorD
 /**
  * Get Input data (temperature, humidity) using resource Client of Iotivity base.
  */
-DIResult DiscomfortIndexSensor::getInput(std::vector< RC::SoftSensorResource::SensorData >
+DIResult DiscomfortIndexSensor::getInput(std::vector< OIC::Service::SoftSensorResource::SensorData >
         &sensorData, InValue *data)
 {
     int result_flag = 0;
@@ -208,10 +208,10 @@ DIResult DiscomfortIndexSensor::makeDiscomfortIndex(InValue *data)
     return SUCCESS;
 }
 
-RC::SoftSensorResource::SensorData DiscomfortIndexSensor::setOutput(int property_count,
+OIC::Service::SoftSensorResource::SensorData DiscomfortIndexSensor::setOutput(int property_count,
         InValue *data)
 {
-    RC::SoftSensorResource::SensorData out;
+    OIC::Service::SoftSensorResource::SensorData out;
 
     std::map < std::string, std::string > output_property;
 
index 4603f24..1a791a9 100644 (file)
 DiscomfortIndexSensorResource::DiscomfortIndexSensorResource()
 {
     m_pDiscomfortIndexSensor = new DiscomfortIndexSensor();
-
-    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"));
-
+    initAttributes();
 }
 
 DiscomfortIndexSensorResource::~DiscomfortIndexSensorResource()
@@ -35,18 +31,26 @@ DiscomfortIndexSensorResource::~DiscomfortIndexSensorResource()
     delete m_pDiscomfortIndexSensor;
 }
 
-void DiscomfortIndexSensorResource::onGetRequest(std::map <std::string, std::string> *attributes)
+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"));
+}
+
+void DiscomfortIndexSensorResource::getAttribute(string attributeName)
 {
-    // TODO : make m_outputs into m_mapAttributes format
-    *attributes = m_mapAttributes;
+    cout << "DiscomfortIndexSensorResource::getAttribute called !!" << endl;
 }
 
-void DiscomfortIndexSensorResource::onSetRequest(std::map <std::string, std::string> attributes)
+void DiscomfortIndexSensorResource::setAttribute(string attributeName, string value)
 {
+    cout << "DiscomfortIndexSensorResource::setAttribute called !!" << endl;
+
+    m_mapAttributes[attributeName] = value;
 }
 
-void DiscomfortIndexSensorResource::onInputDataReceived(std::vector <SensorData> inputs)
+void DiscomfortIndexSensorResource::setInputAttributes(vector < SensorData > inputs)
 {
-    m_vecInputs = inputs;
-    m_pDiscomfortIndexSensor->runLogic(m_vecInputs);
+    m_pDiscomfortIndexSensor->runLogic(inputs);
 }
index 095a39e..5ed7fa8 100644 (file)
@@ -21,7 +21,7 @@
 #include "SampleBundle.h"
 #include "DiscomfortIndexSensorResource.h"
 
-using namespace RC;
+using namespace OIC::Service;
 
 SampleBundle *bundle;
 
@@ -67,9 +67,15 @@ void SampleBundle::deactivateBundle()
 void SampleBundle::createResource(Configuration::resourceInfo resourceInfo)
 {
     std::cout << "SampleBundle::createResource called" << std::endl;
-
+    static int discomfortIndexSensorCount = 0;
     DiscomfortIndexSensorResource *newResource = new DiscomfortIndexSensorResource();
-    newResource->setResourceInfo(resourceInfo);
+    if(!resourceInfo.uri.empty()){
+        newResource->m_uri = resourceInfo.uri;
+    }
+    else{
+        newResource->m_uri = "sampleBundle/discomfortIndex/" + std::to_string(discomfortIndexSensorCount++);
+    }
+    newResource->m_resourceType = resourceInfo.resourceType;
 
     m_pResourceContainer->registerResource(newResource);
 
index 9ba5ff5..eeae19c 100644 (file)
 
 #include "ResourceContainerBundleAPI.h"
 
-using namespace RC;
+using namespace OIC::Service;
 
-namespace RC
+namespace OIC
 {
-    class BundleActivator
+    namespace Service
     {
+        class BundleActivator
+        {
 
         public:
             BundleActivator();
             virtual ~BundleActivator();
-            virtual void activateBundle(ResourceContainerBundleAPI *resourceContainer, std::string bundleId);
+            virtual void activateBundle(ResourceContainerBundleAPI *resourceContainer,
+                    std::string bundleId);
             virtual void deactivateBundle();
-    };
+        };
+    }
 }
 
 #endif /* RESOURCEBUNDLE_H_ */
index 1c725b8..d8d6036 100644 (file)
 
 using namespace std;
 
-namespace RC
+namespace OIC
 {
-    /*
-     * Describes a bundle with resources, that can be loaded dynamically.
-     */
-    class BundleInfo
+    namespace Service
     {
-    public:
-        BundleInfo();
-        virtual ~BundleInfo();
-        virtual void setID(string name) = 0;
-        virtual string getID() = 0;
-        virtual void setPath(string path) = 0;
-        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;
-    };
+        /*
+         * Describes a bundle with resources, that can be loaded dynamically.
+         */
+        class BundleInfo
+        {
+        public:
+            BundleInfo();
+            virtual ~BundleInfo();
+            virtual void setID(string name) = 0;
+            virtual string getID() = 0;
+            virtual void setPath(string path) = 0;
+            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;
+        };
+    }
 }
 
 #endif /* BUNDLEINFO_H_ */
index be811da..e88e66c 100644 (file)
 #include "ResourceContainerBundleAPI.h"
 
 using namespace std;
-using namespace RC;
+using namespace OIC::Service;
 
-namespace RC
-{
-    typedef void activator_t(ResourceContainerBundleAPI *, std::string bundleId);
-    typedef void deactivator_t(void);
+namespace OIC{
+    namespace Service{
 
-    class BundleInfoInternal: public BundleInfo
-    {
-        public:
-            BundleInfoInternal();
-            BundleInfoInternal(BundleInfo *info);
-            virtual ~BundleInfoInternal();
-            void setID(string id);
-            string getID();
-            void setPath(string path);
-            string getPath();
-            void setVersion(string version);
-            string getVersion();
+        typedef void activator_t(ResourceContainerBundleAPI *, std::string bundleId);
+        typedef void deactivator_t(void);
 
-            void setLoaded(bool loaded);
-            bool isLoaded();
-            void setActivated(bool activated);
-            bool isActivated();
-            int getId();
-            void setId(int id);
+        class BundleInfoInternal: public BundleInfo
+        {
+            public:
+                BundleInfoInternal();
+                BundleInfoInternal(BundleInfo *info);
+                virtual ~BundleInfoInternal();
+                void setID(string id);
+                string getID();
+                void setPath(string path);
+                string getPath();
+                void setVersion(string version);
+                string getVersion();
 
-            void setBundleActivator(activator_t *);
-            activator_t *getBundleActivator();
+                void setLoaded(bool loaded);
+                bool isLoaded();
+                void setActivated(bool activated);
+                bool isActivated();
+                int getId();
+                void setId(int id);
 
-            void setBundleDeactivator(deactivator_t *);
-            deactivator_t *getBundleDeactivator();
+                void setBundleActivator(activator_t *);
+                activator_t *getBundleActivator();
 
-            void setBundleHandle(void *);
-            void *getBundleHandle();
+                void setBundleDeactivator(deactivator_t *);
+                deactivator_t *getBundleDeactivator();
 
-        private:
-            bool m_loaded, m_activated;
-            int m_id;
-            activator_t *m_activator;
-            deactivator_t *m_deactivator;
-            void *m_bundleHandle;
-    };
+                void setBundleHandle(void *);
+                void *getBundleHandle();
+
+            private:
+                bool m_loaded, m_activated;
+                int m_id;
+                activator_t *m_activator;
+                deactivator_t *m_deactivator;
+                void *m_bundleHandle;
+        };
+    }
 }
 
 #endif /* BUNDLEINFOINTERNAL_H_ */
index 6f9b696..12aab49 100644 (file)
 #ifndef BUNDLERESOURCE_H_
 #define BUNDLERESOURCE_H_
 
-#include "Configuration.h"
 #include <map>
+#include <vector>
 #include <string>
 
-namespace RC
+using namespace std;
+
+namespace OIC
 {
-    class BundleResource
+    namespace Service
     {
+        class BundleResource
+        {
         public:
             BundleResource();
             virtual ~BundleResource();
 
-            virtual void onGetRequest(std::map <std::string, std::string> *attributes) = 0;
-            virtual void onSetRequest(std::map <std::string, std::string> attributes) = 0;
-
-            Configuration::resourceInfo getResourceInfo();
-            void setResourceInfo(Configuration::resourceInfo resourceInfo);
+            // TODO use type variant mechanism
+            virtual void getAttribute(string attributeName) = 0;
+            virtual void setAttribute(string attributeName, string value) = 0;
+            virtual void initAttributes() = 0;
 
         public:
-            std::map <std::string, std::string> m_mapAttributes;
-            Configuration::resourceInfo m_resourceInfo;
-    };
-
+            string m_name, m_uri, m_resourceType, m_address;
+            map< string, vector< map< string, string > > > m_mapResourceProperty;
+            map< string, string > m_mapAttributes;
+        };
+    }
 }
 
 #endif
index b48e795..20f61ce 100644 (file)
 #include "ResourceContainer.h"
 #include "BundleInfo.h"
 
-using namespace RC;
+using namespace OIC::Service;
 
-namespace RC
+namespace OIC
 {
-
-
-    class Configuration
+    namespace Service
     {
+        class Configuration
+        {
         public:
-            typedef vector<std::map <std::string, std::string>> configInfo;
+            typedef vector< std::map< std::string, std::string > > configInfo;
             struct resourceInfo
             {
                 std::string name;
                 std::string uri;
                 std::string resourceType;
-                std::map < std::string, std::vector< std::map< std::string, std::string > > > resourceProperty;
+                std::string address;
+                std::map< std::string, std::vector< std::map< std::string, std::string > > > resourceProperty;
             };
 
             Configuration();
@@ -56,7 +57,8 @@ namespace RC
 
             void getCommonConfiguration(configInfo *configOutput);
             void getBundleConfiguration(std::string bundleId, configInfo *configOutput);
-            void getResourceConfiguration(std::string bundleId, std::vector<resourceInfo> *configOutput);
+            void getResourceConfiguration(std::string bundleId,
+                    std::vector< resourceInfo > *configOutput);
             void getConfiguredBundles(configInfo *configOutput);
 
         private:
@@ -64,7 +66,8 @@ namespace RC
             void getCurrentPath(std::string *path);
 
             string m_pathConfigFile, m_configFile;
-    };
+        };
+    }
 }
 
 #endif
diff --git a/service/basis/resourceContainer/include/ProtocolBridgeConnector.h b/service/basis/resourceContainer/include/ProtocolBridgeConnector.h
new file mode 100644 (file)
index 0000000..88d033b
--- /dev/null
@@ -0,0 +1,43 @@
+//******************************************************************
+//
+// 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 PROTOCOLBRIDGECONNECTOR_H_
+#define PROTOCOLBRIDGECONNECTOR_H_
+
+#include "BundleResource.h"
+#include <map>
+#include <string>
+
+namespace OIC
+{
+    namespace Service
+    {
+        class ProtocolBridgeConnector
+        {
+        public:
+            ProtocolBridgeConnector();
+            virtual ~ProtocolBridgeConnector();
+            virtual void connect() = 0;
+            virtual void disconnect() = 0;
+        };
+    }
+}
+
+#endif
diff --git a/service/basis/resourceContainer/include/ProtocolBridgeResource.h b/service/basis/resourceContainer/include/ProtocolBridgeResource.h
new file mode 100644 (file)
index 0000000..03543ed
--- /dev/null
@@ -0,0 +1,43 @@
+//******************************************************************
+//
+// 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 PROTOCOLBRIDGERESOURCE_H_
+#define PROTOCOLBRIDGERESOURCE_H_
+
+#include "BundleResource.h"
+#include <map>
+#include <string>
+
+namespace OIC
+{
+    namespace Service
+    {
+        class ProtocolBridgeResource: public BundleResource
+        {
+        public:
+            ProtocolBridgeResource();
+            virtual ~ProtocolBridgeResource();
+            virtual void getAttribute(string attributeName) = 0;
+            virtual void setAttribute(string attributeName, string value) = 0;
+        };
+    }
+}
+
+#endif
index 53cf80f..16643d8 100644 (file)
 
 using namespace std;
 
-namespace RC
+namespace OIC
 {
-
-    // placeholder
-    class Resource
+    namespace Service
     {
+        // placeholder
+        class Resource
+        {
 
-    };
+        };
 
-    class ResourceContainer
-    {
+        class ResourceContainer
+        {
         public:
             ResourceContainer();
             virtual ~ResourceContainer();
@@ -58,7 +59,8 @@ namespace RC
             virtual vector< Resource * > listBundleResources(string id) = 0;
 
             static ResourceContainer *getInstance();
-    };
+        };
+    }
 }
 
 #endif /* RESOURCECONTAINER_H_ */
index f4929a7..74a925a 100644 (file)
 #include "Configuration.h"
 #include "BundleResource.h"
 
-using namespace RC;
+using namespace OIC::Service;
 
-namespace RC
+namespace OIC
 {
-    class ResourceContainerBundleAPI : public Configuration
+    namespace Service
     {
+        class ResourceContainerBundleAPI: public Configuration
+        {
         public:
-            typedef std::map <std::string, std::string> configInfo;
+            typedef std::map< std::string, std::string > configInfo;
             ResourceContainerBundleAPI();
             virtual ~ResourceContainerBundleAPI();
             virtual void registerResource(BundleResource *resource) = 0;
@@ -45,10 +47,11 @@ namespace RC
             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;
+                    std::vector< resourceInfo > *configOutput) = 0;
 
             static ResourceContainerBundleAPI *getInstance();
-    };
+        };
+    }
 }
 
 #endif
index 2976653..feb70e5 100644 (file)
 #include "ResourceContainerBundleAPI.h"
 #include "BundleInfoInternal.h"
 
-using namespace RC;
+#include "PrimitiveRequest.h"
+#include "PrimitiveResponse.h"
+#include "PrimitiveServerResource.h"
 
-namespace RC
-{
+using namespace OIC::Service;
 
-    class ResourceContainerImpl: public ResourceContainer, public ResourceContainerBundleAPI
+namespace OIC
+{
+    namespace Service
     {
+
+        class ResourceContainerImpl: public ResourceContainer, public ResourceContainerBundleAPI
+        {
         public:
             ResourceContainerImpl();
             virtual ~ResourceContainerImpl();
@@ -56,15 +62,24 @@ namespace RC
 
             void getCommonConfiguration(configInfo *configOutput);
             void getBundleConfiguration(std::string bundleId, configInfo *configOutput);
-            void getResourceConfiguration(std::string bundleId, std::vector<resourceInfo> *configOutput);
+            void getResourceConfiguration(std::string bundleId,
+                    std::vector< resourceInfo > *configOutput);
+
+            PrimitiveGetResponse getRequestHandler(const PrimitiveRequest &request,
+                    const ResourceAttributes &attributes);
+
+            PrimitiveSetResponse setRequestHandler(const PrimitiveRequest &request,
+                    const ResourceAttributes &attributes);
 
             static ResourceContainerImpl *getImplInstance();
 
         private:
-            vector<BundleInfoInternal * > m_bundles;
+            vector< BundleInfoInternal * > m_bundles;
+            map< std::string, PrimitiveServerResource::Ptr > m_mapServers; //<uri, serverPtr>
+            map< std::string, BundleResource * > m_mapResources; //<uri, resourcePtr>
             string m_configFile;
             Configuration *m_config;
-    };
+        };
+    }
 }
-
 #endif
index af7045c..da12fc2 100644 (file)
 #define SOFTSENSORRESOURCE_H_
 
 #include "BundleResource.h"
-#include <map>
-#include <string>
 
-namespace RC
+namespace OIC
 {
-
-    class SoftSensorResource : public BundleResource
+    namespace Service
     {
+        class SoftSensorResource: public BundleResource
+        {
         public:
-            // TODO : definition of SensorData definition should be changed
             struct SensorData
             {
-                std::string sensorName;
-                std::vector< std::map<std::string, std::string> > data;
+                string sensorName;
+                vector< map< string, string > > data;
             };
 
             SoftSensorResource();
             virtual ~SoftSensorResource();
 
-            virtual void onInputDataReceived(std::vector <SensorData> inputs) = 0;
+            virtual void setInputAttributes(vector< SensorData > inputs) = 0;
 
             int inputCount;
-            std::vector < SensorData > m_vecInputs;
+            map< string, SensorData > m_mapStoredInputData;
             SensorData m_outputs;
-    };
+        };
+    }
 }
 
 #endif
index de139b9..fc39ed9 100644 (file)
 #include "BundleActivator.h"
 #include "ResourceContainer.h"
 
-using namespace RC;
+using namespace OIC::Service;
 
-namespace RC
+namespace OIC
 {
-    BundleActivator::BundleActivator()
+    namespace Service
     {
+        BundleActivator::BundleActivator()
+        {
 
-    }
+        }
 
-    BundleActivator::~BundleActivator()
-    {
+        BundleActivator::~BundleActivator()
+        {
 
-    }
+        }
 
-    void BundleActivator::activateBundle(ResourceContainerBundleAPI *resourceContainer,
-                                         std::string bundleId)
-    {
+        void BundleActivator::activateBundle(ResourceContainerBundleAPI *resourceContainer,
+                std::string bundleId)
+        {
 
-    }
+        }
 
-    void BundleActivator::deactivateBundle()
-    {
+        void BundleActivator::deactivateBundle()
+        {
 
+        }
     }
 }
+
index 0b37b30..bcdb88f 100644 (file)
 #include "BundleInfo.h"
 #include "BundleInfoInternal.h"
 
-namespace RC
+namespace OIC
 {
-    BundleInfo::BundleInfo()
+    namespace Service
     {
+        BundleInfo::BundleInfo()
+        {
 
-    }
+        }
 
-    BundleInfo::~BundleInfo()
-    {
+        BundleInfo::~BundleInfo()
+        {
 
-    }
+        }
 
-    BundleInfo *BundleInfo::createBundleInfo()
-    {
-        BundleInfoInternal *newBundleInfo = new BundleInfoInternal();
-        return newBundleInfo;
+        BundleInfo *BundleInfo::createBundleInfo()
+        {
+            BundleInfoInternal *newBundleInfo = new BundleInfoInternal();
+            return newBundleInfo;
+        }
     }
 }
index 47d0c21..eee04ae 100644 (file)
 
 #include "BundleInfoInternal.h"
 
-namespace RC
+namespace OIC
 {
-    BundleInfoInternal::BundleInfoInternal()
-    {
-
-    }
-
-    BundleInfoInternal::~BundleInfoInternal()
-    {
-
-    }
-
-    void BundleInfoInternal::setID(string id)
-    {
-        m_ID = id;
-    }
-
-    string BundleInfoInternal::getID()
-    {
-        return m_ID;
-    }
-
-    void BundleInfoInternal::setPath(string path)
-    {
-        m_path = path;
-    }
-    string BundleInfoInternal::getPath()
-    {
-        return m_path;
-    }
-
-    void BundleInfoInternal::setVersion(string version)
-    {
-        m_version = version;
-    }
-
-    string BundleInfoInternal::getVersion()
-    {
-        return m_version;
-    }
-
-    void BundleInfoInternal::setLoaded(bool loaded)
-    {
-        m_loaded = loaded;
-    }
-
-    bool BundleInfoInternal::isLoaded()
-    {
-        return m_loaded;
-    }
-
-    void BundleInfoInternal::setActivated(bool activated)
-    {
-        m_activated = activated;
-    }
-
-    bool BundleInfoInternal::isActivated()
-    {
-        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;
-    }
-
-    activator_t *BundleInfoInternal::getBundleActivator()
-    {
-        return m_activator;
-    }
-
-    void BundleInfoInternal::setBundleDeactivator(deactivator_t *deactivator)
-    {
-        m_deactivator = deactivator;
-    }
-
-    deactivator_t *BundleInfoInternal::getBundleDeactivator()
-    {
-        return m_deactivator;
-    }
-
-    void BundleInfoInternal::setBundleHandle(void *handle)
-    {
-        m_bundleHandle = handle;
-    }
-
-    void *BundleInfoInternal::getBundleHandle()
-    {
-        return m_bundleHandle;
+    namespace Service
+    {
+
+        BundleInfoInternal::BundleInfoInternal()
+        {
+
+        }
+
+        BundleInfoInternal::~BundleInfoInternal()
+        {
+
+        }
+
+        void BundleInfoInternal::setID(string id)
+        {
+            m_ID = id;
+        }
+
+        string BundleInfoInternal::getID()
+        {
+            return m_ID;
+        }
+
+        void BundleInfoInternal::setPath(string path)
+        {
+            m_path = path;
+        }
+        string BundleInfoInternal::getPath()
+        {
+            return m_path;
+        }
+
+        void BundleInfoInternal::setVersion(string version)
+        {
+            m_version = version;
+        }
+
+        string BundleInfoInternal::getVersion()
+        {
+            return m_version;
+        }
+
+        void BundleInfoInternal::setLoaded(bool loaded)
+        {
+            m_loaded = loaded;
+        }
+
+        bool BundleInfoInternal::isLoaded()
+        {
+            return m_loaded;
+        }
+
+        void BundleInfoInternal::setActivated(bool activated)
+        {
+            m_activated = activated;
+        }
+
+        bool BundleInfoInternal::isActivated()
+        {
+            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;
+        }
+
+        activator_t *BundleInfoInternal::getBundleActivator()
+        {
+            return m_activator;
+        }
+
+        void BundleInfoInternal::setBundleDeactivator(deactivator_t *deactivator)
+        {
+            m_deactivator = deactivator;
+        }
+
+        deactivator_t *BundleInfoInternal::getBundleDeactivator()
+        {
+            return m_deactivator;
+        }
+
+        void BundleInfoInternal::setBundleHandle(void *handle)
+        {
+            m_bundleHandle = handle;
+        }
+
+        void *BundleInfoInternal::getBundleHandle()
+        {
+            return m_bundleHandle;
+        }
     }
 }
index a6fd94f..d10bec0 100644 (file)
 #include "Configuration.h"
 
 
-
-BundleResource::BundleResource()
-{
-
-}
-
-BundleResource::~BundleResource()
-{
-
+namespace OIC{
+    namespace Service{
+        BundleResource::BundleResource()
+        {
+            cout << "BundleResource constructor called\n";
+        }
+
+        BundleResource::~BundleResource()
+        {
+
+        }
+    }
 }
-
-Configuration::resourceInfo BundleResource::getResourceInfo()
-{
-    return m_resourceInfo;
-}
-
-void BundleResource::setResourceInfo(Configuration::resourceInfo resourceInfo)
-{
-    m_resourceInfo = resourceInfo;
-}
-
index 06e835a..89f96ed 100644 (file)
 
 #include "Configuration.h"
 
-static inline std::string trim_both(const std::string &str)
+namespace OIC
 {
-    int npos = str.find_first_not_of(" \t\v\n\r");
-
-    if (npos == -1)
+    namespace Service
     {
-        return "";
-    }
+        static inline std::string trim_both(const std::string &str)
+        {
+            int npos = str.find_first_not_of(" \t\v\n\r");
 
-    unsigned int n = (unsigned int)npos;
-    std::string tempString = n == std::string::npos ? str : str.substr(n, str.length());
+            if (npos == -1)
+            {
+                return "";
+            }
 
-    n = tempString.find_last_not_of(" \t\v\n\r");
+            unsigned int n = (unsigned int) npos;
+            std::string tempString = n == std::string::npos ? str : str.substr(n, str.length());
 
-    return n == std::string::npos ? tempString : tempString.substr(0, n + 1);
-}
+            n = tempString.find_last_not_of(" \t\v\n\r");
 
-Configuration::Configuration()
-{
-    // TODO: temporary path and config file name
-    getCurrentPath(&m_pathConfigFile);
-    m_pathConfigFile.append("/");
-    m_pathConfigFile.append("ResourceContainerConfig.xml");
-}
+            return n == std::string::npos ? tempString : tempString.substr(0, n + 1);
+        }
 
-Configuration::~Configuration()
-{}
+        Configuration::Configuration()
+        {
+            // TODO: temporary path and config file name
+            getCurrentPath(&m_pathConfigFile);
+            m_pathConfigFile.append("/");
+            m_pathConfigFile.append("ResourceContainerConfig.xml");
+        }
 
-Configuration::Configuration(string configFile)
-{
-    m_configFile = configFile;
-    getCurrentPath(&m_pathConfigFile);
-    m_pathConfigFile.append("/");
-    m_pathConfigFile.append(m_configFile);
-}
+        Configuration::~Configuration()
+        {
+        }
 
-void Configuration::getCommonConfiguration(configInfo *configOutput)
-{
-    string strConfigData;
+        Configuration::Configuration(string configFile)
+        {
+            m_configFile = configFile;
+            getCurrentPath(&m_pathConfigFile);
+            m_pathConfigFile.append("/");
+            m_pathConfigFile.append(m_configFile);
+        }
 
-    rapidxml::xml_document< char > xmlDoc;
+        void Configuration::getCommonConfiguration(configInfo *configOutput)
+        {
+            string strConfigData;
 
-    rapidxml::xml_node< char > *root;
-    rapidxml::xml_node< char > *item;
-    rapidxml::xml_node< char > *subItem;
+            rapidxml::xml_document< char > xmlDoc;
 
-    string strKey, strValue;
+            rapidxml::xml_node< char > *root;
+            rapidxml::xml_node< char > *item;
+            rapidxml::xml_node< char > *subItem;
 
-    getConfigDocument(m_pathConfigFile, &strConfigData);
+            string strKey, strValue;
 
-    try
-    {
-        xmlDoc.parse< 0 >((char *)strConfigData.c_str());
+            getConfigDocument(m_pathConfigFile, &strConfigData);
 
-        // <container>
-        root = xmlDoc.first_node();
+            try
+            {
+                xmlDoc.parse< 0 >((char *) strConfigData.c_str());
 
-        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();
+                // <container>
+                root = xmlDoc.first_node();
 
-            // <config>
-            if (!strKey.compare("config"))
-            {
-                for (subItem = item->first_node(); subItem;
-                     subItem = subItem->next_sibling())
+                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 = subItem->name();
-                    strValue = subItem->value();
+                    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)));
+                            bundleMap.insert(
+                                    std::make_pair(trim_both(strKey), trim_both(strValue)));
+                        }
+                        break;
+                    }
                 }
-                break;
+                configOutput->push_back(bundleMap);
+            }
+            catch (rapidxml::parse_error &e)
+            {
+                cout << "xml parsing failed !!" << endl;
+                cout << e.what() << endl;
             }
         }
-        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;
+        void Configuration::getConfiguredBundles(configInfo *configOutput)
+        {
+            string strConfigData;
 
-    rapidxml::xml_document< char > xmlDoc;
+            rapidxml::xml_document< char > xmlDoc;
 
-    rapidxml::xml_node< char > *bundle;
-    rapidxml::xml_node< char > *subItem;
+            rapidxml::xml_node< char > *bundle;
+            rapidxml::xml_node< char > *subItem;
 
-    string strKey, strValue;
+            string strKey, strValue;
 
-    cout << "Opening: " << m_pathConfigFile << endl;
+            cout << "Opening: " << m_pathConfigFile << endl;
 
-    getConfigDocument(m_pathConfigFile, &strConfigData);
+            getConfigDocument(m_pathConfigFile, &strConfigData);
 
-    //cout << strConfigData.c_str() << endl;
-    try
-    {
+            //cout << strConfigData.c_str() << endl;
+            try
+            {
 
-        xmlDoc.parse< 0 >((char *)strConfigData.c_str());
-        //cout << "Name of first node is: " << xmlDoc.first_node()->name() << endl;
+                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())
-        {
-            std::map< std::string, std::string > bundleMap;
-            //cout << "Bundle: " << bundle->name() << endl;
-            for (subItem = bundle->first_node(); subItem; subItem = subItem->next_sibling())
-            {
-                strKey = subItem->name();
-                strValue = subItem->value();
-                if (strlen(subItem->value()) > 0)
+                for (bundle = xmlDoc.first_node()->first_node("bundle"); bundle;
+                        bundle = bundle->next_sibling())
                 {
-                    bundleMap.insert(std::make_pair(trim_both(strKey), trim_both(strValue)));
-                    //cout << strKey << " " << strValue << endl;
+                    std::map< std::string, std::string > bundleMap;
+                    //cout << "Bundle: " << bundle->name() << endl;
+                    for (subItem = bundle->first_node(); subItem; subItem = subItem->next_sibling())
+                    {
+                        strKey = subItem->name();
+                        strValue = subItem->value();
+                        if (strlen(subItem->value()) > 0)
+                        {
+                            bundleMap.insert(
+                                    std::make_pair(trim_both(strKey), trim_both(strValue)));
+                            //cout << strKey << " " << strValue << endl;
 
+                        }
+                    }
+                    configOutput->push_back(bundleMap);
                 }
+
+            }
+            catch (rapidxml::parse_error &e)
+            {
+                cout << "xml parsing failed !!" << endl;
+                cout << e.what() << endl;
             }
-            configOutput->push_back(bundleMap);
         }
 
-    }
-    catch (rapidxml::parse_error &e)
-    {
-        cout << "xml parsing failed !!" << endl;
-        cout << e.what() << endl;
-    }
-}
-
-void Configuration::getBundleConfiguration(string bundleId, configInfo *configOutput)
-{
-    string strConfigData;
-
-    rapidxml::xml_document< char > xmlDoc;
+        void Configuration::getBundleConfiguration(string bundleId, configInfo *configOutput)
+        {
+            string strConfigData;
 
-    rapidxml::xml_node< char > *root;
-    rapidxml::xml_node< char > *item;
-    rapidxml::xml_node< char > *subItem;
+            rapidxml::xml_document< char > xmlDoc;
 
-    string strKey, strValue;
+            rapidxml::xml_node< char > *root;
+            rapidxml::xml_node< char > *item;
+            rapidxml::xml_node< char > *subItem;
 
-    getConfigDocument(m_pathConfigFile, &strConfigData);
+            string strKey, strValue;
 
-    try
-    {
-        xmlDoc.parse< 0 >((char *)strConfigData.c_str());
+            getConfigDocument(m_pathConfigFile, &strConfigData);
 
-        // <container>
-        root = xmlDoc.first_node();
+            try
+            {
+                xmlDoc.parse< 0 >((char *) strConfigData.c_str());
 
-        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();
+                // <container>
+                root = xmlDoc.first_node();
 
-            // <bundle>
-            if (!strKey.compare("bundle"))
-            {
-                for (subItem = item->first_node(); subItem; subItem = subItem->next_sibling())
+                if (!root)
                 {
-                    strKey = subItem->name();
-                    strValue = subItem->value();
-
-                    if (!strKey.compare("bundleID") && strValue.compare(bundleId))
-                        break;
+                    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();
 
-                    // bundle info (except resource data)
-                    if (strKey.compare("resources"))
+                    // <bundle>
+                    if (!strKey.compare("bundle"))
                     {
-                        bundleMap.insert(std::make_pair(trim_both(strKey), trim_both(strValue)));
+                        for (subItem = item->first_node(); subItem; subItem =
+                                subItem->next_sibling())
+                        {
+                            strKey = subItem->name();
+                            strValue = subItem->value();
+
+                            if (!strKey.compare("bundleID") && strValue.compare(bundleId))
+                                break;
+
+                            // bundle info (except resource data)
+                            if (strKey.compare("resources"))
+                            {
+                                bundleMap.insert(
+                                        std::make_pair(trim_both(strKey), trim_both(strValue)));
+                            }
+                        }
                     }
                 }
+                configOutput->push_back(bundleMap);
+
+            }
+            catch (rapidxml::parse_error &e)
+            {
+                cout << "xml parsing failed !!" << endl;
+                cout << e.what() << endl;
             }
         }
-        configOutput->push_back(bundleMap);
-
-    }
-    catch (rapidxml::parse_error &e)
-    {
-        cout << "xml parsing failed !!" << endl;
-        cout << e.what() << endl;
-    }
-}
 
-void Configuration::getResourceConfiguration(string bundleId, 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;
+        void Configuration::getResourceConfiguration(string bundleId,
+                vector< resourceInfo > *configOutput)
+        {
+            string strConfigData;
 
-    string strKey, strValue;
+            rapidxml::xml_document< char > xmlDoc;
 
-    getConfigDocument(m_pathConfigFile, &strConfigData);
+            rapidxml::xml_node< char > *root;
+            rapidxml::xml_node< char > *item;
+            rapidxml::xml_node< char > *subItem, *subItem2, *subItem3, *subItem4, *subItem5;
 
-    try
-    {
-        xmlDoc.parse< 0 >((char *)strConfigData.c_str());
+            string strKey, strValue;
 
-        // <container>
-        root = xmlDoc.first_node();
+            getConfigDocument(m_pathConfigFile, &strConfigData);
 
-        if (!root)
-        {
-            throw rapidxml::parse_error("No Root Element", 0);
-        }
+            try
+            {
+                xmlDoc.parse< 0 >((char *) strConfigData.c_str());
 
-        for (item = root->first_node(); item; item = item->next_sibling())
-        {
-            strKey = item->name();
-            strValue = item->value();
+                // <container>
+                root = xmlDoc.first_node();
 
-            // <bundle>
-            if (!strKey.compare("bundle"))
-            {
-                for (subItem = item->first_node(); subItem; subItem = subItem->next_sibling())
+                if (!root)
                 {
-                    strKey = subItem->name();
-                    strValue = subItem->value();
+                    throw rapidxml::parse_error("No Root Element", 0);
+                }
 
-                    if (!strKey.compare("bundleID") && strValue.compare(bundleId))
-                        break;
+                for (item = root->first_node(); item; item = item->next_sibling())
+                {
+                    strKey = item->name();
+                    strValue = item->value();
 
-                    // <resources>
-                    if (!strKey.compare("resources"))
+                    // <bundle>
+                    if (!strKey.compare("bundle"))
                     {
-                        for (subItem2 = subItem->first_node(); subItem2;
-                             subItem2 = subItem2->next_sibling())
+                        for (subItem = item->first_node(); subItem; subItem =
+                                subItem->next_sibling())
                         {
-                            strKey = subItem2->name();
-                            strValue = subItem2->value();
+                            strKey = subItem->name();
+                            strValue = subItem->value();
 
-                            // <resourceInfo> : for 1 resource
-                            if (!strKey.compare("resourceInfo"))
-                            {
-                                resourceInfo tempResourceInfo;
+                            if (!strKey.compare("bundleID") && strValue.compare(bundleId))
+                                break;
 
-                                for (subItem3 = subItem2->first_node(); subItem3; subItem3 = subItem3->next_sibling())
+                            // <resources>
+                            if (!strKey.compare("resources"))
+                            {
+                                for (subItem2 = subItem->first_node(); subItem2;
+                                        subItem2 = subItem2->next_sibling())
                                 {
+                                    strKey = subItem2->name();
+                                    strValue = subItem2->value();
 
-                                    strKey = subItem3->name();
-                                    strValue = subItem3->value();
+                                    // <resourceInfo> : for 1 resource
+                                    if (!strKey.compare("resourceInfo"))
+                                    {
+                                        resourceInfo tempResourceInfo;
 
-                                    if (!strKey.compare("name"))
-                                        tempResourceInfo.name = trim_both(strValue);
+                                        for (subItem3 = subItem2->first_node(); subItem3; subItem3 =
+                                                subItem3->next_sibling())
+                                        {
 
-                                    else if (!strKey.compare("uri"))
-                                        tempResourceInfo.uri = trim_both(strValue);
+                                            strKey = subItem3->name();
+                                            strValue = subItem3->value();
 
-                                    else if (!strKey.compare("resourceType"))
-                                        tempResourceInfo.resourceType = trim_both(strValue);
+                                            if (!strKey.compare("name"))
+                                                tempResourceInfo.name = trim_both(strValue);
 
-                                    else
-                                    {
-                                        for (subItem4 = subItem3->first_node(); subItem4; subItem4 = subItem4->next_sibling())
-                                        {
-                                            map <string, string> propertyMap;
+                                            else if (!strKey.compare("uri"))
+                                                tempResourceInfo.uri = trim_both(strValue);
 
-                                            strKey = subItem4->name();
+                                            else if (!strKey.compare("address"))
+                                                tempResourceInfo.address = trim_both(strValue);
 
-                                            for (subItem5 = subItem4->first_node(); subItem5; subItem5 = subItem5->next_sibling())
-                                            {
-                                                string newStrKey = subItem5->name();
-                                                string newStrValue = subItem5->value();
+                                            else if (!strKey.compare("resourceType"))
+                                                tempResourceInfo.resourceType = trim_both(strValue);
 
-                                                propertyMap[trim_both(newStrKey)] = trim_both(newStrValue);
+                                            else
+                                            {
+                                                for (subItem4 = subItem3->first_node(); subItem4;
+                                                        subItem4 = subItem4->next_sibling())
+                                                {
+                                                    map< string, string > propertyMap;
+
+                                                    strKey = subItem4->name();
+
+                                                    for (subItem5 = subItem4->first_node();
+                                                            subItem5;
+                                                            subItem5 = subItem5->next_sibling())
+                                                    {
+                                                        string newStrKey = subItem5->name();
+                                                        string newStrValue = subItem5->value();
+
+                                                        propertyMap[trim_both(newStrKey)] =
+                                                                trim_both(newStrValue);
+                                                    }
+
+                                                    tempResourceInfo.resourceProperty[trim_both(
+                                                            strKey)].push_back(propertyMap);
+                                                }
                                             }
-
-                                            tempResourceInfo.resourceProperty[trim_both(strKey)].push_back(propertyMap);
                                         }
+                                        configOutput->push_back(tempResourceInfo);
                                     }
                                 }
-                                configOutput->push_back(tempResourceInfo);
                             }
                         }
                     }
                 }
             }
+            catch (rapidxml::parse_error &e)
+            {
+                cout << "xml parsing failed !!" << endl;
+                cout << e.what() << endl;
+            }
         }
-    }
-    catch (rapidxml::parse_error &e)
-    {
-        cout << "xml parsing failed !!" << endl;
-        cout << e.what() << endl;
-    }
-}
 
-void Configuration::getConfigDocument(std::string pathConfigFile, std::string *pConfigData)
-{
-    std::basic_ifstream< char > xmlFile(pathConfigFile.c_str());
+        void Configuration::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);
+            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;
+                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;
-    }
-}
+                xmlFile.read(&xmlData.front(), (std::streamsize) size);
+                xmlFile.close();
+                *pConfigData = std::string(xmlData.data());
+            }
+            else
+            {
+                std::cout << "Configuration File load failed !!" << std::endl;
+            }
+        }
 
-void Configuration::getCurrentPath(std::string *path)
-{
-    char buffer[2048];
-    char *strPath = NULL;
+        void Configuration::getCurrentPath(std::string *path)
+        {
+            char buffer[2048];
+            char *strPath = NULL;
 
-    int length = readlink("/proc/self/exe", buffer, 2047);
+            int length = readlink("/proc/self/exe", buffer, 2047);
 
-    buffer[length] = '\0';
+            buffer[length] = '\0';
 
-    strPath = strrchr(buffer, '/');
+            strPath = strrchr(buffer, '/');
 
-    *strPath = '\0';
+            *strPath = '\0';
 
-    path->append(buffer);
+            path->append(buffer);
+        }
+    }
 }
index 5b4d1fa..d05b2f5 100644 (file)
 #include "BundleInfo.h"
 #include "oc_logger.hpp"
 
-using namespace RC;
+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> &
 {
@@ -49,3 +50,4 @@ int main()
         ;
     }
 }
+
diff --git a/service/basis/resourceContainer/src/ProtocolBridgeConnector.cpp b/service/basis/resourceContainer/src/ProtocolBridgeConnector.cpp
new file mode 100644 (file)
index 0000000..f55d8af
--- /dev/null
@@ -0,0 +1,40 @@
+//******************************************************************
+//
+// 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 "ProtocolBridgeConnector.h"
+
+using namespace OIC::Service;
+
+namespace OIC
+{
+    namespace Service
+    {
+        ProtocolBridgeConnector::ProtocolBridgeConnector()
+        {
+
+        }
+
+        ProtocolBridgeConnector::~ProtocolBridgeConnector()
+        {
+
+        }
+    }
+}
+
diff --git a/service/basis/resourceContainer/src/ProtocolBridgeResource.cpp b/service/basis/resourceContainer/src/ProtocolBridgeResource.cpp
new file mode 100644 (file)
index 0000000..0e0eed0
--- /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.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+#include "ProtocolBridgeResource.h"
+
+using namespace OIC::Service;
+
+namespace OIC{
+    namespace Service{
+        ProtocolBridgeResource::ProtocolBridgeResource()
+        {
+
+        }
+
+        ProtocolBridgeResource::~ProtocolBridgeResource()
+        {
+
+        }
+    }
+}
+
+
index c0c33cd..ff28c4c 100644 (file)
 #include "ResourceContainer.h"
 #include "ResourceContainerImpl.h"
 
-namespace RC
-{
+namespace OIC{
+    namespace Service{
+        ResourceContainer::ResourceContainer()
+        {
 
-    ResourceContainer::ResourceContainer()
-    {
+        }
 
-    }
-
-    ResourceContainer::~ResourceContainer()
-    {
+        ResourceContainer::~ResourceContainer()
+        {
 
-    }
+        }
 
-    ResourceContainer *ResourceContainer::getInstance()
-    {
-        return (ResourceContainer *)ResourceContainerImpl::getImplInstance();
+        ResourceContainer *ResourceContainer::getInstance()
+        {
+            return (ResourceContainer *)ResourceContainerImpl::getImplInstance();
+        }
     }
 }
 
index b2d3170..2a78c9d 100644 (file)
 
 #include "ResourceContainerBundleAPI.h"
 
-using namespace RC;
+using namespace OIC::Service;
 
-namespace RC
-{
+namespace OIC{
+    namespace Service{
 
-    ResourceContainerBundleAPI::ResourceContainerBundleAPI()
-    {
+        ResourceContainerBundleAPI::ResourceContainerBundleAPI()
+        {
 
-    }
+        }
 
-    ResourceContainerBundleAPI::~ResourceContainerBundleAPI()
-    {
+        ResourceContainerBundleAPI::~ResourceContainerBundleAPI()
+        {
 
-    }
+        }
 
+    }
 }
index fe64f35..b9b7c87 100644 (file)
 #include "ResourceContainer.h"
 #include "BundleInfoInternal.h"
 #include "logger.h"
-#include "PrimitiveRequest.h"
-#include "PrimitiveResponse.h"
-#include "PrimitiveServerResource.h"
-
 #include <dlfcn.h>
 #include <unistd.h>
 #include <string.h>
@@ -59,217 +55,288 @@ auto error_logger = []() -> boost::iostreams::stream<OC::oc_log_stream> &
 };
 
 using namespace std;
-using namespace RC;
+using namespace OIC::Service;
 
-namespace RC
+namespace OIC
 {
-
-    ResourceContainerImpl::ResourceContainerImpl()
+    namespace Service
     {
-        // TODO Auto-generated constructor stub
 
-    }
+        ResourceContainerImpl::ResourceContainerImpl()
+        {
+            // TODO Auto-generated constructor stub
 
-    ResourceContainerImpl::~ResourceContainerImpl()
-    {
-        // TODO Auto-generated destructor stub
-    }
+        }
 
-    void ResourceContainerImpl::init()
-    {
+        ResourceContainerImpl::~ResourceContainerImpl()
+        {
+            // TODO Auto-generated destructor stub
+        }
 
-    }
+        void ResourceContainerImpl::init()
+        {
 
-    void ResourceContainerImpl::init(string configFile)
-    {
-        m_config = new Configuration(configFile);
-        Configuration::configInfo bundles;
-        m_config->getConfiguredBundles(&bundles);
-        for (int i = 0; i < bundles.size(); i++)
+        }
+
+        void ResourceContainerImpl::init(string configFile)
         {
-            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;
-            registerBundle(bundleInfo);
-            activateBundle(bundleInfo);
+            m_config = new Configuration(configFile);
+            Configuration::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;
+                registerBundle(bundleInfo);
+                activateBundle(bundleInfo);
+            }
         }
-    }
 
-    // loads the bundle
-    void ResourceContainerImpl::registerBundle(BundleInfo *bundleInfo)
-    {
-        info_logger() << "Registering bundle: " << bundleInfo->getPath() << endl;
+        // loads the bundle
+        void ResourceContainerImpl::registerBundle(BundleInfo *bundleInfo)
+        {
+            info_logger() << "Registering bundle: " << bundleInfo->getPath() << endl;
 
-        m_bundles.push_back((BundleInfoInternal *) bundleInfo);
-        ((BundleInfoInternal *) bundleInfo)->setId(m_bundles.size() - 1);
+            m_bundles.push_back((BundleInfoInternal *) bundleInfo);
+            ((BundleInfoInternal *) bundleInfo)->setId(m_bundles.size() - 1);
 
-        char *error;
+            char *error;
 
-        activator_t *bundleActivator = NULL;
-        deactivator_t *bundleDeactivator = NULL;
+            activator_t *bundleActivator = NULL;
+            deactivator_t *bundleDeactivator = NULL;
 
-        //sstream << bundleInfo.path << std::ends;
+            //sstream << bundleInfo.path << std::ends;
 
-        void *bundleHandle = NULL;
-        bundleHandle = dlopen(bundleInfo->getPath().c_str(), RTLD_LAZY);
+            void *bundleHandle = NULL;
+            bundleHandle = dlopen(bundleInfo->getPath().c_str(), RTLD_LAZY);
 
-        if (bundleHandle != NULL)
-        {
-            bundleActivator = (activator_t *) dlsym(bundleHandle, "externalActivateBundle");
-            bundleDeactivator = (deactivator_t *) dlsym(bundleHandle, "externalDeactivateBundle");
-            if ((error = dlerror()) != NULL)
+            if (bundleHandle != NULL)
             {
-                error_logger() << error << endl;
+                bundleActivator = (activator_t *) dlsym(bundleHandle, "externalActivateBundle");
+                bundleDeactivator = (deactivator_t *) dlsym(bundleHandle,
+                        "externalDeactivateBundle");
+                if ((error = dlerror()) != NULL)
+                {
+                    error_logger() << error << endl;
+                }
+                else
+                {
+                    ((BundleInfoInternal *) bundleInfo)->setBundleActivator(bundleActivator);
+                    ((BundleInfoInternal *) bundleInfo)->setBundleDeactivator(bundleDeactivator);
+                    ((BundleInfoInternal *) bundleInfo)->setLoaded(true);
+                    ((BundleInfoInternal *) bundleInfo)->setBundleHandle(bundleHandle);
+                }
             }
             else
             {
-                ((BundleInfoInternal *) bundleInfo)->setBundleActivator(bundleActivator);
-                ((BundleInfoInternal *) bundleInfo)->setBundleDeactivator(bundleDeactivator);
-                ((BundleInfoInternal *) bundleInfo)->setLoaded(true);
-                ((BundleInfoInternal *) bundleInfo)->setBundleHandle(bundleHandle);
+                if ((error = dlerror()) != NULL)
+                {
+                    error_logger() << error << endl;
+                }
             }
         }
-        else
+
+        void ResourceContainerImpl::activateBundle(int id)
         {
-            if ((error = dlerror()) != NULL)
+            activator_t *bundleActivator = m_bundles[id]->getBundleActivator();
+            info_logger() << "Activating bundle: " << m_bundles[id]->getID() << ", "
+                    << m_bundles[id]->getId() << endl;
+
+            if (bundleActivator != NULL)
             {
-                error_logger() << error << endl;
+                bundleActivator(this, m_bundles[id]->getID());
+                m_bundles[id]->setActivated(true);
+            }
+            else
+            {
+                //Unload module and return error
+                error_logger() << "Activation unsuccessful." << endl;
             }
         }
-    }
 
-    void ResourceContainerImpl::activateBundle(int id)
-    {
-        activator_t *bundleActivator = m_bundles[id]->getBundleActivator();
-        info_logger() << "Activating bundle: " << m_bundles[id]->getID() << ", "
-                      << m_bundles[id]->getId() << endl;
-
-        if (bundleActivator != NULL)
+        void ResourceContainerImpl::activateBundle(BundleInfo *bundleInfo)
         {
-            bundleActivator(this, m_bundles[id]->getID());
-            m_bundles[id]->setActivated(true);
+            if (((BundleInfoInternal *) bundleInfo)->isLoaded())
+            {
+                activateBundle(bundleInfo->getId());
+            }
         }
-        else
+
+        void ResourceContainerImpl::deactivateBundle(BundleInfo *bundleInfo)
         {
-            //Unload module and return error
-            error_logger() << "Activation unsuccessful." << endl;
+            if (((BundleInfoInternal *) bundleInfo)->isActivated())
+            {
+                deactivateBundle(bundleInfo->getId());
+            }
         }
-    }
 
-    void ResourceContainerImpl::activateBundle(BundleInfo *bundleInfo)
-    {
-        if (((BundleInfoInternal *) bundleInfo)->isLoaded())
+        void ResourceContainerImpl::deactivateBundle(int id)
         {
-            activateBundle(bundleInfo->getId());
+            deactivator_t *bundleDeactivator = m_bundles[id]->getBundleDeactivator();
+            info_logger() << "De-activating bundle: " << m_bundles[id]->getID() << ", "
+                    << m_bundles[id]->getId() << endl;
+
+            if (bundleDeactivator != NULL)
+            {
+                bundleDeactivator();
+                m_bundles[id]->setActivated(false);
+            }
+            else
+            {
+                //Unload module and return error
+                error_logger() << "De-activation unsuccessful." << endl;
+            }
         }
-    }
 
-    void ResourceContainerImpl::deactivateBundle(BundleInfo *bundleInfo)
-    {
-        if (((BundleInfoInternal *) bundleInfo)->isActivated())
+        void ResourceContainerImpl::activateBundleByName(string name)
         {
-            deactivateBundle(bundleInfo->getId());
-        }
-    }
 
-    void ResourceContainerImpl::deactivateBundle(int id)
-    {
-        deactivator_t *bundleDeactivator = m_bundles[id]->getBundleDeactivator();
-        info_logger() << "De-activating bundle: " << m_bundles[id]->getID() << ", "
-                      << m_bundles[id]->getId() << endl;
+        }
 
-        if (bundleDeactivator != NULL)
+        void ResourceContainerImpl::deactivateBundleByName(string id)
         {
-            bundleDeactivator();
-            m_bundles[id]->setActivated(false);
+
         }
-        else
+
+        vector< Resource * > ResourceContainerImpl::listBundleResources(string id)
         {
-            //Unload module and return error
-            error_logger() << "De-activation unsuccessful." << endl;
+            vector< Resource * > ret;
+            return ret;
         }
-    }
 
-    void ResourceContainerImpl::activateBundleByName(string name)
-    {
+        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;
 
-    void ResourceContainerImpl::deactivateBundleByName(string id)
-    {
+            PrimitiveServerResource::Ptr server =
+                    PrimitiveServerResource::Builder(strUri, strResourceType, "DEFAULT_INTERFACE").setObservable(
+                            false).setDiscoverable(true).create();
 
-    }
+            m_mapServers[strUri] = server;
+            m_mapResources[strUri] = resource;
 
-    vector< Resource * > ResourceContainerImpl::listBundleResources(string id)
-    {
-        vector< Resource * > ret;
-        return ret;
-    }
+            cout << "Registered resource has " << m_mapResources[strUri]->m_mapAttributes.size()
+                    << " attributes.\n" << endl;
 
-    void ResourceContainerImpl::registerResource(BundleResource *resource)
-    {
-        cout << "Register resource called.\n";
-        PrimitiveServerResource::Ptr server =
-            PrimitiveServerResource::Builder("/softSensors/discomfortIndex/1",
-                                             "core.softSensor",
-                                             "DEFAULT_INTERFACE").setObservable(false).setDiscoverable(true).create();
+            server->setGetRequestHandler(
+                    std::bind(&ResourceContainerImpl::getRequestHandler, this,
+                            std::placeholders::_1, std::placeholders::_2));
+
+            server->setSetRequestHandler(
+                    std::bind(&ResourceContainerImpl::setRequestHandler, this,
+                            std::placeholders::_1, std::placeholders::_2));
+        }
 
-        for (auto i : resource->m_mapAttributes)
+        PrimitiveGetResponse ResourceContainerImpl::getRequestHandler(
+                const PrimitiveRequest &request, const ResourceAttributes &attributes)
         {
-            cout << "Setting attribute " << i.first.c_str() << endl;
-            server->setAttribute(i.first.c_str(), i.second.c_str());
+            ResourceAttributes attr;
+
+            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)
+                {
+                    cout << "Setting attribute " << i.first.c_str() << ", " << i.second.c_str()
+                            << endl;
+                    attr[i.first.c_str()] = i.second.c_str();
+                }
+            }
+
+            return PrimitiveGetResponse::create(attr);
         }
 
-    }
+        PrimitiveSetResponse ResourceContainerImpl::setRequestHandler(
+                const PrimitiveRequest &request, const ResourceAttributes &attributes)
+        {
+            ResourceAttributes attr = attributes;
 
-    void ResourceContainerImpl::unregisterResource(BundleResource *resource)
-    {
+            cout << "Set request handler resource called.\n";
 
-    }
+            if (m_mapServers.find(request.getResourceUri()) != m_mapServers.end()
+                    && m_mapResources.find(request.getResourceUri()) != m_mapResources.end())
+            {
 
-    void ResourceContainerImpl::unregisterBundle(BundleInfo *bundleInfo)
-    {
-        if (((BundleInfoInternal *) bundleInfo)->isLoaded()
-            && !((BundleInfoInternal *) bundleInfo)->isActivated())
+                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)
+                {
+                    if (!attr[i.first].toString().empty())
+                    {
+                        cout << "Setting " << i.first << endl;
+                        m_mapResources[request.getResourceUri()]->setAttribute(i.first,
+                                attr[i.first].toString());
+                    }
+                }
+
+                // set m_mapAttributes to attributes
+            }
+
+            return PrimitiveSetResponse::create(attr);
+        }
+
+        void ResourceContainerImpl::unregisterResource(BundleResource *resource)
         {
-            unregisterBundle(bundleInfo->getId());
+
         }
-    }
 
-    void ResourceContainerImpl::unregisterBundle(int id)
-    {
-        void *bundleHandle = m_bundles[id]->getBundleHandle();
-        info_logger() << "Unregister bundle: " << m_bundles[id]->getID() << ", "
-                      << m_bundles[id]->getId() << endl;
-        char *error;
-        dlclose(bundleHandle);
-        if ((error = dlerror()) != NULL)
+        void ResourceContainerImpl::unregisterBundle(BundleInfo *bundleInfo)
         {
-            error_logger() << error << endl;
+            if (((BundleInfoInternal *) bundleInfo)->isLoaded()
+                    && !((BundleInfoInternal *) bundleInfo)->isActivated())
+            {
+                unregisterBundle(bundleInfo->getId());
+            }
         }
-    }
 
-    ResourceContainerImpl *ResourceContainerImpl::getImplInstance()
-    {
-        ResourceContainerImpl *ret = new ResourceContainerImpl();
-        return ret;
-    }
+        void ResourceContainerImpl::unregisterBundle(int id)
+        {
+            void *bundleHandle = m_bundles[id]->getBundleHandle();
+            info_logger() << "Unregister bundle: " << m_bundles[id]->getID() << ", "
+                    << m_bundles[id]->getId() << endl;
+            char *error;
+            dlclose(bundleHandle);
+            if ((error = dlerror()) != NULL)
+            {
+                error_logger() << error << endl;
+            }
+        }
 
-    void ResourceContainerImpl::getCommonConfiguration(configInfo *configOutput)
-    {
-        m_config->getCommonConfiguration((Configuration::configInfo *) configOutput);
-    }
+        ResourceContainerImpl *ResourceContainerImpl::getImplInstance()
+        {
+            ResourceContainerImpl *ret = new ResourceContainerImpl();
+            return ret;
+        }
 
-    void ResourceContainerImpl::getBundleConfiguration(std::string bundleId, configInfo *configOutput)
-    {
-        m_config->getBundleConfiguration(bundleId, (Configuration::configInfo *) configOutput);
-    }
+        void ResourceContainerImpl::getCommonConfiguration(configInfo *configOutput)
+        {
+            m_config->getCommonConfiguration((Configuration::configInfo *) configOutput);
+        }
 
-    void ResourceContainerImpl::getResourceConfiguration(std::string bundleId,
-            std::vector<resourceInfo> *configOutput)
-    {
-        m_config->getResourceConfiguration(bundleId, configOutput);
+        void ResourceContainerImpl::getBundleConfiguration(std::string bundleId,
+                configInfo *configOutput)
+        {
+            m_config->getBundleConfiguration(bundleId, (Configuration::configInfo *) configOutput);
+        }
+
+        void ResourceContainerImpl::getResourceConfiguration(std::string bundleId,
+                std::vector< resourceInfo > *configOutput)
+        {
+            m_config->getResourceConfiguration(bundleId, configOutput);
+        }
     }
 }
+
index dc5608a..24fe7b1 100644 (file)
 
 #include "SoftSensorResource.h"
 
-using namespace RC;
-SoftSensorResource::SoftSensorResource()
+using namespace OIC::Service;
+namespace OIC
 {
+    namespace Service
+    {
+        SoftSensorResource::SoftSensorResource()
+        {
 
-}
+        }
 
-SoftSensorResource::~SoftSensorResource()
-{
+        SoftSensorResource::~SoftSensorResource()
+        {
 
+        }
+    }
 }
 
-