ISensorEventConnection.cpp revision 724d91d778e71c8186399f4955de14b54812b3ed
1/* 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/BitTube.h> 29 30namespace android { 31// ---------------------------------------------------------------------------- 32 33enum { 34 GET_SENSOR_CHANNEL = IBinder::FIRST_CALL_TRANSACTION, 35 ENABLE_DISABLE, 36 SET_EVENT_RATE, 37 FLUSH_SENSOR 38}; 39 40class BpSensorEventConnection : public BpInterface<ISensorEventConnection> 41{ 42public: 43 BpSensorEventConnection(const sp<IBinder>& impl) 44 : BpInterface<ISensorEventConnection>(impl) 45 { 46 } 47 48 virtual sp<BitTube> getSensorChannel() const 49 { 50 Parcel data, reply; 51 data.writeInterfaceToken(ISensorEventConnection::getInterfaceDescriptor()); 52 remote()->transact(GET_SENSOR_CHANNEL, data, &reply); 53 return new BitTube(reply); 54 } 55 56 virtual status_t enableDisable(int handle, bool enabled, nsecs_t samplingPeriodNs, 57 nsecs_t maxBatchReportLatencyNs, int reservedFlags) 58 { 59 Parcel data, reply; 60 data.writeInterfaceToken(ISensorEventConnection::getInterfaceDescriptor()); 61 data.writeInt32(handle); 62 data.writeInt32(enabled); 63 data.writeInt64(samplingPeriodNs); 64 data.writeInt64(maxBatchReportLatencyNs); 65 data.writeInt32(reservedFlags); 66 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; 73 data.writeInterfaceToken(ISensorEventConnection::getInterfaceDescriptor()); 74 data.writeInt32(handle); 75 data.writeInt64(ns); 76 remote()->transact(SET_EVENT_RATE, data, &reply); 77 return reply.readInt32(); 78 } 79 80 virtual status_t flushSensor(int handle) { 81 Parcel data, reply; 82 data.writeInterfaceToken(ISensorEventConnection::getInterfaceDescriptor()); 83 data.writeInt32(handle); 84 remote()->transact(FLUSH_SENSOR, data, &reply); 85 return reply.readInt32(); 86 } 87}; 88 89IMPLEMENT_META_INTERFACE(SensorEventConnection, "android.gui.SensorEventConnection"); 90 91// ---------------------------------------------------------------------------- 92 93status_t BnSensorEventConnection::onTransact( 94 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) 95{ 96 switch(code) { 97 case GET_SENSOR_CHANNEL: { 98 CHECK_INTERFACE(ISensorEventConnection, data, reply); 99 sp<BitTube> channel(getSensorChannel()); 100 channel->writeToParcel(reply); 101 return NO_ERROR; 102 } break; 103 case ENABLE_DISABLE: { 104 CHECK_INTERFACE(ISensorEventConnection, data, reply); 105 int handle = data.readInt32(); 106 int enabled = data.readInt32(); 107 nsecs_t samplingPeriodNs = data.readInt64(); 108 nsecs_t maxBatchReportLatencyNs = data.readInt64(); 109 int reservedFlags = data.readInt32(); 110 status_t result = enableDisable(handle, enabled, samplingPeriodNs, 111 maxBatchReportLatencyNs, reservedFlags); 112 reply->writeInt32(result); 113 return NO_ERROR; 114 } break; 115 case SET_EVENT_RATE: { 116 CHECK_INTERFACE(ISensorEventConnection, data, reply); 117 int handle = data.readInt32(); 118 int ns = data.readInt64(); 119 status_t result = setEventRate(handle, ns); 120 reply->writeInt32(result); 121 return NO_ERROR; 122 } break; 123 case FLUSH_SENSOR: { 124 CHECK_INTERFACE(ISensorEventConnection, data, reply); 125 int handle = data.readInt32(); 126 status_t result = flushSensor(handle); 127 reply->writeInt32(result); 128 return NO_ERROR; 129 } break; 130 } 131 return BBinder::onTransact(code, data, reply, flags); 132} 133 134// ---------------------------------------------------------------------------- 135}; // namespace android 136