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 CHROMEOS_DBUS_BLUETOOTH_GATT_DESCRIPTOR_CLIENT_H_
6 #define CHROMEOS_DBUS_BLUETOOTH_GATT_DESCRIPTOR_CLIENT_H_
10 #include "base/basictypes.h"
11 #include "base/callback.h"
12 #include "chromeos/chromeos_export.h"
13 #include "chromeos/dbus/dbus_client.h"
14 #include "dbus/object_path.h"
15 #include "dbus/property.h"
19 // BluetoothGattDescriptorClient is used to communicate with remote GATT
20 // characteristic descriptor objects exposed by the Bluetooth daemon.
21 class CHROMEOS_EXPORT BluetoothGattDescriptorClient
: public DBusClient
{
23 // Structure of properties associated with GATT descriptors.
24 struct Properties
: public dbus::PropertySet
{
25 // The 128-bit characteristic descriptor UUID. [read-only]
26 dbus::Property
<std::string
> uuid
;
28 // Object path of the GATT characteristic the descriptor belongs to.
30 dbus::Property
<dbus::ObjectPath
> characteristic
;
32 Properties(dbus::ObjectProxy
* object_proxy
,
33 const std::string
& interface_name
,
34 const PropertyChangedCallback
& callback
);
35 ~Properties() override
;
38 // Interface for observing changes from a remote GATT characteristic
42 virtual ~Observer() {}
44 // Called when the GATT descriptor with object path |object_path| is added
46 virtual void GattDescriptorAdded(const dbus::ObjectPath
& object_path
) {}
48 // Called when the GATT descriptor with object path |object_path| is removed
50 virtual void GattDescriptorRemoved(const dbus::ObjectPath
& object_path
) {}
52 // Called when the GATT descriptor with object path |object_path| has a
53 // change in the value of the property named |property_name|.
54 virtual void GattDescriptorPropertyChanged(
55 const dbus::ObjectPath
& object_path
,
56 const std::string
& property_name
) {}
59 // Callbacks used to report the result of asynchronous methods.
60 typedef base::Callback
<void(const std::string
& error_name
,
61 const std::string
& error_message
)> ErrorCallback
;
62 typedef base::Callback
<void(const std::vector
<uint8
>& value
)> ValueCallback
;
64 ~BluetoothGattDescriptorClient() override
;
66 // Adds and removes observers for events on all remote GATT descriptors. Check
67 // the |object_path| parameter of observer methods to determine which GATT
68 // descriptor is issuing the event.
69 virtual void AddObserver(Observer
* observer
) = 0;
70 virtual void RemoveObserver(Observer
* observer
) = 0;
72 // Returns the list of GATT descriptor object paths known to the system.
73 virtual std::vector
<dbus::ObjectPath
> GetDescriptors() = 0;
75 // Obtain the properties for the GATT descriptor with object path
76 // |object_path|. Values should be copied if needed.
77 virtual Properties
* GetProperties(const dbus::ObjectPath
& object_path
) = 0;
79 // Issues a request to read the value of GATT descriptor with object path
80 // |object_path| and returns the value in |callback| on success. On error,
81 // invokes |error_callback|.
82 virtual void ReadValue(const dbus::ObjectPath
& object_path
,
83 const ValueCallback
& callback
,
84 const ErrorCallback
& error_callback
) = 0;
86 // Issues a request to write the value of GATT descriptor with object path
87 // |object_path| with value |value|. Invokes |callback| on success and
88 // |error_callback| on failure.
89 virtual void WriteValue(const dbus::ObjectPath
& object_path
,
90 const std::vector
<uint8
>& value
,
91 const base::Closure
& callback
,
92 const ErrorCallback
& error_callback
) = 0;
94 // Creates the instance.
95 static BluetoothGattDescriptorClient
* Create();
97 // Constants used to indicate exceptional error conditions.
98 static const char kNoResponseError
[];
99 static const char kUnknownDescriptorError
[];
102 BluetoothGattDescriptorClient();
105 DISALLOW_COPY_AND_ASSIGN(BluetoothGattDescriptorClient
);
108 } // namespace chromeos
110 #endif // CHROMEOS_DBUS_BLUETOOTH_GATT_DESCRIPTOR_CLIENT_H_