00001
00002
00003 #include "Iguana/Framework/interface/IgPluginLoader.h"
00004 #include "Iguana/Framework/interface/IgExtensionDB.h"
00005 #include "Iguana/Framework/interface/IgCapabilityDB.h"
00006 #include "classlib/utils/DebugAids.h"
00007 #include <algorithm>
00008 #include <cstring>
00009
00010
00011
00012
00013
00014
00015
00016
00017 IG_DEFINE_STATE_ELEMENT (IgPluginLoader, "Services/Global/Plugin Loader");
00018
00019
00020
00021
00022
00023 IgPluginLoader::IgPluginLoader (IgState *in)
00024 : m_state (in)
00025 {
00026 ASSERT (m_state);
00027 m_state->put (s_key, this);
00028 }
00029
00030 void
00031 IgPluginLoader::load (const std::string &name, bool prefix )
00032 { load (m_state, name, prefix); }
00033
00034 void
00035 IgPluginLoader::load (IgState *state, const std::string &name,
00036 bool prefix )
00037
00038 {
00039 IgExtensionDB *edb = IgExtensionDB::get ();
00040 IgCapabilityDB *cdb = IgCapabilityDB::get ();
00041
00042
00043
00044
00045
00046
00047 if (! prefix && ! state->get (IgStateKey::index (name)))
00048 {
00049 edb->create (name, state);
00050 cdb->load (name);
00051 }
00052
00053
00054
00055
00056
00057 else if (prefix)
00058 {
00059 const char *pfx = name.c_str ();
00060 size_t n = name.length ();
00061
00062 IgExtensionDB::Iterator ext = edb->begin ();
00063 IgExtensionDB::Iterator lastext = edb->end ();
00064 for ( ; ext != lastext; ++ext)
00065 if (! strncmp ((*ext)->name ().c_str (), pfx, n))
00066 load (state, (*ext)->name ());
00067
00068 IgCapabilityDB::Iterator cap = cdb->begin ();
00069 IgCapabilityDB::Iterator lastcap = cdb->end();
00070 for ( ; cap != lastcap; ++cap)
00071 if (! strncmp ((*cap)->name ().c_str (), pfx, n))
00072 load (state, (*cap)->name ());
00073 }
00074 }