Minsheng Zhang | cb6e05f | 2015-04-20 15:51:47 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Minsheng Zhang | ffe8bbb | 2016-03-10 13:40:37 -0700 | [diff] [blame] | 3 | * Copyright (c) 2014-2016, Regents of the University of California, |
Minsheng Zhang | cb6e05f | 2015-04-20 15:51:47 -0500 | [diff] [blame] | 4 | * Arizona Board of Regents, |
| 5 | * Colorado State University, |
| 6 | * University Pierre & Marie Curie, Sorbonne University, |
| 7 | * Washington University in St. Louis, |
| 8 | * Beijing Institute of Technology, |
| 9 | * The University of Memphis. |
| 10 | * |
| 11 | * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| 12 | * See AUTHORS.md for complete list of NFD authors and contributors. |
| 13 | * |
| 14 | * NFD is free software: you can redistribute it and/or modify it under the terms |
| 15 | * of the GNU General Public License as published by the Free Software Foundation, |
| 16 | * either version 3 of the License, or (at your option) any later version. |
| 17 | * |
| 18 | * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 19 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 20 | * PURPOSE. See the GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License along with |
| 23 | * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 24 | */ |
| 25 | |
| 26 | #include "cs-policy.hpp" |
| 27 | #include "cs.hpp" |
Junxiao Shi | 2af9ca3 | 2016-08-25 21:51:02 +0000 | [diff] [blame] | 28 | #include "core/logger.hpp" |
| 29 | |
| 30 | NFD_LOG_INIT("CsPolicy"); |
Minsheng Zhang | cb6e05f | 2015-04-20 15:51:47 -0500 | [diff] [blame] | 31 | |
| 32 | namespace nfd { |
| 33 | namespace cs { |
| 34 | |
Junxiao Shi | 52555b0 | 2016-11-25 21:39:06 +0000 | [diff] [blame] | 35 | Policy::Registry& |
| 36 | Policy::getRegistry() |
| 37 | { |
| 38 | static Registry registry; |
| 39 | return registry; |
| 40 | } |
| 41 | |
| 42 | unique_ptr<Policy> |
| 43 | Policy::create(const std::string& key) |
| 44 | { |
| 45 | Registry& registry = getRegistry(); |
| 46 | auto i = registry.find(key); |
| 47 | return i == registry.end() ? nullptr : i->second(); |
| 48 | } |
| 49 | |
Minsheng Zhang | cb6e05f | 2015-04-20 15:51:47 -0500 | [diff] [blame] | 50 | Policy::Policy(const std::string& policyName) |
| 51 | : m_policyName(policyName) |
| 52 | { |
| 53 | } |
| 54 | |
Minsheng Zhang | cb6e05f | 2015-04-20 15:51:47 -0500 | [diff] [blame] | 55 | void |
| 56 | Policy::setLimit(size_t nMaxEntries) |
| 57 | { |
Junxiao Shi | 2af9ca3 | 2016-08-25 21:51:02 +0000 | [diff] [blame] | 58 | NFD_LOG_INFO("setLimit " << nMaxEntries); |
Minsheng Zhang | cb6e05f | 2015-04-20 15:51:47 -0500 | [diff] [blame] | 59 | m_limit = nMaxEntries; |
Minsheng Zhang | cb6e05f | 2015-04-20 15:51:47 -0500 | [diff] [blame] | 60 | this->evictEntries(); |
| 61 | } |
| 62 | |
| 63 | void |
| 64 | Policy::afterInsert(iterator i) |
| 65 | { |
| 66 | BOOST_ASSERT(m_cs != nullptr); |
| 67 | this->doAfterInsert(i); |
| 68 | } |
| 69 | |
| 70 | void |
| 71 | Policy::afterRefresh(iterator i) |
| 72 | { |
| 73 | BOOST_ASSERT(m_cs != nullptr); |
| 74 | this->doAfterRefresh(i); |
| 75 | } |
| 76 | |
| 77 | void |
| 78 | Policy::beforeErase(iterator i) |
| 79 | { |
| 80 | BOOST_ASSERT(m_cs != nullptr); |
| 81 | this->doBeforeErase(i); |
| 82 | } |
| 83 | |
| 84 | void |
| 85 | Policy::beforeUse(iterator i) |
| 86 | { |
| 87 | BOOST_ASSERT(m_cs != nullptr); |
| 88 | this->doBeforeUse(i); |
| 89 | } |
| 90 | |
| 91 | } // namespace cs |
| 92 | } // namespace nfd |