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

Side by Side Diff: device/bluetooth/bluetooth_device.h

Issue 13416005: Bluetooth: clean up BluetoothDevice (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Make GetServices return a copy of the list Created 7 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « device/bluetooth/bluetooth_adapter_win.cc ('k') | device/bluetooth/bluetooth_device.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_H_ 5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_H_
6 #define DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_H_ 6 #define DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector>
10 9
11 #include "base/callback.h" 10 #include "base/callback.h"
12 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_vector.h" 12 #include "base/memory/scoped_vector.h"
14 #include "base/string16.h" 13 #include "base/string16.h"
15 14
16 namespace device { 15 namespace device {
17 16
18 class BluetoothServiceRecord; 17 class BluetoothServiceRecord;
19 class BluetoothSocket; 18 class BluetoothSocket;
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 // and removed from the user. 143 // and removed from the user.
145 virtual void DismissDisplayOrConfirm() = 0; 144 virtual void DismissDisplayOrConfirm() = 0;
146 }; 145 };
147 146
148 // Returns true if uuid is in a a valid canonical format 147 // Returns true if uuid is in a a valid canonical format
149 // (see utils::CanonicalUuid). 148 // (see utils::CanonicalUuid).
150 static bool IsUUIDValid(const std::string& uuid); 149 static bool IsUUIDValid(const std::string& uuid);
151 150
152 virtual ~BluetoothDevice(); 151 virtual ~BluetoothDevice();
153 152
153 // Returns the Bluetooth class of the device. GetDeviceType() is preferred
154 // since that already decodes this bit field.
155 virtual uint32 bluetooth_class() const = 0;
youngki 2013/04/03 22:17:17 Should we make bluetooth_class() and name() (proba
keybuk 2013/04/03 22:18:56 I'm happy with that
stevenjb 2013/04/03 23:04:57 Do we even need these in the public interface, or
stevenjb 2013/04/04 00:47:31 If we need these as pure virtuals then we should r
keybuk 2013/04/04 01:18:07 Done.
156
157 // Returns the system name of the Bluetooth device. When being used for
158 // display, GetName() should be preferred.
159 virtual std::string name() const = 0;
160
154 // Returns the Bluetooth of address the device. This should be used as 161 // Returns the Bluetooth of address the device. This should be used as
155 // a unique key to identify the device and copied where needed. 162 // a unique key to identify the device and copied where needed.
156 virtual const std::string& address() const; 163 virtual std::string address() const = 0;
157 164
158 // Returns the name of the device suitable for displaying, this may 165 // Returns the name of the device suitable for displaying, this may
159 // be a synthesied string containing the address and localized type name 166 // be a synthesied string containing the address and localized type name
160 // if the device has no obtained name. 167 // if the device has no obtained name.
161 virtual string16 GetName() const; 168 virtual string16 GetName() const;
162 169
163 // Returns the type of the device, limited to those we support or are 170 // Returns the type of the device, limited to those we support or are
164 // aware of, by decoding the bluetooth class information. The returned 171 // aware of, by decoding the bluetooth class information. The returned
165 // values are unique, and do not overlap, so DEVICE_KEYBOARD is not also 172 // values are unique, and do not overlap, so DEVICE_KEYBOARD is not also
166 // DEVICE_PERIPHERAL. 173 // DEVICE_PERIPHERAL.
167 DeviceType GetDeviceType() const; 174 DeviceType GetDeviceType() const;
168 175
169 // Indicates whether the device is paired to the adapter, whether or not 176 // Indicates whether the device is paired with the adapter.
170 // that pairing is permanent or temporary.
171 virtual bool IsPaired() const = 0; 177 virtual bool IsPaired() const = 0;
172 178
173 // Indicates whether the device is visible to the adapter, this is not 179 // Indicates whether the device is currently connected to the adapter.
174 // mutually exclusive to being paired. 180 virtual bool IsConnected() const = 0;
175 virtual bool IsVisible() const;
176 181
177 // Indicates whether the device is bonded to the adapter, bonding is 182 // Indicates whether the paired device accepts connections initiated from the
178 // formed by pairing and exchanging high-security link keys so that 183 // adapter. This value is undefined for unpaired devices.
179 // connections may be encrypted. 184 virtual bool IsConnectable() const = 0;
180 virtual bool IsBonded() const;
181
182 // Indicates whether the device is currently connected to the adapter
183 // and at least one service available for use.
184 virtual bool IsConnected() const;
185
186 // Indicates whether the bonded device accepts connections initiated from the
187 // adapter. This value is undefined for unbonded devices.
188 virtual bool IsConnectable() const;
189 185
190 // Indicates whether there is a call to Connect() ongoing. For this attribute, 186 // Indicates whether there is a call to Connect() ongoing. For this attribute,
191 // we consider a call is ongoing if none of the callbacks passed to Connect() 187 // we consider a call is ongoing if none of the callbacks passed to Connect()
192 // were called after the corresponding call to Connect(). 188 // were called after the corresponding call to Connect().
193 virtual bool IsConnecting() const; 189 virtual bool IsConnecting() const = 0;
194 190
195 // Returns the services (as UUID strings) that this device provides. 191 // Returns the services (as UUID strings) that this device provides.
196 typedef std::vector<std::string> ServiceList; 192 typedef std::vector<std::string> ServiceList;
197 virtual const ServiceList& GetServices() const = 0; 193 virtual ServiceList GetServices() const = 0;
youngki 2013/04/03 22:17:17 It's just my thinking, but do you think we should
keybuk 2013/04/03 22:18:56 If you think that would be better - I was kinda as
youngki 2013/04/04 12:59:08 actually this might not be worth passing a mutable
198 194
199 // The ErrorCallback is used for methods that can fail in which case it 195 // The ErrorCallback is used for methods that can fail in which case it
200 // is called, in the success case the callback is simply not called. 196 // is called, in the success case the callback is simply not called.
201 typedef base::Callback<void()> ErrorCallback; 197 typedef base::Callback<void()> ErrorCallback;
202 198
203 // The ConnectErrorCallback is used for methods that can fail with an error, 199 // The ConnectErrorCallback is used for methods that can fail with an error,
204 // passed back as an error code argument to this callback. 200 // passed back as an error code argument to this callback.
205 // In the success case this callback is not called. 201 // In the success case this callback is not called.
206 typedef base::Callback<void(enum ConnectErrorCode)> ConnectErrorCallback; 202 typedef base::Callback<void(enum ConnectErrorCode)> ConnectErrorCallback;
207 203
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 315
320 // Clears the Out Of Band pairing data for this device. Exactly one of 316 // Clears the Out Of Band pairing data for this device. Exactly one of
321 // |callback| or |error_callback| will be run. 317 // |callback| or |error_callback| will be run.
322 virtual void ClearOutOfBandPairingData( 318 virtual void ClearOutOfBandPairingData(
323 const base::Closure& callback, 319 const base::Closure& callback,
324 const ErrorCallback& error_callback) = 0; 320 const ErrorCallback& error_callback) = 0;
325 321
326 protected: 322 protected:
327 BluetoothDevice(); 323 BluetoothDevice();
328 324
329 // The Bluetooth class of the device, a bitmask that may be decoded using
330 // https://www.bluetooth.org/Technical/AssignedNumbers/baseband.htm
331 uint32 bluetooth_class_;
332
333 // The name of the device, as supplied by the remote device.
334 std::string name_;
335
336 // The Bluetooth address of the device.
337 std::string address_;
338
339 // Tracked device state, updated by the adapter managing the lifecyle of
340 // the device.
341 bool visible_;
342 bool bonded_;
343 bool connected_;
344
345 // Indicates whether the device normally accepts connections initiated from
346 // the adapter once paired.
347 bool connectable_;
348
349 // Indicated whether the device is in a connecting status.
350 bool connecting_;
351
352 // The services (identified by UUIDs) that this device provides.
353 ServiceList service_uuids_;
354
355 private: 325 private:
356 // Returns a localized string containing the device's bluetooth address and 326 // Returns a localized string containing the device's bluetooth address and
357 // a device type for display when |name_| is empty. 327 // a device type for display when |name_| is empty.
358 string16 GetAddressWithLocalizedDeviceTypeName() const; 328 string16 GetAddressWithLocalizedDeviceTypeName() const;
359 }; 329 };
360 330
361 } // namespace device 331 } // namespace device
362 332
363 #endif // DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_H_ 333 #endif // DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_H_
OLDNEW
« no previous file with comments | « device/bluetooth/bluetooth_adapter_win.cc ('k') | device/bluetooth/bluetooth_device.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698