[SSM] Modify repo init method and fix Resource data reader
authorjk13 <jihyeok13.kim@samsung.com>
Mon, 8 Dec 2014 04:58:12 +0000 (13:58 +0900)
committerjk13 <jihyeok13.kim@samsung.com>
Mon, 8 Dec 2014 05:17:03 +0000 (14:17 +0900)
Modify Repository class init method to load local SoftSensors,

Fix OIC data reader to read correct data

Change-Id: I099d732ddf019deb79d2d88477556eacf2eb2078
Signed-off-by: jk13 <jihyeok13.kim@samsung.com>
service/soft-sensor-manager/SSMCore/src/SSMInterface/SSMCore_JNI.cpp
service/soft-sensor-manager/SSMCore/src/SSMInterface/SSMCore_JNI.h
service/soft-sensor-manager/SSMCore/src/SSMInterface/SSMResourceServer.cpp
service/soft-sensor-manager/SSMCore/src/SensorProcessor/ContextRepository.cpp
service/soft-sensor-manager/SSMCore/src/SensorProcessor/ResourceFinder.h

index 23aabed..9dbb031 100644 (file)
@@ -17,6 +17,7 @@
 * limitations under the License.
 *
 ******************************************************************/
+#include "SSMCore.h"
 #include "SSMInterface/SSMCore_JNI.h"
 #include "Common/PlatformLayer.h"
 
index d771aaf..19dd122 100644 (file)
@@ -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)
                     {
index 20793e0..ce571d6 100644 (file)
@@ -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)
index 4ddd214..0c73dc3 100644 (file)
@@ -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<OC::OCResource>     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};