Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / device / bluetooth / bluetooth_remote_gatt_service_chromeos.h
blob54bde8930fcfec7edc5fa5e614ffc5244473e383
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_SERVICE_CHROMEOS_H_
6 #define DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_SERVICE_CHROMEOS_H_
8 #include <map>
9 #include <string>
10 #include <vector>
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/weak_ptr.h"
14 #include "base/observer_list.h"
15 #include "chromeos/dbus/bluetooth_gatt_characteristic_client.h"
16 #include "chromeos/dbus/bluetooth_gatt_service_client.h"
17 #include "dbus/object_path.h"
18 #include "device/bluetooth/bluetooth_gatt_service.h"
19 #include "device/bluetooth/bluetooth_uuid.h"
21 namespace device {
23 class BluetoothAdapter;
24 class BluetoothGattCharacteristic;
26 } // namespace device
28 namespace chromeos {
30 class BluetoothAdapterChromeOS;
31 class BluetoothDeviceChromeOS;
32 class BluetoothRemoteGattCharacteristicChromeOS;
33 class BluetoothRemoteGattDescriptorChromeOS;
35 // The BluetoothRemoteGattServiceChromeOS class implements BluetootGattService
36 // for remote GATT services on the the Chrome OS platform.
37 class BluetoothRemoteGattServiceChromeOS
38 : public device::BluetoothGattService,
39 public BluetoothGattServiceClient::Observer,
40 public BluetoothGattCharacteristicClient::Observer {
41 public:
42 // device::BluetoothGattService overrides.
43 virtual std::string GetIdentifier() const OVERRIDE;
44 virtual device::BluetoothUUID GetUUID() const OVERRIDE;
45 virtual bool IsLocal() const OVERRIDE;
46 virtual bool IsPrimary() const OVERRIDE;
47 virtual device::BluetoothDevice* GetDevice() const OVERRIDE;
48 virtual std::vector<device::BluetoothGattCharacteristic*>
49 GetCharacteristics() const OVERRIDE;
50 virtual std::vector<device::BluetoothGattService*>
51 GetIncludedServices() const OVERRIDE;
52 virtual device::BluetoothGattCharacteristic* GetCharacteristic(
53 const std::string& identifier) const OVERRIDE;
54 virtual bool AddCharacteristic(
55 device::BluetoothGattCharacteristic* characteristic) OVERRIDE;
56 virtual bool AddIncludedService(
57 device::BluetoothGattService* service) OVERRIDE;
58 virtual void Register(const base::Closure& callback,
59 const ErrorCallback& error_callback) OVERRIDE;
60 virtual void Unregister(const base::Closure& callback,
61 const ErrorCallback& error_callback) OVERRIDE;
63 // Object path of the underlying service.
64 const dbus::ObjectPath& object_path() const { return object_path_; }
66 // Returns the adapter associated with this service.
67 BluetoothAdapterChromeOS* GetAdapter() const;
69 // Notifies its observers that the GATT service has changed. This is mainly
70 // used by BluetoothRemoteGattCharacteristicChromeOS instances to notify
71 // service observers when characteristic descriptors get added and removed.
72 void NotifyServiceChanged();
74 // Notifies its observers that the value of a characteristic has changed.
75 // Called by BluetoothRemoteGattCharacteristicChromeOS instances to notify
76 // service observers when their cached value is updated after a successful
77 // read request or when a "ValueUpdated" signal is received.
78 void NotifyCharacteristicValueChanged(
79 BluetoothRemoteGattCharacteristicChromeOS* characteristic,
80 const std::vector<uint8>& value);
82 // Notifies its observers that a descriptor |descriptor| belonging to
83 // characteristic |characteristic| has been added or removed. This is used
84 // by BluetoothRemoteGattCharacteristicChromeOS instances to notify service
85 // observers when characteristic descriptors get added and removed. If |added|
86 // is true, an "Added" event will be sent. Otherwise, a "Removed" event will
87 // be sent.
88 void NotifyDescriptorAddedOrRemoved(
89 BluetoothRemoteGattCharacteristicChromeOS* characteristic,
90 BluetoothRemoteGattDescriptorChromeOS* descriptor,
91 bool added);
93 // Notifies its observers that the value of a descriptor has changed. Called
94 // by BluetoothRemoteGattDescriptorChromeOS instances to notify service
95 // observers when their cached value gets updated after a read request.
96 void NotifyDescriptorValueChanged(
97 BluetoothRemoteGattCharacteristicChromeOS* characteristic,
98 BluetoothRemoteGattDescriptorChromeOS* descriptor,
99 const std::vector<uint8>& value);
101 private:
102 friend class BluetoothDeviceChromeOS;
104 BluetoothRemoteGattServiceChromeOS(BluetoothAdapterChromeOS* adapter,
105 BluetoothDeviceChromeOS* device,
106 const dbus::ObjectPath& object_path);
107 virtual ~BluetoothRemoteGattServiceChromeOS();
109 // BluetoothGattServiceClient::Observer override.
110 virtual void GattServicePropertyChanged(
111 const dbus::ObjectPath& object_path,
112 const std::string& property_name) OVERRIDE;
114 // BluetoothGattCharacteristicClient::Observer override.
115 virtual void GattCharacteristicAdded(
116 const dbus::ObjectPath& object_path) OVERRIDE;
117 virtual void GattCharacteristicRemoved(
118 const dbus::ObjectPath& object_path) OVERRIDE;
119 virtual void GattCharacteristicPropertyChanged(
120 const dbus::ObjectPath& object_path,
121 const std::string& property_name) OVERRIDE;
123 // Object path of the GATT service.
124 dbus::ObjectPath object_path_;
126 // The adapter associated with this service. It's ok to store a raw pointer
127 // here since |adapter_| indirectly owns this instance.
128 BluetoothAdapterChromeOS* adapter_;
130 // The device this GATT service belongs to. It's ok to store a raw pointer
131 // here since |device_| owns this instance.
132 BluetoothDeviceChromeOS* device_;
134 // Mapping from GATT characteristic object paths to characteristic objects.
135 // owned by this service. Since the Chrome OS implementation uses object
136 // paths as unique identifiers, we also use this mapping to return
137 // characteristics by identifier.
138 typedef std::map<dbus::ObjectPath, BluetoothRemoteGattCharacteristicChromeOS*>
139 CharacteristicMap;
140 CharacteristicMap characteristics_;
142 // Indicates whether or not the characteristics of this service are known to
143 // have been discovered.
144 bool discovery_complete_;
146 // Note: This should remain the last member so it'll be destroyed and
147 // invalidate its weak pointers before any other members are destroyed.
148 base::WeakPtrFactory<BluetoothRemoteGattServiceChromeOS> weak_ptr_factory_;
150 DISALLOW_COPY_AND_ASSIGN(BluetoothRemoteGattServiceChromeOS);
153 } // namespace chromeos
155 #endif // DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_SERVICE_CHROMEOS_H_