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_
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"
22 class BluetoothGattCharacteristic
;
28 class BluetoothDeviceChromeOS
;
29 class BluetoothRemoteGattCharacteristicChromeOS
;
31 // The BluetoothRemoteGattServiceChromeOS class implements BluetootGattService
32 // for remote GATT services on the the Chrome OS platform.
33 class BluetoothRemoteGattServiceChromeOS
34 : public device::BluetoothGattService
,
35 public BluetoothGattServiceClient::Observer
,
36 public BluetoothGattCharacteristicClient::Observer
{
38 // device::BluetoothGattService overrides.
39 virtual void AddObserver(
40 device::BluetoothGattService::Observer
* observer
) OVERRIDE
;
41 virtual void RemoveObserver(
42 device::BluetoothGattService::Observer
* observer
) OVERRIDE
;
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 std::vector
<device::BluetoothGattCharacteristic
*>
48 GetCharacteristics() const OVERRIDE
;
49 virtual std::vector
<device::BluetoothGattService
*>
50 GetIncludedServices() const OVERRIDE
;
51 virtual device::BluetoothGattCharacteristic
* GetCharacteristic(
52 const std::string
& identifier
) OVERRIDE
;
53 virtual bool AddCharacteristic(
54 device::BluetoothGattCharacteristic
* characteristic
) OVERRIDE
;
55 virtual bool AddIncludedService(
56 device::BluetoothGattService
* service
) OVERRIDE
;
57 virtual void Register(const base::Closure
& callback
,
58 const ErrorCallback
& error_callback
) OVERRIDE
;
59 virtual 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 // Notifies its observers that the GATT service has changed. This is mainly
66 // used by BluetoothRemoteGattCharacteristicChromeOS instances to notify
67 // service observers when characteristic descriptors get added and removed.
68 void NotifyServiceChanged();
71 friend class BluetoothDeviceChromeOS
;
73 BluetoothRemoteGattServiceChromeOS(BluetoothDeviceChromeOS
* device
,
74 const dbus::ObjectPath
& object_path
);
75 virtual ~BluetoothRemoteGattServiceChromeOS();
77 // BluetoothGattServiceClient::Observer override.
78 virtual void GattServicePropertyChanged(
79 const dbus::ObjectPath
& object_path
,
80 const std::string
& property_name
) OVERRIDE
;
82 // BluetoothGattCharacteristicClient::Observer override.
83 virtual void GattCharacteristicAdded(
84 const dbus::ObjectPath
& object_path
) OVERRIDE
;
85 virtual void GattCharacteristicRemoved(
86 const dbus::ObjectPath
& object_path
) OVERRIDE
;
87 virtual void GattCharacteristicPropertyChanged(
88 const dbus::ObjectPath
& object_path
,
89 const std::string
& property_name
) OVERRIDE
;
91 // Object path of the GATT service.
92 dbus::ObjectPath object_path_
;
94 // List of observers interested in event notifications from us.
95 ObserverList
<device::BluetoothGattService::Observer
> observers_
;
97 // The device this GATT service belongs to.
98 BluetoothDeviceChromeOS
* device_
;
100 // Mapping from GATT characteristic object paths to characteristic objects.
101 // owned by this service. Since the Chrome OS implementation uses object
102 // paths as unique identifiers, we also use this mapping to return
103 // characteristics by identifier.
104 typedef std::map
<dbus::ObjectPath
, BluetoothRemoteGattCharacteristicChromeOS
*>
106 CharacteristicMap characteristics_
;
108 // Note: This should remain the last member so it'll be destroyed and
109 // invalidate its weak pointers before any other members are destroyed.
110 base::WeakPtrFactory
<BluetoothRemoteGattServiceChromeOS
> weak_ptr_factory_
;
112 DISALLOW_COPY_AND_ASSIGN(BluetoothRemoteGattServiceChromeOS
);
115 } // namespace chromeos
117 #endif // DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_SERVICE_CHROMEOS_H_