#include <stdexcept>
#include <utility>
#include "InternalTypes.h"
+#include <string.h>
#define CONTAINER_TAG "RESOURCE_CONTAINER"
#define DISCOVER_TAG "DISCOVER_RESOURCE_UNIT"
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
{
- if (m_xmlDoc.first_node())
+ bundle = m_xmlDoc.first_node();
+ if (bundle)
{
- for (bundle = m_xmlDoc.first_node()->first_node(BUNDLE_TAG); bundle; bundle =
+ for (bundle = bundle->first_node(BUNDLE_TAG); bundle; bundle =
bundle->next_sibling())
{
std::map< std::string, std::string > bundleMap;
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>
- if (m_xmlDoc.first_node())
+ bundle = m_xmlDoc.first_node();
+ if (bundle)
{
- for (bundle = m_xmlDoc.first_node()->first_node(BUNDLE_TAG); bundle; bundle =
+ for (bundle = bundle->first_node(BUNDLE_TAG); bundle; bundle =
bundle->next_sibling())
{
// <id>
{
strBundleId = bundle->first_node(BUNDLE_ID)->value();
}
- else{
+ else
+ {
strBundleId = "";
}
bundleConfigMap.insert(std::make_pair(BUNDLE_ID, trim_both(strBundleId)));
// <path>
- if (bundle->first_node(BUNDLE_PATH)){
+ if (bundle->first_node(BUNDLE_PATH))
+ {
strPath = bundle->first_node(BUNDLE_PATH)->value();
}
- else{
+ else
+ {
strPath = "";
}
bundleConfigMap.insert(std::make_pair(BUNDLE_PATH, trim_both(strPath)));
// <version>
- if (bundle->first_node(BUNDLE_VERSION)){
+ if (bundle->first_node(BUNDLE_VERSION))
+ {
strVersion = bundle->first_node(BUNDLE_VERSION)->value();
}
- else{
+ else
+ {
strVersion = "";
}
bundleConfigMap.insert(
}
}
- 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;
OIC_LOG_V(INFO, CONTAINER_TAG, "Loading resource configuration for %s %s!",
- bundleId.c_str(), resourceName.c_str());
+ bundleId.c_str(), resourceUri.c_str());
if (m_loaded)
{
try
{
// <bundle>
- if (m_xmlDoc.first_node())
+ bundle = m_xmlDoc.first_node();
+ if (bundle)
{
- for (bundle = m_xmlDoc.first_node()->first_node(BUNDLE_TAG); bundle; bundle =
- bundle->next_sibling())
+ for (bundle = bundle->first_node(BUNDLE_TAG); bundle;
+ bundle = bundle->next_sibling())
{
// <id>
strBundleId = bundle->first_node(BUNDLE_ID)->value();
{
OIC_LOG_V(INFO, CONTAINER_TAG, "Inspecting");
// <resourceInfo>
- if (bundle->first_node(OUTPUT_RESOURCES_TAG)){
- for (resource = bundle->first_node(OUTPUT_RESOURCES_TAG)->
- first_node(OUTPUT_RESOURCE_INFO);
+ bundle = bundle->first_node(OUTPUT_RESOURCES_TAG);
+ if (bundle)
+ {
+ for (resource = bundle->first_node(OUTPUT_RESOURCE_INFO);
resource; resource = resource->next_sibling())
{
strValue = item->value();
if (!strKey.compare(OUTPUT_RESOURCE_NAME))
+ {
+
resourceInfoOut->name = trim_both(strValue);
+ }
else if (!strKey.compare(OUTPUT_RESOURCE_URI))
+ {
+ if (trim_both(strValue).compare(resourceUri) != 0)
+ {
+ break;
+ }
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
{
OIC_LOG_V(ERROR, CONTAINER_TAG, "Exception (%s)", e.what());
}
}
- else{
+ 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;
try
{
// <bundle>
- if (m_xmlDoc.first_node())
+ bundle = m_xmlDoc.first_node();
+ if (bundle)
{
- for (bundle = m_xmlDoc.first_node()->first_node(BUNDLE_TAG); bundle; bundle =
+ for (bundle = bundle->first_node(BUNDLE_TAG); bundle; bundle =
bundle->next_sibling())
{
// <id>
- strBundleId = bundle->first_node(BUNDLE_ID)->value();
+ if (bundle->first_node(BUNDLE_ID))
+ {
+ strBundleId = bundle->first_node(BUNDLE_ID)->value();
+ }
OIC_LOG_V(INFO, CONTAINER_TAG, "Comparing bundle ids %s - %s !",
strBundleId.c_str(), bundleId.c_str());
{
OIC_LOG_V(INFO, CONTAINER_TAG, "Inspecting");
// <resourceInfo>
- if (bundle->first_node(OUTPUT_RESOURCES_TAG))
+ bundle = bundle->first_node(OUTPUT_RESOURCES_TAG);
+ if (bundle)
{
- for (resource = bundle->first_node(OUTPUT_RESOURCES_TAG)->
+ for (resource = bundle->
first_node(OUTPUT_RESOURCE_INFO);
resource; resource = resource->next_sibling())
{
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);
+ }
else if (!strKey.compare(OUTPUT_RESOURCE_TYPE))
+ {
tempResourceInfo.resourceType = trim_both(strValue);
+ }
else
{
OIC_LOG_V(ERROR, CONTAINER_TAG, "Exception (%s)", e.what());
}
}
- else{
+ else
+ {
OIC_LOG(INFO, CONTAINER_TAG, "config is not loaded yet !!");
}
}