Gallery.app: Remove the video related code from Gallery.
[chromium-blink-merge.git] / device / bluetooth / bluetooth_remote_gatt_service_chromeos.h
blobc9de5cea9dfcd3bce28df51952bb0e6492dfa44e
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/weak_ptr.h"
13 #include "base/observer_list.h"
14 #include "chromeos/dbus/bluetooth_gatt_characteristic_client.h"
15 #include "chromeos/dbus/bluetooth_gatt_service_client.h"
16 #include "dbus/object_path.h"
17 #include "device/bluetooth/bluetooth_gatt_service.h"
18 #include "device/bluetooth/bluetooth_uuid.h"
20 namespace device {
22 class BluetoothGattCharacteristic;
24 } // namespace device
26 namespace chromeos {
28 class BluetoothDeviceChromeOS;
29 class BluetoothRemoteGattCharacteristicChromeOS;
30 class BluetoothRemoteGattDescriptorChromeOS;
32 // The BluetoothRemoteGattServiceChromeOS class implements BluetootGattService
33 // for remote GATT services on the the Chrome OS platform.
34 class BluetoothRemoteGattServiceChromeOS
35 : public device::BluetoothGattService,
36 public BluetoothGattServiceClient::Observer,
37 public BluetoothGattCharacteristicClient::Observer {
38 public:
39 // device::BluetoothGattService overrides.
40 virtual void AddObserver(
41 device::BluetoothGattService::Observer* observer) OVERRIDE;
42 virtual void RemoveObserver(
43 device::BluetoothGattService::Observer* observer) OVERRIDE;
44 virtual std::string GetIdentifier() const OVERRIDE;
45 virtual device::BluetoothUUID GetUUID() const OVERRIDE;
46 virtual bool IsLocal() const OVERRIDE;
47 virtual bool IsPrimary() const OVERRIDE;
48 virtual device::BluetoothDevice* GetDevice() const OVERRIDE;
49 virtual std::vector<device::BluetoothGattCharacteristic*>
50 GetCharacteristics() const OVERRIDE;
51 virtual std::vector<device::BluetoothGattService*>
52 GetIncludedServices() const OVERRIDE;
53 virtual device::BluetoothGattCharacteristic* GetCharacteristic(
54 const std::string& identifier) const OVERRIDE;
55 virtual bool AddCharacteristic(
56 device::BluetoothGattCharacteristic* characteristic) OVERRIDE;
57 virtual bool AddIncludedService(
58 device::BluetoothGattService* service) OVERRIDE;
59 virtual void Register(const base::Closure& callback,
60 const ErrorCallback& error_callback) OVERRIDE;
61 virtual void Unregister(const base::Closure& callback,
62 const ErrorCallback& error_callback) OVERRIDE;
64 // Object path of the underlying service.
65 const dbus::ObjectPath& object_path() const { return object_path_; }
67 // Notifies its observers that the GATT service has changed. This is mainly
68 // used by BluetoothRemoteGattCharacteristicChromeOS instances to notify
69 // service observers when characteristic descriptors get added and removed.
70 void NotifyServiceChanged();
72 // Notifies its observers that the value of a characteristic has changed.
73 // Called by BluetoothRemoteGattCharacteristicChromeOS instances to notify
74 // service observers when their cached value is updated after a successful
75 // read request or when a "ValueUpdated" signal is received.
76 void NotifyCharacteristicValueChanged(
77 BluetoothRemoteGattCharacteristicChromeOS* characteristic,
78 const std::vector<uint8>& value);
80 // Notifies its observers that a descriptor |descriptor| belonging to
81 // characteristic |characteristic| has been added or removed. This is used
82 // by BluetoothRemoteGattCharacteristicChromeOS instances to notify service
83 // observers when characteristic descriptors get added and removed. If |added|
84 // is true, an "Added" event will be sent. Otherwise, a "Removed" event will
85 // be sent.
86 void NotifyDescriptorAddedOrRemoved(
87 BluetoothRemoteGattCharacteristicChromeOS* characteristic,
88 BluetoothRemoteGattDescriptorChromeOS* descriptor,
89 bool added);
91 // Notifies its observers that the value of a descriptor has changed. Called
92 // by BluetoothRemoteGattDescriptorChromeOS instances to notify service
93 // observers when their cached value gets updated after a read request.
94 void NotifyDescriptorValueChanged(
95 BluetoothRemoteGattCharacteristicChromeOS* characteristic,
96 BluetoothRemoteGattDescriptorChromeOS* descriptor,
97 const std::vector<uint8>& value);
99 private:
100 friend class BluetoothDeviceChromeOS;
102 BluetoothRemoteGattServiceChromeOS(BluetoothDeviceChromeOS* device,
103 const dbus::ObjectPath& object_path);
104 virtual ~BluetoothRemoteGattServiceChromeOS();
106 // BluetoothGattServiceClient::Observer override.
107 virtual void GattServicePropertyChanged(
108 const dbus::ObjectPath& object_path,
109 const std::string& property_name) OVERRIDE;
111 // BluetoothGattCharacteristicClient::Observer override.
112 virtual void GattCharacteristicAdded(
113 const dbus::ObjectPath& object_path) OVERRIDE;
114 virtual void GattCharacteristicRemoved(
115 const dbus::ObjectPath& object_path) OVERRIDE;
116 virtual void GattCharacteristicPropertyChanged(
117 const dbus::ObjectPath& object_path,
118 const std::string& property_name) OVERRIDE;
120 // Object path of the GATT service.
121 dbus::ObjectPath object_path_;
123 // List of observers interested in event notifications from us.
124 ObserverList<device::BluetoothGattService::Observer> observers_;
126 // The device this GATT service belongs to.
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 typedef std::map<dbus::ObjectPath, BluetoothRemoteGattCharacteristicChromeOS*>
134 CharacteristicMap;
135 CharacteristicMap characteristics_;
137 // Note: This should remain the last member so it'll be destroyed and
138 // invalidate its weak pointers before any other members are destroyed.
139 base::WeakPtrFactory<BluetoothRemoteGattServiceChromeOS> weak_ptr_factory_;
141 DISALLOW_COPY_AND_ASSIGN(BluetoothRemoteGattServiceChromeOS);
144 } // namespace chromeos
146 #endif // DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_SERVICE_CHROMEOS_H_