1 //
2 //  Copyright (C) 2015 Google, Inc.
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 "service/common/bluetooth/binder/IBluetoothGattClientCallback.h"
18 
19 #include <base/logging.h>
20 #include <binder/Parcel.h>
21 
22 using android::IBinder;
23 using android::Parcel;
24 using android::sp;
25 using android::status_t;
26 
27 namespace ipc {
28 namespace binder {
29 
30 // static
31 const char IBluetoothGattClientCallback::kServiceName[] =
32     "bluetooth-gatt-client-callback-service";
33 
34 // BnBluetoothGattClientCallback (server) implementation
35 // ========================================================
36 
onTransact(uint32_t code,const Parcel & data,Parcel * reply,uint32_t flags)37 status_t BnBluetoothGattClientCallback::onTransact(
38     uint32_t code,
39     const Parcel& data,
40     Parcel* reply,
41     uint32_t flags) {
42   VLOG(2) << "IBluetoothGattClientCallback: " << code;
43   if (!data.checkInterface(this))
44     return android::PERMISSION_DENIED;
45 
46   switch (code) {
47   case ON_CLIENT_REGISTERED_TRANSACTION: {
48     int status = data.readInt32();
49     int client_id = data.readInt32();
50     OnClientRegistered(status, client_id);
51     return android::NO_ERROR;
52   }
53   default:
54     return BBinder::onTransact(code, data, reply, flags);
55   }
56 }
57 
58 // BpBluetoothGattClientCallback (client) implementation
59 // ========================================================
60 
BpBluetoothGattClientCallback(const sp<IBinder> & impl)61 BpBluetoothGattClientCallback::BpBluetoothGattClientCallback(
62     const sp<IBinder>& impl)
63     : BpInterface<IBluetoothGattClientCallback>(impl) {
64 }
65 
OnClientRegistered(int status,int client_id)66 void BpBluetoothGattClientCallback::OnClientRegistered(
67     int status, int client_id) {
68   Parcel data, reply;
69 
70   data.writeInterfaceToken(
71       IBluetoothGattClientCallback::getInterfaceDescriptor());
72   data.writeInt32(status);
73   data.writeInt32(client_id);
74 
75   remote()->transact(
76       IBluetoothGattClientCallback::ON_CLIENT_REGISTERED_TRANSACTION,
77       data, &reply,
78       IBinder::FLAG_ONEWAY);
79 }
80 
81 IMPLEMENT_META_INTERFACE(BluetoothGattClientCallback,
82                          IBluetoothGattClientCallback::kServiceName);
83 
84 }  // namespace binder
85 }  // namespace ipc
86