blob: 4810c412b2bc269428824010f6edb253f33166c9 [file] [log] [blame]
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
/*
* Copyright (c) 2012 University of California, Los Angeles
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation;
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Author: Zhenkai Zhu <zhenkai@cs.ucla.edu>
* Chaoyi Bian <bcy@pku.edu.cn>
* Alexander Afanasyev <alexander.afanasyev@ucla.edu>
*/
#ifndef SYNC_INTEREST_TABLE_H
#define SYNC_INTEREST_TABLE_H
#include <ndn-cpp-dev/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