]> Creatis software - cpPlugins.git/blob - lib/third_party/Pluma/Host.hpp
cf049f5abcb598b5fcec6da3f5a6b23d532a0fbb
[cpPlugins.git] / lib / third_party / Pluma / Host.hpp
1 ////////////////////////////////////////////////////////////\r
2 //\r
3 // Pluma - Plug-in Management Framework\r
4 // Copyright (C) 2010-2012 Gil Costa (gsaurus@gmail.com)\r
5 //\r
6 // This software is provided 'as-is', without any express or implied warranty.\r
7 // In no event will the authors be held liable for any damages arising from the use of this software.\r
8 //\r
9 // Permission is granted to anyone to use this software for any purpose,\r
10 // including commercial applications, and to alter it and redistribute it freely,\r
11 // subject to the following restrictions:\r
12 //\r
13 // 1. The origin of this software must not be misrepresented;\r
14 //    you must not claim that you wrote the original software.\r
15 //    If you use this software in a product, an acknowledgment\r
16 //    in the product documentation would be appreciated but is not required.\r
17 //\r
18 // 2. Altered source versions must be plainly marked as such,\r
19 //    and must not be misrepresented as being the original software.\r
20 //\r
21 // 3. This notice may not be removed or altered from any source distribution.\r
22 //\r
23 ////////////////////////////////////////////////////////////\r
24 \r
25 #ifndef PLUMA_HOST_HPP\r
26 #define PLUMA_HOST_HPP\r
27 \r
28 ////////////////////////////////////////////////////////////\r
29 // Headers\r
30 ////////////////////////////////////////////////////////////\r
31 #include <Pluma/Config.hpp>\r
32 #include <Pluma/Provider.hpp>\r
33 \r
34 #include <vector>\r
35 #include <list>\r
36 #include <map>\r
37 \r
38 namespace pluma{\r
39 \r
40 ////////////////////////////////////////////////////////////\r
41 /// \brief Manages providers.\r
42 ///\r
43 ////////////////////////////////////////////////////////////\r
44 class PLUMA_API Host{\r
45 friend class PluginManager;\r
46 friend class Provider;\r
47 \r
48 \r
49 public:\r
50 \r
51     ////////////////////////////////////////////////////////////\r
52     /// \brief Add provider.\r
53     ///\r
54     /// Provider type and version are checked. Only known and\r
55     /// valid provider types are accepted.\r
56     ///\r
57     /// \param provider Provider to be added.\r
58     ///\r
59     /// \return True if the provider is accepted.\r
60     ///\r
61     ////////////////////////////////////////////////////////////\r
62     bool add(Provider* provider);\r
63 \r
64 \r
65 private:\r
66 \r
67     ////////////////////////////////////////////////////////////\r
68     /// \brief Default constructor.\r
69     ///\r
70     /// New Host instances are not publicly allowed.\r
71     ///\r
72     ////////////////////////////////////////////////////////////\r
73     Host();\r
74 \r
75     ////////////////////////////////////////////////////////////\r
76     /// \brief Destructor.\r
77     ///\r
78     /// Clears all hosted providers\r
79     ///\r
80     ////////////////////////////////////////////////////////////\r
81     ~Host();\r
82 \r
83     ////////////////////////////////////////////////////////////\r
84     /// \brief Ckeck if a provider type is registered.\r
85     ///\r
86     /// \param type Provider type id.\r
87     ///\r
88     /// \return True if the type is registered\r
89     ///\r
90     ////////////////////////////////////////////////////////////\r
91     bool knows(const std::string& type) const;\r
92 \r
93     ////////////////////////////////////////////////////////////\r
94     /// \brief Get version of a type of providers.\r
95     ///\r
96     /// \param type Provider type.\r
97     ///\r
98     /// \return The version of the provider type.\r
99     ///\r
100     ////////////////////////////////////////////////////////////\r
101     unsigned int getVersion(const std::string& type) const;\r
102 \r
103     ////////////////////////////////////////////////////////////\r
104     /// \brief Get lowest compatible version of a type of providers.\r
105     ///\r
106     /// \param type Provider type.\r
107     ///\r
108     /// \return The lowest compatible version of the provider type.\r
109     ///\r
110     ////////////////////////////////////////////////////////////\r
111     unsigned int getLowestVersion(const std::string& type) const;\r
112 \r
113     ////////////////////////////////////////////////////////////\r
114     /// \brief Register a type of providers.\r
115     ///\r
116     /// \param type Provider type.\r
117     /// \param version Current version of that provider type.\r
118     /// \param lowestVersion Lowest compatible version of that provider type.\r
119     ///\r
120     ////////////////////////////////////////////////////////////\r
121     void registerType(const std::string& type, unsigned int version, unsigned int lowestVersion);\r
122 \r
123     ////////////////////////////////////////////////////////////\r
124     /// \brief Get providers of a certain type.\r
125     ///\r
126     /// \param type Provider type.\r
127     ///\r
128     /// \return Pointer to the list of providers of that \a type,\r
129     /// or NULL if \a type is not registered.\r
130     ///\r
131     ////////////////////////////////////////////////////////////\r
132     const std::list<Provider*>* getProviders(const std::string& type) const;\r
133 \r
134     ////////////////////////////////////////////////////////////\r
135     /// \brief Clears all hosted providers.\r
136     ///\r
137     ////////////////////////////////////////////////////////////\r
138     void clearProviders();\r
139 \r
140     ////////////////////////////////////////////////////////////\r
141     /// \brief Validate provider type and version.\r
142     ///\r
143     /// \return True if the provider is acceptable.\r
144     ///\r
145     ////////////////////////////////////////////////////////////\r
146     bool validateProvider(Provider* provider) const;\r
147 \r
148     ////////////////////////////////////////////////////////////\r
149     /// \brief Clearly add a provider.\r
150     ///\r
151     /// Provider type and version are checked. Only known and\r
152     /// valid provider types are accepted.\r
153     /// If acepted, provider is directly stored.\r
154     ///\r
155     /// \param provider Provider to be added.\r
156     ///\r
157     /// \return True if the provider is accepted.\r
158     ///\r
159     ////////////////////////////////////////////////////////////\r
160     bool registerProvider(Provider* provider);\r
161 \r
162     ////////////////////////////////////////////////////////////\r
163     /// \brief Previous add calls are canceled.\r
164     ///\r
165     /// Added providers are not stored.\r
166     ///\r
167     /// \see add\r
168     ///\r
169     ////////////////////////////////////////////////////////////\r
170     void cancelAddictions();\r
171 \r
172     ////////////////////////////////////////////////////////////\r
173     /// \brief Previous add calls are confirmed.\r
174     ///\r
175     /// Added providers are finally stored.\r
176     ///\r
177     /// \return True if something was stored.\r
178     ///\r
179     /// \see add\r
180     ///\r
181     ////////////////////////////////////////////////////////////\r
182     bool confirmAddictions();\r
183 \r
184 \r
185 \r
186 ////////////////////////////////////////////////////////////\r
187 // Member data\r
188 ////////////////////////////////////////////////////////////\r
189 \r
190 private:\r
191 \r
192     ////////////////////////////////////////////////////////////\r
193     /// \brief Structure with information about a provider type.\r
194     ///\r
195     ////////////////////////////////////////////////////////////\r
196     struct ProviderInfo{\r
197         unsigned int version;\r
198         unsigned int lowestVersion;\r
199         std::list<Provider*> providers;\r
200     };\r
201 \r
202     typedef std::map<std::string, ProviderInfo > ProvidersMap;\r
203     typedef std::map<std::string, std::list<Provider*> > TempProvidersMap;\r
204 \r
205     ProvidersMap knownTypes;        ///< Map of registered types.\r
206     TempProvidersMap addRequests;   ///< Temporarily added providers\r
207 \r
208 };\r
209 \r
210 }   // namespace pluma\r
211 \r
212 #endif // PLUMA_HOST_HPP\r