diff options
author | Mathias Agopian <mathias@google.com> | 2010-07-14 23:41:37 -0700 |
---|---|---|
committer | Mathias Agopian <mathias@google.com> | 2010-07-19 17:57:29 -0700 |
commit | a7352c9f4a6e642c29782b19db5bc0bd98feddc8 (patch) | |
tree | 634f433fd935e8202ede570b19773f79af2c6a4b | |
parent | ac07cd613f943f662b66e5ed1eecebca9d2c3690 (diff) | |
download | frameworks_native-a7352c9f4a6e642c29782b19db5bc0bd98feddc8.zip frameworks_native-a7352c9f4a6e642c29782b19db5bc0bd98feddc8.tar.gz frameworks_native-a7352c9f4a6e642c29782b19db5bc0bd98feddc8.tar.bz2 |
new SensorService
remove old sensor service and implement SensorManager
on top of the new (native) SensorManger API.
Change-Id: Iddb77d498755da3e11646473a44d651f12f40281
-rw-r--r-- | include/gui/ISensorServer.h | 2 | ||||
-rw-r--r-- | include/gui/Sensor.h | 3 | ||||
-rw-r--r-- | include/gui/SensorEventQueue.h | 9 | ||||
-rw-r--r-- | include/gui/SensorManager.h | 6 | ||||
-rw-r--r-- | libs/gui/ISensorEventConnection.cpp | 3 | ||||
-rw-r--r-- | libs/gui/ISensorServer.cpp | 2 | ||||
-rw-r--r-- | libs/gui/Sensor.cpp | 12 | ||||
-rw-r--r-- | libs/gui/SensorEventQueue.cpp | 46 | ||||
-rw-r--r-- | libs/gui/SensorManager.cpp | 31 |
9 files changed, 97 insertions, 17 deletions
diff --git a/include/gui/ISensorServer.h b/include/gui/ISensorServer.h index 3e05076..9c8afc5 100644 --- a/include/gui/ISensorServer.h +++ b/include/gui/ISensorServer.h @@ -36,7 +36,7 @@ class ISensorServer : public IInterface public: DECLARE_META_INTERFACE(SensorServer); - virtual Vector<Sensor> getSensorList()= 0; + virtual Vector<Sensor> getSensorList() = 0; virtual sp<ISensorEventConnection> createSensorEventConnection() = 0; }; diff --git a/include/gui/Sensor.h b/include/gui/Sensor.h index 86a16f1..e696d63 100644 --- a/include/gui/Sensor.h +++ b/include/gui/Sensor.h @@ -51,7 +51,8 @@ public: TYPE_PROXIMITY = ASENSOR_TYPE_PROXIMITY }; - Sensor(); + Sensor(); + Sensor(struct sensor_t const* hwSensor); virtual ~Sensor(); const String8& getName() const; diff --git a/include/gui/SensorEventQueue.h b/include/gui/SensorEventQueue.h index d8d8128..bb03c12 100644 --- a/include/gui/SensorEventQueue.h +++ b/include/gui/SensorEventQueue.h @@ -42,6 +42,7 @@ namespace android { class ISensorEventConnection; class Sensor; +class PollLoop; // ---------------------------------------------------------------------------- @@ -56,13 +57,21 @@ public: ssize_t write(ASensorEvent const* events, size_t numEvents); ssize_t read(ASensorEvent* events, size_t numEvents); + status_t waitForEvent() const; + status_t wake() const; + status_t enableSensor(Sensor const* sensor) const; status_t disableSensor(Sensor const* sensor) const; + status_t enableSensor(int32_t handle) const; + status_t disableSensor(int32_t handle) const; status_t setEventRate(Sensor const* sensor, nsecs_t ns) const; private: + sp<PollLoop> getPollLoop() const; sp<ISensorEventConnection> mSensorEventConnection; sp<SensorChannel> mSensorChannel; + mutable Mutex mLock; + mutable sp<PollLoop> mPollLoop; }; // ---------------------------------------------------------------------------- diff --git a/include/gui/SensorManager.h b/include/gui/SensorManager.h index 0d65334..e1b1a7b 100644 --- a/include/gui/SensorManager.h +++ b/include/gui/SensorManager.h @@ -47,13 +47,13 @@ public: SensorManager(); ~SensorManager(); - ssize_t getSensorList(Sensor**) const; - Sensor* getDefaultSensor(int type); + ssize_t getSensorList(Sensor const* const** list) const; + Sensor const* getDefaultSensor(int type); sp<SensorEventQueue> createEventQueue(); private: sp<ISensorServer> mSensorServer; - Sensor* mSensorList; + Sensor const** mSensorList; Vector<Sensor> mSensors; }; diff --git a/libs/gui/ISensorEventConnection.cpp b/libs/gui/ISensorEventConnection.cpp index 3e9d456..a5083fe 100644 --- a/libs/gui/ISensorEventConnection.cpp +++ b/libs/gui/ISensorEventConnection.cpp @@ -47,6 +47,7 @@ public: virtual sp<SensorChannel> getSensorChannel() const { Parcel data, reply; + data.writeInterfaceToken(ISensorEventConnection::getInterfaceDescriptor()); remote()->transact(GET_SENSOR_CHANNEL, data, &reply); return new SensorChannel(reply); } @@ -54,6 +55,7 @@ public: virtual status_t enableDisable(int handle, bool enabled) { Parcel data, reply; + data.writeInterfaceToken(ISensorEventConnection::getInterfaceDescriptor()); data.writeInt32(handle); data.writeInt32(enabled); remote()->transact(ENABLE_DISABLE, data, &reply); @@ -63,6 +65,7 @@ public: virtual status_t setEventRate(int handle, nsecs_t ns) { Parcel data, reply; + data.writeInterfaceToken(ISensorEventConnection::getInterfaceDescriptor()); data.writeInt32(handle); data.writeInt64(ns); remote()->transact(SET_EVENT_RATE, data, &reply); diff --git a/libs/gui/ISensorServer.cpp b/libs/gui/ISensorServer.cpp index c6177bc..7111092 100644 --- a/libs/gui/ISensorServer.cpp +++ b/libs/gui/ISensorServer.cpp @@ -48,6 +48,7 @@ public: virtual Vector<Sensor> getSensorList() { Parcel data, reply; + data.writeInterfaceToken(ISensorServer::getInterfaceDescriptor()); remote()->transact(GET_SENSOR_LIST, data, &reply); Sensor s; Vector<Sensor> v; @@ -63,6 +64,7 @@ public: virtual sp<ISensorEventConnection> createSensorEventConnection() { Parcel data, reply; + data.writeInterfaceToken(ISensorServer::getInterfaceDescriptor()); remote()->transact(CREATE_SENSOR_EVENT_CONNECTION, data, &reply); return interface_cast<ISensorEventConnection>(reply.readStrongBinder()); } diff --git a/libs/gui/Sensor.cpp b/libs/gui/Sensor.cpp index 1fdd285..48e1cb7 100644 --- a/libs/gui/Sensor.cpp +++ b/libs/gui/Sensor.cpp @@ -36,6 +36,18 @@ Sensor::Sensor() { } +Sensor::Sensor(struct sensor_t const* hwSensor) +{ + mName = hwSensor->name; + mVendor = hwSensor->vendor; + mHandle = hwSensor->handle; + mType = hwSensor->type; + mMinValue = 0; // FIXME: minValue + mMaxValue = hwSensor->maxRange; // FIXME: maxValue + mResolution = hwSensor->resolution; + mPower = hwSensor->power; +} + Sensor::~Sensor() { } 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); } diff --git a/libs/gui/SensorManager.cpp b/libs/gui/SensorManager.cpp index cd89285..d719efb 100644 --- a/libs/gui/SensorManager.cpp +++ b/libs/gui/SensorManager.cpp @@ -14,6 +14,8 @@ * limitations under the License. */ +#define LOG_TAG "Sensors" + #include <stdint.h> #include <sys/types.h> @@ -21,6 +23,8 @@ #include <utils/RefBase.h> #include <utils/Singleton.h> +#include <binder/IServiceManager.h> + #include <gui/ISensorServer.h> #include <gui/ISensorEventConnection.h> #include <gui/Sensor.h> @@ -36,25 +40,40 @@ ANDROID_SINGLETON_STATIC_INSTANCE(SensorManager) SensorManager::SensorManager() : mSensorList(0) { + const String16 name("sensorservice"); + while (getService(name, &mSensorServer) != NO_ERROR) { + usleep(250000); + } + mSensors = mSensorServer->getSensorList(); - // TODO: needs implementation + size_t count = mSensors.size(); + mSensorList = (Sensor const**)malloc(count * sizeof(Sensor*)); + for (size_t i=0 ; i<count ; i++) { + mSensorList[i] = mSensors.array() + i; + } } SensorManager::~SensorManager() { - // TODO: needs implementation + free(mSensorList); } -ssize_t SensorManager::getSensorList(Sensor** list) const +ssize_t SensorManager::getSensorList(Sensor const* const** list) const { *list = mSensorList; return mSensors.size(); } -Sensor* SensorManager::getDefaultSensor(int type) +Sensor const* SensorManager::getDefaultSensor(int type) { - // TODO: needs implementation - return mSensorList; + // For now we just return the first sensor of that type we find. + // in the future it will make sense to let the SensorService make + // that decision. + for (size_t i=0 ; i<mSensors.size() ; i++) { + if (mSensorList[i]->getType() == type) + return mSensorList[i]; + } + return NULL; } sp<SensorEventQueue> SensorManager::createEventQueue() |