OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROMEOS_DBUS_BLUETOOTH_GATT_DESCRIPTOR_CLIENT_H_ | 5 #ifndef CHROMEOS_DBUS_BLUETOOTH_GATT_DESCRIPTOR_CLIENT_H_ |
6 #define CHROMEOS_DBUS_BLUETOOTH_GATT_DESCRIPTOR_CLIENT_H_ | 6 #define CHROMEOS_DBUS_BLUETOOTH_GATT_DESCRIPTOR_CLIENT_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/callback.h" |
11 #include "chromeos/chromeos_export.h" | 12 #include "chromeos/chromeos_export.h" |
12 #include "chromeos/dbus/dbus_client.h" | 13 #include "chromeos/dbus/dbus_client.h" |
13 #include "dbus/object_path.h" | 14 #include "dbus/object_path.h" |
14 #include "dbus/property.h" | 15 #include "dbus/property.h" |
15 | 16 |
16 namespace chromeos { | 17 namespace chromeos { |
17 | 18 |
18 // BluetoothGattDescriptorClient is used to communicate with remote GATT | 19 // BluetoothGattDescriptorClient is used to communicate with remote GATT |
19 // characteristic descriptor objects exposed by the Bluetooth daemon. | 20 // characteristic descriptor objects exposed by the Bluetooth daemon. |
20 class CHROMEOS_EXPORT BluetoothGattDescriptorClient : public DBusClient { | 21 class CHROMEOS_EXPORT BluetoothGattDescriptorClient : public DBusClient { |
21 public: | 22 public: |
22 // Structure of properties associated with GATT descriptors. | 23 // Structure of properties associated with GATT descriptors. |
23 struct Properties : public dbus::PropertySet { | 24 struct Properties : public dbus::PropertySet { |
24 // The 128-bit characteristic descriptor UUID. [read-only] | 25 // The 128-bit characteristic descriptor UUID. [read-only] |
25 dbus::Property<std::string> uuid; | 26 dbus::Property<std::string> uuid; |
26 | 27 |
27 // Object path of the GATT characteristic the descriptor belongs to. | 28 // Object path of the GATT characteristic the descriptor belongs to. |
28 // [read-only] | 29 // [read-only] |
29 dbus::Property<dbus::ObjectPath> characteristic; | 30 dbus::Property<dbus::ObjectPath> characteristic; |
30 | 31 |
31 // Raw characteristic descriptor value read from the remote Bluetooth | |
32 // device. Setting the value sends a write request to the remote device. | |
33 // [read-write] | |
34 dbus::Property<std::vector<uint8> > value; | |
35 | |
36 Properties(dbus::ObjectProxy* object_proxy, | 32 Properties(dbus::ObjectProxy* object_proxy, |
37 const std::string& interface_name, | 33 const std::string& interface_name, |
38 const PropertyChangedCallback& callback); | 34 const PropertyChangedCallback& callback); |
39 virtual ~Properties(); | 35 virtual ~Properties(); |
40 }; | 36 }; |
41 | 37 |
42 // Interface for observing changes from a remote GATT characteristic | 38 // Interface for observing changes from a remote GATT characteristic |
43 // descriptor. | 39 // descriptor. |
44 class Observer { | 40 class Observer { |
45 public: | 41 public: |
46 virtual ~Observer() {} | 42 virtual ~Observer() {} |
47 | 43 |
48 // Called when the GATT descriptor with object path |object_path| is added | 44 // Called when the GATT descriptor with object path |object_path| is added |
49 // to the system. | 45 // to the system. |
50 virtual void GattDescriptorAdded(const dbus::ObjectPath& object_path) {} | 46 virtual void GattDescriptorAdded(const dbus::ObjectPath& object_path) {} |
51 | 47 |
52 // Called when the GATT descriptor with object path |object_path| is removed | 48 // Called when the GATT descriptor with object path |object_path| is removed |
53 // from the system. | 49 // from the system. |
54 virtual void GattDescriptorRemoved(const dbus::ObjectPath& object_path) {} | 50 virtual void GattDescriptorRemoved(const dbus::ObjectPath& object_path) {} |
55 | 51 |
56 // Called when the GATT descriptor with object path |object_path| has a | 52 // Called when the GATT descriptor with object path |object_path| has a |
57 // change in the value of the property named |property_name|. | 53 // change in the value of the property named |property_name|. |
58 virtual void GattDescriptorPropertyChanged( | 54 virtual void GattDescriptorPropertyChanged( |
59 const dbus::ObjectPath& object_path, | 55 const dbus::ObjectPath& object_path, |
60 const std::string& property_name) {} | 56 const std::string& property_name) {} |
61 }; | 57 }; |
62 | 58 |
| 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; |
| 63 |
63 virtual ~BluetoothGattDescriptorClient(); | 64 virtual ~BluetoothGattDescriptorClient(); |
64 | 65 |
65 // Adds and removes observers for events on all remote GATT descriptors. Check | 66 // Adds and removes observers for events on all remote GATT descriptors. Check |
66 // the |object_path| parameter of observer methods to determine which GATT | 67 // the |object_path| parameter of observer methods to determine which GATT |
67 // descriptor is issuing the event. | 68 // descriptor is issuing the event. |
68 virtual void AddObserver(Observer* observer) = 0; | 69 virtual void AddObserver(Observer* observer) = 0; |
69 virtual void RemoveObserver(Observer* observer) = 0; | 70 virtual void RemoveObserver(Observer* observer) = 0; |
70 | 71 |
71 // Returns the list of GATT descriptor object paths known to the system. | 72 // Returns the list of GATT descriptor object paths known to the system. |
72 virtual std::vector<dbus::ObjectPath> GetDescriptors() = 0; | 73 virtual std::vector<dbus::ObjectPath> GetDescriptors() = 0; |
73 | 74 |
74 // Obtain the properties for the GATT descriptor with object path | 75 // Obtain the properties for the GATT descriptor with object path |
75 // |object_path|. Values should be copied if needed. | 76 // |object_path|. Values should be copied if needed. |
76 virtual Properties* GetProperties(const dbus::ObjectPath& object_path) = 0; | 77 virtual Properties* GetProperties(const dbus::ObjectPath& object_path) = 0; |
77 | 78 |
| 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; |
| 85 |
| 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; |
| 93 |
78 // Creates the instance. | 94 // Creates the instance. |
79 static BluetoothGattDescriptorClient* Create(); | 95 static BluetoothGattDescriptorClient* Create(); |
80 | 96 |
| 97 // Constants used to indicate exceptional error conditions. |
| 98 static const char kNoResponseError[]; |
| 99 static const char kUnknownDescriptorError[]; |
| 100 |
81 protected: | 101 protected: |
82 BluetoothGattDescriptorClient(); | 102 BluetoothGattDescriptorClient(); |
83 | 103 |
84 private: | 104 private: |
85 DISALLOW_COPY_AND_ASSIGN(BluetoothGattDescriptorClient); | 105 DISALLOW_COPY_AND_ASSIGN(BluetoothGattDescriptorClient); |
86 }; | 106 }; |
87 | 107 |
88 } // namespace chromeos | 108 } // namespace chromeos |
89 | 109 |
90 #endif // CHROMEOS_DBUS_BLUETOOTH_GATT_DESCRIPTOR_CLIENT_H_ | 110 #endif // CHROMEOS_DBUS_BLUETOOTH_GATT_DESCRIPTOR_CLIENT_H_ |
OLD | NEW |