| /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */ |
| /* |
| * Copyright (c) 2012-2014 University of California, Los Angeles |
| * |
| * This file is part of ChronoSync, synchronization library for distributed realtime |
| * applications for NDN. |
| * |
| * ChronoSync is free software: you can redistribute it and/or modify it under the terms |
| * of the GNU General Public License as published by the Free Software Foundation, either |
| * version 3 of the License, or (at your option) any later version. |
| * |
| * ChronoSync is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| * PURPOSE. See the GNU General Public License for more details. |
| * |
| * You should have received a copy of the GNU General Public License along with |
| * ChronoSync, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| * |
| * @author Zhenkai Zhu <http://irl.cs.ucla.edu/~zhenkai/> |
| * @author Chaoyi Bian <bcy@pku.edu.cn> |
| * @author Alexander Afanasyev <http://lasr.cs.ucla.edu/afanasyev/index.html> |
| */ |
| |
| #ifndef SYNC_INTEREST_TABLE_H |
| #define SYNC_INTEREST_TABLE_H |
| |
| #include <ndn-cxx/util/scheduler.hpp> |
| |
| #include <string> |
| #include <vector> |
| |
| #include "sync-digest.h" |
| #include "sync-interest-container.h" |
| |
| namespace Sync { |
| |
| /** |
| * \ingroup sync |
| * @brief A table to keep unanswered Sync Interest |
| * all access operation to the table should grab the |
| * mutex first |
| */ |
| class SyncInterestTable |
| { |
| public: |
| SyncInterestTable (boost::asio::io_service& io, ndn::time::system_clock::Duration lifetime); |
| ~SyncInterestTable (); |
| |
| /** |
| * @brief Insert an interest, if interest already exists, update the |
| * timestamp |
| */ |
| bool |
| insert (DigestConstPtr interest, const std::string &name, bool unknownState=false); |
| |
| /** |
| * @brief Remove interest by digest (e.g., when it was satisfied) |
| */ |
| bool |
| remove (DigestConstPtr interest); |
| |
| /** |
| * @brief Remove interest by name (e.g., when it was satisfied) |
| */ |
| bool |
| remove (const std::string &name); |
| |
| /** |
| * @brief pop a non-expired Interest from PIT |
| */ |
| Interest |
| pop (); |
| |
| uint32_t |
| size () const; |
| |
| private: |
| /** |
| * @brief periodically called to expire Interest |
| */ |
| void |
| expireInterests (); |
| |
| private: |
| ndn::time::system_clock::Duration m_entryLifetime; |
| InterestContainer m_table; |
| |
| ndn::Scheduler m_scheduler; |
| }; |
| |
| namespace Error { |
| struct InterestTableIsEmpty : virtual boost::exception, virtual std::exception { }; |
| } |
| |
| } // Sync |
| |
| #endif // SYNC_INTEREST_TABLE_H |