diff options
author | armansito@chromium.org <armansito@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-20 23:24:19 +0000 |
---|---|---|
committer | armansito@chromium.org <armansito@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-20 23:24:19 +0000 |
commit | 13aa72068571a09f84d6bd2524cf6d9ca190f214 (patch) | |
tree | 77b4587e072bdfdde5ac0e95db8292acbf0211f9 /chromeos/dbus/fake_nfc_adapter_client.cc | |
parent | 57afa12e2f3d503b2cea20ecd50a47930156305a (diff) | |
download | chromium_src-13aa72068571a09f84d6bd2524cf6d9ca190f214.zip chromium_src-13aa72068571a09f84d6bd2524cf6d9ca190f214.tar.gz chromium_src-13aa72068571a09f84d6bd2524cf6d9ca190f214.tar.bz2 |
nfc: Implement device::NfcPeerChromeOS.
Implemented device::NfcPeer for Chrome OS. With this, Chrome can now
interact with remote NFC adapters.
BUG=316471
TEST=device_unittests
Review URL: https://codereview.chromium.org/112183002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@242205 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chromeos/dbus/fake_nfc_adapter_client.cc')
-rw-r--r-- | chromeos/dbus/fake_nfc_adapter_client.cc | 81 |
1 files changed, 78 insertions, 3 deletions
diff --git a/chromeos/dbus/fake_nfc_adapter_client.cc b/chromeos/dbus/fake_nfc_adapter_client.cc index ddc673a..f36c262 100644 --- a/chromeos/dbus/fake_nfc_adapter_client.cc +++ b/chromeos/dbus/fake_nfc_adapter_client.cc @@ -5,12 +5,17 @@ #include "chromeos/dbus/fake_nfc_adapter_client.h" #include "base/logging.h" +#include "chromeos/dbus/dbus_thread_manager.h" +#include "chromeos/dbus/fake_nfc_device_client.h" +#include "chromeos/dbus/nfc_client_helpers.h" #include "dbus/message.h" #include "dbus/object_path.h" #include "third_party/cros_system_api/dbus/service_constants.h" namespace chromeos { +using nfc_client_helpers::ObjectPathVector; + const char FakeNfcAdapterClient::kAdapterPath0[] = "/fake/nfc0"; const char FakeNfcAdapterClient::kAdapterPath1[] = "/fake/nfc1"; @@ -44,6 +49,15 @@ void FakeNfcAdapterClient::Properties::Set( // Cannot set the power if currently polling. if (polling.value()) { + LOG(ERROR) << "Cannot set power while polling."; + callback.Run(false); + return; + } + + // Cannot set power if there is a device or a tag that is currently + // "paired". + if (!devices.value().empty() || !tags.value().empty()) { + LOG(ERROR) << "Cannot set power while the device is paired."; callback.Run(false); return; } @@ -66,7 +80,8 @@ void FakeNfcAdapterClient::Properties::Set( FakeNfcAdapterClient::FakeNfcAdapterClient() : present_(true), - second_present_(false) { + second_present_(false), + start_pairing_on_poll_(true) { VLOG(1) << "Creating FakeNfcAdapterClient"; std::vector<std::string> protocols; @@ -139,9 +154,21 @@ void FakeNfcAdapterClient::StartPollLoop( error_callback.Run("org.neard.Error.Failed", "Already polling."); return; } + if (!properties_->devices.value().empty() || + !properties_->tags.value().empty()) { + error_callback.Run("org.neard.Error.Failed", "Adapter busy."); + return; + } properties_->polling.ReplaceValue(true); properties_->mode.ReplaceValue(mode); - // TODO(armansito): Initiate fake device/tag simulation here. + callback.Run(); + + FakeNfcDeviceClient* device_client = + static_cast<FakeNfcDeviceClient*>( + DBusThreadManager::Get()->GetNfcDeviceClient()); + + if (start_pairing_on_poll_) + device_client->BeginPairingSimulation(3000, 2000); } void FakeNfcAdapterClient::StopPollLoop( @@ -157,8 +184,12 @@ void FakeNfcAdapterClient::StopPollLoop( error_callback.Run("org.neard.Error.Failed", "Not polling."); return; } - // TODO(armansito): End fake device/tag simulation here. + FakeNfcDeviceClient* device_client = + static_cast<FakeNfcDeviceClient*>( + DBusThreadManager::Get()->GetNfcDeviceClient()); + device_client->EndPairingSimulation(); properties_->polling.ReplaceValue(false); + callback.Run(); } void FakeNfcAdapterClient::SetAdapterPresent(bool present) { @@ -187,6 +218,50 @@ void FakeNfcAdapterClient::SetSecondAdapterPresent(bool present) { } } +void FakeNfcAdapterClient::SetDevice(const dbus::ObjectPath& device_path) { + LOG(INFO) << "Add device path to the fake adapter: " << device_path.value(); + if (!properties_->polling.value()) { + LOG(ERROR) << "Device not polling, cannot set device."; + return; + } + const ObjectPathVector& devices(properties_->devices.value()); + for (ObjectPathVector::const_iterator iter = devices.begin(); + iter != devices.end(); ++iter) { + if (*iter == device_path) { + LOG(WARNING) << "Device path already in list of devices."; + return; + } + } + // Mark as not polling. + properties_->polling.ReplaceValue(false); + + ObjectPathVector new_devices = devices; + new_devices.push_back(device_path); + properties_->devices.ReplaceValue(new_devices); +} + +void FakeNfcAdapterClient::UnsetDevice(const dbus::ObjectPath& device_path) { + LOG(INFO) << "Add device path to the fake adapter: " << device_path.value(); + ObjectPathVector new_devices = properties_->devices.value(); + for (ObjectPathVector::iterator iter = new_devices.begin(); + iter != new_devices.end(); ++iter) { + if (*iter == device_path) { + new_devices.erase(iter); + properties_->devices.ReplaceValue(new_devices); + + // Mark as polling. + DCHECK(!properties_->polling.value()); + properties_->polling.ReplaceValue(true); + return; + } + } + LOG(WARNING) << "Device path not in list of devices."; +} + +void FakeNfcAdapterClient::EnablePairingOnPoll(bool enabled) { + start_pairing_on_poll_ = enabled; +} + void FakeNfcAdapterClient::OnPropertyChanged( const dbus::ObjectPath& object_path, const std::string& property_name) { |