blob: 3e9d456fd85fa3dfcae9f26455c75166f4a507e5 [file] [log] [blame]
Mathias Agopianb957b9d2010-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>
28#include <gui/SensorChannel.h>
29
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
47 virtual sp<SensorChannel> getSensorChannel() const
48 {
49 Parcel data, reply;
50 remote()->transact(GET_SENSOR_CHANNEL, data, &reply);
51 return new SensorChannel(reply);
52 }
53
54 virtual status_t enableDisable(int handle, bool enabled)
55 {
56 Parcel data, reply;
57 data.writeInt32(handle);
58 data.writeInt32(enabled);
59 remote()->transact(ENABLE_DISABLE, data, &reply);
60 return reply.readInt32();
61 }
62
63 virtual status_t setEventRate(int handle, nsecs_t ns)
64 {
65 Parcel data, reply;
66 data.writeInt32(handle);
67 data.writeInt64(ns);
68 remote()->transact(SET_EVENT_RATE, data, &reply);
69 return reply.readInt32();
70 }
71};
72
73IMPLEMENT_META_INTERFACE(SensorEventConnection, "android.gui.SensorEventConnection");
74
75// ----------------------------------------------------------------------------
76
77status_t BnSensorEventConnection::onTransact(
78 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
79{
80 switch(code) {
81 case GET_SENSOR_CHANNEL: {
82 CHECK_INTERFACE(ISensorEventConnection, data, reply);
83 sp<SensorChannel> channel(getSensorChannel());
84 channel->writeToParcel(reply);
85 return NO_ERROR;
86 } break;
87 case ENABLE_DISABLE: {
88 CHECK_INTERFACE(ISensorEventConnection, data, reply);
89 int handle = data.readInt32();
90 int enabled = data.readInt32();
91 status_t result = enableDisable(handle, enabled);
92 reply->writeInt32(result);
93 return NO_ERROR;
94 } break;
95 case SET_EVENT_RATE: {
96 CHECK_INTERFACE(ISensorEventConnection, data, reply);
97 int handle = data.readInt32();
98 int ns = data.readInt64();
99 status_t result = setEventRate(handle, ns);
100 reply->writeInt32(result);
101 return NO_ERROR;
102 } break;
103 }
104 return BBinder::onTransact(code, data, reply, flags);
105}
106
107// ----------------------------------------------------------------------------
108}; // namespace android