4 #include "p2_modules.h"
6 class P2_ModuleDLEntry {
9 P2_ModuleEntry *m_entry;
14 P2_ModuleDLEntry::P2_ModuleDLEntry()
20 P2_ModuleDLEntry::~P2_ModuleDLEntry()
26 P2_ModuleFactory::P2_ModuleFactory()
30 P2_ModuleFactory::~P2_ModuleFactory()
34 bool P2_ModuleFactory::add(P2_ModuleEntry *entry)
36 P2_ModuleDLEntry *m = new P2_ModuleDLEntry();
38 m_modules.push_back(m);
42 bool P2_ModuleFactory::add(const char *fname)
44 void *dl_handle = dlopen(fname, RTLD_NOW|RTLD_GLOBAL);
48 P2_ModuleEntry *entry =
49 reinterpret_cast<P2_ModuleEntry *>
50 (dlsym(dl_handle, "p2_module_entry"));
56 P2_ModuleDLEntry *m = new P2_ModuleDLEntry();
57 m->m_dl_handle = dl_handle;
59 m_modules.push_back(m);
63 void *P2_ModuleFactory::get_interface(const char *name, int version)
65 std::list<P2_ModuleDLEntry *>::const_iterator it;
66 for (it = m_modules.begin(); it != m_modules.end(); it++)
68 P2_ModuleDLEntry *ent = *it;
69 if (!strcmp(ent->m_entry->name, name) &&
70 ent->m_entry->version == version)
72 return ent->m_entry->interface_ptr;