Skip to content

Commit

Permalink
dbus: add ObjectPath type
Browse files Browse the repository at this point in the history
Rather than use std::string for object paths, add a dbus::ObjectPath type
that wraps one while allowing more type-safety. This solves all sorts of
issues with confusing object paths for strings, and allows us to do
Properties code using templates disambiguating them from strings.

BUG=chromium:109194
TEST=built and run tests

Change-Id: Icaf6f19daea4af23a9d2ec0ed76d2cbd379d680e


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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@121920 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
keybuk@chromium.org committed Feb 14, 2012
1 parent ce1402a commit bc1b18e
Show file tree
Hide file tree
Showing 47 changed files with 470 additions and 333 deletions.
34 changes: 17 additions & 17 deletions chrome/browser/chromeos/bluetooth/bluetooth_adapter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,59 +49,59 @@ class BluetoothAdapterImpl : public BluetoothAdapter,
virtual void StartDiscovery() {
VLOG(1) << id_ << ": StartDiscovery";
DCHECK(bluetooth_adapter_client_);
bluetooth_adapter_client_->StartDiscovery(id_);
bluetooth_adapter_client_->StartDiscovery(dbus::ObjectPath(id_));
}

virtual void StopDiscovery() {
VLOG(1) << id_ << ": StopDiscovery";
DCHECK(bluetooth_adapter_client_);
bluetooth_adapter_client_->StopDiscovery(id_);
bluetooth_adapter_client_->StopDiscovery(dbus::ObjectPath(id_));
}

// BluetoothAdapterClient::Observer override.
virtual void DiscoveringPropertyChanged(const std::string& object_path,
virtual void DiscoveringPropertyChanged(const dbus::ObjectPath& object_path,
bool discovering) {
VLOG(1) << id_ << ": object_path = " << object_path << ", Discovering = "
<< discovering;
if (object_path != id_) {
VLOG(1) << id_ << ": object_path = " << object_path.value()
<< ", Discovering = " << discovering;
if (object_path.value() != id_) {
return;
}
if (discovering) {
FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_,
DiscoveryStarted(object_path));
DiscoveryStarted(object_path.value()));
} else {
FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_,
DiscoveryEnded(object_path));
DiscoveryEnded(object_path.value()));
}
}

// BluetoothAdapterClient::Observer override.
virtual void DeviceFound(const std::string& object_path,
virtual void DeviceFound(const dbus::ObjectPath& object_path,
const std::string& address,
const base::DictionaryValue& device_properties) {
VLOG(1) << id_ << ": object_path = " << object_path << ", Device found: "
<< address << " (with " << device_properties.size()
<< " properties)";
if (object_path != id_) {
VLOG(1) << id_ << ": object_path = " << object_path.value()
<< ", Device found: " << address << " (with "
<< device_properties.size() << " properties)";
if (object_path.value() != id_) {
return;
}
// TODO(vlaviano): later, we will want to persist the device.
scoped_ptr<BluetoothDevice> device(
BluetoothDevice::Create(device_properties));
if (device.get() != NULL) {
FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_,
DeviceFound(object_path, device.get()));
DeviceFound(object_path.value(), device.get()));
} else {
LOG(WARNING) << "Could not create BluetoothDevice from properties.";
}
}

// BluetoothAdapterClient::Observer override.
virtual void DeviceDisappeared(const std::string& object_path,
virtual void DeviceDisappeared(const dbus::ObjectPath& object_path,
const std::string& address) {
VLOG(1) << id_ << ": object_path = " << object_path
VLOG(1) << id_ << ": object_path = " << object_path.value()
<< ", Device disappeared: " << address;
if (object_path != id_) {
if (object_path.value() != id_) {
return;
}
// For now, we don't propagate this event to our observers.
Expand Down
27 changes: 15 additions & 12 deletions chrome/browser/chromeos/bluetooth/bluetooth_manager.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// 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
// found in the LICENSE file.

Expand All @@ -10,6 +10,7 @@
#include "chrome/browser/chromeos/bluetooth/bluetooth_adapter.h"
#include "chrome/browser/chromeos/dbus/bluetooth_manager_client.h"
#include "chrome/browser/chromeos/dbus/dbus_thread_manager.h"
#include "dbus/object_path.h"

namespace chromeos {

Expand Down Expand Up @@ -50,9 +51,10 @@ class BluetoothManagerImpl : public BluetoothManager,
}

// BluetoothManagerClient::Observer override.
virtual void AdapterRemoved(const std::string& adapter) {
VLOG(1) << "AdapterRemoved: " << adapter;
if (default_adapter_.get() == NULL || default_adapter_->Id() != adapter) {
virtual void AdapterRemoved(const dbus::ObjectPath& adapter) {
VLOG(1) << "AdapterRemoved: " << adapter.value();
if (default_adapter_.get() == NULL
|| default_adapter_->Id() != adapter.value()) {
return;
}
// The default adapter was removed.
Expand All @@ -62,8 +64,8 @@ class BluetoothManagerImpl : public BluetoothManager,
}

// BluetoothManagerClient::Observer override.
virtual void DefaultAdapterChanged(const std::string& adapter) {
VLOG(1) << "DefaultAdapterChanged: " << adapter;
virtual void DefaultAdapterChanged(const dbus::ObjectPath& adapter) {
VLOG(1) << "DefaultAdapterChanged: " << adapter.value();
OnNewDefaultAdapter(adapter);
}

Expand All @@ -73,25 +75,26 @@ class BluetoothManagerImpl : public BluetoothManager,
}

// We have updated info about the default adapter.
void OnNewDefaultAdapter(const std::string& adapter) {
VLOG(1) << "OnNewDefaultAdapter: " << adapter;
if (default_adapter_.get() != NULL && default_adapter_->Id() == adapter) {
void OnNewDefaultAdapter(const dbus::ObjectPath& adapter) {
VLOG(1) << "OnNewDefaultAdapter: " << adapter.value();
if (default_adapter_.get() != NULL
&& default_adapter_->Id() == adapter.value()) {
return;
}
default_adapter_.reset(BluetoothAdapter::Create(adapter));
default_adapter_.reset(BluetoothAdapter::Create(adapter.value()));
DCHECK(default_adapter_.get());
FOR_EACH_OBSERVER(BluetoothManager::Observer, observers_,
DefaultAdapterChanged(default_adapter_.get()));
}

// Called by bluetooth_manager_client when our DefaultAdapter request is
// complete
void OnDefaultAdapter(const std::string& adapter, bool success) {
void OnDefaultAdapter(const dbus::ObjectPath& adapter, bool success) {
if (!success) {
LOG(ERROR) << "OnDefaultAdapter: failed.";
return;
}
VLOG(1) << "OnDefaultAdapter: " << adapter;
VLOG(1) << "OnDefaultAdapter: " << adapter.value();
OnNewDefaultAdapter(adapter);
}

Expand Down
Loading

0 comments on commit bc1b18e

Please sign in to comment.