From b957b9d63c88efd3a961759424987b99219adeed Mon Sep 17 00:00:00 2001 From: Mathias Agopian Date: Tue, 13 Jul 2010 22:21:56 -0700 Subject: first step at implementing the native sensor support in this commit: - implemented the C stub - implemented the binder interfaces involved - implemented most of the C++ client side missing: - SensorManager cannot connect to the SensorServer yet (because there is no SensorServer yet) Change-Id: I75010cbeef31c98d6fa62fd5d388dcef87c2636b --- include/gui/ISensorEventConnection.h | 57 +++++++++++++++++++++++ include/gui/ISensorServer.h | 57 +++++++++++++++++++++++ include/gui/Sensor.h | 88 ++++++++++++++++++++++++++++++++++++ include/gui/SensorChannel.h | 53 ++++++++++++++++++++++ include/gui/SensorEventQueue.h | 71 +++++++++++++++++++++++++++++ include/gui/SensorManager.h | 63 ++++++++++++++++++++++++++ 6 files changed, 389 insertions(+) create mode 100644 include/gui/ISensorEventConnection.h create mode 100644 include/gui/ISensorServer.h create mode 100644 include/gui/Sensor.h create mode 100644 include/gui/SensorChannel.h create mode 100644 include/gui/SensorEventQueue.h create mode 100644 include/gui/SensorManager.h (limited to 'include') diff --git a/include/gui/ISensorEventConnection.h b/include/gui/ISensorEventConnection.h new file mode 100644 index 0000000..ed4e4cc --- /dev/null +++ b/include/gui/ISensorEventConnection.h @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2010 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. + */ + +#ifndef ANDROID_GUI_ISENSOR_EVENT_CONNECTION_H +#define ANDROID_GUI_ISENSOR_EVENT_CONNECTION_H + +#include +#include + +#include +#include + +#include + +namespace android { +// ---------------------------------------------------------------------------- + +class SensorChannel; + +class ISensorEventConnection : public IInterface +{ +public: + DECLARE_META_INTERFACE(SensorEventConnection); + + virtual sp getSensorChannel() const = 0; + virtual status_t enableDisable(int handle, bool enabled) = 0; + virtual status_t setEventRate(int handle, nsecs_t ns) = 0; +}; + +// ---------------------------------------------------------------------------- + +class BnSensorEventConnection : public BnInterface +{ +public: + virtual status_t onTransact( uint32_t code, + const Parcel& data, + Parcel* reply, + uint32_t flags = 0); +}; + +// ---------------------------------------------------------------------------- +}; // namespace android + +#endif // ANDROID_GUI_ISENSOR_EVENT_CONNECTION_H diff --git a/include/gui/ISensorServer.h b/include/gui/ISensorServer.h new file mode 100644 index 0000000..3e05076 --- /dev/null +++ b/include/gui/ISensorServer.h @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2010 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. + */ + +#ifndef ANDROID_GUI_ISENSORSERVER_H +#define ANDROID_GUI_ISENSORSERVER_H + +#include +#include + +#include +#include + +#include + +namespace android { +// ---------------------------------------------------------------------------- + +class Sensor; +class ISensorEventConnection; + +class ISensorServer : public IInterface +{ +public: + DECLARE_META_INTERFACE(SensorServer); + + virtual Vector getSensorList()= 0; + virtual sp createSensorEventConnection() = 0; +}; + +// ---------------------------------------------------------------------------- + +class BnSensorServer : public BnInterface +{ +public: + virtual status_t onTransact( uint32_t code, + const Parcel& data, + Parcel* reply, + uint32_t flags = 0); +}; + +// ---------------------------------------------------------------------------- +}; // namespace android + +#endif // ANDROID_GUI_ISENSORSERVER_H diff --git a/include/gui/Sensor.h b/include/gui/Sensor.h new file mode 100644 index 0000000..86a16f1 --- /dev/null +++ b/include/gui/Sensor.h @@ -0,0 +1,88 @@ +/* + * Copyright (C) 2010 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. + */ + +#ifndef ANDROID_GUI_SENSOR_H +#define ANDROID_GUI_SENSOR_H + +#include +#include + +#include +#include +#include + +#include + +#include + +// ---------------------------------------------------------------------------- +// Concrete types for the NDK +struct ASensor { }; + +// ---------------------------------------------------------------------------- +namespace android { +// ---------------------------------------------------------------------------- + +class Parcel; + +// ---------------------------------------------------------------------------- + +class Sensor : public ASensor, public Flattenable +{ +public: + enum { + TYPE_ACCELEROMETER = ASENSOR_TYPE_ACCELEROMETER, + TYPE_MAGNETIC_FIELD = ASENSOR_TYPE_MAGNETIC_FIELD, + TYPE_GYROSCOPE = ASENSOR_TYPE_GYROSCOPE, + TYPE_LIGHT = ASENSOR_TYPE_LIGHT, + TYPE_PROXIMITY = ASENSOR_TYPE_PROXIMITY + }; + + Sensor(); + virtual ~Sensor(); + + const String8& getName() const; + const String8& getVendor() const; + int32_t getHandle() const; + int32_t getType() const; + float getMinValue() const; + float getMaxValue() const; + float getResolution() const; + float getPowerUsage() const; + + // Flattenable interface + virtual size_t getFlattenedSize() const; + virtual size_t getFdCount() const; + virtual status_t flatten(void* buffer, size_t size, + int fds[], size_t count) const; + virtual status_t unflatten(void const* buffer, size_t size, + int fds[], size_t count); + +private: + String8 mName; + String8 mVendor; + int32_t mHandle; + int32_t mType; + float mMinValue; + float mMaxValue; + float mResolution; + float mPower; +}; + +// ---------------------------------------------------------------------------- +}; // namespace android + +#endif // ANDROID_GUI_SENSOR_H diff --git a/include/gui/SensorChannel.h b/include/gui/SensorChannel.h new file mode 100644 index 0000000..bb54618 --- /dev/null +++ b/include/gui/SensorChannel.h @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2010 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. + */ + +#ifndef ANDROID_GUI_SENSOR_CHANNEL_H +#define ANDROID_GUI_SENSOR_CHANNEL_H + +#include +#include + +#include +#include + + +namespace android { +// ---------------------------------------------------------------------------- +class Parcel; + +class SensorChannel : public RefBase +{ +public: + + SensorChannel(); + SensorChannel(const Parcel& data); + virtual ~SensorChannel(); + + int getFd() const; + ssize_t write(void const* vaddr, size_t size); + ssize_t read(void* vaddr, size_t size); + + status_t writeToParcel(Parcel* reply) const; + +private: + int mSendFd; + mutable int mReceiveFd; +}; + +// ---------------------------------------------------------------------------- +}; // namespace android + +#endif // ANDROID_GUI_SENSOR_CHANNEL_H diff --git a/include/gui/SensorEventQueue.h b/include/gui/SensorEventQueue.h new file mode 100644 index 0000000..d8d8128 --- /dev/null +++ b/include/gui/SensorEventQueue.h @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2010 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. + */ + +#ifndef ANDROID_SENSOR_EVENT_QUEUE_H +#define ANDROID_SENSOR_EVENT_QUEUE_H + +#include +#include + +#include +#include +#include + +#include + +// ---------------------------------------------------------------------------- + +struct ALooper; +struct ASensorEvent; + +// Concrete types for the NDK +struct ASensorEventQueue { + ALooper* looper; +}; + +// ---------------------------------------------------------------------------- +namespace android { +// ---------------------------------------------------------------------------- + +class ISensorEventConnection; +class Sensor; + +// ---------------------------------------------------------------------------- + +class SensorEventQueue : public ASensorEventQueue, public RefBase +{ +public: + SensorEventQueue(const sp& connection); + virtual ~SensorEventQueue(); + virtual void onFirstRef(); + + int getFd() const; + ssize_t write(ASensorEvent const* events, size_t numEvents); + ssize_t read(ASensorEvent* events, size_t numEvents); + + status_t enableSensor(Sensor const* sensor) const; + status_t disableSensor(Sensor const* sensor) const; + status_t setEventRate(Sensor const* sensor, nsecs_t ns) const; + +private: + sp mSensorEventConnection; + sp mSensorChannel; +}; + +// ---------------------------------------------------------------------------- +}; // namespace android + +#endif // ANDROID_SENSOR_EVENT_QUEUE_H diff --git a/include/gui/SensorManager.h b/include/gui/SensorManager.h new file mode 100644 index 0000000..0d65334 --- /dev/null +++ b/include/gui/SensorManager.h @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2010 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. + */ + +#ifndef ANDROID_GUI_SENSOR_MANAGER_H +#define ANDROID_GUI_SENSOR_MANAGER_H + +#include +#include + +#include +#include +#include +#include + +#include + +// ---------------------------------------------------------------------------- +// Concrete types for the NDK +struct ASensorManager { }; + +// ---------------------------------------------------------------------------- +namespace android { +// ---------------------------------------------------------------------------- + +class ISensorServer; +class Sensor; +class SensorEventQueue; + +// ---------------------------------------------------------------------------- + +class SensorManager : public ASensorManager, public Singleton +{ +public: + SensorManager(); + ~SensorManager(); + + ssize_t getSensorList(Sensor**) const; + Sensor* getDefaultSensor(int type); + sp createEventQueue(); + +private: + sp mSensorServer; + Sensor* mSensorList; + Vector mSensors; +}; + +// ---------------------------------------------------------------------------- +}; // namespace android + +#endif // ANDROID_GUI_SENSOR_MANAGER_H -- cgit v1.1