/* * 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_SERVICE_H #define ANDROID_SENSOR_SERVICE_H #include #include #include #include #include #include #include #include #include #include #include #include #include // --------------------------------------------------------------------------- struct sensors_poll_device_t; struct sensors_module_t; namespace android { // --------------------------------------------------------------------------- class SensorService : public BinderService, public BnSensorServer, protected Thread { friend class BinderService; SensorService(); virtual ~SensorService(); virtual void onFirstRef(); // Thread interface virtual bool threadLoop(); // ISensorServer interface virtual Vector getSensorList(); virtual sp createSensorEventConnection(); virtual status_t dump(int fd, const Vector& args); class SensorEventConnection : public BnSensorEventConnection { virtual sp getSensorChannel() const; virtual status_t enableDisable(int handle, bool enabled); virtual status_t setEventRate(int handle, nsecs_t ns); sp const mService; sp const mChannel; SortedVector mSensorList; public: SensorEventConnection(const sp& service); virtual ~SensorEventConnection(); virtual void onFirstRef(); status_t sendEvents(sensors_event_t const* buffer, size_t count); bool hasSensor(int32_t handle) const; bool hasAnySensor() const; void addSensor(int32_t handle); void removeSensor(int32_t handle); }; class SensorRecord { SortedVector< wp > mConnections; public: SensorRecord(const sp& connection); status_t addConnection(const sp& connection); bool removeConnection(const wp& connection); size_t getNumConnections() const { return mConnections.size(); } }; SortedVector< wp > getActiveConnections() const; String8 getSensorName(int handle) const; // constants Vector mSensorList; struct sensors_poll_device_t* mSensorDevice; struct sensors_module_t* mSensorModule; Permission mDump; status_t mInitCheck; // protected by mLock mutable Mutex mLock; SortedVector< wp > mConnections; DefaultKeyedVector mActiveSensors; SortedVector< wp > mActiveConnections; public: static char const* getServiceName() { return "sensorservice"; } void cleanupConnection(const wp& connection); status_t enable(const sp& connection, int handle); status_t disable(const sp& connection, int handle); status_t setRate(const sp& connection, int handle, nsecs_t ns); }; // --------------------------------------------------------------------------- }; // namespace android #endif // ANDROID_SENSOR_SERVICE_H