OLD | NEW |
---|---|
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 "base/basictypes.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 | 10 |
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
471 | 471 |
472 template <> | 472 template <> |
473 void Property<std::vector<uint8> >::AppendSetValueToWriter( | 473 void Property<std::vector<uint8> >::AppendSetValueToWriter( |
474 MessageWriter* writer) { | 474 MessageWriter* writer) { |
475 MessageWriter variant_writer(NULL); | 475 MessageWriter variant_writer(NULL); |
476 writer->OpenVariant("ay", &variant_writer); | 476 writer->OpenVariant("ay", &variant_writer); |
477 variant_writer.AppendArrayOfBytes(set_value_.data(), set_value_.size()); | 477 variant_writer.AppendArrayOfBytes(set_value_.data(), set_value_.size()); |
478 writer->CloseContainer(&variant_writer); | 478 writer->CloseContainer(&variant_writer); |
479 } | 479 } |
480 | 480 |
481 // | |
482 // Property<std::map<std::string, std::string>> specialization. | |
483 // | |
484 | |
485 template <> | |
486 bool Property<std::map<std::string, std::string>>::PopValueFromReader( | |
487 MessageReader* reader) { | |
488 MessageReader variant_reader(NULL); | |
489 MessageReader array_reader(NULL); | |
490 if (!reader->PopVariant(&variant_reader) || | |
491 !variant_reader.PopArray(&array_reader)) | |
492 return false; | |
493 value_.clear(); | |
494 while (array_reader.HasMoreData()) { | |
495 dbus::MessageReader dict_entry_reader(NULL); | |
496 if (!array_reader.PopDictEntry(&dict_entry_reader)) | |
497 return false; | |
498 std::string key; | |
499 std::string value; | |
500 if (!dict_entry_reader.PopString(&key) || | |
501 !dict_entry_reader.PopString(&value)) | |
502 return false; | |
503 value_[key] = value; | |
504 } | |
505 return true; | |
506 } | |
507 | |
508 template <> | |
509 void Property<std::map<std::string, std::string>>::AppendSetValueToWriter( | |
510 MessageWriter* writer) { | |
511 MessageWriter variant_writer(NULL); | |
512 MessageWriter dict_writer(NULL); | |
513 writer->OpenVariant("a{ss}", &variant_writer); | |
514 variant_writer.OpenArray("{ss}", &dict_writer); | |
515 for (const auto& pair : set_value_) { | |
516 dbus::MessageWriter entry_writer(NULL); | |
517 dict_writer.OpenDictEntry(&entry_writer); | |
518 entry_writer.AppendString(pair.first); | |
519 entry_writer.AppendString(pair.second); | |
520 dict_writer.CloseContainer(&entry_writer); | |
521 } | |
522 variant_writer.CloseContainer(&dict_writer); | |
523 writer->CloseContainer(&variant_writer); | |
524 } | |
525 | |
526 // | |
527 // Propertystd::vector<std::pair<std::vector<uint8_t>, uint16_t>>> | |
hashimoto
2015/02/06 07:45:12
nit: "<" after Property is missing .
dtapuska
2015/02/06 15:56:01
Done.
| |
528 // specialization. | |
529 // | |
530 | |
531 template <> | |
532 bool Property<std::vector<std::pair<std::vector<uint8_t>, uint16_t>>>:: | |
533 PopValueFromReader(MessageReader* reader) { | |
534 MessageReader variant_reader(NULL); | |
535 MessageReader array_reader(NULL); | |
536 if (!reader->PopVariant(&variant_reader) || | |
537 !variant_reader.PopArray(&array_reader)) | |
538 return false; | |
539 | |
540 value_.clear(); | |
541 while (array_reader.HasMoreData()) { | |
542 dbus::MessageReader struct_reader(NULL); | |
543 if (!array_reader.PopStruct(&struct_reader)) | |
544 return false; | |
545 | |
546 std::pair<std::vector<uint8_t>, uint16_t> entry; | |
547 const uint8* bytes = NULL; | |
548 size_t length = 0; | |
549 if (!struct_reader.PopArrayOfBytes(&bytes, &length)) | |
550 return false; | |
551 entry.first.assign(bytes, bytes + length); | |
552 if (!struct_reader.PopUint16(&entry.second)) | |
553 return false; | |
554 value_.push_back(entry); | |
555 } | |
556 return true; | |
557 } | |
558 | |
559 template <> | |
560 void Property<std::vector<std::pair<std::vector<uint8_t>, uint16_t>>>:: | |
561 AppendSetValueToWriter(MessageWriter* writer) { | |
562 MessageWriter variant_writer(NULL); | |
563 MessageWriter array_writer(NULL); | |
564 writer->OpenVariant("a(ayq)", &variant_writer); | |
565 variant_writer.OpenArray("(ayq)", &array_writer); | |
566 for (const auto& pair : set_value_) { | |
567 dbus::MessageWriter struct_writer(nullptr); | |
568 array_writer.OpenStruct(&struct_writer); | |
569 struct_writer.AppendArrayOfBytes(std::get<0>(pair).data(), | |
570 std::get<0>(pair).size()); | |
571 struct_writer.AppendUint16(std::get<1>(pair)); | |
572 array_writer.CloseContainer(&struct_writer); | |
573 } | |
574 variant_writer.CloseContainer(&array_writer); | |
575 writer->CloseContainer(&variant_writer); | |
576 } | |
577 | |
481 template class Property<uint8>; | 578 template class Property<uint8>; |
482 template class Property<bool>; | 579 template class Property<bool>; |
483 template class Property<int16>; | 580 template class Property<int16>; |
484 template class Property<uint16>; | 581 template class Property<uint16>; |
485 template class Property<int32>; | 582 template class Property<int32>; |
486 template class Property<uint32>; | 583 template class Property<uint32>; |
487 template class Property<int64>; | 584 template class Property<int64>; |
488 template class Property<uint64>; | 585 template class Property<uint64>; |
489 template class Property<double>; | 586 template class Property<double>; |
490 template class Property<std::string>; | 587 template class Property<std::string>; |
491 template class Property<ObjectPath>; | 588 template class Property<ObjectPath>; |
492 template class Property<std::vector<std::string> >; | 589 template class Property<std::vector<std::string> >; |
493 template class Property<std::vector<ObjectPath> >; | 590 template class Property<std::vector<ObjectPath> >; |
494 template class Property<std::vector<uint8> >; | 591 template class Property<std::vector<uint8> >; |
592 template class Property<std::map<std::string, std::string>>; | |
593 template class Property<std::vector<std::pair<std::vector<uint8_t>, uint16_t>>>; | |
495 | 594 |
496 } // namespace dbus | 595 } // namespace dbus |
OLD | NEW |