[SSM] Fix issues about initializing SSM
authorMinji Park <minjii.park@samsung.com>
Fri, 9 Jan 2015 08:01:50 +0000 (17:01 +0900)
committerSudarshan Prasad <sudarshan.prasad@intel.com>
Thu, 22 Jan 2015 14:25:22 +0000 (14:25 +0000)
1. modify to return error code when xml parsing error occurs
2. apply new SSM Interface
3. modify sample apps according to the new interface design
4. modify ResourceFinder to stop checking presence when SSM terminates

Change-Id: Id5cd6aade44fe531cb547400d15bb343ba28655a
Signed-off-by: Minji Park <minjii.park@samsung.com>
(cherry picked from commit 755906466e380ef87011385b89af29004e616bb0)
Reviewed-on: https://gerrit.iotivity.org/gerrit/207
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Sudarshan Prasad <sudarshan.prasad@intel.com>
13 files changed:
service/soft-sensor-manager/SDK/cpp/include/SSMInterface.h
service/soft-sensor-manager/SDK/cpp/src/InprocSSMCore.cpp
service/soft-sensor-manager/SSMCore/include/SSMInterface.h
service/soft-sensor-manager/SSMCore/src/Common/InternalInterface.h
service/soft-sensor-manager/SSMCore/src/SSMInterface/SSMCore.cpp
service/soft-sensor-manager/SSMCore/src/SSMInterface/SoftSensorManager.cpp
service/soft-sensor-manager/SSMCore/src/SensorProcessor/ContextRepository.cpp
service/soft-sensor-manager/SSMCore/src/SensorProcessor/ContextRepository.h
service/soft-sensor-manager/SSMCore/src/SensorProcessor/ResourceFinder.cpp
service/soft-sensor-manager/SSMCore/src/SensorProcessor/ResourceFinder.h
service/soft-sensor-manager/SampleApp/linux/SSMTesterApp/include/SSMTestApp.h
service/soft-sensor-manager/SampleApp/linux/SSMTesterApp/src/SSMTestApp.cpp
service/soft-sensor-manager/SampleApp/tizen/SSMTesterApp/oic-sample/src/oicapp-test.cpp

index 0085b3b..50ab302 100644 (file)
@@ -13,6 +13,9 @@ namespace OIC
         , SSM_E_POINTER
         , SSM_E_OUTOFMEMORY
         , SSM_E_FAIL
+        , SSM_E_NOTINIT
+        , SSM_E_INITIALIZED
+        , SSM_E_INVALIDXML
         , SSM_E_NOINTERFACE
         , SSM_E_NOTIMPL
     };
@@ -183,47 +186,59 @@ namespace OIC
     };
 
     /**
-    * @class    SSMInterface
-    * @brief    This class represents main class for querying Soft Sensors
+    * @fn    InitializeSSM
+    * @brief Initialize Soft sensor manager using given configuration information.
     *
+    * @param [in] std::string xmlDescription - specification described in XML
+    *
+    * @return SSMRESULT
+    * @warning
+    * @exception
     * @see
     */
-    class SSMInterface
-    {
-        public:
-            SSMInterface();
-            ~SSMInterface();
+    SSMRESULT InitializeSSM(std::string xmlDescription);
 
-            /**
-            * @fn     registerQuery
-            * @brief Execute ContextQuery and return ContextQuery ID
-            *
-            * @param [in] std::string queryString - query for requesting data
-            *
-            * @param [in] IQueryEngineEvent listener - listener for receiving data related to query
-            *
-            * @param [in, out] int &cqid - ID of ContextQuery
-            *
-            * @return SSMRESULT
-            * @warning
-            * @exception
-            * @see
-            */
-            SSMRESULT registerQuery(std::string queryString, IQueryEngineEvent *listener, int &cqid);
+    /**
+    * @fn    TerminateSSM
+    * @brief Terminates Soft sensor manager
+    *
+    * @param None
+    *
+    * @return SSMRESULT
+    * @warning
+    * @exception
+    * @see
+    */
+    SSMRESULT TerminateSSM();
 
-            /**
-            * @fn    unregisterQuery
-            * @brief unregister registered ContextQuery according to cqid
-            *
-            * @param [in] int cqid - Context query corresponding to the cqid will be terminated
-            *
-            * @return SSMRESULT
-            * @warning
-            * @exception
-            * @see
-            */
-            SSMRESULT unregisterQuery(int cqid);
-    };
+    /**
+    * @fn     RegisterQuery
+    * @brief Execute ContextQuery and return ContextQuery ID
+    *
+    * @param [in] std::string queryString - query for requesting data
+    *
+    * @param [in] IQueryEngineEvent listener - listener for receiving data related to query
+    *
+    * @param [in, out] int &cqid - ID of ContextQuery
+    *
+    * @return SSMRESULT
+    * @warning
+    * @exception
+    * @see
+    */
+    SSMRESULT RegisterQuery(std::string queryString, IQueryEngineEvent *listener, int &cqid);
 
