Zhenkai Zhu | 406f37a | 2012-03-05 20:23:20 -0800 | [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> |
Chaoyi Bian | 3e1eb16 | 2012-04-03 16:59:32 -0700 | [diff] [blame] | 19 | * Chaoyi Bian <bcy@pku.edu.cn> |
Zhenkai Zhu | 406f37a | 2012-03-05 20:23:20 -0800 | [diff] [blame] | 20 | * Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
| 21 | */ |
| 22 | |
Zhenkai Zhu | 1ac6f80 | 2012-03-06 17:40:27 -0800 | [diff] [blame] | 23 | #ifndef SYNC_INTEREST_TABLE_H |
| 24 | #define SYNC_INTEREST_TABLE_H |
Alexander Afanasyev | f3c03a9 | 2012-05-09 12:00:37 -0700 | [diff] [blame] | 25 | |
Alexander Afanasyev | 531803b | 2014-02-05 15:57:35 -0800 | [diff] [blame] | 26 | #include <ndn-cpp-dev/util/scheduler.hpp> |
| 27 | |
Zhenkai Zhu | 406f37a | 2012-03-05 20:23:20 -0800 | [diff] [blame] | 28 | #include <string> |
Alexander Afanasyev | a585803 | 2012-03-09 15:55:10 -0800 | [diff] [blame] | 29 | #include <vector> |
Alexander Afanasyev | 531803b | 2014-02-05 15:57:35 -0800 | [diff] [blame] | 30 | |
Alexander Afanasyev | f3c03a9 | 2012-05-09 12:00:37 -0700 | [diff] [blame] | 31 | #include "sync-digest.h" |
| 32 | #include "sync-interest-container.h" |
Zhenkai Zhu | 406f37a | 2012-03-05 20:23:20 -0800 | [diff] [blame] | 33 | |
Zhenkai Zhu | 406f37a | 2012-03-05 20:23:20 -0800 | [diff] [blame] | 34 | namespace Sync { |
| 35 | |
| 36 | /** |
| 37 | * \ingroup sync |
| 38 | * @brief A table to keep unanswered Sync Interest |
Zhenkai Zhu | 77169cb | 2012-03-08 16:02:52 -0800 | [diff] [blame] | 39 | * all access operation to the table should grab the |
| 40 | * mutex first |
Zhenkai Zhu | 406f37a | 2012-03-05 20:23:20 -0800 | [diff] [blame] | 41 | */ |
| 42 | class SyncInterestTable |
| 43 | { |
Zhenkai Zhu | 406f37a | 2012-03-05 20:23:20 -0800 | [diff] [blame] | 44 | public: |
Yingdi Yu | 6e1c9cd | 2014-03-25 10:26:54 -0700 | [diff] [blame^] | 45 | SyncInterestTable (boost::asio::io_service& io, ndn::time::system_clock::Duration lifetime); |
Alexander Afanasyev | a022f3d | 2012-03-11 18:14:48 -0700 | [diff] [blame] | 46 | ~SyncInterestTable (); |
Zhenkai Zhu | 77169cb | 2012-03-08 16:02:52 -0800 | [diff] [blame] | 47 | |
Alexander Afanasyev | a022f3d | 2012-03-11 18:14:48 -0700 | [diff] [blame] | 48 | /** |
| 49 | * @brief Insert an interest, if interest already exists, update the |
| 50 | * timestamp |
| 51 | */ |
Alexander Afanasyev | 860e6fe | 2012-03-15 17:30:31 -0700 | [diff] [blame] | 52 | bool |
Alexander Afanasyev | 2b6fbfb | 2012-05-24 10:57:14 -0700 | [diff] [blame] | 53 | insert (DigestConstPtr interest, const std::string &name, bool unknownState=false); |
Alexander Afanasyev | 860e6fe | 2012-03-15 17:30:31 -0700 | [diff] [blame] | 54 | |
| 55 | /** |
Alexander Afanasyev | f3c03a9 | 2012-05-09 12:00:37 -0700 | [diff] [blame] | 56 | * @brief Remove interest by digest (e.g., when it was satisfied) |
Alexander Afanasyev | 860e6fe | 2012-03-15 17:30:31 -0700 | [diff] [blame] | 57 | */ |
| 58 | bool |
Alexander Afanasyev | f3c03a9 | 2012-05-09 12:00:37 -0700 | [diff] [blame] | 59 | remove (DigestConstPtr interest); |
Zhenkai Zhu | 01733f0 | 2012-03-06 13:56:26 -0800 | [diff] [blame] | 60 | |
Alexander Afanasyev | a022f3d | 2012-03-11 18:14:48 -0700 | [diff] [blame] | 61 | /** |
Alexander Afanasyev | f3c03a9 | 2012-05-09 12:00:37 -0700 | [diff] [blame] | 62 | * @brief Remove interest by name (e.g., when it was satisfied) |
Alexander Afanasyev | a022f3d | 2012-03-11 18:14:48 -0700 | [diff] [blame] | 63 | */ |
Alexander Afanasyev | f3c03a9 | 2012-05-09 12:00:37 -0700 | [diff] [blame] | 64 | bool |
| 65 | remove (const std::string &name); |
| 66 | |
| 67 | /** |
| 68 | * @brief pop a non-expired Interest from PIT |
| 69 | */ |
| 70 | Interest |
| 71 | pop (); |
Zhenkai Zhu | 406f37a | 2012-03-05 20:23:20 -0800 | [diff] [blame] | 72 | |
Alexander Afanasyev | 860e6fe | 2012-03-15 17:30:31 -0700 | [diff] [blame] | 73 | uint32_t |
| 74 | size () const; |
| 75 | |
Zhenkai Zhu | 77169cb | 2012-03-08 16:02:52 -0800 | [diff] [blame] | 76 | private: |
Alexander Afanasyev | a022f3d | 2012-03-11 18:14:48 -0700 | [diff] [blame] | 77 | /** |
| 78 | * @brief periodically called to expire Interest |
| 79 | */ |
Alexander Afanasyev | 860e6fe | 2012-03-15 17:30:31 -0700 | [diff] [blame] | 80 | void |
| 81 | expireInterests (); |
Zhenkai Zhu | 77169cb | 2012-03-08 16:02:52 -0800 | [diff] [blame] | 82 | |
| 83 | private: |
Yingdi Yu | 6e1c9cd | 2014-03-25 10:26:54 -0700 | [diff] [blame^] | 84 | ndn::time::system_clock::Duration m_entryLifetime; |
Alexander Afanasyev | f3c03a9 | 2012-05-09 12:00:37 -0700 | [diff] [blame] | 85 | InterestContainer m_table; |
Zhenkai Zhu | 77169cb | 2012-03-08 16:02:52 -0800 | [diff] [blame] | 86 | |
Alexander Afanasyev | 531803b | 2014-02-05 15:57:35 -0800 | [diff] [blame] | 87 | ndn::Scheduler m_scheduler; |
Zhenkai Zhu | 406f37a | 2012-03-05 20:23:20 -0800 | [diff] [blame] | 88 | }; |
| 89 | |
Alexander Afanasyev | 46eb526 | 2012-05-10 16:30:35 -0700 | [diff] [blame] | 90 | namespace Error { |
| 91 | struct InterestTableIsEmpty : virtual boost::exception, virtual std::exception { }; |
| 92 | } |
| 93 | |
Zhenkai Zhu | 406f37a | 2012-03-05 20:23:20 -0800 | [diff] [blame] | 94 | } // Sync |
| 95 | |
Zhenkai Zhu | 1ac6f80 | 2012-03-06 17:40:27 -0800 | [diff] [blame] | 96 | #endif // SYNC_INTEREST_TABLE_H |