This source file includes following definitions.
- Init
- RegisterService
- UnregisterService
- RegisterServiceServiceProvider
- RegisterCharacteristicServiceProvider
- RegisterDescriptorServiceProvider
- UnregisterServiceServiceProvider
- UnregisterCharacteristicServiceProvider
- UnregisterDescriptorServiceProvider
- GetServiceServiceProvider
- GetCharacteristicServiceProvider
- GetDescriptorServiceProvider
- IsServiceRegistered
#include "chromeos/dbus/fake_bluetooth_gatt_manager_client.h"
#include "base/logging.h"
#include "chromeos/dbus/fake_bluetooth_gatt_characteristic_service_provider.h"
#include "chromeos/dbus/fake_bluetooth_gatt_descriptor_service_provider.h"
#include "chromeos/dbus/fake_bluetooth_gatt_service_service_provider.h"
#include "third_party/cros_system_api/dbus/service_constants.h"
namespace chromeos {
FakeBluetoothGattManagerClient::FakeBluetoothGattManagerClient() {
}
FakeBluetoothGattManagerClient::~FakeBluetoothGattManagerClient() {
}
void FakeBluetoothGattManagerClient::Init(dbus::Bus* bus) {
}
void FakeBluetoothGattManagerClient::RegisterService(
const dbus::ObjectPath& service_path,
const Options& options,
const base::Closure& callback,
const ErrorCallback& error_callback) {
VLOG(1) << "Register GATT service: " << service_path.value();
ServiceMap::iterator iter = service_map_.find(service_path);
if (iter == service_map_.end()) {
error_callback.Run(bluetooth_gatt_manager::kErrorInvalidArguments,
"GATT service doesn't exist: " + service_path.value());
return;
}
ServiceProvider* provider = &iter->second;
if (provider->first) {
error_callback.Run(
bluetooth_gatt_manager::kErrorAlreadyExists,
"GATT service already registered: " + service_path.value());
return;
}
provider->first = true;
callback.Run();
}
void FakeBluetoothGattManagerClient::UnregisterService(
const dbus::ObjectPath& service_path,
const base::Closure& callback,
const ErrorCallback& error_callback) {
VLOG(1) << "Unregister GATT service: " << service_path.value();
ServiceMap::iterator iter = service_map_.find(service_path);
if (iter == service_map_.end()) {
error_callback.Run(bluetooth_gatt_manager::kErrorInvalidArguments,
"GATT service doesn't exist: " + service_path.value());
return;
}
ServiceProvider* provider = &iter->second;
if (!provider->first) {
error_callback.Run(
bluetooth_gatt_manager::kErrorDoesNotExist,
"GATT service not registered: " + service_path.value());
return;
}
provider->first = false;
callback.Run();
}
void FakeBluetoothGattManagerClient::RegisterServiceServiceProvider(
FakeBluetoothGattServiceServiceProvider* provider) {
ServiceMap::iterator iter = service_map_.find(provider->object_path());
if (iter != service_map_.end()) {
VLOG(1) << "GATT service service provider already registered for "
<< "object path: " << provider->object_path().value();
return;
}
service_map_[provider->object_path()] = std::make_pair(false, provider);
}
void FakeBluetoothGattManagerClient::RegisterCharacteristicServiceProvider(
FakeBluetoothGattCharacteristicServiceProvider* provider) {
CharacteristicMap::iterator iter =
characteristic_map_.find(provider->object_path());
if (iter != characteristic_map_.end()) {
VLOG(1) << "GATT characteristic service provider already registered for "
<< "object path: " << provider->object_path().value();
return;
}
characteristic_map_[provider->object_path()] = provider;
}
void FakeBluetoothGattManagerClient::RegisterDescriptorServiceProvider(
FakeBluetoothGattDescriptorServiceProvider* provider) {
DescriptorMap::iterator iter =
descriptor_map_.find(provider->object_path());
if (iter != descriptor_map_.end()) {
VLOG(1) << "GATT descriptor service provider already registered for "
<< "object path: " << provider->object_path().value();
return;
}
descriptor_map_[provider->object_path()] = provider;
}
void FakeBluetoothGattManagerClient::UnregisterServiceServiceProvider(
FakeBluetoothGattServiceServiceProvider* provider) {
ServiceMap::iterator iter =
service_map_.find(provider->object_path());
if (iter != service_map_.end() && iter->second.second == provider)
service_map_.erase(iter);
}
void FakeBluetoothGattManagerClient::UnregisterCharacteristicServiceProvider(
FakeBluetoothGattCharacteristicServiceProvider* provider) {
characteristic_map_.erase(provider->object_path());
}
void FakeBluetoothGattManagerClient::UnregisterDescriptorServiceProvider(
FakeBluetoothGattDescriptorServiceProvider* provider) {
descriptor_map_.erase(provider->object_path());
}
FakeBluetoothGattServiceServiceProvider*
FakeBluetoothGattManagerClient::GetServiceServiceProvider(
const dbus::ObjectPath& object_path) const {
ServiceMap::const_iterator iter = service_map_.find(object_path);
if (iter == service_map_.end())
return NULL;
return iter->second.second;
}
FakeBluetoothGattCharacteristicServiceProvider*
FakeBluetoothGattManagerClient::GetCharacteristicServiceProvider(
const dbus::ObjectPath& object_path) const {
CharacteristicMap::const_iterator iter =
characteristic_map_.find(object_path);
if (iter == characteristic_map_.end())
return NULL;
return iter->second;
}
FakeBluetoothGattDescriptorServiceProvider*
FakeBluetoothGattManagerClient::GetDescriptorServiceProvider(
const dbus::ObjectPath& object_path) const {
DescriptorMap::const_iterator iter = descriptor_map_.find(object_path);
if (iter == descriptor_map_.end())
return NULL;
return iter->second;
}
bool FakeBluetoothGattManagerClient::IsServiceRegistered(
const dbus::ObjectPath& object_path) const {
ServiceMap::const_iterator iter = service_map_.find(object_path);
if (iter == service_map_.end())
return false;
return iter->second.first;
}
}