Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / device / bluetooth / bluetooth_remote_gatt_characteristic_chromeos.h
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.
4
5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_CHARACTERISTIC_CHROMEOS_H_
6 #define DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_CHARACTERISTIC_CHROMEOS_H_
7
8 #include <map>
9 #include <string>
10 #include <vector>
11
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"
17
18 namespace device {
19
20 class BluetoothGattDescriptor;
21 class BluetoothGattService;
22
23 }  // namespace device
24
25 namespace chromeos {
26
27 class BluetoothRemoteGattDescriptorChromeOS;
28 class BluetoothRemoteGattServiceChromeOS;
29
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 device::BluetoothGattDescriptor* GetDescriptor(
48       const std::string& identifier) const OVERRIDE;
49   virtual bool AddDescriptor(
50       device::BluetoothGattDescriptor* descriptor) OVERRIDE;
51   virtual bool UpdateValue(const std::vector<uint8>& value) OVERRIDE;
52   virtual void ReadRemoteCharacteristic(
53       const ValueCallback& callback,
54       const ErrorCallback& error_callback) OVERRIDE;
55   virtual void WriteRemoteCharacteristic(
56       const std::vector<uint8>& new_value,
57       const base::Closure& callback,
58       const ErrorCallback& error_callback) OVERRIDE;
59
60   // Object path of the underlying D-Bus characteristic.
61   const dbus::ObjectPath& object_path() const { return object_path_; }
62
63  private:
64   friend class BluetoothRemoteGattServiceChromeOS;
65
66   BluetoothRemoteGattCharacteristicChromeOS(
67       BluetoothRemoteGattServiceChromeOS* service,
68       const dbus::ObjectPath& object_path);
69   virtual ~BluetoothRemoteGattCharacteristicChromeOS();
70
71   // BluetoothGattDescriptorClient::Observer overrides.
72   virtual void GattDescriptorAdded(
73       const dbus::ObjectPath& object_path) OVERRIDE;
74   virtual void GattDescriptorRemoved(
75       const dbus::ObjectPath& object_path) OVERRIDE;
76   virtual void GattDescriptorPropertyChanged(
77       const dbus::ObjectPath& object_path,
78       const std::string& property_name) OVERRIDE;
79
80   // Called by dbus:: on completion of the request to get the characteristic
81   // value.
82   void OnGetValue(const ValueCallback& callback,
83                   const ErrorCallback& error_callback,
84                   bool success);
85
86   // Called by dbus:: on completion of the request to set the characteristic
87   // value.
88   void OnSetValue(const base::Closure& callback,
89                   const ErrorCallback& error_callback,
90                   bool success);
91
92   // Object path of the D-Bus characteristic object.
93   dbus::ObjectPath object_path_;
94
95   // The GATT service this GATT characteristic belongs to.
96   BluetoothRemoteGattServiceChromeOS* service_;
97
98   // Mapping from GATT descriptor object paths to descriptor objects owned by
99   // this characteristic. Since the Chrome OS implementation uses object paths
100   // as unique identifiers, we also use this mapping to return descriptors by
101   // identifier.
102   typedef std::map<dbus::ObjectPath, BluetoothRemoteGattDescriptorChromeOS*>
103       DescriptorMap;
104   DescriptorMap descriptors_;
105
106   // Note: This should remain the last member so it'll be destroyed and
107   // invalidate its weak pointers before any other members are destroyed.
108   base::WeakPtrFactory<BluetoothRemoteGattCharacteristicChromeOS>
109       weak_ptr_factory_;
110
111   DISALLOW_COPY_AND_ASSIGN(BluetoothRemoteGattCharacteristicChromeOS);
112 };
113
114 }  // namespace chromeos
115
116 #endif  // DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_CHARACTERISTIC_CHROMEOS_H_