forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bluetooth_system.h
87 lines (66 loc) · 3.12 KB
/
bluetooth_system.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef SERVICES_DEVICE_BLUETOOTH_BLUETOOTH_SYSTEM_H_
#define SERVICES_DEVICE_BLUETOOTH_BLUETOOTH_SYSTEM_H_
#include <string>
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/optional.h"
#include "dbus/object_path.h"
#include "device/bluetooth/dbus/bluetooth_adapter_client.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "services/device/public/mojom/bluetooth_system.mojom.h"
namespace bluez {
class BluetoothAdapterClient;
class BluetoothDeviceClient;
}
namespace device {
class BluetoothSystem : public mojom::BluetoothSystem,
public bluez::BluetoothAdapterClient::Observer {
public:
static void Create(mojo::PendingReceiver<mojom::BluetoothSystem> receiver,
mojo::PendingRemote<mojom::BluetoothSystemClient> client);
explicit BluetoothSystem(
mojo::PendingRemote<mojom::BluetoothSystemClient> client);
~BluetoothSystem() override;
// bluez::BluetoothAdapterClient::Observer
void AdapterAdded(const dbus::ObjectPath& object_path) override;
void AdapterRemoved(const dbus::ObjectPath& object_path) override;
void AdapterPropertyChanged(const dbus::ObjectPath& object_path,
const std::string& property_name) override;
// mojom::BluetoothSystem
void GetState(GetStateCallback callback) override;
void SetPowered(bool powered, SetPoweredCallback callback) override;
void GetScanState(GetScanStateCallback callback) override;
void StartScan(StartScanCallback callback) override;
void StopScan(StopScanCallback callback) override;
void GetAvailableDevices(GetAvailableDevicesCallback callback) override;
private:
bluez::BluetoothAdapterClient* GetBluetoothAdapterClient();
bluez::BluetoothDeviceClient* GetBluetoothDeviceClient();
void UpdateStateAndNotifyIfNecessary();
ScanState GetScanStateFromActiveAdapter();
void OnSetPoweredFinished(SetPoweredCallback callback, bool succeeded);
void OnStartDiscovery(
StartScanCallback callback,
const base::Optional<bluez::BluetoothAdapterClient::Error>& error);
void OnStopDiscovery(
StopScanCallback callback,
const base::Optional<bluez::BluetoothAdapterClient::Error>& error);
mojo::Remote<mojom::BluetoothSystemClient> client_;
// The ObjectPath of the adapter being used. Updated as BT adapters are
// added and removed. nullopt if there is no adapter.
base::Optional<dbus::ObjectPath> active_adapter_;
// State of |active_adapter_| or kUnavailable if there is no
// |active_adapter_|.
State state_ = State::kUnavailable;
// Note: This should remain the last member so it'll be destroyed and
// invalidate its weak pointers before any other members are destroyed.
base::WeakPtrFactory<BluetoothSystem> weak_ptr_factory_{this};
DISALLOW_COPY_AND_ASSIGN(BluetoothSystem);
};
} // namespace device
#endif // SERVICES_DEVICE_BLUETOOTH_BLUETOOTH_SYSTEM_H_