Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 3 | * Copyright (c) 2014 Regents of the University of California, |
| 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 | * |
| 10 | * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| 11 | * See AUTHORS.md for complete list of NFD authors and contributors. |
| 12 | * |
| 13 | * NFD is free software: you can redistribute it and/or modify it under the terms |
| 14 | * of the GNU General Public License as published by the Free Software Foundation, |
| 15 | * either version 3 of the License, or (at your option) any later version. |
| 16 | * |
| 17 | * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 18 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 19 | * PURPOSE. See the GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License along with |
| 22 | * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 23 | **/ |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 24 | |
Alexander Afanasyev | 613e2a9 | 2014-04-15 13:36:58 -0700 | [diff] [blame] | 25 | #ifndef NFD_DAEMON_TABLE_STRATEGY_CHOICE_HPP |
| 26 | #define NFD_DAEMON_TABLE_STRATEGY_CHOICE_HPP |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 27 | |
| 28 | #include "strategy-choice-entry.hpp" |
| 29 | #include "name-tree.hpp" |
| 30 | |
| 31 | namespace nfd { |
| 32 | |
| 33 | class StrategyChoice : noncopyable |
| 34 | { |
| 35 | public: |
| 36 | StrategyChoice(NameTree& nameTree, shared_ptr<fw::Strategy> defaultStrategy); |
| 37 | |
| 38 | public: // available Strategy types |
| 39 | /** \return true if strategy is installed |
| 40 | */ |
| 41 | bool |
| 42 | hasStrategy(const Name& strategyName) const; |
| 43 | |
| 44 | /** \brief install a strategy |
| 45 | * \return true if installed; false if not installed due to duplicate strategyName |
| 46 | */ |
| 47 | bool |
| 48 | install(shared_ptr<fw::Strategy> strategy); |
| 49 | |
| 50 | public: // Strategy Choice table |
| 51 | /** \brief set strategy of prefix to be strategyName |
| 52 | * \param strategyName the strategy to be used, must be installed |
| 53 | * \return true on success |
| 54 | */ |
| 55 | bool |
| 56 | insert(const Name& prefix, const Name& strategyName); |
| 57 | |
| 58 | /** \brief make prefix to inherit strategy from its parent |
| 59 | * |
| 60 | * not allowed for root prefix (ndn:/) |
| 61 | */ |
| 62 | void |
| 63 | erase(const Name& prefix); |
| 64 | |
| 65 | /** \brief get strategy Name of prefix |
| 66 | * \return strategyName at exact match, or nullptr |
| 67 | */ |
| 68 | shared_ptr<const Name> |
| 69 | get(const Name& prefix) const; |
| 70 | |
| 71 | public: // effect strategy |
| 72 | /// get effective strategy for prefix |
| 73 | fw::Strategy& |
| 74 | findEffectiveStrategy(const Name& prefix) const; |
| 75 | |
| 76 | /// get effective strategy for pitEntry |
| 77 | fw::Strategy& |
| 78 | findEffectiveStrategy(const pit::Entry& pitEntry) const; |
| 79 | |
Junxiao Shi | 7bb0151 | 2014-03-05 21:34:09 -0700 | [diff] [blame] | 80 | /// get effective strategy for measurementsEntry |
| 81 | fw::Strategy& |
| 82 | findEffectiveStrategy(const measurements::Entry& measurementsEntry) const; |
| 83 | |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 84 | /// number of entries stored |
| 85 | size_t |
| 86 | size() const; |
| 87 | |
| 88 | private: |
| 89 | shared_ptr<fw::Strategy> |
| 90 | getStrategy(const Name& strategyName); |
| 91 | |
| 92 | void |
| 93 | setDefaultStrategy(shared_ptr<fw::Strategy> strategy); |
| 94 | |
| 95 | void |
| 96 | changeStrategy(shared_ptr<strategy_choice::Entry> entry, |
| 97 | shared_ptr<fw::Strategy> oldStrategy, |
| 98 | shared_ptr<fw::Strategy> newStrategy); |
| 99 | |
HangZhang | cb4fc83 | 2014-03-11 16:57:11 +0800 | [diff] [blame] | 100 | fw::Strategy& |
| 101 | findEffectiveStrategy(shared_ptr<name_tree::Entry> nameTreeEntry) const; |
| 102 | |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 103 | private: |
| 104 | NameTree& m_nameTree; |
| 105 | size_t m_nItems; |
| 106 | |
| 107 | typedef std::map<Name, shared_ptr<fw::Strategy> > StrategyInstanceTable; |
| 108 | StrategyInstanceTable m_strategyInstances; |
| 109 | }; |
| 110 | |
| 111 | inline size_t |
| 112 | StrategyChoice::size() const |
| 113 | { |
| 114 | return m_nItems; |
| 115 | } |
| 116 | |
| 117 | } // namespace nfd |
| 118 | |
Alexander Afanasyev | 613e2a9 | 2014-04-15 13:36:58 -0700 | [diff] [blame] | 119 | #endif // NFD_DAEMON_TABLE_STRATEGY_CHOICE_HPP |