• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "chromeos/dbus/fake_nfc_manager_client.h"
6 
7 #include "base/bind.h"
8 #include "base/logging.h"
9 #include "dbus/object_path.h"
10 #include "third_party/cros_system_api/dbus/service_constants.h"
11 
12 namespace chromeos {
13 
14 const char FakeNfcManagerClient::kDefaultAdapterPath[] = "/fake/nfc0";
15 
Properties(const PropertyChangedCallback & callback)16 FakeNfcManagerClient::Properties::Properties(
17     const PropertyChangedCallback& callback)
18     : NfcManagerClient::Properties(NULL, callback) {
19 }
20 
~Properties()21 FakeNfcManagerClient::Properties::~Properties() {
22 }
23 
Get(dbus::PropertyBase * property,dbus::PropertySet::GetCallback callback)24 void FakeNfcManagerClient::Properties::Get(
25     dbus::PropertyBase* property,
26     dbus::PropertySet::GetCallback callback) {
27   VLOG(1) << "Get " << property->name();
28   callback.Run(false);
29 }
30 
GetAll()31 void FakeNfcManagerClient::Properties::GetAll() {
32   VLOG(1) << "GetAll";
33 }
34 
Set(dbus::PropertyBase * property,dbus::PropertySet::SetCallback callback)35 void FakeNfcManagerClient::Properties::Set(
36     dbus::PropertyBase* property,
37     dbus::PropertySet::SetCallback callback) {
38   VLOG(1) << "Set " << property->name();
39   callback.Run(false);
40 }
41 
FakeNfcManagerClient()42 FakeNfcManagerClient::FakeNfcManagerClient() {
43   properties_.reset(new Properties(base::Bind(
44       &FakeNfcManagerClient::OnPropertyChanged, base::Unretained(this))));
45   AddAdapter(kDefaultAdapterPath);
46 }
47 
~FakeNfcManagerClient()48 FakeNfcManagerClient::~FakeNfcManagerClient() {
49 }
50 
Init(dbus::Bus * bus)51 void FakeNfcManagerClient::Init(dbus::Bus* bus) {
52 }
53 
AddObserver(Observer * observer)54 void FakeNfcManagerClient::AddObserver(Observer* observer) {
55   observers_.AddObserver(observer);
56 }
57 
RemoveObserver(Observer * observer)58 void FakeNfcManagerClient::RemoveObserver(Observer* observer) {
59   observers_.RemoveObserver(observer);
60 }
61 
GetProperties()62 FakeNfcManagerClient::Properties* FakeNfcManagerClient::GetProperties() {
63   return properties_.get();
64 }
65 
AddAdapter(const std::string & adapter_path)66 void FakeNfcManagerClient::AddAdapter(const std::string& adapter_path) {
67   VLOG(1) << "Adding NFC adapter: " << adapter_path;
68   dbus::ObjectPath new_adapter(adapter_path);
69   std::pair<std::set<dbus::ObjectPath>::iterator, bool> result =
70       adapters_.insert(new_adapter);
71   if (!result.second) {
72     VLOG(1) << "Adapter \"" << adapter_path << "\" already exists.";
73     return;
74   }
75   // Create a vector containing all object paths in the set |adapters_|. This
76   // will copy all members of |adapters_| to |adapters|.
77   std::vector<dbus::ObjectPath> adapters(adapters_.begin(), adapters_.end());
78   properties_->adapters.ReplaceValue(adapters);
79   FOR_EACH_OBSERVER(Observer, observers_, AdapterAdded(new_adapter));
80 }
81 
RemoveAdapter(const std::string & adapter_path)82 void FakeNfcManagerClient::RemoveAdapter(const std::string& adapter_path) {
83   VLOG(1) << "Removing NFC adapter: " << adapter_path;
84   dbus::ObjectPath to_remove(adapter_path);
85   if (adapters_.erase(to_remove) == 0) {
86     VLOG(1) << "No such adapter: \"" << adapter_path << "\"";
87     return;
88   }
89   std::vector<dbus::ObjectPath> adapters(adapters_.begin(), adapters_.end());
90   properties_->adapters.ReplaceValue(adapters);
91   FOR_EACH_OBSERVER(Observer, observers_, AdapterRemoved(to_remove));
92 }
93 
OnPropertyChanged(const std::string & property_name)94 void FakeNfcManagerClient::OnPropertyChanged(
95     const std::string& property_name) {
96   FOR_EACH_OBSERVER(Observer, observers_,
97                     ManagerPropertyChanged(property_name));
98 }
99 
100 }  // namespace chromeos
101