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

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

Issue 893663002: Enhance the DBus interface for peerd (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix minor nits Created 5 years, 10 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/peer_daemon_manager_client.h ('k') | dbus/property.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chromeos/dbus/peer_daemon_manager_client.h" 5 #include "chromeos/dbus/peer_daemon_manager_client.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/weak_ptr.h" 10 #include "base/memory/weak_ptr.h"
11 #include "base/message_loop/message_loop.h"
12 #include "base/observer_list.h"
11 #include "dbus/bus.h" 13 #include "dbus/bus.h"
12 #include "dbus/message.h" 14 #include "dbus/message.h"
15 #include "dbus/object_manager.h"
13 #include "dbus/object_proxy.h" 16 #include "dbus/object_proxy.h"
14 #include "dbus/values_util.h" 17 #include "dbus/values_util.h"
15 18
16 namespace chromeos { 19 namespace chromeos {
17 namespace { 20 namespace {
18 21
19 // TODO(benchan): Move these constants to system_api. 22 // TODO(benchan): Move these constants to system_api.
20 namespace peerd { 23 namespace peerd {
21 const char kPeerdServiceName[] = "org.chromium.peerd"; 24 const char kPeerdServiceName[] = "org.chromium.peerd";
25 const char kPeerdObjectManagerServicePath[] = "/org/chromium/peerd";
22 const char kPeerdManagerPath[] = "/org/chromium/peerd/Manager"; 26 const char kPeerdManagerPath[] = "/org/chromium/peerd/Manager";
23 const char kManagerInterface[] = "org.chromium.peerd.Manager"; 27 const char kManagerInterface[] = "org.chromium.peerd.Manager";
28 const char kServiceInterface[] = "org.chromium.peerd.Service";
29 const char kPeerInterface[] = "org.chromium.peerd.Peer";
24 const char kStartMonitoringMethod[] = "StartMonitoring"; 30 const char kStartMonitoringMethod[] = "StartMonitoring";
25 const char kStopMonitoringMethod[] = "StopMonitoring"; 31 const char kStopMonitoringMethod[] = "StopMonitoring";
26 const char kExposeServiceMethod[] = "ExposeService"; 32 const char kExposeServiceMethod[] = "ExposeService";
27 const char kRemoveExposedServiceMethod[] = "RemoveExposedService"; 33 const char kRemoveExposedServiceMethod[] = "RemoveExposedService";
28 const char kPingMethod[] = "Ping"; 34 const char kPingMethod[] = "Ping";
29 } // namespace peerd 35 } // namespace peerd
30 36
31 // The PeerDaemonManagerClient implementation used in production. 37 // The PeerDaemonManagerClient implementation used in production.
32 class PeerDaemonManagerClientImpl : public PeerDaemonManagerClient { 38 class PeerDaemonManagerClientImpl : public PeerDaemonManagerClient,
39 public dbus::ObjectManager::Interface {
33 public: 40 public:
34 PeerDaemonManagerClientImpl(); 41 PeerDaemonManagerClientImpl();
35 ~PeerDaemonManagerClientImpl() override; 42 ~PeerDaemonManagerClientImpl() override;
36 43
37 // DBusClient overrides: 44 // DBusClient overrides.
38 void Init(dbus::Bus* bus) override; 45 void Init(dbus::Bus* bus) override;
39 46
40 // PeerDaemonManagerClient overrides: 47 // PeerDaemonManagerClient overrides.
48 void AddObserver(Observer* observer) override;
49 void RemoveObserver(Observer* observer) override;
50 std::vector<dbus::ObjectPath> GetServices() override;
51 std::vector<dbus::ObjectPath> GetPeers() override;
52 ServiceProperties* GetServiceProperties(
53 const dbus::ObjectPath& object_path) override;
54 PeerProperties* GetPeerProperties(
55 const dbus::ObjectPath& object_path) override;
41 void StartMonitoring( 56 void StartMonitoring(
42 const std::vector<std::string>& requested_technologies, 57 const std::vector<std::string>& requested_technologies,
43 const base::DictionaryValue& options, 58 const base::DictionaryValue& options,
44 const StringDBusMethodCallback& callback) override; 59 const StringDBusMethodCallback& callback) override;
45 void StopMonitoring(const std::string& monitoring_token, 60 void StopMonitoring(const std::string& monitoring_token,
46 const VoidDBusMethodCallback& callback) override; 61 const VoidDBusMethodCallback& callback) override;
47 void ExposeService( 62 void ExposeService(
48 const std::string& service_id, 63 const std::string& service_id,
49 const std::map<std::string, std::string>& service_info, 64 const std::map<std::string, std::string>& service_info,
50 const base::DictionaryValue& options, 65 const base::DictionaryValue& options,
51 const StringDBusMethodCallback& callback) override; 66 const StringDBusMethodCallback& callback) override;
52 void RemoveExposedService(const std::string& service_token, 67 void RemoveExposedService(const std::string& service_token,
53 const VoidDBusMethodCallback& callback) override; 68 const VoidDBusMethodCallback& callback) override;
54 void Ping(const StringDBusMethodCallback& callback) override; 69 void Ping(const StringDBusMethodCallback& callback) override;
55 70
71 // dbus::ObjectManager::Interface overrides.
72 dbus::PropertySet* CreateProperties(
73 dbus::ObjectProxy* object_proxy,
74 const dbus::ObjectPath& object_path,
75 const std::string& interface_name) override;
76 void ObjectAdded(const dbus::ObjectPath& object_path,
77 const std::string& interface_name) override;
78 void ObjectRemoved(const dbus::ObjectPath& object_path,
79 const std::string& interface_name) override;
80
56 private: 81 private:
57 void OnStringDBusMethod(const StringDBusMethodCallback& callback, 82 void OnStringDBusMethod(const StringDBusMethodCallback& callback,
58 dbus::Response* response); 83 dbus::Response* response);
59 void OnVoidDBusMethod(const VoidDBusMethodCallback& callback, 84 void OnVoidDBusMethod(const VoidDBusMethodCallback& callback,
60 dbus::Response* response); 85 dbus::Response* response);
86 void OnManagerPropertyChanged(const std::string& property_name);
87 void OnServicePropertyChanged(const dbus::ObjectPath& object_path,
88 const std::string& property_name);
89 void OnPeerPropertyChanged(const dbus::ObjectPath& object_path,
90 const std::string& property_name);
61 91
62 dbus::ObjectProxy* peer_daemon_proxy_; 92 // List of observers interested in event notifications from us.
93 ObserverList<Observer> observers_;
94 dbus::ObjectManager* object_manager_;
95
63 base::WeakPtrFactory<PeerDaemonManagerClientImpl> weak_ptr_factory_; 96 base::WeakPtrFactory<PeerDaemonManagerClientImpl> weak_ptr_factory_;
64 97
65 DISALLOW_COPY_AND_ASSIGN(PeerDaemonManagerClientImpl); 98 DISALLOW_COPY_AND_ASSIGN(PeerDaemonManagerClientImpl);
66 }; 99 };
67 100
68 PeerDaemonManagerClientImpl::PeerDaemonManagerClientImpl() 101 PeerDaemonManagerClientImpl::PeerDaemonManagerClientImpl()
69 : peer_daemon_proxy_(nullptr), weak_ptr_factory_(this) { 102 : object_manager_(nullptr), weak_ptr_factory_(this) {
70 } 103 }
71 104
72 PeerDaemonManagerClientImpl::~PeerDaemonManagerClientImpl() { 105 PeerDaemonManagerClientImpl::~PeerDaemonManagerClientImpl() {
106 if (object_manager_) {
107 object_manager_->UnregisterInterface(peerd::kManagerInterface);
108 object_manager_->UnregisterInterface(peerd::kServiceInterface);
109 object_manager_->UnregisterInterface(peerd::kPeerInterface);
110 }
111 }
112
113 void PeerDaemonManagerClientImpl::AddObserver(Observer* observer) {
114 DCHECK(observer);
115 observers_.AddObserver(observer);
116 }
117
118 void PeerDaemonManagerClientImpl::RemoveObserver(Observer* observer) {
119 DCHECK(observer);
120 observers_.RemoveObserver(observer);
121 }
122
123 std::vector<dbus::ObjectPath> PeerDaemonManagerClientImpl::GetServices() {
124 return object_manager_->GetObjectsWithInterface(peerd::kServiceInterface);
125 }
126
127 std::vector<dbus::ObjectPath> PeerDaemonManagerClientImpl::GetPeers() {
128 return object_manager_->GetObjectsWithInterface(peerd::kPeerInterface);
129 }
130
131 PeerDaemonManagerClient::ServiceProperties*
132 PeerDaemonManagerClientImpl::GetServiceProperties(
133 const dbus::ObjectPath& object_path) {
134 return static_cast<ServiceProperties*>(
135 object_manager_->GetProperties(object_path, peerd::kServiceInterface));
136 }
137
138 PeerDaemonManagerClient::PeerProperties*
139 PeerDaemonManagerClientImpl::GetPeerProperties(
140 const dbus::ObjectPath& object_path) {
141 return static_cast<PeerProperties*>(
142 object_manager_->GetProperties(object_path, peerd::kPeerInterface));
73 } 143 }
74 144
75 void PeerDaemonManagerClientImpl::StartMonitoring( 145 void PeerDaemonManagerClientImpl::StartMonitoring(
76 const std::vector<std::string>& requested_technologies, 146 const std::vector<std::string>& requested_technologies,
77 const base::DictionaryValue& options, 147 const base::DictionaryValue& options,
78 const StringDBusMethodCallback& callback) { 148 const StringDBusMethodCallback& callback) {
149 dbus::ObjectProxy* object_proxy = object_manager_->GetObjectProxy(
150 dbus::ObjectPath(peerd::kPeerdManagerPath));
151 if (!object_proxy) {
152 base::MessageLoop::current()->PostTask(
153 FROM_HERE,
154 base::Bind(&PeerDaemonManagerClientImpl::OnStringDBusMethod,
155 weak_ptr_factory_.GetWeakPtr(), callback, nullptr));
156 return;
157 }
158
79 dbus::MethodCall method_call(peerd::kManagerInterface, 159 dbus::MethodCall method_call(peerd::kManagerInterface,
80 peerd::kStartMonitoringMethod); 160 peerd::kStartMonitoringMethod);
81 dbus::MessageWriter writer(&method_call); 161 dbus::MessageWriter writer(&method_call);
82 writer.AppendArrayOfStrings(requested_technologies); 162 writer.AppendArrayOfStrings(requested_technologies);
83 dbus::AppendValueData(&writer, options); 163 dbus::AppendValueData(&writer, options);
84 peer_daemon_proxy_->CallMethod( 164 object_proxy->CallMethod(
85 &method_call, 165 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
86 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
87 base::Bind(&PeerDaemonManagerClientImpl::OnStringDBusMethod, 166 base::Bind(&PeerDaemonManagerClientImpl::OnStringDBusMethod,
88 weak_ptr_factory_.GetWeakPtr(), 167 weak_ptr_factory_.GetWeakPtr(), callback));
89 callback));
90 } 168 }
91 169
92 void PeerDaemonManagerClientImpl::StopMonitoring( 170 void PeerDaemonManagerClientImpl::StopMonitoring(
93 const std::string& monitoring_token, 171 const std::string& monitoring_token,
94 const VoidDBusMethodCallback& callback) { 172 const VoidDBusMethodCallback& callback) {
173 dbus::ObjectProxy* object_proxy = object_manager_->GetObjectProxy(
174 dbus::ObjectPath(peerd::kPeerdManagerPath));
175 if (!object_proxy) {
176 base::MessageLoop::current()->PostTask(
177 FROM_HERE,
178 base::Bind(&PeerDaemonManagerClientImpl::OnVoidDBusMethod,
179 weak_ptr_factory_.GetWeakPtr(), callback, nullptr));
180 return;
181 }
182
95 dbus::MethodCall method_call(peerd::kManagerInterface, 183 dbus::MethodCall method_call(peerd::kManagerInterface,
96 peerd::kStopMonitoringMethod); 184 peerd::kStopMonitoringMethod);
97 dbus::MessageWriter writer(&method_call); 185 dbus::MessageWriter writer(&method_call);
98 writer.AppendString(monitoring_token); 186 writer.AppendString(monitoring_token);
99 peer_daemon_proxy_->CallMethod( 187 object_proxy->CallMethod(
100 &method_call, 188 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
101 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
102 base::Bind(&PeerDaemonManagerClientImpl::OnVoidDBusMethod, 189 base::Bind(&PeerDaemonManagerClientImpl::OnVoidDBusMethod,
103 weak_ptr_factory_.GetWeakPtr(), 190 weak_ptr_factory_.GetWeakPtr(), callback));
104 callback));
105 } 191 }
106 192
107 void PeerDaemonManagerClientImpl::ExposeService( 193 void PeerDaemonManagerClientImpl::ExposeService(
108 const std::string& service_id, 194 const std::string& service_id,
109 const std::map<std::string, std::string>& service_info, 195 const std::map<std::string, std::string>& service_info,
110 const base::DictionaryValue& options, 196 const base::DictionaryValue& options,
111 const StringDBusMethodCallback& callback) { 197 const StringDBusMethodCallback& callback) {
198 dbus::ObjectProxy* object_proxy = object_manager_->GetObjectProxy(
199 dbus::ObjectPath(peerd::kPeerdManagerPath));
200 if (!object_proxy) {
201 base::MessageLoop::current()->PostTask(
202 FROM_HERE,
203 base::Bind(&PeerDaemonManagerClientImpl::OnStringDBusMethod,
204 weak_ptr_factory_.GetWeakPtr(), callback, nullptr));
205 return;
206 }
207
112 dbus::MethodCall method_call(peerd::kManagerInterface, 208 dbus::MethodCall method_call(peerd::kManagerInterface,
113 peerd::kExposeServiceMethod); 209 peerd::kExposeServiceMethod);
114 dbus::MessageWriter writer(&method_call); 210 dbus::MessageWriter writer(&method_call);
115 writer.AppendString(service_id); 211 writer.AppendString(service_id);
116 212
117 dbus::MessageWriter array_writer(nullptr); 213 dbus::MessageWriter array_writer(nullptr);
118 writer.OpenArray("{ss}", &array_writer); 214 writer.OpenArray("{ss}", &array_writer);
119 for (const auto& entry : service_info) { 215 for (const auto& entry : service_info) {
120 dbus::MessageWriter dict_entry_writer(nullptr); 216 dbus::MessageWriter dict_entry_writer(nullptr);
121 array_writer.OpenDictEntry(&dict_entry_writer); 217 array_writer.OpenDictEntry(&dict_entry_writer);
122 dict_entry_writer.AppendString(entry.first); 218 dict_entry_writer.AppendString(entry.first);
123 dict_entry_writer.AppendString(entry.second); 219 dict_entry_writer.AppendString(entry.second);
124 array_writer.CloseContainer(&dict_entry_writer); 220 array_writer.CloseContainer(&dict_entry_writer);
125 } 221 }
126 writer.CloseContainer(&array_writer); 222 writer.CloseContainer(&array_writer);
127 223
128 dbus::AppendValueData(&writer, options); 224 dbus::AppendValueData(&writer, options);
129 peer_daemon_proxy_->CallMethod( 225 object_proxy->CallMethod(
130 &method_call, 226 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
131 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
132 base::Bind(&PeerDaemonManagerClientImpl::OnStringDBusMethod, 227 base::Bind(&PeerDaemonManagerClientImpl::OnStringDBusMethod,
133 weak_ptr_factory_.GetWeakPtr(), 228 weak_ptr_factory_.GetWeakPtr(), callback));
134 callback));
135 } 229 }
136 230
137 void PeerDaemonManagerClientImpl::RemoveExposedService( 231 void PeerDaemonManagerClientImpl::RemoveExposedService(
138 const std::string& service_token, 232 const std::string& service_token,
139 const VoidDBusMethodCallback& callback) { 233 const VoidDBusMethodCallback& callback) {
140 dbus::MethodCall method_call(peerd::kManagerInterface, 234 dbus::MethodCall method_call(peerd::kManagerInterface,
141 peerd::kRemoveExposedServiceMethod); 235 peerd::kRemoveExposedServiceMethod);
236 dbus::ObjectProxy* object_proxy = object_manager_->GetObjectProxy(
237 dbus::ObjectPath(peerd::kPeerdManagerPath));
238 if (!object_proxy) {
239 base::MessageLoop::current()->PostTask(
240 FROM_HERE,
241 base::Bind(&PeerDaemonManagerClientImpl::OnVoidDBusMethod,
242 weak_ptr_factory_.GetWeakPtr(), callback, nullptr));
243 return;
244 }
142 dbus::MessageWriter writer(&method_call); 245 dbus::MessageWriter writer(&method_call);
143 writer.AppendString(service_token); 246 writer.AppendString(service_token);
144 peer_daemon_proxy_->CallMethod( 247 object_proxy->CallMethod(
145 &method_call, 248 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
146 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
147 base::Bind(&PeerDaemonManagerClientImpl::OnVoidDBusMethod, 249 base::Bind(&PeerDaemonManagerClientImpl::OnVoidDBusMethod,
148 weak_ptr_factory_.GetWeakPtr(), 250 weak_ptr_factory_.GetWeakPtr(), callback));
149 callback));
150 } 251 }
151 252
152 void PeerDaemonManagerClientImpl::Ping( 253 void PeerDaemonManagerClientImpl::Ping(
153 const StringDBusMethodCallback& callback) { 254 const StringDBusMethodCallback& callback) {
154 dbus::MethodCall method_call(peerd::kManagerInterface, 255 dbus::MethodCall method_call(peerd::kManagerInterface,
155 peerd::kPingMethod); 256 peerd::kPingMethod);
257 dbus::ObjectProxy* object_proxy = object_manager_->GetObjectProxy(
258 dbus::ObjectPath(peerd::kPeerdManagerPath));
259 if (!object_proxy) {
260 base::MessageLoop::current()->PostTask(
261 FROM_HERE,
262 base::Bind(&PeerDaemonManagerClientImpl::OnStringDBusMethod,
263 weak_ptr_factory_.GetWeakPtr(), callback, nullptr));
264 return;
265 }
156 dbus::MessageWriter writer(&method_call); 266 dbus::MessageWriter writer(&method_call);
157 peer_daemon_proxy_->CallMethod( 267 object_proxy->CallMethod(
158 &method_call, 268 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
159 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
160 base::Bind(&PeerDaemonManagerClientImpl::OnStringDBusMethod, 269 base::Bind(&PeerDaemonManagerClientImpl::OnStringDBusMethod,
161 weak_ptr_factory_.GetWeakPtr(), 270 weak_ptr_factory_.GetWeakPtr(), callback));
162 callback)); 271 }
272
273 dbus::PropertySet* PeerDaemonManagerClientImpl::CreateProperties(
274 dbus::ObjectProxy* object_proxy,
275 const dbus::ObjectPath& object_path,
276 const std::string& interface_name) {
277 dbus::PropertySet* properties = nullptr;
278 if (interface_name == peerd::kManagerInterface) {
279 properties = new ManagerProperties(
280 object_proxy,
281 base::Bind(&PeerDaemonManagerClientImpl::OnManagerPropertyChanged,
282 weak_ptr_factory_.GetWeakPtr()));
283 } else if (interface_name == peerd::kServiceInterface) {
284 properties = new ServiceProperties(
285 object_proxy,
286 base::Bind(&PeerDaemonManagerClientImpl::OnServicePropertyChanged,
287 weak_ptr_factory_.GetWeakPtr(), object_path));
288 } else if (interface_name == peerd::kPeerInterface) {
289 properties = new PeerProperties(
290 object_proxy,
291 base::Bind(&PeerDaemonManagerClientImpl::OnPeerPropertyChanged,
292 weak_ptr_factory_.GetWeakPtr(), object_path));
293 } else {
294 NOTREACHED() << "Unhandled interface name " << interface_name;
295 }
296 return properties;
297 }
298
299 void PeerDaemonManagerClientImpl::ObjectAdded(
300 const dbus::ObjectPath& object_path,
301 const std::string& interface_name) {
302 if (interface_name == peerd::kManagerInterface) {
303 FOR_EACH_OBSERVER(Observer, observers_, ManagerAdded());
304 } else if (interface_name == peerd::kServiceInterface) {
305 FOR_EACH_OBSERVER(Observer, observers_, ServiceAdded(object_path));
306 } else if (interface_name == peerd::kPeerInterface) {
307 FOR_EACH_OBSERVER(Observer, observers_, PeerAdded(object_path));
308 } else {
309 NOTREACHED() << "Unhandled interface name " << interface_name;
310 }
311 }
312
313 void PeerDaemonManagerClientImpl::ObjectRemoved(
314 const dbus::ObjectPath& object_path,
315 const std::string& interface_name) {
316 if (interface_name == peerd::kManagerInterface) {
317 FOR_EACH_OBSERVER(Observer, observers_, ManagerRemoved());
318 } else if (interface_name == peerd::kServiceInterface) {
319 FOR_EACH_OBSERVER(Observer, observers_, ServiceRemoved(object_path));
320 } else if (interface_name == peerd::kPeerInterface) {
321 FOR_EACH_OBSERVER(Observer, observers_, PeerRemoved(object_path));
322 } else {
323 NOTREACHED() << "Unhandled interface name " << interface_name;
324 }
163 } 325 }
164 326
165 void PeerDaemonManagerClientImpl::OnStringDBusMethod( 327 void PeerDaemonManagerClientImpl::OnStringDBusMethod(
166 const StringDBusMethodCallback& callback, 328 const StringDBusMethodCallback& callback,
167 dbus::Response* response) { 329 dbus::Response* response) {
168 if (!response) { 330 if (!response) {
169 callback.Run(DBUS_METHOD_CALL_FAILURE, std::string()); 331 callback.Run(DBUS_METHOD_CALL_FAILURE, std::string());
170 return; 332 return;
171 } 333 }
172 334
173 dbus::MessageReader reader(response); 335 dbus::MessageReader reader(response);
174 std::string result; 336 std::string result;
175 if (!reader.PopString(&result)) { 337 if (!reader.PopString(&result)) {
176 callback.Run(DBUS_METHOD_CALL_FAILURE, std::string()); 338 callback.Run(DBUS_METHOD_CALL_FAILURE, std::string());
177 return; 339 return;
178 } 340 }
179 341
180 callback.Run(DBUS_METHOD_CALL_SUCCESS, result); 342 callback.Run(DBUS_METHOD_CALL_SUCCESS, result);
181 } 343 }
182 344
183 void PeerDaemonManagerClientImpl::OnVoidDBusMethod( 345 void PeerDaemonManagerClientImpl::OnVoidDBusMethod(
184 const VoidDBusMethodCallback& callback, 346 const VoidDBusMethodCallback& callback,
185 dbus::Response* response) { 347 dbus::Response* response) {
186 callback.Run(response ? DBUS_METHOD_CALL_SUCCESS : DBUS_METHOD_CALL_FAILURE); 348 callback.Run(response ? DBUS_METHOD_CALL_SUCCESS : DBUS_METHOD_CALL_FAILURE);
187 } 349 }
188 350
189 void PeerDaemonManagerClientImpl::Init(dbus::Bus* bus) { 351 void PeerDaemonManagerClientImpl::Init(dbus::Bus* bus) {
190 peer_daemon_proxy_ = 352 object_manager_ = bus->GetObjectManager(
191 bus->GetObjectProxy(peerd::kPeerdServiceName, 353 peerd::kPeerdServiceName,
192 dbus::ObjectPath(peerd::kPeerdManagerPath)); 354 dbus::ObjectPath(peerd::kPeerdObjectManagerServicePath));
355 object_manager_->RegisterInterface(peerd::kManagerInterface, this);
356 object_manager_->RegisterInterface(peerd::kServiceInterface, this);
357 object_manager_->RegisterInterface(peerd::kPeerInterface, this);
358 }
359
360 void PeerDaemonManagerClientImpl::OnManagerPropertyChanged(
361 const std::string& property_name) {
362 FOR_EACH_OBSERVER(Observer, observers_,
363 ManagerPropertyChanged(property_name));
364 }
365
366 void PeerDaemonManagerClientImpl::OnServicePropertyChanged(
367 const dbus::ObjectPath& object_path,
368 const std::string& property_name) {
369 FOR_EACH_OBSERVER(Observer, observers_,
370 ServicePropertyChanged(object_path, property_name));
371 }
372
373 void PeerDaemonManagerClientImpl::OnPeerPropertyChanged(
374 const dbus::ObjectPath& object_path,
375 const std::string& property_name) {
376 FOR_EACH_OBSERVER(Observer, observers_,
377 PeerPropertyChanged(object_path, property_name));
193 } 378 }
194 379
195 } // namespace 380 } // namespace
196 381
382 PeerDaemonManagerClient::ManagerProperties::ManagerProperties(
383 dbus::ObjectProxy* object_proxy,
384 const PropertyChangedCallback& callback)
385 : dbus::PropertySet{object_proxy, peerd::kManagerInterface, callback} {
386 RegisterProperty("MonitoredTechnologies", &monitored_technologies_);
387 }
388
389 PeerDaemonManagerClient::ManagerProperties::~ManagerProperties() {
390 }
391
392 PeerDaemonManagerClient::ServiceProperties::ServiceProperties(
393 dbus::ObjectProxy* object_proxy,
394 const PropertyChangedCallback& callback)
395 : dbus::PropertySet{object_proxy, peerd::kServiceInterface, callback} {
396 RegisterProperty("ServiceId", &service_id_);
397 RegisterProperty("ServiceInfo", &service_info_);
398 RegisterProperty("IpInfos", &ip_infos_);
399 }
400
401 PeerDaemonManagerClient::ServiceProperties::~ServiceProperties() {
402 }
403
404 PeerDaemonManagerClient::PeerProperties::PeerProperties(
405 dbus::ObjectProxy* object_proxy,
406 const PropertyChangedCallback& callback)
407 : dbus::PropertySet{object_proxy, peerd::kPeerInterface, callback} {
408 RegisterProperty("UUID", &uuid_);
409 RegisterProperty("LastSeen", &last_seen_);
410 }
411
412 PeerDaemonManagerClient::PeerProperties::~PeerProperties() {
413 }
197 414
198 PeerDaemonManagerClient::PeerDaemonManagerClient() { 415 PeerDaemonManagerClient::PeerDaemonManagerClient() {
199 } 416 }
200 417
201 PeerDaemonManagerClient::~PeerDaemonManagerClient() { 418 PeerDaemonManagerClient::~PeerDaemonManagerClient() {
202 } 419 }
203 420
204 // static 421 // static
205 PeerDaemonManagerClient* PeerDaemonManagerClient::Create() { 422 PeerDaemonManagerClient* PeerDaemonManagerClient::Create() {
206 return new PeerDaemonManagerClientImpl(); 423 return new PeerDaemonManagerClientImpl();
207 } 424 }
208 425
209 } // namespace chromeos 426 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/dbus/peer_daemon_manager_client.h ('k') | dbus/property.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698