Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (C) 2014 Named Data Networking Project |
| 4 | * See COPYING for copyright and distribution information. |
| 5 | */ |
| 6 | |
| 7 | #ifndef NFD_TABLE_STRATEGY_CHOICE_HPP |
| 8 | #define NFD_TABLE_STRATEGY_CHOICE_HPP |
| 9 | |
| 10 | #include "strategy-choice-entry.hpp" |
| 11 | #include "name-tree.hpp" |
| 12 | |
| 13 | namespace nfd { |
| 14 | |
| 15 | class StrategyChoice : noncopyable |
| 16 | { |
| 17 | public: |
| 18 | StrategyChoice(NameTree& nameTree, shared_ptr<fw::Strategy> defaultStrategy); |
| 19 | |
| 20 | public: // available Strategy types |
| 21 | /** \return true if strategy is installed |
| 22 | */ |
| 23 | bool |
| 24 | hasStrategy(const Name& strategyName) const; |
| 25 | |
| 26 | /** \brief install a strategy |
| 27 | * \return true if installed; false if not installed due to duplicate strategyName |
| 28 | */ |
| 29 | bool |
| 30 | install(shared_ptr<fw::Strategy> strategy); |
| 31 | |
| 32 | public: // Strategy Choice table |
| 33 | /** \brief set strategy of prefix to be strategyName |
| 34 | * \param strategyName the strategy to be used, must be installed |
| 35 | * \return true on success |
| 36 | */ |
| 37 | bool |
| 38 | insert(const Name& prefix, const Name& strategyName); |
| 39 | |
| 40 | /** \brief make prefix to inherit strategy from its parent |
| 41 | * |
| 42 | * not allowed for root prefix (ndn:/) |
| 43 | */ |
| 44 | void |
| 45 | erase(const Name& prefix); |
| 46 | |
| 47 | /** \brief get strategy Name of prefix |
| 48 | * \return strategyName at exact match, or nullptr |
| 49 | */ |
| 50 | shared_ptr<const Name> |
| 51 | get(const Name& prefix) const; |
| 52 | |
| 53 | public: // effect strategy |
| 54 | /// get effective strategy for prefix |
| 55 | fw::Strategy& |
| 56 | findEffectiveStrategy(const Name& prefix) const; |
| 57 | |
| 58 | /// get effective strategy for pitEntry |
| 59 | fw::Strategy& |
| 60 | findEffectiveStrategy(const pit::Entry& pitEntry) const; |
| 61 | |
Junxiao Shi | 7bb0151 | 2014-03-05 21:34:09 -0700 | [diff] [blame] | 62 | /// get effective strategy for measurementsEntry |
| 63 | fw::Strategy& |
| 64 | findEffectiveStrategy(const measurements::Entry& measurementsEntry) const; |
| 65 | |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 66 | /// number of entries stored |
| 67 | size_t |
| 68 | size() const; |
| 69 | |
| 70 | private: |
| 71 | shared_ptr<fw::Strategy> |
| 72 | getStrategy(const Name& strategyName); |
| 73 | |
| 74 | void |
| 75 | setDefaultStrategy(shared_ptr<fw::Strategy> strategy); |
| 76 | |
| 77 | void |
| 78 | changeStrategy(shared_ptr<strategy_choice::Entry> entry, |
| 79 | shared_ptr<fw::Strategy> oldStrategy, |
| 80 | shared_ptr<fw::Strategy> newStrategy); |
| 81 | |
HangZhang | cb4fc83 | 2014-03-11 16:57:11 +0800 | [diff] [blame^] | 82 | fw::Strategy& |
| 83 | findEffectiveStrategy(shared_ptr<name_tree::Entry> nameTreeEntry) const; |
| 84 | |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 85 | private: |
| 86 | NameTree& m_nameTree; |
| 87 | size_t m_nItems; |
| 88 | |
| 89 | typedef std::map<Name, shared_ptr<fw::Strategy> > StrategyInstanceTable; |
| 90 | StrategyInstanceTable m_strategyInstances; |
| 91 | }; |
| 92 | |
| 93 | inline size_t |
| 94 | StrategyChoice::size() const |
| 95 | { |
| 96 | return m_nItems; |
| 97 | } |
| 98 | |
| 99 | } // namespace nfd |
| 100 | |
| 101 | #endif // NFD_TABLE_STRATEGY_CHOICE_HPP |