blob: c6d49aa485670b94737374e15530421e5970ca46 [file] [log] [blame]
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -07001/*
2 * Copyright (C) 2006 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/Parcel.h>
21
22#include <utils/IDataConnection.h>
23
24namespace android {
25
26// ---------------------------------------------------------------------------
27
28enum
29{
30 CONNECT_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION,
31 DISCONNECT_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION + 1
32};
33
34class BpDataConnection : public BpInterface<IDataConnection>
35{
36public:
37 BpDataConnection::BpDataConnection(const sp<IBinder>& impl)
38 : BpInterface<IDataConnection>(impl)
39 {
40 }
41
42 virtual void connect()
43 {
44 Parcel data, reply;
45 data.writeInterfaceToken(IDataConnection::descriptor());
46 remote()->transact(CONNECT_TRANSACTION, data, &reply);
47 }
48
49 virtual void disconnect()
50 {
51 Parcel data, reply;
52 remote()->transact(DISCONNECT_TRANSACTION, data, &reply);
53 }
54};
55
56IMPLEMENT_META_INTERFACE(DataConnection, "android.utils.IDataConnection");
57
58#define CHECK_INTERFACE(interface, data, reply) \
59 do { if (!data.enforceInterface(interface::getInterfaceDescriptor())) { \
60 LOGW("Call incorrectly routed to " #interface); \
61 return PERMISSION_DENIED; \
62 } } while (0)
63
64status_t BnDataConnection::onTransact(uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
65{
66 switch(code)
67 {
68 case CONNECT_TRANSACTION:
69 {
70 CHECK_INTERFACE(IDataConnection, data, reply);
71 connect();
72 return NO_ERROR;
73 }
74
75 case DISCONNECT_TRANSACTION:
76 {
77 CHECK_INTERFACE(IDataConnection, data, reply);
78 disconnect();
79 return NO_ERROR;
80 }
81
82 default:
83 return BBinder::onTransact(code, data, reply, flags);
84 }
85}
86
87// ----------------------------------------------------------------------------
88
89}; // namespace android