+    /**
+    * @fn    UnregisterQuery
+    * @brief unregister registered ContextQuery according to cqid
+    *
+    * @param [in] int cqid - Context query corresponding to the cqid will be terminated
+    *
+    * @return SSMRESULT
+    * @warning
+    * @exception
+    * @see
+    */
+    SSMRESULT UnregisterQuery(int cqid);
 }
 #endif
\ No newline at end of file
index 358f807..6b691de 100644 (file)
@@ -57,32 +57,36 @@ CLEANUP:
 IQueryEngine                        *g_pQueryEngineInstance = NULL;
 SSMCoreEventReceiver                *g_pEventReceiver = NULL;
 
-SSMInterface::SSMInterface()
+SSMRESULT OIC::InitializeSSM(std::string xmlDescription)
 {
-    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;
 
+    if (g_pQueryEngineInstance != NULL)
+        SSM_CLEANUP_ASSERT(SSM_E_INITIALIZED);
+
     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:
-    ;
+    if (res != SSM_S_OK)
+    {
+        SAFE_DELETE(g_pEventReceiver);
+    }
+
+    return res;
 }
 
-SSMInterface::~SSMInterface()
+SSMRESULT OIC::TerminateSSM()
 {
     SSMRESULT res = SSM_E_FAIL;
 
+    if (g_pQueryEngineInstance == NULL)
+        SSM_CLEANUP_ASSERT(SSM_E_NOTINIT);
+
     SSM_CLEANUP_ASSERT(g_pQueryEngineInstance->unregisterQueryEvent(g_pEventReceiver));
     ReleaseQueryEngine(g_pQueryEngineInstance);
     g_pQueryEngineInstance = NULL;
@@ -91,31 +95,40 @@ SSMInterface::~SSMInterface()
 
 CLEANUP:
     SAFE_DELETE(g_pEventReceiver);
+    return res;
 }
 
-SSMRESULT SSMInterface::registerQuery(IN std::string queryString, IN IQueryEngineEvent *listener,
-                                      IN int &cqid)
+SSMRESULT OIC::RegisterQuery(IN std::string queryString, IN IQueryEngineEvent *listener,
+                             IN int &cqid)
 {
     SSMRESULT res = SSM_E_FAIL;
 
+    if (g_pQueryEngineInstance == NULL)
+        SSM_CLEANUP_ASSERT(SSM_E_NOTINIT);
+
     g_pEventReceiver->lockListener();
     SSM_CLEANUP_ASSERT(g_pQueryEngineInstance->executeContextQuery(queryString, &cqid));
     g_pEventReceiver->addListener(cqid, listener);
 
 CLEANUP:
-    g_pEventReceiver->unlockListener();
+    if (g_pEventReceiver != NULL)
+        g_pEventReceiver->unlockListener();
     return res;
 }
 
-SSMRESULT SSMInterface::unregisterQuery(IN int cqid)
+SSMRESULT OIC::UnregisterQuery(IN int cqid)
 {
     SSMRESULT res = SSM_E_FAIL;
 
+    if (g_pQueryEngineInstance == NULL)
+        SSM_CLEANUP_ASSERT(SSM_E_NOTINIT);
+
     g_pEventReceiver->lockListener();
     SSM_CLEANUP_ASSERT(g_pQueryEngineInstance->killContextQuery(cqid));
     g_pEventReceiver->removeListener(cqid);
 
 CLEANUP:
-    g_pEventReceiver->unlockListener();
+    if (g_pEventReceiver != NULL)
+        g_pEventReceiver->unlockListener();
     return res;
 }
\ No newline at end of file
index 0085b3b..50ab302 100644 (file)
@@ -13,6 +13,9 @@ namespace OIC
         , SSM_E_POINTER
         , SSM_E_OUTOFMEMORY
         , SSM_E_FAIL
+        , SSM_E_NOTINIT
+        , SSM_E_INITIALIZED
+        , SSM_E_INVALIDXML
         , SSM_E_NOINTERFACE
         , SSM_E_NOTIMPL
     };
