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"
14 FakeBluetoothGattCharacteristicServiceProvider::
15 FakeBluetoothGattCharacteristicServiceProvider(
16 const dbus::ObjectPath
& object_path
,
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
),
24 service_path_(service_path
),
26 VLOG(1) << "Creating Bluetooth GATT characteristic: " << object_path_
.value();
28 DCHECK(object_path_
.IsValid());
29 DCHECK(service_path_
.IsValid());
30 DCHECK(!uuid
.empty());
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.";
79 // Pass on to the 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.";
101 // Pass on to the delegate.
103 delegate_
->SetCharacteristicValue(value
, callback
, error_callback
);
106 } // namespace chromeos