qtmobility/src/sensors/qsensormanager.cpp
changeset 14 6fbed849b4f4
parent 11 06b8e2af4411
equal deleted inserted replaced
11:06b8e2af4411 14:6fbed849b4f4
   158         // No identifier set, try the default
   158         // No identifier set, try the default
   159         factory = factoryByIdentifier[defaultIdentifier];
   159         factory = factoryByIdentifier[defaultIdentifier];
   160         //SENSORLOG() << "factory" << QString().sprintf("0x%08x", (unsigned int)factory);
   160         //SENSORLOG() << "factory" << QString().sprintf("0x%08x", (unsigned int)factory);
   161         sensor->setIdentifier(defaultIdentifier); // the factory requires this
   161         sensor->setIdentifier(defaultIdentifier); // the factory requires this
   162         backend = factory->createBackend(sensor);
   162         backend = factory->createBackend(sensor);
   163         if (backend) goto gotbackend; // Got it!
   163         if (backend) return backend; // Got it!
   164 
   164 
   165         // The default failed to instantiate so try any other registered sensors for this type
   165         // The default failed to instantiate so try any other registered sensors for this type
   166         Q_FOREACH (const QByteArray &identifier, factoryByIdentifier.keys()) {
   166         Q_FOREACH (const QByteArray &identifier, factoryByIdentifier.keys()) {
   167             SENSORLOG() << "Trying" << identifier;
   167             SENSORLOG() << "Trying" << identifier;
   168             if (identifier == defaultIdentifier) continue; // Don't do the default one again
   168             if (identifier == defaultIdentifier) continue; // Don't do the default one again
   169             factory = factoryByIdentifier[identifier];
   169             factory = factoryByIdentifier[identifier];
   170             //SENSORLOG() << "factory" << QString().sprintf("0x%08x", (unsigned int)factory);
   170             //SENSORLOG() << "factory" << QString().sprintf("0x%08x", (unsigned int)factory);
   171             sensor->setIdentifier(identifier); // the factory requires this
   171             sensor->setIdentifier(identifier); // the factory requires this
   172             backend = factory->createBackend(sensor);
   172             backend = factory->createBackend(sensor);
   173             if (backend) goto gotbackend; // Got it!
   173             if (backend) return backend; // Got it!
   174         }
   174         }
   175         SENSORLOG() << "FAILED";
   175         SENSORLOG() << "FAILED";
   176         sensor->setIdentifier(QByteArray()); // clear the identifier
   176         sensor->setIdentifier(QByteArray()); // clear the identifier
   177     } else {
   177     } else {
   178         if (!factoryByIdentifier.contains(sensor->identifier())) {
   178         if (!factoryByIdentifier.contains(sensor->identifier())) {
   182 
   182 
   183         // We were given an explicit identifier so don't substitute other backends if it fails to instantiate
   183         // We were given an explicit identifier so don't substitute other backends if it fails to instantiate
   184         factory = factoryByIdentifier[sensor->identifier()];
   184         factory = factoryByIdentifier[sensor->identifier()];
   185         //SENSORLOG() << "factory" << QString().sprintf("0x%08x", (unsigned int)factory);
   185         //SENSORLOG() << "factory" << QString().sprintf("0x%08x", (unsigned int)factory);
   186         backend = factory->createBackend(sensor);
   186         backend = factory->createBackend(sensor);
   187         if (backend) goto gotbackend; // Got it!
   187         if (backend) return backend; // Got it!
   188     }
   188     }
   189 
   189 
   190     SENSORLOG() << "no suitable backend found for requested identifier" << sensor->identifier() << "and type" << sensor->type();
   190     SENSORLOG() << "no suitable backend found for requested identifier" << sensor->identifier() << "and type" << sensor->type();
   191     return 0;
   191     return 0;
   192 
       
   193 gotbackend:
       
   194     if (sensor->availableDataRates().count() != 0 && sensor->dataRate() == 0) {
       
   195         qWarning() << sensor->identifier() << "backend did not supply default data rate.";
       
   196     }
       
   197     return backend;
       
   198 }
   192 }
   199 
   193 
   200 // =====================================================================
   194 // =====================================================================
   201 
   195 
   202 /*!
   196 /*!