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

Unified Diff: device/bluetooth/dbus/fake_bluetooth_device_client.cc

Issue 2102093003: Implement BluetoothDeviceBlueZ::GetServiceRecords. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: device/bluetooth/dbus/fake_bluetooth_device_client.cc
diff --git a/device/bluetooth/dbus/fake_bluetooth_device_client.cc b/device/bluetooth/dbus/fake_bluetooth_device_client.cc
index 8df4c7521cb1a46c9dcf78bf9efe635b8a7c6d3c..2c0b93b914e862b408ce4d7f2465fc5db8ba44d8 100644
--- a/device/bluetooth/dbus/fake_bluetooth_device_client.cc
+++ b/device/bluetooth/dbus/fake_bluetooth_device_client.cc
@@ -15,8 +15,11 @@
#include <string>
#include <utility>
+#include "base/bind_helpers.h"
#include "base/location.h"
#include "base/logging.h"
+#include "base/memory/ptr_util.h"
+#include "base/memory/ref_counted.h"
#include "base/rand_util.h"
#include "base/single_thread_task_runner.h"
#include "base/stl_util.h"
@@ -24,6 +27,7 @@
#include "base/threading/worker_pool.h"
#include "base/time/time.h"
#include "dbus/file_descriptor.h"
+#include "device/bluetooth/bluez/bluetooth_service_attribute_value_bluez.h"
#include "device/bluetooth/dbus/bluez_dbus_manager.h"
#include "device/bluetooth/dbus/fake_bluetooth_adapter_client.h"
#include "device/bluetooth/dbus/fake_bluetooth_agent_manager_client.h"
@@ -34,6 +38,8 @@
#include "device/bluetooth/dbus/fake_bluetooth_profile_service_provider.h"
#include "third_party/cros_system_api/dbus/service_constants.h"
+namespace bluez {
+
namespace {
// Default interval between simulated events.
@@ -93,9 +99,39 @@ void SimpleErrorCallback(const std::string& error_name,
VLOG(1) << "Bluetooth Error: " << error_name << ": " << error_message;
}
-} // namespace
+BluetoothDeviceClient::ServiceRecordList CreateFakeServiceRecords() {
+ BluetoothDeviceClient::ServiceRecordList records;
+
+ std::unique_ptr<BluetoothServiceRecordBlueZ> record1 =
+ base::MakeUnique<BluetoothServiceRecordBlueZ>();
+ // ID 0 = handle.
+ record1->AddRecordEntry(0x0, BluetoothServiceAttributeValueBlueZ(
+ BluetoothServiceAttributeValueBlueZ::UINT, 4,
+ base::MakeUnique<base::FundamentalValue>(
+ static_cast<int32_t>(0x1337))));
+ // ID 1 = service class id list.
+ std::unique_ptr<BluetoothServiceAttributeValueBlueZ::Sequence> class_id_list =
+ base::MakeUnique<BluetoothServiceAttributeValueBlueZ::Sequence>();
+ class_id_list->emplace_back(BluetoothServiceAttributeValueBlueZ(
Miao 2016/06/30 04:55:59 emplace_back(...) allows in-place construction of
rkc 2016/06/30 20:02:24 Done.
+ BluetoothServiceAttributeValueBlueZ::UUID, 4,
+ base::MakeUnique<base::StringValue>("1802")));
+ record1->AddRecordEntry(
+ 0x1, BluetoothServiceAttributeValueBlueZ(std::move(class_id_list)));
+ records.emplace_back(*record1);
+
+ std::unique_ptr<BluetoothServiceRecordBlueZ> record2 =
+ base::MakeUnique<BluetoothServiceRecordBlueZ>();
+ // ID 0 = handle.
+ record2->AddRecordEntry(0x0, BluetoothServiceAttributeValueBlueZ(
+ BluetoothServiceAttributeValueBlueZ::UINT, 4,
+ base::MakeUnique<base::FundamentalValue>(
+ static_cast<int32_t>(0xffffffff))));
+ records.emplace_back(*record2);
+
+ return records;
+}
-namespace bluez {
+} // namespace
const char FakeBluetoothDeviceClient::kTestPinCode[] = "123456";
const int FakeBluetoothDeviceClient::kTestPassKey = 123456;
@@ -413,7 +449,7 @@ void FakeBluetoothDeviceClient::Disconnect(
Properties* properties = GetProperties(object_path);
if (!properties->connected.value()) {
- error_callback.Run("org.bluez.Error.NotConnected", "Not Connected");
+ error_callback.Run(bluetooth_device::kErrorNotConnected, "Not Connected");
return;
}
@@ -545,13 +581,25 @@ void FakeBluetoothDeviceClient::GetConnInfo(
const ErrorCallback& error_callback) {
Properties* properties = GetProperties(object_path);
if (!properties->connected.value()) {
- error_callback.Run("org.bluez.Error.NotConnected", "Not Connected");
+ error_callback.Run(bluetooth_device::kErrorNotConnected, "Not Connected");
return;
}
callback.Run(connection_rssi_, transmit_power_, max_transmit_power_);
}
+void FakeBluetoothDeviceClient::GetServiceRecords(
+ const dbus::ObjectPath& object_path,
+ const ServiceRecordsCallback& callback,
+ const ErrorCallback& error_callback) {
+ Properties* properties = GetProperties(object_path);
+ if (!properties->connected.value()) {
+ error_callback.Run(bluetooth_device::kErrorNotConnected, "Not Connected");
+ return;
+ }
+ callback.Run(CreateFakeServiceRecords());
+}
+
void FakeBluetoothDeviceClient::BeginDiscoverySimulation(
const dbus::ObjectPath& adapter_path) {
VLOG(1) << "starting discovery simulation";

Powered by Google App Engine
This is Rietveld 408576698