Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Parser Code (Hackathon) #5

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 40 additions & 36 deletions ndnsd/discovery/file-processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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<std::string >();
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<ndn::Name>();
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<std::string>();
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<std::string >();
const auto& val = details.second.get_value<std::string >();
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<std::string>();

NDN_LOG_DEBUG("Key: " << key << "Value: " << val);

m_serviceMetaInfo.insert(std::pair<std::string, std::string>(key, val));
}
m_serviceMetaInfo.insert(std::pair<std::string, std::string>(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)
{
Expand Down
4 changes: 2 additions & 2 deletions ndnsd/discovery/file-processor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class ServiceInfoFileProcessor
public:

ServiceInfoFileProcessor() = default;
ServiceInfoFileProcessor(const std::string filename);
explicit ServiceInfoFileProcessor(std::string filename);

ndn::Name&
getServiceName()
Expand Down Expand Up @@ -69,7 +69,7 @@ class ServiceInfoFileProcessor
ndn::Name m_serviceName;
ndn::Name m_applicationPrefix;
std::map<std::string, std::string> m_serviceMetaInfo;
ndn::time::seconds m_serviceLifeTime;
ndn::time::seconds m_serviceLifeTime{};
};

} // namespace discovery
Expand Down
27 changes: 13 additions & 14 deletions service_name.info
Original file line number Diff line number Diff line change
@@ -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
}