diff --git a/ndnsd/discovery/file-processor.cpp b/ndnsd/discovery/file-processor.cpp index 9446cfa..b84a317 100644 --- a/ndnsd/discovery/file-processor.cpp +++ b/ndnsd/discovery/file-processor.cpp @@ -28,8 +28,8 @@ NDN_LOG_INIT(ndnsd.FileProcessor); namespace ndnsd { namespace discovery { -ServiceInfoFileProcessor::ServiceInfoFileProcessor(const std::string filename) - : m_filename(filename) +ServiceInfoFileProcessor::ServiceInfoFileProcessor(std::string filename) + : m_filename(std::move(filename)) { processFile(); } @@ -42,48 +42,52 @@ ServiceInfoFileProcessor::processFile() { try { - NDN_LOG_INFO("Reading file: "<< m_filename); - boost::property_tree::ptree pt; - read_info(m_filename, pt); - for (auto& block: pt) - { - if (block.first == "required") - { - for (auto& requiredElement: block.second) - { - const auto& val = requiredElement.second.get_value(); + namespace pt = boost::property_tree; + using ConfigSection = boost::property_tree::ptree; + NDN_LOG_INFO("Reading file: "<< m_filename); + std::ifstream ifstream(m_filename.c_str()); + ConfigSection section; + pt::read_info(m_filename, section); + auto a = section.get_child("service-info-namespace"); - if (requiredElement.first == "serviceName") - { - m_serviceName = val; + ndn::Name root, scope, type, identifier; + for (const auto &item: section.get_child("service-info-namespace")) { + std::string key = item.first; + ndn::Name value = item.second.get_value(); + if (key == "root") { + root = value; + } else if (key == "scope") { + scope = value; + } else if (key == "type") { + type = value; + } else if (key == "identifier") { + identifier = value; } - if (requiredElement.first == "appPrefix") - { - m_applicationPrefix = val; - } - if (requiredElement.first == "lifetime") - { - uint32_t lifetime = std::stoi(val); + } + m_serviceName.append(root).append(scope).append(type).append(identifier); + + for (const auto &item: section.get_child("required-service-detail")) { + std::string key = item.first; + std::string value = item.second.get_value(); + if (key == "name") { + m_applicationPrefix = value; + } else if (key == "lifetime") { + uint32_t lifetime = std::stoi(value); m_serviceLifeTime = ndn::time::seconds(lifetime); } - } } - if (block.first == "details") - { - m_serviceMetaInfo.clear(); - for (auto& details: block.second) - { - const auto& key = details.first; //get_value(); - const auto& val = details.second.get_value(); + if (section.get_child_optional("optional-service-detail")) { + for (const auto &item: section.get_child("optional-service-detail")) { + std::string key = item.first; + std::string value = item.second.get_value(); - NDN_LOG_DEBUG("Key: " << key << "Value: " << val); - - m_serviceMetaInfo.insert(std::pair(key, val)); - } + m_serviceMetaInfo.insert(std::pair(key, value)); + } } - } - NDN_LOG_INFO("Successfully updated the file content: "); + + ifstream.close(); + NDN_LOG_INFO("Successfully updated the file content: "); } catch (std::exception const& e) { diff --git a/ndnsd/discovery/file-processor.hpp b/ndnsd/discovery/file-processor.hpp index f65fb31..16ab71e 100644 --- a/ndnsd/discovery/file-processor.hpp +++ b/ndnsd/discovery/file-processor.hpp @@ -35,7 +35,7 @@ class ServiceInfoFileProcessor public: ServiceInfoFileProcessor() = default; - ServiceInfoFileProcessor(const std::string filename); + explicit ServiceInfoFileProcessor(std::string filename); ndn::Name& getServiceName() @@ -69,7 +69,7 @@ class ServiceInfoFileProcessor ndn::Name m_serviceName; ndn::Name m_applicationPrefix; std::map m_serviceMetaInfo; - ndn::time::seconds m_serviceLifeTime; + ndn::time::seconds m_serviceLifeTime{}; }; } // namespace discovery diff --git a/service_name.info b/service_name.info index 47e08da..5cbb4db 100644 --- a/service_name.info +++ b/service_name.info @@ -1,17 +1,16 @@ -; all the item in the required section needs to be filled properly - -required -{ - serviceName printer - appPrefix /repo/r1 ; repo name prefix - lifetime 1 ; in seconds +service-info-namespace { + root /edu/memphis + scope computing + type image-proc/rcnn + identifier rcnn1 } -; additional service details, user can put as many items as desired - -details -{ - description "repo to insert sensor data" - appPrefix /repo/r1 ;repo prefix - servedPrefix /prefix ;prefix repo served data for +required-service-detail { + name /edu/memphis/computing/image-proc/rcnn/rcnn1 + lifetime 50 } + +optional-service-detail { + description "faster rcnn" + release inception_resnet_v2/1 +} \ No newline at end of file