Host.hpp
00001 
00002 //
00003 // Pluma - Plug-in Management Framework
00004 // Copyright (C) 2010-2012 Gil Costa (gsaurus@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024 
00025 #ifndef PLUMA_HOST_HPP
00026 #define PLUMA_HOST_HPP
00027 
00029 // Headers
00031 #include <Pluma/Config.hpp>
00032 #include <Pluma/Provider.hpp>
00033 
00034 #include <vector>
00035 #include <list>
00036 #include <map>
00037 
00038 namespace pluma{
00039 
00044 class PLUMA_API Host{
00045 friend class PluginManager;
00046 friend class Provider;
00047 
00048 
00049 public:
00050 
00062     bool add(Provider* provider);
00063 
00064 
00065 private:
00066 
00073     Host();
00074 
00081     ~Host();
00082 
00091     bool knows(const std::string& type) const;
00092 
00101     unsigned int getVersion(const std::string& type) const;
00102 
00111     unsigned int getLowestVersion(const std::string& type) const;
00112 
00121     void registerType(const std::string& type, unsigned int version, unsigned int lowestVersion);
00122 
00132     const std::list<Provider*>* getProviders(const std::string& type) const;
00133 
00138     void clearProviders();
00139 
00146     bool validateProvider(Provider* provider) const;
00147 
00160     bool registerProvider(Provider* provider);
00161 
00170     void cancelAddictions();
00171 
00182     bool confirmAddictions();
00183 
00184 
00185 
00187 // Member data
00189 
00190 private:
00191 
00196     struct ProviderInfo{
00197         unsigned int version;
00198         unsigned int lowestVersion;
00199         std::list<Provider*> providers;
00200     };
00201 
00202     typedef std::map<std::string, ProviderInfo > ProvidersMap;
00203     typedef std::map<std::string, std::list<Provider*> > TempProvidersMap;
00204 
00205     ProvidersMap knownTypes;        
00206     TempProvidersMap addRequests;   
00207 
00208 };
00209 
00210 }   // namespace pluma
00211 
00212 #endif // PLUMA_HOST_HPP