Commit cb288b63 authored by keybuk@chromium.org's avatar keybuk@chromium.org

chrome: bluetooth: hook up the AdapterAdded signal

The manager sends signals when additional adapters (including the
initial) are added, we may need these to obtain properties before
the default adapter is switched so hook up that signal so the
observer can take it.

BUG=chromium-os:22086
TEST=verified signals are received

Change-Id: I895c699eaef2f77f70ad855601b16e9a7c731ebb


Review URL: http://codereview.chromium.org/9302027

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@120024 0039d316-1c4b-4281-b951-d872f2087c98
parent aa07bb8a
// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
...@@ -28,6 +28,14 @@ class BluetoothManagerClientImpl : public BluetoothManagerClient { ...@@ -28,6 +28,14 @@ class BluetoothManagerClientImpl : public BluetoothManagerClient {
bluetooth_manager::kBluetoothManagerServiceName, bluetooth_manager::kBluetoothManagerServiceName,
bluetooth_manager::kBluetoothManagerServicePath); bluetooth_manager::kBluetoothManagerServicePath);
bluetooth_manager_proxy_->ConnectToSignal(
bluetooth_manager::kBluetoothManagerInterface,
bluetooth_manager::kAdapterAddedSignal,
base::Bind(&BluetoothManagerClientImpl::AdapterAddedReceived,
weak_ptr_factory_.GetWeakPtr()),
base::Bind(&BluetoothManagerClientImpl::AdapterAddedConnected,
weak_ptr_factory_.GetWeakPtr()));
bluetooth_manager_proxy_->ConnectToSignal( bluetooth_manager_proxy_->ConnectToSignal(
bluetooth_manager::kBluetoothManagerInterface, bluetooth_manager::kBluetoothManagerInterface,
bluetooth_manager::kAdapterRemovedSignal, bluetooth_manager::kAdapterRemovedSignal,
...@@ -79,18 +87,39 @@ class BluetoothManagerClientImpl : public BluetoothManagerClient { ...@@ -79,18 +87,39 @@ class BluetoothManagerClientImpl : public BluetoothManagerClient {
} }
private: private:
// Called by dbus:: when an AdapterAdded signal is received.
void AdapterAddedReceived(dbus::Signal* signal) {
DCHECK(signal);
dbus::MessageReader reader(signal);
std::string object_path;
if (!reader.PopObjectPath(&object_path)) {
LOG(ERROR) << "AdapterAdded signal has incorrect parameters: "
<< signal->ToString();
return;
}
VLOG(1) << "Adapter added: " << object_path;
FOR_EACH_OBSERVER(Observer, observers_, AdapterAdded(object_path));
}
// Called by dbus:: when the AdapterAdded signal is initially connected.
void AdapterAddedConnected(const std::string& interface_name,
const std::string& signal_name,
bool success) {
LOG_IF(WARNING, !success) << "Failed to connect to AdapterAdded signal.";
}
// Called by dbus:: when an AdapterRemoved signal is received. // Called by dbus:: when an AdapterRemoved signal is received.
void AdapterRemovedReceived(dbus::Signal* signal) { void AdapterRemovedReceived(dbus::Signal* signal) {
DCHECK(signal); DCHECK(signal);
dbus::MessageReader reader(signal); dbus::MessageReader reader(signal);
std::string adapter; std::string object_path;
if (!reader.PopObjectPath(&adapter)) { if (!reader.PopObjectPath(&object_path)) {
LOG(ERROR) << "AdapterRemoved signal has incorrect parameters: " LOG(ERROR) << "AdapterRemoved signal has incorrect parameters: "
<< signal->ToString(); << signal->ToString();
return; return;
} }
VLOG(1) << "Adapter removed: " << adapter; VLOG(1) << "Adapter removed: " << object_path;
FOR_EACH_OBSERVER(Observer, observers_, AdapterRemoved(adapter)); FOR_EACH_OBSERVER(Observer, observers_, AdapterRemoved(object_path));
} }
// Called by dbus:: when the AdapterRemoved signal is initially connected. // Called by dbus:: when the AdapterRemoved signal is initially connected.
......
// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
...@@ -26,9 +26,13 @@ class BluetoothManagerClient { ...@@ -26,9 +26,13 @@ class BluetoothManagerClient {
public: public:
virtual ~Observer() {} virtual ~Observer() {}
// Called when a local bluetooth adapter is added.
// |object_path| is the dbus object path of the adapter.
virtual void AdapterAdded(const std::string& object_path) {}
// Called when a local bluetooth adapter is removed. // Called when a local bluetooth adapter is removed.
// |adapter| is the dbus object path of the adapter. // |object_path| is the dbus object path of the adapter.
virtual void AdapterRemoved(const std::string& adapter) {} virtual void AdapterRemoved(const std::string& object_path) {}
// Called when the default local bluetooth adapter changes. // Called when the default local bluetooth adapter changes.
// |adapter| is the dbus object path of the new default adapter. // |adapter| is the dbus object path of the new default adapter.
......
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