+/******************************************************************
+ *
+ * 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.
+ *
+ ******************************************************************/
#include "SSMInterface.h"
#include "SSMInterface/SSMCore.h"
#include "Common/PlatformLayer.h"
{
}
- SSMRESULT onQueryEngineEvent(IN int cqid, IN IDataReader *pResult)
+ SSMRESULT onQueryEngineEvent(int cqid, IDataReader *pResult)
{
SSMRESULT res = SSM_E_FAIL;
m_mtxListener.unlock();
}
- void addListener(IN int cqid, IN IQueryEngineEvent *pEngineEvent)
+ void addListener(int cqid, IQueryEngineEvent *pEngineEvent)
{
m_mapListener[cqid] = pEngineEvent;
}
- void removeListener(IN int cqid)
+ void removeListener(int cqid)
{
m_mapListener.erase(cqid);
}
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 &&
+ res != SSM_E_INITIALIZED)
+ {
+ 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;
CLEANUP:
SAFE_DELETE(g_pEventReceiver);
+ return res;
}
-SSMRESULT SSMInterface::registerQuery(IN std::string queryString, IN IQueryEngineEvent *listener,
- IN int &cqid)
+SSMRESULT OIC::RegisterQuery(std::string queryString, IQueryEngineEvent *listener,
+ 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(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