Line data Source code
1 : /**
2 : * @file
3 : *
4 : * @brief Implementation of get/set and error plugins
5 : *
6 : * @copyright BSD License (see LICENSE.md or https://www.libelektra.org)
7 : *
8 : */
9 :
10 :
11 : #ifndef TOOLS_PLUGINS_HPP
12 : #define TOOLS_PLUGINS_HPP
13 :
14 : #include <plugin.hpp>
15 : #include <toolexcept.hpp>
16 :
17 : #include <map>
18 : #include <string>
19 : #include <vector>
20 :
21 : #include <kdb.hpp>
22 :
23 : namespace kdb
24 : {
25 :
26 : namespace tools
27 : {
28 :
29 :
30 : struct Place
31 : {
32 : int current;
33 : int max;
34 :
35 58734 : Place () : current (-1), max (0)
36 : {
37 : }
38 :
39 0 : Place (int current_, int max_) : current (current_), max (max_)
40 : {
41 : }
42 : };
43 :
44 : /**
45 : * @brief A collection of plugins (either get, set or error)
46 : */
47 13554 : class Plugins
48 : {
49 : protected:
50 : std::vector<Plugin *> plugins;
51 :
52 : std::vector<std::string> needed;
53 : std::vector<std::string> recommended;
54 : std::vector<std::string> alreadyProvided;
55 : std::vector<std::string> alreadyConflict;
56 :
57 : int nrStoragePlugins;
58 : int nrResolverPlugins;
59 :
60 : int revPostGet;
61 :
62 : std::map<std::string, Place> placementInfo;
63 :
64 : public:
65 : Plugins ();
66 :
67 : /** Add needed, provided and recommend information */
68 : void addInfo (Plugin & plugin);
69 : void addPlugin (Plugin & plugin, std::string which);
70 :
71 : /** Validate needed, and provided information.
72 : * (Recommended ignored, @see getRecommendedMissing(),
73 : * @see getNeededMissing() */
74 : bool validateProvided () const;
75 : std::vector<std::string> getNeededMissing () const;
76 : std::vector<std::string> getRecommendedMissing () const;
77 :
78 : bool checkPlacement (Plugin & plugin, std::string which);
79 : void checkStorage (Plugin & plugin);
80 : void checkResolver (Plugin & plugin);
81 : void checkOrdering (Plugin & plugin);
82 : void checkConflicts (Plugin & plugin);
83 : };
84 :
85 : /**
86 : * @brief Plugins to get configuration
87 : */
88 3012 : class GetPlugins : private Plugins
89 : {
90 : public:
91 : /**
92 : * Returns true if GetPlugins are valid afterwards.
93 : *
94 : * Will throw an exception if plugin could not
95 : * be added.
96 : */
97 : void tryPlugin (Plugin & plugin);
98 : void addPlugin (Plugin & plugin);
99 : bool validated () const;
100 :
101 : void serialise (kdb::Key & baseKey, kdb::KeySet & ret);
102 : };
103 :
104 :
105 : /**
106 : * @brief Plugins to set configuration
107 : */
108 3012 : class SetPlugins : private Plugins
109 : {
110 : public:
111 : void tryPlugin (Plugin & plugin);
112 : void addPlugin (Plugin & plugin);
113 : bool validated () const;
114 :
115 : void serialise (kdb::Key & baseKey, kdb::KeySet & ret);
116 : };
117 :
118 : /**
119 : * @brief Plugins to handle errors during configuration access
120 : */
121 3012 : class ErrorPlugins : private Plugins
122 : {
123 : public:
124 : void status (std::ostream & os) const;
125 :
126 : void tryPlugin (Plugin & plugin);
127 : void addPlugin (Plugin & plugin);
128 : bool validated () const;
129 :
130 : void serialise (kdb::Key & baseKey, kdb::KeySet & ret);
131 : };
132 : } // namespace tools
133 : } // namespace kdb
134 :
135 : #endif
|