Merge "[SSM] Implement Inproc feature for Linux platform"
authorUze Choi <uzchoi@samsung.com>
Tue, 9 Dec 2014 09:02:35 +0000 (01:02 -0800)
committerGerrit Code Review <gerrit@oicreview.vlan14.01.org>
Tue, 9 Dec 2014 09:02:35 +0000 (01:02 -0800)
service/soft-sensor-manager/SDK/src/InprocSSMCore.cpp [new file with mode: 0644]
service/soft-sensor-manager/SSMCore/include/SSMInterface.h [new file with mode: 0644]
service/soft-sensor-manager/SSMCore/src/SSMInterface/SSMCore.h
service/soft-sensor-manager/SSMCore/src/SSMInterface/SSMResourceServer.h [moved from service/soft-sensor-manager/SSMCore/include/SSMResourceServer.h with 100% similarity]
service/soft-sensor-manager/SSMCore/src/SSMResourceServerLauncher.cpp [deleted file]
service/soft-sensor-manager/SampleApp/linux/ClientApp/include/SSMTestApp.h
service/soft-sensor-manager/SampleApp/linux/ClientApp/src/SSMTestApp.cpp

diff --git a/service/soft-sensor-manager/SDK/src/InprocSSMCore.cpp b/service/soft-sensor-manager/SDK/src/InprocSSMCore.cpp
new file mode 100644 (file)
index 0000000..358f807
--- /dev/null
@@ -0,0 +1,121 @@
+#include "SSMInterface.h"
+#include "SSMInterface/SSMCore.h"
+#include "Common/PlatformLayer.h"
+
+class SSMCoreEventReceiver : public IQueryEngineEvent
+{
+    public:
+        SSMCoreEventReceiver()
+        {
+        }
+
+        SSMRESULT onQueryEngineEvent(IN int cqid, IN IDataReader *pResult)
+        {
+            SSMRESULT res = SSM_E_FAIL;
+
+            m_mtxListener.lock();
+
+            if (m_mapListener.find(cqid) == m_mapListener.end())
+            {
+                SSM_CLEANUP_ASSERT(res);
+            }
+
+            m_mapListener[cqid]->onQueryEngineEvent(cqid, pResult);
+
+            res = SSM_S_OK;
+
+CLEANUP:
+            m_mtxListener.unlock();
+            return res;
+        }
+
+        void lockListener()
+        {
+            m_mtxListener.lock();
+        }
+
+        void unlockListener()
+        {
+            m_mtxListener.unlock();
+        }
+
+        void addListener(IN int cqid, IN IQueryEngineEvent *pEngineEvent)
+        {
+            m_mapListener[cqid] = pEngineEvent;
+        }
+
+        void removeListener(IN int cqid)
+        {
+            m_mapListener.erase(cqid);
+        }
+
+    private:
+        CSimpleMutex                        m_mtxListener;
+        std::map<int, IQueryEngineEvent *>   m_mapListener;
+};
+
+IQueryEngine                        *g_pQueryEngineInstance = NULL;
+SSMCoreEventReceiver                *g_pEventReceiver = NULL;
+
+SSMInterface::SSMInterface()
+{
+    std::string xmlDescription = "<SSMCore>"
+                                 "<Device>"
+                                 "<UDN>abcde123-31f8-11b4-a222-08002b34c003</UDN>"
+                                 "<Name>MyPC</Name>"
+                                 "<Type>PC</Type>"
+                                 "</Device>"
+                                 "</SSMCore>";
+
+    SSMRESULT res = SSM_E_FAIL;
+
+    g_pEventReceiver = new SSMCoreEventReceiver();
+    SSM_CLEANUP_NULL_ASSERT(g_pEventReceiver);
+    SSM_CLEANUP_ASSERT(InitializeSSMCore(xmlDescription));
+    SSM_CLEANUP_ASSERT(StartSSMCore());
+    SSM_CLEANUP_ASSERT(CreateQueryEngine(&g_pQueryEngineInstance));
+    SSM_CLEANUP_ASSERT(g_pQueryEngineInstance->registerQueryEvent(g_pEventReceiver));
+CLEANUP:
+    ;
+}
+
+SSMInterface::~SSMInterface()
+{
+    SSMRESULT res = SSM_E_FAIL;
+
+    SSM_CLEANUP_ASSERT(g_pQueryEngineInstance->unregisterQueryEvent(g_pEventReceiver));
+    ReleaseQueryEngine(g_pQueryEngineInstance);
+    g_pQueryEngineInstance = NULL;
+    SSM_CLEANUP_ASSERT(StopSSMCore());
+    SSM_CLEANUP_ASSERT(TerminateSSMCore());
+
+CLEANUP:
+    SAFE_DELETE(g_pEventReceiver);
+}
+
+SSMRESULT SSMInterface::registerQuery(IN std::string queryString, IN IQueryEngineEvent *listener,
+                                      IN int &cqid)
+{
+    SSMRESULT res = SSM_E_FAIL;
+
+    g_pEventReceiver->lockListener();
+    SSM_CLEANUP_ASSERT(g_pQueryEngineInstance->executeContextQuery(queryString, &cqid));
+    g_pEventReceiver->addListener(cqid, listener);
+
+CLEANUP:
+    g_pEventReceiver->unlockListener();
+    return res;
+}
+
+SSMRESULT SSMInterface::unregisterQuery(IN int cqid)
+{
+    SSMRESULT res = SSM_E_FAIL;
+
+    g_pEventReceiver->lockListener();
+    SSM_CLEANUP_ASSERT(g_pQueryEngineInstance->killContextQuery(cqid));
+    g_pEventReceiver->removeListener(cqid);
+
+CLEANUP:
+    g_pEventReceiver->unlockListener();
+    return res;
+}
\ No newline at end of file
diff --git a/service/soft-sensor-manager/SSMCore/include/SSMInterface.h b/service/soft-sensor-manager/SSMCore/include/SSMInterface.h
new file mode 100644 (file)
index 0000000..b126130
--- /dev/null
@@ -0,0 +1,195 @@
+#ifndef _SSMInterface_H_
+#define _SSMInterface_H_
+
+#include <string>
+#include <vector>
+
+enum SSMRESULT
+{
+    SSM_S_OK
+    , SSM_S_FALSE
+    , SSM_E_POINTER
+    , SSM_E_OUTOFMEMORY
+    , SSM_E_FAIL
+    , SSM_E_NOINTERFACE
+    , SSM_E_NOTIMPL
+};
+
+/**
+* @class    IModelData
+* @brief    IModelData Interface
+*            This class represents context model data package
+*
+* @see
+*/
+class IModelData
+{
+    public:
+        /**
+        * @fn     getDataId
+        * @brief Get affected DataId. ContextModel has plenty of data so \n
+        *         returned data is matched from given condition
+        *
+        * @param None
+        *
+        * @return int
+        * @warning
+        * @exception
+        * @see
+        */
+        virtual int getDataId() = 0;
+
+        /**
+        * @fn     GetPropertyCount
+        * @brief ContextModel has at least one property that contains data \n
+        *         property is described from its specification.
+        *
+        * @param None
+        *
+        * @return int
+        * @warning
+        * @exception
+        * @see
+        */
+        virtual int getPropertyCount() = 0;
+
+        /**
+        * @fn     getPropertyName
+        * @brief Retrieve propertyName
+        *
+        * @param [in] int propertyIndex - index of property to read
+        *
+        * @return std::string
+        * @warning
+        * @exception
+        * @see
+        */
+        virtual std::string getPropertyName(int propertyIndex) = 0;
+
+        /**
+        * @fn     getPropertyValue
+        * @brief Retrieve propertyValue
+        *
+        * @param [in] int propertyIndex - index of property to read
+        *
+        * @return std::string
+        * @warning
+        * @exception
+        * @see
+        */
+        virtual std::string getPropertyValue(int propertyIndex) = 0;
+
+        /**
+        * @fn     getPropertyValueByName
+        * @brief Retrieve propertyValue using given name
+        *
+        * @param [in] std::string propertyName - property name looking for
+        *
+        * @return std::string
+        * @warning
+        * @exception
+        * @see
+        */
+        virtual std::string getPropertyValueByName(std::string propertyName) = 0;
+    protected:
+        virtual ~IModelData() {};
+};
+
+/**
+* @class    IDataReader
+* @brief    IDataReader Interface
+*            This class represents context model data package's reader
+*
+* @see
+*/
+class IDataReader
+{
+    public:
+        /**
+        * @fn     getAffectedModels
+        * @brief Get affected ContextModels. The CQL can specify multiple ContextModels for retrieving data.
+        *
+        * @param [out] std::vector<std::string> *pAffectedModels - affected ContextModel list
+        *
+        * @return SSMRESULT
+        * @warning
+        * @exception
+        * @see
+        */
+        virtual SSMRESULT getAffectedModels(std::vector<std::string> *pAffectedModels) = 0;
+
+        /**
+        * @fn     getModelDataCount
+        * @brief Get affected data count. There are multiple data can exist from given condition.
+        *
+        * @param [in] std::string modelName - affected ContextModel name
+        *
+        * @param [out] int *pDataCount - affected dataId count
+        *
+        * @return SSMRESULT
+        * @warning
+        * @exception
+        * @see
+        */
+        virtual SSMRESULT getModelDataCount(std::string modelName, int *pDataCount) = 0;
+
+        /**
+        * @fn     getModelData
+        * @brief Get actual Context Model data
+        *
+        * @param [in] std::string modelName - affected ContextModel name
+        *
+        *
+        * @param [in] int dataIndex - affected dataId index
+        *
+        *
+        * @param [out] IModelData **ppModelData - affected ContextModel data reader
+        *
+        * @return SSMRESULT
+        * @warning
+        * @exception
+        * @see
+        */
+        virtual SSMRESULT getModelData(std::string modelName, int dataIndex, IModelData **ppModelData) = 0;
+    protected:
+        virtual ~IDataReader() {};
+};
+
+/**
+* @class    IQueryEngineEvent
+* @brief    IQueryEngineEvent Interface
+*            This class represents Query Engine's event that contains results
+*
+* @see
+*/
+class IQueryEngineEvent
+{
+    public:
+        /**
+        * @fn     onQueryEngineEvent
+        * @brief Transmit result of SSMCore to Application layer
+        *
+        * @param [in] int cqid - entered ContextQuery ID
+        *
+        * @param [in] IDataReader *pResult - result of SSMCore
+        *
+        * @return SSMRESULT
+        * @warning
+        * @exception
+        * @see
+        */
+        virtual SSMRESULT onQueryEngineEvent(int cqid, IDataReader *pResult) = 0;
+    protected:
+        virtual ~IQueryEngineEvent() {};
+};
+
+class SSMInterface
+{
+    public:
+        SSMInterface();
+        ~SSMInterface();
+
+        SSMRESULT registerQuery(std::string queryString, IQueryEngineEvent *listener, int &cqid);
+        SSMRESULT unregisterQuery(int cqid);
+};
+#endif
\ No newline at end of file
index f109cfb..1217284 100644 (file)
@@ -20,9 +20,7 @@
 #ifndef _SSMCore_H_
 #define _SSMCore_H_
 
