Host.hpp
1 //
3 // Pluma - Plug-in Management Framework
4 // Copyright (C) 2010-2012 Gil Costa (gsaurus@gmail.com)
5 //
6 // This software is provided 'as-is', without any express or implied warranty.
7 // In no event will the authors be held liable for any damages arising from the use of this software.
8 //
9 // Permission is granted to anyone to use this software for any purpose,
10 // including commercial applications, and to alter it and redistribute it freely,
11 // subject to the following restrictions:
12 //
13 // 1. The origin of this software must not be misrepresented;
14 // you must not claim that you wrote the original software.
15 // If you use this software in a product, an acknowledgment
16 // in the product documentation would be appreciated but is not required.
17 //
18 // 2. Altered source versions must be plainly marked as such,
19 // and must not be misrepresented as being the original software.
20 //
21 // 3. This notice may not be removed or altered from any source distribution.
22 //
24 
25 #ifndef PLUMA_HOST_HPP
26 #define PLUMA_HOST_HPP
27 
29 // Headers
31 #include <Pluma/Config.hpp>
32 #include <Pluma/Provider.hpp>
33 
34 #include <vector>
35 #include <list>
36 #include <map>
37 
38 namespace pluma{
39 
44 class PLUMA_API Host{
45 friend class PluginManager;
46 friend class Provider;
47 
48 
49 public:
50 
62  bool add(Provider* provider);
63 
64 
65 private:
66 
73  Host();
74 
81  ~Host();
82 
91  bool knows(const std::string& type) const;
92 
101  unsigned int getVersion(const std::string& type) const;
102 
111  unsigned int getLowestVersion(const std::string& type) const;
112 
121  void registerType(const std::string& type, unsigned int version, unsigned int lowestVersion);
122 
132  const std::list<Provider*>* getProviders(const std::string& type) const;
133 
138  void clearProviders();
139 
146  bool validateProvider(Provider* provider) const;
147 
160  bool registerProvider(Provider* provider);
161 
170  void cancelAddictions();
171 
182  bool confirmAddictions();
183 
184 
185 
187 // Member data
189 
190 private:
191 
196  struct ProviderInfo{
197  unsigned int version;
198  unsigned int lowestVersion;
199  std::list<Provider*> providers;
200  };
201 
202  typedef std::map<std::string, ProviderInfo > ProvidersMap;
203  typedef std::map<std::string, std::list<Provider*> > TempProvidersMap;
204 
205  ProvidersMap knownTypes;
206  TempProvidersMap addRequests;
207 
208 };
209 
210 } // namespace pluma
211 
212 #endif // PLUMA_HOST_HPP
Manages loaded plugins.
Interface to provide applications with objects from plugins.
Definition: Provider.hpp:42
Manages providers.
Definition: Host.hpp:44