*
******************************************************************/
#include "ContextRepository.h"
+#include "rapidxml/rapidxml.hpp"
static inline std::string trim_both(const std::string &str)
{
return res;
}
-SSMRESULT CContextRepository::registerResourceFinderEvent(IN IResourceEvent *pResourceEvent)
+SSMRESULT CContextRepository::stopResourceFinder()
+{
+ SSMRESULT res = SSM_E_FAIL;
+
+ SSM_CLEANUP_ASSERT(m_resourceFinder->stopResourceFinder());
+
+CLEANUP:
+ return res;
+}
+
+SSMRESULT CContextRepository::registerResourceFinderEvent(IResourceEvent *pResourceEvent)
{
m_resourceEvents.push_back(pResourceEvent);
return SSM_S_OK;
{
}
-SSMRESULT CContextRepository::initRepository(IN std::string name, IN std::string type,
- IN std::string pathSoftSensors, IN std::string pathDescription)
+SSMRESULT CContextRepository::initRepository(std::string name, std::string type,
+ std::string pathSoftSensors, std::string pathDescription)
{
SSMRESULT res = SSM_E_FAIL;
if (pathSoftSensors.length() == 0)
{
- SSM_CLEANUP_ASSERT(GetCurrentPath(&m_pathSoftSensors));
+ SSM_CLEANUP_ASSERT(getCurrentPath(&m_pathSoftSensors));
m_pathSoftSensors.append("/");
}
else
if (pathDescription.length() == 0)
{
- SSM_CLEANUP_ASSERT(GetCurrentPath(&m_pathSoftSensorsDescription));
+ SSM_CLEANUP_ASSERT(getCurrentPath(&m_pathSoftSensorsDescription));
m_pathSoftSensorsDescription.append("/");
m_pathSoftSensorsDescription.append(DEFAULT_PATH_SOFT_SENSORS);
}
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;
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;
return res;
}
-SSMRESULT CContextRepository::getSoftSensorList(OUT std::vector<ISSMResource *> *pSoftSensorList)
+SSMRESULT CContextRepository::getSoftSensorList(std::vector<ISSMResource *> *pSoftSensorList)
{
for (size_t i = 0; i < m_lstSoftSensor.size(); i++)
{
return SSM_S_OK;
}
-SSMRESULT CContextRepository::getPrimitiveSensorList(OUT std::vector<ISSMResource *>
+SSMRESULT CContextRepository::getPrimitiveSensorList(std::vector<ISSMResource *>
*pPrimitiveSensorList)
{
for (size_t i = 0; i < m_lstPrimitiveSensor.size(); i++)
return SSM_S_OK;
}
-SSMRESULT CContextRepository::onResourceFound(IN ISSMResource *pSensor)
+SSMRESULT CContextRepository::onResourceFound(ISSMResource *pSensor)
{
m_lstPrimitiveSensor.push_back(pSensor);
return SSM_S_OK;
}
-SSMRESULT CContextRepository::onResourceLost(IN ISSMResource *pSensor)
+SSMRESULT CContextRepository::onResourceLost(ISSMResource *pSensor)
{
std::vector<ISSMResource *>::iterator itor;
itor = std::find(m_lstPrimitiveSensor.begin(), m_lstPrimitiveSensor.end(), pSensor);
return SSM_E_FAIL;
}
-SSMRESULT CContextRepository::startObserveResource(IN ISSMResource *pSensor, IN IEvent *pEvent)
+SSMRESULT CContextRepository::startObserveResource(ISSMResource *pSensor, IEvent *pEvent)
{
return m_resourceFinder->startObserveResource(pSensor, pEvent);
}
-SSMRESULT CContextRepository::stopObserveResource(IN ISSMResource *pSensor)
+SSMRESULT CContextRepository::stopObserveResource(ISSMResource *pSensor)
{
return m_resourceFinder->stopObserveResource(pSensor);
}
std::stringstream sstream;
SSMRESULT res = SSM_E_FAIL;
- typedef void(*InitContext)(IN ICtxDelegate *);
+ typedef void(*InitContext)(ICtxDelegate *);
InitContext InitializeContextFunction = NULL;
// load dll(so)
return res;
}
-SSMRESULT CContextRepository::GetCurrentPath(std::string *path)
+SSMRESULT CContextRepository::getCurrentPath(std::string *path)
{
char buffer[2048];
SSMRESULT res = SSM_E_FAIL;
CLEANUP:
return res;
-}
\ No newline at end of file
+}