#include <stdexcept>
#include <utility>
#include "InternalTypes.h"
+#include <string.h>
#define CONTAINER_TAG "RESOURCE_CONTAINER"
+#define DISCOVER_TAG "DISCOVER_RESOURCE_UNIT"
namespace OIC
{
bool Configuration::isHasInput(std::string &bundleId) const
{
+
try
{
+ 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)
{
+ 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);
}
}
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 = "";
+ }
- // <path>
- strPath = bundle->first_node(BUNDLE_PATH)->value();
- bundleConfigMap.insert(std::make_pair(BUNDLE_PATH, trim_both(strPath)));
+ if (!strBundleId.compare(bundleId))
+ {
+ bundleConfigMap.insert(std::make_pair(BUNDLE_ID, trim_both(strBundleId)));
- // <version>
- strVersion = bundle->first_node(BUNDLE_VERSION)->value();
- bundleConfigMap.insert(
- std::make_pair(BUNDLE_VERSION, trim_both(strVersion)));
+ // <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)));
- configOutput->push_back(bundleConfigMap);
+ // <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);
- break;
+ break;
+ }
}
}
}
}
}
- void Configuration::getResourceConfiguration(std::string bundleId,
- std::vector< resourceInfo > *configOutput)
+ void Configuration::getResourceConfiguration(std::string bundleId, std::string resourceUri,
+ resourceInfo *resourceInfoOut)
{
- 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;
+ 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();
-
- if (!strBundleId.compare(bundleId))
+ for (bundle = bundle->first_node(BUNDLE_TAG); bundle;
+ bundle = bundle->next_sibling())
{
- // <resourceInfo>
- for (resource = bundle->first_node(OUTPUT_RESOURCES_TAG)->first_node(OUTPUT_RESOURCE_INFO);
- resource; resource = resource->next_sibling())
- {
- resourceInfo tempResourceInfo;
+ // <id>
+ strBundleId = bundle->first_node(BUNDLE_ID)->value();
+
+ OIC_LOG_V(INFO, CONTAINER_TAG, "Comparing bundle id %s - %s !",
+ strBundleId.c_str(), bundleId.c_str());
- for (item = resource->first_node(); item; item =
- item->next_sibling())
+ if (!strBundleId.compare(bundleId))
+ {
+ OIC_LOG_V(INFO, CONTAINER_TAG, "Inspecting");
+ // <resourceInfo>
+ bundle = bundle->first_node(OUTPUT_RESOURCES_TAG);
+ if (bundle)
{
- strKey = item->name();
- strValue = item->value();
+ for (resource = bundle->first_node(OUTPUT_RESOURCE_INFO);
+ resource; resource = resource->next_sibling())
+ {
- if (!strKey.compare(OUTPUT_RESOURCE_NAME))
- tempResourceInfo.name = trim_both(strValue);
+ for (item = resource->first_node(); item; item =
+ item->next_sibling())
+ {
+ strKey = item->name();
+ 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_URI))
- tempResourceInfo.uri = trim_both(strValue);
+ else if (!strKey.compare(OUTPUT_RESOURCE_ADDR))
+ {
+ resourceInfoOut->address = trim_both(strValue);
+ }
- else if (!strKey.compare(OUTPUT_RESOURCE_ADDR))
- tempResourceInfo.address = trim_both(strValue);
+ else if (!strKey.compare(OUTPUT_RESOURCE_TYPE))
+ {
+ resourceInfoOut->resourceType = trim_both(strValue);
+ }
- else if (!strKey.compare(OUTPUT_RESOURCE_TYPE))
- tempResourceInfo.resourceType = trim_both(strValue);
+ 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);
+ }
+ }
+ }
- else
+ }
+ }
+ }
+ }
+ }
+ }
+ catch (rapidxml::parse_error &e)
+ {
+ OIC_LOG(ERROR, CONTAINER_TAG, "xml parsing failed !!");
+ OIC_LOG_V(ERROR, CONTAINER_TAG, "Exception (%s)", e.what());
+ }
+ }
+ 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 = 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(INFO, CONTAINER_TAG, "Loading resource configuration!");
+
+ if (m_loaded)
+ {
+ try
+ {
+ // <bundle>
+ bundle = m_xmlDoc.first_node();
+ if (bundle)
+ {
+ for (bundle = bundle->first_node(BUNDLE_TAG); bundle; bundle =
+ bundle->next_sibling())
+ {
+ // <id>
+ 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());
+
+ 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;
+ 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();
+ 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);
}
}
}
OIC_LOG_V(ERROR, CONTAINER_TAG, "Exception (%s)", e.what());
}
}
+ else
+ {
+ OIC_LOG(INFO, CONTAINER_TAG, "config is not loaded yet !!");
+ }
}
void Configuration::getConfigDocument(std::string pathConfigFile)