diff options
| author | Mathias Agopian <mathias@google.com> | 2010-07-21 18:10:22 -0700 |
|---|---|---|
| committer | Mathias Agopian <mathias@google.com> | 2010-07-21 18:10:22 -0700 |
| commit | 50558b956157dad980441bf4fb44931ce834e36b (patch) | |
| tree | 2d208a78ab3a1c77d91751b8bbe5cafd9415f0d8 /libs/gui/SensorEventQueue.cpp | |
| parent | c1b11b1b37d0692bd3c63575c9f2c0d9fa566602 (diff) | |
| parent | bc54e63c84a517f0dca88ba900ff2b56719f685b (diff) | |
| download | frameworks_base-50558b956157dad980441bf4fb44931ce834e36b.zip frameworks_base-50558b956157dad980441bf4fb44931ce834e36b.tar.gz frameworks_base-50558b956157dad980441bf4fb44931ce834e36b.tar.bz2 | |
resolved conflicts for merge of bc54e63c to master
Change-Id: I4245b15b4cda6963d735442c0c6a04a0477ff5e1
Diffstat (limited to 'libs/gui/SensorEventQueue.cpp')
| -rw-r--r-- | libs/gui/SensorEventQueue.cpp | 46 |
1 files changed, 40 insertions, 6 deletions
diff --git a/libs/gui/SensorEventQueue.cpp b/libs/gui/SensorEventQueue.cpp index f922ac4..cc98656 100644 --- a/libs/gui/SensorEventQueue.cpp +++ b/libs/gui/SensorEventQueue.cpp @@ -13,11 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + +#define LOG_TAG "Sensors" + #include <stdint.h> #include <sys/types.h> #include <utils/Errors.h> #include <utils/RefBase.h> +#include <utils/PollLoop.h> #include <gui/Sensor.h> #include <gui/SensorChannel.h> @@ -68,7 +72,7 @@ ssize_t SensorEventQueue::read(ASensorEvent* events, size_t numEvents) ssize_t size = mSensorChannel->read(events, numEvents*sizeof(events[0])); if (size >= 0) { if (size % sizeof(events[0])) { - // partial write!!! should never happen. + // partial read!!! should never happen. return -EINVAL; } // returns number of events read @@ -77,18 +81,48 @@ ssize_t SensorEventQueue::read(ASensorEvent* events, size_t numEvents) return size; } -status_t SensorEventQueue::enableSensor(Sensor const* sensor) const +sp<PollLoop> SensorEventQueue::getPollLoop() const { - return mSensorEventConnection->enableDisable(sensor->getHandle(), true); + Mutex::Autolock _l(mLock); + if (mPollLoop == 0) { + mPollLoop = new PollLoop(true); + mPollLoop->setCallback(getFd(), POLLIN, NULL, NULL); + } + return mPollLoop; } -status_t SensorEventQueue::disableSensor(Sensor const* sensor) const +status_t SensorEventQueue::waitForEvent() const { - return mSensorEventConnection->enableDisable(sensor->getHandle(), false); + const int fd = getFd(); + sp<PollLoop> pollLoop(getPollLoop()); + int32_t result = pollLoop->pollOnce(-1, NULL, NULL); + return (result == fd) ? NO_ERROR : -1; } -status_t SensorEventQueue::setEventRate(Sensor const* sensor, nsecs_t ns) const +status_t SensorEventQueue::wake() const { + sp<PollLoop> pollLoop(getPollLoop()); + pollLoop->wake(); + return NO_ERROR; +} + +status_t SensorEventQueue::enableSensor(Sensor const* sensor) const { + return mSensorEventConnection->enableDisable(sensor->getHandle(), true); +} + +status_t SensorEventQueue::disableSensor(Sensor const* sensor) const { + return mSensorEventConnection->enableDisable(sensor->getHandle(), false); +} + +status_t SensorEventQueue::enableSensor(int32_t handle) const { + return mSensorEventConnection->enableDisable(handle, true); +} + +status_t SensorEventQueue::disableSensor(int32_t handle) const { + return mSensorEventConnection->enableDisable(handle, false); +} + +status_t SensorEventQueue::setEventRate(Sensor const* sensor, nsecs_t ns) const { return mSensorEventConnection->setEventRate(sensor->getHandle(), ns); } |
