hidl: sensors: 1.0: Add (and run) clang-format file
Change-Id: I88beb777f386cdfadc1d39be3a36a1c3ebdee06a
This commit is contained in:
parent
61c7f9360d
commit
eed8c0648b
1
hidl/sensors/1.0/.clang-format
Symbolic link
1
hidl/sensors/1.0/.clang-format
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../../../../../build/soong/scripts/system-clang-format
|
@ -35,7 +35,7 @@ namespace implementation {
|
|||||||
static bool UseMultiHal() {
|
static bool UseMultiHal() {
|
||||||
const std::string& name = MULTI_HAL_CONFIG_FILE_PATH;
|
const std::string& name = MULTI_HAL_CONFIG_FILE_PATH;
|
||||||
struct stat buffer;
|
struct stat buffer;
|
||||||
return (stat (name.c_str(), &buffer) == 0);
|
return (stat(name.c_str(), &buffer) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Result ResultFromStatus(status_t err) {
|
static Result ResultFromStatus(status_t err) {
|
||||||
@ -53,28 +53,20 @@ static Result ResultFromStatus(status_t err) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Sensors::Sensors()
|
Sensors::Sensors() : mInitCheck(NO_INIT), mSensorModule(nullptr), mSensorDevice(nullptr) {
|
||||||
: mInitCheck(NO_INIT),
|
|
||||||
mSensorModule(nullptr),
|
|
||||||
mSensorDevice(nullptr) {
|
|
||||||
status_t err = OK;
|
status_t err = OK;
|
||||||
if (UseMultiHal()) {
|
if (UseMultiHal()) {
|
||||||
mSensorModule = ::get_multi_hal_module_info();
|
mSensorModule = ::get_multi_hal_module_info();
|
||||||
} else {
|
} else {
|
||||||
err = hw_get_module(
|
err = hw_get_module(SENSORS_HARDWARE_MODULE_ID, (hw_module_t const**)&mSensorModule);
|
||||||
SENSORS_HARDWARE_MODULE_ID,
|
|
||||||
(hw_module_t const **)&mSensorModule);
|
|
||||||
}
|
}
|
||||||
if (mSensorModule == NULL) {
|
if (mSensorModule == NULL) {
|
||||||
err = UNKNOWN_ERROR;
|
err = UNKNOWN_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (err != OK) {
|
if (err != OK) {
|
||||||
LOG(ERROR) << "Couldn't load "
|
LOG(ERROR) << "Couldn't load " << SENSORS_HARDWARE_MODULE_ID << " module ("
|
||||||
<< SENSORS_HARDWARE_MODULE_ID
|
<< strerror(-err) << ")";
|
||||||
<< " module ("
|
|
||||||
<< strerror(-err)
|
|
||||||
<< ")";
|
|
||||||
|
|
||||||
mInitCheck = err;
|
mInitCheck = err;
|
||||||
return;
|
return;
|
||||||
@ -83,11 +75,8 @@ Sensors::Sensors()
|
|||||||
err = sensors_open_1(&mSensorModule->common, &mSensorDevice);
|
err = sensors_open_1(&mSensorModule->common, &mSensorDevice);
|
||||||
|
|
||||||
if (err != OK) {
|
if (err != OK) {
|
||||||
LOG(ERROR) << "Couldn't open device for module "
|
LOG(ERROR) << "Couldn't open device for module " << SENSORS_HARDWARE_MODULE_ID << " ("
|
||||||
<< SENSORS_HARDWARE_MODULE_ID
|
<< strerror(-err) << ")";
|
||||||
<< " ("
|
|
||||||
<< strerror(-err)
|
|
||||||
<< ")";
|
|
||||||
|
|
||||||
mInitCheck = err;
|
mInitCheck = err;
|
||||||
return;
|
return;
|
||||||
@ -114,15 +103,15 @@ status_t Sensors::initCheck() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Return<void> Sensors::getSensorsList(getSensorsList_cb _hidl_cb) {
|
Return<void> Sensors::getSensorsList(getSensorsList_cb _hidl_cb) {
|
||||||
sensor_t const *list;
|
sensor_t const* list;
|
||||||
size_t count = mSensorModule->get_sensors_list(mSensorModule, &list);
|
size_t count = mSensorModule->get_sensors_list(mSensorModule, &list);
|
||||||
|
|
||||||
hidl_vec<SensorInfo> out;
|
hidl_vec<SensorInfo> out;
|
||||||
out.resize(count);
|
out.resize(count);
|
||||||
|
|
||||||
for (size_t i = 0; i < count; ++i) {
|
for (size_t i = 0; i < count; ++i) {
|
||||||
const sensor_t *src = &list[i];
|
const sensor_t* src = &list[i];
|
||||||
SensorInfo *dst = &out[i];
|
SensorInfo* dst = &out[i];
|
||||||
|
|
||||||
convertFromSensor(*src, dst);
|
convertFromSensor(*src, dst);
|
||||||
}
|
}
|
||||||
@ -141,31 +130,26 @@ int Sensors::getHalDeviceVersion() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Return<Result> Sensors::setOperationMode(OperationMode mode) {
|
Return<Result> Sensors::setOperationMode(OperationMode mode) {
|
||||||
if (getHalDeviceVersion() < SENSORS_DEVICE_API_VERSION_1_4
|
if (getHalDeviceVersion() < SENSORS_DEVICE_API_VERSION_1_4 ||
|
||||||
|| mSensorModule->set_operation_mode == nullptr) {
|
mSensorModule->set_operation_mode == nullptr) {
|
||||||
return Result::INVALID_OPERATION;
|
return Result::INVALID_OPERATION;
|
||||||
}
|
}
|
||||||
return ResultFromStatus(mSensorModule->set_operation_mode((uint32_t)mode));
|
return ResultFromStatus(mSensorModule->set_operation_mode((uint32_t)mode));
|
||||||
}
|
}
|
||||||
|
|
||||||
Return<Result> Sensors::activate(
|
Return<Result> Sensors::activate(int32_t sensor_handle, bool enabled) {
|
||||||
int32_t sensor_handle, bool enabled) {
|
return ResultFromStatus(mSensorDevice->activate(
|
||||||
return ResultFromStatus(
|
reinterpret_cast<sensors_poll_device_t*>(mSensorDevice), sensor_handle, enabled));
|
||||||
mSensorDevice->activate(
|
|
||||||
reinterpret_cast<sensors_poll_device_t *>(mSensorDevice),
|
|
||||||
sensor_handle,
|
|
||||||
enabled));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Return<void> Sensors::poll(int32_t maxCount, poll_cb _hidl_cb) {
|
Return<void> Sensors::poll(int32_t maxCount, poll_cb _hidl_cb) {
|
||||||
|
|
||||||
hidl_vec<Event> out;
|
hidl_vec<Event> out;
|
||||||
hidl_vec<SensorInfo> dynamicSensorsAdded;
|
hidl_vec<SensorInfo> dynamicSensorsAdded;
|
||||||
|
|
||||||
std::unique_ptr<sensors_event_t[]> data;
|
std::unique_ptr<sensors_event_t[]> data;
|
||||||
int err = android::NO_ERROR;
|
int err = android::NO_ERROR;
|
||||||
|
|
||||||
{ // scope of reentry lock
|
{ // scope of reentry lock
|
||||||
|
|
||||||
// This enforces a single client, meaning that a maximum of one client can call poll().
|
// This enforces a single client, meaning that a maximum of one client can call poll().
|
||||||
// If this function is re-entred, it means that we are stuck in a state that may prevent
|
// If this function is re-entred, it means that we are stuck in a state that may prevent
|
||||||
@ -175,11 +159,11 @@ Return<void> Sensors::poll(int32_t maxCount, poll_cb _hidl_cb) {
|
|||||||
//
|
//
|
||||||
// This function must not call _hidl_cb(...) or return until there is no risk of blocking.
|
// This function must not call _hidl_cb(...) or return until there is no risk of blocking.
|
||||||
std::unique_lock<std::mutex> lock(mPollLock, std::try_to_lock);
|
std::unique_lock<std::mutex> lock(mPollLock, std::try_to_lock);
|
||||||
if(!lock.owns_lock()){
|
if (!lock.owns_lock()) {
|
||||||
// cannot get the lock, hidl service will go into deadlock if it is not restarted.
|
// cannot get the lock, hidl service will go into deadlock if it is not restarted.
|
||||||
// This is guaranteed to not trigger in passthrough mode.
|
// This is guaranteed to not trigger in passthrough mode.
|
||||||
LOG(ERROR) <<
|
LOG(ERROR)
|
||||||
"ISensors::poll() re-entry. I do not know what to do except killing myself.";
|
<< "ISensors::poll() re-entry. I do not know what to do except killing myself.";
|
||||||
::exit(-1);
|
::exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -188,9 +172,8 @@ Return<void> Sensors::poll(int32_t maxCount, poll_cb _hidl_cb) {
|
|||||||
} else {
|
} else {
|
||||||
int bufferSize = maxCount <= kPollMaxBufferSize ? maxCount : kPollMaxBufferSize;
|
int bufferSize = maxCount <= kPollMaxBufferSize ? maxCount : kPollMaxBufferSize;
|
||||||
data.reset(new sensors_event_t[bufferSize]);
|
data.reset(new sensors_event_t[bufferSize]);
|
||||||
err = mSensorDevice->poll(
|
err = mSensorDevice->poll(reinterpret_cast<sensors_poll_device_t*>(mSensorDevice),
|
||||||
reinterpret_cast<sensors_poll_device_t *>(mSensorDevice),
|
data.get(), bufferSize);
|
||||||
data.get(), bufferSize);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -206,7 +189,7 @@ Return<void> Sensors::poll(int32_t maxCount, poll_cb _hidl_cb) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const dynamic_sensor_meta_event_t *dyn = &data[i].dynamic_sensor_meta;
|
const dynamic_sensor_meta_event_t* dyn = &data[i].dynamic_sensor_meta;
|
||||||
|
|
||||||
if (!dyn->connected) {
|
if (!dyn->connected) {
|
||||||
continue;
|
continue;
|
||||||
@ -231,17 +214,10 @@ Return<void> Sensors::poll(int32_t maxCount, poll_cb _hidl_cb) {
|
|||||||
return Void();
|
return Void();
|
||||||
}
|
}
|
||||||
|
|
||||||
Return<Result> Sensors::batch(
|
Return<Result> Sensors::batch(int32_t sensor_handle, int64_t sampling_period_ns,
|
||||||
int32_t sensor_handle,
|
int64_t max_report_latency_ns) {
|
||||||
int64_t sampling_period_ns,
|
return ResultFromStatus(mSensorDevice->batch(mSensorDevice, sensor_handle, 0, /*flags*/
|
||||||
int64_t max_report_latency_ns) {
|
sampling_period_ns, max_report_latency_ns));
|
||||||
return ResultFromStatus(
|
|
||||||
mSensorDevice->batch(
|
|
||||||
mSensorDevice,
|
|
||||||
sensor_handle,
|
|
||||||
0, /*flags*/
|
|
||||||
sampling_period_ns,
|
|
||||||
max_report_latency_ns));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Return<Result> Sensors::flush(int32_t sensor_handle) {
|
Return<Result> Sensors::flush(int32_t sensor_handle) {
|
||||||
@ -249,22 +225,21 @@ Return<Result> Sensors::flush(int32_t sensor_handle) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Return<Result> Sensors::injectSensorData(const Event& event) {
|
Return<Result> Sensors::injectSensorData(const Event& event) {
|
||||||
if (getHalDeviceVersion() < SENSORS_DEVICE_API_VERSION_1_4
|
if (getHalDeviceVersion() < SENSORS_DEVICE_API_VERSION_1_4 ||
|
||||||
|| mSensorDevice->inject_sensor_data == nullptr) {
|
mSensorDevice->inject_sensor_data == nullptr) {
|
||||||
return Result::INVALID_OPERATION;
|
return Result::INVALID_OPERATION;
|
||||||
}
|
}
|
||||||
|
|
||||||
sensors_event_t out;
|
sensors_event_t out;
|
||||||
convertToSensorEvent(event, &out);
|
convertToSensorEvent(event, &out);
|
||||||
|
|
||||||
return ResultFromStatus(
|
return ResultFromStatus(mSensorDevice->inject_sensor_data(mSensorDevice, &out));
|
||||||
mSensorDevice->inject_sensor_data(mSensorDevice, &out));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Return<void> Sensors::registerDirectChannel(
|
Return<void> Sensors::registerDirectChannel(const SharedMemInfo& mem,
|
||||||
const SharedMemInfo& mem, registerDirectChannel_cb _hidl_cb) {
|
registerDirectChannel_cb _hidl_cb) {
|
||||||
if (mSensorDevice->register_direct_channel == nullptr
|
if (mSensorDevice->register_direct_channel == nullptr ||
|
||||||
|| mSensorDevice->config_direct_report == nullptr) {
|
mSensorDevice->config_direct_report == nullptr) {
|
||||||
// HAL does not support
|
// HAL does not support
|
||||||
_hidl_cb(Result::INVALID_OPERATION, -1);
|
_hidl_cb(Result::INVALID_OPERATION, -1);
|
||||||
return Void();
|
return Void();
|
||||||
@ -272,8 +247,8 @@ Return<void> Sensors::registerDirectChannel(
|
|||||||
|
|
||||||
sensors_direct_mem_t m;
|
sensors_direct_mem_t m;
|
||||||
if (!convertFromSharedMemInfo(mem, &m)) {
|
if (!convertFromSharedMemInfo(mem, &m)) {
|
||||||
_hidl_cb(Result::BAD_VALUE, -1);
|
_hidl_cb(Result::BAD_VALUE, -1);
|
||||||
return Void();
|
return Void();
|
||||||
}
|
}
|
||||||
|
|
||||||
int err = mSensorDevice->register_direct_channel(mSensorDevice, &m, -1);
|
int err = mSensorDevice->register_direct_channel(mSensorDevice, &m, -1);
|
||||||
@ -288,8 +263,8 @@ Return<void> Sensors::registerDirectChannel(
|
|||||||
}
|
}
|
||||||
|
|
||||||
Return<Result> Sensors::unregisterDirectChannel(int32_t channelHandle) {
|
Return<Result> Sensors::unregisterDirectChannel(int32_t channelHandle) {
|
||||||
if (mSensorDevice->register_direct_channel == nullptr
|
if (mSensorDevice->register_direct_channel == nullptr ||
|
||||||
|| mSensorDevice->config_direct_report == nullptr) {
|
mSensorDevice->config_direct_report == nullptr) {
|
||||||
// HAL does not support
|
// HAL does not support
|
||||||
return Result::INVALID_OPERATION;
|
return Result::INVALID_OPERATION;
|
||||||
}
|
}
|
||||||
@ -299,26 +274,22 @@ Return<Result> Sensors::unregisterDirectChannel(int32_t channelHandle) {
|
|||||||
return Result::OK;
|
return Result::OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
Return<void> Sensors::configDirectReport(
|
Return<void> Sensors::configDirectReport(int32_t sensorHandle, int32_t channelHandle,
|
||||||
int32_t sensorHandle, int32_t channelHandle, RateLevel rate,
|
RateLevel rate, configDirectReport_cb _hidl_cb) {
|
||||||
configDirectReport_cb _hidl_cb) {
|
if (mSensorDevice->register_direct_channel == nullptr ||
|
||||||
if (mSensorDevice->register_direct_channel == nullptr
|
mSensorDevice->config_direct_report == nullptr) {
|
||||||
|| mSensorDevice->config_direct_report == nullptr) {
|
|
||||||
// HAL does not support
|
// HAL does not support
|
||||||
_hidl_cb(Result::INVALID_OPERATION, -1);
|
_hidl_cb(Result::INVALID_OPERATION, -1);
|
||||||
return Void();
|
return Void();
|
||||||
}
|
}
|
||||||
|
|
||||||
sensors_direct_cfg_t cfg = {
|
sensors_direct_cfg_t cfg = {.rate_level = convertFromRateLevel(rate)};
|
||||||
.rate_level = convertFromRateLevel(rate)
|
|
||||||
};
|
|
||||||
if (cfg.rate_level < 0) {
|
if (cfg.rate_level < 0) {
|
||||||
_hidl_cb(Result::BAD_VALUE, -1);
|
_hidl_cb(Result::BAD_VALUE, -1);
|
||||||
return Void();
|
return Void();
|
||||||
}
|
}
|
||||||
|
|
||||||
int err = mSensorDevice->config_direct_report(mSensorDevice,
|
int err = mSensorDevice->config_direct_report(mSensorDevice, sensorHandle, channelHandle, &cfg);
|
||||||
sensorHandle, channelHandle, &cfg);
|
|
||||||
|
|
||||||
if (rate == RateLevel::STOP) {
|
if (rate == RateLevel::STOP) {
|
||||||
_hidl_cb(ResultFromStatus(err), -1);
|
_hidl_cb(ResultFromStatus(err), -1);
|
||||||
@ -329,20 +300,18 @@ Return<void> Sensors::configDirectReport(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
void Sensors::convertFromSensorEvents(
|
void Sensors::convertFromSensorEvents(size_t count, const sensors_event_t* srcArray,
|
||||||
size_t count,
|
hidl_vec<Event>* dstVec) {
|
||||||
const sensors_event_t *srcArray,
|
|
||||||
hidl_vec<Event> *dstVec) {
|
|
||||||
for (size_t i = 0; i < count; ++i) {
|
for (size_t i = 0; i < count; ++i) {
|
||||||
const sensors_event_t &src = srcArray[i];
|
const sensors_event_t& src = srcArray[i];
|
||||||
Event *dst = &(*dstVec)[i];
|
Event* dst = &(*dstVec)[i];
|
||||||
|
|
||||||
convertFromSensorEvent(src, dst);
|
convertFromSensorEvent(src, dst);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ISensors *HIDL_FETCH_ISensors(const char * /* hal */) {
|
ISensors* HIDL_FETCH_ISensors(const char* /* hal */) {
|
||||||
Sensors *sensors = new Sensors;
|
Sensors* sensors = new Sensors;
|
||||||
if (sensors->initCheck() != OK) {
|
if (sensors->initCheck() != OK) {
|
||||||
delete sensors;
|
delete sensors;
|
||||||
sensors = nullptr;
|
sensors = nullptr;
|
||||||
|
@ -29,7 +29,6 @@ namespace sensors {
|
|||||||
namespace V1_0 {
|
namespace V1_0 {
|
||||||
namespace implementation {
|
namespace implementation {
|
||||||
|
|
||||||
|
|
||||||
struct Sensors : public ::android::hardware::sensors::V1_0::ISensors {
|
struct Sensors : public ::android::hardware::sensors::V1_0::ISensors {
|
||||||
Sensors();
|
Sensors();
|
||||||
|
|
||||||
@ -39,45 +38,41 @@ struct Sensors : public ::android::hardware::sensors::V1_0::ISensors {
|
|||||||
|
|
||||||
Return<Result> setOperationMode(OperationMode mode) override;
|
Return<Result> setOperationMode(OperationMode mode) override;
|
||||||
|
|
||||||
Return<Result> activate(
|
Return<Result> activate(int32_t sensor_handle, bool enabled) override;
|
||||||
int32_t sensor_handle, bool enabled) override;
|
|
||||||
|
|
||||||
Return<void> poll(int32_t maxCount, poll_cb _hidl_cb) override;
|
Return<void> poll(int32_t maxCount, poll_cb _hidl_cb) override;
|
||||||
|
|
||||||
Return<Result> batch(
|
Return<Result> batch(int32_t sensor_handle, int64_t sampling_period_ns,
|
||||||
int32_t sensor_handle,
|
int64_t max_report_latency_ns) override;
|
||||||
int64_t sampling_period_ns,
|
|
||||||
int64_t max_report_latency_ns) override;
|
|
||||||
|
|
||||||
Return<Result> flush(int32_t sensor_handle) override;
|
Return<Result> flush(int32_t sensor_handle) override;
|
||||||
|
|
||||||
Return<Result> injectSensorData(const Event& event) override;
|
Return<Result> injectSensorData(const Event& event) override;
|
||||||
|
|
||||||
Return<void> registerDirectChannel(
|
Return<void> registerDirectChannel(const SharedMemInfo& mem,
|
||||||
const SharedMemInfo& mem, registerDirectChannel_cb _hidl_cb) override;
|
registerDirectChannel_cb _hidl_cb) override;
|
||||||
|
|
||||||
Return<Result> unregisterDirectChannel(int32_t channelHandle) override;
|
Return<Result> unregisterDirectChannel(int32_t channelHandle) override;
|
||||||
|
|
||||||
Return<void> configDirectReport(
|
Return<void> configDirectReport(int32_t sensorHandle, int32_t channelHandle, RateLevel rate,
|
||||||
int32_t sensorHandle, int32_t channelHandle, RateLevel rate,
|
configDirectReport_cb _hidl_cb) override;
|
||||||
configDirectReport_cb _hidl_cb) override;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static constexpr int32_t kPollMaxBufferSize = 128;
|
static constexpr int32_t kPollMaxBufferSize = 128;
|
||||||
status_t mInitCheck;
|
status_t mInitCheck;
|
||||||
sensors_module_t *mSensorModule;
|
sensors_module_t* mSensorModule;
|
||||||
sensors_poll_device_1_t *mSensorDevice;
|
sensors_poll_device_1_t* mSensorDevice;
|
||||||
std::mutex mPollLock;
|
std::mutex mPollLock;
|
||||||
|
|
||||||
int getHalDeviceVersion() const;
|
int getHalDeviceVersion() const;
|
||||||
|
|
||||||
static void convertFromSensorEvents(
|
static void convertFromSensorEvents(size_t count, const sensors_event_t* src,
|
||||||
size_t count, const sensors_event_t *src, hidl_vec<Event> *dst);
|
hidl_vec<Event>* dst);
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(Sensors);
|
DISALLOW_COPY_AND_ASSIGN(Sensors);
|
||||||
};
|
};
|
||||||
|
|
||||||
extern "C" ISensors *HIDL_FETCH_ISensors(const char *name);
|
extern "C" ISensors* HIDL_FETCH_ISensors(const char* name);
|
||||||
|
|
||||||
} // namespace implementation
|
} // namespace implementation
|
||||||
} // namespace V1_0
|
} // namespace V1_0
|
||||||
|
@ -24,7 +24,7 @@ namespace sensors {
|
|||||||
namespace V1_0 {
|
namespace V1_0 {
|
||||||
namespace implementation {
|
namespace implementation {
|
||||||
|
|
||||||
void convertFromSensor(const sensor_t &src, SensorInfo *dst) {
|
void convertFromSensor(const sensor_t& src, SensorInfo* dst) {
|
||||||
dst->name = src.name;
|
dst->name = src.name;
|
||||||
dst->vendor = src.vendor;
|
dst->vendor = src.vendor;
|
||||||
dst->version = src.version;
|
dst->version = src.version;
|
||||||
@ -42,9 +42,7 @@ void convertFromSensor(const sensor_t &src, SensorInfo *dst) {
|
|||||||
dst->flags = src.flags;
|
dst->flags = src.flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
void convertToSensor(
|
void convertToSensor(const ::android::hardware::sensors::V1_0::SensorInfo& src, sensor_t* dst) {
|
||||||
const ::android::hardware::sensors::V1_0::SensorInfo &src,
|
|
||||||
sensor_t *dst) {
|
|
||||||
dst->name = strdup(src.name.c_str());
|
dst->name = strdup(src.name.c_str());
|
||||||
dst->vendor = strdup(src.vendor.c_str());
|
dst->vendor = strdup(src.vendor.c_str());
|
||||||
dst->version = src.version;
|
dst->version = src.version;
|
||||||
@ -63,7 +61,7 @@ void convertToSensor(
|
|||||||
dst->reserved[0] = dst->reserved[1] = 0;
|
dst->reserved[0] = dst->reserved[1] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void convertFromSensorEvent(const sensors_event_t &src, Event *dst) {
|
void convertFromSensorEvent(const sensors_event_t& src, Event* dst) {
|
||||||
typedef ::android::hardware::sensors::V1_0::SensorType SensorType;
|
typedef ::android::hardware::sensors::V1_0::SensorType SensorType;
|
||||||
typedef ::android::hardware::sensors::V1_0::MetaDataEventType MetaDataEventType;
|
typedef ::android::hardware::sensors::V1_0::MetaDataEventType MetaDataEventType;
|
||||||
|
|
||||||
@ -196,7 +194,7 @@ void convertFromSensorEvent(const sensors_event_t &src, Event *dst) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void convertToSensorEvent(const Event &src, sensors_event_t *dst) {
|
void convertToSensorEvent(const Event& src, sensors_event_t* dst) {
|
||||||
*dst = {.version = sizeof(sensors_event_t),
|
*dst = {.version = sizeof(sensors_event_t),
|
||||||
.sensor = src.sensorHandle,
|
.sensor = src.sensorHandle,
|
||||||
.type = (int32_t)src.sensorType,
|
.type = (int32_t)src.sensorType,
|
||||||
@ -247,8 +245,7 @@ void convertToSensorEvent(const Event &src, sensors_event_t *dst) {
|
|||||||
|
|
||||||
case SensorType::MAGNETIC_FIELD_UNCALIBRATED:
|
case SensorType::MAGNETIC_FIELD_UNCALIBRATED:
|
||||||
case SensorType::GYROSCOPE_UNCALIBRATED:
|
case SensorType::GYROSCOPE_UNCALIBRATED:
|
||||||
case SensorType::ACCELEROMETER_UNCALIBRATED:
|
case SensorType::ACCELEROMETER_UNCALIBRATED: {
|
||||||
{
|
|
||||||
dst->uncalibrated_gyro.x_uncalib = src.u.uncal.x;
|
dst->uncalibrated_gyro.x_uncalib = src.u.uncal.x;
|
||||||
dst->uncalibrated_gyro.y_uncalib = src.u.uncal.y;
|
dst->uncalibrated_gyro.y_uncalib = src.u.uncal.y;
|
||||||
dst->uncalibrated_gyro.z_uncalib = src.u.uncal.z;
|
dst->uncalibrated_gyro.z_uncalib = src.u.uncal.z;
|
||||||
@ -303,26 +300,21 @@ void convertToSensorEvent(const Event &src, sensors_event_t *dst) {
|
|||||||
dst->dynamic_sensor_meta.handle = src.u.dynamic.sensorHandle;
|
dst->dynamic_sensor_meta.handle = src.u.dynamic.sensorHandle;
|
||||||
dst->dynamic_sensor_meta.sensor = NULL; // to be filled in later
|
dst->dynamic_sensor_meta.sensor = NULL; // to be filled in later
|
||||||
|
|
||||||
memcpy(dst->dynamic_sensor_meta.uuid,
|
memcpy(dst->dynamic_sensor_meta.uuid, src.u.dynamic.uuid.data(), 16);
|
||||||
src.u.dynamic.uuid.data(),
|
|
||||||
16);
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case SensorType::ADDITIONAL_INFO: {
|
case SensorType::ADDITIONAL_INFO: {
|
||||||
const ::android::hardware::sensors::V1_0::AdditionalInfo &srcInfo =
|
const ::android::hardware::sensors::V1_0::AdditionalInfo& srcInfo = src.u.additional;
|
||||||
src.u.additional;
|
|
||||||
|
|
||||||
additional_info_event_t *dstInfo = &dst->additional_info;
|
additional_info_event_t* dstInfo = &dst->additional_info;
|
||||||
dstInfo->type = (int32_t)srcInfo.type;
|
dstInfo->type = (int32_t)srcInfo.type;
|
||||||
dstInfo->serial = srcInfo.serial;
|
dstInfo->serial = srcInfo.serial;
|
||||||
|
|
||||||
CHECK_EQ(sizeof(srcInfo.u), sizeof(dstInfo->data_int32));
|
CHECK_EQ(sizeof(srcInfo.u), sizeof(dstInfo->data_int32));
|
||||||
|
|
||||||
memcpy(dstInfo->data_int32,
|
memcpy(dstInfo->data_int32, &srcInfo.u, sizeof(dstInfo->data_int32));
|
||||||
&srcInfo.u,
|
|
||||||
sizeof(dstInfo->data_int32));
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -334,12 +326,12 @@ void convertToSensorEvent(const Event &src, sensors_event_t *dst) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool convertFromSharedMemInfo(const SharedMemInfo& memIn, sensors_direct_mem_t *memOut) {
|
bool convertFromSharedMemInfo(const SharedMemInfo& memIn, sensors_direct_mem_t* memOut) {
|
||||||
if (memOut == nullptr) {
|
if (memOut == nullptr) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(memIn.type) {
|
switch (memIn.type) {
|
||||||
case SharedMemType::ASHMEM:
|
case SharedMemType::ASHMEM:
|
||||||
memOut->type = SENSOR_DIRECT_MEM_TYPE_ASHMEM;
|
memOut->type = SENSOR_DIRECT_MEM_TYPE_ASHMEM;
|
||||||
break;
|
break;
|
||||||
@ -350,7 +342,7 @@ bool convertFromSharedMemInfo(const SharedMemInfo& memIn, sensors_direct_mem_t *
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(memIn.format) {
|
switch (memIn.format) {
|
||||||
case SharedMemFormat::SENSORS_EVENT:
|
case SharedMemFormat::SENSORS_EVENT:
|
||||||
memOut->format = SENSOR_DIRECT_FMT_SENSORS_EVENT;
|
memOut->format = SENSOR_DIRECT_FMT_SENSORS_EVENT;
|
||||||
break;
|
break;
|
||||||
@ -368,7 +360,7 @@ bool convertFromSharedMemInfo(const SharedMemInfo& memIn, sensors_direct_mem_t *
|
|||||||
}
|
}
|
||||||
|
|
||||||
int convertFromRateLevel(RateLevel rate) {
|
int convertFromRateLevel(RateLevel rate) {
|
||||||
switch(rate) {
|
switch (rate) {
|
||||||
case RateLevel::STOP:
|
case RateLevel::STOP:
|
||||||
return SENSOR_DIRECT_RATE_STOP;
|
return SENSOR_DIRECT_RATE_STOP;
|
||||||
case RateLevel::NORMAL:
|
case RateLevel::NORMAL:
|
||||||
@ -387,4 +379,3 @@ int convertFromRateLevel(RateLevel rate) {
|
|||||||
} // namespace sensors
|
} // namespace sensors
|
||||||
} // namespace hardware
|
} // namespace hardware
|
||||||
} // namespace android
|
} // namespace android
|
||||||
|
|
||||||
|
@ -27,13 +27,13 @@ namespace sensors {
|
|||||||
namespace V1_0 {
|
namespace V1_0 {
|
||||||
namespace implementation {
|
namespace implementation {
|
||||||
|
|
||||||
void convertFromSensor(const sensor_t &src, SensorInfo *dst);
|
void convertFromSensor(const sensor_t& src, SensorInfo* dst);
|
||||||
void convertToSensor(const SensorInfo &src, sensor_t *dst);
|
void convertToSensor(const SensorInfo& src, sensor_t* dst);
|
||||||
|
|
||||||
void convertFromSensorEvent(const sensors_event_t &src, Event *dst);
|
void convertFromSensorEvent(const sensors_event_t& src, Event* dst);
|
||||||
void convertToSensorEvent(const Event &src, sensors_event_t *dst);
|
void convertToSensorEvent(const Event& src, sensors_event_t* dst);
|
||||||
|
|
||||||
bool convertFromSharedMemInfo(const SharedMemInfo& memIn, sensors_direct_mem_t *memOut);
|
bool convertFromSharedMemInfo(const SharedMemInfo& memIn, sensors_direct_mem_t* memOut);
|
||||||
int convertFromRateLevel(RateLevel rate);
|
int convertFromRateLevel(RateLevel rate);
|
||||||
|
|
||||||
} // namespace implementation
|
} // namespace implementation
|
||||||
|
Loading…
Reference in New Issue
Block a user