akmhoque | 66e6618 | 2014-02-21 17:56:03 -0600 | [diff] [blame] | 1 | /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2012 University of California, Los Angeles |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License version 2 as |
| 7 | * published by the Free Software Foundation; |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17 | * |
| 18 | * Author: Zhenkai Zhu <zhenkai@cs.ucla.edu> |
| 19 | * Chaoyi Bian <bcy@pku.edu.cn> |
| 20 | * Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
| 21 | */ |
| 22 | |
| 23 | #ifndef SYNC_INTEREST_TABLE_H |
| 24 | #define SYNC_INTEREST_TABLE_H |
| 25 | |
| 26 | #include <ndn-cpp-dev/util/scheduler.hpp> |
| 27 | |
| 28 | #include <string> |
| 29 | #include <vector> |
| 30 | |
| 31 | #include "sync-digest.h" |
| 32 | #include "sync-interest-container.h" |
| 33 | |
| 34 | namespace Sync { |
| 35 | |
| 36 | /** |
| 37 | * \ingroup sync |
| 38 | * @brief A table to keep unanswered Sync Interest |
| 39 | * all access operation to the table should grab the |
| 40 | * mutex first |
| 41 | */ |
| 42 | class SyncInterestTable |
| 43 | { |
| 44 | public: |
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame^] | 45 | SyncInterestTable (boost::asio::io_service& io, ndn::time::system_clock::Duration lifetime); |
akmhoque | 66e6618 | 2014-02-21 17:56:03 -0600 | [diff] [blame] | 46 | ~SyncInterestTable (); |
| 47 | |
| 48 | /** |
| 49 | * @brief Insert an interest, if interest already exists, update the |
| 50 | * timestamp |
| 51 | */ |
| 52 | bool |
| 53 | insert (DigestConstPtr interest, const std::string &name, bool unknownState=false); |
| 54 | |
| 55 | /** |
| 56 | * @brief Remove interest by digest (e.g., when it was satisfied) |
| 57 | */ |
| 58 | bool |
| 59 | remove (DigestConstPtr interest); |
| 60 | |
| 61 | /** |
| 62 | * @brief Remove interest by name (e.g., when it was satisfied) |
| 63 | */ |
| 64 | bool |
| 65 | remove (const std::string &name); |
| 66 | |
| 67 | /** |
| 68 | * @brief pop a non-expired Interest from PIT |
| 69 | */ |
| 70 | Interest |
| 71 | pop (); |
| 72 | |
| 73 | uint32_t |
| 74 | size () const; |
| 75 | |
| 76 | private: |
| 77 | /** |
| 78 | * @brief periodically called to expire Interest |
| 79 | */ |
| 80 | void |
| 81 | expireInterests (); |
| 82 | |
| 83 | private: |
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame^] | 84 | ndn::time::system_clock::Duration m_entryLifetime; |
akmhoque | 66e6618 | 2014-02-21 17:56:03 -0600 | [diff] [blame] | 85 | InterestContainer m_table; |
| 86 | |
| 87 | ndn::Scheduler m_scheduler; |
| 88 | }; |
| 89 | |
| 90 | namespace Error { |
| 91 | struct InterestTableIsEmpty : virtual boost::exception, virtual std::exception { }; |
| 92 | } |
| 93 | |
| 94 | } // Sync |
| 95 | |
| 96 | #endif // SYNC_INTEREST_TABLE_H |