| Index: components/proximity_auth/ble/bluetooth_low_energy_advertisement_rotator.h
|
| diff --git a/components/proximity_auth/ble/bluetooth_low_energy_advertisement_rotator.h b/components/proximity_auth/ble/bluetooth_low_energy_advertisement_rotator.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..45c58b6d040d6935a08fcfc19aa80627dd440371
|
| --- /dev/null
|
| +++ b/components/proximity_auth/ble/bluetooth_low_energy_advertisement_rotator.h
|
| @@ -0,0 +1,99 @@
|
| +// 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 COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_LOW_ENERGY_WEAVE_ADVERTISEMENT_ROTATOR_H_
|
| +#define COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_LOW_ENERGY_WEAVE_ADVERTISEMENT_ROTATOR_H_
|
| +
|
| +#include <stddef.h>
|
| +#include <stdint.h>
|
| +
|
| +#include <map>
|
| +#include <memory>
|
| +#include <vector>
|
| +
|
| +#include "components/proximity_auth/ble/bluetooth_low_energy_eid_generator.h"
|
| +#include "device/bluetooth/bluetooth_advertisement.h"
|
| +
|
| +namespace proximity_auth {
|
| +namespace weave {
|
| +namespace {
|
| +
|
| +using Advertisement = device::BluetoothAdvertisement::Data;
|
| +
|
| +} // namespace
|
| +
|
| +// Represent a queue of advertisements for the devices added.
|
| +// Devices are identified by their bluetooth address and no device with the same
|
| +// address will be added.
|
| +// The class also provides simple conversion from bluetooth address to it's
|
| +// corresponding advertisement. The advertisement returned will be the most up
|
| +// to date at that moment with the EID seed and EID of that period.
|
| +class BluetoothLowEnergyAdvertisementRotator {
|
| + public:
|
| + class Factory {
|
| + public:
|
| + static std::unique_ptr<BluetoothLowEnergyAdvertisementRotator> NewInstance(
|
| + std::string service_uuid);
|
| +
|
| + // Exposed for testing.
|
| + static void SetInstanceForTesting(Factory* factory);
|
| +
|
| + protected:
|
| + // Exposed for testing.
|
| + virtual std::unique_ptr<BluetoothLowEnergyAdvertisementRotator>
|
| + BuildInstance(std::string service_uuid);
|
| +
|
| + private:
|
| + static Factory* factory_instance_;
|
| + };
|
| +
|
| + ~BluetoothLowEnergyAdvertisementRotator();
|
| +
|
| + bool IsRotatorEmpty();
|
| +
|
| + // Get the next device in the rotator and it's corresponding advertisement.
|
| + // The rotator must not be empty.
|
| + std::pair<std::string, std::unique_ptr<Advertisement>> GetNextAdvertisement();
|
| +
|
| + // Move to the next advertisement.
|
| + void RotateAdvertisement();
|
| +
|
| + // Adds a device to the rotator.
|
| + // Device must not exist already in the rotator.
|
| + void AddDevice(const RemoteDevice& device);
|
| +
|
| + // Remove the device from the rotator.
|
| + // Device must exist in the rotator.
|
| + void RemoveDevice(const RemoteDevice& device);
|
| +
|
| + // Inject the device to the front of the queue.
|
| + void CutAdvertisementLine(std::string bluetooth_address);
|
| +
|
| + bool HasDeviceWithAddress(std::string bluetooth_address);
|
| +
|
| + protected:
|
| + BluetoothLowEnergyAdvertisementRotator(std::string service_uuid);
|
| +
|
| + private:
|
| + // Get the index of the device with |bluetooth_address| in devices_.
|
| + // Device must exist in the rotator.
|
| + int GetPosWithAddress(std::string bluetooth_address);
|
| +
|
| + const std::string service_uuid_;
|
| +
|
| + std::unique_ptr<BluetoothLowEnergyEidGenerator> eid_generator_;
|
| +
|
| + // A queue containing index into |devices_|. GetNextAdvertisement and
|
| + // Rotateadvertisement will be based on this queue.
|
| + std::vector<int> waiting_queue_;
|
| +
|
| + // Devices added to the rotator.
|
| + std::vector<RemoteDevice> devices_;
|
| +};
|
| +
|
| +} // namespace weave
|
| +
|
| +} // namespace proximity_auth
|
| +
|
| +#endif // COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_LOW_ENERGY_WEAVE_ADVERTISEMENT_ROTATOR_H_
|
|
|