@@ -183,47 +186,59 @@ namespace OIC
     };
 
     /**
-    * @class    SSMInterface
-    * @brief    This class represents main class for querying Soft Sensors
+    * @fn    InitializeSSM
+    * @brief Initialize Soft sensor manager using given configuration information.
     *
+    * @param [in] std::string xmlDescription - specification described in XML
+    *
+    * @return SSMRESULT
+    * @warning
+    * @exception
     * @see
     */
-    class SSMInterface
-    {
-        public:
-            SSMInterface();
-            ~SSMInterface();
+    SSMRESULT InitializeSSM(std::string xmlDescription);
 
-            /**
-            * @fn     registerQuery
-            * @brief Execute ContextQuery and return ContextQuery ID
-            *
-            * @param [in] std::string queryString - query for requesting data
-            *
-            * @param [in] IQueryEngineEvent listener - listener for receiving data related to query
-            *
-            * @param [in, out] int &cqid - ID of ContextQuery
-            *
-            * @return SSMRESULT
-            * @warning
-            * @exception
-            * @see
-            */
-            SSMRESULT registerQuery(std::string queryString, IQueryEngineEvent *listener, int &cqid);
+    /**
+    * @fn    TerminateSSM
+    * @brief Terminates Soft sensor manager
+    *
+    * @param None
+    *
+    * @return SSMRESULT
+    * @warning
+    * @exception
+    * @see
+    */
+    SSMRESULT TerminateSSM();
 
-            /**
-            * @fn    unregisterQuery
-            * @brief unregister registered ContextQuery according to cqid
-            *
-            * @param [in] int cqid - Context query corresponding to the cqid will be terminated
-            *
-            * @return SSMRESULT
-            * @warning
-            * @exception
-            * @see
-            */
-            SSMRESULT unregisterQuery(int cqid);
-    };
+    /**
+    * @fn     RegisterQuery
+    * @brief Execute ContextQuery and return ContextQuery ID
+    *
+    * @param [in] std::string queryString - query for requesting data
+    *
+    * @param [in] IQueryEngineEvent listener - listener for receiving data related to query
+    *
+    * @param [in, out] int &cqid - ID of ContextQuery
+    *
+    * @return SSMRESULT
+    * @warning
+    * @exception
+    * @see
+    */
+    SSMRESULT RegisterQuery(std::string queryString, IQueryEngineEvent *listener, int &cqid);
 
+    /**
+    * @fn    UnregisterQuery
+    * @brief unregister registered ContextQuery according to cqid
+    *
+    * @param [in] int cqid - Context query corresponding to the cqid will be terminated
+    *
+    * @return SSMRESULT
+    * @warning
+    * @exception
+    * @see
+    */
+    SSMRESULT UnregisterQuery(int cqid);
 }
 #endif
\ No newline at end of file
index e0db5b2..884e14d 100644 (file)
@@ -131,6 +131,7 @@ class IContextRepository : public IBase
 
         virtual SSMRESULT registerResourceFinderEvent(IN IResourceEvent *pResourceEvent) = 0;
         virtual SSMRESULT startResourceFinder() = 0;
+        virtual SSMRESULT stopResourceFinder() = 0;
         virtual SSMRESULT onResourceFound(IN ISSMResource *pSensor) = 0;
         virtual SSMRESULT onResourceLost(IN ISSMResource *pSensor) = 0;
 
@@ -1195,6 +1196,7 @@ class IResourceFinder : public IBase
     public:
         virtual SSMRESULT registerResourceFinderEvent(IN IResourceFinderEvent *pEvent) = 0;
         virtual SSMRESULT startResourceFinder() = 0;
+        virtual SSMRESULT stopResourceFinder() = 0;
         virtual SSMRESULT startObserveResource(IN ISSMResource *pSensor, IN IEvent *pEvent) = 0;
         virtual SSMRESULT stopObserveResource(IN ISSMResource *pSensor) = 0;
 };
index 5b1340f..2c735ef 100644 (file)
@@ -122,6 +122,18 @@ const char *GetSSMError(SSMRESULT res)
             msg = "SSM_E_FAIL";
             break;
 
+        case SSM_E_NOTINIT:
+            msg = "SSM_E_NOTINIT";
+            break;
+
+        case SSM_E_INITIALIZED:
+            msg = "SSM_E_INITIALIZED";
+            break;
+
+        case SSM_E_INVALIDXML:
+            msg = "SSM_E_INVALIDXML";
+            break;
+
         case SSM_E_NOINTERFACE:
             msg = "SSM_E_NOINTERFACE";
             break;
