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