Chromium Code Reviews| Index: chromeos/components/tether/ble_advertisement_device_queue.h |
| diff --git a/chromeos/components/tether/ble_advertisement_device_queue.h b/chromeos/components/tether/ble_advertisement_device_queue.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..23425e2869060262f2c1373c4dc9154654106b8d |
| --- /dev/null |
| +++ b/chromeos/components/tether/ble_advertisement_device_queue.h |
| @@ -0,0 +1,63 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CHROMEOS_COMPONENTS_TETHER_BLE_ADVERTISEMENT_DEVICE_QUEUE_H_ |
| +#define CHROMEOS_COMPONENTS_TETHER_BLE_ADVERTISEMENT_DEVICE_QUEUE_H_ |
| + |
| +#include <vector> |
| + |
| +#include "base/macros.h" |
| +#include "components/cryptauth/remote_device.h" |
| + |
| +namespace chromeos { |
| + |
| +namespace tether { |
| + |
| +// Queue of devices to which to advertise. Because only |
| +// |kMaxConcurrentAdvertisements| devices can be advertised to concurrently, |
| +// this queue maintains the order of devices to ensure that each device gets its |
| +// fair share of time spent contacting it. |
| +class BleAdvertisementDeviceQueue { |
| + public: |
| + // The maximum number of devices to which to advertise concurrently. If more |
| + // than this number of devices are registered, some advertisement must be |
| + // stopped before new ones can be added. |
| + // |
| + // Note that this upper limit on concurrent advertisements is imposed due to a |
| + // hardware limit of advertisements. |
| + static const int kMaxConcurrentAdvertisements; |
| + |
| + BleAdvertisementDeviceQueue(); |
| + virtual ~BleAdvertisementDeviceQueue(); |
| + |
| + // Updates the queue with the given |devices|. Devices which are already in |
| + // the queue and are not in |devices| are removed from the queue, and all |
| + // devices which are not in the queue but are in |devices| are added to the |
| + // end of the queue. Note devices that are already in the queue will not |
| + // change order as a result of this function being called to ensure that the |
| + // queue remains in order. |
| + bool SetDevices(std::vector<cryptauth::RemoteDevice> devices); |
|
Ryan Hansberry
2016/12/19 20:06:52
Explain what a return value of true or false means
Kyle Horimoto
2016/12/19 20:15:03
Done.
|
| + |
| + // Moves the given device to the end of the queue. If the device was not in |
| + // the queue to begin with, do nothing. |
| + void MoveDeviceToEnd(std::string device_id); |
| + |
| + // Returns a list of devices to which to advertise. The devices returned are |
| + // the first |kMaxConcurrentAdvertisements| devices in the front of the queue, |
| + // or fewer if the number of devices in the queue is less than that value. |
| + std::vector<cryptauth::RemoteDevice> GetDevicesToWhichToAdvertise() const; |
| + |
| + size_t GetSize() const; |
| + |
| + private: |
| + std::vector<cryptauth::RemoteDevice> device_queue_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(BleAdvertisementDeviceQueue); |
| +}; |
| + |
| +} // namespace tether |
| + |
| +} // namespace chromeos |
| + |
| +#endif // CHROMEOS_COMPONENTS_TETHER_BLE_ADVERTISEMENT_DEVICE_QUEUE_H_ |