-#include <string>
-#include <vector>
-
+#include "SSMInterface.h"
 #include "SSMModelDefinition.h"
 
 #define IN
 */
 #define INTERFACE_DECLSPEC
 
-enum SSMRESULT
-{
-    SSM_S_OK
-    , SSM_S_FALSE
-    , SSM_E_POINTER
-    , SSM_E_OUTOFMEMORY
-    , SSM_E_FAIL
-    , SSM_E_NOINTERFACE
-    , SSM_E_NOTIMPL
-};
-
-/**
-* @class    IModelData
-* @brief    IModelData Interface
-*            This class represents context model data package
-*
-* @see
-*/
-class IModelData
-{
-    public:
-        /**
-        * @fn     getDataId
-        * @brief Get affected DataId. ContextModel has plenty of data so \n
-        *         returned data is matched from given condition
-        *
-        * @param None
-        *
-        * @return int
-        * @warning
-        * @exception
-        * @see
-        */
-        virtual int getDataId() = 0;
-
-        /**
-        * @fn     GetPropertyCount
-        * @brief ContextModel has at least one property that contains data \n
-        *         property is described from its specification.
-        *
-        * @param None
-        *
-        * @return int
-        * @warning
-        * @exception
-        * @see
-        */
-        virtual int getPropertyCount() = 0;
-
-        /**
-        * @fn     getPropertyName
-        * @brief Retrieve propertyName
-        *
-        * @param [in] int propertyIndex - index of property to read
-        *
-        * @return std::string
-        * @warning
-        * @exception
-        * @see
-        */
-        virtual std::string getPropertyName(IN int propertyIndex) = 0;
-
-        /**
-        * @fn     getPropertyValue
-        * @brief Retrieve propertyValue
-        *
-        * @param [in] int propertyIndex - index of property to read
-        *
-        * @return std::string
-        * @warning
-        * @exception
-        * @see
-        */
-        virtual std::string getPropertyValue(IN int propertyIndex) = 0;
-
-        /**
-        * @fn     getPropertyValueByName
-        * @brief Retrieve propertyValue using given name
-        *
-        * @param [in] std::string propertyName - property name looking for
-        *
-        * @return std::string
-        * @warning
-        * @exception
-        * @see
-        */
-        virtual std::string getPropertyValueByName(IN std::string propertyName) = 0;
-    protected:
-        virtual ~IModelData() {};
-};
-
-/**
-* @class    IDataReader
-* @brief    IDataReader Interface
-*            This class represents context model data package's reader
-*
-* @see
-*/
-class IDataReader
-{
-    public:
-        /**
-        * @fn     getAffectedModels
-        * @brief Get affected ContextModels. The CQL can specify multiple ContextModels for retrieving data.
-        *
-        * @param [out] std::vector<std::string> *pAffectedModels - affected ContextModel list
-        *
-        * @return SSMRESULT
-        * @warning
-        * @exception
-        * @see
-        */
-        virtual SSMRESULT getAffectedModels(OUT std::vector<std::string> *pAffectedModels) = 0;
-
-        /**
-        * @fn     getModelDataCount
-        * @brief Get affected data count. There are multiple data can exist from given condition.
-        *
-        * @param [in] std::string modelName - affected ContextModel name
-        *
-        * @param [out] int *pDataCount - affected dataId count
-        *
-        * @return SSMRESULT
-        * @warning
-        * @exception
-        * @see
-        */
-        virtual SSMRESULT getModelDataCount(IN std::string modelName, OUT int *pDataCount) = 0;
-
-        /**
-        * @fn     getModelData
-        * @brief Get actual Context Model data
-        *
-        * @param [in] std::string modelName - affected ContextModel name
-        *
-        *
-        * @param [in] int dataIndex - affected dataId index
-        *
-        *
-        * @param [out] IModelData **ppModelData - affected ContextModel data reader
-        *
-        * @return SSMRESULT
-        * @warning
-        * @exception
-        * @see
-        */
-        virtual SSMRESULT getModelData(IN std::string modelName, IN int dataIndex,
-                                       OUT IModelData **ppModelData) = 0;
-    protected:
-        virtual ~IDataReader() {};
-};
-
-/**
-* @class    IQueryEngineEvent
-* @brief    IQueryEngineEvent Interface
-*            This class represents Query Engine's event that contains results
-*
-* @see
-*/
-class IQueryEngineEvent
-{
-    public:
-        /**
-        * @fn     onQueryEngineEvent
-        * @brief Transmit result of SSMCore to Application layer
-        *
-        * @param [in] int cqid - entered ContextQuery ID
-        *
-        * @param [in] IDataReader *pResult - result of SSMCore
-        *
-        * @return SSMRESULT
-        * @warning
-        * @exception
-        * @see
-        */
-        virtual SSMRESULT onQueryEngineEvent(IN int cqid, IN IDataReader *pResult) = 0;
-    protected:
-        virtual ~IQueryEngineEvent() {};
-};
-
 /**
 * @class    IQueryEngine
 * @brief    IQueryEngine Interface
diff --git a/service/soft-sensor-manager/SSMCore/src/SSMResourceServerLauncher.cpp b/service/soft-sensor-manager/SSMCore/src/SSMResourceServerLauncher.cpp
deleted file mode 100644 (file)
index bf96c57..0000000
+++ /dev/null
@@ -1,69 +0,0 @@
-/******************************************************************
- *
- * 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.
- *
- ******************************************************************/
-
-/*
- * SSMResourceServerLauncher.cpp
- */
-#include "SSMResourceServer.h"
-
-string xmlDescription = "<SSMCore>"
-                        "<Device>"
-                        "<UDN>abcde123-31f8-11b4-a222-08002b34c003</UDN>"
-                        "<Name>MyPC</Name>"
-                        "<Type>PC</Type>"
-                        "</Device>"
-                        "</SSMCore>";
-
-using namespace std;
-
-int main(int argc, char *argv[])
-{
-    int inputKey = 0;
-
-    try
-    {
-        SSMResourceServer ssmResourceServer;
-
-        cout << "Initializing Resource Server" << endl;
-
-        if (ssmResourceServer.initializeManager(xmlDescription) != 0)
-        {
-            cout << "SSM Resource Server init failed" << endl;
-            return -1;
-        }
-
-        cout << "SSM Resource Server is working, press anykey to terminate" << endl;
-
-        cin >> inputKey;
-
-        cout << "SSM Resource Server is terminating" << endl;
-
-        if (ssmResourceServer.terminateManager() != 0)
-        {
-            cout << "SSM Resource Server terminate failed" << endl;
-        }
-    }
-    catch (std::exception e)
-    {
-        cout << e.what() << endl;
-    }
-
-    cout << "bye bye" << endl;
-}
index f564708..63b94c8 100644 (file)
@@ -29,6 +29,7 @@
 
 #include "OCResource.h"
 #include "OCPlatform.h"
