static int _hwSensors_load( QEMUFile* f, QemudService* s, void* opaque) { HwSensors* h = opaque; /* check number of sensors */ int32_t num_sensors = qemu_get_be32(f); if (num_sensors != MAX_SENSORS) { D("%s: cannot load: snapshot requires %d sensors, %d available\n", __FUNCTION__, num_sensors, MAX_SENSORS); return -EIO; } /* load sensor state */ AndroidSensor i; for (i = 0 ; i < MAX_SENSORS; i++) { Sensor* s = &h->sensors[i]; s->enabled = qemu_get_be32(f); /* this switch ensures that a warning is raised when a new sensor is * added and is not added here as well. */ switch (i) { case ANDROID_SENSOR_ACCELERATION: s->u.acceleration.x = qemu_get_float(f); s->u.acceleration.y = qemu_get_float(f); s->u.acceleration.z = qemu_get_float(f); break; case ANDROID_SENSOR_MAGNETIC_FIELD: s->u.magnetic.x = qemu_get_float(f); s->u.magnetic.y = qemu_get_float(f); s->u.magnetic.z = qemu_get_float(f); break; case ANDROID_SENSOR_ORIENTATION: s->u.orientation.azimuth = qemu_get_float(f); s->u.orientation.pitch = qemu_get_float(f); s->u.orientation.roll = qemu_get_float(f); break; case ANDROID_SENSOR_TEMPERATURE: s->u.temperature.celsius = qemu_get_float(f); break; case MAX_SENSORS: break; } } return 0; }
static int _hwSensors_load( QEMUFile* f, QemudService* s, void* opaque) { HwSensors* h = opaque; /* check number of sensors */ int32_t num_sensors = qemu_get_be32(f); if (num_sensors > MAX_SENSORS) { D("%s: cannot load: snapshot requires %d sensors, %d available\n", __FUNCTION__, num_sensors, MAX_SENSORS); return -EIO; } /* load sensor state */ AndroidSensor i; for (i = 0 ; i < num_sensors; i++) { Sensor* s = &h->sensors[i]; s->enabled = qemu_get_be32(f); /* this switch ensures that a warning is raised when a new sensor is * added and is not added here as well. */ switch (i) { case ANDROID_SENSOR_ACCELERATION: s->u.acceleration.x = qemu_get_float(f); s->u.acceleration.y = qemu_get_float(f); s->u.acceleration.z = qemu_get_float(f); break; case ANDROID_SENSOR_MAGNETIC_FIELD: s->u.magnetic.x = qemu_get_float(f); s->u.magnetic.y = qemu_get_float(f); s->u.magnetic.z = qemu_get_float(f); break; case ANDROID_SENSOR_ORIENTATION: s->u.orientation.azimuth = qemu_get_float(f); s->u.orientation.pitch = qemu_get_float(f); s->u.orientation.roll = qemu_get_float(f); break; case ANDROID_SENSOR_TEMPERATURE: s->u.temperature.celsius = qemu_get_float(f); break; case ANDROID_SENSOR_PROXIMITY: s->u.proximity.value = qemu_get_float(f); break; case MAX_SENSORS: break; } } /* The following is necessary when we resume a snaphost * created by an older version of the emulator that provided * less hardware sensors. */ for ( ; i < MAX_SENSORS; i++ ) { h->sensors[i].enabled = 0; } return 0; }