29 #include <Pluma/Host.hpp>
43 if (provider == NULL){
44 fprintf(stderr,
"Trying to add a null provider.\n");
47 if (!validateProvider(provider)){
51 addRequests[ provider->plumaGetType() ].push_back(provider);
64 void Host::clearProviders(){
65 ProvidersMap::iterator it;
66 for (it = knownTypes.begin() ; it != knownTypes.end() ; ++it){
67 std::list<Provider*>& providers = it->second.providers;
68 std::list<Provider*>::iterator provIt;
69 for (provIt = providers.begin() ; provIt != providers.end() ; ++provIt){
72 std::list<Provider*>().swap(providers);
78 bool Host::knows(
const std::string& type)
const{
79 return knownTypes.find(type) != knownTypes.end();
84 unsigned int Host::getVersion(
const std::string& type)
const{
85 ProvidersMap::const_iterator it = knownTypes.find(type);
86 if (it != knownTypes.end())
87 return it->second.version;
93 unsigned int Host::getLowestVersion(
const std::string& type)
const{
94 ProvidersMap::const_iterator it = knownTypes.find(type);
95 if (it != knownTypes.end())
96 return it->second.lowestVersion;
102 void Host::registerType(
const std::string& type,
unsigned int version,
unsigned int lowestVersion){
105 pi.version = version;
106 pi.lowestVersion = lowestVersion;
107 knownTypes[type] = pi;
113 const std::list<Provider*>* Host::getProviders(
const std::string& type)
const{
114 ProvidersMap::const_iterator it = knownTypes.find(type);
115 if (it != knownTypes.end())
116 return &it->second.providers;
122 bool Host::validateProvider(Provider* provider)
const{
123 const std::string& type = provider->plumaGetType();
125 fprintf(stderr,
"%s provider type isn't registered.\n", type.c_str());
128 if (!provider->isCompatible(*
this)){
129 fprintf(stderr,
"Incompatible %s provider version.\n", type.c_str());
137 bool Host::registerProvider(Provider* provider){
138 if (!validateProvider(provider)){
142 knownTypes[ provider->plumaGetType() ].providers.push_back(provider);
148 void Host::cancelAddictions(){
149 TempProvidersMap::iterator it;
150 for( it = addRequests.begin() ; it != addRequests.end() ; ++it){
151 std::list<Provider*> lst = it->second;
152 std::list<Provider*>::iterator providerIt;
153 for (providerIt = lst.begin() ; providerIt != lst.end() ; ++providerIt){
158 TempProvidersMap().swap(addRequests);
163 bool Host::confirmAddictions(){
164 if (addRequests.empty())
return false;
165 TempProvidersMap::iterator it;
166 for( it = addRequests.begin() ; it != addRequests.end() ; ++it){
167 std::list<Provider*> lst = it->second;
168 std::list<Provider*>::iterator providerIt;
169 for (providerIt = lst.begin() ; providerIt != lst.end() ; ++providerIt){
170 knownTypes[it->first].providers.push_back(*providerIt);
174 TempProvidersMap().swap(addRequests);
Interface to provide applications with objects from plugins.
bool add(Provider *provider)
Add provider.