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

Side by Side Diff: dbus/property.cc

Issue 1541193002: Switch to standard integer types in dbus/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 12 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 | « dbus/property.h ('k') | dbus/property_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/property.h" 5 #include "dbus/property.h"
6 6
7 #include "base/basictypes.h" 7 #include <stddef.h>
8
8 #include "base/bind.h" 9 #include "base/bind.h"
9 #include "base/logging.h" 10 #include "base/logging.h"
10 11
11 #include "dbus/message.h" 12 #include "dbus/message.h"
12 #include "dbus/object_path.h" 13 #include "dbus/object_path.h"
13 #include "dbus/object_proxy.h" 14 #include "dbus/object_proxy.h"
14 15
15 namespace dbus { 16 namespace dbus {
16 17
17 // 18 //
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 void PropertySet::NotifyPropertyChanged(const std::string& name) { 296 void PropertySet::NotifyPropertyChanged(const std::string& name) {
296 if (!property_changed_callback_.is_null()) 297 if (!property_changed_callback_.is_null())
297 property_changed_callback_.Run(name); 298 property_changed_callback_.Run(name);
298 } 299 }
299 300
300 // 301 //
301 // Property<Byte> specialization. 302 // Property<Byte> specialization.
302 // 303 //
303 304
304 template <> 305 template <>
305 Property<uint8>::Property() : value_(0) { 306 Property<uint8_t>::Property()
306 } 307 : value_(0) {}
307 308
308 template <> 309 template <>
309 bool Property<uint8>::PopValueFromReader(MessageReader* reader) { 310 bool Property<uint8_t>::PopValueFromReader(MessageReader* reader) {
310 return reader->PopVariantOfByte(&value_); 311 return reader->PopVariantOfByte(&value_);
311 } 312 }
312 313
313 template <> 314 template <>
314 void Property<uint8>::AppendSetValueToWriter(MessageWriter* writer) { 315 void Property<uint8_t>::AppendSetValueToWriter(MessageWriter* writer) {
315 writer->AppendVariantOfByte(set_value_); 316 writer->AppendVariantOfByte(set_value_);
316 } 317 }
317 318
318 // 319 //
319 // Property<bool> specialization. 320 // Property<bool> specialization.
320 // 321 //
321 322
322 template <> 323 template <>
323 Property<bool>::Property() : value_(false) { 324 Property<bool>::Property() : value_(false) {
324 } 325 }
325 326
326 template <> 327 template <>
327 bool Property<bool>::PopValueFromReader(MessageReader* reader) { 328 bool Property<bool>::PopValueFromReader(MessageReader* reader) {
328 return reader->PopVariantOfBool(&value_); 329 return reader->PopVariantOfBool(&value_);
329 } 330 }
330 331
331 template <> 332 template <>
332 void Property<bool>::AppendSetValueToWriter(MessageWriter* writer) { 333 void Property<bool>::AppendSetValueToWriter(MessageWriter* writer) {
333 writer->AppendVariantOfBool(set_value_); 334 writer->AppendVariantOfBool(set_value_);
334 } 335 }
335 336
336 // 337 //
337 // Property<int16> specialization. 338 // Property<int16_t> specialization.
338 // 339 //
339 340
340 template <> 341 template <>
341 Property<int16>::Property() : value_(0) { 342 Property<int16_t>::Property()
342 } 343 : value_(0) {}
343 344
344 template <> 345 template <>
345 bool Property<int16>::PopValueFromReader(MessageReader* reader) { 346 bool Property<int16_t>::PopValueFromReader(MessageReader* reader) {
346 return reader->PopVariantOfInt16(&value_); 347 return reader->PopVariantOfInt16(&value_);
347 } 348 }
348 349
349 template <> 350 template <>
350 void Property<int16>::AppendSetValueToWriter(MessageWriter* writer) { 351 void Property<int16_t>::AppendSetValueToWriter(MessageWriter* writer) {
351 writer->AppendVariantOfInt16(set_value_); 352 writer->AppendVariantOfInt16(set_value_);
352 } 353 }
353 354
354 // 355 //
355 // Property<uint16> specialization. 356 // Property<uint16_t> specialization.
356 // 357 //
357 358
358 template <> 359 template <>
359 Property<uint16>::Property() : value_(0) { 360 Property<uint16_t>::Property()
360 } 361 : value_(0) {}
361 362
362 template <> 363 template <>
363 bool Property<uint16>::PopValueFromReader(MessageReader* reader) { 364 bool Property<uint16_t>::PopValueFromReader(MessageReader* reader) {
364 return reader->PopVariantOfUint16(&value_); 365 return reader->PopVariantOfUint16(&value_);
365 } 366 }
366 367
367 template <> 368 template <>
368 void Property<uint16>::AppendSetValueToWriter(MessageWriter* writer) { 369 void Property<uint16_t>::AppendSetValueToWriter(MessageWriter* writer) {
369 writer->AppendVariantOfUint16(set_value_); 370 writer->AppendVariantOfUint16(set_value_);
370 } 371 }
371 372
372 // 373 //
373 // Property<int32> specialization. 374 // Property<int32_t> specialization.
374 // 375 //
375 376
376 template <> 377 template <>
377 Property<int32>::Property() : value_(0) { 378 Property<int32_t>::Property()
378 } 379 : value_(0) {}
379 380
380 template <> 381 template <>
381 bool Property<int32>::PopValueFromReader(MessageReader* reader) { 382 bool Property<int32_t>::PopValueFromReader(MessageReader* reader) {
382 return reader->PopVariantOfInt32(&value_); 383 return reader->PopVariantOfInt32(&value_);
383 } 384 }
384 385
385 template <> 386 template <>
386 void Property<int32>::AppendSetValueToWriter(MessageWriter* writer) { 387 void Property<int32_t>::AppendSetValueToWriter(MessageWriter* writer) {
387 writer->AppendVariantOfInt32(set_value_); 388 writer->AppendVariantOfInt32(set_value_);
388 } 389 }
389 390
390 // 391 //
391 // Property<uint32> specialization. 392 // Property<uint32_t> specialization.
392 // 393 //
393 394
394 template <> 395 template <>
395 Property<uint32>::Property() : value_(0) { 396 Property<uint32_t>::Property()
396 } 397 : value_(0) {}
397 398
398 template <> 399 template <>
399 bool Property<uint32>::PopValueFromReader(MessageReader* reader) { 400 bool Property<uint32_t>::PopValueFromReader(MessageReader* reader) {
400 return reader->PopVariantOfUint32(&value_); 401 return reader->PopVariantOfUint32(&value_);
401 } 402 }
402 403
403 template <> 404 template <>
404 void Property<uint32>::AppendSetValueToWriter(MessageWriter* writer) { 405 void Property<uint32_t>::AppendSetValueToWriter(MessageWriter* writer) {
405 writer->AppendVariantOfUint32(set_value_); 406 writer->AppendVariantOfUint32(set_value_);
406 } 407 }
407 408
408 // 409 //
409 // Property<int64> specialization. 410 // Property<int64_t> specialization.
410 // 411 //
411 412
412 template <> 413 template <>
413 Property<int64>::Property() : value_(0), set_value_(0) { 414 Property<int64_t>::Property()
414 } 415 : value_(0), set_value_(0) {}
415 416
416 template <> 417 template <>
417 bool Property<int64>::PopValueFromReader(MessageReader* reader) { 418 bool Property<int64_t>::PopValueFromReader(MessageReader* reader) {
418 return reader->PopVariantOfInt64(&value_); 419 return reader->PopVariantOfInt64(&value_);
419 } 420 }
420 421
421 template <> 422 template <>
422 void Property<int64>::AppendSetValueToWriter(MessageWriter* writer) { 423 void Property<int64_t>::AppendSetValueToWriter(MessageWriter* writer) {
423 writer->AppendVariantOfInt64(set_value_); 424 writer->AppendVariantOfInt64(set_value_);
424 } 425 }
425 426
426 // 427 //
427 // Property<uint64> specialization. 428 // Property<uint64_t> specialization.
428 // 429 //
429 430
430 template <> 431 template <>
431 Property<uint64>::Property() : value_(0) { 432 Property<uint64_t>::Property()
432 } 433 : value_(0) {}
433 434
434 template <> 435 template <>
435 bool Property<uint64>::PopValueFromReader(MessageReader* reader) { 436 bool Property<uint64_t>::PopValueFromReader(MessageReader* reader) {
436 return reader->PopVariantOfUint64(&value_); 437 return reader->PopVariantOfUint64(&value_);
437 } 438 }
438 439
439 template <> 440 template <>
440 void Property<uint64>::AppendSetValueToWriter(MessageWriter* writer) { 441 void Property<uint64_t>::AppendSetValueToWriter(MessageWriter* writer) {
441 writer->AppendVariantOfUint64(set_value_); 442 writer->AppendVariantOfUint64(set_value_);
442 } 443 }
443 444
444 // 445 //
445 // Property<double> specialization. 446 // Property<double> specialization.
446 // 447 //
447 448
448 template <> 449 template <>
449 Property<double>::Property() : value_(0.0) { 450 Property<double>::Property() : value_(0.0) {
450 } 451 }
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 template <> 530 template <>
530 void Property<std::vector<ObjectPath> >::AppendSetValueToWriter( 531 void Property<std::vector<ObjectPath> >::AppendSetValueToWriter(
531 MessageWriter* writer) { 532 MessageWriter* writer) {
532 MessageWriter variant_writer(NULL); 533 MessageWriter variant_writer(NULL);
533 writer->OpenVariant("ao", &variant_writer); 534 writer->OpenVariant("ao", &variant_writer);
534 variant_writer.AppendArrayOfObjectPaths(set_value_); 535 variant_writer.AppendArrayOfObjectPaths(set_value_);
535 writer->CloseContainer(&variant_writer); 536 writer->CloseContainer(&variant_writer);
536 } 537 }
537 538
538 // 539 //
539 // Property<std::vector<uint8> > specialization. 540 // Property<std::vector<uint8_t> > specialization.
540 // 541 //
541 542
542 template <> 543 template <>
543 bool Property<std::vector<uint8> >::PopValueFromReader(MessageReader* reader) { 544 bool Property<std::vector<uint8_t>>::PopValueFromReader(MessageReader* reader) {
544 MessageReader variant_reader(NULL); 545 MessageReader variant_reader(NULL);
545 if (!reader->PopVariant(&variant_reader)) 546 if (!reader->PopVariant(&variant_reader))
546 return false; 547 return false;
547 548
548 value_.clear(); 549 value_.clear();
549 const uint8* bytes = NULL; 550 const uint8_t* bytes = NULL;
550 size_t length = 0; 551 size_t length = 0;
551 if (!variant_reader.PopArrayOfBytes(&bytes, &length)) 552 if (!variant_reader.PopArrayOfBytes(&bytes, &length))
552 return false; 553 return false;
553 value_.assign(bytes, bytes + length); 554 value_.assign(bytes, bytes + length);
554 return true; 555 return true;
555 } 556 }
556 557
557 template <> 558 template <>
558 void Property<std::vector<uint8> >::AppendSetValueToWriter( 559 void Property<std::vector<uint8_t>>::AppendSetValueToWriter(
559 MessageWriter* writer) { 560 MessageWriter* writer) {
560 MessageWriter variant_writer(NULL); 561 MessageWriter variant_writer(NULL);
561 writer->OpenVariant("ay", &variant_writer); 562 writer->OpenVariant("ay", &variant_writer);
562 variant_writer.AppendArrayOfBytes(set_value_.data(), set_value_.size()); 563 variant_writer.AppendArrayOfBytes(set_value_.data(), set_value_.size());
563 writer->CloseContainer(&variant_writer); 564 writer->CloseContainer(&variant_writer);
564 } 565 }
565 566
566 // 567 //
567 // Property<std::map<std::string, std::string>> specialization. 568 // Property<std::map<std::string, std::string>> specialization.
568 // 569 //
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
622 !variant_reader.PopArray(&array_reader)) 623 !variant_reader.PopArray(&array_reader))
623 return false; 624 return false;
624 625
625 value_.clear(); 626 value_.clear();
626 while (array_reader.HasMoreData()) { 627 while (array_reader.HasMoreData()) {
627 dbus::MessageReader struct_reader(NULL); 628 dbus::MessageReader struct_reader(NULL);
628 if (!array_reader.PopStruct(&struct_reader)) 629 if (!array_reader.PopStruct(&struct_reader))
629 return false; 630 return false;
630 631
631 std::pair<std::vector<uint8_t>, uint16_t> entry; 632 std::pair<std::vector<uint8_t>, uint16_t> entry;
632 const uint8* bytes = NULL; 633 const uint8_t* bytes = NULL;
633 size_t length = 0; 634 size_t length = 0;
634 if (!struct_reader.PopArrayOfBytes(&bytes, &length)) 635 if (!struct_reader.PopArrayOfBytes(&bytes, &length))
635 return false; 636 return false;
636 entry.first.assign(bytes, bytes + length); 637 entry.first.assign(bytes, bytes + length);
637 if (!struct_reader.PopUint16(&entry.second)) 638 if (!struct_reader.PopUint16(&entry.second))
638 return false; 639 return false;
639 value_.push_back(entry); 640 value_.push_back(entry);
640 } 641 }
641 return true; 642 return true;
642 } 643 }
(...skipping 10 matching lines...) Expand all
653 array_writer.OpenStruct(&struct_writer); 654 array_writer.OpenStruct(&struct_writer);
654 struct_writer.AppendArrayOfBytes(std::get<0>(pair).data(), 655 struct_writer.AppendArrayOfBytes(std::get<0>(pair).data(),
655 std::get<0>(pair).size()); 656 std::get<0>(pair).size());
656 struct_writer.AppendUint16(std::get<1>(pair)); 657 struct_writer.AppendUint16(std::get<1>(pair));
657 array_writer.CloseContainer(&struct_writer); 658 array_writer.CloseContainer(&struct_writer);
658 } 659 }
659 variant_writer.CloseContainer(&array_writer); 660 variant_writer.CloseContainer(&array_writer);
660 writer->CloseContainer(&variant_writer); 661 writer->CloseContainer(&variant_writer);
661 } 662 }
662 663
663 template class Property<uint8>; 664 template class Property<uint8_t>;
664 template class Property<bool>; 665 template class Property<bool>;
665 template class Property<int16>; 666 template class Property<int16_t>;
666 template class Property<uint16>; 667 template class Property<uint16_t>;
667 template class Property<int32>; 668 template class Property<int32_t>;
668 template class Property<uint32>; 669 template class Property<uint32_t>;
669 template class Property<int64>; 670 template class Property<int64_t>;
670 template class Property<uint64>; 671 template class Property<uint64_t>;
671 template class Property<double>; 672 template class Property<double>;
672 template class Property<std::string>; 673 template class Property<std::string>;
673 template class Property<ObjectPath>; 674 template class Property<ObjectPath>;
674 template class Property<std::vector<std::string> >; 675 template class Property<std::vector<std::string> >;
675 template class Property<std::vector<ObjectPath> >; 676 template class Property<std::vector<ObjectPath> >;
676 template class Property<std::vector<uint8> >; 677 template class Property<std::vector<uint8_t>>;
677 template class Property<std::map<std::string, std::string>>; 678 template class Property<std::map<std::string, std::string>>;
678 template class Property<std::vector<std::pair<std::vector<uint8_t>, uint16_t>>>; 679 template class Property<std::vector<std::pair<std::vector<uint8_t>, uint16_t>>>;
679 680
680 } // namespace dbus 681 } // namespace dbus
OLDNEW
« no previous file with comments | « dbus/property.h ('k') | dbus/property_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698