22 #ifndef NDN_DETAIL_FACE_IMPL_HPP 23 #define NDN_DETAIL_FACE_IMPL_HPP 25 #include "../common.hpp" 26 #include "../face.hpp" 32 #include "../util/scheduler.hpp" 33 #include "../util/config-file.hpp" 34 #include "../util/signal.hpp" 36 #include "../transport/transport.hpp" 37 #include "../transport/unix-transport.hpp" 38 #include "../transport/tcp-transport.hpp" 40 #include "../management/nfd-controller.hpp" 41 #include "../management/nfd-command-options.hpp" 43 #include "../lp/packet.hpp" 44 #include "../lp/tags.hpp" 60 auto postOnEmptyPitOrNoRegisteredPrefixes = [
this] {
68 m_pendingInterestTable.onEmpty.connect(postOnEmptyPitOrNoRegisteredPrefixes);
69 m_registeredPrefixTable.onEmpty.connect(postOnEmptyPitOrNoRegisteredPrefixes);
78 for (
auto entry = m_pendingInterestTable.begin(); entry != m_pendingInterestTable.end(); ) {
79 if ((*entry)->getInterest()->matchesData(data)) {
80 shared_ptr<PendingInterest> matchedEntry = *entry;
82 entry = m_pendingInterestTable.erase(entry);
84 matchedEntry->invokeDataCallback(data);
94 for (
auto entry = m_pendingInterestTable.begin(); entry != m_pendingInterestTable.end(); ) {
95 const Interest& pendingInterest = *(*entry)->getInterest();
97 shared_ptr<PendingInterest> matchedEntry = *entry;
99 entry = m_pendingInterestTable.erase(entry);
101 matchedEntry->invokeNackCallback(nack);
112 for (
const auto& filter : m_interestFilterTable) {
113 if (filter->doesMatch(interest.getName())) {
114 filter->invokeInterestCallback(interest);
125 if (!m_face.m_transport->isConnected())
126 m_face.m_transport->connect(m_face.getIoService(),
127 bind(&Face::onReceiveElement, &m_face, _1));
129 if (wantResume && !m_face.m_transport->isExpectingData())
130 m_face.m_transport->resume();
142 m_pendingInterestTable.insert(make_shared<PendingInterest>(interest,
146 ref(m_scheduler))).first;
147 (*entry)->setDeleter([
this, entry] { m_pendingInterestTable.erase(entry); });
152 if (nextHopFaceIdTag !=
nullptr) {
157 interest->wireEncode().end()));
159 m_face.m_transport->send(packet.
wireEncode());
165 m_pendingInterestTable.remove_if(MatchPendingInterestId(pendingInterestId));
171 m_pendingInterestTable.clear();
182 if (cachePolicyTag !=
nullptr) {
187 data->wireEncode().end()));
189 m_face.m_transport->send(packet.
wireEncode());
200 Block interest = nack->getInterest().wireEncode();
203 m_face.m_transport->send(packet.
wireEncode());
212 m_interestFilterTable.push_back(interestFilterRecord);
219 m_interestFilterTable.end(),
220 MatchInterestFilterId(interestFilterId));
221 if (i != m_interestFilterTable.end())
223 m_interestFilterTable.erase(i);
230 const RegisteredPrefixId*
232 const shared_ptr<InterestFilterRecord>& filter,
236 const nfd::CommandOptions& options)
241 params.setName(prefix);
242 params.setFlags(flags);
244 auto prefixToRegister = make_shared<RegisteredPrefix>(prefix, filter, options);
246 m_face.m_nfdController->start<RibRegisterCommand>(params,
248 prefixToRegister, onSuccess),
249 bind(onFailure, prefixToRegister->getPrefix(), _2),
252 return reinterpret_cast<const RegisteredPrefixId*
>(prefixToRegister.get());
259 m_registeredPrefixTable.insert(registeredPrefix);
261 if (static_cast<bool>(registeredPrefix->getFilter())) {
263 m_interestFilterTable.push_back(registeredPrefix->getFilter());
266 if (static_cast<bool>(onSuccess)) {
267 onSuccess(registeredPrefix->getPrefix());
277 auto i = std::find_if(m_registeredPrefixTable.begin(),
278 m_registeredPrefixTable.end(),
279 MatchRegisteredPrefixId(registeredPrefixId));
280 if (i != m_registeredPrefixTable.end()) {
281 RegisteredPrefix& record = **i;
283 const shared_ptr<InterestFilterRecord>& filter = record.getFilter();
285 if (filter !=
nullptr) {
287 m_interestFilterTable.remove(filter);
291 params.setName(record.getPrefix());
292 m_face.m_nfdController->start<RibUnregisterCommand>(params,
295 record.getCommandOptions());
298 if (onFailure !=
nullptr) {
299 onFailure(
"Unrecognized PrefixId");
310 m_registeredPrefixTable.erase(item);
312 if (static_cast<bool>(onSuccess)) {
320 if (m_pendingInterestTable.empty() && m_registeredPrefixTable.empty()) {
321 m_face.m_transport->pause();
327 util::Scheduler m_scheduler;
329 PendingInterestTable m_pendingInterestTable;
330 InterestFilterTable m_interestFilterTable;
331 RegisteredPrefixTable m_registeredPrefixTable;
338 #endif // NDN_DETAIL_FACE_IMPL_HPP Copyright (c) 2011-2015 Regents of the University of California.
ContainerWithOnEmptySignal< shared_ptr< RegisteredPrefix > > RegisteredPrefixTable
void ensureConnected(bool wantResume)
size_t wireEncode(EncodingImpl< TAG > &encoder) const
append packet to encoder
function< void(const std::string &)> UnregisterPrefixFailureCallback
Callback called when unregisterPrefix or unsetInterestFilter command fails.
void asyncExpressInterest(shared_ptr< const Interest > interest, const DataCallback &afterSatisfied, const NackCallback &afterNacked, const TimeoutCallback &afterTimeout)
void afterPrefixRegistered(const shared_ptr< RegisteredPrefix > ®isteredPrefix, const RegisterPrefixSuccessCallback &onSuccess)
Packet & add(const typename FIELD::ValueType &value)
add a FIELD with value
void nackPendingInterests(const lp::Nack &nack)
void asyncPutData(const shared_ptr< const Data > &data)
void asyncUnsetInterestFilter(const InterestFilterId *interestFilterId)
void asyncUnregisterPrefix(const RegisteredPrefixId *registeredPrefixId, const UnregisterPrefixSuccessCallback &onSuccess, const UnregisterPrefixFailureCallback &onFailure)
represents a Network Nack
provides a tag type for simple types
Table::const_iterator iterator
Copyright (c) 2011-2015 Regents of the University of California.
std::list< shared_ptr< InterestFilterRecord > > InterestFilterTable
void finalizeUnregisterPrefix(RegisteredPrefixTable::iterator item, const UnregisterPrefixSuccessCallback &onSuccess)
void asyncRemoveAllPendingInterests()
void processInterestFilters(Interest &interest)
function< void(const Name &, const std::string &)> RegisterPrefixFailureCallback
Callback called when registerPrefix or setInterestFilter command fails.
function< void(const Name &)> RegisterPrefixSuccessCallback
Callback called when registerPrefix or setInterestFilter command succeeds.
boost::asio::io_service & getIoService()
Return nullptr (cannot use IoService in simulations), preserved for API compatibility.
void asyncSetInterestFilter(const shared_ptr< InterestFilterRecord > &interestFilterRecord)
function< void()> UnregisterPrefixSuccessCallback
Callback called when unregisterPrefix or unsetInterestFilter command succeeds.
void satisfyPendingInterests(Data &data)
void asyncRemovePendingInterest(const PendingInterestId *pendingInterestId)
const RegisteredPrefixId * registerPrefix(const Name &prefix, const shared_ptr< InterestFilterRecord > &filter, const RegisterPrefixSuccessCallback &onSuccess, const RegisterPrefixFailureCallback &onFailure, uint64_t flags, const nfd::CommandOptions &options)
function< void(const Interest &)> TimeoutCallback
Callback called when expressed Interest times out.
ContainerWithOnEmptySignal< shared_ptr< PendingInterest > > PendingInterestTable
function< void(const Interest &, const lp::Nack &)> NackCallback
Callback called when Nack is sent in response to expressed Interest.
void asyncPutNack(shared_ptr< const lp::Nack > nack)
const Interest & getInterest() const
function< void(const Interest &, const Data &)> DataCallback
Callback called when expressed Interest gets satisfied with a Data packet.
void onEmptyPitOrNoRegisteredPrefixes()