Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(615)

Unified Diff: components/proximity_auth/ble/bluetooth_low_energy_advertisement_rotator.h

Issue 2183523006: Chrome OS uWeave Characteristics Server (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@migration
Patch Set: added channel Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..563771f057cb8dc0b53ac172ad5ff403ebc5d3c0
--- /dev/null
+++ b/components/proximity_auth/ble/bluetooth_low_energy_advertisement_rotator.h
@@ -0,0 +1,89 @@
+// 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
+
+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 will be added at the end of the
+ // conceptual queue.
+ // 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);
+
+ bool HasDeviceWithId(std::string device_id);
+
+ protected:
+ BluetoothLowEnergyAdvertisementRotator(std::string service_uuid);
+
+ private:
+ void AdvanceQueueHead();
+
+ const std::string service_uuid_;
+
+ std::unique_ptr<BluetoothLowEnergyEidGenerator> eid_generator_;
+
+ std::vector<RemoteDevice> devices_;
+
+ // Index into devices_.
+ // Points to the head of the wrap around conceptual queue on top of the vector
+ // of devices.
+ uint32_t queue_head_;
+};
+
+} // namespace weave
+
+} // namespace proximity_auth
+
+#endif // COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_LOW_ENERGY_WEAVE_ADVERTISEMENT_ROTATOR_H_
« no previous file with comments | « components/proximity_auth/ble/BUILD.gn ('k') | components/proximity_auth/ble/bluetooth_low_energy_advertisement_rotator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698