face-module.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
46 #include "face-module.hpp"
47 #include "format-helpers.hpp"
48 
49 namespace nfd {
50 namespace tools {
51 namespace nfdc {
52 
53 void
54 FaceModule::fetchStatus(Controller& controller,
55  const function<void()>& onSuccess,
56  const Controller::DatasetFailCallback& onFailure,
57  const CommandOptions& options)
58 {
59  controller.fetch<ndn::nfd::FaceDataset>(
60  [this, onSuccess] (const std::vector<FaceStatus>& result) {
61  m_status = result;
62  onSuccess();
63  },
64  onFailure, options);
65 }
66 
67 void
68 FaceModule::formatStatusXml(std::ostream& os) const
69 {
70  os << "<faces>";
71  for (const FaceStatus& item : m_status) {
72  this->formatItemXml(os, item);
73  }
74  os << "</faces>";
75 }
76 
77 void
78 FaceModule::formatItemXml(std::ostream& os, const FaceStatus& item) const
79 {
80  os << "<face>";
81 
82  os << "<faceId>" << item.getFaceId() << "</faceId>";
83  os << "<remoteUri>" << xml::Text{item.getRemoteUri()} << "</remoteUri>";
84  os << "<localUri>" << xml::Text{item.getLocalUri()} << "</localUri>";
85 
86  if (item.hasExpirationPeriod()) {
87  os << "<expirationPeriod>" << xml::formatDuration(item.getExpirationPeriod())
88  << "</expirationPeriod>";
89  }
90  os << "<faceScope>" << item.getFaceScope() << "</faceScope>";
91  os << "<facePersistency>" << item.getFacePersistency() << "</facePersistency>";
92  os << "<linkType>" << item.getLinkType() << "</linkType>";
93 
94  if (item.getFlags() == 0) {
95  os << "<flags/>";
96  }
97  else {
98  os << "<flags>";
99  if (item.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED)) {
100  os << "<localFieldsEnabled/>";
101  }
102  os << "</flags>";
103  }
104 
105  os << "<packetCounters>";
106  os << "<incomingPackets>"
107  << "<nInterests>" << item.getNInInterests() << "</nInterests>"
108  << "<nDatas>" << item.getNInDatas() << "</nDatas>"
109  << "<nNacks>" << item.getNInNacks() << "</nNacks>"
110  << "</incomingPackets>";
111  os << "<outgoingPackets>"
112  << "<nInterests>" << item.getNOutInterests() << "</nInterests>"
113  << "<nDatas>" << item.getNOutDatas() << "</nDatas>"
114  << "<nNacks>" << item.getNOutNacks() << "</nNacks>"
115  << "</outgoingPackets>";
116  os << "</packetCounters>";
117 
118  os << "<byteCounters>";
119  os << "<incomingBytes>" << item.getNInBytes() << "</incomingBytes>";
120  os << "<outgoingBytes>" << item.getNOutBytes() << "</outgoingBytes>";
121  os << "</byteCounters>";
122 
123  os << "</face>";
124 }
125 
126 void
127 FaceModule::formatStatusText(std::ostream& os) const
128 {
129  os << "Faces:\n";
130  for (const FaceStatus& item : m_status) {
131  this->formatItemText(os, item);
132  }
133 }
134 
135 void
136 FaceModule::formatItemText(std::ostream& os, const FaceStatus& item) const
137 {
138  os << " faceid=" << item.getFaceId();
139  os << " remote=" << item.getRemoteUri();
140  os << " local=" << item.getLocalUri();
141 
142  if (item.hasExpirationPeriod()) {
143  os << " expires=" << text::formatDuration(item.getExpirationPeriod());
144  }
145 
146  os << " counters={in={"
147  << item.getNInInterests() << "i "
148  << item.getNInDatas() << "d "
149  << item.getNInNacks() << "n "
150  << item.getNInBytes() << "B} ";
151  os << "out={"
152  << item.getNOutInterests() << "i "
153  << item.getNOutDatas() << "d "
154  << item.getNOutNacks() << "n "
155  << item.getNOutBytes() << "B}}";
156 
157  os << " " << item.getFaceScope();
158  os << " " << item.getFacePersistency();
159  os << " " << item.getLinkType();
160 
161  os << " flags={";
162  if (item.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED)) {
163  os << "local-fields";
164  }
165  os << "}";
166 
167  os << "\n";
168 }
169 
170 } // namespace nfdc
171 } // namespace tools
172 } // namespace nfd
virtual void fetchStatus(Controller &controller, const function< void()> &onSuccess, const Controller::DatasetFailCallback &onFailure, const CommandOptions &options) override
collect status from NFD
Definition: face-module.cpp:54
std::string formatDuration(DURATION d)
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
void formatItemXml(std::ostream &os, const FaceStatus &item) const
format a single status item as XML
Definition: face-module.cpp:78
std::string formatDuration(DURATION d, bool isLong=false)
void formatItemText(std::ostream &os, const FaceStatus &item) const
format a single status item as text
virtual void formatStatusXml(std::ostream &os) const override
format collected status as XML
Definition: face-module.cpp:68
virtual void formatStatusText(std::ostream &os) const override
format collected status as text