Chromium Code Reviews| 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 const device::BluetoothAdvertisement::AdvertisementType kPeripheralAdType = | |
|
rkc
2016/07/27 00:56:33
Why is this in an anonymous namespace in a header
jingxuy
2016/07/27 23:31:48
Done.
| |
| 23 device::BluetoothAdvertisement::AdvertisementType:: | |
| 24 ADVERTISEMENT_TYPE_PERIPHERAL; | |
| 25 | |
| 26 } // namespace | |
| 27 | |
| 28 class BluetoothLowEnergyAdvertisementRotator { | |
|
rkc
2016/07/27 00:56:34
Class comment? What does this class do?
Kyle Horimoto
2016/07/27 17:58:48
There should just be one EidGenerator used to gene
jingxuy
2016/07/27 23:31:47
If there is going to be different seed for differe
jingxuy
2016/07/27 23:31:48
Done.
| |
| 29 public: | |
| 30 class Factory { | |
| 31 public: | |
| 32 static std::unique_ptr<BluetoothLowEnergyAdvertisementRotator> NewInstance( | |
| 33 std::string service_uuid); | |
| 34 | |
| 35 // Exposed for testing. | |
| 36 static void SetInstanceForTesting(Factory* factory); | |
|
rkc
2016/07/27 00:56:34
Is there a better way to do this. We've moved away
Kyle Horimoto
2016/07/27 06:34:53
Rahul, I actually suggested this approach to Jing
jingxuy
2016/07/27 23:31:48
I would be open to other ways of doing this becaus
| |
| 37 | |
| 38 protected: | |
| 39 // Exposed for testing. | |
| 40 virtual std::unique_ptr<BluetoothLowEnergyAdvertisementRotator> | |
| 41 BuildInstance(std::string service_uuid); | |
| 42 | |
| 43 private: | |
| 44 static Factory* factory_instance_; | |
| 45 }; | |
| 46 | |
| 47 typedef device::BluetoothAdvertisement::Data Advertisement; | |
| 48 | |
| 49 ~BluetoothLowEnergyAdvertisementRotator(); | |
| 50 | |
| 51 // Return whether the rotator is empty. | |
|
rkc
2016/07/27 00:56:34
Unnecessary comment.
jingxuy
2016/07/27 23:31:48
Done.
| |
| 52 bool IsRotatorEmpty(); | |
| 53 | |
| 54 // Get the next device in the rotator and it's corresponding advertisement. | |
| 55 // The rotator must not be empty. | |
| 56 std::pair<std::string, std::unique_ptr<Advertisement>> GetNextAdvertisement(); | |
| 57 | |
| 58 // Return a refreshed version of advertisement for the given device. | |
| 59 // Device must be already added to the rotator. | |
| 60 std::unique_ptr<Advertisement> GetAddedDeviceAdvertisement( | |
| 61 std::string bluetooth_address); | |
| 62 | |
| 63 // Move to the next advertisement. | |
| 64 void RotateAdvertisement(); | |
| 65 | |
| 66 // Adds a device to the rotator. | |
| 67 // Device must not exist already in the rotator. | |
| 68 void AddDevice(const RemoteDevice& device); | |
| 69 | |
| 70 // Remove the device from the rotator. | |
| 71 // Device must exist in the rotator. | |
| 72 void RemoveDevice(const RemoteDevice& device); | |
| 73 | |
| 74 void CutAdvertisementLine(std::string bluetooth_address); | |
| 75 | |
| 76 bool HasDeviceWithAddress(std::string bluetooth_address); | |
| 77 | |
| 78 protected: | |
| 79 BluetoothLowEnergyAdvertisementRotator(std::string service_uuid); | |
|
rkc
2016/07/27 00:56:33
Why is this protected? Why inherits this class?
jingxuy
2016/07/27 23:31:48
This the part of the implementation for the factor
| |
| 80 | |
| 81 private: | |
| 82 int GetPosWithAddress(std::string bluetooth_address); | |
| 83 | |
| 84 const std::string service_uuid_; | |
| 85 | |
| 86 std::map<std::string, std::unique_ptr<BluetoothLowEnergyEidGenerator>> | |
| 87 map_to_eid_generator_; | |
| 88 | |
| 89 std::vector<int> waiting_queue_; | |
|
rkc
2016/07/27 00:56:34
What do these variables hold?
jingxuy
2016/07/27 23:31:48
Done.
| |
| 90 std::vector<RemoteDevice> devices_; | |
| 91 }; | |
| 92 | |
| 93 } // namespace weave | |
| 94 | |
| 95 } // namespace proximity_auth | |
| 96 | |
| 97 #endif // COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_LOW_ENERGY_WEAVE_ADVERTISEMEN T_ROTATOR_H_ | |
| OLD | NEW |