Back to index

nordugrid-arc-nox  1.1.0~rc6
resources_handling.cpp
Go to the documentation of this file.
00001 #ifdef HAVE_CONFIG_H
00002 #include <config.h>
00003 #endif
00004 
00005 #include <cstdlib>
00006 
00007 #include "resources_handling.h"
00008 
00009 namespace GridScheduler
00010 {
00011 
00012 ResourcesHandling::ResourcesHandling(void) 
00013 {
00014     // NOP
00015 }
00016 
00017 void ResourcesHandling::add(Resource &r) 
00018 {
00019     resources.insert(make_pair(r.getURL(), r));
00020 }
00021 
00022 void ResourcesHandling::remove(const std::string &id) 
00023 {
00024     resources.erase(id);
00025 }
00026 
00027 Resource &ResourcesHandling::get(const std::string &id) 
00028 {
00029     return resources[id];
00030 }
00031 
00032 bool ResourcesHandling::refresh(const std::string &id) 
00033 {
00034     resources[id].refresh();
00035     return true;
00036 }
00037 
00038 Resource &ResourcesHandling::random(void) 
00039 {
00040     int i;
00041     srand((unsigned)time(NULL));
00042     i = std::rand() % resources.size();
00043 
00044     std::map<std::string, Resource>::iterator it;
00045     it = resources.begin();
00046     for (;i > 0; it++, i--) {}
00047     std::cout << "Random selected resource: " << it->second.getURL() << std::endl;
00048     return (*it).second;
00049 }
00050 
00051 }