index 0d0149e..aaf04a7 100644 (file)
@@ -119,8 +119,9 @@ SSMRESULT CSoftSensorManager::initializeCore(IN std::string xmlDescription)
         }
     }
 
-    SSM_CLEANUP_ASSERT(CreateGlobalInstance(OID_IContextRepository, (IBase **)&m_pContextRepository));
     SSM_CLEANUP_ASSERT(CreateGlobalInstance(OID_ISensingEngine, (IBase **)&m_pSensingEngine));
+    SSM_CLEANUP_ASSERT(m_pSensingEngine->queryInterface(OID_IContextRepository,
+                       (IBase **)&m_pContextRepository));
     SSM_CLEANUP_ASSERT(m_pContextRepository->initRepository(name, type, pathSoftSensors,
                        pathDescription));
 
@@ -137,14 +138,22 @@ CLEANUP:
 
 SSMRESULT CSoftSensorManager::startCore()
 {
-    //m_pSharingLayer->Start();
-    return SSM_S_OK;
+    SSMRESULT res = SSM_E_FAIL;
+
+    SSM_CLEANUP_ASSERT(m_pContextRepository->startResourceFinder());
+
+CLEANUP:
+    return res;
 }
 
 SSMRESULT CSoftSensorManager::stopCore()
 {
-    //m_pSharingLayer->Stop();
-    return SSM_S_OK;
+    SSMRESULT res = SSM_E_FAIL;
+
+    SSM_CLEANUP_ASSERT(m_pContextRepository->stopResourceFinder());
+
+CLEANUP:
+    return res;
 }
 
 SSMRESULT CSoftSensorManager::terminateCore(bool factoryResetFlag)
index 767f6c8..06bd3f7 100644 (file)
@@ -55,6 +55,16 @@ CLEANUP:
     return res;
 }
 
