| OLD | NEW |
| 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 <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| 11 #include <set> | 11 #include <set> |
| 12 #include <string> | 12 #include <string> |
| 13 #include <vector> | 13 #include <vector> |
| 14 | 14 |
| 15 #include "base/callback.h" | 15 #include "base/callback.h" |
| 16 #include "base/containers/scoped_ptr_hash_map.h" | 16 #include "base/containers/scoped_ptr_hash_map.h" |
| 17 #include "base/gtest_prod_util.h" | 17 #include "base/gtest_prod_util.h" |
| 18 #include "base/memory/ref_counted.h" | 18 #include "base/memory/ref_counted.h" |
| 19 #include "base/strings/string16.h" | 19 #include "base/strings/string16.h" |
| 20 #include "base/time/time.h" |
| 20 #include "device/bluetooth/bluetooth_export.h" | 21 #include "device/bluetooth/bluetooth_export.h" |
| 21 #include "device/bluetooth/bluetooth_uuid.h" | 22 #include "device/bluetooth/bluetooth_uuid.h" |
| 22 #include "net/log/net_log.h" | 23 #include "net/log/net_log.h" |
| 23 | 24 |
| 24 namespace base { | 25 namespace base { |
| 25 class BinaryValue; | 26 class BinaryValue; |
| 26 } | 27 } |
| 27 | 28 |
| 28 namespace device { | 29 namespace device { |
| 29 | 30 |
| (...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 460 virtual base::BinaryValue* GetServiceData(BluetoothUUID serviceUUID) const; | 461 virtual base::BinaryValue* GetServiceData(BluetoothUUID serviceUUID) const; |
| 461 | 462 |
| 462 // Returns the list UUIDs of services that have service data. | 463 // Returns the list UUIDs of services that have service data. |
| 463 virtual UUIDList GetServiceDataUUIDs() const; | 464 virtual UUIDList GetServiceDataUUIDs() const; |
| 464 | 465 |
| 465 // Returns the |address| in the canonical format: XX:XX:XX:XX:XX:XX, where | 466 // Returns the |address| in the canonical format: XX:XX:XX:XX:XX:XX, where |
| 466 // each 'X' is a hex digit. If the input |address| is invalid, returns an | 467 // each 'X' is a hex digit. If the input |address| is invalid, returns an |
| 467 // empty string. | 468 // empty string. |
| 468 static std::string CanonicalizeAddress(const std::string& address); | 469 static std::string CanonicalizeAddress(const std::string& address); |
| 469 | 470 |
| 471 // Return the timestamp for when this device was last seen. |
| 472 base::Time GetLastUpdateTime() const { return last_update_time_; } |
| 473 |
| 474 // Update the last time this device was seen. |
| 475 void UpdateTimestamp(); |
| 476 |
| 470 // Return associated BluetoothAdapter. | 477 // Return associated BluetoothAdapter. |
| 471 BluetoothAdapter* GetAdapter() { return adapter_; } | 478 BluetoothAdapter* GetAdapter() { return adapter_; } |
| 472 | 479 |
| 473 protected: | 480 protected: |
| 474 // BluetoothGattConnection is a friend to call Add/RemoveGattConnection. | 481 // BluetoothGattConnection is a friend to call Add/RemoveGattConnection. |
| 475 friend BluetoothGattConnection; | 482 friend BluetoothGattConnection; |
| 476 FRIEND_TEST_ALL_PREFIXES( | 483 FRIEND_TEST_ALL_PREFIXES( |
| 477 BluetoothTest, | 484 BluetoothTest, |
| 478 BluetoothGattConnection_DisconnectGatt_SimulateConnect); | 485 BluetoothGattConnection_DisconnectGatt_SimulateConnect); |
| 479 FRIEND_TEST_ALL_PREFIXES( | 486 FRIEND_TEST_ALL_PREFIXES( |
| 480 BluetoothTest, | 487 BluetoothTest, |
| 481 BluetoothGattConnection_DisconnectGatt_SimulateDisconnect); | 488 BluetoothGattConnection_DisconnectGatt_SimulateDisconnect); |
| 482 FRIEND_TEST_ALL_PREFIXES(BluetoothTest, | 489 FRIEND_TEST_ALL_PREFIXES(BluetoothTest, |
| 483 BluetoothGattConnection_ErrorAfterConnection); | 490 BluetoothGattConnection_ErrorAfterConnection); |
| 484 FRIEND_TEST_ALL_PREFIXES(BluetoothTest, | 491 FRIEND_TEST_ALL_PREFIXES(BluetoothTest, |
| 485 BluetoothGattConnection_DisconnectGatt_Cleanup); | 492 BluetoothGattConnection_DisconnectGatt_Cleanup); |
| 493 FRIEND_TEST_ALL_PREFIXES(BluetoothTest, RemoveOutdatedDevices); |
| 486 | 494 |
| 487 BluetoothDevice(BluetoothAdapter* adapter); | 495 BluetoothDevice(BluetoothAdapter* adapter); |
| 488 | 496 |
| 489 // Returns the internal name of the Bluetooth device, used by GetName(). | 497 // Returns the internal name of the Bluetooth device, used by GetName(). |
| 490 virtual std::string GetDeviceName() const = 0; | 498 virtual std::string GetDeviceName() const = 0; |
| 491 | 499 |
| 492 // Implements platform specific operations to initiate a GATT connection. | 500 // Implements platform specific operations to initiate a GATT connection. |
| 493 // Subclasses must also call DidConnectGatt, DidFailToConnectGatt, or | 501 // Subclasses must also call DidConnectGatt, DidFailToConnectGatt, or |
| 494 // DidDisconnectGatt immediately or asynchronously as the connection state | 502 // DidDisconnectGatt immediately or asynchronously as the connection state |
| 495 // changes. | 503 // changes. |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 540 typedef base::ScopedPtrHashMap<std::string, scoped_ptr<BluetoothGattService>> | 548 typedef base::ScopedPtrHashMap<std::string, scoped_ptr<BluetoothGattService>> |
| 541 GattServiceMap; | 549 GattServiceMap; |
| 542 GattServiceMap gatt_services_; | 550 GattServiceMap gatt_services_; |
| 543 bool gatt_services_discovery_complete_; | 551 bool gatt_services_discovery_complete_; |
| 544 | 552 |
| 545 // Mapping from service UUID represented as a std::string of a bluetooth | 553 // Mapping from service UUID represented as a std::string of a bluetooth |
| 546 // service to | 554 // service to |
| 547 // the specific data. The data is stored as BinaryValue. | 555 // the specific data. The data is stored as BinaryValue. |
| 548 scoped_ptr<base::DictionaryValue> services_data_; | 556 scoped_ptr<base::DictionaryValue> services_data_; |
| 549 | 557 |
| 558 // Timestamp for when an advertisement was last seen. |
| 559 base::Time last_update_time_; |
| 560 |
| 550 private: | 561 private: |
| 551 // Returns a localized string containing the device's bluetooth address and | 562 // Returns a localized string containing the device's bluetooth address and |
| 552 // a device type for display when |name_| is empty. | 563 // a device type for display when |name_| is empty. |
| 553 base::string16 GetAddressWithLocalizedDeviceTypeName() const; | 564 base::string16 GetAddressWithLocalizedDeviceTypeName() const; |
| 554 }; | 565 }; |
| 555 | 566 |
| 556 } // namespace device | 567 } // namespace device |
| 557 | 568 |
| 558 #endif // DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_H_ | 569 #endif // DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_H_ |
| OLD | NEW |