Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chromeos / dbus / fake_bluetooth_gatt_characteristic_service_provider.cc
blob5a548debf02fb73a86314ace9f86bd0b86275240
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.
5 #include "chromeos/dbus/fake_bluetooth_gatt_characteristic_service_provider.h"
7 #include "base/logging.h"
8 #include "base/strings/string_util.h"
9 #include "chromeos/dbus/dbus_thread_manager.h"
10 #include "chromeos/dbus/fake_bluetooth_gatt_manager_client.h"
12 namespace chromeos {
14 FakeBluetoothGattCharacteristicServiceProvider::
15 FakeBluetoothGattCharacteristicServiceProvider(
16 const dbus::ObjectPath& object_path,
17 Delegate* delegate,
18 const std::string& uuid,
19 const std::vector<std::string>& flags,
20 const std::vector<std::string>& permissions,
21 const dbus::ObjectPath& service_path)
22 : object_path_(object_path),
23 uuid_(uuid),
24 service_path_(service_path),
25 delegate_(delegate) {
26 VLOG(1) << "Creating Bluetooth GATT characteristic: " << object_path_.value();
28 DCHECK(object_path_.IsValid());
29 DCHECK(service_path_.IsValid());
30 DCHECK(!uuid.empty());
31 DCHECK(delegate_);
32 DCHECK(base::StartsWith(object_path_.value(),
33 service_path_.value() + "/",
34 base::CompareCase::SENSITIVE));
36 // TODO(armansito): Do something with |flags| and |permissions|.
38 FakeBluetoothGattManagerClient* fake_bluetooth_gatt_manager_client =
39 static_cast<FakeBluetoothGattManagerClient*>(
40 DBusThreadManager::Get()->GetBluetoothGattManagerClient());
41 fake_bluetooth_gatt_manager_client->
42 RegisterCharacteristicServiceProvider(this);
45 FakeBluetoothGattCharacteristicServiceProvider::
46 ~FakeBluetoothGattCharacteristicServiceProvider() {
47 VLOG(1) << "Cleaning up Bluetooth GATT characteristic: "
48 << object_path_.value();
50 FakeBluetoothGattManagerClient* fake_bluetooth_gatt_manager_client =
51 static_cast<FakeBluetoothGattManagerClient*>(
52 DBusThreadManager::Get()->GetBluetoothGattManagerClient());
53 fake_bluetooth_gatt_manager_client->
54 UnregisterCharacteristicServiceProvider(this);
57 void FakeBluetoothGattCharacteristicServiceProvider::SendValueChanged(
58 const std::vector<uint8>& value) {
59 VLOG(1) << "Sent characteristic value changed: " << object_path_.value()
60 << " UUID: " << uuid_;
63 void FakeBluetoothGattCharacteristicServiceProvider::GetValue(
64 const Delegate::ValueCallback& callback,
65 const Delegate::ErrorCallback& error_callback) {
66 VLOG(1) << "GATT characteristic value Get request: " << object_path_.value()
67 << " UUID: " << uuid_;
69 // Check if this characteristic is registered.
70 FakeBluetoothGattManagerClient* fake_bluetooth_gatt_manager_client =
71 static_cast<FakeBluetoothGattManagerClient*>(
72 DBusThreadManager::Get()->GetBluetoothGattManagerClient());
73 if (!fake_bluetooth_gatt_manager_client->IsServiceRegistered(service_path_)) {
74 VLOG(1) << "GATT characteristic not registered.";
75 error_callback.Run();
76 return;
79 // Pass on to the delegate.
80 DCHECK(delegate_);
81 delegate_->GetCharacteristicValue(callback, error_callback);
84 void FakeBluetoothGattCharacteristicServiceProvider::SetValue(
85 const std::vector<uint8>& value,
86 const base::Closure& callback,
87 const Delegate::ErrorCallback& error_callback) {
88 VLOG(1) << "GATT characteristic value Set request: " << object_path_.value()
89 << " UUID: " << uuid_;
91 // Check if this characteristic is registered.
92 FakeBluetoothGattManagerClient* fake_bluetooth_gatt_manager_client =
93 static_cast<FakeBluetoothGattManagerClient*>(
94 DBusThreadManager::Get()->GetBluetoothGattManagerClient());
95 if (!fake_bluetooth_gatt_manager_client->IsServiceRegistered(service_path_)) {
96 VLOG(1) << "GATT characteristic not registered.";
97 error_callback.Run();
98 return;
101 // Pass on to the delegate.
102 DCHECK(delegate_);
103 delegate_->SetCharacteristicValue(value, callback, error_callback);
106 } // namespace chromeos