1 #include "simulatorinterface.h"
5 #include <QLibraryInfo>
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
);
28 qWarning() << "Library error" << filename
<< lib
.errorString();
32 void registerSimulators()
34 bool simulatorsFound
= false;
37 #if defined(__APPLE__)
38 filters
<< "*-simulator.dylib";
39 #elif (!defined __GNUC__) || (defined __CYGWIN__)
40 filters
<< "*-simulator.dll";
42 filters
<< "*-simulator.so";
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";
55 dir
= SIMULATOR_LIB_SEARCH_PATH
;
57 foreach(QString filename
, dir
.entryList(filters
, QDir::Files
)) {
58 registerSimulator(filename
.prepend(dir
.path() + "/"));
59 simulatorsFound
= true;
65 SimulatorFactory
*getSimulatorFactory(const QString
&name
)
67 QString simuName
= name
;
69 qDebug() << "searching" << simuName
<< "simulator";
70 foreach (QString name
, registered_simulators
.keys()) {
71 if (name
.contains(simuName
)) {
73 return registered_simulators
[simuName
];
76 int pos
= simuName
.lastIndexOf('-');
79 simuName
= simuName
.mid(0, pos
);