+SSMRESULT CContextRepository::stopResourceFinder()
+{
+    SSMRESULT res = SSM_E_FAIL;
+
+    SSM_CLEANUP_ASSERT(m_resourceFinder->stopResourceFinder());
+
+CLEANUP:
+    return res;
+}
+
 SSMRESULT CContextRepository::registerResourceFinderEvent(IN IResourceEvent *pResourceEvent)
 {
     m_resourceEvents.push_back(pResourceEvent);
@@ -108,10 +118,9 @@ SSMRESULT CContextRepository::loadXMLFromString(char *xmlData,
         std::vector<DictionaryData> *dataList)
 {
     // use  rapidxml-----------------------
-    SSMRESULT res = SSM_E_FAIL;
+    SSMRESULT res = SSM_E_INVALIDXML;
     rapidxml::xml_document< char > xmlDoc;
     //xmlDoc.parse< 0 >( &xmlData.front() );
-    xmlDoc.parse< 0 >(xmlData);
 
     std::string keyStr;
     std::string valueStr;
@@ -121,73 +130,84 @@ SSMRESULT CContextRepository::loadXMLFromString(char *xmlData,
     rapidxml::xml_node< char > *subItem2;
     rapidxml::xml_node< char > *subItem3;
 
-    // get value
-    rapidxml::xml_node< char > *root = xmlDoc.first_node();
+    rapidxml::xml_node< char > *root;
 
-    if (!root)
+    try
     {
-        SSM_CLEANUP_ASSERT(SSM_E_FAIL);
-    }
+        xmlDoc.parse< 0 >(xmlData);
 
-    for ( item = root->first_node(); item; item = item->next_sibling() )
-    {
-        DictionaryData dictionaryData;
-        for ( subItem = item->first_node(); subItem ; subItem = subItem->next_sibling() )
+        // get value
+        root = xmlDoc.first_node();
+
+        if (!root)
         {
-            //root name
-            keyStr = subItem->name();  // key
-            valueStr = subItem->value();   // value
+            throw rapidxml::parse_error("No Root Element", 0);
+        }
 
-            if (!keyStr.compare("name"))
-            {
-                dictionaryData.rootName = trim_both(valueStr);
-            }
-            ////std::cout<<keyStr << " : " << subItem->value() <<std::endl<<std::endl; //root_name
-            for (subItem2 = subItem->first_node(); subItem2 ; subItem2 = subItem2->next_sibling())
+        for (item = root->first_node(); item; item = item->next_sibling())
+        {
+            DictionaryData dictionaryData;
+            for (subItem = item->first_node(); subItem; subItem = subItem->next_sibling())
             {
-                std::map<std::string, std::string> propertyMap;
-                std::vector<std::string> enterconditionVector;
+                //root name
+                keyStr = subItem->name();  // key
+                valueStr = subItem->value();   // value
 
-                keyStr = subItem2->name();  // key
-                valueStr = subItem2->value();   // value
-
-                if (!keyStr.compare("input"))
+                if (!keyStr.compare("name"))
                 {
-                    dictionaryData.inputs.push_back(trim_both(valueStr));
+                    dictionaryData.rootName = trim_both(valueStr);
                 }
-                ////std::cout<<name << " :: " << subItem2->value() <<std::endl<<std::endl;
-                for (subItem3 = subItem2->first_node(); subItem3 ; subItem3 = subItem3->next_sibling())
+                ////std::cout<<keyStr << " : " << subItem->value() <<std::endl<<std::endl; //root_name
+                for (subItem2 = subItem->first_node(); subItem2; subItem2 = subItem2->next_sibling())
                 {
-                    std::string newKeyStr = subItem3->name();  // key
-                    valueStr = subItem3->value();   // value
+                    std::map<std::string, std::string> propertyMap;
+                    std::vector<std::string> enterconditionVector;
+
+                    keyStr = subItem2->name();  // key
+                    valueStr = subItem2->value();   // value
 
-                    if (!keyStr.compare("attribute") || !keyStr.compare("output") )
+                    if (!keyStr.compare("input"))
                     {
-                        propertyMap.insert(std::make_pair(trim_both(newKeyStr), trim_both(valueStr)));
+                        dictionaryData.inputs.push_back(trim_both(valueStr));
+                    }
+                    ////std::cout<<name << " :: " << subItem2->value() <<std::endl<<std::endl;
+                    for (subItem3 = subItem2->first_node(); subItem3; subItem3 = subItem3->next_sibling())
+                    {
+                        std::string newKeyStr = subItem3->name();  // key
+                        valueStr = subItem3->value();   // value
+
+                        if (!keyStr.compare("attribute") || !keyStr.compare("output"))
+                        {
+                            propertyMap.insert(std::make_pair(trim_both(newKeyStr), trim_both(valueStr)));
+                        }
+                    }
+                    if (!keyStr.compare("attribute"))
+                    {
+                        dictionaryData.attributeProperty.push_back(propertyMap);
+                    }
+                    else if (!keyStr.compare("output"))
+                    {
+                        dictionaryData.outputProperty.push_back(propertyMap);
                     }
-                }
-                if (!keyStr.compare("attribute"))
-                {
-                    dictionaryData.attributeProperty.push_back(propertyMap);
-                }
-                else if (!keyStr.compare("output"))
-                {
-                    dictionaryData.outputProperty.push_back(propertyMap);
                 }
             }
+            //for accurate data.
+            /*
+            dictionaryData.app_input_count = std::to_string((long long)dictionaryData.app_inputs.size());
+            dictionaryData.input_count = std::to_string((long long)dictionaryData.inputs.size());
+            dictionaryData.attribute_property_count = std::to_string((long long)dictionaryData.attribute_property.size());
+            dictionaryData.output_property_count = std::to_string((long long)dictionaryData.output_property.size());
+            */
+
+            dataList->push_back(dictionaryData);
         }
-        //for accurate data.
-        /*
-        dictionaryData.app_input_count = std::to_string((long long)dictionaryData.app_inputs.size());
-        dictionaryData.input_count = std::to_string((long long)dictionaryData.inputs.size());
-        dictionaryData.attribute_property_count = std::to_string((long long)dictionaryData.attribute_property.size());
-        dictionaryData.output_property_count = std::to_string((long long)dictionaryData.output_property.size());
-        */
-
-        dataList->push_back(dictionaryData);
-    }
 
-    res = SSM_S_OK;
+        res = SSM_S_OK;
+    }
+    catch (rapidxml::parse_error &e)
+    {
+        SSM_CLEANUP_ASSERT(SSM_E_INVALIDXML);
+    }
 
 CLEANUP:
     return res;
@@ -428,4 +448,4 @@ SSMRESULT CContextRepository::getCurrentPath(std::string *path)
 
 CLEANUP:
     return res;
-}
\ No newline at end of file
+}
index d822679..1008701 100644 (file)
@@ -131,6 +131,7 @@ class CContextRepository :
 
         SSMRESULT registerResourceFinderEvent(IN IResourceEvent *pResourceEvent);
         SSMRESULT startResourceFinder();
