| 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 class BluetoothLowEnergyAdvertisementRotator { |
| 27 public: |
| 28 class Factory { |
| 29 public: |
| 30 static std::unique_ptr<BluetoothLowEnergyAdvertisementRotator> NewInstance( |
| 31 std::string service_uuid); |
| 32 |
| 33 // Exposed for testing. |
| 34 static void SetInstanceForTesting(Factory* factory); |
| 35 |
| 36 protected: |
| 37 // Exposed for testing. |
| 38 virtual std::unique_ptr<BluetoothLowEnergyAdvertisementRotator> |
| 39 BuildInstance(std::string service_uuid); |
| 40 |
| 41 private: |
| 42 static Factory* factory_instance_; |
| 43 }; |
| 44 |
| 45 ~BluetoothLowEnergyAdvertisementRotator(); |
| 46 |
| 47 bool IsRotatorEmpty(); |
| 48 |
| 49 // Get the next device in the rotator and it's corresponding advertisement. |
| 50 // The rotator must not be empty. |
| 51 std::pair<std::string, std::unique_ptr<Advertisement>> GetNextAdvertisement(); |
| 52 |
| 53 // Move to the next advertisement. |
| 54 void RotateAdvertisement(); |
| 55 |
| 56 // Adds a device to the rotator. Device will be added at the end of the |
| 57 // conceptual queue. |
| 58 // Device must not exist already in the rotator. |
| 59 void AddDevice(const RemoteDevice& device); |
| 60 |
| 61 // Remove the device from the rotator. |
| 62 // Device must exist in the rotator. |
| 63 void RemoveDevice(const RemoteDevice& device); |
| 64 |
| 65 bool HasDeviceWithId(std::string device_id); |
| 66 |
| 67 protected: |
| 68 BluetoothLowEnergyAdvertisementRotator(std::string service_uuid); |
| 69 |
| 70 private: |
| 71 void AdvanceQueueHead(); |
| 72 |
| 73 const std::string service_uuid_; |
| 74 |
| 75 std::unique_ptr<BluetoothLowEnergyEidGenerator> eid_generator_; |
| 76 |
| 77 std::vector<RemoteDevice> devices_; |
| 78 |
| 79 // Index into devices_. |
| 80 // Points to the head of the wrap around conceptual queue on top of the vector |
| 81 // of devices. |
| 82 uint32_t queue_head_; |
| 83 }; |
| 84 |
| 85 } // namespace weave |
| 86 |
| 87 } // namespace proximity_auth |
| 88 |
| 89 #endif // COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_LOW_ENERGY_WEAVE_ADVERTISEMEN
T_ROTATOR_H_ |
| OLD | NEW |