summaryrefslogtreecommitdiff
path: root/chromium/third_party/nearby/src/cpp/core/internal/injected_bluetooth_device_store.h
blob: cc61c2fef3376ab107c613f03da3036555df7b63 (plain)
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
// Copyright 2020 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef CORE_INTERNAL_INJECTED_BLUETOOTH_DEVICE_STORE_H_
#define CORE_INTERNAL_INJECTED_BLUETOOTH_DEVICE_STORE_H_

#include <memory>
#include <vector>

#include "core/internal/pcp.h"
#include "platform/base/byte_array.h"
#include "platform/public/bluetooth_adapter.h"

namespace location {
namespace nearby {
namespace connections {

// Creates and stores BluetoothDevice objects which have been "injected" (i.e.,
// passed to Nearby Connections manually by the client instead of through the
// normal discovery flow).
class InjectedBluetoothDeviceStore {
 public:
  InjectedBluetoothDeviceStore();
  ~InjectedBluetoothDeviceStore();

  // Creates an injected BluetoothDevice given the provided parameters:
  //   |remote_bluetooth_mac_address|: A 6-byte MAC address.
  //   |endpoint_id|: A string of length 4.
  //   |endpoint_info|: A non-empty ByteArray whose length is <=131 bytes.
  //   |service_id_hash|: A ByteArray whose length is 3.
  //   |pcp|: PCP value to be used for the connection to this device.
  //
  // If the provided parameters are malformed or of incorrect length, this
  // function returns an invalid BluetoothDevice. Clients should use
  // BluetoothDevice::IsValid() with the returned device to verify that the
  // parameters were successfully processed.
  //
  // Note that successfully-injected devices stay valid for the lifetime of the
  // InjectedBluetoothDeviceStore and are not cleared until this object is
  // deleted.
  BluetoothDevice CreateInjectedBluetoothDevice(
      const ByteArray& remote_bluetooth_mac_address,
      const std::string& endpoint_id, const ByteArray& endpoint_info,
      const ByteArray& service_id_hash, Pcp pcp);

 private:
  // Devices created by this class. BluetoothDevice objects returned by
  // CreateInjectedBluetoothDevice() store pointers to underlying
  // api::BluetoothDevice objects, so this maintains these underlying devices
  // to ensure that they are not deleted before they are referenced.
  std::vector<std::unique_ptr<api::BluetoothDevice>> devices_;
};

}  // namespace connections
}  // namespace nearby
}  // namespace location

#endif  // CORE_INTERNAL_INJECTED_BLUETOOTH_DEVICE_STORE_H_