+        SSMRESULT stopResourceFinder();
         SSMRESULT onResourceFound(IN ISSMResource *pSensor);
         SSMRESULT onResourceLost(IN ISSMResource *pSensor);
 
@@ -149,4 +150,4 @@ class CContextRepository :
         SSMRESULT loadXMLFromString(IN char *xmlData, IN std::vector<DictionaryData> *dataList);
         SSMRESULT getCurrentPath(OUT std::string *path);
 };
-#endif
\ No newline at end of file
+#endif
index 57dbe2c..9920eda 100644 (file)
@@ -32,6 +32,8 @@ SSMRESULT CResourceFinder::finalConstruct()
 
     m_pResourceFinderEvent = NULL;
 
+    m_multicastPresenceHandle = nullptr;
+
 CLEANUP:
     return res;
 }
@@ -59,8 +61,6 @@ void CResourceFinder::onResourceFound(std::shared_ptr< OC::OCResource > resource
         pMessage[0] = RESOURCE_DISCOVER_REQUESTPROFILE;
         pMessage[1] = reinterpret_cast<intptr_t> (new  std::shared_ptr<OC::OCResource>(resource));
 
-        std::cout << "Resource Found !! >> " << path << std::endl;
-
         m_pTasker->addTask(this, pMessage);
     }
 }
@@ -117,15 +117,13 @@ SSMRESULT CResourceFinder::startResourceFinder()
     SSMRESULT res = SSM_E_FAIL;
     OCStackResult ret = OC_STACK_ERROR;
 
-    OC::OCPlatform::OCPresenceHandle presenceHandle = nullptr;
-
     ret = OC::OCPlatform::findResource("", "coap://224.0.1.187/oc/core?rt=SoftSensorManager.Sensor",
                                        std::bind(&CResourceFinder::onResourceFound, this, std::placeholders::_1));
 
     if (ret != OC_STACK_OK)
         SSM_CLEANUP_ASSERT(SSM_E_FAIL);
 
-    ret = OC::OCPlatform::subscribePresence(presenceHandle, "coap://224.0.1.187",
+    ret = OC::OCPlatform::subscribePresence(m_multicastPresenceHandle, "coap://224.0.1.187",
                                             "SoftSensorManager.Sensor",
                                             std::bind(&CResourceFinder::presenceHandler, this, std::placeholders::_1,
                                                     std::placeholders::_2, std::placeholders::_3));
@@ -139,6 +137,24 @@ CLEANUP:
     return res;
 }
 
+SSMRESULT CResourceFinder::stopResourceFinder()
+{
+    SSMRESULT res = SSM_E_FAIL;
+    OCStackResult ret = OC_STACK_ERROR;
+
+    ret = OC::OCPlatform::unsubscribePresence(m_multicastPresenceHandle);
+
+    if (ret != OC_STACK_OK)
+        SSM_CLEANUP_ASSERT(SSM_E_FAIL);
+
+    m_multicastPresenceHandle = nullptr;
+
+    res = SSM_S_OK;
+
+CLEANUP:
+    return res;
+}
+
 SSMRESULT CResourceFinder::startObserveResource(IN ISSMResource *pSensor, IN IEvent *pEvent)
 {
     return m_mapResourceHandler[pSensor->name]->startObserve(pEvent);
index 1ad2ccf..9564e38 100644 (file)
@@ -55,6 +55,7 @@ class CResourceFinder: public CObjectRoot< CObjectMultiThreadModel >,
         void presenceHandler(OCStackResult result, const unsigned int nonce,
                              const std::string &hostAddress);
         SSMRESULT startResourceFinder();
+        SSMRESULT stopResourceFinder();
 
         SSMRESULT startObserveResource(IN ISSMResource *pSensor, IN IEvent *pEvent);
         SSMRESULT stopObserveResource(IN ISSMResource *pSensor);
@@ -201,8 +202,10 @@ CLEANUP: return res;
             RESOURCE_DISCOVER_INSTALL_RESOURCE,
             RESOURCE_DISCOVER_UNINSTALL_RESOURCE
         };
+
         IResourceFinderEvent *m_pResourceFinderEvent;
         CObjectPtr< ITasker > m_pTasker;
+        OC::OCPlatform::OCPresenceHandle m_multicastPresenceHandle;
         std::map< std::string, OICResourceHandler * > m_mapResourceHandler;
         std::map< std::string, std::vector<std::string> >
         m_mapResources;    // <hostaddress, std::vector<resources> >
