| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 #include "chromeos/dbus/fake_bluetooth_gatt_manager_client.h" | 5 #include "device/bluetooth/dbus/fake_bluetooth_gatt_manager_client.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "chromeos/dbus/fake_bluetooth_gatt_characteristic_service_provider.h" | 8 #include "device/bluetooth/dbus/fake_bluetooth_gatt_characteristic_service_provi
der.h" |
| 9 #include "chromeos/dbus/fake_bluetooth_gatt_descriptor_service_provider.h" | 9 #include "device/bluetooth/dbus/fake_bluetooth_gatt_descriptor_service_provider.
h" |
| 10 #include "chromeos/dbus/fake_bluetooth_gatt_service_service_provider.h" | 10 #include "device/bluetooth/dbus/fake_bluetooth_gatt_service_service_provider.h" |
| 11 #include "third_party/cros_system_api/dbus/service_constants.h" | 11 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 12 | 12 |
| 13 namespace chromeos { | 13 namespace bluez { |
| 14 | 14 |
| 15 FakeBluetoothGattManagerClient::FakeBluetoothGattManagerClient() { | 15 FakeBluetoothGattManagerClient::FakeBluetoothGattManagerClient() {} |
| 16 } | |
| 17 | 16 |
| 18 FakeBluetoothGattManagerClient::~FakeBluetoothGattManagerClient() { | 17 FakeBluetoothGattManagerClient::~FakeBluetoothGattManagerClient() {} |
| 19 } | |
| 20 | 18 |
| 21 // DBusClient override. | 19 // DBusClient override. |
| 22 void FakeBluetoothGattManagerClient::Init(dbus::Bus* bus) { | 20 void FakeBluetoothGattManagerClient::Init(dbus::Bus* bus) {} |
| 23 } | |
| 24 | 21 |
| 25 // BluetoothGattManagerClient overrides. | 22 // BluetoothGattManagerClient overrides. |
| 26 void FakeBluetoothGattManagerClient::RegisterService( | 23 void FakeBluetoothGattManagerClient::RegisterService( |
| 27 const dbus::ObjectPath& service_path, | 24 const dbus::ObjectPath& service_path, |
| 28 const Options& options, | 25 const Options& options, |
| 29 const base::Closure& callback, | 26 const base::Closure& callback, |
| 30 const ErrorCallback& error_callback) { | 27 const ErrorCallback& error_callback) { |
| 31 VLOG(1) << "Register GATT service: " << service_path.value(); | 28 VLOG(1) << "Register GATT service: " << service_path.value(); |
| 32 | 29 |
| 33 // If a service provider wasn't created before, return error. | 30 // If a service provider wasn't created before, return error. |
| (...skipping 28 matching lines...) Expand all Loading... |
| 62 ServiceMap::iterator iter = service_map_.find(service_path); | 59 ServiceMap::iterator iter = service_map_.find(service_path); |
| 63 if (iter == service_map_.end()) { | 60 if (iter == service_map_.end()) { |
| 64 error_callback.Run(bluetooth_gatt_manager::kErrorInvalidArguments, | 61 error_callback.Run(bluetooth_gatt_manager::kErrorInvalidArguments, |
| 65 "GATT service doesn't exist: " + service_path.value()); | 62 "GATT service doesn't exist: " + service_path.value()); |
| 66 return; | 63 return; |
| 67 } | 64 } |
| 68 | 65 |
| 69 // Return error if the GATT service wasn't registered before. | 66 // Return error if the GATT service wasn't registered before. |
| 70 ServiceProvider* provider = &iter->second; | 67 ServiceProvider* provider = &iter->second; |
| 71 if (!provider->first) { | 68 if (!provider->first) { |
| 72 error_callback.Run( | 69 error_callback.Run(bluetooth_gatt_manager::kErrorDoesNotExist, |
| 73 bluetooth_gatt_manager::kErrorDoesNotExist, | 70 "GATT service not registered: " + service_path.value()); |
| 74 "GATT service not registered: " + service_path.value()); | |
| 75 return; | 71 return; |
| 76 } | 72 } |
| 77 | 73 |
| 78 // Success! | 74 // Success! |
| 79 provider->first = false; | 75 provider->first = false; |
| 80 callback.Run(); | 76 callback.Run(); |
| 81 } | 77 } |
| 82 | 78 |
| 83 void FakeBluetoothGattManagerClient::RegisterServiceServiceProvider( | 79 void FakeBluetoothGattManagerClient::RegisterServiceServiceProvider( |
| 84 FakeBluetoothGattServiceServiceProvider* provider) { | 80 FakeBluetoothGattServiceServiceProvider* provider) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 101 VLOG(1) << "GATT characteristic service provider already registered for " | 97 VLOG(1) << "GATT characteristic service provider already registered for " |
| 102 << "object path: " << provider->object_path().value(); | 98 << "object path: " << provider->object_path().value(); |
| 103 return; | 99 return; |
| 104 } | 100 } |
| 105 characteristic_map_[provider->object_path()] = provider; | 101 characteristic_map_[provider->object_path()] = provider; |
| 106 } | 102 } |
| 107 | 103 |
| 108 void FakeBluetoothGattManagerClient::RegisterDescriptorServiceProvider( | 104 void FakeBluetoothGattManagerClient::RegisterDescriptorServiceProvider( |
| 109 FakeBluetoothGattDescriptorServiceProvider* provider) { | 105 FakeBluetoothGattDescriptorServiceProvider* provider) { |
| 110 // Ignore, if a service provider is already registered for the object path. | 106 // Ignore, if a service provider is already registered for the object path. |
| 111 DescriptorMap::iterator iter = | 107 DescriptorMap::iterator iter = descriptor_map_.find(provider->object_path()); |
| 112 descriptor_map_.find(provider->object_path()); | |
| 113 if (iter != descriptor_map_.end()) { | 108 if (iter != descriptor_map_.end()) { |
| 114 VLOG(1) << "GATT descriptor service provider already registered for " | 109 VLOG(1) << "GATT descriptor service provider already registered for " |
| 115 << "object path: " << provider->object_path().value(); | 110 << "object path: " << provider->object_path().value(); |
| 116 return; | 111 return; |
| 117 } | 112 } |
| 118 descriptor_map_[provider->object_path()] = provider; | 113 descriptor_map_[provider->object_path()] = provider; |
| 119 } | 114 } |
| 120 | 115 |
| 121 void FakeBluetoothGattManagerClient::UnregisterServiceServiceProvider( | 116 void FakeBluetoothGattManagerClient::UnregisterServiceServiceProvider( |
| 122 FakeBluetoothGattServiceServiceProvider* provider) { | 117 FakeBluetoothGattServiceServiceProvider* provider) { |
| 123 ServiceMap::iterator iter = | 118 ServiceMap::iterator iter = service_map_.find(provider->object_path()); |
| 124 service_map_.find(provider->object_path()); | |
| 125 if (iter != service_map_.end() && iter->second.second == provider) | 119 if (iter != service_map_.end() && iter->second.second == provider) |
| 126 service_map_.erase(iter); | 120 service_map_.erase(iter); |
| 127 } | 121 } |
| 128 | 122 |
| 129 void FakeBluetoothGattManagerClient::UnregisterCharacteristicServiceProvider( | 123 void FakeBluetoothGattManagerClient::UnregisterCharacteristicServiceProvider( |
| 130 FakeBluetoothGattCharacteristicServiceProvider* provider) { | 124 FakeBluetoothGattCharacteristicServiceProvider* provider) { |
| 131 characteristic_map_.erase(provider->object_path()); | 125 characteristic_map_.erase(provider->object_path()); |
| 132 } | 126 } |
| 133 | 127 |
| 134 void FakeBluetoothGattManagerClient::UnregisterDescriptorServiceProvider( | 128 void FakeBluetoothGattManagerClient::UnregisterDescriptorServiceProvider( |
| 135 FakeBluetoothGattDescriptorServiceProvider* provider) { | 129 FakeBluetoothGattDescriptorServiceProvider* provider) { |
| 136 descriptor_map_.erase(provider->object_path()); | 130 descriptor_map_.erase(provider->object_path()); |
| 137 } | 131 } |
| 138 | 132 |
| 139 FakeBluetoothGattServiceServiceProvider* | 133 FakeBluetoothGattServiceServiceProvider* |
| 140 FakeBluetoothGattManagerClient::GetServiceServiceProvider( | 134 FakeBluetoothGattManagerClient::GetServiceServiceProvider( |
| 141 const dbus::ObjectPath& object_path) const { | 135 const dbus::ObjectPath& object_path) const { |
| 142 ServiceMap::const_iterator iter = service_map_.find(object_path); | 136 ServiceMap::const_iterator iter = service_map_.find(object_path); |
| 143 if (iter == service_map_.end()) | 137 if (iter == service_map_.end()) |
| 144 return NULL; | 138 return NULL; |
| 145 return iter->second.second; | 139 return iter->second.second; |
| 146 } | 140 } |
| 147 | 141 |
| 148 FakeBluetoothGattCharacteristicServiceProvider* | 142 FakeBluetoothGattCharacteristicServiceProvider* |
| 149 FakeBluetoothGattManagerClient::GetCharacteristicServiceProvider( | 143 FakeBluetoothGattManagerClient::GetCharacteristicServiceProvider( |
| 150 const dbus::ObjectPath& object_path) const { | 144 const dbus::ObjectPath& object_path) const { |
| 151 CharacteristicMap::const_iterator iter = | 145 CharacteristicMap::const_iterator iter = |
| 152 characteristic_map_.find(object_path); | 146 characteristic_map_.find(object_path); |
| 153 if (iter == characteristic_map_.end()) | 147 if (iter == characteristic_map_.end()) |
| 154 return NULL; | 148 return NULL; |
| 155 return iter->second; | 149 return iter->second; |
| 156 } | 150 } |
| 157 | 151 |
| 158 FakeBluetoothGattDescriptorServiceProvider* | 152 FakeBluetoothGattDescriptorServiceProvider* |
| 159 FakeBluetoothGattManagerClient::GetDescriptorServiceProvider( | 153 FakeBluetoothGattManagerClient::GetDescriptorServiceProvider( |
| 160 const dbus::ObjectPath& object_path) const { | 154 const dbus::ObjectPath& object_path) const { |
| 161 DescriptorMap::const_iterator iter = descriptor_map_.find(object_path); | 155 DescriptorMap::const_iterator iter = descriptor_map_.find(object_path); |
| 162 if (iter == descriptor_map_.end()) | 156 if (iter == descriptor_map_.end()) |
| 163 return NULL; | 157 return NULL; |
| 164 return iter->second; | 158 return iter->second; |
| 165 } | 159 } |
| 166 | 160 |
| 167 bool FakeBluetoothGattManagerClient::IsServiceRegistered( | 161 bool FakeBluetoothGattManagerClient::IsServiceRegistered( |
| 168 const dbus::ObjectPath& object_path) const { | 162 const dbus::ObjectPath& object_path) const { |
| 169 ServiceMap::const_iterator iter = service_map_.find(object_path); | 163 ServiceMap::const_iterator iter = service_map_.find(object_path); |
| 170 if (iter == service_map_.end()) | 164 if (iter == service_map_.end()) |
| 171 return false; | 165 return false; |
| 172 return iter->second.first; | 166 return iter->second.first; |
| 173 } | 167 } |
| 174 | 168 |
| 175 } // namespace chromeos | 169 } // namespace bluez |
| OLD | NEW |