Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1412)

Side by Side Diff: chromeos/dbus/nfc_manager_client.cc

Issue 2292703002: chromeos: Remove unused NFC D-Bus client library (Closed)
Patch Set: rebase Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chromeos/dbus/nfc_manager_client.h ('k') | chromeos/dbus/nfc_property_set.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 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/nfc_manager_client.h"
6
7 #include <memory>
8
9 #include "base/macros.h"
10 #include "base/memory/weak_ptr.h"
11 #include "base/observer_list.h"
12 #include "dbus/bus.h"
13 #include "third_party/cros_system_api/dbus/service_constants.h"
14
15 namespace chromeos {
16
17 NfcManagerClient::Properties::Properties(
18 dbus::ObjectProxy* object_proxy,
19 const PropertyChangedCallback& callback)
20 : NfcPropertySet(object_proxy,
21 nfc_manager::kNfcManagerInterface,
22 callback) {
23 RegisterProperty(nfc_manager::kAdaptersProperty, &adapters);
24 }
25
26 NfcManagerClient::Properties::~Properties() {
27 }
28
29
30 // The NfcManagerClient implementation used in production.
31 class NfcManagerClientImpl : public NfcManagerClient {
32 public:
33 NfcManagerClientImpl()
34 : object_proxy_(NULL),
35 weak_ptr_factory_(this) {
36 }
37
38 ~NfcManagerClientImpl() override {}
39
40 // NfcManagerClient override.
41 void AddObserver(Observer* observer) override {
42 DCHECK(observer);
43 observers_.AddObserver(observer);
44 }
45
46 // NfcManagerClient override.
47 void RemoveObserver(Observer* observer) override {
48 DCHECK(observer);
49 observers_.RemoveObserver(observer);
50 }
51
52 // NfcManagerClient override.
53 Properties* GetProperties() override { return properties_.get(); }
54
55 protected:
56 // DBusClient override.
57 void Init(dbus::Bus* bus) override {
58 VLOG(1) << "Creating NfcManagerClientImpl";
59
60 // Create the object proxy.
61 object_proxy_ = bus->GetObjectProxy(
62 nfc_manager::kNfcManagerServiceName,
63 dbus::ObjectPath(nfc_manager::kNfcManagerServicePath));
64
65 // Set up the signal handlers.
66 object_proxy_->ConnectToSignal(
67 nfc_manager::kNfcManagerInterface,
68 nfc_manager::kAdapterAddedSignal,
69 base::Bind(&NfcManagerClientImpl::AdapterAddedReceived,
70 weak_ptr_factory_.GetWeakPtr()),
71 base::Bind(&NfcManagerClientImpl::AdapterAddedConnected,
72 weak_ptr_factory_.GetWeakPtr()));
73 object_proxy_->ConnectToSignal(
74 nfc_manager::kNfcManagerInterface,
75 nfc_manager::kAdapterRemovedSignal,
76 base::Bind(&NfcManagerClientImpl::AdapterRemovedReceived,
77 weak_ptr_factory_.GetWeakPtr()),
78 base::Bind(&NfcManagerClientImpl::AdapterRemovedConnected,
79 weak_ptr_factory_.GetWeakPtr()));
80
81 // Create the properties structure.
82 properties_.reset(new Properties(
83 object_proxy_,
84 base::Bind(&NfcManagerClientImpl::OnPropertyChanged,
85 weak_ptr_factory_.GetWeakPtr())));
86 properties_->ConnectSignals();
87
88 object_proxy_->WaitForServiceToBeAvailable(
89 base::Bind(&NfcManagerClientImpl::OnServiceInitiallyAvailable,
90 weak_ptr_factory_.GetWeakPtr()));
91 }
92
93 private:
94 // Called by |object_proxy_| when the D-Bus service initially becomes
95 // available.
96 void OnServiceInitiallyAvailable(bool service_is_available) {
97 if (service_is_available)
98 properties_->GetAll();
99 else
100 LOG(ERROR) << "Failed to wait for D-Bus service to become available";
101 }
102
103 // NFC manager signal handlers.
104 void OnPropertyChanged(const std::string& property_name) {
105 VLOG(1) << "NFC Manager property changed: " << property_name;
106 FOR_EACH_OBSERVER(Observer, observers_,
107 ManagerPropertyChanged(property_name));
108 }
109
110 // Called by dbus:: when an "AdapterAdded" signal is received.
111 void AdapterAddedReceived(dbus::Signal* signal) {
112 DCHECK(signal);
113 dbus::MessageReader reader(signal);
114 dbus::ObjectPath object_path;
115 if (!reader.PopObjectPath(&object_path)) {
116 LOG(WARNING) << "AdapterAdded signal has incorrect parameters: "
117 << signal->ToString();
118 return;
119 }
120 VLOG(1) << "Adapter added: " << object_path.value();
121 FOR_EACH_OBSERVER(Observer, observers_, AdapterAdded(object_path));
122 }
123
124 // Called by dbus:: when the "AdapterAdded" signal is initially connected.
125 void AdapterAddedConnected(const std::string& interface_name,
126 const std::string& signal_name,
127 bool success) {
128 LOG_IF(WARNING, !success) << "Failed to connect to AdapterAdded signal.";
129 }
130
131 // Called by dbus:: when an "AdapterRemoved" signal is received..
132 void AdapterRemovedReceived(dbus::Signal* signal) {
133 DCHECK(signal);
134 dbus::MessageReader reader(signal);
135 dbus::ObjectPath object_path;
136 if (!reader.PopObjectPath(&object_path)) {
137 LOG(WARNING) << "AdapterRemoved signal has incorrect parameters: "
138 << signal->ToString();
139 return;
140 }
141 VLOG(1) << "Adapter removed: " << object_path.value();
142 FOR_EACH_OBSERVER(Observer, observers_, AdapterRemoved(object_path));
143 }
144
145 // Called by dbus:: when the "AdapterAdded" signal is initially connected.
146 void AdapterRemovedConnected(const std::string& interface_name,
147 const std::string& signal_name,
148 bool success) {
149 LOG_IF(WARNING, !success) << "Failed to connect to AdapterRemoved signal.";
150 }
151
152 // D-Bus proxy for neard Manager interface.
153 dbus::ObjectProxy* object_proxy_;
154
155 // Properties for neard Manager interface.
156 std::unique_ptr<Properties> properties_;
157
158 // List of observers interested in event notifications.
159 base::ObserverList<NfcManagerClient::Observer> observers_;
160
161 // Weak pointer factory for generating 'this' pointers that might live longer
162 // than we do.
163 // Note: This should remain the last member so it'll be destroyed and
164 // invalidate its weak pointers before any other members are destroyed.
165 base::WeakPtrFactory<NfcManagerClientImpl> weak_ptr_factory_;
166
167 DISALLOW_COPY_AND_ASSIGN(NfcManagerClientImpl);
168 };
169
170 NfcManagerClient::NfcManagerClient() {
171 }
172
173 NfcManagerClient::~NfcManagerClient() {
174 }
175
176 // static
177 NfcManagerClient* NfcManagerClient::Create() {
178 return new NfcManagerClientImpl();
179 }
180
181 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/dbus/nfc_manager_client.h ('k') | chromeos/dbus/nfc_property_set.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698