index c68304d..a1b45cf 100644 (file)
@@ -35,7 +35,7 @@ namespace APPMenu
 {
     typedef enum
     {
-        NONE = 0, REGISTER, UNREGISTER, DISCOMFORT_SAMPLE, EXIT = 9
+        NONE = 0, REGISTER, UNREGISTER, DISCOMFORT_SAMPLE, ITS_SAMPLE, EXIT = 9
     } APPMenu;
 }
 ;
@@ -47,9 +47,6 @@ typedef enum
 
 class SSMTestApp: public IQueryEngineEvent
 {
-    private:
-        SSMInterface m_SSMClient;
-
     public:
 
         SSMTestApp();
@@ -58,6 +55,8 @@ class SSMTestApp: public IQueryEngineEvent
         void registerQuery(std::string queryString);
         void unregisterQuery();
 
+        void TrajectoryDataOutput(IModelData *pModelData);
+
         /* operations from listener interface */
         SSMRESULT onQueryEngineEvent(int cqid, IDataReader *pResult);
 };
index 50ba8fc..c4ed161 100644 (file)
@@ -38,6 +38,7 @@ void SSMTestApp::displayMenu()
     printf("   1. Register Query \n");
     printf("   2. Unregister Query \n");
     printf("   3. Register DiscomfortIndexSensor sample query \n");
+    printf("   4. Register IndoorTrajectorySensor sample query \n");
     printf("   9. exit \n");
     printf("===============================================\n");
     printf("   Please Enter the NO: ");
@@ -56,7 +57,7 @@ void SSMTestApp::registerQuery(std::string queryString)
         getline(cin, queryString);
     }
 
-    rtn = m_SSMClient.registerQuery(queryString, this, qid);
+    rtn = RegisterQuery(queryString, this, qid);
 
     if (rtn == SSM_S_OK)
     {
@@ -64,7 +65,7 @@ void SSMTestApp::registerQuery(std::string queryString)
         printf("QID : %d\n", qid);
     }
     else
-        printf("Error occured(%d)", rtn);
+        printf("Error occured(%d)\n", rtn);
 }
 
 /* unRegister Query.*/
@@ -73,11 +74,11 @@ void SSMTestApp::unregisterQuery(void)
     std::string qid;
     SSMRESULT rtn = SSM_E_FAIL;
 
-    printf("   Please Enter query string: ");
+    printf("   Please Enter query Id: ");
     cin.ignore();
     getline(cin, qid);
 
-    rtn = m_SSMClient.unregisterQuery(atoi(qid.c_str()));
+    rtn = UnregisterQuery(atoi(qid.c_str()));
 
     if (rtn == SSM_S_OK)
         printf("The query has been unregistered!\n");
@@ -85,6 +86,89 @@ void SSMTestApp::unregisterQuery(void)
         printf("Error occured(%d)\n", (int) rtn);
 }
 
