5 #include "p2_modules.h"
7 class P2_ModuleDLEntry {
10 P2_ModuleEntry *m_entry;
15 P2_ModuleDLEntry::P2_ModuleDLEntry()
21 P2_ModuleDLEntry::~P2_ModuleDLEntry()
27 P2_ModuleFactory::P2_ModuleFactory()
31 P2_ModuleFactory::~P2_ModuleFactory()
35 bool P2_ModuleFactory::add(P2_ModuleEntry *entry)
37 P2_ModuleDLEntry *m = new P2_ModuleDLEntry();
39 m_modules.push_back(m);
43 bool P2_ModuleFactory::add(const char *fname)
45 void *dl_handle = dlopen(fname, RTLD_NOW|RTLD_GLOBAL);
49 P2_ModuleEntry *entry =
50 reinterpret_cast<P2_ModuleEntry *>
51 (dlsym(dl_handle, "p2_module_entry"));
57 P2_ModuleDLEntry *m = new P2_ModuleDLEntry();
58 m->m_dl_handle = dl_handle;
60 m_modules.push_back(m);
64 void *P2_ModuleFactory::get_interface(const char *name, int version)
66 std::list<P2_ModuleDLEntry *>::const_iterator it;
67 for (it = m_modules.begin(); it != m_modules.end(); it++)
69 P2_ModuleDLEntry *ent = *it;
70 if (!strcmp(ent->m_entry->name, name) &&
71 ent->m_entry->version == version)
73 return ent->m_entry->interface_ptr;