Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 2 | /** |
Alexander Afanasyev | 9d158f0 | 2015-02-17 21:30:19 -0800 | [diff] [blame] | 3 | * Copyright (c) 2013-2015 Regents of the University of California. |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 4 | * |
| 5 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 6 | * |
Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 7 | * ndn-cxx library is free software: you can redistribute it and/or modify it under the |
| 8 | * terms of the GNU Lesser General Public License as published by the Free Software |
| 9 | * Foundation, either version 3 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY |
| 12 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
| 13 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
| 14 | * |
| 15 | * You should have received copies of the GNU General Public License and GNU Lesser |
| 16 | * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see |
| 17 | * <http://www.gnu.org/licenses/>. |
| 18 | * |
| 19 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 20 | */ |
| 21 | |
| 22 | #ifndef NDN_DETAIL_FACE_IMPL_HPP |
| 23 | #define NDN_DETAIL_FACE_IMPL_HPP |
| 24 | |
| 25 | #include "../common.hpp" |
| 26 | #include "../face.hpp" |
| 27 | |
| 28 | #include "registered-prefix.hpp" |
| 29 | #include "pending-interest.hpp" |
Alexander Afanasyev | 9d158f0 | 2015-02-17 21:30:19 -0800 | [diff] [blame] | 30 | #include "container-with-on-empty-signal.hpp" |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 31 | |
| 32 | #include "../util/scheduler.hpp" |
| 33 | #include "../util/config-file.hpp" |
Alexander Afanasyev | 9d158f0 | 2015-02-17 21:30:19 -0800 | [diff] [blame] | 34 | #include "../util/signal.hpp" |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 35 | |
Junxiao Shi | 0fa2845 | 2014-12-13 22:02:36 -0700 | [diff] [blame] | 36 | #include "../transport/transport.hpp" |
| 37 | #include "../transport/unix-transport.hpp" |
| 38 | #include "../transport/tcp-transport.hpp" |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 39 | |
Junxiao Shi | 0fa2845 | 2014-12-13 22:02:36 -0700 | [diff] [blame] | 40 | #include "../management/nfd-controller.hpp" |
| 41 | #include "../management/nfd-command-options.hpp" |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 42 | #include "../management/nfd-local-control-header.hpp" |
| 43 | |
| 44 | #include "../lp/packet.hpp" |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 45 | |
| 46 | namespace ndn { |
| 47 | |
| 48 | class Face::Impl : noncopyable |
| 49 | { |
| 50 | public: |
Alexander Afanasyev | 9d158f0 | 2015-02-17 21:30:19 -0800 | [diff] [blame] | 51 | typedef ContainerWithOnEmptySignal<shared_ptr<PendingInterest>> PendingInterestTable; |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 52 | typedef std::list<shared_ptr<InterestFilterRecord> > InterestFilterTable; |
Alexander Afanasyev | 9d158f0 | 2015-02-17 21:30:19 -0800 | [diff] [blame] | 53 | typedef ContainerWithOnEmptySignal<shared_ptr<RegisteredPrefix>> RegisteredPrefixTable; |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 54 | |
| 55 | explicit |
| 56 | Impl(Face& face) |
| 57 | : m_face(face) |
Alexander Afanasyev | 9d158f0 | 2015-02-17 21:30:19 -0800 | [diff] [blame] | 58 | , m_scheduler(m_face.getIoService()) |
| 59 | , m_processEventsTimeoutEvent(m_scheduler) |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 60 | { |
Alexander Afanasyev | 9d158f0 | 2015-02-17 21:30:19 -0800 | [diff] [blame] | 61 | auto postOnEmptyPitOrNoRegisteredPrefixes = [this] { |
| 62 | this->m_face.getIoService().post(bind(&Impl::onEmptyPitOrNoRegisteredPrefixes, this)); |
| 63 | // without this extra "post", transport can get paused (-async_read) and then resumed |
| 64 | // (+async_read) from within onInterest/onData callback. After onInterest/onData |
| 65 | // finishes, there is another +async_read with the same memory block. A few of such |
| 66 | // async_read duplications can cause various effects and result in segfault. |
| 67 | }; |
| 68 | |
| 69 | m_pendingInterestTable.onEmpty.connect(postOnEmptyPitOrNoRegisteredPrefixes); |
| 70 | m_registeredPrefixTable.onEmpty.connect(postOnEmptyPitOrNoRegisteredPrefixes); |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | ///////////////////////////////////////////////////////////////////////////////////////////////// |
| 74 | ///////////////////////////////////////////////////////////////////////////////////////////////// |
| 75 | |
| 76 | void |
| 77 | satisfyPendingInterests(Data& data) |
| 78 | { |
Alexander Afanasyev | 9d158f0 | 2015-02-17 21:30:19 -0800 | [diff] [blame] | 79 | for (auto entry = m_pendingInterestTable.begin(); entry != m_pendingInterestTable.end(); ) { |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 80 | if ((*entry)->getInterest()->matchesData(data)) { |
Alexander Afanasyev | 9d158f0 | 2015-02-17 21:30:19 -0800 | [diff] [blame] | 81 | shared_ptr<PendingInterest> matchedEntry = *entry; |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 82 | |
Alexander Afanasyev | 9d158f0 | 2015-02-17 21:30:19 -0800 | [diff] [blame] | 83 | entry = m_pendingInterestTable.erase(entry); |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 84 | |
Alexander Afanasyev | 9d158f0 | 2015-02-17 21:30:19 -0800 | [diff] [blame] | 85 | matchedEntry->invokeDataCallback(data); |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 86 | } |
Alexander Afanasyev | 9d158f0 | 2015-02-17 21:30:19 -0800 | [diff] [blame] | 87 | else |
| 88 | ++entry; |
| 89 | } |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | void |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 93 | nackPendingInterests(const lp::Nack& nack) |
| 94 | { |
| 95 | for (auto entry = m_pendingInterestTable.begin(); entry != m_pendingInterestTable.end(); ) { |
| 96 | const Interest& pendingInterest = *(*entry)->getInterest(); |
| 97 | if (pendingInterest == nack.getInterest()) { |
| 98 | shared_ptr<PendingInterest> matchedEntry = *entry; |
| 99 | |
| 100 | entry = m_pendingInterestTable.erase(entry); |
| 101 | |
| 102 | matchedEntry->invokeNackCallback(nack); |
| 103 | } |
| 104 | else { |
| 105 | ++entry; |
| 106 | } |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | void |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 111 | processInterestFilters(Interest& interest) |
| 112 | { |
Alexander Afanasyev | 9d158f0 | 2015-02-17 21:30:19 -0800 | [diff] [blame] | 113 | for (const auto& filter : m_interestFilterTable) { |
| 114 | if (filter->doesMatch(interest.getName())) { |
| 115 | filter->invokeInterestCallback(interest); |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 116 | } |
Alexander Afanasyev | 9d158f0 | 2015-02-17 21:30:19 -0800 | [diff] [blame] | 117 | } |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | ///////////////////////////////////////////////////////////////////////////////////////////////// |
| 121 | ///////////////////////////////////////////////////////////////////////////////////////////////// |
| 122 | |
| 123 | void |
Alexander Afanasyev | 9d158f0 | 2015-02-17 21:30:19 -0800 | [diff] [blame] | 124 | ensureConnected(bool wantResume) |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 125 | { |
Alexander Afanasyev | 407e949 | 2014-07-10 18:50:44 -0700 | [diff] [blame] | 126 | if (!m_face.m_transport->isConnected()) |
Junxiao Shi | 2cced06 | 2014-11-02 21:27:38 -0700 | [diff] [blame] | 127 | m_face.m_transport->connect(m_face.m_ioService, |
Alexander Afanasyev | 407e949 | 2014-07-10 18:50:44 -0700 | [diff] [blame] | 128 | bind(&Face::onReceiveElement, &m_face, _1)); |
| 129 | |
Junxiao Shi | a1ea506 | 2014-12-27 22:33:39 -0700 | [diff] [blame] | 130 | if (wantResume && !m_face.m_transport->isExpectingData()) |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 131 | m_face.m_transport->resume(); |
Junxiao Shi | a1ea506 | 2014-12-27 22:33:39 -0700 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | void |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 135 | asyncExpressInterest(shared_ptr<const Interest> interest, |
| 136 | const DataCallback& afterSatisfied, |
| 137 | const NackCallback& afterNacked, |
| 138 | const TimeoutCallback& afterTimeout) |
Junxiao Shi | a1ea506 | 2014-12-27 22:33:39 -0700 | [diff] [blame] | 139 | { |
Alexander Afanasyev | 9d158f0 | 2015-02-17 21:30:19 -0800 | [diff] [blame] | 140 | this->ensureConnected(true); |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 141 | |
Alexander Afanasyev | 9d158f0 | 2015-02-17 21:30:19 -0800 | [diff] [blame] | 142 | auto entry = |
| 143 | m_pendingInterestTable.insert(make_shared<PendingInterest>(interest, |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 144 | afterSatisfied, |
| 145 | afterNacked, |
| 146 | afterTimeout, |
Alexander Afanasyev | 9d158f0 | 2015-02-17 21:30:19 -0800 | [diff] [blame] | 147 | ref(m_scheduler))).first; |
| 148 | (*entry)->setDeleter([this, entry] { m_pendingInterestTable.erase(entry); }); |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 149 | |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 150 | lp::Packet packet; |
| 151 | |
| 152 | nfd::LocalControlHeader localControlHeader = interest->getLocalControlHeader(); |
| 153 | if (localControlHeader.hasNextHopFaceId()) { |
| 154 | packet.add<lp::NextHopFaceIdField>(localControlHeader.getNextHopFaceId()); |
Alexander Afanasyev | 9d158f0 | 2015-02-17 21:30:19 -0800 | [diff] [blame] | 155 | } |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 156 | |
| 157 | packet.add<lp::FragmentField>(std::make_pair(interest->wireEncode().begin(), |
| 158 | interest->wireEncode().end())); |
| 159 | |
| 160 | m_face.m_transport->send(packet.wireEncode()); |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | void |
| 164 | asyncRemovePendingInterest(const PendingInterestId* pendingInterestId) |
| 165 | { |
| 166 | m_pendingInterestTable.remove_if(MatchPendingInterestId(pendingInterestId)); |
| 167 | } |
| 168 | |
Alexander Afanasyev | 6a05b4b | 2014-07-18 17:23:00 -0700 | [diff] [blame] | 169 | void |
| 170 | asyncPutData(const shared_ptr<const Data>& data) |
| 171 | { |
Alexander Afanasyev | 9d158f0 | 2015-02-17 21:30:19 -0800 | [diff] [blame] | 172 | this->ensureConnected(true); |
Alexander Afanasyev | 6a05b4b | 2014-07-18 17:23:00 -0700 | [diff] [blame] | 173 | |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 174 | lp::Packet packet; |
| 175 | |
| 176 | nfd::LocalControlHeader localControlHeader = data->getLocalControlHeader(); |
| 177 | if (localControlHeader.hasCachingPolicy()) { |
| 178 | switch (localControlHeader.getCachingPolicy()) { |
| 179 | case nfd::LocalControlHeader::CachingPolicy::NO_CACHE: { |
| 180 | lp::CachePolicy cachePolicy; |
| 181 | cachePolicy.setPolicy(lp::CachePolicyType::NO_CACHE); |
| 182 | packet.add<lp::CachePolicyField>(cachePolicy); |
| 183 | break; |
| 184 | } |
| 185 | default: |
| 186 | break; |
| 187 | } |
Alexander Afanasyev | 9d158f0 | 2015-02-17 21:30:19 -0800 | [diff] [blame] | 188 | } |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 189 | |
| 190 | packet.add<lp::FragmentField>(std::make_pair(data->wireEncode().begin(), |
| 191 | data->wireEncode().end())); |
| 192 | |
| 193 | m_face.m_transport->send(packet.wireEncode()); |
| 194 | } |
| 195 | |
| 196 | void |
| 197 | asyncPutNack(shared_ptr<const lp::Nack> nack) |
| 198 | { |
| 199 | this->ensureConnected(true); |
| 200 | |
| 201 | lp::Packet packet; |
| 202 | packet.add<lp::NackField>(nack->getHeader()); |
| 203 | |
| 204 | Block interest = nack->getInterest().wireEncode(); |
| 205 | packet.add<lp::FragmentField>(std::make_pair(interest.begin(), interest.end())); |
| 206 | |
| 207 | m_face.m_transport->send(packet.wireEncode()); |
Alexander Afanasyev | 6a05b4b | 2014-07-18 17:23:00 -0700 | [diff] [blame] | 208 | } |
| 209 | |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 210 | ///////////////////////////////////////////////////////////////////////////////////////////////// |
| 211 | ///////////////////////////////////////////////////////////////////////////////////////////////// |
| 212 | |
| 213 | void |
| 214 | asyncSetInterestFilter(const shared_ptr<InterestFilterRecord>& interestFilterRecord) |
| 215 | { |
| 216 | m_interestFilterTable.push_back(interestFilterRecord); |
| 217 | } |
| 218 | |
| 219 | void |
| 220 | asyncUnsetInterestFilter(const InterestFilterId* interestFilterId) |
| 221 | { |
| 222 | InterestFilterTable::iterator i = std::find_if(m_interestFilterTable.begin(), |
| 223 | m_interestFilterTable.end(), |
| 224 | MatchInterestFilterId(interestFilterId)); |
| 225 | if (i != m_interestFilterTable.end()) |
| 226 | { |
| 227 | m_interestFilterTable.erase(i); |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | ///////////////////////////////////////////////////////////////////////////////////////////////// |
| 232 | ///////////////////////////////////////////////////////////////////////////////////////////////// |
| 233 | |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 234 | const RegisteredPrefixId* |
| 235 | registerPrefix(const Name& prefix, |
| 236 | const shared_ptr<InterestFilterRecord>& filter, |
| 237 | const RegisterPrefixSuccessCallback& onSuccess, |
| 238 | const RegisterPrefixFailureCallback& onFailure, |
Alexander Afanasyev | 0866f51 | 2014-08-11 13:25:09 -0700 | [diff] [blame] | 239 | uint64_t flags, |
Junxiao Shi | 388ec25 | 2014-11-02 15:19:57 -0700 | [diff] [blame] | 240 | const nfd::CommandOptions& options) |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 241 | { |
| 242 | using namespace nfd; |
| 243 | |
Joao Pereira | ba1e3b9 | 2015-06-01 17:50:37 -0400 | [diff] [blame] | 244 | ControlParameters params; |
| 245 | params.setName(prefix); |
| 246 | params.setFlags(flags); |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 247 | |
Joao Pereira | ba1e3b9 | 2015-06-01 17:50:37 -0400 | [diff] [blame] | 248 | auto prefixToRegister = make_shared<RegisteredPrefix>(prefix, filter, options); |
Alexander Afanasyev | 0866f51 | 2014-08-11 13:25:09 -0700 | [diff] [blame] | 249 | |
Joao Pereira | ba1e3b9 | 2015-06-01 17:50:37 -0400 | [diff] [blame] | 250 | m_face.m_nfdController->start<RibRegisterCommand>(params, |
| 251 | bind(&Impl::afterPrefixRegistered, this, |
| 252 | prefixToRegister, onSuccess), |
| 253 | bind(onFailure, prefixToRegister->getPrefix(), _2), |
| 254 | options); |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 255 | |
| 256 | return reinterpret_cast<const RegisteredPrefixId*>(prefixToRegister.get()); |
| 257 | } |
| 258 | |
| 259 | void |
| 260 | afterPrefixRegistered(const shared_ptr<RegisteredPrefix>& registeredPrefix, |
| 261 | const RegisterPrefixSuccessCallback& onSuccess) |
| 262 | { |
Alexander Afanasyev | 9d158f0 | 2015-02-17 21:30:19 -0800 | [diff] [blame] | 263 | m_registeredPrefixTable.insert(registeredPrefix); |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 264 | |
| 265 | if (static_cast<bool>(registeredPrefix->getFilter())) { |
| 266 | // it was a combined operation |
| 267 | m_interestFilterTable.push_back(registeredPrefix->getFilter()); |
| 268 | } |
| 269 | |
| 270 | if (static_cast<bool>(onSuccess)) { |
| 271 | onSuccess(registeredPrefix->getPrefix()); |
| 272 | } |
| 273 | } |
| 274 | |
| 275 | void |
| 276 | asyncUnregisterPrefix(const RegisteredPrefixId* registeredPrefixId, |
| 277 | const UnregisterPrefixSuccessCallback& onSuccess, |
| 278 | const UnregisterPrefixFailureCallback& onFailure) |
| 279 | { |
Joao Pereira | ba1e3b9 | 2015-06-01 17:50:37 -0400 | [diff] [blame] | 280 | using namespace nfd; |
| 281 | auto i = std::find_if(m_registeredPrefixTable.begin(), |
| 282 | m_registeredPrefixTable.end(), |
| 283 | MatchRegisteredPrefixId(registeredPrefixId)); |
| 284 | if (i != m_registeredPrefixTable.end()) { |
| 285 | RegisteredPrefix& record = **i; |
| 286 | |
| 287 | const shared_ptr<InterestFilterRecord>& filter = record.getFilter(); |
| 288 | |
| 289 | if (filter != nullptr) { |
| 290 | // it was a combined operation |
| 291 | m_interestFilterTable.remove(filter); |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 292 | } |
Joao Pereira | ba1e3b9 | 2015-06-01 17:50:37 -0400 | [diff] [blame] | 293 | |
| 294 | ControlParameters params; |
| 295 | params.setName(record.getPrefix()); |
| 296 | m_face.m_nfdController->start<RibUnregisterCommand>(params, |
| 297 | bind(&Impl::finalizeUnregisterPrefix, this, i, onSuccess), |
| 298 | bind(onFailure, _2), |
| 299 | record.getCommandOptions()); |
| 300 | } |
Alexander Afanasyev | 851228a | 2014-10-20 15:55:28 -0400 | [diff] [blame] | 301 | else { |
Joao Pereira | ba1e3b9 | 2015-06-01 17:50:37 -0400 | [diff] [blame] | 302 | if (onFailure != nullptr) { |
Alexander Afanasyev | 851228a | 2014-10-20 15:55:28 -0400 | [diff] [blame] | 303 | onFailure("Unrecognized PrefixId"); |
| 304 | } |
| 305 | } |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 306 | |
| 307 | // there cannot be two registered prefixes with the same id |
| 308 | } |
| 309 | |
| 310 | void |
| 311 | finalizeUnregisterPrefix(RegisteredPrefixTable::iterator item, |
| 312 | const UnregisterPrefixSuccessCallback& onSuccess) |
| 313 | { |
| 314 | m_registeredPrefixTable.erase(item); |
| 315 | |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 316 | if (static_cast<bool>(onSuccess)) { |
| 317 | onSuccess(); |
| 318 | } |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 319 | } |
| 320 | |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 321 | void |
Alexander Afanasyev | 9d158f0 | 2015-02-17 21:30:19 -0800 | [diff] [blame] | 322 | onEmptyPitOrNoRegisteredPrefixes() |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 323 | { |
Alexander Afanasyev | 9d158f0 | 2015-02-17 21:30:19 -0800 | [diff] [blame] | 324 | if (m_pendingInterestTable.empty() && m_registeredPrefixTable.empty()) { |
| 325 | m_face.m_transport->pause(); |
| 326 | if (!m_ioServiceWork) { |
| 327 | m_processEventsTimeoutEvent.cancel(); |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 328 | } |
| 329 | } |
| 330 | } |
| 331 | |
| 332 | private: |
| 333 | Face& m_face; |
Alexander Afanasyev | 9d158f0 | 2015-02-17 21:30:19 -0800 | [diff] [blame] | 334 | util::Scheduler m_scheduler; |
| 335 | util::scheduler::ScopedEventId m_processEventsTimeoutEvent; |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 336 | |
| 337 | PendingInterestTable m_pendingInterestTable; |
| 338 | InterestFilterTable m_interestFilterTable; |
| 339 | RegisteredPrefixTable m_registeredPrefixTable; |
| 340 | |
Alexander Afanasyev | 9d158f0 | 2015-02-17 21:30:19 -0800 | [diff] [blame] | 341 | unique_ptr<boost::asio::io_service::work> m_ioServiceWork; // if thread needs to be preserved |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 342 | |
| 343 | friend class Face; |
| 344 | }; |
| 345 | |
| 346 | } // namespace ndn |
| 347 | |
| 348 | #endif // NDN_DETAIL_FACE_IMPL_HPP |