From bbd5c1aeea95dec6d8722bc536872d82f847f128 Mon Sep 17 00:00:00 2001 From: Markus Jung Date: Sun, 7 Jun 2015 17:09:52 +0900 Subject: [PATCH] Resource container update Dynamic loading of resource bundles and activation. Configuration based container initialization. Example resource bundle and configuration file. Separation of ContainerAPI to initialize, configure the container and resource bundles and BundleAPI to be used by resource bundles. Change-Id: Ib91fc12ad350f3cbd0723b83ee65c953775328ce Signed-off-by: Markus Jung Reviewed-on: https://gerrit.iotivity.org/gerrit/1235 Tested-by: jenkins-iotivity Reviewed-by: Madan Lanka Reviewed-by: Uze Choi --- service/basis/resourceContainer/SConscript | 19 +- .../examples/ResourceContainerConfig.xml | 48 +++ .../SampleBundle/include/DiscomfortIndexSensor.h | 86 +++++ .../examples/SampleBundle/include/SampleBundle.h | 6 +- .../examples/SampleBundle/include/SysTimer.h | 37 +++ .../SampleBundle/src/DiscomfortIndexSensor.cpp | 253 ++++++++++++++ .../examples/SampleBundle/src/SampleBundle.cpp | 28 +- .../examples/SampleBundle/src/SysTimer.cpp | 56 ++++ .../resourceContainer/include/BundleActivator.h | 24 +- .../basis/resourceContainer/include/BundleInfo.h | 41 +-- .../resourceContainer/include/BundleInfoInternal.h | 68 ++-- .../resourceContainer/include/BundleResource.h | 53 +++ .../resourceContainer/include/Configuration.h | 67 ++++ .../resourceContainer/include/ResourceContainer.h | 81 ++--- .../include/ResourceContainerBundleAPI.h | 52 +++ .../include/ResourceContainerImpl.h | 66 ++++ .../resourceContainer/src/BundleActivator.cpp | 21 +- service/basis/resourceContainer/src/BundleInfo.cpp | 45 +-- .../resourceContainer/src/BundleInfoInternal.cpp | 123 +++++++ .../basis/resourceContainer/src/Configuration.cpp | 362 +++++++++++++++++++++ .../basis/resourceContainer/src/ContainerTest.cpp | 44 ++- .../ResourceContainer.cpp} | 40 +-- .../src/ResourceContainerBundleAPI.cpp | 38 +++ .../src/ResourceContainerImpl.cpp | 238 ++++++++++++++ .../src/ResourceContainerInternal.cpp | 361 -------------------- 25 files changed, 1685 insertions(+), 572 deletions(-) create mode 100644 service/basis/resourceContainer/examples/ResourceContainerConfig.xml create mode 100644 service/basis/resourceContainer/examples/SampleBundle/include/DiscomfortIndexSensor.h create mode 100644 service/basis/resourceContainer/examples/SampleBundle/include/SysTimer.h create mode 100644 service/basis/resourceContainer/examples/SampleBundle/src/DiscomfortIndexSensor.cpp create mode 100644 service/basis/resourceContainer/examples/SampleBundle/src/SysTimer.cpp create mode 100644 service/basis/resourceContainer/include/BundleResource.h create mode 100644 service/basis/resourceContainer/include/Configuration.h create mode 100644 service/basis/resourceContainer/include/ResourceContainerBundleAPI.h create mode 100644 service/basis/resourceContainer/include/ResourceContainerImpl.h create mode 100644 service/basis/resourceContainer/src/BundleInfoInternal.cpp create mode 100644 service/basis/resourceContainer/src/Configuration.cpp rename service/basis/resourceContainer/{include/ResourceContainerInternal.h => src/ResourceContainer.cpp} (54%) create mode 100644 service/basis/resourceContainer/src/ResourceContainerBundleAPI.cpp create mode 100644 service/basis/resourceContainer/src/ResourceContainerImpl.cpp delete mode 100644 service/basis/resourceContainer/src/ResourceContainerInternal.cpp diff --git a/service/basis/resourceContainer/SConscript b/service/basis/resourceContainer/SConscript index 8c9d587..b3a6357 100644 --- a/service/basis/resourceContainer/SConscript +++ b/service/basis/resourceContainer/SConscript @@ -1,6 +1,6 @@ #****************************************************************** # -# Copyright 2014 Samsung Electronics All Rights Reserved. +# Copyright 2015 Samsung Electronics All Rights Reserved. # #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= # @@ -19,7 +19,7 @@ #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= ## -# things_manager project build script +# resource container build script ## import os Import('env') @@ -33,7 +33,12 @@ target_os = env.get('TARGET_OS') ###################################################################### # Build flags ###################################################################### -resource_container_env.AppendUnique(CPPPATH = [env.get('SRC_DIR')+'/extlibs', 'include', 'src']) +resource_container_env.AppendUnique( + CPPPATH = [ + env.get('SRC_DIR')+'/extlibs', + 'include', + 'src' + ]) if target_os not in ['windows', 'winrt']: resource_container_env.AppendUnique(CXXFLAGS = ['-std=c++0x', '-Wall']) @@ -76,7 +81,8 @@ SAMPLE_RESOURCE_BUNDLE_DIR = 'examples/SampleBundle/' sample_resource_bundle_env.AppendUnique(CPPPATH = [ SAMPLE_RESOURCE_BUNDLE_DIR + 'include', 'include/' - ]) + ]) + sample_resource_bundle_src = [ Glob(SAMPLE_RESOURCE_BUNDLE_DIR + 'src/*.cpp'), Glob('src/*.cpp')] @@ -88,6 +94,11 @@ sample_resource_bundle_env.InstallTarget(SampleBundle, 'libSampleBundle') ###################################################################### containertest_env = resource_container_env.Clone(); containertest_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')]) +containertest_env.PrependUnique(LIBS = ['oc', 'oc_logger_core', 'oc_logger']) + +# Copy test configuration +Command("examples/ResourceContainerConfig.xml","examples/ResourceContainerConfig.xml", Copy("$TARGET", "$SOURCE")) +Ignore("examples/ResourceContainerConfig.xml", "examples/ResourceContainerConfig.xml") containertestapp = containertest_env.Program('ContainerTest', res_container_src) Alias("containertest", containertestapp) diff --git a/service/basis/resourceContainer/examples/ResourceContainerConfig.xml b/service/basis/resourceContainer/examples/ResourceContainerConfig.xml new file mode 100644 index 0000000..b18d32d --- /dev/null +++ b/service/basis/resourceContainer/examples/ResourceContainerConfig.xml @@ -0,0 +1,48 @@ + + + + oic.bundle.discomfortIndexSensor + libSampleBundle.so + libSampleBundle.so + + + DiscomfortIndexSensor1 + core.softsensor + + + version + string + 1.0 + + + lifetime + int + 60 + + + + + timestamp + string + + + temperature + string + + + humidity + string + + + discomfortIndex + int + + + + Thing_TempHumSensor + Thing_TempHumSensor1 + + + + + diff --git a/service/basis/resourceContainer/examples/SampleBundle/include/DiscomfortIndexSensor.h b/service/basis/resourceContainer/examples/SampleBundle/include/DiscomfortIndexSensor.h new file mode 100644 index 0000000..70202df --- /dev/null +++ b/service/basis/resourceContainer/examples/SampleBundle/include/DiscomfortIndexSensor.h @@ -0,0 +1,86 @@ +/****************************************************************** +* +* Copyright 2014 Samsung Electronics All Rights Reserved. +* +* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************/ + +/* +* DiscomfortIndexSensor.h +*/ + +#ifndef DISCOMFORTINDEXSENSOR_H_ +#define DISCOMFORTINDEXSENSOR_H_ + +/** +* This header file is included to define _EXPORT_. +*/ + +#include +#include +#include + +struct SensorData +{ + std::string sensorName; + std::vector< std::map > data; +}; + +namespace DiscomfortIndexSensorName +{ +#define PHYSICAL_EA 2 + + typedef struct _physicalInput_ + { + char *m_thingName; + int m_inputNum; + void *m_pInputStruct; + } physicalInput; + + typedef enum + { + SUCCESS = 0, ERROR, ALL_DISCOMPORT, HALF_DISCOMPORT, LITTLE_DISCOMPORT, ALL_COMPORT + } DIResult; + + class DiscomfortIndexSensor + { + private: + + static physicalInput s_PHYSICAL_SOFTSENSORs[PHYSICAL_EA]; + + class InValue + { + public: + std::string m_timestamp; // . + std::string m_discomfortIndex; // Discomfort Index. ( 2 ~ 5 ) + std::string m_humidity; // relative humidity. + std::string m_temperature; // celsius temperature. + }; + + InValue m_DI[PHYSICAL_EA]; + InValue m_result; + + public: + DiscomfortIndexSensor(); + + int runLogic(std::vector< SensorData > &sensorData); + DIResult getInput(std::vector< SensorData > &contextDataList, InValue *data); + DIResult makeDiscomfortIndex(InValue *data); + SensorData setOutput(int property_count, InValue *data); + }; +}; + +#endif /* DISCOMFORTINDEXSENSOR_H_ */ diff --git a/service/basis/resourceContainer/examples/SampleBundle/include/SampleBundle.h b/service/basis/resourceContainer/examples/SampleBundle/include/SampleBundle.h index bb0a6db..976fd43 100644 --- a/service/basis/resourceContainer/examples/SampleBundle/include/SampleBundle.h +++ b/service/basis/resourceContainer/examples/SampleBundle/include/SampleBundle.h @@ -23,7 +23,7 @@ #include -#include "ResourceContainer.h" +#include "ResourceContainerBundleAPI.h" #include "BundleActivator.h" using namespace RC; @@ -34,13 +34,13 @@ class SampleBundle: public BundleActivator SampleBundle(); ~SampleBundle(); - void activateBundle(ResourceContainerInternal resourceContainer); + void activateBundle(ResourceContainerBundleAPI* resourceContainer); void deactivateBundle(); void createResource(); void destroyResource(); - ResourceContainerInternal m_ResourceContainer; + ResourceContainerBundleAPI* m_ResourceContainer; std::vector m_vecResources; }; diff --git a/service/basis/resourceContainer/examples/SampleBundle/include/SysTimer.h b/service/basis/resourceContainer/examples/SampleBundle/include/SysTimer.h new file mode 100644 index 0000000..496d4a4 --- /dev/null +++ b/service/basis/resourceContainer/examples/SampleBundle/include/SysTimer.h @@ -0,0 +1,37 @@ +/****************************************************************** + * + * Copyright 2014 Samsung Electronics All Rights Reserved. + * + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************/ +/* + * SysTimer.h + */ + +#ifndef SYSTIMER_H_ +#define SYSTIMER_H_ + +#include +#include +#include +class SysTimer +{ + public: + static std::string MilliSecondAsString(); + static std::string UTCSecondAsString(); +}; + +#endif /* SYSTIMER_H_ */ diff --git a/service/basis/resourceContainer/examples/SampleBundle/src/DiscomfortIndexSensor.cpp b/service/basis/resourceContainer/examples/SampleBundle/src/DiscomfortIndexSensor.cpp new file mode 100644 index 0000000..14fd35b --- /dev/null +++ b/service/basis/resourceContainer/examples/SampleBundle/src/DiscomfortIndexSensor.cpp @@ -0,0 +1,253 @@ +/****************************************************************** + * + * Copyright 2014 Samsung Electronics All Rights Reserved. + * + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************/ + +/** + * This file contains the exported symbol. + */ +#include +#include +#include +#include +#include + +#include "DiscomfortIndexSensor.h" +#include "SysTimer.h" + +#ifdef __ANDROID__ +#include "OCAndroid.h" +#endif + +using namespace DiscomfortIndexSensorName; + +#define SENSOR_NAME "DiscomfortIndexSensor" + +char *inputName[2] = +{ (char *)"temperature", (char *)"humidity" }; + +physicalInput DiscomfortIndexSensor::s_PHYSICAL_SOFTSENSORs[PHYSICAL_EA] = +{ + { (char *)"Thing_TempHumSensor", 2, (void *) &inputName }, + { (char *)"Thing_TempHumSensor1", 2, (void *) &inputName } +}; + +DiscomfortIndexSensor::DiscomfortIndexSensor() +{ + m_result.m_timestamp = ""; + m_result.m_humidity = ""; + m_result.m_temperature = ""; + m_result.m_discomfortIndex = ""; +} + +int DiscomfortIndexSensor::runLogic(std::vector< SensorData > &sensorData) +{ + std::cout << "[DiscomfortIndexSensor] DiscomfortIndexSensor::" << __func__ << " is called." + << std::endl; + + DIResult result; + + if (getInput(sensorData, m_DI) == SUCCESS) + { + if ((result = makeDiscomfortIndex(m_DI)) != SUCCESS) + { + std::cout << "Error : makeDiscomfortIndex() result = " << result << std::endl; + return -1; + } + + //g_pSoftSensorCore->pushResults(setOutput(4, m_DI)); + + return 0; + } + + return -1; +} + +/** + * Get Input data (temperature, humidity) using resource Client of Iotivity base. + */ +DIResult DiscomfortIndexSensor::getInput(std::vector< SensorData > &sensorData, InValue *data) +{ + //int result_flag = 0; + //int contextSize = 0; + + //if ((contextSize = sensorData.size()) == 0) + //{ + // std::cout << "Physical Context data is not exist." << std::endl; + // return ERROR; + //} + + //for (int i = 0; i < contextSize; i++) + //{ + // for (int k = 0; k < PHYSICAL_EA; k++) + // { + // if (sensorData[i].sensorName == s_PHYSICAL_SOFTSENSORs[k].m_thingName) + // { + // std::vector < std::map< std::string, std::string > > lVector = + // sensorData[i].data; + // int requiredInputNum = s_PHYSICAL_SOFTSENSORs[k].m_inputNum; + // char **pchar = (char **) (s_PHYSICAL_SOFTSENSORs[k].m_pInputStruct); + // if (requiredInputNum == 0) + // { + // std::cout << "No input List." << std::endl; + // return ERROR; + // } + + // for (unsigned int j = 0; j < lVector.size(); j++) + // { + // std::string name = lVector[j]["name"]; + + // if (name.compare(*pchar) == 0) + // { + // data->m_temperature = lVector[j]["value"]; + // requiredInputNum--; + // } + // else if (name.compare(*(++pchar)) == 0) + // { + // data->m_humidity = lVector[j]["value"]; + // requiredInputNum--; + // } + // } + + // if (requiredInputNum == 0) + // { + // data++; + // result_flag++; + // } + // break; + // } // if + // } // for + //} + + //if (result_flag == PHYSICAL_EA) + //{ + // std::cout << "Success : getInput()" << std::endl; + // return SUCCESS; + //} + + //return ERROR; +} + +/** + * Calculation of DiscomfortIndex with TEMP&HUMI of InValue. + */ +DIResult DiscomfortIndexSensor::makeDiscomfortIndex(InValue *data) +{ + int discomfortIndex = (int) ERROR; + double sumDI = 0.0; + + m_result.m_temperature = ""; + m_result.m_humidity = ""; + + for (int i = 0; i < PHYSICAL_EA; i++) + { + if (i != 0) + { + m_result.m_temperature += ", "; + m_result.m_humidity += ", "; + } + + double dI = 0.0; + int t = std::stoi((data + i)->m_temperature); + int h = std::stoi((data + i)->m_humidity); + double F = (9.0 * (double) t) / 5.0 + 32.0; + + std::cout << "Device Number : " << i << std::endl; + + dI = F - (F - 58.0) * (double) ((100 - h) * 55) / 10000.0; + + std::cout << "Discomfort level : " << dI << ", Temperature :" << t << ", Humidity :" << h + << std::endl; + + (data + i)->m_discomfortIndex = std::to_string(0); + m_result.m_temperature += std::to_string(t) + ", "; + m_result.m_humidity += std::to_string(h) + ", "; + sumDI += dI; + } + + sumDI = sumDI / PHYSICAL_EA; + std::cout << "[result] Avg. DI level : " << sumDI << std::endl; + if (sumDI >= 80.0) + { + discomfortIndex = (int) ALL_DISCOMPORT; + std::cout << "DI : " << discomfortIndex << " : All person discomfort. : " << sumDI + << std::endl; + } + else if (sumDI >= 75.0) + { + discomfortIndex = (int) HALF_DISCOMPORT; + std::cout << "DI : " << discomfortIndex << " : Half of person discomfort. : " << sumDI + << std::endl; + } + else if (sumDI >= 68.0) + { + discomfortIndex = (int) LITTLE_DISCOMPORT; + std::cout << "DI : " << discomfortIndex << " : A little person discomfort. : " << sumDI + << std::endl; + } + else + { + discomfortIndex = (int) ALL_COMPORT; + std::cout << "DI : " << discomfortIndex << " : All person comfort. : " << sumDI + << std::endl; + } + + m_result.m_discomfortIndex = std::to_string(discomfortIndex); + std::cout << "[result] Discomfort Index : " << m_result.m_discomfortIndex << std::endl; + + return SUCCESS; +} + +SensorData DiscomfortIndexSensor::setOutput(int property_count, InValue *data) +{ + //SensorData out; + + //std::map < std::string, std::string > output_property; + + //out.sensorName = SENSOR_NAME; + + //output_property.insert(std::make_pair("name", "timestamp")); + //output_property.insert(std::make_pair("type", "string")); + //output_property.insert(std::make_pair("value", m_result.m_timestamp)); + + //out.data.push_back(output_property); + + //output_property.clear(); + //output_property.insert(std::make_pair("name", "temperature")); + //output_property.insert(std::make_pair("type", "string")); + //output_property.insert(std::make_pair("value", m_result.m_temperature)); + + //out.data.push_back(output_property); + + //output_property.clear(); + //output_property.insert(std::make_pair("name", "humidity")); + //output_property.insert(std::make_pair("type", "string")); + //output_property.insert(std::make_pair("value", m_result.m_humidity)); + + //out.data.push_back(output_property); + + //output_property.clear(); + //output_property.insert(std::make_pair("name", "discomfortIndex")); + //output_property.insert(std::make_pair("type", "int")); + //output_property.insert(std::make_pair("value", m_result.m_discomfortIndex)); + + //out.data.push_back(output_property); + + //return out; +} + diff --git a/service/basis/resourceContainer/examples/SampleBundle/src/SampleBundle.cpp b/service/basis/resourceContainer/examples/SampleBundle/src/SampleBundle.cpp index c294e95..bec7077 100644 --- a/service/basis/resourceContainer/examples/SampleBundle/src/SampleBundle.cpp +++ b/service/basis/resourceContainer/examples/SampleBundle/src/SampleBundle.cpp @@ -19,6 +19,9 @@ //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= #include "SampleBundle.h" +#include "ResourceContainerBundleAPI.h" +#include "Configuration.h" + using namespace RC; @@ -32,23 +35,24 @@ SampleBundle::~SampleBundle() { } -void SampleBundle::activateBundle(ResourceContainerInternal resourceContainer) +void SampleBundle::activateBundle(ResourceContainerBundleAPI* resourceContainer) { std::cout << "SampleBundle::activateBundle called" << std::endl; m_ResourceContainer = resourceContainer; // parse configuration, instantiate resource and register resources - ConfigParam configParam = m_ResourceContainer.getConfiguration(CONFIG_RESOURCES, "oic.bundle.sample"); + Configuration::configInfo config; + // m_ResourceContainer->getConfiguration(ConfigKey::CONFIG_RESOURCES, "oic.bundle.sample", &config); std::cout << "Resource Information" << std::endl; - for (int i = 0; i < configParam.size(); i++) - { - for (map ::iterator itor = configParam[i].begin(); itor != configParam[i].end(); - itor++) - - cout << "key : " << itor->first << " | value : " << itor->second << endl; - } + // for (int i = 0; i < configParam.size(); i++) + //{ + // for (map ::iterator itor = configParam[i].begin(); itor != configParam[i].end(); + // itor++) + // + // cout << "key : " << itor->first << " | value : " << itor->second << endl; + // } // createResource(); } @@ -73,9 +77,8 @@ void SampleBundle::destroyResource() //std::cout << "resourceContainer.unregisterResource()" << std::endl; } -extern "C" void externalActivateBundle(ResourceContainerInternal resourceContainer) +extern "C" void externalActivateBundle(ResourceContainerBundleAPI* resourceContainer) { - printf("External activate\n"); bundle = new SampleBundle(); bundle->activateBundle(resourceContainer); } @@ -86,5 +89,4 @@ extern "C" void externalDeactivateBundle() { bundle->deactivateBundle(); } - printf("External deactivate\n"); -} \ No newline at end of file +} diff --git a/service/basis/resourceContainer/examples/SampleBundle/src/SysTimer.cpp b/service/basis/resourceContainer/examples/SampleBundle/src/SysTimer.cpp new file mode 100644 index 0000000..032e0fc --- /dev/null +++ b/service/basis/resourceContainer/examples/SampleBundle/src/SysTimer.cpp @@ -0,0 +1,56 @@ +/****************************************************************** + * + * Copyright 2014 Samsung Electronics All Rights Reserved. + * + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************/ + +#include +#include +#include +#include +#include + +#include "SysTimer.h" + +#include +std::string SysTimer::MilliSecondAsString() +{ + std::stringstream ss; + struct timeval tv; + + gettimeofday(&tv, NULL); + long long val = tv.tv_sec * (long long) 1000 + tv.tv_usec / 1000; + + ss << val; + std::string strTime = ss.str(); + + return strTime; +} + +std::string SysTimer::UTCSecondAsString() +{ + std::stringstream ss; + struct timeval tv; + + gettimeofday(&tv, NULL); + unsigned long val = tv.tv_sec; + + ss << val; + std::string strTime = ss.str(); + + return strTime; +} diff --git a/service/basis/resourceContainer/include/BundleActivator.h b/service/basis/resourceContainer/include/BundleActivator.h index 0fa4bad..62d20ab 100644 --- a/service/basis/resourceContainer/include/BundleActivator.h +++ b/service/basis/resourceContainer/include/BundleActivator.h @@ -18,22 +18,24 @@ // //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= -#ifndef RESOURCEBUNDLE_H_ -#define RESOURCEBUNDLE_H_ +#ifndef BUNDLEACTIVATOR_H_ +#define BUNDLEACTIVATOR_H_ -#include "ResourceContainerInternal.h" +#include "ResourceContainerBundleAPI.h" using namespace RC; -namespace RC{ - class BundleActivator { +namespace RC +{ + class BundleActivator + { - public: - BundleActivator(); - virtual ~BundleActivator(); - virtual void activateBundle(ResourceContainerInternal resourceContainer); - virtual void deactivateBundle(); - }; + public: + BundleActivator(); + virtual ~BundleActivator(); + virtual void activateBundle(ResourceContainerBundleAPI* resourceContainer); + virtual void deactivateBundle(); + }; } #endif /* RESOURCEBUNDLE_H_ */ diff --git a/service/basis/resourceContainer/include/BundleInfo.h b/service/basis/resourceContainer/include/BundleInfo.h index d207bce..1c725b8 100644 --- a/service/basis/resourceContainer/include/BundleInfo.h +++ b/service/basis/resourceContainer/include/BundleInfo.h @@ -18,7 +18,6 @@ // //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - #ifndef BUNDLEINFO_H_ #define BUNDLEINFO_H_ @@ -26,25 +25,27 @@ using namespace std; -namespace RC{ - /* - * Describes a bundle with resources, that can be loaded dynamically. - */ - class BundleInfo { - public: - BundleInfo(); - virtual ~BundleInfo(); - void setName(string name); - string getName(); - void setPath(string path); - string getPath(); - void setVersion(string version); - string getVersion(); - virtual int getId() = 0; // will be set by container - static BundleInfo* createBundleInfo(); - private: - string m_name, m_path, m_version; - }; +namespace RC +{ + /* + * 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_ */ diff --git a/service/basis/resourceContainer/include/BundleInfoInternal.h b/service/basis/resourceContainer/include/BundleInfoInternal.h index 70c1426..820322f 100644 --- a/service/basis/resourceContainer/include/BundleInfoInternal.h +++ b/service/basis/resourceContainer/include/BundleInfoInternal.h @@ -18,41 +18,57 @@ // //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - #ifndef BUNDLEINFOINTERNAL_H_ #define BUNDLEINFOINTERNAL_H_ #include #include "BundleInfo.h" +#include "ResourceContainerBundleAPI.h" using namespace std; using namespace RC; -namespace RC{ - /* - * Adds resource container specific flags to the bundle info class. - */ - class BundleInfoInternal : public BundleInfo { - public: - BundleInfoInternal(); - BundleInfoInternal(BundleInfo* info); - virtual ~BundleInfoInternal(); - void setName(string name); - string getName(); - void setPath(string path); - string getPath(); - void setVersion(string version); - - void setLoaded(bool loaded); - bool isLoaded(); - void setActivated(bool activated); - bool isActivated(); - int getId(); - void setId(int id); - private: - bool m_loaded, m_activated; - int m_id; - }; +namespace RC +{ + typedef void activator_t(ResourceContainerBundleAPI *); + typedef void deactivator_t(void); + + 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 setLoaded(bool loaded); + bool isLoaded(); + void setActivated(bool activated); + bool isActivated(); + int getId(); + void setId(int id); + + void setBundleActivator(activator_t*); + activator_t* getBundleActivator(); + + void setBundleDeactivator(deactivator_t*); + deactivator_t* getBundleDeactivator(); + + 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_ */ diff --git a/service/basis/resourceContainer/include/BundleResource.h b/service/basis/resourceContainer/include/BundleResource.h new file mode 100644 index 0000000..c2c87b8 --- /dev/null +++ b/service/basis/resourceContainer/include/BundleResource.h @@ -0,0 +1,53 @@ +//****************************************************************** +// +// 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 BUNDLERESOURCE_H_ +#define BUNDLERESOURCE_H_ + +#include +#include + +namespace RC +{ + class BundleResource + { + public: + BundleResource(); + virtual ~BundleResource(); + + virtual void onGetRequest() = 0; + virtual void onSetRequest() = 0; + + std::map m_mapAttributes; + }; + + class SoftSensorResource : public BundleResource + { + public: + SoftSensorResource(); + virtual ~SoftSensorResource(); + + virtual void runLogic() = 0; + + std::map m_mapInputs; + }; +} + +#endif diff --git a/service/basis/resourceContainer/include/Configuration.h b/service/basis/resourceContainer/include/Configuration.h new file mode 100644 index 0000000..f72d7af --- /dev/null +++ b/service/basis/resourceContainer/include/Configuration.h @@ -0,0 +1,67 @@ +//****************************************************************** +// +// Copyright 2015 Samsung Electronics All Rights Reserved. +// +//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + +#ifndef CONFIGURATION_H_ +#define CONFIGURATION_H_ + +#include +#include +#include + +#include "ResourceContainer.h" +#include "BundleInfo.h" + +using namespace RC; + +namespace RC +{ + + +class Configuration +{ + public: + typedef vector> 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; + }; + + Configuration(); + ~Configuration(); + + Configuration(string configFile); + + void getCommonConfiguration(configInfo *configOutput); + void getBundleConfiguration(std::string bundleId, configInfo *configOutput); + void getResourceConfiguration(std::string bundleId, std::vector *configOutput); + void getConfiguredBundles(configInfo *configOutput); + + private: + void getConfigDocument(std::string pathConfigFile, std::string *pConfigData); + void getCurrentPath(std::string *path); + + string m_pathConfigFile, m_configFile; +}; +} + +#endif diff --git a/service/basis/resourceContainer/include/ResourceContainer.h b/service/basis/resourceContainer/include/ResourceContainer.h index 76b74f2..895711b 100644 --- a/service/basis/resourceContainer/include/ResourceContainer.h +++ b/service/basis/resourceContainer/include/ResourceContainer.h @@ -26,6 +26,8 @@ #include #include +#include "BundleInfo.h" + #include "rapidxml/rapidxml.hpp" #include "rapidxml/rapidxml_print.hpp" @@ -33,20 +35,8 @@ using namespace std; namespace RC { - /* - * Describes a bundle with resources, that can be loaded dynamically. - */ - class BundleInfo - { - public: - BundleInfo(); - virtual ~BundleInfo(); - public: - string id, name, path, version; - - }; - // Will be provided by the resource builder + // placeholder class Resource { @@ -54,55 +44,24 @@ namespace RC class ResourceContainer { - public: - ResourceContainer(); - virtual ~ResourceContainer(); - virtual void init() = 0; - virtual void registerBundle(BundleInfo bundleinfo) = 0; - virtual void activateBundle(string id) = 0; - virtual void activateBundleByName(string name) = 0; - virtual void deactivateBundle(string id) = 0 ; - virtual void deactivateBundleByName(string id) = 0; - virtual vector listBundleResources(string id) = 0; - }; - - typedef vector < map < std::string, std::string > > ConfigParam; - typedef enum { CONFIG_COMMON, CONFIG_BUNDLES, CONFIG_RESOURCES } ConfigKey; - - class ResourceContainerInternal : public ResourceContainer - { - public: - ResourceContainerInternal(); - virtual ~ResourceContainerInternal(); - void registerResource(Resource *resource); - void unregisterResource(Resource *resource); - - ConfigParam getConfiguration(string configKey); - ConfigParam getConfiguration(ConfigKey configKey, string id = ""); - - void init(); - void registerBundle(BundleInfo bundleinfo); - void activateBundle(string id); - void activateBundleByName(string name); - void deactivateBundle(string id); - void deactivateBundleByName(string name); - vector listBundleResources(string id); - - private: - void getConfigDocument(std::string pathConfigFile, std::string *pConfigData); - void getConfigBundleData(rapidxml::xml_node< char > *configData, string BundleId, - ConfigParam *pConfigOutput); - void getConfigResourceData(rapidxml::xml_node< char > *configData, string BundleId, - ConfigParam *pConfigOutput); - void getCurrentPath(std::string *path); - }; - - // TBD - class InputPropertyDescriptor - { - + public: + ResourceContainer(); + virtual ~ResourceContainer(); + virtual void init() = 0; + virtual void init(string configFile) = 0; + virtual void registerBundle(BundleInfo* bundleinfo) = 0; + virtual void unregisterBundle(BundleInfo* bundleinfo) = 0; + virtual void unregisterBundle(int id) = 0; + virtual void activateBundle(int id) = 0; + virtual void deactivateBundle(int id) = 0; + virtual void activateBundleByName(string name) = 0; + virtual void deactivateBundleByName(string id) = 0; + virtual void activateBundle(BundleInfo* bundleInfo) = 0; + virtual void deactivateBundle(BundleInfo* bundleInfo) = 0; + virtual vector< Resource * > listBundleResources(string id) = 0; + + static ResourceContainer* getInstance(); }; } - #endif /* RESOURCECONTAINER_H_ */ diff --git a/service/basis/resourceContainer/include/ResourceContainerBundleAPI.h b/service/basis/resourceContainer/include/ResourceContainerBundleAPI.h new file mode 100644 index 0000000..1ceb3f8 --- /dev/null +++ b/service/basis/resourceContainer/include/ResourceContainerBundleAPI.h @@ -0,0 +1,52 @@ +//****************************************************************** +// +// 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 RESOURCECONTAINERBUNDLEAPI_H_ +#define RESOURCECONTAINERBUNDLEAPI_H_ + +#include +#include +#include + +#include "ResourceContainer.h" +#include "BundleInfo.h" +#include "Configuration.h" + +using namespace RC; + +namespace RC +{ + class ResourceContainerBundleAPI : public Configuration + { + public: + typedef std::map configInfo; + ResourceContainerBundleAPI(); + virtual ~ResourceContainerBundleAPI(); + virtual void registerResource(Resource *resource) = 0; + virtual void unregisterResource(Resource *resource) = 0; + void getCommonConfiguration(configInfo *configOutput); + void getBundleConfiguration(std::string bundleId, configInfo *configOutput); + void getResourceConfiguration(std::string bundleId, std::vector *configOutput); + + static ResourceContainerBundleAPI *getInstance(); + }; +} + +#endif diff --git a/service/basis/resourceContainer/include/ResourceContainerImpl.h b/service/basis/resourceContainer/include/ResourceContainerImpl.h new file mode 100644 index 0000000..173b807 --- /dev/null +++ b/service/basis/resourceContainer/include/ResourceContainerImpl.h @@ -0,0 +1,66 @@ +//****************************************************************** +// +// 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 RESOURCECONTAINERIMPL_H_ +#define RESOURCECONTAINERIMPL_H_ + +#include "ResourceContainer.h" +#include "ResourceContainerBundleAPI.h" +#include "BundleInfoInternal.h" + +using namespace RC; + +namespace RC +{ + + class ResourceContainerImpl: public ResourceContainer, public ResourceContainerBundleAPI + { + public: + ResourceContainerImpl(); + virtual ~ResourceContainerImpl(); + + // methods from ResourceContainer + void init(); + void init(string configFile); + void activateBundle(int id); + void deactivateBundle(int id); + void activateBundleByName(string name); + void deactivateBundleByName(string id); + void activateBundle(BundleInfo* bundleInfo); + void deactivateBundle(BundleInfo* bundleInfo); + vector< Resource* > listBundleResources(string id); + + // methods from ResourceContainerBundleAPI + void registerBundle(BundleInfo* bundleinfo); + void unregisterBundle(BundleInfo* bundleinfo); + void unregisterBundle(int id); + void registerResource(Resource* resource); + void unregisterResource(Resource* resource); + + static ResourceContainerImpl* getImplInstance(); + + private: + vector m_bundles; + string m_configFile; + Configuration m_config; + }; +} + +#endif diff --git a/service/basis/resourceContainer/src/BundleActivator.cpp b/service/basis/resourceContainer/src/BundleActivator.cpp index 72f1b42..3b6295f 100644 --- a/service/basis/resourceContainer/src/BundleActivator.cpp +++ b/service/basis/resourceContainer/src/BundleActivator.cpp @@ -23,19 +23,24 @@ using namespace RC; -BundleActivator::BundleActivator(){ - -} +namespace RC{ + BundleActivator::BundleActivator() + { + } -BundleActivator::~BundleActivator(){ + BundleActivator::~BundleActivator() + { -} + } -void BundleActivator::activateBundle(ResourceContainerInternal resourceContainer){ + void BundleActivator::activateBundle(ResourceContainerBundleAPI* resourceContainer) + { -} + } -void BundleActivator::deactivateBundle(){ + void BundleActivator::deactivateBundle() + { + } } diff --git a/service/basis/resourceContainer/src/BundleInfo.cpp b/service/basis/resourceContainer/src/BundleInfo.cpp index 097a3bf..1d04f83 100644 --- a/service/basis/resourceContainer/src/BundleInfo.cpp +++ b/service/basis/resourceContainer/src/BundleInfo.cpp @@ -21,40 +21,21 @@ #include "BundleInfo.h" #include "BundleInfoInternal.h" -namespace RC{ - BundleInfo::BundleInfo(){ +namespace RC +{ + BundleInfo::BundleInfo() + { - } + } - BundleInfo::~BundleInfo(){ + BundleInfo::~BundleInfo() + { - } + } - void BundleInfo::setName(string name){ - m_name = name; - } - - string BundleInfo::getName(){ - return m_name; - } - - void BundleInfo::setPath(string path){ - m_path = path; - } - string BundleInfo::getPath(){ - return m_path; - } - - void BundleInfo::setVersion(string version){ - m_version = version; - } - - string BundleInfo::getVersion(){ - return m_version; - } - - BundleInfo* BundleInfo::createBundleInfo(){ - BundleInfoInternal* newBundleInfo = new BundleInfoInternal(); - return newBundleInfo; - } + BundleInfo* BundleInfo::createBundleInfo() + { + BundleInfoInternal* newBundleInfo = new BundleInfoInternal(); + return newBundleInfo; + } } diff --git a/service/basis/resourceContainer/src/BundleInfoInternal.cpp b/service/basis/resourceContainer/src/BundleInfoInternal.cpp new file mode 100644 index 0000000..eae79a5 --- /dev/null +++ b/service/basis/resourceContainer/src/BundleInfoInternal.cpp @@ -0,0 +1,123 @@ +//****************************************************************** +// +// 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 "BundleInfoInternal.h" + +namespace RC +{ + 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; + } +} diff --git a/service/basis/resourceContainer/src/Configuration.cpp b/service/basis/resourceContainer/src/Configuration.cpp new file mode 100644 index 0000000..736a918 --- /dev/null +++ b/service/basis/resourceContainer/src/Configuration.cpp @@ -0,0 +1,362 @@ +//****************************************************************** +// +// 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 "Configuration.h" + +static inline std::string trim_both(const std::string &str) +{ + int npos = str.find_first_not_of(" \t\v\n\r"); + + if (npos == -1) + { + return ""; + } + + unsigned int n = (unsigned int)npos; + std::string tempString = n == std::string::npos ? str : str.substr(n, str.length()); + + n = tempString.find_last_not_of(" \t\v\n\r"); + + return n == std::string::npos ? tempString : tempString.substr(0, n + 1); +} + +Configuration::Configuration() +{ + // TODO: temporary path and config file name + getCurrentPath(&m_pathConfigFile); + m_pathConfigFile.append("/"); + m_pathConfigFile.append("ResourceContainerConfig.xml"); +} + +Configuration::~Configuration() +{} + +Configuration::Configuration(string configFile){ + m_configFile = configFile; + getCurrentPath(&m_pathConfigFile); + m_pathConfigFile.append("/"); + m_pathConfigFile.append(m_configFile); +} + +void Configuration::getCommonConfiguration(configInfo *configOutput) +{ + string strConfigData; + + rapidxml::xml_document< char > xmlDoc; + + rapidxml::xml_node< char > *root; + rapidxml::xml_node< char > *item; + rapidxml::xml_node< char > *subItem; + + string strKey, strValue; + + getConfigDocument(m_pathConfigFile, &strConfigData); + + try + { + xmlDoc.parse< 0 >((char *)strConfigData.c_str()); + + // + root = xmlDoc.first_node(); + + if (!root) + { + throw rapidxml::parse_error("No Root Element", 0); + } + std::map< std::string, std::string > bundleMap; + for (item = root->first_node(); item; item = item->next_sibling()) + { + strKey = item->name(); + strValue = item->value(); + + // + if (!strKey.compare("config")) + { + for (subItem = item->first_node(); subItem; + subItem = subItem->next_sibling()) + { + strKey = subItem->name(); + strValue = subItem->value(); + + bundleMap.insert(std::make_pair(trim_both(strKey), trim_both(strValue))); + } + break; + } + } + configOutput->push_back(bundleMap); + } + catch (rapidxml::parse_error &e) + { + cout << "xml parsing failed !!" << endl; + cout << e.what() << endl; + } +} + +void Configuration::getConfiguredBundles(configInfo* configOutput){ + string strConfigData; + + rapidxml::xml_document< char > xmlDoc; + + rapidxml::xml_node< char > *root; + rapidxml::xml_node< char > *bundle; + rapidxml::xml_node< char > *subItem; + + string strKey, strValue; + + cout << "Opening: " << m_pathConfigFile << endl; + + getConfigDocument(m_pathConfigFile, &strConfigData); + + //cout << strConfigData.c_str() << endl; + try + { + + xmlDoc.parse< 0 >((char *)strConfigData.c_str()); + //cout << "Name of first node is: " << xmlDoc.first_node()->name() << endl; + + for (bundle = xmlDoc.first_node()->first_node("bundle"); bundle; bundle = bundle->next_sibling()) + { + 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; + } +} + +void Configuration::getBundleConfiguration(string bundleId, configInfo *configOutput) +{ + string strConfigData; + + rapidxml::xml_document< char > xmlDoc; + + rapidxml::xml_node< char > *root; + rapidxml::xml_node< char > *item; + rapidxml::xml_node< char > *subItem; + + string strKey, strValue; + + getConfigDocument(m_pathConfigFile, &strConfigData); + + try + { + xmlDoc.parse< 0 >((char *)strConfigData.c_str()); + + // + root = xmlDoc.first_node(); + + if (!root) + { + throw rapidxml::parse_error("No Root Element", 0); + } + std::map< std::string, std::string > bundleMap; + for (item = root->first_node(); item; item = item->next_sibling()) + { + strKey = item->name(); + strValue = item->value(); + + // + if (!strKey.compare("bundle")) + { + for (subItem = item->first_node(); subItem; subItem = subItem->next_sibling()) + { + strKey = subItem->name(); + strValue = subItem->value(); + + if (!strKey.compare("bundleID") && strValue.compare(bundleId)) + break; + + // 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; + } +} + +void Configuration::getResourceConfiguration(string bundleId, vector *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; + + string strKey, strValue; + + getConfigDocument(m_pathConfigFile, &strConfigData); + + try + { + xmlDoc.parse< 0 >((char *)strConfigData.c_str()); + + // + root = xmlDoc.first_node(); + + if (!root) + { + throw rapidxml::parse_error("No Root Element", 0); + } + + for (item = root->first_node(); item; item = item->next_sibling()) + { + strKey = item->name(); + strValue = item->value(); + + // + if (!strKey.compare("bundle")) + { + for (subItem = item->first_node(); subItem; subItem = subItem->next_sibling()) + { + strKey = subItem->name(); + strValue = subItem->value(); + + if (!strKey.compare("bundleID") && strValue.compare(bundleId)) + break; + + // + if (!strKey.compare("resources")) + { + for (subItem2 = subItem->first_node(); subItem2; + subItem2 = subItem2->next_sibling()) + { + strKey = subItem2->name(); + strValue = subItem2->value(); + + // : for 1 resource + if (!strKey.compare("resourceInfo")) + { + resourceInfo tempResourceInfo; + + for (subItem3 = subItem2->first_node(); subItem3; subItem3 = subItem3->next_sibling()) + { + + strKey = subItem3->name(); + strValue = subItem3->value(); + + if (!strKey.compare("name")) + tempResourceInfo.name = trim_both(strValue); + + else if (!strKey.compare("uri")) + tempResourceInfo.uri = trim_both(strValue); + + else if (!strKey.compare("resourceType")) + tempResourceInfo.resourceType = trim_both(strValue); + + else + { + for (subItem4 = subItem3->first_node(); subItem4; subItem4 = subItem4->next_sibling()) + { + map 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); + } + } + } + configOutput->push_back(tempResourceInfo); + } + } + } + } + } + } + } + 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()); + + if (!xmlFile.fail()) + { + xmlFile.seekg(0, std::ios::end); + unsigned int size = (unsigned int)xmlFile.tellg(); + xmlFile.seekg(0); + + std::vector< char > xmlData(size + 1); + xmlData[size] = 0; + + xmlFile.read(&xmlData.front(), (std::streamsize) size); + xmlFile.close(); + *pConfigData = std::string(xmlData.data()); + } + else + { + std::cout << "Configuration File load failed !!" << std::endl; + } +} + +void Configuration::getCurrentPath(std::string *path) +{ + char buffer[2048]; + char *strPath = NULL; + + int length = readlink("/proc/self/exe", buffer, 2047); + + buffer[length] = '\0'; + + strPath = strrchr(buffer, '/'); + + *strPath = '\0'; + + path->append(buffer); +} diff --git a/service/basis/resourceContainer/src/ContainerTest.cpp b/service/basis/resourceContainer/src/ContainerTest.cpp index 919ab76..1defa11 100644 --- a/service/basis/resourceContainer/src/ContainerTest.cpp +++ b/service/basis/resourceContainer/src/ContainerTest.cpp @@ -18,21 +18,43 @@ // //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= -#include "ResourceContainerInternal.h" +#include "ResourceContainer.h" #include "BundleInfo.h" +#include "oc_logger.hpp" using namespace RC; +using OC::oc_log_stream; -int main(){ - printf("Test\n"); - BundleInfo* bundleInfo = BundleInfo::createBundleInfo(); - bundleInfo->setPath("/home/iotivity/development/iotivity-mj-rc/iotivity-mj/out/linux/x86/release/service/resource-container/libSampleBundle.so"); - bundleInfo->setVersion("1.0"); - bundleInfo->setName("Sample Bundle"); +/* Annother way to create a context: */ +auto info_logger = []() -> boost::iostreams::stream& +{ + static OC::oc_log_stream ols(oc_make_ostream_logger); + static boost::iostreams::stream os(ols); - ResourceContainerInternal container; - container.registerBundle(bundleInfo); + return os; +}; - //bundleInfo.path = "/"; - //bundleInfo.version = "1.0"; +int main() +{ + info_logger()->set_module("ContainerTest"); + info_logger()->set_level(OC_LOG_INFO); + + info_logger() << "Starting container test." << std::flush; + + /*BundleInfo* bundleInfo = BundleInfo::createBundleInfo(); + bundleInfo->setPath( + "/home/iotivity/development/iotivity-mj/out/linux/x86/release/libSampleBundle.so"); + bundleInfo->setVersion("1.0"); + bundleInfo->setName("Sample Bundle");*/ + + ResourceContainer* container = ResourceContainer::getInstance(); + container->init("examples/ResourceContainerConfig.xml"); + + //container->registerBundle(bundleInfo); + //container->activateBundle(bundleInfo); + //container->deactivateBundle(bundleInfo); + //container->unregisterBundle(bundleInfo); + + //bundleInfo.path = "/"; + //bundleInfo.version = "1.0"; } diff --git a/service/basis/resourceContainer/include/ResourceContainerInternal.h b/service/basis/resourceContainer/src/ResourceContainer.cpp similarity index 54% rename from service/basis/resourceContainer/include/ResourceContainerInternal.h rename to service/basis/resourceContainer/src/ResourceContainer.cpp index 0a89743..c77a0b1 100644 --- a/service/basis/resourceContainer/include/ResourceContainerInternal.h +++ b/service/basis/resourceContainer/src/ResourceContainer.cpp @@ -18,29 +18,25 @@ // //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= -#ifndef RESOURCECONTAINERINTERNAL_H_ -#define RESOURCECONTAINERINTERNAL_H_ - #include "ResourceContainer.h" +#include "ResourceContainerImpl.h" + +namespace RC +{ + + ResourceContainer::ResourceContainer() + { + + } + + ResourceContainer::~ResourceContainer() + { + + } -using namespace RC; - -namespace RC{ - class ResourceContainerInternal: public ResourceContainer { - public: - ResourceContainerInternal(); - virtual ~ResourceContainerInternal(); - void registerResource(Resource* resource); - void unregisterResource(Resource* resource); - ConfigParam getConfiguration(string configKey); - void init(); - void registerBundle(BundleInfo* bundleinfo); - void activateBundle(string id); - void activateBundleByName(string name); - void deactivateBundle(string id); - void deactivateBundleByName(string id); - vector listBundleResources(string id); - }; + ResourceContainer* ResourceContainer::getInstance() + { + return (ResourceContainer*) ResourceContainerImpl::getImplInstance(); + } } -#endif //RESOURCECONTAINERINTERNAL_H_ diff --git a/service/basis/resourceContainer/src/ResourceContainerBundleAPI.cpp b/service/basis/resourceContainer/src/ResourceContainerBundleAPI.cpp new file mode 100644 index 0000000..b2d3170 --- /dev/null +++ b/service/basis/resourceContainer/src/ResourceContainerBundleAPI.cpp @@ -0,0 +1,38 @@ +//****************************************************************** +// +// Copyright 2015 Samsung Electronics All Rights Reserved. +// +//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + +#include "ResourceContainerBundleAPI.h" + +using namespace RC; + +namespace RC +{ + + ResourceContainerBundleAPI::ResourceContainerBundleAPI() + { + + } + + ResourceContainerBundleAPI::~ResourceContainerBundleAPI() + { + + } + +} diff --git a/service/basis/resourceContainer/src/ResourceContainerImpl.cpp b/service/basis/resourceContainer/src/ResourceContainerImpl.cpp new file mode 100644 index 0000000..ed1babd --- /dev/null +++ b/service/basis/resourceContainer/src/ResourceContainerImpl.cpp @@ -0,0 +1,238 @@ +//****************************************************************** +// +// 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 "ResourceContainerImpl.h" +#include "BundleActivator.h" +#include "ResourceContainer.h" +#include "BundleInfoInternal.h" +#include "logger.h" + +#include +#include +#include +#include +#include + +#include "oc_logger.hpp" + +using OC::oc_log_stream; + +auto info_logger = []() -> boost::iostreams::stream& +{ + static OC::oc_log_stream ols(oc_make_ostream_logger); + static boost::iostreams::stream os(ols); + os->set_level(OC_LOG_INFO); + os->set_module("ResourceContainerImpl"); + return os; +}; + +auto error_logger = []() -> boost::iostreams::stream& +{ + static OC::oc_log_stream ols(oc_make_ostream_logger); + static boost::iostreams::stream os(ols); + os->set_level(OC_LOG_ERROR); + os->set_module("ResourceContainerImpl"); + return os; +}; + +using namespace std; +using namespace RC; + +namespace RC +{ + + ResourceContainerImpl::ResourceContainerImpl() + { + // TODO Auto-generated constructor stub + + } + + ResourceContainerImpl::~ResourceContainerImpl() + { + // TODO Auto-generated destructor stub + } + + void ResourceContainerImpl::init() + { + + } + + void ResourceContainerImpl::init(string configFile) + { + Configuration config(configFile); + Configuration::configInfo bundles; + 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; + + m_bundles.push_back((BundleInfoInternal*) bundleInfo); + ((BundleInfoInternal*) bundleInfo)->setId(m_bundles.size() - 1); + + const char* error; + + activator_t* bundleActivator = NULL; + deactivator_t* bundleDeactivator = NULL; + + //sstream << bundleInfo.path << std::ends; + + 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) + { + error_logger() << error << endl; + } + else + { + ((BundleInfoInternal*) bundleInfo)->setBundleActivator(bundleActivator); + ((BundleInfoInternal*) bundleInfo)->setBundleDeactivator(bundleDeactivator); + ((BundleInfoInternal*) bundleInfo)->setLoaded(true); + ((BundleInfoInternal*) bundleInfo)->setBundleHandle(bundleHandle); + } + } + else + { + if ((error = dlerror()) != NULL) + { + error_logger() << error << 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) + { + bundleActivator(this); + m_bundles[id]->setActivated(true); + } + else + { + //Unload module and return error + error_logger() << "Activation unsuccessful." << endl; + } + } + + void ResourceContainerImpl::activateBundle(BundleInfo* bundleInfo) + { + if (((BundleInfoInternal*) bundleInfo)->isLoaded()) + { + activateBundle(bundleInfo->getId()); + } + } + + void ResourceContainerImpl::deactivateBundle(BundleInfo* bundleInfo) + { + if (((BundleInfoInternal*) bundleInfo)->isActivated()) + { + 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) + { + bundleDeactivator(); + m_bundles[id]->setActivated(false); + } + else + { + //Unload module and return error + error_logger() << "De-activation unsuccessful." << endl; + } + } + + void ResourceContainerImpl::activateBundleByName(string name) + { + + } + + void ResourceContainerImpl::deactivateBundleByName(string id) + { + + } + + vector< Resource* > ResourceContainerImpl::listBundleResources(string id) + { + vector< Resource* > ret; + return ret; + } + + void ResourceContainerImpl::registerResource(Resource* resource) + { + + } + + void ResourceContainerImpl::unregisterResource(Resource* resource) + { + + } + + void ResourceContainerImpl::unregisterBundle(BundleInfo* bundleInfo){ + if (((BundleInfoInternal*) bundleInfo)->isLoaded() && !((BundleInfoInternal*) bundleInfo)->isActivated()) + { + 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; + const char* error; + dlclose(bundleHandle); + if ((error = dlerror()) != NULL) + { + error_logger() << error << endl; + } + } + + ResourceContainerImpl* ResourceContainerImpl::getImplInstance() + { + ResourceContainerImpl* ret = new ResourceContainerImpl(); + return ret; + } +} diff --git a/service/basis/resourceContainer/src/ResourceContainerInternal.cpp b/service/basis/resourceContainer/src/ResourceContainerInternal.cpp deleted file mode 100644 index dca0c5a..0000000 --- a/service/basis/resourceContainer/src/ResourceContainerInternal.cpp +++ /dev/null @@ -1,361 +0,0 @@ -//****************************************************************** -// -// Copyright 2015 Samsung Electronics All Rights Reserved. -// -//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - -#include "ResourceContainerInternal.h" -#include "BundleActivator.h" -#include -#include - -#include -#include -#include -#include -#include - - -using namespace std; - -static inline std::string trim_both(const std::string &str) -{ - int npos = str.find_first_not_of(" \t\v\n\r"); - - if (npos == -1) - { - return ""; - } - - unsigned int n = (unsigned int) npos; - std::string tempString = n == std::string::npos ? str : str.substr(n, str.length()); - - n = tempString.find_last_not_of(" \t\v\n\r"); - - return n == std::string::npos ? tempString : tempString.substr(0, n + 1); -} - -namespace RC { - - ResourceContainerInternal::ResourceContainerInternal() { - // TODO Auto-generated constructor stub - - } - - ResourceContainerInternal::~ResourceContainerInternal() { - // TODO Auto-generated destructor stub - } - - void ResourceContainerInternal::init() { - - } - - // loads the bundle - void ResourceContainerInternal::registerBundle(BundleInfo* bundleInfo) { - - cout << "\nRegistering bundle: " << bundleInfo->getPath() << "\n"; - char* error; - - typedef void (*activator_t)(ResourceContainerInternal *); - activator_t bundleActivator = NULL; - - //sstream << bundleInfo.path << std::ends; - - void *hModule = NULL; - hModule = dlopen(bundleInfo->getPath().c_str(), RTLD_LAZY); - - if (hModule != NULL) { - bundleActivator = (activator_t) dlsym(hModule, - "externalActivateBundle"); - if ((error = dlerror()) != NULL) { - fprintf(stderr, "%s\n", error); - } - } else { - if ((error = dlerror()) != NULL) { - fprintf(stderr, "%s\n", error); - } - } - - if (bundleActivator != NULL) { - bundleActivator(this); - } else { - //Unload module and return error - printf("load unsuccessful.\n"); - } - } - - void ResourceContainerInternal::activateBundle(string id) { - - } - - void ResourceContainerInternal::activateBundleByName(string name) { - - } - - void ResourceContainerInternal::deactivateBundle(string id) { - - } - - void ResourceContainerInternal::deactivateBundleByName(string id) { - - } - - vector ResourceContainerInternal::listBundleResources(string id) { - - } - - void ResourceContainerInternal::registerResource(Resource* resource) { - - } - - void ResourceContainerInternal::unregisterResource(Resource* resource) { - - } - - ConfigParam getConfiguration(string configKey) {} - - ConfigParam ResourceContainerInternal::getConfiguration(ConfigKey configKey, string id) - { - string pathXMLFile; - string strConfigData; - ConfigParam configOutput; - - rapidxml::xml_document< char > xmlDoc; - - rapidxml::xml_node< char > *root; - rapidxml::xml_node< char > *item; - rapidxml::xml_node< char > *subItem; - - string strKey, strValue; - - // TODO: temporary path and config file name - getCurrentPath(&pathXMLFile); - pathXMLFile.append("/"); - pathXMLFile.append("ResourceContainerConfig.xml"); - - getConfigDocument(pathXMLFile, &strConfigData); - - try - { - xmlDoc.parse< 0 >((char *) strConfigData.c_str()); - - // - root = xmlDoc.first_node(); - - if (!root) - { - throw rapidxml::parse_error("No Root Element", 0); - } - - switch (configKey) - { - case CONFIG_COMMON: - for (item = root->first_node(); item; item = item->next_sibling()) - { - strKey = item->name(); - strValue = item->value(); - - if (!strKey.compare("config")) - { - for (subItem = item->first_node(); subItem; subItem = subItem->next_sibling()) - { - strKey = subItem->name(); - strValue = subItem->value(); - - map < string, string > mapCommonConfig; - mapCommonConfig[trim_both(strKey)] = trim_both(strValue); - - configOutput.push_back(mapCommonConfig); - } - break; - } - } - break; - - case CONFIG_BUNDLES: - getConfigBundleData(root, id, &configOutput); - break; - - case CONFIG_RESOURCES: - getConfigResourceData(root, id, &configOutput); - break; - - default: - assert(0); - } - } - catch (rapidxml::parse_error &e) - { - cout << "xml parsing failed !!" << endl; - cout << e.what() << endl; - } - - return configOutput; - } - - void ResourceContainerInternal::getConfigDocument(std::string pathConfigFile, - std::string *pConfigData) - { - std::basic_ifstream< char > xmlFile(pathConfigFile.c_str()); - - if (!xmlFile.fail()) - { - xmlFile.seekg(0, std::ios::end); - unsigned int size = (unsigned int)xmlFile.tellg(); - xmlFile.seekg(0); - - std::vector< char > xmlData(size + 1); - xmlData[size] = 0; - - xmlFile.read(&xmlData.front(), (std::streamsize) size); - xmlFile.close(); - *pConfigData = std::string(xmlData.data()); - } - else - { - std::cout << "Configuration File load failed !!" << std::endl; - } - } - - void ResourceContainerInternal::getConfigBundleData(rapidxml::xml_node< char > *rootData, - string bundleId, ConfigParam *pConfigOutput) - { - rapidxml::xml_node< char > *item; - rapidxml::xml_node< char > *subItem; - - string strKey, strValue; - - try - { - for (item = rootData->first_node(); item; item = item->next_sibling()) - { - strKey = item->name(); - strValue = item->value(); - - // - if (!strKey.compare("bundle")) - { - for (subItem = item->first_node(); subItem; subItem = subItem->next_sibling()) - { - strKey = subItem->name(); - strValue = subItem->value(); - - if (!bundleId.empty()) - { - if (!strKey.compare("bundleID") && strValue.compare(bundleId)) - break; - } - - // bundle info except resource data - if (strKey.compare("resources")) - { - map < string, string > mapBundleConfig; - mapBundleConfig[trim_both(strKey)] = trim_both(strValue); - - pConfigOutput->push_back(mapBundleConfig); - } - } - } - } - } - catch (rapidxml::parse_error &e) - { - cout << "xml parsing failed !!" << endl; - cout << e.what() << endl; - } - } - - void ResourceContainerInternal::getConfigResourceData(rapidxml::xml_node< char > *rootData, - string bundleId, ConfigParam *pConfigOutput) - { - rapidxml::xml_node< char > *item; - rapidxml::xml_node< char > *subItem; - rapidxml::xml_node< char > *subItem2; - rapidxml::xml_node< char > *subItem3; - - string strKey, strValue; - - try - { - for (item = rootData->first_node(); item; item = item->next_sibling()) - { - strKey = item->name(); - strValue = item->value(); - - // - if (!strKey.compare("bundle")) - { - for (subItem = item->first_node(); subItem; subItem = subItem->next_sibling()) - { - strKey = subItem->name(); - strValue = subItem->value(); - - if (!strKey.compare("bundleID") && strValue.compare(bundleId)) - break; - - // - if (!strKey.compare("resources")) - { - for (subItem2 = subItem->first_node(); subItem2; subItem2 = subItem2->next_sibling()) - { - strKey = subItem2->name(); - strValue = subItem2->value(); - - // - if (!strKey.compare("resourceInfo")) - { - map mapResourceInfo; - - for (subItem3 = subItem2->first_node(); subItem3; subItem3 = subItem3->next_sibling()) - { - strKey = subItem3->name(); - strValue = subItem3->value(); - - mapResourceInfo[trim_both(strKey)] = trim_both(strValue); - } - - pConfigOutput->push_back(mapResourceInfo); - } - } - } - } - } - } - } - catch (rapidxml::parse_error &e) - { - cout << "xml parsing failed !!" << endl; - cout << e.what() << endl; - } - } - - void ResourceContainerInternal::getCurrentPath(std::string *path) - { - char buffer[2048]; - char *strPath = NULL; - - int length = readlink("/proc/self/exe", buffer, 2047); - - buffer[length] = '\0'; - - strPath = strrchr(buffer, '/'); - - *strPath = '\0'; - - path->append(buffer); - } -} -- 2.7.4