diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /hal/gonk/GonkSensorsHelpers.cpp | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'hal/gonk/GonkSensorsHelpers.cpp')
-rw-r--r-- | hal/gonk/GonkSensorsHelpers.cpp | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/hal/gonk/GonkSensorsHelpers.cpp b/hal/gonk/GonkSensorsHelpers.cpp new file mode 100644 index 000000000..ccc940c7c --- /dev/null +++ b/hal/gonk/GonkSensorsHelpers.cpp @@ -0,0 +1,112 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=2 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "GonkSensorsHelpers.h" + +namespace mozilla { +namespace hal { + +// +// Unpacking +// + +nsresult +UnpackPDU(DaemonSocketPDU& aPDU, SensorsEvent& aOut) +{ + nsresult rv = UnpackPDU(aPDU, aOut.mType); + if (NS_FAILED(rv)) { + return rv; + } + rv = UnpackPDU(aPDU, aOut.mTimestamp); + if (NS_FAILED(rv)) { + return rv; + } + rv = UnpackPDU(aPDU, aOut.mStatus); + if (NS_FAILED(rv)) { + return rv; + } + + size_t i = 0; + + switch (aOut.mType) { + case SENSORS_TYPE_MAGNETIC_FIELD_UNCALIBRATED: + case SENSORS_TYPE_GYROSCOPE_UNCALIBRATED: + /* 6 data values */ + rv = UnpackPDU(aPDU, aOut.mData.mFloat[i++]); + if (NS_FAILED(rv)) { + return rv; + } + /* fall through */ + case SENSORS_TYPE_ROTATION_VECTOR: + case SENSORS_TYPE_GAME_ROTATION_VECTOR: + case SENSORS_TYPE_GEOMAGNETIC_ROTATION_VECTOR: + /* 5 data values */ + rv = UnpackPDU(aPDU, aOut.mData.mFloat[i++]); + if (NS_FAILED(rv)) { + return rv; + } + rv = UnpackPDU(aPDU, aOut.mData.mFloat[i++]); + if (NS_FAILED(rv)) { + return rv; + } + /* fall through */ + case SENSORS_TYPE_ACCELEROMETER: + case SENSORS_TYPE_GEOMAGNETIC_FIELD: + case SENSORS_TYPE_ORIENTATION: + case SENSORS_TYPE_GYROSCOPE: + case SENSORS_TYPE_GRAVITY: + case SENSORS_TYPE_LINEAR_ACCELERATION: + /* 3 data values */ + rv = UnpackPDU(aPDU, aOut.mData.mFloat[i++]); + if (NS_FAILED(rv)) { + return rv; + } + rv = UnpackPDU(aPDU, aOut.mData.mFloat[i++]); + if (NS_FAILED(rv)) { + return rv; + } + /* fall through */ + case SENSORS_TYPE_LIGHT: + case SENSORS_TYPE_PRESSURE: + case SENSORS_TYPE_TEMPERATURE: + case SENSORS_TYPE_PROXIMITY: + case SENSORS_TYPE_RELATIVE_HUMIDITY: + case SENSORS_TYPE_AMBIENT_TEMPERATURE: + case SENSORS_TYPE_HEART_RATE: + case SENSORS_TYPE_TILT_DETECTOR: + case SENSORS_TYPE_WAKE_GESTURE: + case SENSORS_TYPE_GLANCE_GESTURE: + case SENSORS_TYPE_PICK_UP_GESTURE: + case SENSORS_TYPE_WRIST_TILT_GESTURE: + case SENSORS_TYPE_SIGNIFICANT_MOTION: + case SENSORS_TYPE_STEP_DETECTED: + /* 1 data value */ + rv = UnpackPDU(aPDU, aOut.mData.mFloat[i++]); + if (NS_FAILED(rv)) { + return rv; + } + break; + case SENSORS_TYPE_STEP_COUNTER: + /* 1 data value */ + rv = UnpackPDU(aPDU, aOut.mData.mUint[0]); + if (NS_FAILED(rv)) { + return rv; + } + break; + default: + if (MOZ_HAL_IPC_UNPACK_WARN_IF(true, SensorsEvent)) { + return NS_ERROR_ILLEGAL_VALUE; + } + } + rv = UnpackPDU(aPDU, aOut.mDeliveryMode); + if (NS_FAILED(rv)) { + return rv; + } + return NS_OK; +} + +} // namespace hal +} // namespace mozilla |