Chromium Code Reviews| Index: components/proximity_auth/ble/bluetooth_low_energy_weave_server.h |
| diff --git a/components/proximity_auth/ble/bluetooth_low_energy_weave_server.h b/components/proximity_auth/ble/bluetooth_low_energy_weave_server.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..4e913b9e9254c43cd7683b83d73810efc5746452 |
| --- /dev/null |
| +++ b/components/proximity_auth/ble/bluetooth_low_energy_weave_server.h |
| @@ -0,0 +1,175 @@ |
| +// 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_SERVER_H_ |
| +#define COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_LOW_ENERGY_WEAVE_SERVER_H_ |
| + |
| +#include <stddef.h> |
| +#include <stdint.h> |
| + |
| +#include <map> |
| +#include <memory> |
| +#include <vector> |
| + |
| +#include "base/memory/ref_counted.h" |
| +#include "base/task_runner.h" |
| +#include "components/proximity_auth/ble/bluetooth_low_energy_advertisement_rotator.h" |
| +#include "components/proximity_auth/ble/bluetooth_low_energy_weave_defines.h" |
| +#include "components/proximity_auth/ble/bluetooth_low_energy_weave_server_connection.h" |
| +#include "components/proximity_auth/connection.h" |
| +#include "components/proximity_auth/remote_device.h" |
| +#include "device/bluetooth/bluetooth_adapter.h" |
| +#include "device/bluetooth/bluetooth_device.h" |
| +#include "device/bluetooth/bluetooth_local_gatt_characteristic.h" |
| +#include "device/bluetooth/bluetooth_local_gatt_descriptor.h" |
| +#include "device/bluetooth/bluetooth_local_gatt_service.h" |
| + |
| +namespace base { |
| +class TaskRunner; |
| +} |
| + |
| +namespace proximity_auth { |
| +namespace weave { |
| +namespace { |
| + |
| +typedef device::BluetoothAdapter BluetoothAdapter; |
| +typedef device::BluetoothAdvertisement BluetoothAdvertisement; |
| +typedef device::BluetoothDevice BluetoothDevice; |
| +typedef device::BluetoothLocalGattCharacteristic |
| + BluetoothLocalGattCharacteristic; |
| +typedef device::BluetoothLocalGattService BluetoothLocalGattService; |
| +typedef device::BluetoothLocalGattDescriptor BluetoothLocalGattDescriptor; |
| +typedef base::Callback<void(const std::vector<uint8_t>&)> ValueCallback; |
| +typedef base::Closure ErrorCallback; |
| +typedef proximity_auth::Connection::Status ConnectionStatus; |
| +typedef BluetoothLowEnergyAdvertisementRotator::Advertisement Advertisement; |
| + |
| +} // namespace |
| + |
| +class BluetoothLowEnergyWeaveServerConnection; |
| + |
| +class BluetoothLowEnergyWeaveServer |
|
rkc
2016/07/27 00:56:34
Class comment? Method comments?
jingxuy
2016/07/27 23:31:48
Done.
|
| + : public device::BluetoothLocalGattService::Delegate { |
| + public: |
| + class Factory { |
| + public: |
| + static std::unique_ptr<BluetoothLowEnergyWeaveServer> NewInstance(); |
| + |
| + // Exposed for testing. |
| + static void SetInstanceForTesting(Factory* factory); |
| + |
| + protected: |
| + // Exposed for testing. |
| + virtual std::unique_ptr<BluetoothLowEnergyWeaveServer> BuildInstance(); |
| + |
| + private: |
| + static Factory* factory_instance_; |
| + }; |
| + |
| + // device::BluetoothLocalGattService::Delegate: |
| + void OnCharacteristicReadRequest( |
| + const BluetoothDevice* bluetooth_device, |
| + const BluetoothLocalGattCharacteristic* characteristic, |
| + int offset, |
| + const ValueCallback& callback, |
| + const ErrorCallback& error_callback) override; |
| + |
| + void OnCharacteristicWriteRequest( |
| + const BluetoothDevice* bluetooth_device, |
| + const BluetoothLocalGattCharacteristic* characteristic, |
| + const Packet& value, |
| + int offset, |
| + const base::Closure& callback, |
| + const ErrorCallback& error_callback) override; |
| + |
| + void OnDescriptorReadRequest(const BluetoothDevice* device, |
| + const BluetoothLocalGattDescriptor* descriptor, |
| + int offset, |
| + const ValueCallback& callback, |
| + const ErrorCallback& error_callback) override{}; |
| + |
| + void OnDescriptorWriteRequest(const BluetoothDevice* device, |
| + const BluetoothLocalGattDescriptor* descriptor, |
| + const std::vector<uint8_t>& value, |
| + int offset, |
| + const base::Closure& callback, |
| + const ErrorCallback& error_callback) override{}; |
| + |
| + void OnNotificationsStart( |
| + const BluetoothDevice* bluetooth_device, |
| + const BluetoothLocalGattCharacteristic* characteristic) override; |
| + |
| + void OnNotificationsStop( |
| + const BluetoothDevice* bluetooth_device, |
| + const BluetoothLocalGattCharacteristic* characteristic) override; |
| + |
| + ~BluetoothLowEnergyWeaveServer(); |
| + |
| + // Duplicate registeration has no effect. |
| + void RegisterDevice(const RemoteDevice& remote_device); |
| + |
| + void UnregisterDevice(const RemoteDevice& remote_device); |
| + |
| + bool HasDevice(std::string device_address); |
| + |
| + const RemoteDevice& GetRemoteDevice(const BluetoothDevice* bluetooth_device); |
| + |
| + void StartAdvertising(const RemoteDevice& remote_device); |
| + |
| + void StopAdvertising(const RemoteDevice& remote_device); |
| + |
| + protected: |
| + BluetoothLowEnergyWeaveServer(); |
| + |
| + // Sets |task_runner_| for testing. |
| + void SetTaskRunnerForTesting(scoped_refptr<base::TaskRunner> task_runner); |
| + |
| + private: |
| + void UpdateEidSeeds(); |
| + void UpdateEids(); |
| + void RefreshAdvertisement(); |
| + |
| + void RotateAdvertisement(); |
| + void Advertise(); |
| + |
| + void CreateAdapterCallback(); |
| + |
| + void UnregisterAdvertisement(std::string bluetooth_address); |
| + void UnregisterAdvertisementSuccess(std::string bluetooth_address); |
| + void UnregisterAdvertisementError(std::string bluetooth_address, |
| + BluetoothAdvertisement::ErrorCode error); |
| + |
| + void RegisterAdvertisementSuccess( |
| + std::string bluetooth_address, |
| + scoped_refptr<BluetoothAdvertisement> advertisement); |
| + void RegisterAdvertisementError(BluetoothAdvertisement::ErrorCode error); |
| + |
| + scoped_refptr<base::TaskRunner> task_runner_; |
| + |
| + std::map<std::string, RemoteDevice> map_to_remote_device_; |
| + |
| + std::unique_ptr<BluetoothLowEnergyAdvertisementRotator> ad_rotator_; |
| + |
| + std::map<std::string, scoped_refptr<BluetoothAdvertisement>> |
| + map_to_advertisement_; |
| + |
| + std::map<std::string, |
| + std::unique_ptr<BluetoothLowEnergyWeaveServerConnection>> |
| + map_to_server_connection_; |
| + |
| + scoped_refptr<BluetoothAdapter> adapter_; |
| + |
| + base::WeakPtr<BluetoothLocalGattService> service_; |
| + |
| + base::WeakPtr<BluetoothLocalGattCharacteristic> rx_characteristic_; |
| + base::WeakPtr<BluetoothLocalGattCharacteristic> tx_characteristic_; |
| + |
| + base::WeakPtrFactory<BluetoothLowEnergyWeaveServer> weak_ptr_factory_; |
| +}; |
| + |
| +} // namespace weave |
| + |
| +} // namespace proximity_auth |
| + |
| +#endif // COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_LOW_ENERGY_WEAVE_SERVER_H_ |