From a4116db3002715e73ba8d48fbefabd15b91c92a2 Mon Sep 17 00:00:00 2001 From: Marty Fouts Date: Wed, 29 Jun 2011 18:13:42 -0700 Subject: ARM: omap4: tuna: Add input event reader to sensor HAL Change-Id: I34a4a4dea8b30b22046889246f164c3ea40ab2a4 Signed-off-by: Danke Xie --- libsensors/InputEventReader.cpp | 111 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 libsensors/InputEventReader.cpp (limited to 'libsensors/InputEventReader.cpp') diff --git a/libsensors/InputEventReader.cpp b/libsensors/InputEventReader.cpp new file mode 100644 index 0000000..964eda5 --- /dev/null +++ b/libsensors/InputEventReader.cpp @@ -0,0 +1,111 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include + +#include +#include + +#include + +#include + +#include "InputEventReader.h" + +/*****************************************************************************/ + +template +static inline T min(T a, T b) { + return a 0) + { + iovcnt++; + iov[1].iov_base = mBuffer; + iov[1].iov_len = numSecond * sizeof(input_event); + } + + const ssize_t nread = readv(fd, iov, iovcnt); + if (nread < 0 || nread % sizeof(input_event)) { + // we got a partial event!! + return nread < 0 ? -errno : -EINVAL; + } + + numEventsRead = nread / sizeof(input_event); + if (numEventsRead) { + mHead += numEventsRead; + mFreeSpace -= numEventsRead; + if (mHead >= mBufferEnd) + mHead -= mBufferEnd - mBuffer; + } + } + + return numEventsRead; +} + +bool InputEventCircularReader::readEvent(int fd, input_event const** events) +{ + if (mFreeSpace >= mEvents) { + ssize_t eventCount = fill(fd); + if (eventCount <= 0) + return false; + } + *events = mCurr; + return true; +} + +void InputEventCircularReader::next() +{ + mCurr++; + mFreeSpace++; + if (mCurr >= mBufferEnd) { + mCurr = mBuffer; + } +} -- cgit v1.1