+
+#define INPUT_EA        9
+char input_name[INPUT_EA][10] = { "trackeeID", "timeT0", "ref01T0", "ref02T0", "ref03T0", "timeT1", "ref01T1", "ref02T1", "ref03T1" };
+
+void SSMTestApp::TrajectoryDataOutput(IModelData *pModelData)
+{
+    std::string name = "";
+    int l = 0;
+
+    std::string trackeeID;
+    std::string T0DateTime;
+    std::string T0Ref01;
+    std::string T0Ref02;
+    std::string T0Ref03;
+    std::string T1DateTime;
+    std::string T1Ref01;
+    std::string T1Ref02;
+    std::string T1Ref03;
+
+    for (int j = 0; j < pModelData->getPropertyCount(); j++)
+    {
+        name = pModelData->getPropertyName(j);
+
+        for (l = 0; l < INPUT_EA; l++)
+        {
+            if (name.compare(input_name[l]) == 0)
+                break;
+        }
+
+        switch (l)
+        {
+            case 0:
+                trackeeID = pModelData->getPropertyValue(j);
+                break;
+            case 1:
+                T0DateTime = pModelData->getPropertyValue(j);
+                break;
+            case 2:
+                T0Ref01 = pModelData->getPropertyValue(j);
+                break;
+            case 3:
+                T0Ref02 = pModelData->getPropertyValue(j);
+                break;
+            case 4:
+                T0Ref03 = pModelData->getPropertyValue(j);
+                break;
+            case 5:
+                T1DateTime = pModelData->getPropertyValue(j);
+                break;
+            case 6:
+                T1Ref01 = pModelData->getPropertyValue(j);
+                break;
+            case 7:
+                T1Ref02 = pModelData->getPropertyValue(j);
+                break;
+            case 8:
+                T1Ref03 = pModelData->getPropertyValue(j);
+                break;
+            default:
+                ;
+        }
+    }
+
+    printf("===========================================\n");
+    printf("        ITS Trajectory Data Output         \n");
+    printf("===========================================\n");
+    printf("\n");
+    printf(" < Trackee Thing ID : %s > \n", trackeeID.c_str());
+    printf("   - Trajectory 01         \n");
+    printf("     0. Date, Time : %s    \n", T0DateTime.c_str());
+    printf("     1. Ref. Thing : %s    \n", T0Ref01.c_str());
+    printf("     2. Ref. Thing : %s    \n", T0Ref02.c_str());
+    printf("     3. Ref. Thing : %s    \n", T0Ref03.c_str());
+    printf("\n");
+    printf("   - Trajectory 02         \n");
+    printf("     0. Date, Time : %s    \n", T1DateTime.c_str());
+    printf("     1. Ref. Thing : %s    \n", T1Ref01.c_str());
+    printf("     2. Ref. Thing : %s    \n", T1Ref02.c_str());
+    printf("     3. Ref. Thing : %s    \n", T1Ref03.c_str());
+    printf("\n");
+    printf("===========================================\n");
+}
+
 /* APP. Level Callback Function for Observer of client. */
 SSMRESULT SSMTestApp::onQueryEngineEvent(int cqid, IDataReader *pResult)
 {
@@ -110,6 +194,8 @@ SSMRESULT SSMTestApp::onQueryEngineEvent(int cqid, IDataReader *pResult)
                 cout << "Type: " << pModelData->getPropertyName(j) << " Value: " << pModelData->getPropertyValue(
                          j) << endl;
             }
+
+            //TrajectoryDataOutput(pModelData);
         }
     }
 
@@ -126,6 +212,17 @@ int main()
     SSMTestApp *SSMApp = new SSMTestApp();
     APPMenu::APPMenu menu = APPMenu::NONE;
 
+    std::string xmlDescription = "<SSMCore>"
+                                 "<Device>"
+                                 "<UDN>abcde123-31f8-11b4-a222-08002b34c003</UDN>"
+                                 "<Name>MyPC</Name>"
+                                 "<Type>PC</Type>"
+                                 "</Device>"
+                                 "</SSMCore>";
+
+    if (InitializeSSM(xmlDescription) != SSM_S_OK)
+        std::cout << "core init failed" << std::endl;
+
     while (menu != APPMenu::EXIT)
     {
         SSMApp->displayMenu();
@@ -151,6 +248,11 @@ int main()
                                       "if Device.DiscomfortIndexSensor.discomfortIndex > 0");
                 break;
 
+            case APPMenu::ITS_SAMPLE:
+                SSMApp->registerQuery("subscribe Device.IndoorTrajectorySensor "\
+                                      "if Device.IndoorTrajectorySensor.trackeeID == \"9059AF16FEF7\"");
+                break;
+
             case APPMenu::EXIT:
                 std::cout << "program exit." << std::endl;
                 break;
@@ -160,6 +262,8 @@ int main()
         }
     } // while
 
+    TerminateSSM();
+
     delete SSMApp;
 }
 
index 826ef69..3fb4288 100644 (file)
@@ -67,7 +67,6 @@ class CQueryEngineEvent : public IQueryEngineEvent
 };
 
 CQueryEngineEvent   *g_SSMClientListener = new CQueryEngineEvent();
-SSMInterface        *g_SSMClient = new SSMInterface();
 
 static Elm_Object_Item *oicapp_append_separator(Evas_Object *genlist,
         oicapp_data *ad)
@@ -290,7 +289,7 @@ static void _btn_clicked(void *data, Evas_Object *obj, void *event_info)
         str.replace(foundLT, strLT.length(), "<");
     }
 
-    g_SSMClient->registerQuery(str, g_SSMClientListener, g_CQID);
+    RegisterQuery(str, g_SSMClientListener, g_CQID);
 
     sstream << "Query executed! cqid = " << g_CQID << std::ends;
 
@@ -429,7 +428,7 @@ static int oicapp_terminate(void *data)
     oicapp_data *ad = (oicapp_data *)data;
 
     if (g_CQID != 9999)
-        g_SSMClient->unregisterQuery(g_CQID);
+        UnregisterQuery(g_CQID);
 
     if (ad->win)
         evas_object_del(ad->win);