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

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: Address comments from patch 1 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
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> GetPeers() override;
51 std::vector<dbus::ObjectPath> GetServices() override;
52 PeerProperties* GetPeerProperties(
53 const dbus::ObjectPath& object_path) override;
54 ServiceProperties* GetServiceProperties(
55 const dbus::ObjectPath& object_path) override;
hashimoto 2015/02/06 07:45:11 nit: Please put these overrides in the same order
dtapuska 2015/02/06 15:56:00 Done... Manager, Service, Peer should be the order
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 OnPeerPropertyChanged(const dbus::ObjectPath& object_path,
hashimoto 2015/02/06 07:45:11 nit: Please stick exclusively to one ordering, Man
dtapuska 2015/02/06 15:56:00 Done.
88 const std::string& property_name);
89 void OnServicePropertyChanged(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::kPeerInterface);
109 object_manager_->UnregisterInterface(peerd::kServiceInterface);
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::GetPeers() {
124 return object_manager_->GetObjectsWithInterface(peerd::kPeerInterface);
125 }
126
127 std::vector<dbus::ObjectPath> PeerDaemonManagerClientImpl::GetServices() {
128 return object_manager_->GetObjectsWithInterface(peerd::kServiceInterface);
129 }
130
131 PeerDaemonManagerClient::PeerProperties*
132 PeerDaemonManagerClientImpl::GetPeerProperties(
133 const dbus::ObjectPath& object_path) {
134 return static_cast<PeerProperties*>(
135 object_manager_->GetProperties(object_path, peerd::kPeerInterface));
136 }
137
138 PeerDaemonManagerClient::ServiceProperties*
139 PeerDaemonManagerClientImpl::GetServiceProperties(
140 const dbus::ObjectPath& object_path) {
141 return static_cast<ServiceProperties*>(
142 object_manager_->GetProperties(object_path, peerd::kServiceInterface));
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 callback.Run(DBUS_METHOD_CALL_FAILURE, "");
hashimoto 2015/02/06 07:45:12 Please PostTask() here and use std::string(). The
dtapuska 2015/02/06 15:56:00 Done.
202 return;
203 }
204
112 dbus::MethodCall method_call(peerd::kManagerInterface, 205 dbus::MethodCall method_call(peerd::kManagerInterface,
113 peerd::kExposeServiceMethod); 206 peerd::kExposeServiceMethod);
114 dbus::MessageWriter writer(&method_call); 207 dbus::MessageWriter writer(&method_call);
115 writer.AppendString(service_id); 208 writer.AppendString(service_id);
116 209
117 dbus::MessageWriter array_writer(nullptr); 210 dbus::MessageWriter array_writer(nullptr);
118 writer.OpenArray("{ss}", &array_writer); 211 writer.OpenArray("{ss}", &array_writer);
119 for (const auto& entry : service_info) { 212 for (const auto& entry : service_info) {
120 dbus::MessageWriter dict_entry_writer(nullptr); 213 dbus::MessageWriter dict_entry_writer(nullptr);
121 array_writer.OpenDictEntry(&dict_entry_writer); 214 array_writer.OpenDictEntry(&dict_entry_writer);
122 dict_entry_writer.AppendString(entry.first); 215 dict_entry_writer.AppendString(entry.first);
123 dict_entry_writer.AppendString(entry.second); 216 dict_entry_writer.AppendString(entry.second);
124 array_writer.CloseContainer(&dict_entry_writer); 217 array_writer.CloseContainer(&dict_entry_writer);
125 } 218 }
126 writer.CloseContainer(&array_writer); 219 writer.CloseContainer(&array_writer);
127 220
128 dbus::AppendValueData(&writer, options); 221 dbus::AppendValueData(&writer, options);
129 peer_daemon_proxy_->CallMethod( 222 object_proxy->CallMethod(
130 &method_call, 223 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
131 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
132 base::Bind(&PeerDaemonManagerClientImpl::OnStringDBusMethod, 224 base::Bind(&PeerDaemonManagerClientImpl::OnStringDBusMethod,
133 weak_ptr_factory_.GetWeakPtr(), 225 weak_ptr_factory_.GetWeakPtr(), callback));
134 callback));
135 } 226 }
136 227
137 void PeerDaemonManagerClientImpl::RemoveExposedService( 228 void PeerDaemonManagerClientImpl::RemoveExposedService(
138 const std::string& service_token, 229 const std::string& service_token,
139 const VoidDBusMethodCallback& callback) { 230 const VoidDBusMethodCallback& callback) {
140 dbus::MethodCall method_call(peerd::kManagerInterface, 231 dbus::MethodCall method_call(peerd::kManagerInterface,
141 peerd::kRemoveExposedServiceMethod); 232 peerd::kRemoveExposedServiceMethod);
233 dbus::ObjectProxy* object_proxy = object_manager_->GetObjectProxy(
234 dbus::ObjectPath(peerd::kPeerdManagerPath));
235 if (!object_proxy) {
236 callback.Run(DBUS_METHOD_CALL_FAILURE);
237 return;
238 }
142 dbus::MessageWriter writer(&method_call); 239 dbus::MessageWriter writer(&method_call);
143 writer.AppendString(service_token); 240 writer.AppendString(service_token);
144 peer_daemon_proxy_->CallMethod( 241 object_proxy->CallMethod(
145 &method_call, 242 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
146 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
147 base::Bind(&PeerDaemonManagerClientImpl::OnVoidDBusMethod, 243 base::Bind(&PeerDaemonManagerClientImpl::OnVoidDBusMethod,
148 weak_ptr_factory_.GetWeakPtr(), 244 weak_ptr_factory_.GetWeakPtr(), callback));
149 callback));
150 } 245 }
151 246
152 void PeerDaemonManagerClientImpl::Ping( 247 void PeerDaemonManagerClientImpl::Ping(
153 const StringDBusMethodCallback& callback) { 248 const StringDBusMethodCallback& callback) {
154 dbus::MethodCall method_call(peerd::kManagerInterface, 249 dbus::MethodCall method_call(peerd::kManagerInterface,
155 peerd::kPingMethod); 250 peerd::kPingMethod);
251 dbus::ObjectProxy* object_proxy = object_manager_->GetObjectProxy(
252 dbus::ObjectPath(peerd::kPeerdManagerPath));
253 if (!object_proxy) {
254 callback.Run(DBUS_METHOD_CALL_FAILURE, "");
255 return;
256 }
156 dbus::MessageWriter writer(&method_call); 257 dbus::MessageWriter writer(&method_call);
157 peer_daemon_proxy_->CallMethod( 258 object_proxy->CallMethod(
158 &method_call, 259 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
159 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
160 base::Bind(&PeerDaemonManagerClientImpl::OnStringDBusMethod, 260 base::Bind(&PeerDaemonManagerClientImpl::OnStringDBusMethod,
161 weak_ptr_factory_.GetWeakPtr(), 261 weak_ptr_factory_.GetWeakPtr(), callback));
162 callback)); 262 }
263
264 dbus::PropertySet* PeerDaemonManagerClientImpl::CreateProperties(
265 dbus::ObjectProxy* object_proxy,
266 const dbus::ObjectPath& object_path,
267 const std::string& interface_name) {
268 dbus::PropertySet* properties = nullptr;
269 if (interface_name == peerd::kManagerInterface) {
270 properties = new ManagerProperties(
271 object_proxy,
272 base::Bind(&PeerDaemonManagerClientImpl::OnManagerPropertyChanged,
273 weak_ptr_factory_.GetWeakPtr()));
274 } else if (interface_name == peerd::kServiceInterface) {
275 properties = new ServiceProperties(
276 object_proxy,
277 base::Bind(&PeerDaemonManagerClientImpl::OnServicePropertyChanged,
278 weak_ptr_factory_.GetWeakPtr(), object_path));
279 } else if (interface_name == peerd::kPeerInterface) {
280 properties = new PeerProperties(
281 object_proxy,
282 base::Bind(&PeerDaemonManagerClientImpl::OnPeerPropertyChanged,
283 weak_ptr_factory_.GetWeakPtr(), object_path));
284 } else {
285 NOTREACHED() << "Unhandled interface name " << interface_name;
286 }
287 return properties;
288 }
289
290 void PeerDaemonManagerClientImpl::ObjectAdded(
291 const dbus::ObjectPath& object_path,
292 const std::string& interface_name) {
293 if (interface_name == peerd::kManagerInterface) {
294 FOR_EACH_OBSERVER(Observer, observers_, ManagerAdded());
295 } else if (interface_name == peerd::kServiceInterface) {
296 FOR_EACH_OBSERVER(Observer, observers_, ServiceAdded(object_path));
297 } else if (interface_name == peerd::kPeerInterface) {
298 FOR_EACH_OBSERVER(Observer, observers_, PeerAdded(object_path));
299 } else {
300 NOTREACHED() << "Unhandled interface name " << interface_name;
301 }
302 }
303
304 void PeerDaemonManagerClientImpl::ObjectRemoved(
305 const dbus::ObjectPath& object_path,
306 const std::string& interface_name) {
307 if (interface_name == peerd::kManagerInterface) {
308 FOR_EACH_OBSERVER(Observer, observers_, ManagerRemoved());
309 } else if (interface_name == peerd::kServiceInterface) {
310 FOR_EACH_OBSERVER(Observer, observers_, ServiceRemoved(object_path));
311 } else if (interface_name == peerd::kPeerInterface) {
312 FOR_EACH_OBSERVER(Observer, observers_, PeerRemoved(object_path));
313 } else {
314 NOTREACHED() << "Unhandled interface name " << interface_name;
315 }
163 } 316 }
164 317
165 void PeerDaemonManagerClientImpl::OnStringDBusMethod( 318 void PeerDaemonManagerClientImpl::OnStringDBusMethod(
166 const StringDBusMethodCallback& callback, 319 const StringDBusMethodCallback& callback,
167 dbus::Response* response) { 320 dbus::Response* response) {
168 if (!response) { 321 if (!response) {
169 callback.Run(DBUS_METHOD_CALL_FAILURE, std::string()); 322 callback.Run(DBUS_METHOD_CALL_FAILURE, std::string());
170 return; 323 return;
171 } 324 }
172 325
173 dbus::MessageReader reader(response); 326 dbus::MessageReader reader(response);
174 std::string result; 327 std::string result;
175 if (!reader.PopString(&result)) { 328 if (!reader.PopString(&result)) {
176 callback.Run(DBUS_METHOD_CALL_FAILURE, std::string()); 329 callback.Run(DBUS_METHOD_CALL_FAILURE, std::string());
177 return; 330 return;
178 } 331 }
179 332
180 callback.Run(DBUS_METHOD_CALL_SUCCESS, result); 333 callback.Run(DBUS_METHOD_CALL_SUCCESS, result);
181 } 334 }
182 335
183 void PeerDaemonManagerClientImpl::OnVoidDBusMethod( 336 void PeerDaemonManagerClientImpl::OnVoidDBusMethod(
184 const VoidDBusMethodCallback& callback, 337 const VoidDBusMethodCallback& callback,
185 dbus::Response* response) { 338 dbus::Response* response) {
186 callback.Run(response ? DBUS_METHOD_CALL_SUCCESS : DBUS_METHOD_CALL_FAILURE); 339 callback.Run(response ? DBUS_METHOD_CALL_SUCCESS : DBUS_METHOD_CALL_FAILURE);
187 } 340 }
188 341
189 void PeerDaemonManagerClientImpl::Init(dbus::Bus* bus) { 342 void PeerDaemonManagerClientImpl::Init(dbus::Bus* bus) {
190 peer_daemon_proxy_ = 343 object_manager_ = bus->GetObjectManager(
191 bus->GetObjectProxy(peerd::kPeerdServiceName, 344 peerd::kPeerdServiceName,
192 dbus::ObjectPath(peerd::kPeerdManagerPath)); 345 dbus::ObjectPath(peerd::kPeerdObjectManagerServicePath));
346 object_manager_->RegisterInterface(peerd::kManagerInterface, this);
347 object_manager_->RegisterInterface(peerd::kPeerInterface, this);
348 object_manager_->RegisterInterface(peerd::kServiceInterface, this);
349 }
350
351 void PeerDaemonManagerClientImpl::OnManagerPropertyChanged(
352 const std::string& property_name) {
353 FOR_EACH_OBSERVER(Observer, observers_,
354 ManagerPropertyChanged(property_name));
355 }
356
357 void PeerDaemonManagerClientImpl::OnPeerPropertyChanged(
358 const dbus::ObjectPath& object_path,
359 const std::string& property_name) {
360 FOR_EACH_OBSERVER(Observer, observers_,
361 PeerPropertyChanged(object_path, property_name));
362 }
363
364 void PeerDaemonManagerClientImpl::OnServicePropertyChanged(
365 const dbus::ObjectPath& object_path,
366 const std::string& property_name) {
367 FOR_EACH_OBSERVER(Observer, observers_,
368 ServicePropertyChanged(object_path, property_name));
193 } 369 }
194 370
195 } // namespace 371 } // namespace
196 372
373 PeerDaemonManagerClient::ManagerProperties::ManagerProperties(
374 dbus::ObjectProxy* object_proxy,
375 const PropertyChangedCallback& callback)
376 : dbus::PropertySet{object_proxy, peerd::kManagerInterface, callback} {
377 RegisterProperty("MonitoredTechnologies", &monitored_technologies);
378 }
379
380 PeerDaemonManagerClient::ManagerProperties::~ManagerProperties() {
381 }
382
383 PeerDaemonManagerClient::PeerProperties::PeerProperties(
hashimoto 2015/02/06 07:45:11 Please put methods in the same order as declared i
dtapuska 2015/02/06 15:56:00 Done.
384 dbus::ObjectProxy* object_proxy,
385 const PropertyChangedCallback& callback)
386 : dbus::PropertySet{object_proxy, peerd::kPeerInterface, callback} {
387 RegisterProperty("UUID", &uuid);
388 RegisterProperty("LastSeen", &last_seen);
389 }
390
391 PeerDaemonManagerClient::PeerProperties::~PeerProperties() {
392 }
393
394 PeerDaemonManagerClient::ServiceProperties::ServiceProperties(
395 dbus::ObjectProxy* object_proxy,
396 const PropertyChangedCallback& callback)
397 : dbus::PropertySet{object_proxy, peerd::kServiceInterface, callback} {
398 RegisterProperty("ServiceId", &service_id);
399 RegisterProperty("ServiceInfo", &service_info);
400 RegisterProperty("IpInfos", &ip_infos);
401 }
402
403 PeerDaemonManagerClient::ServiceProperties::~ServiceProperties() {
404 }
197 405
198 PeerDaemonManagerClient::PeerDaemonManagerClient() { 406 PeerDaemonManagerClient::PeerDaemonManagerClient() {
199 } 407 }
200 408
201 PeerDaemonManagerClient::~PeerDaemonManagerClient() { 409 PeerDaemonManagerClient::~PeerDaemonManagerClient() {
202 } 410 }
203 411
204 // static 412 // static
205 PeerDaemonManagerClient* PeerDaemonManagerClient::Create() { 413 PeerDaemonManagerClient* PeerDaemonManagerClient::Create() {
206 return new PeerDaemonManagerClientImpl(); 414 return new PeerDaemonManagerClientImpl();
207 } 415 }
208 416
209 } // namespace chromeos 417 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/dbus/peer_daemon_manager_client.h ('k') | dbus/property.h » ('j') | dbus/property.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698