1900c9dc00243990f96922dee904728be1732276fArman Uguray//
2900c9dc00243990f96922dee904728be1732276fArman Uguray//  Copyright (C) 2015 Google, Inc.
3900c9dc00243990f96922dee904728be1732276fArman Uguray//
4900c9dc00243990f96922dee904728be1732276fArman Uguray//  Licensed under the Apache License, Version 2.0 (the "License");
5900c9dc00243990f96922dee904728be1732276fArman Uguray//  you may not use this file except in compliance with the License.
6900c9dc00243990f96922dee904728be1732276fArman Uguray//  You may obtain a copy of the License at:
7900c9dc00243990f96922dee904728be1732276fArman Uguray//
8900c9dc00243990f96922dee904728be1732276fArman Uguray//  http://www.apache.org/licenses/LICENSE-2.0
9900c9dc00243990f96922dee904728be1732276fArman Uguray//
10900c9dc00243990f96922dee904728be1732276fArman Uguray//  Unless required by applicable law or agreed to in writing, software
11900c9dc00243990f96922dee904728be1732276fArman Uguray//  distributed under the License is distributed on an "AS IS" BASIS,
12900c9dc00243990f96922dee904728be1732276fArman Uguray//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13900c9dc00243990f96922dee904728be1732276fArman Uguray//  See the License for the specific language governing permissions and
14900c9dc00243990f96922dee904728be1732276fArman Uguray//  limitations under the License.
15900c9dc00243990f96922dee904728be1732276fArman Uguray//
16900c9dc00243990f96922dee904728be1732276fArman Uguray
17900c9dc00243990f96922dee904728be1732276fArman Uguray#pragma once
18900c9dc00243990f96922dee904728be1732276fArman Uguray
19900c9dc00243990f96922dee904728be1732276fArman Uguray#include <base/macros.h>
20900c9dc00243990f96922dee904728be1732276fArman Uguray
21a4bd0d2370bd469942e92e724cfc9c7c01d3da74Jakub Pawlowski#include <android/bluetooth/BnBluetoothGattClient.h>
22a4bd0d2370bd469942e92e724cfc9c7c01d3da74Jakub Pawlowski#include <android/bluetooth/IBluetoothGattClientCallback.h>
23a4bd0d2370bd469942e92e724cfc9c7c01d3da74Jakub Pawlowski
2450a31545d2d20d92d161c51195b653eafd164025Arman Uguray#include "service/gatt_client.h"
25bb18c41ffa0370d4eb0c4a15904b114355606466Arman Uguray#include "service/ipc/binder/interface_with_instances_base.h"
26900c9dc00243990f96922dee904728be1732276fArman Uguray
27a4bd0d2370bd469942e92e724cfc9c7c01d3da74Jakub Pawlowskiusing android::bluetooth::BnBluetoothGattClient;
28a4bd0d2370bd469942e92e724cfc9c7c01d3da74Jakub Pawlowskiusing android::bluetooth::IBluetoothGattClientCallback;
29a4bd0d2370bd469942e92e724cfc9c7c01d3da74Jakub Pawlowski
30a4bd0d2370bd469942e92e724cfc9c7c01d3da74Jakub Pawlowskiusing ::android::binder::Status;
31a4bd0d2370bd469942e92e724cfc9c7c01d3da74Jakub Pawlowski
32900c9dc00243990f96922dee904728be1732276fArman Uguraynamespace bluetooth {
33900c9dc00243990f96922dee904728be1732276fArman Ugurayclass Adapter;
34900c9dc00243990f96922dee904728be1732276fArman Uguray}  // namespace bluetooth
35900c9dc00243990f96922dee904728be1732276fArman Uguray
36900c9dc00243990f96922dee904728be1732276fArman Uguraynamespace ipc {
37900c9dc00243990f96922dee904728be1732276fArman Uguraynamespace binder {
38900c9dc00243990f96922dee904728be1732276fArman Uguray
39900c9dc00243990f96922dee904728be1732276fArman Uguray// Implements the server side of the IBluetoothGattClient interface.
4050a31545d2d20d92d161c51195b653eafd164025Arman Ugurayclass BluetoothGattClientBinderServer : public BnBluetoothGattClient,
41bb18c41ffa0370d4eb0c4a15904b114355606466Arman Uguray                                        public InterfaceWithInstancesBase {
42900c9dc00243990f96922dee904728be1732276fArman Uguray public:
43900c9dc00243990f96922dee904728be1732276fArman Uguray  explicit BluetoothGattClientBinderServer(bluetooth::Adapter* adapter);
44900c9dc00243990f96922dee904728be1732276fArman Uguray  ~BluetoothGattClientBinderServer() override = default;
45900c9dc00243990f96922dee904728be1732276fArman Uguray
46900c9dc00243990f96922dee904728be1732276fArman Uguray  // IBluetoothGattClient overrides:
47a4bd0d2370bd469942e92e724cfc9c7c01d3da74Jakub Pawlowski  Status RegisterClient(
48a4bd0d2370bd469942e92e724cfc9c7c01d3da74Jakub Pawlowski      const android::sp<IBluetoothGattClientCallback>& callback,
49a4bd0d2370bd469942e92e724cfc9c7c01d3da74Jakub Pawlowski      bool* _aidl_return) override;
50a4bd0d2370bd469942e92e724cfc9c7c01d3da74Jakub Pawlowski  Status UnregisterClient(int client_id) override;
51a4bd0d2370bd469942e92e724cfc9c7c01d3da74Jakub Pawlowski  Status UnregisterAll() override;
52900c9dc00243990f96922dee904728be1732276fArman Uguray
53900c9dc00243990f96922dee904728be1732276fArman Uguray private:
5450a31545d2d20d92d161c51195b653eafd164025Arman Uguray  // Returns a pointer to the IBluetoothGattClientCallback instance
5550a31545d2d20d92d161c51195b653eafd164025Arman Uguray  // associated with |client_id|. Returns NULL if such a callback cannot be
5650a31545d2d20d92d161c51195b653eafd164025Arman Uguray  // found.
57a4bd0d2370bd469942e92e724cfc9c7c01d3da74Jakub Pawlowski  android::sp<IBluetoothGattClientCallback> GetGattClientCallback(
58a4bd0d2370bd469942e92e724cfc9c7c01d3da74Jakub Pawlowski      int client_id);
5950a31545d2d20d92d161c51195b653eafd164025Arman Uguray
6050a31545d2d20d92d161c51195b653eafd164025Arman Uguray  // Returns a pointer to the GattClient instance associated with |client_id|.
6150a31545d2d20d92d161c51195b653eafd164025Arman Uguray  // Returns NULL if such a client cannot be found.
6250a31545d2d20d92d161c51195b653eafd164025Arman Uguray  std::shared_ptr<bluetooth::GattClient> GetGattClient(int client_id);
6350a31545d2d20d92d161c51195b653eafd164025Arman Uguray
64bb18c41ffa0370d4eb0c4a15904b114355606466Arman Uguray  // InterfaceWithInstancesBase override:
65a4bd0d2370bd469942e92e724cfc9c7c01d3da74Jakub Pawlowski  void OnRegisterInstanceImpl(bluetooth::BLEStatus status,
66a4bd0d2370bd469942e92e724cfc9c7c01d3da74Jakub Pawlowski                              android::sp<IInterface> callback,
67a4bd0d2370bd469942e92e724cfc9c7c01d3da74Jakub Pawlowski                              bluetooth::BluetoothInstance* instance) override;
6850a31545d2d20d92d161c51195b653eafd164025Arman Uguray
69900c9dc00243990f96922dee904728be1732276fArman Uguray  bluetooth::Adapter* adapter_;  // weak
70900c9dc00243990f96922dee904728be1732276fArman Uguray
71900c9dc00243990f96922dee904728be1732276fArman Uguray  DISALLOW_COPY_AND_ASSIGN(BluetoothGattClientBinderServer);
72900c9dc00243990f96922dee904728be1732276fArman Uguray};
73900c9dc00243990f96922dee904728be1732276fArman Uguray
74900c9dc00243990f96922dee904728be1732276fArman Uguray}  // namespace binder
75900c9dc00243990f96922dee904728be1732276fArman Uguray}  // namespace ipc
76