Back to index

nordugrid-arc-nox  1.1.0~rc6
FinderLoader.cpp
Go to the documentation of this file.
00001 // -*- indent-tabs-mode: nil -*-
00002 
00003 #ifdef HAVE_CONFIG_H
00004 #include <config.h>
00005 #endif
00006 
00007 #include <glibmm/fileutils.h>
00008 
00009 #include <arc/ArcConfig.h>
00010 
00011 #include "Plugin.h"
00012 
00013 #include "FinderLoader.h"
00014 
00015 namespace Arc {
00016 
00017   static inline bool name_is_plugin(std::string& name) {
00018     if (name.substr(0, 3) != "lib") return false;
00019     std::string::size_type p = name.rfind('.');
00020     if(p == std::string::npos) return false;
00021     if(name.substr(p+1) != G_MODULE_SUFFIX) return false;
00022     name = name.substr(3, p - 3);
00023     return true;
00024   }
00025 
00026   const std::list<std::string> FinderLoader::GetLibrariesList(void) {
00027     BaseConfig basecfg;
00028     NS ns;
00029     Config cfg(ns);
00030     basecfg.MakeConfig(cfg);
00031     std::list<std::string> names;
00032 
00033     for (XMLNode n = cfg["ModuleManager"]; n; ++n) {
00034       for (XMLNode m = n["Path"]; m; ++m) {
00035         // Protect against insane configurations...
00036         if ((std::string)m == "/usr/lib" || (std::string)m == "/usr/lib64" ||
00037             (std::string)m == "/usr/bin" || (std::string)m == "/usr/libexec")
00038           continue;
00039         try {
00040           Glib::Dir dir((std::string)m);
00041           for (Glib::DirIterator file = dir.begin();
00042                                 file != dir.end(); file++) {
00043             std::string name = *file;
00044             if(name_is_plugin(name)) names.push_back(name);
00045           }
00046         } catch (Glib::FileError) {}
00047       }
00048     }
00049     return names;
00050   }
00051 
00052 } // namespace Arc
00053