blob: fad339febc6a27842a1e9cd6a7fe592f89e33fea [file] [log] [blame]
Zhenkai Zhu406f37a2012-03-05 20:23:20 -08001/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
2/*
Alexander Afanasyev8722d872014-07-02 13:00:29 -07003 * Copyright (c) 2012-2014 University of California, Los Angeles
Zhenkai Zhu406f37a2012-03-05 20:23:20 -08004 *
Alexander Afanasyev8722d872014-07-02 13:00:29 -07005 * This file is part of ChronoSync, synchronization library for distributed realtime
6 * applications for NDN.
Zhenkai Zhu406f37a2012-03-05 20:23:20 -08007 *
Alexander Afanasyev8722d872014-07-02 13:00:29 -07008 * ChronoSync is free software: you can redistribute it and/or modify it under the terms
9 * of the GNU General Public License as published by the Free Software Foundation, either
10 * version 3 of the License, or (at your option) any later version.
Zhenkai Zhu406f37a2012-03-05 20:23:20 -080011 *
Alexander Afanasyev8722d872014-07-02 13:00:29 -070012 * ChronoSync is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
Zhenkai Zhu406f37a2012-03-05 20:23:20 -080015 *
Alexander Afanasyev8722d872014-07-02 13:00:29 -070016 * You should have received a copy of the GNU General Public License along with
17 * ChronoSync, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
18 *
19 * @author Zhenkai Zhu <http://irl.cs.ucla.edu/~zhenkai/>
20 * @author Chaoyi Bian <bcy@pku.edu.cn>
21 * @author Alexander Afanasyev <http://lasr.cs.ucla.edu/afanasyev/index.html>
Zhenkai Zhu406f37a2012-03-05 20:23:20 -080022 */
23
Zhenkai Zhu1ac6f802012-03-06 17:40:27 -080024#ifndef SYNC_INTEREST_TABLE_H
25#define SYNC_INTEREST_TABLE_H
Alexander Afanasyevf3c03a92012-05-09 12:00:37 -070026
Yingdi Yu7c64e5c2014-04-30 14:06:37 -070027#include <ndn-cxx/util/scheduler.hpp>
Alexander Afanasyev531803b2014-02-05 15:57:35 -080028
Zhenkai Zhu406f37a2012-03-05 20:23:20 -080029#include <string>
Alexander Afanasyeva5858032012-03-09 15:55:10 -080030#include <vector>
Alexander Afanasyev531803b2014-02-05 15:57:35 -080031
Alexander Afanasyevf3c03a92012-05-09 12:00:37 -070032#include "sync-digest.h"
33#include "sync-interest-container.h"
Zhenkai Zhu406f37a2012-03-05 20:23:20 -080034
Zhenkai Zhu406f37a2012-03-05 20:23:20 -080035namespace Sync {
36
37/**
38 * \ingroup sync
39 * @brief A table to keep unanswered Sync Interest
Yingdi Yu7c64e5c2014-04-30 14:06:37 -070040 * all access operation to the table should grab the
Zhenkai Zhu77169cb2012-03-08 16:02:52 -080041 * mutex first
Zhenkai Zhu406f37a2012-03-05 20:23:20 -080042 */
43class SyncInterestTable
44{
Zhenkai Zhu406f37a2012-03-05 20:23:20 -080045public:
Yingdi Yu6e1c9cd2014-03-25 10:26:54 -070046 SyncInterestTable (boost::asio::io_service& io, ndn::time::system_clock::Duration lifetime);
Alexander Afanasyeva022f3d2012-03-11 18:14:48 -070047 ~SyncInterestTable ();
Zhenkai Zhu77169cb2012-03-08 16:02:52 -080048
Alexander Afanasyeva022f3d2012-03-11 18:14:48 -070049 /**
50 * @brief Insert an interest, if interest already exists, update the
51 * timestamp
52 */
Alexander Afanasyev860e6fe2012-03-15 17:30:31 -070053 bool
Alexander Afanasyev2b6fbfb2012-05-24 10:57:14 -070054 insert (DigestConstPtr interest, const std::string &name, bool unknownState=false);
Alexander Afanasyev860e6fe2012-03-15 17:30:31 -070055
56 /**
Alexander Afanasyevf3c03a92012-05-09 12:00:37 -070057 * @brief Remove interest by digest (e.g., when it was satisfied)
Alexander Afanasyev860e6fe2012-03-15 17:30:31 -070058 */
59 bool
Alexander Afanasyevf3c03a92012-05-09 12:00:37 -070060 remove (DigestConstPtr interest);
Zhenkai Zhu01733f02012-03-06 13:56:26 -080061
Alexander Afanasyeva022f3d2012-03-11 18:14:48 -070062 /**
Alexander Afanasyevf3c03a92012-05-09 12:00:37 -070063 * @brief Remove interest by name (e.g., when it was satisfied)
Alexander Afanasyeva022f3d2012-03-11 18:14:48 -070064 */
Alexander Afanasyevf3c03a92012-05-09 12:00:37 -070065 bool
66 remove (const std::string &name);
Yingdi Yu7c64e5c2014-04-30 14:06:37 -070067
Alexander Afanasyevf3c03a92012-05-09 12:00:37 -070068 /**
69 * @brief pop a non-expired Interest from PIT
70 */
71 Interest
72 pop ();
Zhenkai Zhu406f37a2012-03-05 20:23:20 -080073
Alexander Afanasyev860e6fe2012-03-15 17:30:31 -070074 uint32_t
75 size () const;
76
Zhenkai Zhu77169cb2012-03-08 16:02:52 -080077private:
Alexander Afanasyeva022f3d2012-03-11 18:14:48 -070078 /**
79 * @brief periodically called to expire Interest
80 */
Alexander Afanasyev860e6fe2012-03-15 17:30:31 -070081 void
82 expireInterests ();
Zhenkai Zhu77169cb2012-03-08 16:02:52 -080083
84private:
Yingdi Yu6e1c9cd2014-03-25 10:26:54 -070085 ndn::time::system_clock::Duration m_entryLifetime;
Alexander Afanasyevf3c03a92012-05-09 12:00:37 -070086 InterestContainer m_table;
Zhenkai Zhu77169cb2012-03-08 16:02:52 -080087
Alexander Afanasyev531803b2014-02-05 15:57:35 -080088 ndn::Scheduler m_scheduler;
Zhenkai Zhu406f37a2012-03-05 20:23:20 -080089};
90
Alexander Afanasyev46eb5262012-05-10 16:30:35 -070091namespace Error {
92struct InterestTableIsEmpty : virtual boost::exception, virtual std::exception { };
93}
94
Zhenkai Zhu406f37a2012-03-05 20:23:20 -080095} // Sync
96
Zhenkai Zhu1ac6f802012-03-06 17:40:27 -080097#endif // SYNC_INTEREST_TABLE_H