Commit 3c011dd0 authored by rkc's avatar rkc Committed by Commit bot

Add DBus bindings for BLE Advertisement.

This CL adds the DBus bindings needed to be able to host BLE advertisment
objects and register those advertisements with BlueZ.

R=armansito@chromium.org, jamuraa@chromium.org
BUG=466375

Review URL: https://codereview.chromium.org/1052363005

Cr-Commit-Position: refs/heads/master@{#325497}
parent 04ab34e0
...@@ -61,6 +61,10 @@ ...@@ -61,6 +61,10 @@
'dbus/blocking_method_caller.h', 'dbus/blocking_method_caller.h',
'dbus/bluetooth_adapter_client.cc', 'dbus/bluetooth_adapter_client.cc',
'dbus/bluetooth_adapter_client.h', 'dbus/bluetooth_adapter_client.h',
'dbus/bluetooth_le_advertising_manager_client.cc',
'dbus/bluetooth_le_advertising_manager_client.h',
'dbus/bluetooth_le_advertisement_service_provider.cc',
'dbus/bluetooth_le_advertisement_service_provider.h',
'dbus/bluetooth_agent_manager_client.cc', 'dbus/bluetooth_agent_manager_client.cc',
'dbus/bluetooth_agent_manager_client.h', 'dbus/bluetooth_agent_manager_client.h',
'dbus/bluetooth_agent_service_provider.cc', 'dbus/bluetooth_agent_service_provider.cc',
...@@ -118,6 +122,10 @@ ...@@ -118,6 +122,10 @@
'dbus/fake_audio_dsp_client.h', 'dbus/fake_audio_dsp_client.h',
'dbus/fake_bluetooth_adapter_client.cc', 'dbus/fake_bluetooth_adapter_client.cc',
'dbus/fake_bluetooth_adapter_client.h', 'dbus/fake_bluetooth_adapter_client.h',
'dbus/fake_bluetooth_le_advertising_manager_client.cc',
'dbus/fake_bluetooth_le_advertising_manager_client.h',
'dbus/fake_bluetooth_le_advertisement_service_provider.cc',
'dbus/fake_bluetooth_le_advertisement_service_provider.h',
'dbus/fake_bluetooth_agent_manager_client.cc', 'dbus/fake_bluetooth_agent_manager_client.cc',
'dbus/fake_bluetooth_agent_manager_client.h', 'dbus/fake_bluetooth_agent_manager_client.h',
'dbus/fake_bluetooth_agent_service_provider.cc', 'dbus/fake_bluetooth_agent_service_provider.cc',
......
This diff is collapsed.
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROMEOS_DBUS_BLUETOOTH_LE_ADVERTISEMENT_SERVICE_PROVIDER_H_
#define CHROMEOS_DBUS_BLUETOOTH_LE_ADVERTISEMENT_SERVICE_PROVIDER_H_
#include <stdint.h>
#include <map>
#include <string>
#include <vector>
#include "base/basictypes.h"
#include "base/callback.h"
#include "base/memory/scoped_ptr.h"
#include "chromeos/chromeos_export.h"
#include "dbus/bus.h"
#include "dbus/file_descriptor.h"
#include "dbus/object_path.h"
namespace chromeos {
// BluetoothAdvertisementServiceProvider is used to provide a D-Bus object that
// the Bluetooth daemon can communicate with to advertise data.
class CHROMEOS_EXPORT BluetoothLEAdvertisementServiceProvider {
public:
using UUIDList = std::vector<std::string>;
using ManufacturerData = std::map<uint16_t, std::vector<uint8_t>>;
using ServiceData = std::map<std::string, std::vector<uint8_t>>;
// Type of advertisement.
enum AdvertisementType {
ADVERTISEMENT_TYPE_BROADCAST,
ADVERTISEMENT_TYPE_PERIPHERAL
};
// Interface for reacting to advertisement changes.
class Delegate {
public:
virtual ~Delegate() {}
// This method will be called when the advertisement is unregistered from
// the Bluetooth daemon, generally at shutdown or if the adapter goes away.
// It may be used to perform cleanup tasks. This corresponds to the
// org.bluez.LEAdvertisement1.Release method and is renamed to avoid a
// conflict with base::Refcounted<T>.
virtual void Released() = 0;
};
virtual ~BluetoothLEAdvertisementServiceProvider();
// Creates the instance where |bus| is the D-Bus bus connection to export
// the object onto, |object_path| is the object path that it should have
// and |delegate| is the object to which all method calls will be passed
// and responses generated from.
static BluetoothLEAdvertisementServiceProvider* Create(
dbus::Bus* bus,
const dbus::ObjectPath& object_path,
Delegate* delegate,
AdvertisementType type,
scoped_ptr<UUIDList> service_uuids,
scoped_ptr<ManufacturerData> manufacturer_data,
scoped_ptr<UUIDList> solicit_uuids,
scoped_ptr<ServiceData> service_data);
protected:
BluetoothLEAdvertisementServiceProvider();
private:
DISALLOW_COPY_AND_ASSIGN(BluetoothLEAdvertisementServiceProvider);
};
} // namespace chromeos
#endif // CHROMEOS_DBUS_BLUETOOTH_LE_ADVERTISEMENT_SERVICE_PROVIDER_H_
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chromeos/dbus/bluetooth_le_advertising_manager_client.h"
#include "base/bind.h"
#include "base/logging.h"
#include "base/observer_list.h"
#include "dbus/bus.h"
#include "dbus/message.h"
#include "dbus/object_manager.h"
#include "dbus/object_proxy.h"
#include "third_party/cros_system_api/dbus/service_constants.h"
namespace chromeos {
const char BluetoothLEAdvertisingManagerClient::kNoResponseError[] =
"org.chromium.Error.NoResponse";
// The BluetoothAdvertisementManagerClient implementation used in production.
class BluetoothAdvertisementManagerClientImpl
: public BluetoothLEAdvertisingManagerClient,
public dbus::ObjectManager::Interface {
public:
BluetoothAdvertisementManagerClientImpl()
: object_manager_(NULL), weak_ptr_factory_(this) {}
~BluetoothAdvertisementManagerClientImpl() override {
object_manager_->UnregisterInterface(
bluetooth_advertising_manager::kBluetoothAdvertisingManagerInterface);
}
// BluetoothAdapterClient override.
void AddObserver(
BluetoothLEAdvertisingManagerClient::Observer* observer) override {
DCHECK(observer);
observers_.AddObserver(observer);
}
// BluetoothAdapterClient override.
void RemoveObserver(
BluetoothLEAdvertisingManagerClient::Observer* observer) override {
DCHECK(observer);
observers_.RemoveObserver(observer);
}
// dbus::ObjectManager::Interface override.
dbus::PropertySet* CreateProperties(
dbus::ObjectProxy* object_proxy,
const dbus::ObjectPath& object_path,
const std::string& interface_name) override {
return new dbus::PropertySet(object_proxy, interface_name,
dbus::PropertySet::PropertyChangedCallback());
}
// BluetoothAdvertisementManagerClient override.
void RegisterAdvertisement(const dbus::ObjectPath& manager_object_path,
const dbus::ObjectPath& advertisement_object_path,
const base::Closure& callback,
const ErrorCallback& error_callback) override {
dbus::MethodCall method_call(
bluetooth_advertising_manager::kBluetoothAdvertisingManagerInterface,
bluetooth_advertising_manager::kRegisterAdvertisement);
dbus::MessageWriter writer(&method_call);
writer.AppendObjectPath(advertisement_object_path);
// Empty dictionary for options.
dbus::MessageWriter dict_entry_writer(NULL);
writer.OpenDictEntry(&dict_entry_writer);
writer.CloseContainer(&dict_entry_writer);
writer.AppendObjectPath(advertisement_object_path);
dbus::ObjectProxy* object_proxy =
object_manager_->GetObjectProxy(manager_object_path);
object_proxy->CallMethodWithErrorCallback(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::Bind(&BluetoothAdvertisementManagerClientImpl::OnSuccess,
weak_ptr_factory_.GetWeakPtr(), callback),
base::Bind(&BluetoothAdvertisementManagerClientImpl::OnError,
weak_ptr_factory_.GetWeakPtr(), error_callback));
}
// BluetoothAdvertisementManagerClient override.
void UnregisterAdvertisement(
const dbus::ObjectPath& manager_object_path,
const dbus::ObjectPath& advertisement_object_path,
const base::Closure& callback,
const ErrorCallback& error_callback) override {
dbus::MethodCall method_call(
bluetooth_advertising_manager::kBluetoothAdvertisingManagerInterface,
bluetooth_advertising_manager::kUnregisterAdvertisement);
dbus::MessageWriter writer(&method_call);
writer.AppendObjectPath(advertisement_object_path);
dbus::ObjectProxy* object_proxy =
object_manager_->GetObjectProxy(manager_object_path);
object_proxy->CallMethodWithErrorCallback(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::Bind(&BluetoothAdvertisementManagerClientImpl::OnSuccess,
weak_ptr_factory_.GetWeakPtr(), callback),
base::Bind(&BluetoothAdvertisementManagerClientImpl::OnError,
weak_ptr_factory_.GetWeakPtr(), error_callback));
}
protected:
void Init(dbus::Bus* bus) override {
DCHECK(bus);
object_manager_ = bus->GetObjectManager(
bluetooth_object_manager::kBluetoothObjectManagerServiceName,
dbus::ObjectPath(
bluetooth_object_manager::kBluetoothObjectManagerServicePath));
object_manager_->RegisterInterface(
bluetooth_advertising_manager::kBluetoothAdvertisingManagerInterface,
this);
}
private:
// Called by dbus::ObjectManager when an object with the advertising manager
// interface is created. Informs observers.
void ObjectAdded(const dbus::ObjectPath& object_path,
const std::string& interface_name) override {
FOR_EACH_OBSERVER(BluetoothLEAdvertisingManagerClient::Observer, observers_,
AdvertisingManagerAdded(object_path));
}
// Called by dbus::ObjectManager when an object with the advertising manager
// interface is removed. Informs observers.
void ObjectRemoved(const dbus::ObjectPath& object_path,
const std::string& interface_name) override {
FOR_EACH_OBSERVER(BluetoothLEAdvertisingManagerClient::Observer, observers_,
AdvertisingManagerRemoved(object_path));
}
// Called when a response for successful method call is received.
void OnSuccess(const base::Closure& callback, dbus::Response* response) {
DCHECK(response);
callback.Run();
}
// Called when a response for a failed method call is received.
void OnError(const ErrorCallback& error_callback,
dbus::ErrorResponse* response) {
// Error response has optional error message argument.
std::string error_name;
std::string error_message;
if (response) {
dbus::MessageReader reader(response);
error_name = response->GetErrorName();
reader.PopString(&error_message);
} else {
error_name = kNoResponseError;
error_message = "";
}
error_callback.Run(error_name, error_message);
}
dbus::ObjectManager* object_manager_;
// List of observers interested in event notifications from us.
ObserverList<BluetoothLEAdvertisingManagerClient::Observer> observers_;
// Weak pointer factory for generating 'this' pointers that might live longer
// than we do.
// Note: This should remain the last member so it'll be destroyed and
// invalidate its weak pointers before any other members are destroyed.
base::WeakPtrFactory<BluetoothAdvertisementManagerClientImpl>
weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(BluetoothAdvertisementManagerClientImpl);
};
BluetoothLEAdvertisingManagerClient::BluetoothLEAdvertisingManagerClient() {
}
BluetoothLEAdvertisingManagerClient::~BluetoothLEAdvertisingManagerClient() {
}
BluetoothLEAdvertisingManagerClient*
BluetoothLEAdvertisingManagerClient::Create() {
return new BluetoothAdvertisementManagerClientImpl();
}
} // namespace chromeos
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROMEOS_DBUS_BLUETOOTH_LE_ADVERTISING_MANAGER_CLIENT_H_
#define CHROMEOS_DBUS_BLUETOOTH_LE_ADVERTISING_MANAGER_CLIENT_H_
#include <string>
#include <vector>
#include "base/callback.h"
#include "base/memory/scoped_ptr.h"
#include "base/values.h"
#include "chromeos/chromeos_export.h"
#include "chromeos/dbus/dbus_client.h"
#include "dbus/object_path.h"
namespace chromeos {
// BluetoothAdvertisingManagerClient is used to communicate with the advertising
// manager object of the BlueZ daemon.
class CHROMEOS_EXPORT BluetoothLEAdvertisingManagerClient : public DBusClient {
public:
// Interface for observing changes to advertising managers.
class Observer {
public:
virtual ~Observer() {}
// Called when an advertising manager with object path |object_path| is
// added to the system.
virtual void AdvertisingManagerAdded(const dbus::ObjectPath& object_path) {}
// Called when an advertising manager with object path |object_path| is
// removed from the system.
virtual void AdvertisingManagerRemoved(
const dbus::ObjectPath& object_path) {}
};
~BluetoothLEAdvertisingManagerClient() override;
// Adds and removes observers for events which change the advertising
// managers on the system.
virtual void AddObserver(Observer* observer) = 0;
virtual void RemoveObserver(Observer* observer) = 0;
// The ErrorCallback is used by advertising manager methods to indicate
// failure. It receives two arguments: the name of the error in |error_name|
// and an optional message in |error_message|.
using ErrorCallback = base::Callback<void(const std::string& error_name,
const std::string& error_message)>;
// Registers an advertisement with the DBus object path
// |advertisement_object_path| with BlueZ's advertising manager.
virtual void RegisterAdvertisement(
const dbus::ObjectPath& manager_object_path,
const dbus::ObjectPath& advertisement_object_path,
const base::Closure& callback,
const ErrorCallback& error_callback) = 0;
// Unregisters an advertisement with the DBus object path
// |advertisement_object_path| with BlueZ's advertising manager.
virtual void UnregisterAdvertisement(
const dbus::ObjectPath& manager_object_path,
const dbus::ObjectPath& advertisement_object_path,
const base::Closure& callback,
const ErrorCallback& error_callback) = 0;
// Creates the instance.
static BluetoothLEAdvertisingManagerClient* Create();
// Constants used to indicate exceptional error conditions.
static const char kNoResponseError[];
protected:
BluetoothLEAdvertisingManagerClient();
private:
DISALLOW_COPY_AND_ASSIGN(BluetoothLEAdvertisingManagerClient);
};
} // namespace chromeos
#endif // CHROMEOS_DBUS_BLUETOOTH_LE_ADVERTISING_MANAGER_CLIENT_H_
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "chromeos/dbus/bluetooth_gatt_manager_client.h" #include "chromeos/dbus/bluetooth_gatt_manager_client.h"
#include "chromeos/dbus/bluetooth_gatt_service_client.h" #include "chromeos/dbus/bluetooth_gatt_service_client.h"
#include "chromeos/dbus/bluetooth_input_client.h" #include "chromeos/dbus/bluetooth_input_client.h"
#include "chromeos/dbus/bluetooth_le_advertising_manager_client.h"
#include "chromeos/dbus/bluetooth_media_client.h" #include "chromeos/dbus/bluetooth_media_client.h"
#include "chromeos/dbus/bluetooth_media_transport_client.h" #include "chromeos/dbus/bluetooth_media_transport_client.h"
#include "chromeos/dbus/bluetooth_profile_manager_client.h" #include "chromeos/dbus/bluetooth_profile_manager_client.h"
...@@ -40,6 +41,7 @@ ...@@ -40,6 +41,7 @@
#include "chromeos/dbus/fake_bluetooth_gatt_manager_client.h" #include "chromeos/dbus/fake_bluetooth_gatt_manager_client.h"
#include "chromeos/dbus/fake_bluetooth_gatt_service_client.h" #include "chromeos/dbus/fake_bluetooth_gatt_service_client.h"
#include "chromeos/dbus/fake_bluetooth_input_client.h" #include "chromeos/dbus/fake_bluetooth_input_client.h"
#include "chromeos/dbus/fake_bluetooth_le_advertising_manager_client.h"
#include "chromeos/dbus/fake_bluetooth_media_client.h" #include "chromeos/dbus/fake_bluetooth_media_client.h"
#include "chromeos/dbus/fake_bluetooth_media_transport_client.h" #include "chromeos/dbus/fake_bluetooth_media_transport_client.h"
#include "chromeos/dbus/fake_bluetooth_profile_manager_client.h" #include "chromeos/dbus/fake_bluetooth_profile_manager_client.h"
...@@ -161,6 +163,8 @@ DBusClientBundle::DBusClientBundle(DBusClientTypeMask unstub_client_mask) ...@@ -161,6 +163,8 @@ DBusClientBundle::DBusClientBundle(DBusClientTypeMask unstub_client_mask)
if (!IsUsingStub(BLUETOOTH)) { if (!IsUsingStub(BLUETOOTH)) {
bluetooth_adapter_client_.reset(BluetoothAdapterClient::Create()); bluetooth_adapter_client_.reset(BluetoothAdapterClient::Create());
bluetooth_le_advertising_manager_client_.reset(
BluetoothLEAdvertisingManagerClient::Create());
bluetooth_agent_manager_client_.reset( bluetooth_agent_manager_client_.reset(
BluetoothAgentManagerClient::Create()); BluetoothAgentManagerClient::Create());
bluetooth_device_client_.reset(BluetoothDeviceClient::Create()); bluetooth_device_client_.reset(BluetoothDeviceClient::Create());
...@@ -180,6 +184,8 @@ DBusClientBundle::DBusClientBundle(DBusClientTypeMask unstub_client_mask) ...@@ -180,6 +184,8 @@ DBusClientBundle::DBusClientBundle(DBusClientTypeMask unstub_client_mask)
BluetoothGattServiceClient::Create()); BluetoothGattServiceClient::Create());
} else { } else {
bluetooth_adapter_client_.reset(new FakeBluetoothAdapterClient); bluetooth_adapter_client_.reset(new FakeBluetoothAdapterClient);
bluetooth_le_advertising_manager_client_.reset(
new FakeBluetoothLEAdvertisingManagerClient);
bluetooth_agent_manager_client_.reset(new FakeBluetoothAgentManagerClient); bluetooth_agent_manager_client_.reset(new FakeBluetoothAgentManagerClient);
bluetooth_device_client_.reset(new FakeBluetoothDeviceClient); bluetooth_device_client_.reset(new FakeBluetoothDeviceClient);
bluetooth_input_client_.reset(new FakeBluetoothInputClient); bluetooth_input_client_.reset(new FakeBluetoothInputClient);
......
...@@ -23,6 +23,7 @@ class BluetoothGattDescriptorClient; ...@@ -23,6 +23,7 @@ class BluetoothGattDescriptorClient;
class BluetoothGattManagerClient; class BluetoothGattManagerClient;
class BluetoothGattServiceClient; class BluetoothGattServiceClient;
class BluetoothInputClient; class BluetoothInputClient;
class BluetoothLEAdvertisingManagerClient;
class BluetoothMediaClient; class BluetoothMediaClient;
class BluetoothMediaTransportClient; class BluetoothMediaTransportClient;
class BluetoothProfileManagerClient; class BluetoothProfileManagerClient;
...@@ -123,6 +124,11 @@ class CHROMEOS_EXPORT DBusClientBundle { ...@@ -123,6 +124,11 @@ class CHROMEOS_EXPORT DBusClientBundle {
return bluetooth_adapter_client_.get(); return bluetooth_adapter_client_.get();
} }
BluetoothLEAdvertisingManagerClient*
bluetooth_le_advertising_manager_client() {
return bluetooth_le_advertising_manager_client_.get();
}
BluetoothAgentManagerClient* bluetooth_agent_manager_client() { BluetoothAgentManagerClient* bluetooth_agent_manager_client() {
return bluetooth_agent_manager_client_.get(); return bluetooth_agent_manager_client_.get();
} }
...@@ -296,6 +302,8 @@ class CHROMEOS_EXPORT DBusClientBundle { ...@@ -296,6 +302,8 @@ class CHROMEOS_EXPORT DBusClientBundle {
scoped_ptr<ApManagerClient> ap_manager_client_; scoped_ptr<ApManagerClient> ap_manager_client_;
scoped_ptr<AudioDspClient> audio_dsp_client_; scoped_ptr<AudioDspClient> audio_dsp_client_;
scoped_ptr<BluetoothAdapterClient> bluetooth_adapter_client_; scoped_ptr<BluetoothAdapterClient> bluetooth_adapter_client_;
scoped_ptr<BluetoothLEAdvertisingManagerClient>
bluetooth_le_advertising_manager_client_;
scoped_ptr<BluetoothAgentManagerClient> bluetooth_agent_manager_client_; scoped_ptr<BluetoothAgentManagerClient> bluetooth_agent_manager_client_;
scoped_ptr<BluetoothDeviceClient> bluetooth_device_client_; scoped_ptr<BluetoothDeviceClient> bluetooth_device_client_;
scoped_ptr<BluetoothGattCharacteristicClient> scoped_ptr<BluetoothGattCharacteristicClient>
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "chromeos/dbus/bluetooth_gatt_manager_client.h" #include "chromeos/dbus/bluetooth_gatt_manager_client.h"
#include "chromeos/dbus/bluetooth_gatt_service_client.h" #include "chromeos/dbus/bluetooth_gatt_service_client.h"
#include "chromeos/dbus/bluetooth_input_client.h" #include "chromeos/dbus/bluetooth_input_client.h"
#include "chromeos/dbus/bluetooth_le_advertising_manager_client.h"
#include "chromeos/dbus/bluetooth_media_client.h" #include "chromeos/dbus/bluetooth_media_client.h"
#include "chromeos/dbus/bluetooth_media_transport_client.h" #include "chromeos/dbus/bluetooth_media_transport_client.h"
#include "chromeos/dbus/bluetooth_profile_manager_client.h" #include "chromeos/dbus/bluetooth_profile_manager_client.h"
...@@ -132,6 +133,11 @@ BluetoothAdapterClient* DBusThreadManager::GetBluetoothAdapterClient() { ...@@ -132,6 +133,11 @@ BluetoothAdapterClient* DBusThreadManager::GetBluetoothAdapterClient() {
return client_bundle_->bluetooth_adapter_client(); return client_bundle_->bluetooth_adapter_client();
} }
BluetoothLEAdvertisingManagerClient*
DBusThreadManager::GetBluetoothLEAdvertisingManagerClient() {
return client_bundle_->bluetooth_le_advertising_manager_client();
}
BluetoothAgentManagerClient* BluetoothAgentManagerClient*
DBusThreadManager::GetBluetoothAgentManagerClient() { DBusThreadManager::GetBluetoothAgentManagerClient() {
return client_bundle_->bluetooth_agent_manager_client(); return client_bundle_->bluetooth_agent_manager_client();
...@@ -488,6 +494,12 @@ void DBusThreadManagerSetter::SetBluetoothAdapterClient( ...@@ -488,6 +494,12 @@ void DBusThreadManagerSetter::SetBluetoothAdapterClient(
client.Pass(); client.Pass();
} }
void DBusThreadManagerSetter::SetBluetoothLEAdvertisingManagerClient(
scoped_ptr<BluetoothLEAdvertisingManagerClient> client) {
DBusThreadManager::Get()->client_bundle_->
bluetooth_le_advertising_manager_client_ = client.Pass();
}
void DBusThreadManagerSetter::SetBluetoothAgentManagerClient( void DBusThreadManagerSetter::SetBluetoothAgentManagerClient(
scoped_ptr<BluetoothAgentManagerClient> client) { scoped_ptr<BluetoothAgentManagerClient> client) {
DBusThreadManager::Get()->client_bundle_->bluetooth_agent_manager_client_ = DBusThreadManager::Get()->client_bundle_->bluetooth_agent_manager_client_ =
......
...@@ -29,6 +29,7 @@ class AmplifierClient; ...@@ -29,6 +29,7 @@ class AmplifierClient;
class ApManagerClient; class ApManagerClient;
class AudioDspClient; class AudioDspClient;
class BluetoothAdapterClient; class BluetoothAdapterClient;
class BluetoothLEAdvertisingManagerClient;
class BluetoothAgentManagerClient; class BluetoothAgentManagerClient;
class BluetoothDeviceClient; class BluetoothDeviceClient;
class BluetoothGattCharacteristicClient; class BluetoothGattCharacteristicClient;
...@@ -126,6 +127,7 @@ class CHROMEOS_EXPORT DBusThreadManager { ...@@ -126,6 +127,7 @@ class CHROMEOS_EXPORT DBusThreadManager {
ApManagerClient* GetApManagerClient(); ApManagerClient* GetApManagerClient();
AudioDspClient* GetAudioDspClient(); AudioDspClient* GetAudioDspClient();
BluetoothAdapterClient* GetBluetoothAdapterClient(); BluetoothAdapterClient* GetBluetoothAdapterClient();
BluetoothLEAdvertisingManagerClient* GetBluetoothLEAdvertisingManagerClient();
BluetoothAgentManagerClient* GetBluetoothAgentManagerClient(); BluetoothAgentManagerClient* GetBluetoothAgentManagerClient();
BluetoothDeviceClient* GetBluetoothDeviceClient(); BluetoothDeviceClient* GetBluetoothDeviceClient();
BluetoothGattCharacteristicClient* GetBluetoothGattCharacteristicClient(); BluetoothGattCharacteristicClient* GetBluetoothGattCharacteristicClient();
...@@ -213,6 +215,8 @@ class CHROMEOS_EXPORT DBusThreadManagerSetter { ...@@ -213,6 +215,8 @@ class CHROMEOS_EXPORT DBusThreadManagerSetter {
void SetAmplifierClient(scoped_ptr<AmplifierClient> client); void SetAmplifierClient(scoped_ptr<AmplifierClient> client);
void SetAudioDspClient(scoped_ptr<AudioDspClient> client); void SetAudioDspClient(scoped_ptr<AudioDspClient> client);
void SetBluetoothAdapterClient(scoped_ptr<BluetoothAdapterClient> client); void SetBluetoothAdapterClient(scoped_ptr<BluetoothAdapterClient> client);
void SetBluetoothLEAdvertisingManagerClient(
scoped_ptr<BluetoothLEAdvertisingManagerClient> client);
void SetBluetoothAgentManagerClient( void SetBluetoothAgentManagerClient(
scoped_ptr<BluetoothAgentManagerClient> client); scoped_ptr<BluetoothAgentManagerClient> client);
void SetBluetoothDeviceClient(scoped_ptr<BluetoothDeviceClient> client); void SetBluetoothDeviceClient(scoped_ptr<BluetoothDeviceClient> client);
......
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chromeos/dbus/dbus_thread_manager.h"
#include "fake_bluetooth_le_advertisement_service_provider.h"
#include "fake_bluetooth_le_advertising_manager_client.h"
namespace chromeos {
FakeBluetoothLEAdvertisementServiceProvider::
FakeBluetoothLEAdvertisementServiceProvider(
const dbus::ObjectPath& object_path,
Delegate* delegate)
: object_path_(object_path), delegate_(delegate) {
VLOG(1) << "Creating Bluetooth Advertisement: " << object_path_.value();
FakeBluetoothLEAdvertisingManagerClient*
fake_bluetooth_profile_manager_client =
static_cast<FakeBluetoothLEAdvertisingManagerClient*>(
DBusThreadManager::Get()
->GetBluetoothLEAdvertisingManagerClient());
fake_bluetooth_profile_manager_client->RegisterAdvertisementServiceProvider(
this);
}
FakeBluetoothLEAdvertisementServiceProvider::
~FakeBluetoothLEAdvertisementServiceProvider() {
VLOG(1) << "Cleaning up Bluetooth Advertisement: " << object_path_.value();
FakeBluetoothLEAdvertisingManagerClient*
fake_bluetooth_profile_manager_client =
static_cast<FakeBluetoothLEAdvertisingManagerClient*>(
DBusThreadManager::Get()
->GetBluetoothLEAdvertisingManagerClient());
fake_bluetooth_profile_manager_client->UnregisterAdvertisementServiceProvider(
this);
}
void FakeBluetoothLEAdvertisementServiceProvider::Release() {
VLOG(1) << object_path_.value() << ": Release";
delegate_->Released();
}
} // namespace chromeos
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROMEOS_DBUS_FAKE_BLUETOOTH_LE_ADVERTISEMENT_SERVICE_PROVIDER_H_
#define CHROMEOS_DBUS_FAKE_BLUETOOTH_LE_ADVERTISEMENT_SERVICE_PROVIDER_H_
#include "base/bind.h"
#include "base/callback.h"
#include "base/memory/scoped_ptr.h"
#include "chromeos/chromeos_export.h"
#include "chromeos/dbus/bluetooth_le_advertisement_service_provider.h"
#include "dbus/file_descriptor.h"
#include "dbus/object_path.h"
namespace chromeos {
// FakeBluetoothAdvertisementServiceProvider simulates the behavior of a local
// Bluetooth agent object and is used both in test cases in place of a
// mock and on the Linux desktop.
class CHROMEOS_EXPORT FakeBluetoothLEAdvertisementServiceProvider
: public BluetoothLEAdvertisementServiceProvider {
public:
FakeBluetoothLEAdvertisementServiceProvider(
const dbus::ObjectPath& object_path,
Delegate* delegate);
~FakeBluetoothLEAdvertisementServiceProvider() override;
// Each of these calls the equivalent
// BluetoothAdvertisementServiceProvider::Delegate method on the object passed
// on construction.
void Release();
const dbus::ObjectPath& object_path() { return object_path_; }
private:
friend class FakeBluetoothLEAdvertisingManagerClient;
// D-Bus object path we are faking.
dbus::ObjectPath object_path_;
// All incoming method calls are passed on to the Delegate and a callback
// passed to generate the reply. |delegate_| is generally the object that
// owns this one, and must outlive it.
Delegate* delegate_;
DISALLOW_COPY_AND_ASSIGN(FakeBluetoothLEAdvertisementServiceProvider);
};
} // namespace chromeos
#endif // CHROMEOS_DBUS_FAKE_BLUETOOTH_LE_ADVERTISEMENT_SERVICE_PROVIDER_H_
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/logging.h"
#include "base/message_loop/message_loop.h"
#include "dbus/bus.h"
#include "dbus/message.h"
#include "dbus/object_proxy.h"
#include "fake_bluetooth_le_advertisement_service_provider.h"
#include "fake_bluetooth_le_advertising_manager_client.h"
#include "third_party/cros_system_api/dbus/service_constants.h"
namespace chromeos {
const char FakeBluetoothLEAdvertisingManagerClient::kAdvertisingManagerPath[] =
"/fake/hci0";
FakeBluetoothLEAdvertisingManagerClient::
FakeBluetoothLEAdvertisingManagerClient() {
}
FakeBluetoothLEAdvertisingManagerClient::
~FakeBluetoothLEAdvertisingManagerClient() {
}
void FakeBluetoothLEAdvertisingManagerClient::Init(dbus::Bus* bus) {
}
void FakeBluetoothLEAdvertisingManagerClient::AddObserver(Observer* observer) {
}
void FakeBluetoothLEAdvertisingManagerClient::RemoveObserver(
Observer* observer) {
}
void FakeBluetoothLEAdvertisingManagerClient::RegisterAdvertisement(
const dbus::ObjectPath& manager_object_path,
const dbus::ObjectPath& advertisement_object_path,
const base::Closure& callback,
const ErrorCallback& error_callback) {
VLOG(1) << "RegisterAdvertisment: " << advertisement_object_path.value();
if (manager_object_path != dbus::ObjectPath(kAdvertisingManagerPath)) {
error_callback.Run(kNoResponseError, "Invalid Advertising Manager path.");
return;
}
ServiceProviderMap::iterator iter =
service_provider_map_.find(advertisement_object_path);
if (iter == service_provider_map_.end()) {
error_callback.Run(bluetooth_advertising_manager::kErrorInvalidArguments,
"Advertisement object not registered");
} else if (!currently_registered_.value().empty()) {
error_callback.Run(bluetooth_advertising_manager::kErrorFailed,
"Maximum advertisements reached");
} else if (advertisement_object_path != currently_registered_) {
error_callback.Run(bluetooth_advertising_manager::kErrorAlreadyExists,
"Already advertising.");
} else {
currently_registered_ = advertisement_object_path;
base::MessageLoop::current()->PostTask(FROM_HERE, callback);
}
}
void FakeBluetoothLEAdvertisingManagerClient::UnregisterAdvertisement(
const dbus::ObjectPath& manager_object_path,
const dbus::ObjectPath& advertisement_object_path,
const base::Closure& callback,
const ErrorCallback& error_callback) {
VLOG(1) << "UnregisterAdvertisment: " << advertisement_object_path.value();
if (manager_object_path != dbus::ObjectPath(kAdvertisingManagerPath)) {
error_callback.Run(kNoResponseError, "Invalid Advertising Manager path.");
return;
}
ServiceProviderMap::iterator iter =
service_provider_map_.find(advertisement_object_path);
if (iter == service_provider_map_.end()) {
error_callback.Run(bluetooth_advertising_manager::kErrorDoesNotExist,
"Advertisement not registered");
} else if (advertisement_object_path != currently_registered_) {
error_callback.Run(bluetooth_advertising_manager::kErrorDoesNotExist,
"Does not exist");
} else {
currently_registered_ = dbus::ObjectPath("");
base::MessageLoop::current()->PostTask(FROM_HERE, callback);
}
}
void FakeBluetoothLEAdvertisingManagerClient::
RegisterAdvertisementServiceProvider(
FakeBluetoothLEAdvertisementServiceProvider* service_provider) {
service_provider_map_[service_provider->object_path_] = service_provider;
}
void FakeBluetoothLEAdvertisingManagerClient::
UnregisterAdvertisementServiceProvider(
FakeBluetoothLEAdvertisementServiceProvider* service_provider) {
ServiceProviderMap::iterator iter =
service_provider_map_.find(service_provider->object_path_);
if (iter != service_provider_map_.end() && iter->second == service_provider)
service_provider_map_.erase(iter);
}
} // namespace chromeos
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROMEOS_DBUS_FAKE_BLUETOOTH_LE_ADVERTISING_MANAGER_CLIENT_H_
#define CHROMEOS_DBUS_FAKE_BLUETOOTH_LE_ADVERTISING_MANAGER_CLIENT_H_
#include <map>
#include <string>
#include "base/bind.h"
#include "base/callback.h"
#include "base/observer_list.h"
#include "bluetooth_le_advertising_manager_client.h"
#include "chromeos/chromeos_export.h"
#include "dbus/object_path.h"
#include "dbus/property.h"
namespace chromeos {
class FakeBluetoothLEAdvertisementServiceProvider;
// FakeBluetoothAdvertisementManagerClient simulates the behavior of the
// Bluetooth
// Daemon's profile manager object and is used both in test cases in place of a
// mock and on the Linux desktop.
class CHROMEOS_EXPORT FakeBluetoothLEAdvertisingManagerClient
: public BluetoothLEAdvertisingManagerClient {
public:
FakeBluetoothLEAdvertisingManagerClient();
~FakeBluetoothLEAdvertisingManagerClient() override;
// DBusClient overrides:
void Init(dbus::Bus* bus) override;
// BluetoothAdvertisingManagerClient overrides:
void AddObserver(Observer* observer) override;
void RemoveObserver(Observer* observer) override;
void RegisterAdvertisement(const dbus::ObjectPath& manager_object_path,
const dbus::ObjectPath& advertisement_object_path,
const base::Closure& callback,
const ErrorCallback& error_callback) override;
void UnregisterAdvertisement(
const dbus::ObjectPath& manager_object_path,
const dbus::ObjectPath& advertisement_object_path,
const base::Closure& callback,
const ErrorCallback& error_callback) override;
// Register, unregister and retrieve pointers to profile server providers.
void RegisterAdvertisementServiceProvider(
FakeBluetoothLEAdvertisementServiceProvider* service_provider);
void UnregisterAdvertisementServiceProvider(
FakeBluetoothLEAdvertisementServiceProvider* service_provider);
FakeBluetoothLEAdvertisementServiceProvider* GetAdvertisementServiceProvider(
const std::string& uuid);
// Advertising manager path that we simulate.
static const char kAdvertisingManagerPath[];
private:
// Map of a D-Bus object path to the FakeBluetoothAdvertisementServiceProvider
// registered for it; maintained by RegisterAdvertisementServiceProvider() and
// UnregisterProfileServiceProvicer() called by the constructor and
// destructor of FakeBluetoothAdvertisementServiceProvider.
typedef std::map<dbus::ObjectPath,
FakeBluetoothLEAdvertisementServiceProvider*>
ServiceProviderMap;
ServiceProviderMap service_provider_map_;
// Holds the currently registered advertisement. If there is no advertisement
// registered, this path is empty.
dbus::ObjectPath currently_registered_;
DISALLOW_COPY_AND_ASSIGN(FakeBluetoothLEAdvertisingManagerClient);
};
} // namespace chromeos
#endif // CHROMEOS_DBUS_FAKE_BLUETOOTH_LE_ADVERTISING_MANAGER_CLIENT_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment