// 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 DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_WIN_FAKE_H_ #define DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_WIN_FAKE_H_ #include "device/bluetooth/bluetooth_low_energy_win.h" #include #include namespace device { namespace win { struct BLEDevice; struct BLEGattService; struct BLEGattCharacteristic; struct BLEGattDescriptor; // The key of BLEDevicesMap is the string of the BLE device address. typedef std::unordered_map> BLEDevicesMap; // The key of BLEGattServicesMap, BLEGattCharacteristicsMap and // BLEGattDescriptorsMap is the string of the attribute handle. typedef std::unordered_map> BLEGattServicesMap; typedef std::unordered_map> BLEGattCharacteristicsMap; typedef std::unordered_map> BLEGattDescriptorsMap; // The key of BLEAttributeHandleTable is the string of the BLE device address. typedef std::unordered_map>> BLEAttributeHandleTable; struct BLEDevice { BLEDevice(); ~BLEDevice(); scoped_ptr device_info; BLEGattServicesMap primary_services; }; struct BLEGattService { BLEGattService(); ~BLEGattService(); scoped_ptr service_info; BLEGattServicesMap included_services; BLEGattCharacteristicsMap included_characteristics; }; struct BLEGattCharacteristic { BLEGattCharacteristic(); ~BLEGattCharacteristic(); scoped_ptr characteristic_info; scoped_ptr value; BLEGattDescriptorsMap included_descriptors; }; struct BLEGattDescriptor { BLEGattDescriptor(); ~BLEGattDescriptor(); scoped_ptr descriptor_info; scoped_ptr value; }; // Fake implementation of BluetoothLowEnergyWrapper. Used for BluetoothTestWin. class BluetoothLowEnergyWrapperFake : public BluetoothLowEnergyWrapper { public: BluetoothLowEnergyWrapperFake(); ~BluetoothLowEnergyWrapperFake() override; bool EnumerateKnownBluetoothLowEnergyDevices( ScopedVector* devices, std::string* error) override; bool EnumerateKnownBluetoothLowEnergyGattServiceDevices( ScopedVector* devices, std::string* error) override; bool EnumerateKnownBluetoothLowEnergyServices( const base::FilePath& device_path, ScopedVector* services, std::string* error) override; BLEDevice* SimulateBLEDevice(std::string device_name, BLUETOOTH_ADDRESS device_address); BLEDevice* GetSimulatedBLEDevice(std::string device_address); BLEGattService* SimulateBLEGattService(BLEDevice* device, std::string uuid); private: // Generate an unique attribute handle on |device_address|. USHORT GenerateAUniqueAttributeHandle(std::string device_address); // Generate device path for the BLE device with |device_address|. base::string16 GenerateBLEDevicePath(std::string device_address); // Generate GATT service device path of the service with // |service_attribute_handle|. |resident_device_path| is the BLE device this // GATT service belongs to. base::string16 GenerateBLEGattServiceDevicePath( base::string16 resident_device_path, USHORT service_attribute_handle); // Extract device address from the device |path| generated by // GenerateBLEDevicePath or GenerateBLEGattServiceDevicePath. base::string16 ExtractDeviceAddressFromDevicePath(base::string16 path); // Extract service attribute handle from the |path| generated by // GenerateBLEGattServiceDevicePath. base::string16 ExtractServiceAttributeHandleFromDevicePath( base::string16 path); // The canonical BLE device address string format is the // BluetoothDevice::CanonicalizeAddress. std::string BluetoothAddressToCanonicalString(const BLUETOOTH_ADDRESS& btha); // The canonical UUID string format is device::BluetoothUUID.value(). BTH_LE_UUID CanonicalStringToBTH_LE_UUID(std::string uuid); // Table to store allocated attribute handle for a device. BLEAttributeHandleTable attribute_handle_table_; BLEDevicesMap simulated_devices_; }; } // namespace win } // namespace device #endif // DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_WIN_FAKE_H_