blob: 28fcb53d8f0f523ee2b13ffa644a2693ee6d64c5 [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,
Aravind Akella724d91d2013-06-27 12:04:23 -070036 SET_EVENT_RATE,
Aravind Akella56ae4262014-07-10 16:01:10 -070037 FLUSH_SENSOR
Mathias Agopian589ce852010-07-13 22:21:56 -070038};
39
40class BpSensorEventConnection : public BpInterface<ISensorEventConnection>
41{
42public:
43 BpSensorEventConnection(const sp<IBinder>& impl)
44 : BpInterface<ISensorEventConnection>(impl)
45 {
46 }
47
Mathias Agopian5cae0d02011-10-20 18:42:02 -070048 virtual sp<BitTube> getSensorChannel() const
Mathias Agopian589ce852010-07-13 22:21:56 -070049 {
50 Parcel data, reply;
Mathias Agopiana7352c92010-07-14 23:41:37 -070051 data.writeInterfaceToken(ISensorEventConnection::getInterfaceDescriptor());
Mathias Agopian589ce852010-07-13 22:21:56 -070052 remote()->transact(GET_SENSOR_CHANNEL, data, &reply);
Mathias Agopian5cae0d02011-10-20 18:42:02 -070053 return new BitTube(reply);
Mathias Agopian589ce852010-07-13 22:21:56 -070054 }
55
Aravind Akella724d91d2013-06-27 12:04:23 -070056 virtual status_t enableDisable(int handle, bool enabled, nsecs_t samplingPeriodNs,
57 nsecs_t maxBatchReportLatencyNs, int reservedFlags)
Mathias Agopian589ce852010-07-13 22:21:56 -070058 {
59 Parcel data, reply;
Mathias Agopiana7352c92010-07-14 23:41:37 -070060 data.writeInterfaceToken(ISensorEventConnection::getInterfaceDescriptor());
Mathias Agopian589ce852010-07-13 22:21:56 -070061 data.writeInt32(handle);
62 data.writeInt32(enabled);
Aravind Akella724d91d2013-06-27 12:04:23 -070063 data.writeInt64(samplingPeriodNs);
64 data.writeInt64(maxBatchReportLatencyNs);
65 data.writeInt32(reservedFlags);
Mathias Agopian589ce852010-07-13 22:21:56 -070066 remote()->transact(ENABLE_DISABLE, data, &reply);
67 return reply.readInt32();
68 }
69
70 virtual status_t setEventRate(int handle, nsecs_t ns)
71 {
72 Parcel data, reply;
Mathias Agopiana7352c92010-07-14 23:41:37 -070073 data.writeInterfaceToken(ISensorEventConnection::getInterfaceDescriptor());
Mathias Agopian589ce852010-07-13 22:21:56 -070074 data.writeInt32(handle);
75 data.writeInt64(ns);
76 remote()->transact(SET_EVENT_RATE, data, &reply);
77 return reply.readInt32();
78 }
Aravind Akella724d91d2013-06-27 12:04:23 -070079
Aravind Akella701166d2013-10-08 14:59:26 -070080 virtual status_t flush() {
Aravind Akella724d91d2013-06-27 12:04:23 -070081 Parcel data, reply;
82 data.writeInterfaceToken(ISensorEventConnection::getInterfaceDescriptor());
Aravind Akella724d91d2013-06-27 12:04:23 -070083 remote()->transact(FLUSH_SENSOR, data, &reply);
84 return reply.readInt32();
85 }
Mathias Agopian589ce852010-07-13 22:21:56 -070086};
87
88IMPLEMENT_META_INTERFACE(SensorEventConnection, "android.gui.SensorEventConnection");
89
90// ----------------------------------------------------------------------------
91
92status_t BnSensorEventConnection::onTransact(
93 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
94{
95 switch(code) {
96 case GET_SENSOR_CHANNEL: {
97 CHECK_INTERFACE(ISensorEventConnection, data, reply);
Mathias Agopian5cae0d02011-10-20 18:42:02 -070098 sp<BitTube> channel(getSensorChannel());
Mathias Agopian589ce852010-07-13 22:21:56 -070099 channel->writeToParcel(reply);
100 return NO_ERROR;
101 } break;
102 case ENABLE_DISABLE: {
103 CHECK_INTERFACE(ISensorEventConnection, data, reply);
104 int handle = data.readInt32();
105 int enabled = data.readInt32();
Aravind Akella724d91d2013-06-27 12:04:23 -0700106 nsecs_t samplingPeriodNs = data.readInt64();
107 nsecs_t maxBatchReportLatencyNs = data.readInt64();
108 int reservedFlags = data.readInt32();
109 status_t result = enableDisable(handle, enabled, samplingPeriodNs,
110 maxBatchReportLatencyNs, reservedFlags);
Mathias Agopian589ce852010-07-13 22:21:56 -0700111 reply->writeInt32(result);
112 return NO_ERROR;
113 } break;
114 case SET_EVENT_RATE: {
115 CHECK_INTERFACE(ISensorEventConnection, data, reply);
116 int handle = data.readInt32();
117 int ns = data.readInt64();
118 status_t result = setEventRate(handle, ns);
119 reply->writeInt32(result);
120 return NO_ERROR;
121 } break;
Aravind Akella724d91d2013-06-27 12:04:23 -0700122 case FLUSH_SENSOR: {
123 CHECK_INTERFACE(ISensorEventConnection, data, reply);
Aravind Akella701166d2013-10-08 14:59:26 -0700124 status_t result = flush();
Aravind Akella724d91d2013-06-27 12:04:23 -0700125 reply->writeInt32(result);
126 return NO_ERROR;
127 } break;
Mathias Agopian589ce852010-07-13 22:21:56 -0700128 }
129 return BBinder::onTransact(code, data, reply, flags);
130}
131
132// ----------------------------------------------------------------------------
133}; // namespace android