| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_LOW_ENERGY_WEAVE_ADVERTISEMENT_R
OTATOR_H_ |
| 6 #define COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_LOW_ENERGY_WEAVE_ADVERTISEMENT_R
OTATOR_H_ |
| 7 |
| 8 #include <stddef.h> |
| 9 #include <stdint.h> |
| 10 |
| 11 #include <map> |
| 12 #include <memory> |
| 13 #include <vector> |
| 14 |
| 15 #include "components/proximity_auth/ble/bluetooth_low_energy_eid_generator.h" |
| 16 #include "device/bluetooth/bluetooth_advertisement.h" |
| 17 |
| 18 namespace proximity_auth { |
| 19 namespace weave { |
| 20 namespace { |
| 21 |
| 22 using Advertisement = device::BluetoothAdvertisement::Data; |
| 23 |
| 24 } // namespace |
| 25 |
| 26 // Represent a queue of advertisements for the devices added. |
| 27 // Devices are identified by their bluetooth address and no device with the same |
| 28 // address will be added. |
| 29 // The class also provides simple conversion from bluetooth address to it's |
| 30 // corresponding advertisement. The advertisement returned will be the most up |
| 31 // to date at that moment with the EID seed and EID of that period. |
| 32 class BluetoothLowEnergyAdvertisementRotator { |
| 33 public: |
| 34 class Factory { |
| 35 public: |
| 36 static std::unique_ptr<BluetoothLowEnergyAdvertisementRotator> NewInstance( |
| 37 std::string service_uuid); |
| 38 |
| 39 // Exposed for testing. |
| 40 static void SetInstanceForTesting(Factory* factory); |
| 41 |
| 42 protected: |
| 43 // Exposed for testing. |
| 44 virtual std::unique_ptr<BluetoothLowEnergyAdvertisementRotator> |
| 45 BuildInstance(std::string service_uuid); |
| 46 |
| 47 private: |
| 48 static Factory* factory_instance_; |
| 49 }; |
| 50 |
| 51 ~BluetoothLowEnergyAdvertisementRotator(); |
| 52 |
| 53 bool IsRotatorEmpty(); |
| 54 |
| 55 // Get the next device in the rotator and it's corresponding advertisement. |
| 56 // The rotator must not be empty. |
| 57 std::pair<std::string, std::unique_ptr<Advertisement>> GetNextAdvertisement(); |
| 58 |
| 59 // Move to the next advertisement. |
| 60 void RotateAdvertisement(); |
| 61 |
| 62 // Adds a device to the rotator. |
| 63 // Device must not exist already in the rotator. |
| 64 void AddDevice(const RemoteDevice& device); |
| 65 |
| 66 // Remove the device from the rotator. |
| 67 // Device must exist in the rotator. |
| 68 void RemoveDevice(const RemoteDevice& device); |
| 69 |
| 70 // Inject the device to the front of the queue. |
| 71 void CutAdvertisementLine(std::string bluetooth_address); |
| 72 |
| 73 bool HasDeviceWithAddress(std::string bluetooth_address); |
| 74 |
| 75 protected: |
| 76 BluetoothLowEnergyAdvertisementRotator(std::string service_uuid); |
| 77 |
| 78 private: |
| 79 // Get the index of the device with |bluetooth_address| in devices_. |
| 80 // Device must exist in the rotator. |
| 81 int GetPosWithAddress(std::string bluetooth_address); |
| 82 |
| 83 const std::string service_uuid_; |
| 84 |
| 85 std::unique_ptr<BluetoothLowEnergyEidGenerator> eid_generator_; |
| 86 |
| 87 // A queue containing index into |devices_|. GetNextAdvertisement and |
| 88 // Rotateadvertisement will be based on this queue. |
| 89 std::vector<int> waiting_queue_; |
| 90 |
| 91 // Devices added to the rotator. |
| 92 std::vector<RemoteDevice> devices_; |
| 93 }; |
| 94 |
| 95 } // namespace weave |
| 96 |
| 97 } // namespace proximity_auth |
| 98 |
| 99 #endif // COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_LOW_ENERGY_WEAVE_ADVERTISEMEN
T_ROTATOR_H_ |
| OLD | NEW |