blob: 8e09e7ca73b3032bb6585276a6b732209c7d5c1f [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/Vector.h>
23#include <utils/Timers.h>
24
25#include <binder/Parcel.h>
26#include <binder/IInterface.h>
27
28#include <gui/Sensor.h>
29#include <gui/ISensorServer.h>
30#include <gui/ISensorEventConnection.h>
31
32namespace android {
33// ----------------------------------------------------------------------------
34
35enum {
36 GET_SENSOR_LIST = IBinder::FIRST_CALL_TRANSACTION,
37 CREATE_SENSOR_EVENT_CONNECTION,
38};
39
40class BpSensorServer : public BpInterface<ISensorServer>
41{
42public:
43 BpSensorServer(const sp<IBinder>& impl)
44 : BpInterface<ISensorServer>(impl)
45 {
46 }
47
Dan Stozad723bd72014-11-18 10:24:03 -080048 virtual ~BpSensorServer();
49
Mathias Agopian589ce852010-07-13 22:21:56 -070050 virtual Vector<Sensor> getSensorList()
51 {
52 Parcel data, reply;
Mathias Agopiana7352c92010-07-14 23:41:37 -070053 data.writeInterfaceToken(ISensorServer::getInterfaceDescriptor());
Mathias Agopian589ce852010-07-13 22:21:56 -070054 remote()->transact(GET_SENSOR_LIST, data, &reply);
55 Sensor s;
56 Vector<Sensor> v;
Dan Stozad723bd72014-11-18 10:24:03 -080057 uint32_t n = reply.readUint32();
Mathias Agopian589ce852010-07-13 22:21:56 -070058 v.setCapacity(n);
59 while (n--) {
Mathias Agopian8683fca2012-08-12 19:37:16 -070060 reply.read(s);
Mathias Agopian589ce852010-07-13 22:21:56 -070061 v.add(s);
62 }
63 return v;
64 }
65
66 virtual sp<ISensorEventConnection> createSensorEventConnection()
67 {
68 Parcel data, reply;
Mathias Agopiana7352c92010-07-14 23:41:37 -070069 data.writeInterfaceToken(ISensorServer::getInterfaceDescriptor());
Mathias Agopian589ce852010-07-13 22:21:56 -070070 remote()->transact(CREATE_SENSOR_EVENT_CONNECTION, data, &reply);
71 return interface_cast<ISensorEventConnection>(reply.readStrongBinder());
72 }
73};
74
Dan Stozad723bd72014-11-18 10:24:03 -080075// Out-of-line virtual method definition to trigger vtable emission in this
76// translation unit (see clang warning -Wweak-vtables)
77BpSensorServer::~BpSensorServer() {}
78
Mathias Agopian589ce852010-07-13 22:21:56 -070079IMPLEMENT_META_INTERFACE(SensorServer, "android.gui.SensorServer");
80
81// ----------------------------------------------------------------------
82
83status_t BnSensorServer::onTransact(
84 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
85{
86 switch(code) {
87 case GET_SENSOR_LIST: {
88 CHECK_INTERFACE(ISensorServer, data, reply);
89 Vector<Sensor> v(getSensorList());
90 size_t n = v.size();
Dan Stozad723bd72014-11-18 10:24:03 -080091 reply->writeUint32(static_cast<uint32_t>(n));
92 for (size_t i = 0; i < n; i++) {
Mathias Agopian8683fca2012-08-12 19:37:16 -070093 reply->write(v[i]);
Mathias Agopian589ce852010-07-13 22:21:56 -070094 }
95 return NO_ERROR;
Dan Stozad723bd72014-11-18 10:24:03 -080096 }
Mathias Agopian589ce852010-07-13 22:21:56 -070097 case CREATE_SENSOR_EVENT_CONNECTION: {
98 CHECK_INTERFACE(ISensorServer, data, reply);
99 sp<ISensorEventConnection> connection(createSensorEventConnection());
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800100 reply->writeStrongBinder(IInterface::asBinder(connection));
Mathias Agopian589ce852010-07-13 22:21:56 -0700101 return NO_ERROR;
Dan Stozad723bd72014-11-18 10:24:03 -0800102 }
Mathias Agopian589ce852010-07-13 22:21:56 -0700103 }
104 return BBinder::onTransact(code, data, reply, flags);
105}
106
107// ----------------------------------------------------------------------------
108}; // namespace android