#include <stdexcept>
#include <utility>
#include "InternalTypes.h"
+#include <string.h>
#define CONTAINER_TAG "RESOURCE_CONTAINER"
#define DISCOVER_TAG "DISCOVER_RESOURCE_UNIT"
try
{
- OC_LOG_V(INFO, CONTAINER_TAG, "isHasInput: (%d) %s",m_mapisHasInput.at(bundleId), bundleId.c_str() );
+ OIC_LOG_V(INFO, CONTAINER_TAG, "isHasInput: (%d) %s",m_mapisHasInput.at(bundleId), bundleId.c_str() );
return m_mapisHasInput.at(bundleId);
}
catch (std::out_of_range &e)
{
- OC_LOG_V(INFO, CONTAINER_TAG, "isHasInput out of range %s.", bundleId.c_str());
+ OIC_LOG_V(INFO, CONTAINER_TAG, "isHasInput out of range %s.", bundleId.c_str());
return false;
}
}
void Configuration::getConfiguredBundles(configInfo *configOutput)
{
- rapidxml::xml_node< char > *bundle;
- rapidxml::xml_node< char > *subItem;
+ rapidxml::xml_node< char > *bundle = nullptr;
+ rapidxml::xml_node< char > *subItem = nullptr;
string strKey, strValue;
{
try
{
- for (bundle = m_xmlDoc.first_node()->first_node(BUNDLE_TAG); bundle; bundle =
- bundle->next_sibling())
+ bundle = m_xmlDoc.first_node();
+ if (bundle)
{
- std::map< std::string, std::string > bundleMap;
- for (subItem = bundle->first_node(); subItem;
- subItem = subItem->next_sibling())
+ for (bundle = bundle->first_node(BUNDLE_TAG); bundle; bundle =
+ bundle->next_sibling())
{
- strKey = subItem->name();
- strValue = subItem->value();
-
- if (strlen(subItem->value()) > 0)
+ std::map< std::string, std::string > bundleMap;
+ for (subItem = bundle->first_node(); subItem;
+ subItem = subItem->next_sibling())
{
- bundleMap.insert(
- std::make_pair(trim_both(strKey), trim_both(strValue)));
+ strKey = subItem->name();
+ strValue = subItem->value();
+
+ if (strlen(subItem->value()) > 0)
+ {
+ bundleMap.insert(
+ std::make_pair(trim_both(strKey), trim_both(strValue)));
+ }
}
+ configOutput->push_back(bundleMap);
}
- configOutput->push_back(bundleMap);
}
}
catch (rapidxml::parse_error &e)
{
- OC_LOG(ERROR, CONTAINER_TAG, "xml parsing failed !!");
- OC_LOG_V(ERROR, CONTAINER_TAG, "Exception : (%s)", e.what());
+ OIC_LOG(ERROR, CONTAINER_TAG, "xml parsing failed !!");
+ OIC_LOG_V(ERROR, CONTAINER_TAG, "Exception : (%s)", e.what());
}
}
}
void Configuration::getBundleConfiguration(string bundleId, configInfo *configOutput)
{
- rapidxml::xml_node< char > *bundle;
+ rapidxml::xml_node< char > *bundle = nullptr;
string strBundleId, strPath, strVersion;
std::map< std::string, std::string > bundleConfigMap;
// <bundle>
- for (bundle = m_xmlDoc.first_node()->first_node(BUNDLE_TAG); bundle; bundle =
- bundle->next_sibling())
+ bundle = m_xmlDoc.first_node();
+ if (bundle)
{
- // <id>
- strBundleId = bundle->first_node(BUNDLE_ID)->value();
-
- if (!strBundleId.compare(bundleId))
+ for (bundle = bundle->first_node(BUNDLE_TAG); bundle; bundle =
+ bundle->next_sibling())
{
- bundleConfigMap.insert(std::make_pair(BUNDLE_ID, trim_both(strBundleId)));
+ // <id>
+ if (bundle->first_node(BUNDLE_ID))
+ {
+ strBundleId = bundle->first_node(BUNDLE_ID)->value();
+ }
+ else
+ {
+ strBundleId = "";
+ }
+
+ if (!strBundleId.compare(bundleId))
+ {
+ bundleConfigMap.insert(std::make_pair(BUNDLE_ID, trim_both(strBundleId)));
- // <path>
- strPath = bundle->first_node(BUNDLE_PATH)->value();
- bundleConfigMap.insert(std::make_pair(BUNDLE_PATH, trim_both(strPath)));
+ // <path>
+ if (bundle->first_node(BUNDLE_PATH))
+ {
+ strPath = bundle->first_node(BUNDLE_PATH)->value();
+ }
+ else
+ {
+ strPath = "";
+ }
+ bundleConfigMap.insert(std::make_pair(BUNDLE_PATH, trim_both(strPath)));
- // <version>
- strVersion = bundle->first_node(BUNDLE_VERSION)->value();
- bundleConfigMap.insert(
- std::make_pair(BUNDLE_VERSION, trim_both(strVersion)));
+ // <version>
+ if (bundle->first_node(BUNDLE_VERSION))
+ {
+ strVersion = bundle->first_node(BUNDLE_VERSION)->value();
+ }
+ else
+ {
+ strVersion = "";
+ }
+ bundleConfigMap.insert(
+ std::make_pair(BUNDLE_VERSION, trim_both(strVersion)));
- configOutput->push_back(bundleConfigMap);
+ configOutput->push_back(bundleConfigMap);
- break;
+ break;
+ }
}
}
}
catch (rapidxml::parse_error &e)
{
- OC_LOG(ERROR, CONTAINER_TAG, "xml parsing failed !!");
- OC_LOG_V(ERROR, CONTAINER_TAG, "Exception (%s)", e.what());
+ OIC_LOG(ERROR, CONTAINER_TAG, "xml parsing failed !!");
+ OIC_LOG_V(ERROR, CONTAINER_TAG, "Exception (%s)", e.what());
}
}
}
- void Configuration::getResourceConfiguration(std::string bundleId, std::string resourceName,
- resourceInfo *resourceInfoOut){
- rapidxml::xml_node< char > *bundle;
- rapidxml::xml_node< char > *resource;
- rapidxml::xml_node< char > *item, *subItem, *subItem2;
+ void Configuration::getResourceConfiguration(std::string bundleId, std::string resourceUri,
+ resourceInfo *resourceInfoOut)
+ {
+ rapidxml::xml_node< char > *bundle = nullptr;
+ rapidxml::xml_node< char > *resource = nullptr;
+ rapidxml::xml_node< char > *item = nullptr;
+ rapidxml::xml_node< char > *subItem = nullptr;
+ rapidxml::xml_node< char > *subItem2 = nullptr;
string strBundleId;
string strKey, strValue;
- OC_LOG_V(INFO, CONTAINER_TAG, "Loading resource configuration for %s %s!", bundleId.c_str(), resourceName.c_str());
+ OIC_LOG_V(INFO, CONTAINER_TAG, "Loading resource configuration for %s %s!",
+ bundleId.c_str(), resourceUri.c_str());
if (m_loaded)
{
try
{
// <bundle>
- for (bundle = m_xmlDoc.first_node()->first_node(BUNDLE_TAG); bundle; bundle =
- bundle->next_sibling())
+ bundle = m_xmlDoc.first_node();
+ if (bundle)
{
- // <id>
- strBundleId = bundle->first_node(BUNDLE_ID)->value();
+ for (bundle = bundle->first_node(BUNDLE_TAG); bundle;
+ bundle = bundle->next_sibling())
+ {
+ // <id>
+ strBundleId = bundle->first_node(BUNDLE_ID)->value();
- OC_LOG_V(INFO, CONTAINER_TAG, "Comparing bundle id %s - %s !", strBundleId.c_str(), bundleId.c_str());
+ OIC_LOG_V(INFO, CONTAINER_TAG, "Comparing bundle id %s - %s !",
+ strBundleId.c_str(), bundleId.c_str());
- if (!strBundleId.compare(bundleId))
- {
- OC_LOG_V(INFO, CONTAINER_TAG, "Inspecting");
- // <resourceInfo>
- for (resource = bundle->first_node(OUTPUT_RESOURCES_TAG)->first_node(OUTPUT_RESOURCE_INFO);
- resource; resource = resource->next_sibling())
+ if (!strBundleId.compare(bundleId))
{
-
- for (item = resource->first_node(); item; item =
- item->next_sibling())
+ OIC_LOG_V(INFO, CONTAINER_TAG, "Inspecting");
+ // <resourceInfo>
+ bundle = bundle->first_node(OUTPUT_RESOURCES_TAG);
+ if (bundle)
{
- strKey = item->name();
- strValue = item->value();
-
- if (!strKey.compare(OUTPUT_RESOURCE_NAME))
- resourceInfoOut->name = trim_both(strValue);
-
- else if (!strKey.compare(OUTPUT_RESOURCE_URI))
- resourceInfoOut->uri = trim_both(strValue);
-
- else if (!strKey.compare(OUTPUT_RESOURCE_ADDR))
- resourceInfoOut->address = trim_both(strValue);
-
- else if (!strKey.compare(OUTPUT_RESOURCE_TYPE))
- resourceInfoOut->resourceType = trim_both(strValue);
-
- else
+ for (resource = bundle->first_node(OUTPUT_RESOURCE_INFO);
+ resource; resource = resource->next_sibling())
{
- for (subItem = item->first_node(); subItem; subItem =
- subItem->next_sibling())
+
+ for (item = resource->first_node(); item; item =
+ item->next_sibling())
{
- map< string, string > propertyMap;
+ strKey = item->name();
+ strValue = item->value();
- strKey = subItem->name();
+ if (!strKey.compare(OUTPUT_RESOURCE_NAME))
+ {
+
+ resourceInfoOut->name = trim_both(strValue);
+ }
- if (strKey.compare(INPUT_RESOURCE))
+ else if (!strKey.compare(OUTPUT_RESOURCE_URI))
{
- m_mapisHasInput[strBundleId] = true;
- OC_LOG_V(INFO, CONTAINER_TAG, "Bundle has input (%s)", strBundleId.c_str());
+ if (trim_both(strValue).compare(resourceUri) != 0)
+ {
+ break;
+ }
+ resourceInfoOut->uri = trim_both(strValue);
}
- for (subItem2 = subItem->first_node(); subItem2;
- subItem2 = subItem2->next_sibling())
+ else if (!strKey.compare(OUTPUT_RESOURCE_ADDR))
{
- string newStrKey = subItem2->name();
- string newStrValue = subItem2->value();
- OC_LOG_V(INFO, CONTAINER_TAG, "key: %s, value %s", newStrKey.c_str(), newStrValue.c_str());
+ resourceInfoOut->address = trim_both(strValue);
+ }
- propertyMap[trim_both(newStrKey)] = trim_both(
- newStrValue);
+ else if (!strKey.compare(OUTPUT_RESOURCE_TYPE))
+ {
+ resourceInfoOut->resourceType = trim_both(strValue);
}
- resourceInfoOut->resourceProperty[trim_both(strKey)].push_back(
- propertyMap);
+ else
+ {
+ for (subItem = item->first_node(); subItem; subItem =
+ subItem->next_sibling())
+ {
+ map< string, string > propertyMap;
+
+ strKey = subItem->name();
+
+ if (strKey.compare(INPUT_RESOURCE))
+ {
+ m_mapisHasInput[strBundleId] = true;
+ OIC_LOG_V(INFO, CONTAINER_TAG,
+ "Bundle has input (%s)",
+ strBundleId.c_str());
+ }
+
+ for (subItem2 = subItem->first_node(); subItem2;
+ subItem2 = subItem2->next_sibling())
+ {
+ string newStrKey = subItem2->name();
+ string newStrValue = subItem2->value();
+ OIC_LOG_V(INFO, CONTAINER_TAG,
+ "key: %s, value %s",
+ newStrKey.c_str(), newStrValue.c_str());
+
+ propertyMap[trim_both(newStrKey)] =
+ trim_both(newStrValue);
+ }
+
+ resourceInfoOut->resourceProperty[trim_both(strKey)].push_back(
+ propertyMap);
+ }
+ }
}
+
}
}
-
}
}
}
}
catch (rapidxml::parse_error &e)
{
- OC_LOG(ERROR, CONTAINER_TAG, "xml parsing failed !!");
- OC_LOG_V(ERROR, CONTAINER_TAG, "Exception (%s)", e.what());
+ OIC_LOG(ERROR, CONTAINER_TAG, "xml parsing failed !!");
+ OIC_LOG_V(ERROR, CONTAINER_TAG, "Exception (%s)", e.what());
}
}
- else{
- OC_LOG(INFO, CONTAINER_TAG, "config is not loaded yet !!");
+ else
+ {
+ OIC_LOG(INFO, CONTAINER_TAG, "config is not loaded yet !!");
}
}
void Configuration::getResourceConfiguration(std::string bundleId,
std::vector< resourceInfo > *configOutput)
{
- rapidxml::xml_node< char > *bundle;
- rapidxml::xml_node< char > *resource;
- rapidxml::xml_node< char > *item, *subItem, *subItem2;
+ rapidxml::xml_node< char > *bundle = nullptr;
+ rapidxml::xml_node< char > *resource = nullptr;
+ rapidxml::xml_node< char > *item = nullptr;
+ rapidxml::xml_node< char > *subItem = nullptr;
+ rapidxml::xml_node< char > *subItem2 = nullptr;
string strBundleId;
string strKey, strValue;
- OC_LOG(INFO, CONTAINER_TAG, "Loading resource configuration!");
+ OIC_LOG(INFO, CONTAINER_TAG, "Loading resource configuration!");
if (m_loaded)
{
try
{
// <bundle>
- for (bundle = m_xmlDoc.first_node()->first_node(BUNDLE_TAG); bundle; bundle =
- bundle->next_sibling())
+ bundle = m_xmlDoc.first_node();
+ if (bundle)
{
- // <id>
- strBundleId = bundle->first_node(BUNDLE_ID)->value();
-
- OC_LOG_V(INFO, CONTAINER_TAG, "Comparing bundle ids %s - %s !", strBundleId.c_str(), bundleId.c_str());
-
- if (!strBundleId.compare(bundleId))
+ for (bundle = bundle->first_node(BUNDLE_TAG); bundle; bundle =
+ bundle->next_sibling())
{
- OC_LOG_V(INFO, CONTAINER_TAG, "Inspecting");
- // <resourceInfo>
- for (resource = bundle->first_node(OUTPUT_RESOURCES_TAG)->first_node(OUTPUT_RESOURCE_INFO);
- resource; resource = resource->next_sibling())
+ // <id>
+ if (bundle->first_node(BUNDLE_ID))
{
- resourceInfo tempResourceInfo;
-
- for (item = resource->first_node(); item; item =
- item->next_sibling())
- {
- strKey = item->name();
- strValue = item->value();
-
- if (!strKey.compare(OUTPUT_RESOURCE_NAME))
- tempResourceInfo.name = trim_both(strValue);
-
- else if (!strKey.compare(OUTPUT_RESOURCE_URI))
- tempResourceInfo.uri = trim_both(strValue);
-
- else if (!strKey.compare(OUTPUT_RESOURCE_ADDR))
- tempResourceInfo.address = trim_both(strValue);
+ strBundleId = bundle->first_node(BUNDLE_ID)->value();
+ }
- else if (!strKey.compare(OUTPUT_RESOURCE_TYPE))
- tempResourceInfo.resourceType = trim_both(strValue);
+ OIC_LOG_V(INFO, CONTAINER_TAG, "Comparing bundle ids %s - %s !",
+ strBundleId.c_str(), bundleId.c_str());
- else
+ if (!strBundleId.compare(bundleId))
+ {
+ OIC_LOG_V(INFO, CONTAINER_TAG, "Inspecting");
+ // <resourceInfo>
+ bundle = bundle->first_node(OUTPUT_RESOURCES_TAG);
+ if (bundle)
+ {
+ for (resource = bundle->
+ first_node(OUTPUT_RESOURCE_INFO);
+ resource; resource = resource->next_sibling())
{
- for (subItem = item->first_node(); subItem; subItem =
- subItem->next_sibling())
+ resourceInfo tempResourceInfo;
+
+ for (item = resource->first_node(); item; item =
+ item->next_sibling())
{
- map< string, string > propertyMap;
+ strKey = item->name();
+ strValue = item->value();
- strKey = subItem->name();
+ if (!strKey.compare(OUTPUT_RESOURCE_NAME))
+ {
+ tempResourceInfo.name = trim_both(strValue);
+ }
- if (strKey.compare(INPUT_RESOURCE))
+ else if (!strKey.compare(OUTPUT_RESOURCE_URI))
{
- m_mapisHasInput[strBundleId] = true;
- OC_LOG_V(INFO, CONTAINER_TAG, "Bundle has input (%s)", strBundleId.c_str());
+ tempResourceInfo.uri = trim_both(strValue);
}
- for (subItem2 = subItem->first_node(); subItem2;
- subItem2 = subItem2->next_sibling())
+ else if (!strKey.compare(OUTPUT_RESOURCE_ADDR))
{
- string newStrKey = subItem2->name();
- string newStrValue = subItem2->value();
- OC_LOG_V(INFO, CONTAINER_TAG, "key: %s, value %s", newStrKey.c_str(), newStrValue.c_str());
+ tempResourceInfo.address = trim_both(strValue);
+ }
- propertyMap[trim_both(newStrKey)] = trim_both(
- newStrValue);
+ else if (!strKey.compare(OUTPUT_RESOURCE_TYPE))
+ {
+ tempResourceInfo.resourceType = trim_both(strValue);
}
- tempResourceInfo.resourceProperty[trim_both(strKey)].push_back(
- propertyMap);
+ else
+ {
+ for (subItem = item->first_node(); subItem; subItem =
+ subItem->next_sibling())
+ {
+ map< string, string > propertyMap;
+
+ strKey = subItem->name();
+
+ if (strKey.compare(INPUT_RESOURCE))
+ {
+ m_mapisHasInput[strBundleId] = true;
+ OIC_LOG_V(INFO, CONTAINER_TAG,
+ "Bundle has input (%s)",
+ strBundleId.c_str());
+ }
+
+ for (subItem2 = subItem->first_node(); subItem2;
+ subItem2 = subItem2->next_sibling())
+ {
+ string newStrKey = subItem2->name();
+ string newStrValue = subItem2->value();
+ OIC_LOG_V(INFO, CONTAINER_TAG,
+ "key: %s, value %s",
+ newStrKey.c_str(),
+ newStrValue.c_str());
+
+ propertyMap[trim_both(newStrKey)] =
+ trim_both(newStrValue);
+ }
+
+ tempResourceInfo.resourceProperty[trim_both(strKey)].
+ push_back(propertyMap);
+ }
+ }
}
+ configOutput->push_back(tempResourceInfo);
}
}
- configOutput->push_back(tempResourceInfo);
}
}
}
}
catch (rapidxml::parse_error &e)
{
- OC_LOG(ERROR, CONTAINER_TAG, "xml parsing failed !!");
- OC_LOG_V(ERROR, CONTAINER_TAG, "Exception (%s)", e.what());
+ OIC_LOG(ERROR, CONTAINER_TAG, "xml parsing failed !!");
+ OIC_LOG_V(ERROR, CONTAINER_TAG, "Exception (%s)", e.what());
}
}
- else{
- OC_LOG(INFO, CONTAINER_TAG, "config is not loaded yet !!");
+ else
+ {
+ OIC_LOG(INFO, CONTAINER_TAG, "config is not loaded yet !!");
}
}
}
catch (rapidxml::parse_error &e)
{
- OC_LOG(ERROR, CONTAINER_TAG, "xml parsing failed !!");
- OC_LOG_V(ERROR, CONTAINER_TAG, "Exception (%s)", e.what());
+ OIC_LOG(ERROR, CONTAINER_TAG, "xml parsing failed !!");
+ OIC_LOG_V(ERROR, CONTAINER_TAG, "Exception (%s)", e.what());
}
}
else
{
- OC_LOG(ERROR, CONTAINER_TAG, "Configuration File load failed !!");
+ OIC_LOG(ERROR, CONTAINER_TAG, "Configuration File load failed !!");
}
}
}