removed PrefixPath debug line
[opentx.git] / companion / src / simulation / simulatorinterface.cpp
blobcfb0fe3582800507feb6233771666b786e327ea0
1 #include "simulatorinterface.h"
2 #include <QDebug>
3 #include <QDir>
4 #include <QLibrary>
5 #include <QLibraryInfo>
6 #include <QMap>
7 #include <QMessageBox>
8 #include "version.h"
10 QMap<QString, SimulatorFactory *> registered_simulators;
12 void registerSimulatorFactory(SimulatorFactory *factory)
14 qDebug() << "registering" << factory->name() << "simulator";
15 registered_simulators[factory->name()] = factory;
18 void registerSimulator(const QString &filename)
20 QLibrary lib(filename);
21 typedef SimulatorFactory * (*RegisterSimulator)();
22 RegisterSimulator registerSimulator = (RegisterSimulator)lib.resolve("registerSimu");
23 if (registerSimulator) {
24 SimulatorFactory *factory = registerSimulator();
25 registerSimulatorFactory(factory);
27 else {
28 qWarning() << "Library error" << filename << lib.errorString();
32 void registerSimulators()
34 bool simulatorsFound = false;
35 QDir dir(".");
36 QStringList filters;
37 #if defined(__APPLE__)
38 filters << "*-simulator.dylib";
39 #elif (!defined __GNUC__) || (defined __CYGWIN__)
40 filters << "*-simulator.dll";
41 #else
42 filters << "*-simulator.so";
43 #endif
45 foreach(QString filename, dir.entryList(filters, QDir::Files)) {
46 registerSimulator(filename.prepend("./"));
47 simulatorsFound = true;
50 #if defined(__APPLE__) || !( (!defined __GNUC__) || (defined __CYGWIN__) )
51 if (!simulatorsFound) {
52 #if defined(__APPLE__)
53 dir = QLibraryInfo::location(QLibraryInfo::PrefixPath) + "/Resources";
54 #else
55 dir = SIMULATOR_LIB_SEARCH_PATH;
56 #endif
57 foreach(QString filename, dir.entryList(filters, QDir::Files)) {
58 registerSimulator(filename.prepend(dir.path() + "/"));
59 simulatorsFound = true;
62 #endif
65 SimulatorFactory *getSimulatorFactory(const QString &name)
67 QString simuName = name;
68 while(1) {
69 qDebug() << "searching" << simuName << "simulator";
70 foreach (QString name, registered_simulators.keys()) {
71 if (name.contains(simuName)) {
72 simuName = name;
73 return registered_simulators[simuName];
76 int pos = simuName.lastIndexOf('-');
77 if (pos <= 0)
78 break;
79 simuName = simuName.mid(0, pos);
81 return NULL;