blob: 9b7c46bde37ca759f5e4148819ab3f9a5c3abec2 [file] [log] [blame]
Zhenkai Zhu406f37a2012-03-05 20:23:20 -08001/* -*- 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 Bian3e1eb162012-04-03 16:59:32 -070019 * Chaoyi Bian <bcy@pku.edu.cn>
Zhenkai Zhu406f37a2012-03-05 20:23:20 -080020 * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
21 */
22
Zhenkai Zhu1ac6f802012-03-06 17:40:27 -080023#ifndef SYNC_INTEREST_TABLE_H
24#define SYNC_INTEREST_TABLE_H
Alexander Afanasyevf3c03a92012-05-09 12:00:37 -070025
Alexander Afanasyev531803b2014-02-05 15:57:35 -080026#include <ndn-cpp-dev/util/scheduler.hpp>
27
Zhenkai Zhu406f37a2012-03-05 20:23:20 -080028#include <string>
Alexander Afanasyeva5858032012-03-09 15:55:10 -080029#include <vector>
Alexander Afanasyev531803b2014-02-05 15:57:35 -080030
Alexander Afanasyevf3c03a92012-05-09 12:00:37 -070031#include "sync-digest.h"
32#include "sync-interest-container.h"
Zhenkai Zhu406f37a2012-03-05 20:23:20 -080033
Zhenkai Zhu406f37a2012-03-05 20:23:20 -080034namespace Sync {
35
36/**
37 * \ingroup sync
38 * @brief A table to keep unanswered Sync Interest
Zhenkai Zhu77169cb2012-03-08 16:02:52 -080039 * all access operation to the table should grab the
40 * mutex first
Zhenkai Zhu406f37a2012-03-05 20:23:20 -080041 */
42class SyncInterestTable
43{
Zhenkai Zhu406f37a2012-03-05 20:23:20 -080044public:
Alexander Afanasyev531803b2014-02-05 15:57:35 -080045 SyncInterestTable (boost::asio::io_service& io, ndn::time::Duration lifetime);
Alexander Afanasyeva022f3d2012-03-11 18:14:48 -070046 ~SyncInterestTable ();
Zhenkai Zhu77169cb2012-03-08 16:02:52 -080047
Alexander Afanasyeva022f3d2012-03-11 18:14:48 -070048 /**
49 * @brief Insert an interest, if interest already exists, update the
50 * timestamp
51 */
Alexander Afanasyev860e6fe2012-03-15 17:30:31 -070052 bool
Alexander Afanasyev2b6fbfb2012-05-24 10:57:14 -070053 insert (DigestConstPtr interest, const std::string &name, bool unknownState=false);
Alexander Afanasyev860e6fe2012-03-15 17:30:31 -070054
55 /**
Alexander Afanasyevf3c03a92012-05-09 12:00:37 -070056 * @brief Remove interest by digest (e.g., when it was satisfied)
Alexander Afanasyev860e6fe2012-03-15 17:30:31 -070057 */
58 bool
Alexander Afanasyevf3c03a92012-05-09 12:00:37 -070059 remove (DigestConstPtr interest);
Zhenkai Zhu01733f02012-03-06 13:56:26 -080060
Alexander Afanasyeva022f3d2012-03-11 18:14:48 -070061 /**
Alexander Afanasyevf3c03a92012-05-09 12:00:37 -070062 * @brief Remove interest by name (e.g., when it was satisfied)
Alexander Afanasyeva022f3d2012-03-11 18:14:48 -070063 */
Alexander Afanasyevf3c03a92012-05-09 12:00:37 -070064 bool
65 remove (const std::string &name);
66
67 /**
68 * @brief pop a non-expired Interest from PIT
69 */
70 Interest
71 pop ();
Zhenkai Zhu406f37a2012-03-05 20:23:20 -080072
Alexander Afanasyev860e6fe2012-03-15 17:30:31 -070073 uint32_t
74 size () const;
75
Zhenkai Zhu77169cb2012-03-08 16:02:52 -080076private:
Alexander Afanasyeva022f3d2012-03-11 18:14:48 -070077 /**
78 * @brief periodically called to expire Interest
79 */
Alexander Afanasyev860e6fe2012-03-15 17:30:31 -070080 void
81 expireInterests ();
Zhenkai Zhu77169cb2012-03-08 16:02:52 -080082
83private:
Alexander Afanasyev531803b2014-02-05 15:57:35 -080084 ndn::time::Duration m_entryLifetime;
Alexander Afanasyevf3c03a92012-05-09 12:00:37 -070085 InterestContainer m_table;
Zhenkai Zhu77169cb2012-03-08 16:02:52 -080086
Alexander Afanasyev531803b2014-02-05 15:57:35 -080087 ndn::Scheduler m_scheduler;
Zhenkai Zhu406f37a2012-03-05 20:23:20 -080088};
89
Alexander Afanasyev46eb5262012-05-10 16:30:35 -070090namespace Error {
91struct InterestTableIsEmpty : virtual boost::exception, virtual std::exception { };
92}
93
Zhenkai Zhu406f37a2012-03-05 20:23:20 -080094} // Sync
95
Zhenkai Zhu1ac6f802012-03-06 17:40:27 -080096#endif // SYNC_INTEREST_TABLE_H