blob: 0e51e8ef0de68a4e69f59aab9b613edf93b4508f [file] [log] [blame]
Mathias Agopian589ce852010-07-13 22:21:56 -07001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <stdint.h>
18#include <sys/types.h>
19
20#include <utils/Errors.h>
21#include <utils/RefBase.h>
22#include <utils/Timers.h>
23
24#include <binder/Parcel.h>
25#include <binder/IInterface.h>
26
27#include <gui/ISensorEventConnection.h>
Mathias Agopian5cae0d02011-10-20 18:42:02 -070028#include <gui/BitTube.h>
Mathias Agopian589ce852010-07-13 22:21:56 -070029
30namespace android {
31// ----------------------------------------------------------------------------
32
33enum {
34 GET_SENSOR_CHANNEL = IBinder::FIRST_CALL_TRANSACTION,
35 ENABLE_DISABLE,
36 SET_EVENT_RATE
37};
38
39class BpSensorEventConnection : public BpInterface<ISensorEventConnection>
40{
41public:
42 BpSensorEventConnection(const sp<IBinder>& impl)
43 : BpInterface<ISensorEventConnection>(impl)
44 {
45 }
46
Mathias Agopian5cae0d02011-10-20 18:42:02 -070047 virtual sp<BitTube> getSensorChannel() const
Mathias Agopian589ce852010-07-13 22:21:56 -070048 {
49 Parcel data, reply;
Mathias Agopiana7352c92010-07-14 23:41:37 -070050 data.writeInterfaceToken(ISensorEventConnection::getInterfaceDescriptor());
Mathias Agopian589ce852010-07-13 22:21:56 -070051 remote()->transact(GET_SENSOR_CHANNEL, data, &reply);
Mathias Agopian5cae0d02011-10-20 18:42:02 -070052 return new BitTube(reply);
Mathias Agopian589ce852010-07-13 22:21:56 -070053 }
54
55 virtual status_t enableDisable(int handle, bool enabled)
56 {
57 Parcel data, reply;
Mathias Agopiana7352c92010-07-14 23:41:37 -070058 data.writeInterfaceToken(ISensorEventConnection::getInterfaceDescriptor());
Mathias Agopian589ce852010-07-13 22:21:56 -070059 data.writeInt32(handle);
60 data.writeInt32(enabled);
61 remote()->transact(ENABLE_DISABLE, data, &reply);
62 return reply.readInt32();
63 }
64
65 virtual status_t setEventRate(int handle, nsecs_t ns)
66 {
67 Parcel data, reply;
Mathias Agopiana7352c92010-07-14 23:41:37 -070068 data.writeInterfaceToken(ISensorEventConnection::getInterfaceDescriptor());
Mathias Agopian589ce852010-07-13 22:21:56 -070069 data.writeInt32(handle);
70 data.writeInt64(ns);
71 remote()->transact(SET_EVENT_RATE, data, &reply);
72 return reply.readInt32();
73 }
74};
75
76IMPLEMENT_META_INTERFACE(SensorEventConnection, "android.gui.SensorEventConnection");
77
78// ----------------------------------------------------------------------------
79
80status_t BnSensorEventConnection::onTransact(
81 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
82{
83 switch(code) {
84 case GET_SENSOR_CHANNEL: {
85 CHECK_INTERFACE(ISensorEventConnection, data, reply);
Mathias Agopian5cae0d02011-10-20 18:42:02 -070086 sp<BitTube> channel(getSensorChannel());
Mathias Agopian589ce852010-07-13 22:21:56 -070087 channel->writeToParcel(reply);
88 return NO_ERROR;
89 } break;
90 case ENABLE_DISABLE: {
91 CHECK_INTERFACE(ISensorEventConnection, data, reply);
92 int handle = data.readInt32();
93 int enabled = data.readInt32();
94 status_t result = enableDisable(handle, enabled);
95 reply->writeInt32(result);
96 return NO_ERROR;
97 } break;
98 case SET_EVENT_RATE: {
99 CHECK_INTERFACE(ISensorEventConnection, data, reply);
100 int handle = data.readInt32();
101 int ns = data.readInt64();
102 status_t result = setEventRate(handle, ns);
103 reply->writeInt32(result);
104 return NO_ERROR;
105 } break;
106 }
107 return BBinder::onTransact(code, data, reply, flags);
108}
109
110// ----------------------------------------------------------------------------
111}; // namespace android