Move notification sending out of AutocompleteController
[chromium-blink-merge.git] / device / bluetooth / bluetooth_remote_gatt_service_chromeos.h
blob9aa8fdd2a78eaea217bc64a1172cf398aa974997
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 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 std::string GetIdentifier() const override;
44 device::BluetoothUUID GetUUID() const override;
45 bool IsLocal() const override;
46 bool IsPrimary() const override;
47 device::BluetoothDevice* GetDevice() const override;
48 std::vector<device::BluetoothGattCharacteristic*> GetCharacteristics()
49 const override;
50 std::vector<device::BluetoothGattService*> GetIncludedServices()
51 const override;
52 device::BluetoothGattCharacteristic* GetCharacteristic(
53 const std::string& identifier) const override;
54 bool AddCharacteristic(
55 device::BluetoothGattCharacteristic* characteristic) override;
56 bool AddIncludedService(device::BluetoothGattService* service) override;
57 void Register(const base::Closure& callback,
58 const ErrorCallback& error_callback) override;
59 void Unregister(const base::Closure& callback,
60 const ErrorCallback& error_callback) override;
62 // Object path of the underlying service.
63 const dbus::ObjectPath& object_path() const { return object_path_; }
65 // Parses a named D-Bus error into a service error code.
66 static device::BluetoothGattService::GattErrorCode DBusErrorToServiceError(
67 const std::string error_name);
69 // Returns the adapter associated with this service.
70 BluetoothAdapterChromeOS* GetAdapter() const;
72 // Notifies its observers that the GATT service has changed. This is mainly
73 // used by BluetoothRemoteGattCharacteristicChromeOS instances to notify
74 // service observers when characteristic descriptors get added and removed.
75 void NotifyServiceChanged();
77 // Notifies its observers that a descriptor |descriptor| belonging to
78 // characteristic |characteristic| has been added or removed. This is used
79 // by BluetoothRemoteGattCharacteristicChromeOS instances to notify service
80 // observers when characteristic descriptors get added and removed. If |added|
81 // is true, an "Added" event will be sent. Otherwise, a "Removed" event will
82 // be sent.
83 void NotifyDescriptorAddedOrRemoved(
84 BluetoothRemoteGattCharacteristicChromeOS* characteristic,
85 BluetoothRemoteGattDescriptorChromeOS* descriptor,
86 bool added);
88 // Notifies its observers that the value of a descriptor has changed. Called
89 // by BluetoothRemoteGattCharacteristicChromeOS instances to notify service
90 // observers.
91 void NotifyDescriptorValueChanged(
92 BluetoothRemoteGattCharacteristicChromeOS* characteristic,
93 BluetoothRemoteGattDescriptorChromeOS* descriptor,
94 const std::vector<uint8>& value);
96 private:
97 friend class BluetoothDeviceChromeOS;
99 typedef std::map<dbus::ObjectPath, BluetoothRemoteGattCharacteristicChromeOS*>
100 CharacteristicMap;
102 BluetoothRemoteGattServiceChromeOS(BluetoothAdapterChromeOS* adapter,
103 BluetoothDeviceChromeOS* device,
104 const dbus::ObjectPath& object_path);
105 ~BluetoothRemoteGattServiceChromeOS() override;
107 // BluetoothGattServiceClient::Observer override.
108 void GattServicePropertyChanged(const dbus::ObjectPath& object_path,
109 const std::string& property_name) override;
111 // BluetoothGattCharacteristicClient::Observer override.
112 void GattCharacteristicAdded(const dbus::ObjectPath& object_path) override;
113 void GattCharacteristicRemoved(const dbus::ObjectPath& object_path) override;
114 void GattCharacteristicPropertyChanged(
115 const dbus::ObjectPath& object_path,
116 const std::string& property_name) override;
118 // Object path of the GATT service.
119 dbus::ObjectPath object_path_;
121 // The adapter associated with this service. It's ok to store a raw pointer
122 // here since |adapter_| indirectly owns this instance.
123 BluetoothAdapterChromeOS* adapter_;
125 // The device this GATT service belongs to. It's ok to store a raw pointer
126 // here since |device_| owns this instance.
127 BluetoothDeviceChromeOS* device_;
129 // Mapping from GATT characteristic object paths to characteristic objects.
130 // owned by this service. Since the Chrome OS implementation uses object
131 // paths as unique identifiers, we also use this mapping to return
132 // characteristics by identifier.
133 CharacteristicMap characteristics_;
135 // Indicates whether or not the characteristics of this service are known to
136 // have been discovered.
137 bool discovery_complete_;
139 // Note: This should remain the last member so it'll be destroyed and
140 // invalidate its weak pointers before any other members are destroyed.
141 base::WeakPtrFactory<BluetoothRemoteGattServiceChromeOS> weak_ptr_factory_;
143 DISALLOW_COPY_AND_ASSIGN(BluetoothRemoteGattServiceChromeOS);
146 } // namespace chromeos
148 #endif // DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_SERVICE_CHROMEOS_H_