Revert 264226 "Reduce dependency of TiclInvalidationService on P..."
[chromium-blink-merge.git] / device / bluetooth / bluetooth_remote_gatt_characteristic_chromeos.h
blob1a4f045d3d1d2c6db9cb52777856977d68fb6cda
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_CHARACTERISTIC_CHROMEOS_H_
6 #define DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_CHARACTERISTIC_CHROMEOS_H_
8 #include <map>
9 #include <string>
10 #include <vector>
12 #include "base/memory/weak_ptr.h"
13 #include "chromeos/dbus/bluetooth_gatt_descriptor_client.h"
14 #include "dbus/object_path.h"
15 #include "device/bluetooth/bluetooth_gatt_characteristic.h"
16 #include "device/bluetooth/bluetooth_uuid.h"
18 namespace device {
20 class BluetoothGattDescriptor;
21 class BluetoothGattService;
23 } // namespace device
25 namespace chromeos {
27 class BluetoothRemoteGattDescriptorChromeOS;
28 class BluetoothRemoteGattServiceChromeOS;
30 // The BluetoothRemoteGattCharacteristicChromeOS class implements
31 // BluetoothGattCharacteristic for remote GATT characteristics on the Chrome OS
32 // platform.
33 class BluetoothRemoteGattCharacteristicChromeOS
34 : public device::BluetoothGattCharacteristic,
35 public BluetoothGattDescriptorClient::Observer {
36 public:
37 // device::BluetoothGattCharacteristic overrides.
38 virtual std::string GetIdentifier() const OVERRIDE;
39 virtual device::BluetoothUUID GetUUID() const OVERRIDE;
40 virtual bool IsLocal() const OVERRIDE;
41 virtual const std::vector<uint8>& GetValue() const OVERRIDE;
42 virtual device::BluetoothGattService* GetService() const OVERRIDE;
43 virtual Properties GetProperties() const OVERRIDE;
44 virtual Permissions GetPermissions() const OVERRIDE;
45 virtual std::vector<device::BluetoothGattDescriptor*>
46 GetDescriptors() const OVERRIDE;
47 virtual bool AddDescriptor(
48 device::BluetoothGattDescriptor* descriptor) OVERRIDE;
49 virtual bool UpdateValue(const std::vector<uint8>& value) OVERRIDE;
50 virtual void ReadRemoteCharacteristic(
51 const ValueCallback& callback,
52 const ErrorCallback& error_callback) OVERRIDE;
53 virtual void WriteRemoteCharacteristic(
54 const std::vector<uint8>& new_value,
55 const base::Closure& callback,
56 const ErrorCallback& error_callback) OVERRIDE;
58 // Object path of the underlying D-Bus characteristic.
59 const dbus::ObjectPath& object_path() const { return object_path_; }
61 private:
62 friend class BluetoothRemoteGattServiceChromeOS;
64 BluetoothRemoteGattCharacteristicChromeOS(
65 BluetoothRemoteGattServiceChromeOS* service,
66 const dbus::ObjectPath& object_path);
67 virtual ~BluetoothRemoteGattCharacteristicChromeOS();
69 // BluetoothGattDescriptorClient::Observer overrides.
70 virtual void GattDescriptorAdded(
71 const dbus::ObjectPath& object_path) OVERRIDE;
72 virtual void GattDescriptorRemoved(
73 const dbus::ObjectPath& object_path) OVERRIDE;
74 virtual void GattDescriptorPropertyChanged(
75 const dbus::ObjectPath& object_path,
76 const std::string& property_name) OVERRIDE;
78 // Called by dbus:: on completion of the request to get the characteristic
79 // value.
80 void OnGetValue(const ValueCallback& callback,
81 const ErrorCallback& error_callback,
82 bool success);
84 // Called by dbus:: on completion of the request to set the characteristic
85 // value.
86 void OnSetValue(const base::Closure& callback,
87 const ErrorCallback& error_callback,
88 bool success);
90 // Object path of the D-Bus characteristic object.
91 dbus::ObjectPath object_path_;
93 // The GATT service this GATT characteristic belongs to.
94 BluetoothRemoteGattServiceChromeOS* service_;
96 // Mapping from GATT descriptor object paths to descriptor objects owned by
97 // this characteristic. Since the Chrome OS implementation uses object paths
98 // as unique identifiers, we also use this mapping to return descriptors by
99 // identifier.
100 typedef std::map<dbus::ObjectPath, BluetoothRemoteGattDescriptorChromeOS*>
101 DescriptorMap;
102 DescriptorMap descriptors_;
104 // Note: This should remain the last member so it'll be destroyed and
105 // invalidate its weak pointers before any other members are destroyed.
106 base::WeakPtrFactory<BluetoothRemoteGattCharacteristicChromeOS>
107 weak_ptr_factory_;
109 DISALLOW_COPY_AND_ASSIGN(BluetoothRemoteGattCharacteristicChromeOS);
112 } // namespace chromeos
114 #endif // DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_CHARACTERISTIC_CHROMEOS_H_