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