From cbe9bfff9126da0c049ac0eb89f3a54dfeaaef06 Mon Sep 17 00:00:00 2001 From: Minji Park Date: Mon, 15 Jun 2015 15:20:48 +0900 Subject: [PATCH] Update Resource container - server builder integration, softsensor template, - integrate server builder to create bundle resource - add first version of basic resource template and resource template for soft sensor - apply IoTivity c++ format to Resource Container codes Change-Id: I502c9a48256d51da2227ed766851e7d1d72362a0 Signed-off-by: Minji Park Reviewed-on: https://gerrit.iotivity.org/gerrit/1268 Tested-by: jenkins-iotivity Reviewed-by: Uze Choi --- service/basis/SConscript | 2 +- service/basis/resourceContainer/SConscript | 11 +- .../SampleBundle/include/DiscomfortIndexSensor.h | 17 +- .../include/DiscomfortIndexSensorResource.h | 45 ++++++ .../examples/SampleBundle/include/SampleBundle.h | 21 +-- .../SampleBundle/src/DiscomfortIndexSensor.cpp | 178 ++++++++++----------- .../src/DiscomfortIndexSensorResource.cpp | 52 ++++++ .../examples/SampleBundle/src/SampleBundle.cpp | 73 +++++---- .../resourceContainer/include/BundleActivator.h | 10 +- .../resourceContainer/include/BundleInfoInternal.h | 58 +++---- .../resourceContainer/include/BundleResource.h | 20 +-- .../resourceContainer/include/Configuration.h | 49 +++--- .../resourceContainer/include/ResourceContainer.h | 35 ++-- .../include/ResourceContainerBundleAPI.h | 12 +- .../include/ResourceContainerImpl.h | 52 +++--- .../resourceContainer/include/SoftSensorResource.h | 52 ++++++ .../resourceContainer/src/BundleActivator.cpp | 6 +- service/basis/resourceContainer/src/BundleInfo.cpp | 4 +- .../resourceContainer/src/BundleInfoInternal.cpp | 12 +- .../basis/resourceContainer/src/BundleResource.cpp | 45 ++++++ .../basis/resourceContainer/src/Configuration.cpp | 20 +-- .../basis/resourceContainer/src/ContainerTest.cpp | 21 +-- .../resourceContainer/src/ResourceContainer.cpp | 4 +- .../src/ResourceContainerImpl.cpp | 115 ++++++++----- .../resourceContainer/src/SoftSensorResource.cpp | 34 ++++ 25 files changed, 611 insertions(+), 337 deletions(-) create mode 100644 service/basis/resourceContainer/examples/SampleBundle/include/DiscomfortIndexSensorResource.h create mode 100644 service/basis/resourceContainer/examples/SampleBundle/src/DiscomfortIndexSensorResource.cpp create mode 100644 service/basis/resourceContainer/include/SoftSensorResource.h create mode 100644 service/basis/resourceContainer/src/BundleResource.cpp create mode 100644 service/basis/resourceContainer/src/SoftSensorResource.cpp diff --git a/service/basis/SConscript b/service/basis/SConscript index 71185ab..4d7e052 100644 --- a/service/basis/SConscript +++ b/service/basis/SConscript @@ -28,8 +28,8 @@ Import('env') SConscript('common/SConscript') #SConscript('resourceBroker/SConscript') #SConscript('resourceCache/SConscript') -#SConscript('resourceContainer/SConscript') SConscript('serverBuilder/SConscript') +SConscript('resourceContainer/SConscript') #SConscript('sdk/SConscript') diff --git a/service/basis/resourceContainer/SConscript b/service/basis/resourceContainer/SConscript index b3a6357..d544610 100644 --- a/service/basis/resourceContainer/SConscript +++ b/service/basis/resourceContainer/SConscript @@ -37,7 +37,9 @@ resource_container_env.AppendUnique( CPPPATH = [ env.get('SRC_DIR')+'/extlibs', 'include', - 'src' + 'src', + '../serverBuilder/include', + '../common/primitiveResource/include' ]) if target_os not in ['windows', 'winrt']: @@ -48,7 +50,9 @@ if target_os not in ['windows', 'winrt']: if target_os == 'android': resource_container_env.AppendUnique(CXXFLAGS = ['-frtti', '-fexceptions']) resource_container_env.PrependUnique(LIBS = ['gnustl_shared', 'compatibility', 'log']) - + +#resource_container_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')]) +resource_container_env.PrependUnique(LIBS = ['ServerBuilder', 'ServiceCommon', 'oc','octbstack', 'oc_logger', 'oc_logger_core', 'connectivity_abstraction', 'coap']) resource_container_env.AppendUnique(LIBS = ['dl']) ###################################################################### @@ -93,8 +97,7 @@ sample_resource_bundle_env.InstallTarget(SampleBundle, 'libSampleBundle') # Build Container Test ###################################################################### containertest_env = resource_container_env.Clone(); -containertest_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')]) -containertest_env.PrependUnique(LIBS = ['oc', 'oc_logger_core', 'oc_logger']) +#containertest_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')]) # Copy test configuration Command("examples/ResourceContainerConfig.xml","examples/ResourceContainerConfig.xml", Copy("$TARGET", "$SOURCE")) diff --git a/service/basis/resourceContainer/examples/SampleBundle/include/DiscomfortIndexSensor.h b/service/basis/resourceContainer/examples/SampleBundle/include/DiscomfortIndexSensor.h index 70202df..a30c1f4 100644 --- a/service/basis/resourceContainer/examples/SampleBundle/include/DiscomfortIndexSensor.h +++ b/service/basis/resourceContainer/examples/SampleBundle/include/DiscomfortIndexSensor.h @@ -33,11 +33,9 @@ #include #include -struct SensorData -{ - std::string sensorName; - std::vector< std::map > data; -}; +// temp +#include "BundleResource.h" +#include "SoftSensorResource.h" namespace DiscomfortIndexSensorName { @@ -76,10 +74,13 @@ namespace DiscomfortIndexSensorName public: DiscomfortIndexSensor(); - int runLogic(std::vector< SensorData > &sensorData); - DIResult getInput(std::vector< SensorData > &contextDataList, InValue *data); + int runLogic(std::vector< RC::SoftSensorResource::SensorData > &sensorData); + DIResult getInput(std::vector< RC::SoftSensorResource::SensorData > &contextDataList, + InValue *data); DIResult makeDiscomfortIndex(InValue *data); - SensorData setOutput(int property_count, InValue *data); + RC::SoftSensorResource::SensorData setOutput(int property_count, InValue *data); + + RC::SoftSensorResource::SensorData m_output; }; }; diff --git a/service/basis/resourceContainer/examples/SampleBundle/include/DiscomfortIndexSensorResource.h b/service/basis/resourceContainer/examples/SampleBundle/include/DiscomfortIndexSensorResource.h new file mode 100644 index 0000000..3364037 --- /dev/null +++ b/service/basis/resourceContainer/examples/SampleBundle/include/DiscomfortIndexSensorResource.h @@ -0,0 +1,45 @@ +//****************************************************************** +// +// 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 DISCOMFORTINDEXSENSORRESOURCE_H_ +#define DISCOMFORTINDEXSENSORRESOURCE_H_ + +#include "BundleResource.h" +#include "DiscomfortIndexSensor.h" + +using namespace DiscomfortIndexSensorName; +using namespace RC; + +class DiscomfortIndexSensorResource : public SoftSensorResource +{ + public: + DiscomfortIndexSensorResource(); + ~DiscomfortIndexSensorResource(); + + void onGetRequest(std::map *attributes); + void onSetRequest(std::map attributes); + + void onInputDataReceived(std::vector inputs); + + private: + DiscomfortIndexSensor *m_pDiscomfortIndexSensor; +}; + +#endif diff --git a/service/basis/resourceContainer/examples/SampleBundle/include/SampleBundle.h b/service/basis/resourceContainer/examples/SampleBundle/include/SampleBundle.h index 976fd43..f241a7b 100644 --- a/service/basis/resourceContainer/examples/SampleBundle/include/SampleBundle.h +++ b/service/basis/resourceContainer/examples/SampleBundle/include/SampleBundle.h @@ -21,10 +21,12 @@ #ifndef SAMPLEBUNDLE_H_ #define SAMPLEBUNDLE_H_ +#include #include #include "ResourceContainerBundleAPI.h" #include "BundleActivator.h" +#include "BundleResource.h" using namespace RC; @@ -34,22 +36,15 @@ class SampleBundle: public BundleActivator SampleBundle(); ~SampleBundle(); - void activateBundle(ResourceContainerBundleAPI* resourceContainer); + void activateBundle(ResourceContainerBundleAPI *resourceContainer, std::string bundleId); void deactivateBundle(); - void createResource(); - void destroyResource(); + void createResource(Configuration::resourceInfo); + void destroyResource(BundleResource *); - ResourceContainerBundleAPI* m_ResourceContainer; - std::vector m_vecResources; -}; - - -class SampleBundleResource: public Resource -{ - public: - SampleBundleResource(); - ~SampleBundleResource(); + std::string m_bundleId; + ResourceContainerBundleAPI *m_pResourceContainer; + std::vector m_vecResources; }; #endif /* SAMPLEBUNDLE_H_ */ diff --git a/service/basis/resourceContainer/examples/SampleBundle/src/DiscomfortIndexSensor.cpp b/service/basis/resourceContainer/examples/SampleBundle/src/DiscomfortIndexSensor.cpp index 14fd35b..f4b94ab 100644 --- a/service/basis/resourceContainer/examples/SampleBundle/src/DiscomfortIndexSensor.cpp +++ b/service/basis/resourceContainer/examples/SampleBundle/src/DiscomfortIndexSensor.cpp @@ -21,12 +21,6 @@ /** * This file contains the exported symbol. */ -#include -#include -#include -#include -#include - #include "DiscomfortIndexSensor.h" #include "SysTimer.h" @@ -55,7 +49,7 @@ DiscomfortIndexSensor::DiscomfortIndexSensor() m_result.m_discomfortIndex = ""; } -int DiscomfortIndexSensor::runLogic(std::vector< SensorData > &sensorData) +int DiscomfortIndexSensor::runLogic(std::vector< RC::SoftSensorResource::SensorData > &sensorData) { std::cout << "[DiscomfortIndexSensor] DiscomfortIndexSensor::" << __func__ << " is called." << std::endl; @@ -70,7 +64,7 @@ int DiscomfortIndexSensor::runLogic(std::vector< SensorData > &sensorData) return -1; } - //g_pSoftSensorCore->pushResults(setOutput(4, m_DI)); + m_output = setOutput(4, m_DI); return 0; } @@ -81,66 +75,67 @@ int DiscomfortIndexSensor::runLogic(std::vector< SensorData > &sensorData) /** * Get Input data (temperature, humidity) using resource Client of Iotivity base. */ -DIResult DiscomfortIndexSensor::getInput(std::vector< SensorData > &sensorData, InValue *data) +DIResult DiscomfortIndexSensor::getInput(std::vector< RC::SoftSensorResource::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; + 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; } /** @@ -213,41 +208,42 @@ DIResult DiscomfortIndexSensor::makeDiscomfortIndex(InValue *data) return SUCCESS; } -SensorData DiscomfortIndexSensor::setOutput(int property_count, InValue *data) +RC::SoftSensorResource::SensorData DiscomfortIndexSensor::setOutput(int property_count, + InValue *data) { - //SensorData out; + RC::SoftSensorResource::SensorData out; - //std::map < std::string, std::string > output_property; + std::map < std::string, std::string > output_property; - //out.sensorName = SENSOR_NAME; + 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)); + 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); + 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)); + 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); + 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)); + 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); + 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)); + 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); + out.data.push_back(output_property); - //return out; + return out; } diff --git a/service/basis/resourceContainer/examples/SampleBundle/src/DiscomfortIndexSensorResource.cpp b/service/basis/resourceContainer/examples/SampleBundle/src/DiscomfortIndexSensorResource.cpp new file mode 100644 index 0000000..4603f24 --- /dev/null +++ b/service/basis/resourceContainer/examples/SampleBundle/src/DiscomfortIndexSensorResource.cpp @@ -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. +// +//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + +#include "DiscomfortIndexSensorResource.h" + +DiscomfortIndexSensorResource::DiscomfortIndexSensorResource() +{ + m_pDiscomfortIndexSensor = new DiscomfortIndexSensor(); + + m_mapAttributes.insert(std::pair("temperature", "23")); + m_mapAttributes.insert(std::pair("humidity", "40")); + m_mapAttributes.insert(std::pair("discomfortIndex", "5")); + +} + +DiscomfortIndexSensorResource::~DiscomfortIndexSensorResource() +{ + delete m_pDiscomfortIndexSensor; +} + +void DiscomfortIndexSensorResource::onGetRequest(std::map *attributes) +{ + // TODO : make m_outputs into m_mapAttributes format + *attributes = m_mapAttributes; +} + +void DiscomfortIndexSensorResource::onSetRequest(std::map attributes) +{ +} + +void DiscomfortIndexSensorResource::onInputDataReceived(std::vector inputs) +{ + m_vecInputs = inputs; + m_pDiscomfortIndexSensor->runLogic(m_vecInputs); +} diff --git a/service/basis/resourceContainer/examples/SampleBundle/src/SampleBundle.cpp b/service/basis/resourceContainer/examples/SampleBundle/src/SampleBundle.cpp index bec7077..095a39e 100644 --- a/service/basis/resourceContainer/examples/SampleBundle/src/SampleBundle.cpp +++ b/service/basis/resourceContainer/examples/SampleBundle/src/SampleBundle.cpp @@ -19,9 +19,7 @@ //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= #include "SampleBundle.h" -#include "ResourceContainerBundleAPI.h" -#include "Configuration.h" - +#include "DiscomfortIndexSensorResource.h" using namespace RC; @@ -35,52 +33,71 @@ SampleBundle::~SampleBundle() { } -void SampleBundle::activateBundle(ResourceContainerBundleAPI* resourceContainer) +void SampleBundle::activateBundle(ResourceContainerBundleAPI *resourceContainer, + std::string bundleId) { std::cout << "SampleBundle::activateBundle called" << std::endl; - m_ResourceContainer = resourceContainer; + m_pResourceContainer = resourceContainer; + m_bundleId = bundleId; - // parse configuration, instantiate resource and register resources - Configuration::configInfo config; - // m_ResourceContainer->getConfiguration(ConfigKey::CONFIG_RESOURCES, "oic.bundle.sample", &config); + vector resourceConfig; - 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; - // } + resourceContainer->getResourceConfiguration(m_bundleId, &resourceConfig); - // createResource(); + for (vector::iterator itor = resourceConfig.begin(); + itor != resourceConfig.end(); itor++) + { + createResource(*itor); + } } void SampleBundle::deactivateBundle() { std::cout << "SampleBundle::deactivateBundle called" << std::endl; - // unregister resources + + for (std::vector::iterator itor = m_vecResources.begin(); + itor != m_vecResources.end(); itor++) + { + destroyResource(*itor); + } } -void SampleBundle::createResource() +// TODO : has to be updated for setting the info +void SampleBundle::createResource(Configuration::resourceInfo resourceInfo) { - //std::cout << "SampleBundle::createResource called" << std::endl; - //SampleBundleResource *newResource = new SampleBundleResource(); - //m_vecResources.push_back(newResource); - //std::cout << "resourceContainer.registerResource()" << std::endl; + std::cout << "SampleBundle::createResource called" << std::endl; + + DiscomfortIndexSensorResource *newResource = new DiscomfortIndexSensorResource(); + newResource->setResourceInfo(resourceInfo); + + m_pResourceContainer->registerResource(newResource); + + m_vecResources.push_back(newResource); } -void SampleBundle::destroyResource() +void SampleBundle::destroyResource(BundleResource *resource) { - //std::cout << "SampleBundle::destroyResource called" << std::endl; - //std::cout << "resourceContainer.unregisterResource()" << std::endl; + std::cout << "SampleBundle::destroyResource called" << std::endl; + + std::vector ::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) +extern "C" void externalActivateBundle(ResourceContainerBundleAPI *resourceContainer, + std::string bundleId) { bundle = new SampleBundle(); - bundle->activateBundle(resourceContainer); + bundle->activateBundle(resourceContainer, bundleId); } extern "C" void externalDeactivateBundle() diff --git a/service/basis/resourceContainer/include/BundleActivator.h b/service/basis/resourceContainer/include/BundleActivator.h index 62d20ab..9ba5ff5 100644 --- a/service/basis/resourceContainer/include/BundleActivator.h +++ b/service/basis/resourceContainer/include/BundleActivator.h @@ -30,11 +30,11 @@ namespace RC class BundleActivator { - public: - BundleActivator(); - virtual ~BundleActivator(); - virtual void activateBundle(ResourceContainerBundleAPI* resourceContainer); - virtual void deactivateBundle(); + public: + BundleActivator(); + virtual ~BundleActivator(); + virtual void activateBundle(ResourceContainerBundleAPI *resourceContainer, std::string bundleId); + virtual void deactivateBundle(); }; } diff --git a/service/basis/resourceContainer/include/BundleInfoInternal.h b/service/basis/resourceContainer/include/BundleInfoInternal.h index 820322f..be811da 100644 --- a/service/basis/resourceContainer/include/BundleInfoInternal.h +++ b/service/basis/resourceContainer/include/BundleInfoInternal.h @@ -30,44 +30,44 @@ using namespace RC; namespace RC { - typedef void activator_t(ResourceContainerBundleAPI *); + typedef void activator_t(ResourceContainerBundleAPI *, std::string bundleId); 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(); + 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 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 setBundleActivator(activator_t *); + activator_t *getBundleActivator(); - void setBundleDeactivator(deactivator_t*); - deactivator_t* getBundleDeactivator(); + void setBundleDeactivator(deactivator_t *); + deactivator_t *getBundleDeactivator(); - void setBundleHandle(void*); - void* getBundleHandle(); + 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; + private: + bool m_loaded, m_activated; + int m_id; + activator_t *m_activator; + deactivator_t *m_deactivator; + void *m_bundleHandle; }; } diff --git a/service/basis/resourceContainer/include/BundleResource.h b/service/basis/resourceContainer/include/BundleResource.h index c2c87b8..6f9b696 100644 --- a/service/basis/resourceContainer/include/BundleResource.h +++ b/service/basis/resourceContainer/include/BundleResource.h @@ -21,6 +21,7 @@ #ifndef BUNDLERESOURCE_H_ #define BUNDLERESOURCE_H_ +#include "Configuration.h" #include #include @@ -32,22 +33,17 @@ namespace RC BundleResource(); virtual ~BundleResource(); - virtual void onGetRequest() = 0; - virtual void onSetRequest() = 0; + virtual void onGetRequest(std::map *attributes) = 0; + virtual void onSetRequest(std::map attributes) = 0; - std::map m_mapAttributes; - }; + Configuration::resourceInfo getResourceInfo(); + void setResourceInfo(Configuration::resourceInfo resourceInfo); - class SoftSensorResource : public BundleResource - { public: - SoftSensorResource(); - virtual ~SoftSensorResource(); - - virtual void runLogic() = 0; - - std::map m_mapInputs; + std::map m_mapAttributes; + Configuration::resourceInfo m_resourceInfo; }; + } #endif diff --git a/service/basis/resourceContainer/include/Configuration.h b/service/basis/resourceContainer/include/Configuration.h index f72d7af..b48e795 100644 --- a/service/basis/resourceContainer/include/Configuration.h +++ b/service/basis/resourceContainer/include/Configuration.h @@ -25,6 +25,9 @@ #include #include +#include "rapidxml/rapidxml.hpp" +#include "rapidxml/rapidxml_print.hpp" + #include "ResourceContainer.h" #include "BundleInfo.h" @@ -34,34 +37,34 @@ 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; - }; + 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(); + ~Configuration(); - Configuration(string configFile); + 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); + 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); + private: + void getConfigDocument(std::string pathConfigFile, std::string *pConfigData); + void getCurrentPath(std::string *path); - string m_pathConfigFile, m_configFile; -}; + string m_pathConfigFile, m_configFile; + }; } #endif diff --git a/service/basis/resourceContainer/include/ResourceContainer.h b/service/basis/resourceContainer/include/ResourceContainer.h index 895711b..53cf80f 100644 --- a/service/basis/resourceContainer/include/ResourceContainer.h +++ b/service/basis/resourceContainer/include/ResourceContainer.h @@ -28,9 +28,6 @@ #include "BundleInfo.h" -#include "rapidxml/rapidxml.hpp" -#include "rapidxml/rapidxml_print.hpp" - using namespace std; namespace RC @@ -44,23 +41,23 @@ namespace RC class ResourceContainer { - public: - ResourceContainer(); - virtual ~ResourceContainer(); - virtual void init() = 0; - virtual void init(string configFile) = 0; - virtual void registerBundle(BundleInfo* bundleinfo) = 0; - virtual void unregisterBundle(BundleInfo* bundleinfo) = 0; - virtual void unregisterBundle(int id) = 0; - virtual void activateBundle(int id) = 0; - virtual void deactivateBundle(int id) = 0; - virtual void activateBundleByName(string name) = 0; - virtual void deactivateBundleByName(string id) = 0; - virtual void activateBundle(BundleInfo* bundleInfo) = 0; - virtual void deactivateBundle(BundleInfo* bundleInfo) = 0; - virtual vector< Resource * > listBundleResources(string id) = 0; + 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(); + static ResourceContainer *getInstance(); }; } diff --git a/service/basis/resourceContainer/include/ResourceContainerBundleAPI.h b/service/basis/resourceContainer/include/ResourceContainerBundleAPI.h index 1ceb3f8..f4929a7 100644 --- a/service/basis/resourceContainer/include/ResourceContainerBundleAPI.h +++ b/service/basis/resourceContainer/include/ResourceContainerBundleAPI.h @@ -28,6 +28,7 @@ #include "ResourceContainer.h" #include "BundleInfo.h" #include "Configuration.h" +#include "BundleResource.h" using namespace RC; @@ -39,11 +40,12 @@ namespace RC 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); + virtual void registerResource(BundleResource *resource) = 0; + virtual void unregisterResource(BundleResource *resource) = 0; + virtual void getCommonConfiguration(configInfo *configOutput) = 0; + virtual void getBundleConfiguration(std::string bundleId, configInfo *configOutput) = 0; + virtual void getResourceConfiguration(std::string bundleId, + std::vector *configOutput) = 0; static ResourceContainerBundleAPI *getInstance(); }; diff --git a/service/basis/resourceContainer/include/ResourceContainerImpl.h b/service/basis/resourceContainer/include/ResourceContainerImpl.h index 173b807..2976653 100644 --- a/service/basis/resourceContainer/include/ResourceContainerImpl.h +++ b/service/basis/resourceContainer/include/ResourceContainerImpl.h @@ -32,34 +32,38 @@ namespace RC class ResourceContainerImpl: public ResourceContainer, public ResourceContainerBundleAPI { - public: - ResourceContainerImpl(); - virtual ~ResourceContainerImpl(); + 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 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); + // methods from ResourceContainerBundleAPI + void registerBundle(BundleInfo *bundleinfo); + void unregisterBundle(BundleInfo *bundleinfo); + void unregisterBundle(int id); + void registerResource(BundleResource *resource); + void unregisterResource(BundleResource *resource); - static ResourceContainerImpl* getImplInstance(); + void getCommonConfiguration(configInfo *configOutput); + void getBundleConfiguration(std::string bundleId, configInfo *configOutput); + void getResourceConfiguration(std::string bundleId, std::vector *configOutput); - private: - vector m_bundles; - string m_configFile; - Configuration m_config; + static ResourceContainerImpl *getImplInstance(); + + private: + vector m_bundles; + string m_configFile; + Configuration *m_config; }; } diff --git a/service/basis/resourceContainer/include/SoftSensorResource.h b/service/basis/resourceContainer/include/SoftSensorResource.h new file mode 100644 index 0000000..af7045c --- /dev/null +++ b/service/basis/resourceContainer/include/SoftSensorResource.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 SOFTSENSORRESOURCE_H_ +#define SOFTSENSORRESOURCE_H_ + +#include "BundleResource.h" +#include +#include + +namespace RC +{ + + class SoftSensorResource : public BundleResource + { + public: + // TODO : definition of SensorData definition should be changed + struct SensorData + { + std::string sensorName; + std::vector< std::map > data; + }; + + SoftSensorResource(); + virtual ~SoftSensorResource(); + + virtual void onInputDataReceived(std::vector inputs) = 0; + + int inputCount; + std::vector < SensorData > m_vecInputs; + SensorData m_outputs; + }; +} + +#endif diff --git a/service/basis/resourceContainer/src/BundleActivator.cpp b/service/basis/resourceContainer/src/BundleActivator.cpp index 3b6295f..de139b9 100644 --- a/service/basis/resourceContainer/src/BundleActivator.cpp +++ b/service/basis/resourceContainer/src/BundleActivator.cpp @@ -23,7 +23,8 @@ using namespace RC; -namespace RC{ +namespace RC +{ BundleActivator::BundleActivator() { @@ -34,7 +35,8 @@ namespace RC{ } - void BundleActivator::activateBundle(ResourceContainerBundleAPI* resourceContainer) + void BundleActivator::activateBundle(ResourceContainerBundleAPI *resourceContainer, + std::string bundleId) { } diff --git a/service/basis/resourceContainer/src/BundleInfo.cpp b/service/basis/resourceContainer/src/BundleInfo.cpp index 1d04f83..0b37b30 100644 --- a/service/basis/resourceContainer/src/BundleInfo.cpp +++ b/service/basis/resourceContainer/src/BundleInfo.cpp @@ -33,9 +33,9 @@ namespace RC } - BundleInfo* BundleInfo::createBundleInfo() + BundleInfo *BundleInfo::createBundleInfo() { - BundleInfoInternal* newBundleInfo = new BundleInfoInternal(); + BundleInfoInternal *newBundleInfo = new BundleInfoInternal(); return newBundleInfo; } } diff --git a/service/basis/resourceContainer/src/BundleInfoInternal.cpp b/service/basis/resourceContainer/src/BundleInfoInternal.cpp index eae79a5..47d0c21 100644 --- a/service/basis/resourceContainer/src/BundleInfoInternal.cpp +++ b/service/basis/resourceContainer/src/BundleInfoInternal.cpp @@ -91,32 +91,32 @@ namespace RC m_id = id; } - void BundleInfoInternal::setBundleActivator(activator_t* activator) + void BundleInfoInternal::setBundleActivator(activator_t *activator) { m_activator = activator; } - activator_t* BundleInfoInternal::getBundleActivator() + activator_t *BundleInfoInternal::getBundleActivator() { return m_activator; } - void BundleInfoInternal::setBundleDeactivator(deactivator_t* deactivator) + void BundleInfoInternal::setBundleDeactivator(deactivator_t *deactivator) { m_deactivator = deactivator; } - deactivator_t* BundleInfoInternal::getBundleDeactivator() + deactivator_t *BundleInfoInternal::getBundleDeactivator() { return m_deactivator; } - void BundleInfoInternal::setBundleHandle(void* handle) + void BundleInfoInternal::setBundleHandle(void *handle) { m_bundleHandle = handle; } - void* BundleInfoInternal::getBundleHandle() + void *BundleInfoInternal::getBundleHandle() { return m_bundleHandle; } diff --git a/service/basis/resourceContainer/src/BundleResource.cpp b/service/basis/resourceContainer/src/BundleResource.cpp new file mode 100644 index 0000000..a6fd94f --- /dev/null +++ b/service/basis/resourceContainer/src/BundleResource.cpp @@ -0,0 +1,45 @@ +//****************************************************************** +// +// 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 "BundleResource.h" +#include "Configuration.h" + + + +BundleResource::BundleResource() +{ + +} + +BundleResource::~BundleResource() +{ + +} + +Configuration::resourceInfo BundleResource::getResourceInfo() +{ + return m_resourceInfo; +} + +void BundleResource::setResourceInfo(Configuration::resourceInfo resourceInfo) +{ + m_resourceInfo = resourceInfo; +} + diff --git a/service/basis/resourceContainer/src/Configuration.cpp b/service/basis/resourceContainer/src/Configuration.cpp index 736a918..06e835a 100644 --- a/service/basis/resourceContainer/src/Configuration.cpp +++ b/service/basis/resourceContainer/src/Configuration.cpp @@ -48,7 +48,8 @@ Configuration::Configuration() Configuration::~Configuration() {} -Configuration::Configuration(string configFile){ +Configuration::Configuration(string configFile) +{ m_configFile = configFile; getCurrentPath(&m_pathConfigFile); m_pathConfigFile.append("/"); @@ -109,12 +110,12 @@ void Configuration::getCommonConfiguration(configInfo *configOutput) } } -void Configuration::getConfiguredBundles(configInfo* configOutput){ +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; @@ -137,13 +138,14 @@ void Configuration::getConfiguredBundles(configInfo* configOutput){ //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; + 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); } diff --git a/service/basis/resourceContainer/src/ContainerTest.cpp b/service/basis/resourceContainer/src/ContainerTest.cpp index 1defa11..5b4d1fa 100644 --- a/service/basis/resourceContainer/src/ContainerTest.cpp +++ b/service/basis/resourceContainer/src/ContainerTest.cpp @@ -26,7 +26,7 @@ using namespace RC; using OC::oc_log_stream; /* Annother way to create a context: */ -auto info_logger = []() -> boost::iostreams::stream& +auto info_logger = []() -> boost::iostreams::stream & { static OC::oc_log_stream ols(oc_make_ostream_logger); static boost::iostreams::stream os(ols); @@ -41,20 +41,11 @@ int main() 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(); + 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"; + while (1) + { + ; + } } diff --git a/service/basis/resourceContainer/src/ResourceContainer.cpp b/service/basis/resourceContainer/src/ResourceContainer.cpp index c77a0b1..c0c33cd 100644 --- a/service/basis/resourceContainer/src/ResourceContainer.cpp +++ b/service/basis/resourceContainer/src/ResourceContainer.cpp @@ -34,9 +34,9 @@ namespace RC } - ResourceContainer* ResourceContainer::getInstance() + ResourceContainer *ResourceContainer::getInstance() { - return (ResourceContainer*) ResourceContainerImpl::getImplInstance(); + return (ResourceContainer *)ResourceContainerImpl::getImplInstance(); } } diff --git a/service/basis/resourceContainer/src/ResourceContainerImpl.cpp b/service/basis/resourceContainer/src/ResourceContainerImpl.cpp index ed1babd..8b0cf63 100644 --- a/service/basis/resourceContainer/src/ResourceContainerImpl.cpp +++ b/service/basis/resourceContainer/src/ResourceContainerImpl.cpp @@ -23,6 +23,10 @@ #include "ResourceContainer.h" #include "BundleInfoInternal.h" #include "logger.h" +#include "PrimitiveRequest.h" +#include "PrimitiveResponse.h" +#include "PrimitiveServerResource.h" + #include #include @@ -34,7 +38,8 @@ using OC::oc_log_stream; -auto info_logger = []() -> boost::iostreams::stream& +/* 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); @@ -43,7 +48,8 @@ auto info_logger = []() -> boost::iostreams::stream& return os; }; -auto error_logger = []() -> boost::iostreams::stream& +/* Annother way to create a context: */ +auto error_logger = []() -> boost::iostreams::stream & { static OC::oc_log_stream ols(oc_make_ostream_logger); static boost::iostreams::stream os(ols); @@ -76,11 +82,12 @@ namespace RC void ResourceContainerImpl::init(string configFile) { - Configuration config(configFile); + m_config = new Configuration(configFile); Configuration::configInfo bundles; - config.getConfiguredBundles(&bundles); - for(int i = 0; i < bundles.size(); i++){ - BundleInfo* bundleInfo = BundleInfo::createBundleInfo(); + 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"]); @@ -91,17 +98,17 @@ namespace RC } // loads the bundle - void ResourceContainerImpl::registerBundle(BundleInfo* bundleInfo) + 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); - const 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; @@ -110,18 +117,18 @@ namespace RC if (bundleHandle != NULL) { - bundleActivator = (activator_t*) dlsym(bundleHandle, "externalActivateBundle"); - bundleDeactivator = (deactivator_t*) dlsym(bundleHandle, "externalDeactivateBundle"); + 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); + ((BundleInfoInternal *) bundleInfo)->setBundleActivator(bundleActivator); + ((BundleInfoInternal *) bundleInfo)->setBundleDeactivator(bundleDeactivator); + ((BundleInfoInternal *) bundleInfo)->setLoaded(true); + ((BundleInfoInternal *) bundleInfo)->setBundleHandle(bundleHandle); } } else @@ -135,13 +142,13 @@ namespace RC void ResourceContainerImpl::activateBundle(int id) { - activator_t* bundleActivator = m_bundles[id]->getBundleActivator(); + activator_t *bundleActivator = m_bundles[id]->getBundleActivator(); info_logger() << "Activating bundle: " << m_bundles[id]->getID() << ", " - << m_bundles[id]->getId() << endl; + << m_bundles[id]->getId() << endl; if (bundleActivator != NULL) { - bundleActivator(this); + bundleActivator(this, m_bundles[id]->getID()); m_bundles[id]->setActivated(true); } else @@ -151,17 +158,17 @@ namespace RC } } - void ResourceContainerImpl::activateBundle(BundleInfo* bundleInfo) + void ResourceContainerImpl::activateBundle(BundleInfo *bundleInfo) { - if (((BundleInfoInternal*) bundleInfo)->isLoaded()) + if (((BundleInfoInternal *) bundleInfo)->isLoaded()) { activateBundle(bundleInfo->getId()); } } - void ResourceContainerImpl::deactivateBundle(BundleInfo* bundleInfo) + void ResourceContainerImpl::deactivateBundle(BundleInfo *bundleInfo) { - if (((BundleInfoInternal*) bundleInfo)->isActivated()) + if (((BundleInfoInternal *) bundleInfo)->isActivated()) { deactivateBundle(bundleInfo->getId()); } @@ -169,9 +176,9 @@ namespace RC void ResourceContainerImpl::deactivateBundle(int id) { - deactivator_t* bundleDeactivator = m_bundles[id]->getBundleDeactivator(); + deactivator_t *bundleDeactivator = m_bundles[id]->getBundleDeactivator(); info_logger() << "De-activating bundle: " << m_bundles[id]->getID() << ", " - << m_bundles[id]->getId() << endl; + << m_bundles[id]->getId() << endl; if (bundleDeactivator != NULL) { @@ -195,34 +202,48 @@ namespace RC } - vector< Resource* > ResourceContainerImpl::listBundleResources(string id) + vector< Resource * > ResourceContainerImpl::listBundleResources(string id) { - vector< Resource* > ret; + vector< Resource * > ret; return ret; } - void ResourceContainerImpl::registerResource(Resource* resource) + 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(); + + for (auto i : resource->m_mapAttributes) + { + cout << "Setting attribute " << i.first.c_str() << endl; + server->setAttribute(i.first.c_str(), i.second.c_str()); + } } - void ResourceContainerImpl::unregisterResource(Resource* resource) + void ResourceContainerImpl::unregisterResource(BundleResource *resource) { } - void ResourceContainerImpl::unregisterBundle(BundleInfo* bundleInfo){ - if (((BundleInfoInternal*) bundleInfo)->isLoaded() && !((BundleInfoInternal*) bundleInfo)->isActivated()) + 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(); + 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; + << m_bundles[id]->getId() << endl; + char *error; dlclose(bundleHandle); if ((error = dlerror()) != NULL) { @@ -230,9 +251,25 @@ namespace RC } } - ResourceContainerImpl* ResourceContainerImpl::getImplInstance() + ResourceContainerImpl *ResourceContainerImpl::getImplInstance() { - ResourceContainerImpl* ret = new ResourceContainerImpl(); + ResourceContainerImpl *ret = new ResourceContainerImpl(); return ret; } + + void ResourceContainerImpl::getCommonConfiguration(configInfo *configOutput) + { + m_config->getCommonConfiguration((Configuration::configInfo *) configOutput); + } + + void ResourceContainerImpl::getBundleConfiguration(std::string bundleId, configInfo *configOutput) + { + m_config->getBundleConfiguration(bundleId, (Configuration::configInfo *) configOutput); + } + + void ResourceContainerImpl::getResourceConfiguration(std::string bundleId, + std::vector *configOutput) + { + m_config->getResourceConfiguration(bundleId, configOutput); + } } diff --git a/service/basis/resourceContainer/src/SoftSensorResource.cpp b/service/basis/resourceContainer/src/SoftSensorResource.cpp new file mode 100644 index 0000000..dc5608a --- /dev/null +++ b/service/basis/resourceContainer/src/SoftSensorResource.cpp @@ -0,0 +1,34 @@ +//****************************************************************** +// +// 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 "SoftSensorResource.h" + +using namespace RC; +SoftSensorResource::SoftSensorResource() +{ + +} + +SoftSensorResource::~SoftSensorResource() +{ + +} + + -- 2.7.4