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

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: 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/observer_list.h"
11 #include "dbus/bus.h" 12 #include "dbus/bus.h"
12 #include "dbus/message.h" 13 #include "dbus/message.h"
14 #include "dbus/object_manager.h"
13 #include "dbus/object_proxy.h" 15 #include "dbus/object_proxy.h"
14 #include "dbus/values_util.h" 16 #include "dbus/values_util.h"
15 17
16 namespace chromeos { 18 namespace chromeos {
17 namespace {
18 19
19 // TODO(benchan): Move these constants to system_api. 20 // TODO(benchan): Move these constants to system_api.
20 namespace peerd { 21 namespace peerd {
21 const char kPeerdServiceName[] = "org.chromium.peerd"; 22 const char kPeerdServiceName[] = "org.chromium.peerd";
23 const char kPeerdObjectManagerServicePath[] = "/org/chromium/peerd";
22 const char kPeerdManagerPath[] = "/org/chromium/peerd/Manager"; 24 const char kPeerdManagerPath[] = "/org/chromium/peerd/Manager";
23 const char kManagerInterface[] = "org.chromium.peerd.Manager"; 25 const char kManagerInterface[] = "org.chromium.peerd.Manager";
26 const char kPeerInterface[] = "org.chromium.peerd.Peer";
27 const char kServiceInterface[] = "org.chromium.peerd.Service";
hashimoto 2015/02/05 09:51:11 nit: As noted in the header, please be consistent
dtapuska 2015/02/05 19:51:16 Done.
24 const char kStartMonitoringMethod[] = "StartMonitoring"; 28 const char kStartMonitoringMethod[] = "StartMonitoring";
25 const char kStopMonitoringMethod[] = "StopMonitoring"; 29 const char kStopMonitoringMethod[] = "StopMonitoring";
26 const char kExposeServiceMethod[] = "ExposeService"; 30 const char kExposeServiceMethod[] = "ExposeService";
27 const char kRemoveExposedServiceMethod[] = "RemoveExposedService"; 31 const char kRemoveExposedServiceMethod[] = "RemoveExposedService";
28 const char kPingMethod[] = "Ping"; 32 const char kPingMethod[] = "Ping";
29 } // namespace peerd 33 } // namespace peerd
30 34
35 namespace {
hashimoto 2015/02/05 09:51:11 unnamed namespace should start from before string
dtapuska 2015/02/05 19:51:16 Done.
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;
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 override.
hashimoto 2015/02/05 09:51:11 nit: "overrides:" instead of "override." to be con
dtapuska 2015/02/05 19:51:16 Done.
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,
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("org.chromium.leaderd.Manager");
hashimoto 2015/02/05 09:51:11 This code doesn't match with RegisterInterface() c
dtapuska 2015/02/05 19:51:16 Done.
108 object_manager_->UnregisterInterface("org.chromium.leaderd.Group");
109 }
110 }
111
112 void PeerDaemonManagerClientImpl::AddObserver(Observer* observer) {
113 DCHECK(observer);
114 observers_.AddObserver(observer);
115 }
116
117 void PeerDaemonManagerClientImpl::RemoveObserver(Observer* observer) {
118 DCHECK(observer);
119 observers_.RemoveObserver(observer);
120 }
121
122 std::vector<dbus::ObjectPath> PeerDaemonManagerClientImpl::GetPeers() {
123 return object_manager_->GetObjectsWithInterface(peerd::kPeerInterface);
124 }
125
126 std::vector<dbus::ObjectPath> PeerDaemonManagerClientImpl::GetServices() {
127 return object_manager_->GetObjectsWithInterface(peerd::kServiceInterface);
128 }
129
130 PeerDaemonManagerClient::PeerProperties*
131 PeerDaemonManagerClientImpl::GetPeerProperties(
132 const dbus::ObjectPath& object_path) {
133 return static_cast<PeerProperties*>(
134 object_manager_->GetProperties(object_path, peerd::kPeerInterface));
135 }
136
137 PeerDaemonManagerClient::ServiceProperties*
138 PeerDaemonManagerClientImpl::GetServiceProperties(
139 const dbus::ObjectPath& object_path) {
140 return static_cast<ServiceProperties*>(
141 object_manager_->GetProperties(object_path, peerd::kServiceInterface));
73 } 142 }
74 143
75 void PeerDaemonManagerClientImpl::StartMonitoring( 144 void PeerDaemonManagerClientImpl::StartMonitoring(
76 const std::vector<std::string>& requested_technologies, 145 const std::vector<std::string>& requested_technologies,
77 const base::DictionaryValue& options, 146 const base::DictionaryValue& options,
78 const StringDBusMethodCallback& callback) { 147 const StringDBusMethodCallback& callback) {
148 dbus::ObjectProxy* object_proxy = object_manager_->GetObjectProxy(
149 dbus::ObjectPath(peerd::kPeerdManagerPath));
150 if (!object_proxy) {
151 callback.Run(DBUS_METHOD_CALL_FAILURE, "");
hashimoto 2015/02/05 09:51:11 nit: Please use std::string() instead of "" (cf. h
dtapuska 2015/02/05 19:51:16 Done.
152 return;
153 }
154
79 dbus::MethodCall method_call(peerd::kManagerInterface, 155 dbus::MethodCall method_call(peerd::kManagerInterface,
80 peerd::kStartMonitoringMethod); 156 peerd::kStartMonitoringMethod);
81 dbus::MessageWriter writer(&method_call); 157 dbus::MessageWriter writer(&method_call);
82 writer.AppendArrayOfStrings(requested_technologies); 158 writer.AppendArrayOfStrings(requested_technologies);
83 dbus::AppendValueData(&writer, options); 159 dbus::AppendValueData(&writer, options);
84 peer_daemon_proxy_->CallMethod( 160 object_proxy->CallMethod(
85 &method_call, 161 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
86 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
87 base::Bind(&PeerDaemonManagerClientImpl::OnStringDBusMethod, 162 base::Bind(&PeerDaemonManagerClientImpl::OnStringDBusMethod,
88 weak_ptr_factory_.GetWeakPtr(), 163 weak_ptr_factory_.GetWeakPtr(), callback));
89 callback));
90 } 164 }
91 165
92 void PeerDaemonManagerClientImpl::StopMonitoring( 166 void PeerDaemonManagerClientImpl::StopMonitoring(
93 const std::string& monitoring_token, 167 const std::string& monitoring_token,
94 const VoidDBusMethodCallback& callback) { 168 const VoidDBusMethodCallback& callback) {
169 dbus::ObjectProxy* object_proxy = object_manager_->GetObjectProxy(
170 dbus::ObjectPath(peerd::kPeerdManagerPath));
171 if (!object_proxy) {
172 callback.Run(DBUS_METHOD_CALL_FAILURE);
173 return;
174 }
175
95 dbus::MethodCall method_call(peerd::kManagerInterface, 176 dbus::MethodCall method_call(peerd::kManagerInterface,
96 peerd::kStopMonitoringMethod); 177 peerd::kStopMonitoringMethod);
97 dbus::MessageWriter writer(&method_call); 178 dbus::MessageWriter writer(&method_call);
98 writer.AppendString(monitoring_token); 179 writer.AppendString(monitoring_token);
99 peer_daemon_proxy_->CallMethod( 180 object_proxy->CallMethod(
100 &method_call, 181 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
101 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
102 base::Bind(&PeerDaemonManagerClientImpl::OnVoidDBusMethod, 182 base::Bind(&PeerDaemonManagerClientImpl::OnVoidDBusMethod,
103 weak_ptr_factory_.GetWeakPtr(), 183 weak_ptr_factory_.GetWeakPtr(), callback));
104 callback));
105 } 184 }
106 185
107 void PeerDaemonManagerClientImpl::ExposeService( 186 void PeerDaemonManagerClientImpl::ExposeService(
108 const std::string& service_id, 187 const std::string& service_id,
109 const std::map<std::string, std::string>& service_info, 188 const std::map<std::string, std::string>& service_info,
110 const base::DictionaryValue& options, 189 const base::DictionaryValue& options,
111 const StringDBusMethodCallback& callback) { 190 const StringDBusMethodCallback& callback) {
191 dbus::ObjectProxy* object_proxy = object_manager_->GetObjectProxy(
192 dbus::ObjectPath(peerd::kPeerdManagerPath));
193 if (!object_proxy) {
194 callback.Run(DBUS_METHOD_CALL_FAILURE, "");
195 return;
196 }
197
112 dbus::MethodCall method_call(peerd::kManagerInterface, 198 dbus::MethodCall method_call(peerd::kManagerInterface,
113 peerd::kExposeServiceMethod); 199 peerd::kExposeServiceMethod);
114 dbus::MessageWriter writer(&method_call); 200 dbus::MessageWriter writer(&method_call);
115 writer.AppendString(service_id); 201 writer.AppendString(service_id);
116 202
117 dbus::MessageWriter array_writer(nullptr); 203 dbus::MessageWriter array_writer(nullptr);
118 writer.OpenArray("{ss}", &array_writer); 204 writer.OpenArray("{ss}", &array_writer);
119 for (const auto& entry : service_info) { 205 for (const auto& entry : service_info) {
120 dbus::MessageWriter dict_entry_writer(nullptr); 206 dbus::MessageWriter dict_entry_writer(nullptr);
121 array_writer.OpenDictEntry(&dict_entry_writer); 207 array_writer.OpenDictEntry(&dict_entry_writer);
122 dict_entry_writer.AppendString(entry.first); 208 dict_entry_writer.AppendString(entry.first);
123 dict_entry_writer.AppendString(entry.second); 209 dict_entry_writer.AppendString(entry.second);
124 array_writer.CloseContainer(&dict_entry_writer); 210 array_writer.CloseContainer(&dict_entry_writer);
125 } 211 }
126 writer.CloseContainer(&array_writer); 212 writer.CloseContainer(&array_writer);
127 213
128 dbus::AppendValueData(&writer, options); 214 dbus::AppendValueData(&writer, options);
129 peer_daemon_proxy_->CallMethod( 215 object_proxy->CallMethod(
130 &method_call, 216 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
131 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
132 base::Bind(&PeerDaemonManagerClientImpl::OnStringDBusMethod, 217 base::Bind(&PeerDaemonManagerClientImpl::OnStringDBusMethod,
133 weak_ptr_factory_.GetWeakPtr(), 218 weak_ptr_factory_.GetWeakPtr(), callback));
134 callback));
135 } 219 }
136 220
137 void PeerDaemonManagerClientImpl::RemoveExposedService( 221 void PeerDaemonManagerClientImpl::RemoveExposedService(
138 const std::string& service_token, 222 const std::string& service_token,
139 const VoidDBusMethodCallback& callback) { 223 const VoidDBusMethodCallback& callback) {
140 dbus::MethodCall method_call(peerd::kManagerInterface, 224 dbus::MethodCall method_call(peerd::kManagerInterface,
141 peerd::kRemoveExposedServiceMethod); 225 peerd::kRemoveExposedServiceMethod);
226 dbus::ObjectProxy* object_proxy = object_manager_->GetObjectProxy(
227 dbus::ObjectPath(peerd::kPeerdManagerPath));
228 if (!object_proxy) {
229 callback.Run(DBUS_METHOD_CALL_FAILURE);
230 return;
231 }
142 dbus::MessageWriter writer(&method_call); 232 dbus::MessageWriter writer(&method_call);
143 writer.AppendString(service_token); 233 writer.AppendString(service_token);
144 peer_daemon_proxy_->CallMethod( 234 object_proxy->CallMethod(
145 &method_call, 235 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
146 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
147 base::Bind(&PeerDaemonManagerClientImpl::OnVoidDBusMethod, 236 base::Bind(&PeerDaemonManagerClientImpl::OnVoidDBusMethod,
148 weak_ptr_factory_.GetWeakPtr(), 237 weak_ptr_factory_.GetWeakPtr(), callback));
149 callback));
150 } 238 }
151 239
152 void PeerDaemonManagerClientImpl::Ping( 240 void PeerDaemonManagerClientImpl::Ping(
153 const StringDBusMethodCallback& callback) { 241 const StringDBusMethodCallback& callback) {
154 dbus::MethodCall method_call(peerd::kManagerInterface, 242 dbus::MethodCall method_call(peerd::kManagerInterface,
155 peerd::kPingMethod); 243 peerd::kPingMethod);
244 dbus::ObjectProxy* object_proxy = object_manager_->GetObjectProxy(
245 dbus::ObjectPath(peerd::kPeerdManagerPath));
246 if (!object_proxy) {
247 callback.Run(DBUS_METHOD_CALL_FAILURE, "");
248 return;
249 }
156 dbus::MessageWriter writer(&method_call); 250 dbus::MessageWriter writer(&method_call);
157 peer_daemon_proxy_->CallMethod( 251 object_proxy->CallMethod(
158 &method_call, 252 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
159 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
160 base::Bind(&PeerDaemonManagerClientImpl::OnStringDBusMethod, 253 base::Bind(&PeerDaemonManagerClientImpl::OnStringDBusMethod,
161 weak_ptr_factory_.GetWeakPtr(), 254 weak_ptr_factory_.GetWeakPtr(), callback));
162 callback)); 255 }
256
257 dbus::PropertySet* PeerDaemonManagerClientImpl::CreateProperties(
258 dbus::ObjectProxy* object_proxy,
259 const dbus::ObjectPath& object_path,
260 const std::string& interface_name) {
261 dbus::PropertySet* properties = nullptr;
262 if (interface_name == peerd::kManagerInterface) {
263 properties = new ManagerProperties(
264 object_proxy,
265 base::Bind(&PeerDaemonManagerClientImpl::OnManagerPropertyChanged,
266 weak_ptr_factory_.GetWeakPtr()));
267 } else if (interface_name == peerd::kServiceInterface) {
268 properties = new ServiceProperties(
269 object_proxy,
270 base::Bind(&PeerDaemonManagerClientImpl::OnServicePropertyChanged,
271 weak_ptr_factory_.GetWeakPtr(), object_path));
272 } else if (interface_name == peerd::kPeerInterface) {
273 properties = new PeerProperties(
274 object_proxy,
275 base::Bind(&PeerDaemonManagerClientImpl::OnPeerPropertyChanged,
276 weak_ptr_factory_.GetWeakPtr(), object_path));
277 }
hashimoto 2015/02/05 09:51:11 How about leaving a log when interface_name is an
dtapuska 2015/02/05 19:51:16 Done.
278 return properties;
279 }
280
281 void PeerDaemonManagerClientImpl::ObjectAdded(
282 const dbus::ObjectPath& object_path,
283 const std::string& interface_name) {
284 if (interface_name == peerd::kManagerInterface) {
285 FOR_EACH_OBSERVER(Observer, observers_, ManagerAdded());
286 } else if (interface_name == peerd::kServiceInterface) {
287 FOR_EACH_OBSERVER(Observer, observers_, ServiceAdded(object_path));
288 } else if (interface_name == peerd::kPeerInterface) {
289 FOR_EACH_OBSERVER(Observer, observers_, PeerAdded(object_path));
290 }
291 }
292
293 void PeerDaemonManagerClientImpl::ObjectRemoved(
294 const dbus::ObjectPath& object_path,
295 const std::string& interface_name) {
296 if (interface_name == peerd::kManagerInterface) {
297 FOR_EACH_OBSERVER(Observer, observers_, ManagerRemoved());
298 } else if (interface_name == peerd::kServiceInterface) {
299 FOR_EACH_OBSERVER(Observer, observers_, ServiceRemoved(object_path));
300 } else if (interface_name == peerd::kPeerInterface) {
301 FOR_EACH_OBSERVER(Observer, observers_, PeerRemoved(object_path));
302 }
163 } 303 }
164 304
165 void PeerDaemonManagerClientImpl::OnStringDBusMethod( 305 void PeerDaemonManagerClientImpl::OnStringDBusMethod(
166 const StringDBusMethodCallback& callback, 306 const StringDBusMethodCallback& callback,
167 dbus::Response* response) { 307 dbus::Response* response) {
168 if (!response) { 308 if (!response) {
169 callback.Run(DBUS_METHOD_CALL_FAILURE, std::string()); 309 callback.Run(DBUS_METHOD_CALL_FAILURE, std::string());
170 return; 310 return;
171 } 311 }
172 312
173 dbus::MessageReader reader(response); 313 dbus::MessageReader reader(response);
174 std::string result; 314 std::string result;
175 if (!reader.PopString(&result)) { 315 if (!reader.PopString(&result)) {
176 callback.Run(DBUS_METHOD_CALL_FAILURE, std::string()); 316 callback.Run(DBUS_METHOD_CALL_FAILURE, std::string());
177 return; 317 return;
178 } 318 }
179 319
180 callback.Run(DBUS_METHOD_CALL_SUCCESS, result); 320 callback.Run(DBUS_METHOD_CALL_SUCCESS, result);
181 } 321 }
182 322
183 void PeerDaemonManagerClientImpl::OnVoidDBusMethod( 323 void PeerDaemonManagerClientImpl::OnVoidDBusMethod(
184 const VoidDBusMethodCallback& callback, 324 const VoidDBusMethodCallback& callback,
185 dbus::Response* response) { 325 dbus::Response* response) {
186 callback.Run(response ? DBUS_METHOD_CALL_SUCCESS : DBUS_METHOD_CALL_FAILURE); 326 callback.Run(response ? DBUS_METHOD_CALL_SUCCESS : DBUS_METHOD_CALL_FAILURE);
187 } 327 }
188 328
189 void PeerDaemonManagerClientImpl::Init(dbus::Bus* bus) { 329 void PeerDaemonManagerClientImpl::Init(dbus::Bus* bus) {
190 peer_daemon_proxy_ = 330 object_manager_ = bus->GetObjectManager(
191 bus->GetObjectProxy(peerd::kPeerdServiceName, 331 peerd::kPeerdServiceName,
192 dbus::ObjectPath(peerd::kPeerdManagerPath)); 332 dbus::ObjectPath(peerd::kPeerdObjectManagerServicePath));
333 object_manager_->RegisterInterface(peerd::kManagerInterface, this);
334 object_manager_->RegisterInterface(peerd::kPeerInterface, this);
335 object_manager_->RegisterInterface(peerd::kServiceInterface, this);
336 }
337
338 void PeerDaemonManagerClientImpl::OnManagerPropertyChanged(
339 const std::string& property_name) {
340 FOR_EACH_OBSERVER(Observer, observers_,
341 ManagerPropertyChanged(property_name));
342 }
343
344 void PeerDaemonManagerClientImpl::OnPeerPropertyChanged(
345 const dbus::ObjectPath& object_path,
346 const std::string& property_name) {
347 FOR_EACH_OBSERVER(Observer, observers_,
348 PeerPropertyChanged(object_path, property_name));
349 }
350
351 void PeerDaemonManagerClientImpl::OnServicePropertyChanged(
352 const dbus::ObjectPath& object_path,
353 const std::string& property_name) {
354 FOR_EACH_OBSERVER(Observer, observers_,
355 ServicePropertyChanged(object_path, property_name));
193 } 356 }
194 357
195 } // namespace 358 } // namespace
196 359
360 PeerDaemonManagerClient::ManagerProperties::ManagerProperties(
361 dbus::ObjectProxy* object_proxy,
362 const PropertyChangedCallback& callback)
363 : dbus::PropertySet{object_proxy, peerd::kManagerInterface, callback} {
364 RegisterProperty("MonitoredTechnologies", &monitored_technologies);
365 }
366
367 PeerDaemonManagerClient::ManagerProperties::~ManagerProperties() {
368 }
369
370 PeerDaemonManagerClient::PeerProperties::PeerProperties(
371 dbus::ObjectProxy* object_proxy,
372 const PropertyChangedCallback& callback)
373 : dbus::PropertySet{object_proxy, peerd::kPeerInterface, callback} {
374 RegisterProperty("UUID", &u_u_i_d);
375 RegisterProperty("LastSeen", &last_seen);
376 }
377
378 PeerDaemonManagerClient::PeerProperties::~PeerProperties() {
379 }
380
381 PeerDaemonManagerClient::ServiceProperties::ServiceProperties(
382 dbus::ObjectProxy* object_proxy,
383 const PropertyChangedCallback& callback)
384 : dbus::PropertySet{object_proxy, peerd::kServiceInterface, callback} {
385 RegisterProperty("ServiceId", &service_id);
386 RegisterProperty("ServiceInfo", &service_info);
387 RegisterProperty("IpInfos", &ip_infos);
388 }
389
390 PeerDaemonManagerClient::ServiceProperties::~ServiceProperties() {
391 }
197 392
198 PeerDaemonManagerClient::PeerDaemonManagerClient() { 393 PeerDaemonManagerClient::PeerDaemonManagerClient() {
199 } 394 }
200 395
201 PeerDaemonManagerClient::~PeerDaemonManagerClient() { 396 PeerDaemonManagerClient::~PeerDaemonManagerClient() {
202 } 397 }
203 398
204 // static 399 // static
205 PeerDaemonManagerClient* PeerDaemonManagerClient::Create() { 400 PeerDaemonManagerClient* PeerDaemonManagerClient::Create() {
206 return new PeerDaemonManagerClientImpl(); 401 return new PeerDaemonManagerClientImpl();
207 } 402 }
208 403
209 } // namespace chromeos 404 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698