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#include <stdint.h>
18589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian#include <sys/types.h>
19589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian
20589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian#include <utils/Errors.h>
21589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian#include <utils/RefBase.h>
22589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian#include <utils/Timers.h>
23589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian
24589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian#include <binder/Parcel.h>
25589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian#include <binder/IInterface.h>
26589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian
27589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian#include <gui/ISensorEventConnection.h>
285cae0d0699a169e468fff3e21165f35db12f2cdeMathias Agopian#include <gui/BitTube.h>
29589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian
30589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopiannamespace android {
31589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian// ----------------------------------------------------------------------------
32589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian
33589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopianenum {
34589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian    GET_SENSOR_CHANNEL = IBinder::FIRST_CALL_TRANSACTION,
35589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian    ENABLE_DISABLE,
36589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian    SET_EVENT_RATE
37589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian};
38589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian
39589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopianclass BpSensorEventConnection : public BpInterface<ISensorEventConnection>
40589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian{
41589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopianpublic:
42589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian    BpSensorEventConnection(const sp<IBinder>& impl)
43589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian        : BpInterface<ISensorEventConnection>(impl)
44589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian    {
45589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian    }
46589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian
475cae0d0699a169e468fff3e21165f35db12f2cdeMathias Agopian    virtual sp<BitTube> getSensorChannel() const
48589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian    {
49589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian        Parcel data, reply;
50a7352c9f4a6e642c29782b19db5bc0bd98feddc8Mathias Agopian        data.writeInterfaceToken(ISensorEventConnection::getInterfaceDescriptor());
51589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian        remote()->transact(GET_SENSOR_CHANNEL, data, &reply);
525cae0d0699a169e468fff3e21165f35db12f2cdeMathias Agopian        return new BitTube(reply);
53589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian    }
54589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian
55589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian    virtual status_t enableDisable(int handle, bool enabled)
56589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian    {
57589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian        Parcel data, reply;
58a7352c9f4a6e642c29782b19db5bc0bd98feddc8Mathias Agopian        data.writeInterfaceToken(ISensorEventConnection::getInterfaceDescriptor());
59589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian        data.writeInt32(handle);
60589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian        data.writeInt32(enabled);
61589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian        remote()->transact(ENABLE_DISABLE, data, &reply);
62589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian        return reply.readInt32();
63589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian    }
64589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian
65589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian    virtual status_t setEventRate(int handle, nsecs_t ns)
66589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian    {
67589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian        Parcel data, reply;
68a7352c9f4a6e642c29782b19db5bc0bd98feddc8Mathias Agopian        data.writeInterfaceToken(ISensorEventConnection::getInterfaceDescriptor());
69589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian        data.writeInt32(handle);
70589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian        data.writeInt64(ns);
71589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian        remote()->transact(SET_EVENT_RATE, data, &reply);
72589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian        return reply.readInt32();
73589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian    }
74589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian};
75589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian
76589ce85ee4174829cfedce91b6b2509d2a4002ebMathias AgopianIMPLEMENT_META_INTERFACE(SensorEventConnection, "android.gui.SensorEventConnection");
77589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian
78589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian// ----------------------------------------------------------------------------
79589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian
80589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopianstatus_t BnSensorEventConnection::onTransact(
81589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian    uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
82589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian{
83589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian    switch(code) {
84589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian        case GET_SENSOR_CHANNEL: {
85589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian            CHECK_INTERFACE(ISensorEventConnection, data, reply);
865cae0d0699a169e468fff3e21165f35db12f2cdeMathias Agopian            sp<BitTube> channel(getSensorChannel());
87589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian            channel->writeToParcel(reply);
88589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian            return NO_ERROR;
89589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian        } break;
90589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian        case ENABLE_DISABLE: {
91589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian            CHECK_INTERFACE(ISensorEventConnection, data, reply);
92589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian            int handle = data.readInt32();
93589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian            int enabled = data.readInt32();
94589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian            status_t result = enableDisable(handle, enabled);
95589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian            reply->writeInt32(result);
96589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian            return NO_ERROR;
97589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian        } break;
98589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian        case SET_EVENT_RATE: {
99589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian            CHECK_INTERFACE(ISensorEventConnection, data, reply);
100589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian            int handle = data.readInt32();
101589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian            int ns = data.readInt64();
102589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian            status_t result = setEventRate(handle, ns);
103589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian            reply->writeInt32(result);
104589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian            return NO_ERROR;
105589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian        } break;
106589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian    }
107589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian    return BBinder::onTransact(code, data, reply, flags);
108589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian}
109589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian
110589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian// ----------------------------------------------------------------------------
111589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian}; // namespace android
112