From 7775956c8db90d697796ed865d0df014beb66b84 Mon Sep 17 00:00:00 2001 From: jk13 Date: Mon, 8 Dec 2014 13:58:12 +0900 Subject: [PATCH] [SSM] Modify repo init method and fix Resource data reader Modify Repository class init method to load local SoftSensors, Fix OIC data reader to read correct data Change-Id: I099d732ddf019deb79d2d88477556eacf2eb2078 Signed-off-by: jk13 --- .../SSMCore/src/SSMInterface/SSMCore_JNI.cpp | 1 + .../SSMCore/src/SSMInterface/SSMCore_JNI.h | 1 - .../SSMCore/src/SSMInterface/SSMResourceServer.cpp | 8 ++-- .../src/SensorProcessor/ContextRepository.cpp | 56 +++++++++++----------- .../SSMCore/src/SensorProcessor/ResourceFinder.h | 19 +++++--- 5 files changed, 45 insertions(+), 40 deletions(-) diff --git a/service/soft-sensor-manager/SSMCore/src/SSMInterface/SSMCore_JNI.cpp b/service/soft-sensor-manager/SSMCore/src/SSMInterface/SSMCore_JNI.cpp index 23aabed..9dbb031 100644 --- a/service/soft-sensor-manager/SSMCore/src/SSMInterface/SSMCore_JNI.cpp +++ b/service/soft-sensor-manager/SSMCore/src/SSMInterface/SSMCore_JNI.cpp @@ -17,6 +17,7 @@ * limitations under the License. * ******************************************************************/ +#include "SSMCore.h" #include "SSMInterface/SSMCore_JNI.h" #include "Common/PlatformLayer.h" diff --git a/service/soft-sensor-manager/SSMCore/src/SSMInterface/SSMCore_JNI.h b/service/soft-sensor-manager/SSMCore/src/SSMInterface/SSMCore_JNI.h index 48ffdb7..4f50e2b 100644 --- a/service/soft-sensor-manager/SSMCore/src/SSMInterface/SSMCore_JNI.h +++ b/service/soft-sensor-manager/SSMCore/src/SSMInterface/SSMCore_JNI.h @@ -21,7 +21,6 @@ #define _SSMCore_JNI_H_ #include -#include "SSMCore.h" #ifdef __cplusplus extern "C" { diff --git a/service/soft-sensor-manager/SSMCore/src/SSMInterface/SSMResourceServer.cpp b/service/soft-sensor-manager/SSMCore/src/SSMInterface/SSMResourceServer.cpp index d771aaf..19dd122 100644 --- a/service/soft-sensor-manager/SSMCore/src/SSMInterface/SSMResourceServer.cpp +++ b/service/soft-sensor-manager/SSMCore/src/SSMInterface/SSMResourceServer.cpp @@ -270,7 +270,7 @@ OCEntityHandlerResult SSMResourceServer::entityHandler(std::shared_ptr< OCResour } else if (requestAttributeMap["command"] == "ReleaseQueryEngine") { - pQueryEngine = (IQueryEngine *) stoi( + pQueryEngine = (IQueryEngine *) std::stoi( requestAttributeMap["queryEngineId"]); ReleaseQueryEngine(pQueryEngine); @@ -279,7 +279,7 @@ OCEntityHandlerResult SSMResourceServer::entityHandler(std::shared_ptr< OCResour { int CQID = 0; - pQueryEngine = (IQueryEngine *) stoi( + pQueryEngine = (IQueryEngine *) std::stoi( requestAttributeMap["queryEngineId"]); res = pQueryEngine->executeContextQuery( @@ -297,10 +297,10 @@ OCEntityHandlerResult SSMResourceServer::entityHandler(std::shared_ptr< OCResour } else if (requestAttributeMap["command"] == "KillContextQuery") { - pQueryEngine = (IQueryEngine *) stoi( + pQueryEngine = (IQueryEngine *) std::stoi( requestAttributeMap["queryEngineId"]); - res = pQueryEngine->killContextQuery(stoi(requestAttributeMap["CQID"])); + res = pQueryEngine->killContextQuery(std::stoi(requestAttributeMap["CQID"])); if (res != SSM_S_OK) { diff --git a/service/soft-sensor-manager/SSMCore/src/SensorProcessor/ContextRepository.cpp b/service/soft-sensor-manager/SSMCore/src/SensorProcessor/ContextRepository.cpp index 20793e0..ce571d6 100644 --- a/service/soft-sensor-manager/SSMCore/src/SensorProcessor/ContextRepository.cpp +++ b/service/soft-sensor-manager/SSMCore/src/SensorProcessor/ContextRepository.cpp @@ -74,8 +74,28 @@ SSMRESULT CContextRepository::initRepository(IN std::string name, IN std::string m_name = name; m_type = type; - m_pathSoftSensors = pathSoftSensors; - m_pathSoftSensorsDescription = pathDescription; + + if (pathSoftSensors.length() == 0) + { + SSM_CLEANUP_ASSERT(GetCurrentPath(&m_pathSoftSensors)); + m_pathSoftSensors.append("/"); + } + else + { + m_pathSoftSensors = pathSoftSensors; + } + + if (pathDescription.length() == 0) + { + SSM_CLEANUP_ASSERT(GetCurrentPath(&m_pathSoftSensorsDescription)); + m_pathSoftSensorsDescription.append("/"); + m_pathSoftSensorsDescription.append(DEFAULT_PATH_SOFT_SENSORS); + } + else + { + m_pathSoftSensorsDescription = pathDescription; + } + SSM_CLEANUP_ASSERT(loadXMLFromFile(m_pathSoftSensorsDescription.c_str(), &dict)); SSM_CLEANUP_ASSERT(makeSSMResourceListForDictionaryData(dict, &m_lstSoftSensor)); @@ -179,22 +199,6 @@ SSMRESULT CContextRepository::loadXMLFromFile(std::string descriptionFilePath, SSMRESULT res = SSM_E_FAIL; std::basic_ifstream< char > xmlFile(descriptionFilePath.c_str()); - if (descriptionFilePath.length() > 0 && xmlFile.fail()) - { - //error while opening given path, return error - SSM_CLEANUP_ASSERT(SSM_E_FAIL); - } - - if (descriptionFilePath.length() == 0) - { - //No given path, try to open local Path - std::string path; - SSM_CLEANUP_ASSERT(GetCurrentPath(&path)); - path.append("/"); - path.append(DEFAULT_PATH_SOFT_SENSORS); - xmlFile.open(path); - } - //path loaded if (!xmlFile.fail()) { @@ -317,13 +321,6 @@ SSMRESULT CContextRepository::loadSoftSensor(std::string softSensorName, ICtxDel typedef void(*InitContext)(IN ICtxDelegate *); InitContext InitializeContextFunction = NULL; - if (m_pathSoftSensors.length() == 0) - { - SSM_CLEANUP_ASSERT(GetCurrentPath(&m_pathSoftSensors)); - } - - m_pathSoftSensors.append("/"); - // load dll(so) res = SSM_E_FAIL; for (unsigned int i = 1; i <= SSM_MODEL_RETRY; ++i) @@ -340,8 +337,7 @@ SSMRESULT CContextRepository::loadSoftSensor(std::string softSensorName, ICtxDel { InitializeContextFunction = (InitContext)GetProcAddress(hModule, "InitializeContext"); } -#else - //sstream << "/data/data/com.example.javaproject/lib/lib" << modelName <<".so" << std::ends; +#elif defined(LINUX) sstream << m_pathSoftSensors << "lib" << softSensorName.c_str() << ".so" << std::ends; void *hModule = NULL; @@ -354,8 +350,10 @@ SSMRESULT CContextRepository::loadSoftSensor(std::string softSensorName, ICtxDel #endif if (hModule == NULL) { - InitializeContextFunction = NULL; - continue; + //load library failed. raise error + SSM_CLEANUP_ASSERT(SSM_E_FAIL); + //InitializeContextFunction = NULL; + //continue; } if (InitializeContextFunction != NULL) diff --git a/service/soft-sensor-manager/SSMCore/src/SensorProcessor/ResourceFinder.h b/service/soft-sensor-manager/SSMCore/src/SensorProcessor/ResourceFinder.h index 4ddd214..0c73dc3 100644 --- a/service/soft-sensor-manager/SSMCore/src/SensorProcessor/ResourceFinder.h +++ b/service/soft-sensor-manager/SSMCore/src/SensorProcessor/ResourceFinder.h @@ -124,9 +124,9 @@ CLEANUP: { for (size_t i = 0; i < attributeMap.size() / 3; i++) { - outputProperty["name"] = attributeMap.find(std::to_string(i * 3))->second; - outputProperty["type"] = attributeMap.find(std::to_string(i * 3 + 1))->second; - outputProperty["value"] = attributeMap.find(std::to_string(i * 3 + 2))->second; + outputProperty["name"] = attributeMap.find(toString(i * 3))->second; + outputProperty["type"] = attributeMap.find(toString(i * 3 + 1))->second; + outputProperty["value"] = attributeMap.find(toString(i * 3 + 2))->second; ctxData.outputProperty.push_back(outputProperty); } @@ -166,9 +166,9 @@ CLEANUP: //TODO: Temporally used for json parsing limitation for (size_t i = 0; i < attributeMap.size() / 3; i++) { - outputProperty["name"] = attributeMap.find(std::to_string(i * 3))->second.front(); - outputProperty["type"] = attributeMap.find(std::to_string(i * 3 + 1))->second.front(); - outputProperty["value"] = attributeMap.find(std::to_string(i * 3 + 2))->second.front(); + outputProperty["name"] = attributeMap.find(toString(i * 3))->second; + outputProperty["type"] = attributeMap.find(toString(i * 3 + 1))->second; + outputProperty["value"] = attributeMap.find(toString(i * 3 + 2))->second; pSSMResource->outputProperty.push_back(outputProperty); } ///////////////////////////////////////////////////// @@ -185,6 +185,13 @@ CLEANUP: std::shared_ptr m_pResource; IThreadClient *m_pResourceFinderClient; IEvent *m_pEvent; + + std::string toString(int t) + { + std::ostringstream os; + os << t; + return os.str(); + } }; enum RESOURCE_DISCOVER_STATE {RESOURCE_DISCOVER_REQUESTPROFILE, RESOURCE_DISCOVER_SETUP_RESOURCE}; -- 2.7.4