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 CHROMEOS_COMPONENTS_TETHER_BLE_ADVERTISEMENT_DEVICE_QUEUE_H_ |
| 6 #define CHROMEOS_COMPONENTS_TETHER_BLE_ADVERTISEMENT_DEVICE_QUEUE_H_ |
| 7 |
| 8 #include <vector> |
| 9 |
| 10 #include "base/macros.h" |
| 11 #include "components/cryptauth/remote_device.h" |
| 12 |
| 13 namespace chromeos { |
| 14 |
| 15 namespace tether { |
| 16 |
| 17 // Queue of devices to which to advertise. Because only |
| 18 // |kMaxConcurrentAdvertisements| devices can be advertised to concurrently, |
| 19 // this queue maintains the order of devices to ensure that each device gets its |
| 20 // fair share of time spent contacting it. |
| 21 class BleAdvertisementDeviceQueue { |
| 22 public: |
| 23 // The maximum number of devices to which to advertise concurrently. If more |
| 24 // than this number of devices are registered, some advertisement must be |
| 25 // stopped before new ones can be added. |
| 26 // |
| 27 // Note that this upper limit on concurrent advertisements is imposed due to a |
| 28 // hardware limit of advertisements. |
| 29 static const int kMaxConcurrentAdvertisements; |
| 30 |
| 31 BleAdvertisementDeviceQueue(); |
| 32 virtual ~BleAdvertisementDeviceQueue(); |
| 33 |
| 34 // Updates the queue with the given |devices|. Devices which are already in |
| 35 // the queue and are not in |devices| are removed from the queue, and all |
| 36 // devices which are not in the queue but are in |devices| are added to the |
| 37 // end of the queue. Note devices that are already in the queue will not |
| 38 // change order as a result of this function being called to ensure that the |
| 39 // queue remains in order. Returns whether the device list has changed due to |
| 40 // the function call. |
| 41 bool SetDevices(std::vector<cryptauth::RemoteDevice> devices); |
| 42 |
| 43 // Moves the given device to the end of the queue. If the device was not in |
| 44 // the queue to begin with, do nothing. |
| 45 void MoveDeviceToEnd(std::string device_id); |
| 46 |
| 47 // Returns a list of devices to which to advertise. The devices returned are |
| 48 // the first |kMaxConcurrentAdvertisements| devices in the front of the queue, |
| 49 // or fewer if the number of devices in the queue is less than that value. |
| 50 std::vector<cryptauth::RemoteDevice> GetDevicesToWhichToAdvertise() const; |
| 51 |
| 52 size_t GetSize() const; |
| 53 |
| 54 private: |
| 55 std::vector<cryptauth::RemoteDevice> device_queue_; |
| 56 |
| 57 DISALLOW_COPY_AND_ASSIGN(BleAdvertisementDeviceQueue); |
| 58 }; |
| 59 |
| 60 } // namespace tether |
| 61 |
| 62 } // namespace chromeos |
| 63 |
| 64 #endif // CHROMEOS_COMPONENTS_TETHER_BLE_ADVERTISEMENT_DEVICE_QUEUE_H_ |
OLD | NEW |