8 Module::Module(const char *name
) : m_name(name
), m_moduleHandle(NULL
){
9 QString path
= modulePath(QString("lib").append(name
).append("Visualizer.so"));
10 if(path
.length() == 0) return;
11 m_moduleHandle
= dlopen(path
.toAscii().constData(), RTLD_LAZY
| RTLD_LOCAL
);
12 if(m_moduleHandle
== NULL
) {
13 qWarning("Cannot load module \"%s\". Error: %s", name
, dlerror());
14 qWarning("Last path is %s.", path
.toAscii().constData());
18 void *instantiationHandle
= dlsym(m_moduleHandle
, "AesalonVisualizerCreateInstance");
20 if(instantiationHandle
== NULL
) {
21 qWarning("Module \"%s\" does not have instantiation function.", name
);
25 ModuleInterface
*(*instantiateFunction
)();
26 *(void **)(&instantiateFunction
) = instantiationHandle
;
28 m_interface
= instantiateFunction();
30 if(m_interface
== NULL
) {
31 qWarning("Module \"%s\" failed to create ModuleInterface instance.", name
);
40 void Module::processIncoming(DataPacket
*packet
) {
41 if(m_interface
== NULL
) return;
42 m_interface
->processIncoming(packet
);
45 QString
Module::modulePath(QString filename
) {
47 QString pathList
= settings
.value("module-path", "modules/build/").toString();
48 if(filename
.length() == 0 || pathList
.length() == 0) return "";
51 QString path
= pathList
.left(pathList
.indexOf(":"));
53 QString filePath
= path
;
57 struct stat possibleStat
;
58 if(stat(filePath
.toAscii().constData(), &possibleStat
) == 0) return filePath
;
60 pathList
.remove(0, path
.length()+1);
61 } while(pathList
.contains(":"));