blob: 2e3a8fdceb07a64bb3eafa8fea61f6dd74fc3ce4 [file] [log] [blame]
Junxiao Shibb5105f2014-03-03 12:06:45 -07001/* -*- 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
13namespace nfd {
14
15class StrategyChoice : noncopyable
16{
17public:
18 StrategyChoice(NameTree& nameTree, shared_ptr<fw::Strategy> defaultStrategy);
19
20public: // 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
32public: // 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
53public: // 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 Shi7bb01512014-03-05 21:34:09 -070062 /// get effective strategy for measurementsEntry
63 fw::Strategy&
64 findEffectiveStrategy(const measurements::Entry& measurementsEntry) const;
65
Junxiao Shibb5105f2014-03-03 12:06:45 -070066 /// number of entries stored
67 size_t
68 size() const;
69
70private:
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
HangZhangcb4fc832014-03-11 16:57:11 +080082 fw::Strategy&
83 findEffectiveStrategy(shared_ptr<name_tree::Entry> nameTreeEntry) const;
84
Junxiao Shibb5105f2014-03-03 12:06:45 -070085private:
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
93inline size_t
94StrategyChoice::size() const
95{
96 return m_nItems;
97}
98
99} // namespace nfd
100
101#endif // NFD_TABLE_STRATEGY_CHOICE_HPP