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

Side by Side Diff: dbus/test_service.cc

Issue 16012018: Cleanup: Put DBus unit tests in the dbus namespace, so one does not need to write dbus:: everywhere… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « dbus/string_util_unittest.cc ('k') | dbus/values_util_unittest.cc » ('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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "dbus/test_service.h" 5 #include "dbus/test_service.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/test/test_timeouts.h" 8 #include "base/test/test_timeouts.h"
9 #include "base/threading/platform_thread.h" 9 #include "base/threading/platform_thread.h"
10 #include "dbus/bus.h" 10 #include "dbus/bus.h"
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 84
85 void TestService::SendTestSignalFromRoot(const std::string& message) { 85 void TestService::SendTestSignalFromRoot(const std::string& message) {
86 message_loop()->PostTask( 86 message_loop()->PostTask(
87 FROM_HERE, 87 FROM_HERE,
88 base::Bind(&TestService::SendTestSignalFromRootInternal, 88 base::Bind(&TestService::SendTestSignalFromRootInternal,
89 base::Unretained(this), 89 base::Unretained(this),
90 message)); 90 message));
91 } 91 }
92 92
93 void TestService::SendTestSignalInternal(const std::string& message) { 93 void TestService::SendTestSignalInternal(const std::string& message) {
94 dbus::Signal signal("org.chromium.TestInterface", "Test"); 94 Signal signal("org.chromium.TestInterface", "Test");
95 dbus::MessageWriter writer(&signal); 95 MessageWriter writer(&signal);
96 writer.AppendString(message); 96 writer.AppendString(message);
97 exported_object_->SendSignal(&signal); 97 exported_object_->SendSignal(&signal);
98 } 98 }
99 99
100 void TestService::SendTestSignalFromRootInternal(const std::string& message) { 100 void TestService::SendTestSignalFromRootInternal(const std::string& message) {
101 dbus::Signal signal("org.chromium.TestInterface", "Test"); 101 Signal signal("org.chromium.TestInterface", "Test");
102 dbus::MessageWriter writer(&signal); 102 MessageWriter writer(&signal);
103 writer.AppendString(message); 103 writer.AppendString(message);
104 104
105 bus_->RequestOwnership("org.chromium.TestService", 105 bus_->RequestOwnership("org.chromium.TestService",
106 base::Bind(&TestService::OnOwnership, 106 base::Bind(&TestService::OnOwnership,
107 base::Unretained(this), 107 base::Unretained(this),
108 base::Bind(&EmptyCallback))); 108 base::Bind(&EmptyCallback)));
109 109
110 // Use "/" just like dbus-send does. 110 // Use "/" just like dbus-send does.
111 ExportedObject* root_object = 111 ExportedObject* root_object = bus_->GetExportedObject(ObjectPath("/"));
112 bus_->GetExportedObject(dbus::ObjectPath("/"));
113 root_object->SendSignal(&signal); 112 root_object->SendSignal(&signal);
114 } 113 }
115 114
116 void TestService::RequestOwnership(base::Callback<void(bool)> callback) { 115 void TestService::RequestOwnership(base::Callback<void(bool)> callback) {
117 message_loop()->PostTask( 116 message_loop()->PostTask(
118 FROM_HERE, 117 FROM_HERE,
119 base::Bind(&TestService::RequestOwnershipInternal, 118 base::Bind(&TestService::RequestOwnershipInternal,
120 base::Unretained(this), 119 base::Unretained(this),
121 callback)); 120 callback));
122 } 121 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 bus_options.connection_type = Bus::PRIVATE; 158 bus_options.connection_type = Bus::PRIVATE;
160 bus_options.dbus_task_runner = dbus_task_runner_; 159 bus_options.dbus_task_runner = dbus_task_runner_;
161 bus_ = new Bus(bus_options); 160 bus_ = new Bus(bus_options);
162 161
163 bus_->RequestOwnership("org.chromium.TestService", 162 bus_->RequestOwnership("org.chromium.TestService",
164 base::Bind(&TestService::OnOwnership, 163 base::Bind(&TestService::OnOwnership,
165 base::Unretained(this), 164 base::Unretained(this),
166 base::Bind(&EmptyCallback))); 165 base::Bind(&EmptyCallback)));
167 166
168 exported_object_ = bus_->GetExportedObject( 167 exported_object_ = bus_->GetExportedObject(
169 dbus::ObjectPath("/org/chromium/TestObject")); 168 ObjectPath("/org/chromium/TestObject"));
170 169
171 int num_methods = 0; 170 int num_methods = 0;
172 exported_object_->ExportMethod( 171 exported_object_->ExportMethod(
173 "org.chromium.TestInterface", 172 "org.chromium.TestInterface",
174 "Echo", 173 "Echo",
175 base::Bind(&TestService::Echo, 174 base::Bind(&TestService::Echo,
176 base::Unretained(this)), 175 base::Unretained(this)),
177 base::Bind(&TestService::OnExported, 176 base::Bind(&TestService::OnExported,
178 base::Unretained(this))); 177 base::Unretained(this)));
179 ++num_methods; 178 ++num_methods;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 exported_object_->ExportMethod( 234 exported_object_->ExportMethod(
236 kPropertiesInterface, 235 kPropertiesInterface,
237 kPropertiesSet, 236 kPropertiesSet,
238 base::Bind(&TestService::SetProperty, 237 base::Bind(&TestService::SetProperty,
239 base::Unretained(this)), 238 base::Unretained(this)),
240 base::Bind(&TestService::OnExported, 239 base::Bind(&TestService::OnExported,
241 base::Unretained(this))); 240 base::Unretained(this)));
242 ++num_methods; 241 ++num_methods;
243 242
244 exported_object_manager_ = bus_->GetExportedObject( 243 exported_object_manager_ = bus_->GetExportedObject(
245 dbus::ObjectPath("/org/chromium/TestService")); 244 ObjectPath("/org/chromium/TestService"));
246 245
247 exported_object_manager_->ExportMethod( 246 exported_object_manager_->ExportMethod(
248 kObjectManagerInterface, 247 kObjectManagerInterface,
249 kObjectManagerGetManagedObjects, 248 kObjectManagerGetManagedObjects,
250 base::Bind(&TestService::GetManagedObjects, 249 base::Bind(&TestService::GetManagedObjects,
251 base::Unretained(this)), 250 base::Unretained(this)),
252 base::Bind(&TestService::OnExported, 251 base::Bind(&TestService::OnExported,
253 base::Unretained(this))); 252 base::Unretained(this)));
254 ++num_methods; 253 ++num_methods;
255 254
256 // Just print an error message as we don't want to crash tests. 255 // Just print an error message as we don't want to crash tests.
257 // Tests will fail at a call to WaitUntilServiceIsStarted(). 256 // Tests will fail at a call to WaitUntilServiceIsStarted().
258 if (num_methods != kNumMethodsToExport) { 257 if (num_methods != kNumMethodsToExport) {
259 LOG(ERROR) << "The number of methods does not match"; 258 LOG(ERROR) << "The number of methods does not match";
260 } 259 }
261 message_loop->Run(); 260 message_loop->Run();
262 } 261 }
263 262
264 void TestService::Echo(MethodCall* method_call, 263 void TestService::Echo(MethodCall* method_call,
265 dbus::ExportedObject::ResponseSender response_sender) { 264 ExportedObject::ResponseSender response_sender) {
266 MessageReader reader(method_call); 265 MessageReader reader(method_call);
267 std::string text_message; 266 std::string text_message;
268 if (!reader.PopString(&text_message)) { 267 if (!reader.PopString(&text_message)) {
269 response_sender.Run(scoped_ptr<dbus::Response>()); 268 response_sender.Run(scoped_ptr<Response>());
270 return; 269 return;
271 } 270 }
272 271
273 scoped_ptr<Response> response = Response::FromMethodCall(method_call); 272 scoped_ptr<Response> response = Response::FromMethodCall(method_call);
274 MessageWriter writer(response.get()); 273 MessageWriter writer(response.get());
275 writer.AppendString(text_message); 274 writer.AppendString(text_message);
276 response_sender.Run(response.Pass()); 275 response_sender.Run(response.Pass());
277 } 276 }
278 277
279 void TestService::SlowEcho( 278 void TestService::SlowEcho(MethodCall* method_call,
280 MethodCall* method_call, 279 ExportedObject::ResponseSender response_sender) {
281 dbus::ExportedObject::ResponseSender response_sender) {
282 base::PlatformThread::Sleep(TestTimeouts::tiny_timeout()); 280 base::PlatformThread::Sleep(TestTimeouts::tiny_timeout());
283 Echo(method_call, response_sender); 281 Echo(method_call, response_sender);
284 } 282 }
285 283
286 void TestService::AsyncEcho( 284 void TestService::AsyncEcho(MethodCall* method_call,
287 MethodCall* method_call, 285 ExportedObject::ResponseSender response_sender) {
288 dbus::ExportedObject::ResponseSender response_sender) {
289 // Schedule a call to Echo() to send an asynchronous response after we return. 286 // Schedule a call to Echo() to send an asynchronous response after we return.
290 message_loop()->PostDelayedTask(FROM_HERE, 287 message_loop()->PostDelayedTask(FROM_HERE,
291 base::Bind(&TestService::Echo, 288 base::Bind(&TestService::Echo,
292 base::Unretained(this), 289 base::Unretained(this),
293 method_call, 290 method_call,
294 response_sender), 291 response_sender),
295 TestTimeouts::tiny_timeout()); 292 TestTimeouts::tiny_timeout());
296 } 293 }
297 294
298 void TestService::BrokenMethod( 295 void TestService::BrokenMethod(MethodCall* method_call,
299 MethodCall* method_call, 296 ExportedObject::ResponseSender response_sender) {
300 dbus::ExportedObject::ResponseSender response_sender) { 297 response_sender.Run(scoped_ptr<Response>());
301 response_sender.Run(scoped_ptr<dbus::Response>());
302 } 298 }
303 299
304 300
305 void TestService::GetAllProperties( 301 void TestService::GetAllProperties(
306 MethodCall* method_call, 302 MethodCall* method_call,
307 dbus::ExportedObject::ResponseSender response_sender) { 303 ExportedObject::ResponseSender response_sender) {
308 MessageReader reader(method_call); 304 MessageReader reader(method_call);
309 std::string interface; 305 std::string interface;
310 if (!reader.PopString(&interface)) { 306 if (!reader.PopString(&interface)) {
311 response_sender.Run(scoped_ptr<dbus::Response>()); 307 response_sender.Run(scoped_ptr<Response>());
312 return; 308 return;
313 } 309 }
314 310
315 scoped_ptr<Response> response = Response::FromMethodCall(method_call); 311 scoped_ptr<Response> response = Response::FromMethodCall(method_call);
316 MessageWriter writer(response.get()); 312 MessageWriter writer(response.get());
317 313
318 AddPropertiesToWriter(&writer); 314 AddPropertiesToWriter(&writer);
319 315
320 response_sender.Run(response.Pass()); 316 response_sender.Run(response.Pass());
321 } 317 }
322 318
323 void TestService::GetProperty( 319 void TestService::GetProperty(MethodCall* method_call,
324 MethodCall* method_call, 320 ExportedObject::ResponseSender response_sender) {
325 dbus::ExportedObject::ResponseSender response_sender) {
326 MessageReader reader(method_call); 321 MessageReader reader(method_call);
327 std::string interface; 322 std::string interface;
328 if (!reader.PopString(&interface)) { 323 if (!reader.PopString(&interface)) {
329 response_sender.Run(scoped_ptr<dbus::Response>()); 324 response_sender.Run(scoped_ptr<Response>());
330 return; 325 return;
331 } 326 }
332 327
333 std::string name; 328 std::string name;
334 if (!reader.PopString(&name)) { 329 if (!reader.PopString(&name)) {
335 response_sender.Run(scoped_ptr<dbus::Response>()); 330 response_sender.Run(scoped_ptr<Response>());
336 return; 331 return;
337 } 332 }
338 333
339 if (name == "Name") { 334 if (name == "Name") {
340 // Return the previous value for the "Name" property: 335 // Return the previous value for the "Name" property:
341 // Variant<"TestService"> 336 // Variant<"TestService">
342 scoped_ptr<Response> response = Response::FromMethodCall(method_call); 337 scoped_ptr<Response> response = Response::FromMethodCall(method_call);
343 MessageWriter writer(response.get()); 338 MessageWriter writer(response.get());
344 339
345 writer.AppendVariantOfString("TestService"); 340 writer.AppendVariantOfString("TestService");
(...skipping 29 matching lines...) Expand all
375 } else if (name == "Objects") { 370 } else if (name == "Objects") {
376 // Return the previous value for the "Objects" property: 371 // Return the previous value for the "Objects" property:
377 // Variant<[objectpath:"/TestObjectPath"]> 372 // Variant<[objectpath:"/TestObjectPath"]>
378 scoped_ptr<Response> response = Response::FromMethodCall(method_call); 373 scoped_ptr<Response> response = Response::FromMethodCall(method_call);
379 MessageWriter writer(response.get()); 374 MessageWriter writer(response.get());
380 MessageWriter variant_writer(NULL); 375 MessageWriter variant_writer(NULL);
381 MessageWriter variant_array_writer(NULL); 376 MessageWriter variant_array_writer(NULL);
382 377
383 writer.OpenVariant("ao", &variant_writer); 378 writer.OpenVariant("ao", &variant_writer);
384 variant_writer.OpenArray("o", &variant_array_writer); 379 variant_writer.OpenArray("o", &variant_array_writer);
385 variant_array_writer.AppendObjectPath(dbus::ObjectPath("/TestObjectPath")); 380 variant_array_writer.AppendObjectPath(ObjectPath("/TestObjectPath"));
386 variant_writer.CloseContainer(&variant_array_writer); 381 variant_writer.CloseContainer(&variant_array_writer);
387 writer.CloseContainer(&variant_writer); 382 writer.CloseContainer(&variant_writer);
388 383
389 response_sender.Run(response.Pass()); 384 response_sender.Run(response.Pass());
390 } else { 385 } else {
391 // Return error. 386 // Return error.
392 response_sender.Run(scoped_ptr<dbus::Response>()); 387 response_sender.Run(scoped_ptr<Response>());
393 return; 388 return;
394 } 389 }
395 } 390 }
396 391
397 void TestService::SetProperty( 392 void TestService::SetProperty(MethodCall* method_call,
398 MethodCall* method_call, 393 ExportedObject::ResponseSender response_sender) {
399 dbus::ExportedObject::ResponseSender response_sender) {
400 MessageReader reader(method_call); 394 MessageReader reader(method_call);
401 std::string interface; 395 std::string interface;
402 if (!reader.PopString(&interface)) { 396 if (!reader.PopString(&interface)) {
403 response_sender.Run(scoped_ptr<dbus::Response>()); 397 response_sender.Run(scoped_ptr<Response>());
404 return; 398 return;
405 } 399 }
406 400
407 std::string name; 401 std::string name;
408 if (!reader.PopString(&name)) { 402 if (!reader.PopString(&name)) {
409 response_sender.Run(scoped_ptr<dbus::Response>()); 403 response_sender.Run(scoped_ptr<Response>());
410 return; 404 return;
411 } 405 }
412 406
413 if (name != "Name") { 407 if (name != "Name") {
414 response_sender.Run(scoped_ptr<dbus::Response>()); 408 response_sender.Run(scoped_ptr<Response>());
415 return; 409 return;
416 } 410 }
417 411
418 std::string value; 412 std::string value;
419 if (!reader.PopVariantOfString(&value)) { 413 if (!reader.PopVariantOfString(&value)) {
420 response_sender.Run(scoped_ptr<dbus::Response>()); 414 response_sender.Run(scoped_ptr<Response>());
421 return; 415 return;
422 } 416 }
423 417
424 SendPropertyChangedSignal(value); 418 SendPropertyChangedSignal(value);
425 419
426 response_sender.Run(Response::FromMethodCall(method_call)); 420 response_sender.Run(Response::FromMethodCall(method_call));
427 } 421 }
428 422
429 void TestService::PerformAction( 423 void TestService::PerformAction(
430 MethodCall* method_call, 424 MethodCall* method_call,
431 dbus::ExportedObject::ResponseSender response_sender) { 425 ExportedObject::ResponseSender response_sender) {
432 MessageReader reader(method_call); 426 MessageReader reader(method_call);
433 std::string action; 427 std::string action;
434 dbus::ObjectPath object_path; 428 ObjectPath object_path;
435 if (!reader.PopString(&action) || !reader.PopObjectPath(&object_path)) { 429 if (!reader.PopString(&action) || !reader.PopObjectPath(&object_path)) {
436 response_sender.Run(scoped_ptr<dbus::Response>()); 430 response_sender.Run(scoped_ptr<Response>());
437 return; 431 return;
438 } 432 }
439 433
440 if (action == "AddObject") 434 if (action == "AddObject")
441 AddObject(object_path); 435 AddObject(object_path);
442 else if (action == "RemoveObject") 436 else if (action == "RemoveObject")
443 RemoveObject(object_path); 437 RemoveObject(object_path);
444 438
445 scoped_ptr<Response> response = Response::FromMethodCall(method_call); 439 scoped_ptr<Response> response = Response::FromMethodCall(method_call);
446 response_sender.Run(response.Pass()); 440 response_sender.Run(response.Pass());
447 } 441 }
448 442
449 void TestService::GetManagedObjects( 443 void TestService::GetManagedObjects(
450 MethodCall* method_call, 444 MethodCall* method_call,
451 dbus::ExportedObject::ResponseSender response_sender) { 445 ExportedObject::ResponseSender response_sender) {
452 scoped_ptr<Response> response = Response::FromMethodCall(method_call); 446 scoped_ptr<Response> response = Response::FromMethodCall(method_call);
453 MessageWriter writer(response.get()); 447 MessageWriter writer(response.get());
454 448
455 // The managed objects response is a dictionary of object paths identifying 449 // The managed objects response is a dictionary of object paths identifying
456 // the object(s) with a dictionary of strings identifying the interface(s) 450 // the object(s) with a dictionary of strings identifying the interface(s)
457 // they implement and then a dictionary of property values. 451 // they implement and then a dictionary of property values.
458 // 452 //
459 // Thus this looks something like: 453 // Thus this looks something like:
460 // 454 //
461 // { 455 // {
462 // "/org/chromium/TestObject": { 456 // "/org/chromium/TestObject": {
463 // "org.chromium.TestInterface": { /* Properties */ } 457 // "org.chromium.TestInterface": { /* Properties */ }
464 // } 458 // }
465 // } 459 // }
466 460
467 461
468 MessageWriter array_writer(NULL); 462 MessageWriter array_writer(NULL);
469 MessageWriter dict_entry_writer(NULL); 463 MessageWriter dict_entry_writer(NULL);
470 MessageWriter object_array_writer(NULL); 464 MessageWriter object_array_writer(NULL);
471 MessageWriter object_dict_entry_writer(NULL); 465 MessageWriter object_dict_entry_writer(NULL);
472 466
473 writer.OpenArray("{oa{sa{sv}}}", &array_writer); 467 writer.OpenArray("{oa{sa{sv}}}", &array_writer);
474 468
475 array_writer.OpenDictEntry(&dict_entry_writer); 469 array_writer.OpenDictEntry(&dict_entry_writer);
476 dict_entry_writer.AppendObjectPath( 470 dict_entry_writer.AppendObjectPath(ObjectPath("/org/chromium/TestObject"));
477 dbus::ObjectPath("/org/chromium/TestObject"));
478 dict_entry_writer.OpenArray("{sa{sv}}", &object_array_writer); 471 dict_entry_writer.OpenArray("{sa{sv}}", &object_array_writer);
479 472
480 object_array_writer.OpenDictEntry(&object_dict_entry_writer); 473 object_array_writer.OpenDictEntry(&object_dict_entry_writer);
481 object_dict_entry_writer.AppendString("org.chromium.TestInterface"); 474 object_dict_entry_writer.AppendString("org.chromium.TestInterface");
482 AddPropertiesToWriter(&object_dict_entry_writer); 475 AddPropertiesToWriter(&object_dict_entry_writer);
483 object_array_writer.CloseContainer(&object_dict_entry_writer); 476 object_array_writer.CloseContainer(&object_dict_entry_writer);
484 477
485 dict_entry_writer.CloseContainer(&object_array_writer); 478 dict_entry_writer.CloseContainer(&object_array_writer);
486 479
487 array_writer.CloseContainer(&dict_entry_writer); 480 array_writer.CloseContainer(&dict_entry_writer);
488 writer.CloseContainer(&array_writer); 481 writer.CloseContainer(&array_writer);
489 482
490 response_sender.Run(response.Pass()); 483 response_sender.Run(response.Pass());
491 } 484 }
492 485
493 void TestService::AddPropertiesToWriter(MessageWriter* writer) 486 void TestService::AddPropertiesToWriter(MessageWriter* writer) {
494 {
495 // The properties response is a dictionary of strings identifying the 487 // The properties response is a dictionary of strings identifying the
496 // property and a variant containing the property value. We return all 488 // property and a variant containing the property value. We return all
497 // of the properties, thus the response is: 489 // of the properties, thus the response is:
498 // 490 //
499 // { 491 // {
500 // "Name": Variant<"TestService">, 492 // "Name": Variant<"TestService">,
501 // "Version": Variant<10>, 493 // "Version": Variant<10>,
502 // "Methods": Variant<["Echo", "SlowEcho", "AsyncEcho", "BrokenMethod"]>, 494 // "Methods": Variant<["Echo", "SlowEcho", "AsyncEcho", "BrokenMethod"]>,
503 // "Objects": Variant<[objectpath:"/TestObjectPath"]> 495 // "Objects": Variant<[objectpath:"/TestObjectPath"]>
504 // ] 496 // }
505 497
506 MessageWriter array_writer(NULL); 498 MessageWriter array_writer(NULL);
507 MessageWriter dict_entry_writer(NULL); 499 MessageWriter dict_entry_writer(NULL);
508 MessageWriter variant_writer(NULL); 500 MessageWriter variant_writer(NULL);
509 MessageWriter variant_array_writer(NULL); 501 MessageWriter variant_array_writer(NULL);
510 502
511 writer->OpenArray("{sv}", &array_writer); 503 writer->OpenArray("{sv}", &array_writer);
512 504
513 array_writer.OpenDictEntry(&dict_entry_writer); 505 array_writer.OpenDictEntry(&dict_entry_writer);
514 dict_entry_writer.AppendString("Name"); 506 dict_entry_writer.AppendString("Name");
(...skipping 14 matching lines...) Expand all
529 variant_array_writer.AppendString("AsyncEcho"); 521 variant_array_writer.AppendString("AsyncEcho");
530 variant_array_writer.AppendString("BrokenMethod"); 522 variant_array_writer.AppendString("BrokenMethod");
531 variant_writer.CloseContainer(&variant_array_writer); 523 variant_writer.CloseContainer(&variant_array_writer);
532 dict_entry_writer.CloseContainer(&variant_writer); 524 dict_entry_writer.CloseContainer(&variant_writer);
533 array_writer.CloseContainer(&dict_entry_writer); 525 array_writer.CloseContainer(&dict_entry_writer);
534 526
535 array_writer.OpenDictEntry(&dict_entry_writer); 527 array_writer.OpenDictEntry(&dict_entry_writer);
536 dict_entry_writer.AppendString("Objects"); 528 dict_entry_writer.AppendString("Objects");
537 dict_entry_writer.OpenVariant("ao", &variant_writer); 529 dict_entry_writer.OpenVariant("ao", &variant_writer);
538 variant_writer.OpenArray("o", &variant_array_writer); 530 variant_writer.OpenArray("o", &variant_array_writer);
539 variant_array_writer.AppendObjectPath(dbus::ObjectPath("/TestObjectPath")); 531 variant_array_writer.AppendObjectPath(ObjectPath("/TestObjectPath"));
540 variant_writer.CloseContainer(&variant_array_writer); 532 variant_writer.CloseContainer(&variant_array_writer);
541 dict_entry_writer.CloseContainer(&variant_writer); 533 dict_entry_writer.CloseContainer(&variant_writer);
542 array_writer.CloseContainer(&dict_entry_writer); 534 array_writer.CloseContainer(&dict_entry_writer);
543 535
544 writer->CloseContainer(&array_writer); 536 writer->CloseContainer(&array_writer);
545 } 537 }
546 538
547 void TestService::AddObject(const dbus::ObjectPath& object_path) { 539 void TestService::AddObject(const ObjectPath& object_path) {
548 message_loop()->PostTask( 540 message_loop()->PostTask(
549 FROM_HERE, 541 FROM_HERE,
550 base::Bind(&TestService::AddObjectInternal, 542 base::Bind(&TestService::AddObjectInternal,
551 base::Unretained(this), 543 base::Unretained(this),
552 object_path)); 544 object_path));
553 } 545 }
554 546
555 void TestService::AddObjectInternal(const dbus::ObjectPath& object_path) { 547 void TestService::AddObjectInternal(const ObjectPath& object_path) {
556 dbus::Signal signal(kObjectManagerInterface, kObjectManagerInterfacesAdded); 548 Signal signal(kObjectManagerInterface, kObjectManagerInterfacesAdded);
557 dbus::MessageWriter writer(&signal); 549 MessageWriter writer(&signal);
558 writer.AppendObjectPath(object_path); 550 writer.AppendObjectPath(object_path);
559 551
560 MessageWriter array_writer(NULL); 552 MessageWriter array_writer(NULL);
561 MessageWriter dict_entry_writer(NULL); 553 MessageWriter dict_entry_writer(NULL);
562 554
563 writer.OpenArray("{sa{sv}}", &array_writer); 555 writer.OpenArray("{sa{sv}}", &array_writer);
564 array_writer.OpenDictEntry(&dict_entry_writer); 556 array_writer.OpenDictEntry(&dict_entry_writer);
565 dict_entry_writer.AppendString("org.chromium.TestInterface"); 557 dict_entry_writer.AppendString("org.chromium.TestInterface");
566 AddPropertiesToWriter(&dict_entry_writer); 558 AddPropertiesToWriter(&dict_entry_writer);
567 array_writer.CloseContainer(&dict_entry_writer); 559 array_writer.CloseContainer(&dict_entry_writer);
568 writer.CloseContainer(&array_writer); 560 writer.CloseContainer(&array_writer);
569 561
570 exported_object_manager_->SendSignal(&signal); 562 exported_object_manager_->SendSignal(&signal);
571 } 563 }
572 564
573 void TestService::RemoveObject(const dbus::ObjectPath& object_path) { 565 void TestService::RemoveObject(const ObjectPath& object_path) {
574 message_loop()->PostTask( 566 message_loop()->PostTask(FROM_HERE,
575 FROM_HERE, 567 base::Bind(&TestService::RemoveObjectInternal,
576 base::Bind(&TestService::RemoveObjectInternal, 568 base::Unretained(this),
577 base::Unretained(this), 569 object_path));
578 object_path));
579 } 570 }
580 571
581 void TestService::RemoveObjectInternal(const dbus::ObjectPath& object_path) { 572 void TestService::RemoveObjectInternal(const ObjectPath& object_path) {
582 dbus::Signal signal(kObjectManagerInterface, kObjectManagerInterfacesRemoved); 573 Signal signal(kObjectManagerInterface, kObjectManagerInterfacesRemoved);
583 dbus::MessageWriter writer(&signal); 574 MessageWriter writer(&signal);
584 575
585 writer.AppendObjectPath(object_path); 576 writer.AppendObjectPath(object_path);
586 577
587 std::vector<std::string> interfaces; 578 std::vector<std::string> interfaces;
588 interfaces.push_back("org.chromium.TestInterface"); 579 interfaces.push_back("org.chromium.TestInterface");
589 writer.AppendArrayOfStrings(interfaces); 580 writer.AppendArrayOfStrings(interfaces);
590 581
591 exported_object_manager_->SendSignal(&signal); 582 exported_object_manager_->SendSignal(&signal);
592 } 583 }
593 584
594 void TestService::SendPropertyChangedSignal(const std::string& name) { 585 void TestService::SendPropertyChangedSignal(const std::string& name) {
595 message_loop()->PostTask( 586 message_loop()->PostTask(
596 FROM_HERE, 587 FROM_HERE,
597 base::Bind(&TestService::SendPropertyChangedSignalInternal, 588 base::Bind(&TestService::SendPropertyChangedSignalInternal,
598 base::Unretained(this), 589 base::Unretained(this),
599 name)); 590 name));
600 } 591 }
601 592
602 void TestService::SendPropertyChangedSignalInternal(const std::string& name) { 593 void TestService::SendPropertyChangedSignalInternal(const std::string& name) {
603 dbus::Signal signal(kPropertiesInterface, kPropertiesChanged); 594 Signal signal(kPropertiesInterface, kPropertiesChanged);
604 dbus::MessageWriter writer(&signal); 595 MessageWriter writer(&signal);
605 writer.AppendString("org.chromium.TestInterface"); 596 writer.AppendString("org.chromium.TestInterface");
606 597
607 MessageWriter array_writer(NULL); 598 MessageWriter array_writer(NULL);
608 MessageWriter dict_entry_writer(NULL); 599 MessageWriter dict_entry_writer(NULL);
609 600
610 writer.OpenArray("{sv}", &array_writer); 601 writer.OpenArray("{sv}", &array_writer);
611 array_writer.OpenDictEntry(&dict_entry_writer); 602 array_writer.OpenDictEntry(&dict_entry_writer);
612 dict_entry_writer.AppendString("Name"); 603 dict_entry_writer.AppendString("Name");
613 dict_entry_writer.AppendVariantOfString(name); 604 dict_entry_writer.AppendVariantOfString(name);
614 array_writer.CloseContainer(&dict_entry_writer); 605 array_writer.CloseContainer(&dict_entry_writer);
615 writer.CloseContainer(&array_writer); 606 writer.CloseContainer(&array_writer);
616 607
617 exported_object_->SendSignal(&signal); 608 exported_object_->SendSignal(&signal);
618 } 609 }
619 610
620 } // namespace dbus 611 } // namespace dbus
OLDNEW
« no previous file with comments | « dbus/string_util_unittest.cc ('k') | dbus/values_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698