+#include "SSMInterface.h"
 #include "SSMClient.h"
 #include "ISSMClientListener.h"
 
@@ -47,9 +48,11 @@ typedef enum
 } DIResult;
 
 class SSMTestApp: public ISSMClientListener
+    , public IQueryEngineEvent
 {
     private:
-        SSMClient m_SSMClient;
+        //SSMClient m_SSMClient;
+        SSMInterface m_SSMClient;
 
     public:
 
@@ -61,7 +64,7 @@ class SSMTestApp: public ISSMClientListener
 
         /* operations from listener interface */
         void onRegisterQuery(const AttributeMap &attributeMap, SSMReturn &eCode);
-
+        SSMRESULT onQueryEngineEvent(int cqid, IDataReader *pResult);
 };
 
 #endif /* SSMTESTAPP_H_ */
index 008a880..907790d 100644 (file)
@@ -23,7 +23,6 @@
 #include <iostream>
 
 #include "SSMTestApp.h"
-#include "SSMClient.h"
 
 SSMTestApp::SSMTestApp()
 {
@@ -45,8 +44,8 @@ void SSMTestApp::displayMenu()
 /* Register Query.*/
 void SSMTestApp::registerQuery(std::string queryString)
 {
-    std::string qid;
-    SSMReturn rtn = SSM_ERROR;
+    int qid;
+    SSMRESULT rtn = SSM_E_FAIL;
 
     if (queryString.size() == 0)
     {
@@ -57,10 +56,10 @@ void SSMTestApp::registerQuery(std::string queryString)
 
     rtn = m_SSMClient.registerQuery(queryString, this, qid);
 
-    if (rtn == SSM_SUCCESS)
+    if (rtn == SSM_S_OK)
     {
         printf("The query has been registered!\n");
-        printf("QID : %s\n", qid.c_str());
+        printf("QID : %d\n", qid);
     }
     else
         printf("Error occured(%d)", rtn);
@@ -70,15 +69,15 @@ void SSMTestApp::registerQuery(std::string queryString)
 void SSMTestApp::unregisterQuery(void)
 {
     std::string qid;
-    SSMReturn rtn = SSM_ERROR;
+    SSMRESULT rtn = SSM_E_FAIL;
 
     printf("   Please Enter query string: ");
     cin.ignore();
     getline(cin, qid);
 
-    rtn = m_SSMClient.unregisterQuery(qid);
+    rtn = m_SSMClient.unregisterQuery(atoi(qid.c_str()));
 
-    if (rtn == SSM_SUCCESS)
+    if (rtn == SSM_S_OK)
         printf("The query has been unregistered!\n");
     else
         printf("Error occured(%d)\n", (int) rtn);
@@ -144,6 +143,36 @@ void SSMTestApp::onRegisterQuery(const AttributeMap &attributeMap, SSMReturn &eC
     }
 }
 
+SSMRESULT SSMTestApp::onQueryEngineEvent(int cqid, IDataReader *pResult)
+{
+    int     dataCount = 0;
+    IModelData      *pModelData = NULL;
+    std::vector<std::string>        affectedModels;
+
+    cout << "Event received! cqid = " << cqid << endl;
+
+    pResult->getAffectedModels(&affectedModels);
+
+    for (std::vector<std::string>::iterator itor = affectedModels.begin();
+         itor != affectedModels.end(); ++itor)
+    {
+        cout << "Printing " << *itor << " model" << endl;
+        pResult->getModelDataCount(*itor, &dataCount);
+        for (int i = 0; i < dataCount; i++)
+        {
+            pResult->getModelData(*itor, i, &pModelData);
+            cout << "dataId: " << pModelData->getDataId() << endl;
+            for (int j = 0; j < pModelData->getPropertyCount(); j++)
+            {
+                cout << "Type: " << pModelData->getPropertyName(j) << " Value: " << pModelData->getPropertyValue(
+                         j) << endl;
+            }
+        }
+    }
+
+    return SSM_S_OK;
+}
+
 /**
  * APP. Main Function.
  */