1589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian/*
2589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian * Copyright (C) 2010 The Android Open Source Project
3589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian *
4589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian * Licensed under the Apache License, Version 2.0 (the "License");
5589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian * you may not use this file except in compliance with the License.
6589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian * You may obtain a copy of the License at
7589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian *
8589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian *      http://www.apache.org/licenses/LICENSE-2.0
9589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian *
10589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian * Unless required by applicable law or agreed to in writing, software
11589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian * distributed under the License is distributed on an "AS IS" BASIS,
12589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian * See the License for the specific language governing permissions and
14589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian * limitations under the License.
15589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian */
16589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian
17589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian#ifndef ANDROID_SENSOR_EVENT_QUEUE_H
18589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian#define ANDROID_SENSOR_EVENT_QUEUE_H
19589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian
20589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian#include <stdint.h>
21589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian#include <sys/types.h>
22589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian
23589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian#include <utils/Errors.h>
24589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian#include <utils/RefBase.h>
25589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian#include <utils/Timers.h>
26589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian
275cae0d0699a169e468fff3e21165f35db12f2cdeMathias Agopian#include <gui/BitTube.h>
28589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian
29589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian// ----------------------------------------------------------------------------
30589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian
31589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopianstruct ALooper;
32589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopianstruct ASensorEvent;
33589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian
34589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian// Concrete types for the NDK
35589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopianstruct ASensorEventQueue {
36589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian    ALooper* looper;
37589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian};
38589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian
39589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian// ----------------------------------------------------------------------------
40589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopiannamespace android {
41589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian// ----------------------------------------------------------------------------
42589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian
43589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopianclass ISensorEventConnection;
44589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopianclass Sensor;
4559abe7e0909bf4b7bf7b9601e1e40a05f6d4fd8aJeff Brownclass Looper;
46589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian
47589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian// ----------------------------------------------------------------------------
48589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian
49589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopianclass SensorEventQueue : public ASensorEventQueue, public RefBase
50589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian{
51589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopianpublic:
52589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian            SensorEventQueue(const sp<ISensorEventConnection>& connection);
53589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian    virtual ~SensorEventQueue();
54589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian    virtual void onFirstRef();
55589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian
56589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian    int getFd() const;
577b5be95cb3903087742f1079fe89cddd8abe3696Mathias Agopian
587b5be95cb3903087742f1079fe89cddd8abe3696Mathias Agopian    static ssize_t write(const sp<BitTube>& tube,
597b5be95cb3903087742f1079fe89cddd8abe3696Mathias Agopian            ASensorEvent const* events, size_t numEvents);
607b5be95cb3903087742f1079fe89cddd8abe3696Mathias Agopian
61589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian    ssize_t read(ASensorEvent* events, size_t numEvents);
62589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian
63a7352c9f4a6e642c29782b19db5bc0bd98feddc8Mathias Agopian    status_t waitForEvent() const;
64a7352c9f4a6e642c29782b19db5bc0bd98feddc8Mathias Agopian    status_t wake() const;
65a7352c9f4a6e642c29782b19db5bc0bd98feddc8Mathias Agopian
66589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian    status_t enableSensor(Sensor const* sensor) const;
67589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian    status_t disableSensor(Sensor const* sensor) const;
68589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian    status_t setEventRate(Sensor const* sensor, nsecs_t ns) const;
69589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian
70e3c8234765050023b8a588607f819e8cc41a6363Mathias Agopian    // these are here only to support SensorManager.java
71a48bcf62b6a26f24a0bdd2b44bb39fadce499e92Mathias Agopian    status_t enableSensor(int32_t handle, int32_t us) const;
72e3c8234765050023b8a588607f819e8cc41a6363Mathias Agopian    status_t disableSensor(int32_t handle) const;
73e3c8234765050023b8a588607f819e8cc41a6363Mathias Agopian
74589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopianprivate:
7559abe7e0909bf4b7bf7b9601e1e40a05f6d4fd8aJeff Brown    sp<Looper> getLooper() const;
76589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian    sp<ISensorEventConnection> mSensorEventConnection;
775cae0d0699a169e468fff3e21165f35db12f2cdeMathias Agopian    sp<BitTube> mSensorChannel;
78a7352c9f4a6e642c29782b19db5bc0bd98feddc8Mathias Agopian    mutable Mutex mLock;
7959abe7e0909bf4b7bf7b9601e1e40a05f6d4fd8aJeff Brown    mutable sp<Looper> mLooper;
80589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian};
81589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian
82589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian// ----------------------------------------------------------------------------
83589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian}; // namespace android
84589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian
85589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian#endif // ANDROID_SENSOR_EVENT_QUEUE_H
86