1 ////////////////////////////////////////////////////////////
\r
3 // Pluma - Plug-in Management Framework
\r
4 // Copyright (C) 2010-2012 Gil Costa (gsaurus@gmail.com)
\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
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
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
18 // 2. Altered source versions must be plainly marked as such,
\r
19 // and must not be misrepresented as being the original software.
\r
21 // 3. This notice may not be removed or altered from any source distribution.
\r
23 ////////////////////////////////////////////////////////////
\r
25 #ifndef PLUMA_HOST_HPP
\r
26 #define PLUMA_HOST_HPP
\r
28 ////////////////////////////////////////////////////////////
\r
30 ////////////////////////////////////////////////////////////
\r
31 #include <Pluma/Config.hpp>
\r
32 #include <Pluma/Provider.hpp>
\r
40 ////////////////////////////////////////////////////////////
\r
41 /// \brief Manages providers.
\r
43 ////////////////////////////////////////////////////////////
\r
44 class PLUMA_API Host{
\r
45 friend class PluginManager;
\r
46 friend class Provider;
\r
51 ////////////////////////////////////////////////////////////
\r
52 /// \brief Add provider.
\r
54 /// Provider type and version are checked. Only known and
\r
55 /// valid provider types are accepted.
\r
57 /// \param provider Provider to be added.
\r
59 /// \return True if the provider is accepted.
\r
61 ////////////////////////////////////////////////////////////
\r
62 bool add(Provider* provider);
\r
67 ////////////////////////////////////////////////////////////
\r
68 /// \brief Default constructor.
\r
70 /// New Host instances are not publicly allowed.
\r
72 ////////////////////////////////////////////////////////////
\r
75 ////////////////////////////////////////////////////////////
\r
76 /// \brief Destructor.
\r
78 /// Clears all hosted providers
\r
80 ////////////////////////////////////////////////////////////
\r
83 ////////////////////////////////////////////////////////////
\r
84 /// \brief Ckeck if a provider type is registered.
\r
86 /// \param type Provider type id.
\r
88 /// \return True if the type is registered
\r
90 ////////////////////////////////////////////////////////////
\r
91 bool knows(const std::string& type) const;
\r
93 ////////////////////////////////////////////////////////////
\r
94 /// \brief Get version of a type of providers.
\r
96 /// \param type Provider type.
\r
98 /// \return The version of the provider type.
\r
100 ////////////////////////////////////////////////////////////
\r
101 unsigned int getVersion(const std::string& type) const;
\r
103 ////////////////////////////////////////////////////////////
\r
104 /// \brief Get lowest compatible version of a type of providers.
\r
106 /// \param type Provider type.
\r
108 /// \return The lowest compatible version of the provider type.
\r
110 ////////////////////////////////////////////////////////////
\r
111 unsigned int getLowestVersion(const std::string& type) const;
\r
113 ////////////////////////////////////////////////////////////
\r
114 /// \brief Register a type of providers.
\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
120 ////////////////////////////////////////////////////////////
\r
121 void registerType(const std::string& type, unsigned int version, unsigned int lowestVersion);
\r
123 ////////////////////////////////////////////////////////////
\r
124 /// \brief Get providers of a certain type.
\r
126 /// \param type Provider type.
\r
128 /// \return Pointer to the list of providers of that \a type,
\r
129 /// or NULL if \a type is not registered.
\r
131 ////////////////////////////////////////////////////////////
\r
132 const std::list<Provider*>* getProviders(const std::string& type) const;
\r
134 ////////////////////////////////////////////////////////////
\r
135 /// \brief Clears all hosted providers.
\r
137 ////////////////////////////////////////////////////////////
\r
138 void clearProviders();
\r
140 ////////////////////////////////////////////////////////////
\r
141 /// \brief Validate provider type and version.
\r
143 /// \return True if the provider is acceptable.
\r
145 ////////////////////////////////////////////////////////////
\r
146 bool validateProvider(Provider* provider) const;
\r
148 ////////////////////////////////////////////////////////////
\r
149 /// \brief Clearly add a provider.
\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
155 /// \param provider Provider to be added.
\r
157 /// \return True if the provider is accepted.
\r
159 ////////////////////////////////////////////////////////////
\r
160 bool registerProvider(Provider* provider);
\r
162 ////////////////////////////////////////////////////////////
\r
163 /// \brief Previous add calls are canceled.
\r
165 /// Added providers are not stored.
\r
169 ////////////////////////////////////////////////////////////
\r
170 void cancelAddictions();
\r
172 ////////////////////////////////////////////////////////////
\r
173 /// \brief Previous add calls are confirmed.
\r
175 /// Added providers are finally stored.
\r
177 /// \return True if something was stored.
\r
181 ////////////////////////////////////////////////////////////
\r
182 bool confirmAddictions();
\r
186 ////////////////////////////////////////////////////////////
\r
188 ////////////////////////////////////////////////////////////
\r
192 ////////////////////////////////////////////////////////////
\r
193 /// \brief Structure with information about a provider type.
\r
195 ////////////////////////////////////////////////////////////
\r
196 struct ProviderInfo{
\r
197 unsigned int version;
\r
198 unsigned int lowestVersion;
\r
199 std::list<Provider*> providers;
\r
202 typedef std::map<std::string, ProviderInfo > ProvidersMap;
\r
203 typedef std::map<std::string, std::list<Provider*> > TempProvidersMap;
\r
205 ProvidersMap knownTypes; ///< Map of registered types.
\r
206 TempProvidersMap addRequests; ///< Temporarily added providers
\r
210 } // namespace pluma
\r
212 #endif // PLUMA_HOST_HPP
\r