78 static void loadPlugins() |
77 static void loadPlugins() |
79 { |
78 { |
80 QSensorManagerPrivate *d = sensorManagerPrivate(); |
79 QSensorManagerPrivate *d = sensorManagerPrivate(); |
81 d->pluginsLoaded = true; |
80 d->pluginsLoaded = true; |
82 |
81 |
83 qDebug() << "initializing static plugins"; |
82 SENSORLOG() << "initializing static plugins"; |
84 Q_FOREACH (CreatePluginFunc func, d->staticRegistrations) { |
83 Q_FOREACH (CreatePluginFunc func, d->staticRegistrations) { |
85 QSensorPluginInterface *plugin = func(); |
84 QSensorPluginInterface *plugin = func(); |
86 plugin->registerSensors(); |
85 plugin->registerSensors(); |
87 } |
86 } |
88 |
87 |
89 qDebug() << "initializing plugins"; |
88 SENSORLOG() << "initializing plugins"; |
90 Q_FOREACH (QSensorPluginInterface *plugin, pluginLoader()->plugins()) { |
89 Q_FOREACH (QSensorPluginInterface *plugin, pluginLoader()->plugins()) { |
91 plugin->registerSensors(); |
90 plugin->registerSensors(); |
92 } |
91 } |
93 } |
92 } |
94 |
93 |
140 |
140 |
141 QSensorManagerPrivate *d = sensorManagerPrivate(); |
141 QSensorManagerPrivate *d = sensorManagerPrivate(); |
142 if (!d->pluginsLoaded) |
142 if (!d->pluginsLoaded) |
143 loadPlugins(); |
143 loadPlugins(); |
144 |
144 |
145 //LOG() << "QSensorManager::createBackend" << "type" << sensor->type() << "identifier" << sensor->identifier(); |
145 SENSORLOG() << "QSensorManager::createBackend" << "type" << sensor->type() << "identifier" << sensor->identifier(); |
146 |
146 |
147 if (!d->backendsByType.contains(sensor->type())) { |
147 if (!d->backendsByType.contains(sensor->type())) { |
148 qDebug() << "no backends of type" << sensor->type() << "have been registered."; |
148 SENSORLOG() << "no backends of type" << sensor->type() << "have been registered."; |
149 return 0; |
149 return 0; |
150 } |
150 } |
151 |
151 |
152 const FactoryForIdentifierMap &factoryByIdentifier = d->backendsByType[sensor->type()]; |
152 const FactoryForIdentifierMap &factoryByIdentifier = d->backendsByType[sensor->type()]; |
153 QSensorBackendFactory *factory; |
153 QSensorBackendFactory *factory; |
154 QSensorBackend *backend; |
154 QSensorBackend *backend; |
155 |
155 |
156 if (sensor->identifier().isEmpty()) { |
156 if (sensor->identifier().isEmpty()) { |
157 QByteArray defaultIdentifier = QSensor::defaultSensorForType(sensor->type()); |
157 QByteArray defaultIdentifier = QSensor::defaultSensorForType(sensor->type()); |
158 //LOG() << "Trying the default" << defaultIdentifier; |
158 SENSORLOG() << "Trying the default" << defaultIdentifier; |
159 // No identifier set, try the default |
159 // No identifier set, try the default |
160 factory = factoryByIdentifier[defaultIdentifier]; |
160 factory = factoryByIdentifier[defaultIdentifier]; |
161 //LOG() << "factory" << QString().sprintf("0x%08x", (unsigned int)factory); |
161 //SENSORLOG() << "factory" << QString().sprintf("0x%08x", (unsigned int)factory); |
162 sensor->setIdentifier(defaultIdentifier); // the factory requires this |
162 sensor->setIdentifier(defaultIdentifier); // the factory requires this |
163 backend = factory->createBackend(sensor); |
163 backend = factory->createBackend(sensor); |
164 if (backend) return backend; // Got it! |
164 if (backend) goto gotbackend; // Got it! |
165 |
165 |
166 // The default failed to instantiate so try any other registered sensors for this type |
166 // The default failed to instantiate so try any other registered sensors for this type |
167 Q_FOREACH (const QByteArray &identifier, factoryByIdentifier.keys()) { |
167 Q_FOREACH (const QByteArray &identifier, factoryByIdentifier.keys()) { |
168 //LOG() << "Trying" << identifier; |
168 SENSORLOG() << "Trying" << identifier; |
169 if (identifier == defaultIdentifier) continue; // Don't do the default one again |
169 if (identifier == defaultIdentifier) continue; // Don't do the default one again |
170 factory = factoryByIdentifier[identifier]; |
170 factory = factoryByIdentifier[identifier]; |
171 //LOG() << "factory" << QString().sprintf("0x%08x", (unsigned int)factory); |
171 //SENSORLOG() << "factory" << QString().sprintf("0x%08x", (unsigned int)factory); |
172 sensor->setIdentifier(identifier); // the factory requires this |
172 sensor->setIdentifier(identifier); // the factory requires this |
173 backend = factory->createBackend(sensor); |
173 backend = factory->createBackend(sensor); |
174 if (backend) return backend; // Got it! |
174 if (backend) goto gotbackend; // Got it! |
175 } |
175 } |
176 //LOG() << "FAILED"; |
176 SENSORLOG() << "FAILED"; |
177 sensor->setIdentifier(QByteArray()); // clear the identifier |
177 sensor->setIdentifier(QByteArray()); // clear the identifier |
178 } else { |
178 } else { |
179 if (!factoryByIdentifier.contains(sensor->identifier())) { |
179 if (!factoryByIdentifier.contains(sensor->identifier())) { |
180 qDebug() << "no backend with identifier" << sensor->identifier() << "for type" << sensor->type(); |
180 SENSORLOG() << "no backend with identifier" << sensor->identifier() << "for type" << sensor->type(); |
181 return 0; |
181 return 0; |
182 } |
182 } |
183 |
183 |
184 // We were given an explicit identifier so don't substitute other backends if it fails to instantiate |
184 // We were given an explicit identifier so don't substitute other backends if it fails to instantiate |
185 factory = factoryByIdentifier[sensor->identifier()]; |
185 factory = factoryByIdentifier[sensor->identifier()]; |
186 //LOG() << "factory" << QString().sprintf("0x%08x", (unsigned int)factory); |
186 //SENSORLOG() << "factory" << QString().sprintf("0x%08x", (unsigned int)factory); |
187 backend = factory->createBackend(sensor); |
187 backend = factory->createBackend(sensor); |
188 if (backend) return backend; // Got it! |
188 if (backend) goto gotbackend; // Got it! |
189 } |
189 } |
190 |
190 |
191 qDebug() << "no suitable backend found for requested identifier" << sensor->identifier() << "and type" << sensor->type(); |
191 SENSORLOG() << "no suitable backend found for requested identifier" << sensor->identifier() << "and type" << sensor->type(); |
192 return 0; |
192 return 0; |
|
193 |
|
194 gotbackend: |
|
195 if (sensor->availableDataRates().count() == 0) { |
|
196 qWarning() << sensor->identifier() << "backend does not support any data rates. It cannot be used."; |
|
197 } |
|
198 if (sensor->dataRate() == 0) { |
|
199 qWarning() << sensor->identifier() << "backend did not supply default data rate."; |
|
200 } |
|
201 return backend; |
193 } |
202 } |
194 |
203 |
195 // ===================================================================== |
204 // ===================================================================== |
196 |
205 |
197 /*! |
206 /*! |