blob: 71110925d9e7ba69fb2dbd872b41e6cec0af46f3 [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/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
48 virtual Vector<Sensor> getSensorList()
49 {
50 Parcel data, reply;
Mathias Agopian1bf79782010-07-14 23:41:37 -070051 data.writeInterfaceToken(ISensorServer::getInterfaceDescriptor());
Mathias Agopianb957b9d2010-07-13 22:21:56 -070052 remote()->transact(GET_SENSOR_LIST, data, &reply);
53 Sensor s;
54 Vector<Sensor> v;
55 int32_t n = reply.readInt32();
56 v.setCapacity(n);
57 while (n--) {
58 reply.read(static_cast<Flattenable&>(s));
59 v.add(s);
60 }
61 return v;
62 }
63
64 virtual sp<ISensorEventConnection> createSensorEventConnection()
65 {
66 Parcel data, reply;
Mathias Agopian1bf79782010-07-14 23:41:37 -070067 data.writeInterfaceToken(ISensorServer::getInterfaceDescriptor());
Mathias Agopianb957b9d2010-07-13 22:21:56 -070068 remote()->transact(CREATE_SENSOR_EVENT_CONNECTION, data, &reply);
69 return interface_cast<ISensorEventConnection>(reply.readStrongBinder());
70 }
71};
72
73IMPLEMENT_META_INTERFACE(SensorServer, "android.gui.SensorServer");
74
75// ----------------------------------------------------------------------
76
77status_t BnSensorServer::onTransact(
78 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
79{
80 switch(code) {
81 case GET_SENSOR_LIST: {
82 CHECK_INTERFACE(ISensorServer, data, reply);
83 Vector<Sensor> v(getSensorList());
84 size_t n = v.size();
85 reply->writeInt32(n);
86 for (size_t i=0 ; i<n ; i++) {
87 reply->write(static_cast<const Flattenable&>(v[i]));
88 }
89 return NO_ERROR;
90 } break;
91 case CREATE_SENSOR_EVENT_CONNECTION: {
92 CHECK_INTERFACE(ISensorServer, data, reply);
93 sp<ISensorEventConnection> connection(createSensorEventConnection());
94 reply->writeStrongBinder(connection->asBinder());
95 return NO_ERROR;
96 } break;
97 }
98 return BBinder::onTransact(code, data, reply, flags);
99}
100
101// ----------------------------------------------------------------------------
102}; // namespace android