OSDN Git Service

resolved conflicts for b8cc54d1 to mnc-dr-dev-plus-aosp
[android-x86/system-bt.git] / service / hal / fake_bluetooth_gatt_interface.h
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 #pragma once
18
19 #include <base/macros.h>
20 #include <base/observer_list.h>
21
22 #include "service/hal/bluetooth_gatt_interface.h"
23
24 namespace bluetooth {
25 namespace hal {
26
27 class FakeBluetoothGattInterface : public BluetoothGattInterface {
28  public:
29   // Handles HAL Bluetooth API calls for testing. Test code can provide a fake
30   // or mock implementation of this and all calls will be routed to it.
31   class TestHandler {
32    public:
33     virtual ~TestHandler() = default;
34
35     virtual bt_status_t RegisterClient(bt_uuid_t* app_uuid) = 0;
36     virtual bt_status_t UnregisterClient(int client_if) = 0;
37   };
38
39   // Constructs the fake with the given handler |handler|. Implementations can
40   // provide their own handlers or simply pass "nullptr" for the default
41   // behavior in which BT_STATUS_FAIL will be returned from all calls.
42   FakeBluetoothGattInterface(std::shared_ptr<TestHandler> handler);
43   ~FakeBluetoothGattInterface();
44
45   // The methods below can be used to notify observers with certain events and
46   // given parameters.
47   void NotifyRegisterClientCallback(int status, int client_if,
48                                     const bt_uuid_t& app_uuid);
49
50   // BluetoothGattInterface overrides:
51   void AddClientObserver(ClientObserver* observer) override;
52   void RemoveClientObserver(ClientObserver* observer) override;
53   const btgatt_client_interface_t* GetClientHALInterface() const override;
54
55  private:
56   base::ObserverList<ClientObserver> client_observers_;
57   std::shared_ptr<TestHandler> handler_;
58
59   DISALLOW_COPY_AND_ASSIGN(FakeBluetoothGattInterface);
60 };
61
62 }  // namespace hal
63 }  // namespace bluetooth