Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(416)

Side by Side Diff: chromeos/dbus/bluetooth_gatt_characteristic_client.h

Issue 1347193004: Refactor DBusThreadManager to split away BT clients. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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_CHARACTERISTIC_CLIENT_H_
6 #define CHROMEOS_DBUS_BLUETOOTH_GATT_CHARACTERISTIC_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 // BluetoothGattCharacteristicClient is used to communicate with remote GATT
21 // characteristic objects exposed by the Bluetooth daemon.
22 class CHROMEOS_EXPORT BluetoothGattCharacteristicClient : public DBusClient {
23 public:
24 // Structure of properties associated with GATT characteristics.
25 struct Properties : public dbus::PropertySet {
26 // The 128-bit characteristic UUID. [read-only]
27 dbus::Property<std::string> uuid;
28
29 // Object path of the GATT service the characteristic belongs to.
30 // [read-only]
31 dbus::Property<dbus::ObjectPath> service;
32
33 // The cached value of the characteristic. This property gets updated only
34 // after a successful read request and when a notification or indication is
35 // received. [read-only]
36 dbus::Property<std::vector<uint8_t>> value;
37
38 // Whether or not this characteristic is currently sending ValueUpdated
39 // signals. [read-only]
40 dbus::Property<bool> notifying;
41
42 // List of flags representing the GATT "Characteristic Properties bit field"
43 // and properties read from the GATT "Characteristic Extended Properties"
44 // descriptor bit field. [read-only, optional]
45 dbus::Property<std::vector<std::string>> flags;
46
47 // Array of object paths representing the descriptors of this
48 // characteristic. [read-only]
49 dbus::Property<std::vector<dbus::ObjectPath>> descriptors;
50
51 Properties(dbus::ObjectProxy* object_proxy,
52 const std::string& interface_name,
53 const PropertyChangedCallback& callback);
54 ~Properties() override;
55 };
56
57 // Interface for observing changes from a remote GATT characteristic.
58 class Observer {
59 public:
60 virtual ~Observer() {}
61
62 // Called when the GATT characteristic with object path |object_path| is
63 // added to the system.
64 virtual void GattCharacteristicAdded(const dbus::ObjectPath& object_path) {}
65
66 // Called when the GATT characteristic with object path |object_path| is
67 // removed from the system.
68 virtual void GattCharacteristicRemoved(
69 const dbus::ObjectPath& object_path) {}
70
71 // Called when the GATT characteristic with object path |object_path| has a
72 // change in the value of the property named |property_name|.
73 virtual void GattCharacteristicPropertyChanged(
74 const dbus::ObjectPath& object_path,
75 const std::string& property_name) {}
76 };
77
78 // Callbacks used to report the result of asynchronous methods.
79 typedef base::Callback<void(const std::string& error_name,
80 const std::string& error_message)> ErrorCallback;
81 typedef base::Callback<void(const std::vector<uint8>& value)> ValueCallback;
82
83 ~BluetoothGattCharacteristicClient() override;
84
85 // Adds and removes observers for events on all remote GATT characteristics.
86 // Check the |object_path| parameter of observer methods to determine which
87 // GATT characteristic is issuing the event.
88 virtual void AddObserver(Observer* observer) = 0;
89 virtual void RemoveObserver(Observer* observer) = 0;
90
91 // Returns the list of GATT characteristic object paths known to the system.
92 virtual std::vector<dbus::ObjectPath> GetCharacteristics() = 0;
93
94 // Obtain the properties for the GATT characteristic with object path
95 // |object_path|. Values should be copied if needed.
96 virtual Properties* GetProperties(const dbus::ObjectPath& object_path) = 0;
97
98 // Issues a request to read the value of GATT characteristic with object path
99 // |object_path| and returns the value in |callback| on success. On error,
100 // invokes |error_callback|.
101 virtual void ReadValue(const dbus::ObjectPath& object_path,
102 const ValueCallback& callback,
103 const ErrorCallback& error_callback) = 0;
104
105 // Issues a request to write the value of GATT characteristic with object path
106 // |object_path| with value |value|. Invokes |callback| on success and
107 // |error_callback| on failure.
108 virtual void WriteValue(const dbus::ObjectPath& object_path,
109 const std::vector<uint8>& value,
110 const base::Closure& callback,
111 const ErrorCallback& error_callback) = 0;
112
113 // Starts a notification session from this characteristic with object path
114 // |object_path| if it supports value notifications or indications. Invokes
115 // |callback| on success and |error_callback| on failure.
116 virtual void StartNotify(const dbus::ObjectPath& object_path,
117 const base::Closure& callback,
118 const ErrorCallback& error_callback) = 0;
119
120 // Cancels any previous StartNotify transaction for characteristic with
121 // object path |object_path|. Invokes |callback| on success and
122 // |error_callback| on failure.
123 virtual void StopNotify(const dbus::ObjectPath& object_path,
124 const base::Closure& callback,
125 const ErrorCallback& error_callback) = 0;
126
127 // Creates the instance.
128 static BluetoothGattCharacteristicClient* Create();
129
130 // Constants used to indicate exceptional error conditions.
131 static const char kNoResponseError[];
132 static const char kUnknownCharacteristicError[];
133
134 protected:
135 BluetoothGattCharacteristicClient();
136
137 private:
138 DISALLOW_COPY_AND_ASSIGN(BluetoothGattCharacteristicClient);
139 };
140
141 } // namespace chromeos
142
143 #endif // CHROMEOS_DBUS_BLUETOOTH_GATT_CHARACTERISTIC_CLIENT_H_
OLDNEW
« no previous file with comments | « chromeos/dbus/bluetooth_device_client.cc ('k') | chromeos/dbus/bluetooth_gatt_characteristic_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698