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

Side by Side Diff: dbus/property.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
« dbus/property.h ('K') | « dbus/property.h ('k') | no next file » | 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 "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
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.
hashimoto 2015/02/05 09:51:12 nit: No need for space in "> >". The same goes for
dtapuska 2015/02/05 19:51:17 Done.
483 //
484
485 template <>
486 bool Property<std::map<std::string, std::string>>::PopValueFromReader(
487 MessageReader* reader) {
488 MessageReader array_reader(NULL);
hashimoto 2015/02/05 09:51:12 nit: Please move this line to the line before PopA
dtapuska 2015/02/05 19:51:17 Done.
489 MessageReader variant_reader(NULL);
490 if (!reader->PopVariant(&variant_reader))
491 return false;
492 if (!variant_reader.PopArray(&array_reader))
493 return false;
494 value_.clear();
495 while (array_reader.HasMoreData()) {
496 dbus::MessageReader dict_entry_reader(NULL);
497 if (!array_reader.PopDictEntry(&dict_entry_reader))
498 return false;
499 std::string key;
500 std::string value;
501 if (!dict_entry_reader.PopString(&key) ||
502 !dict_entry_reader.PopString(&value))
503 return false;
504 value_.emplace(std::move(key), std::move(value));
hashimoto 2015/02/05 09:51:12 move is not allowed yet. http://chromium-cpp.appsp
dtapuska 2015/02/05 19:51:17 Done.
505 }
506 return true;
507 }
508
509 template <>
510 void Property<std::map<std::string, std::string>>::AppendSetValueToWriter(
511 MessageWriter* writer) {
512 MessageWriter variant_writer(NULL);
513 MessageWriter dict_writer(NULL);
514 writer->OpenVariant("a{ss}", &variant_writer);
515 variant_writer.OpenArray("{ss}", &dict_writer);
516 for (const auto& pair : set_value_) {
517 dbus::MessageWriter entry_writer(NULL);
518 dict_writer.OpenDictEntry(&entry_writer);
519 entry_writer.AppendString(pair.first);
520 entry_writer.AppendString(pair.second);
521 dict_writer.CloseContainer(&entry_writer);
522 }
523 variant_writer.CloseContainer(&dict_writer);
524 writer->CloseContainer(&variant_writer);
525 }
526
527 //
528 // Propertystd::vector<std::tuple<std::vector<uint8_t>, uint16_t> > >
hashimoto 2015/02/05 09:51:12 nit: Property<std::vector<std::tuple<std::vector<u
dtapuska 2015/02/05 19:51:17 Done.
529 // specialization.
530 //
531
532 template <>
533 bool Property<std::vector<std::tuple<std::vector<uint8_t>, uint16_t>>>::
534 PopValueFromReader(MessageReader* reader) {
535 MessageReader array_reader(NULL);
536 MessageReader variant_reader(NULL);
537 if (!reader->PopVariant(&variant_reader))
538 return false;
539 if (!variant_reader.PopArray(&array_reader))
540 return false;
541
542 value_.clear();
543 while (array_reader.HasMoreData()) {
544 dbus::MessageReader struct_reader(NULL);
545 if (!array_reader.PopStruct(&struct_reader))
546 return false;
547
548 std::tuple<std::vector<uint8_t>, uint16_t> entry;
549 const uint8* bytes = NULL;
550 size_t length = 0;
551 if (!struct_reader.PopArrayOfBytes(&bytes, &length))
552 return false;
553 std::get<0>(entry).assign(bytes, bytes + length);
554 if (!struct_reader.PopUint16(&std::get<1>(entry)))
555 return false;
556 value_.push_back(std::move(entry));
557 }
558 return true;
559 }
560
561 template <>
562 void Property<std::vector<std::tuple<std::vector<uint8_t>, uint16_t>>>::
563 AppendSetValueToWriter(MessageWriter* writer) {
564 MessageWriter variant_writer(NULL);
565 MessageWriter array_writer(NULL);
566 writer->OpenVariant("a(ayq)", &variant_writer);
567 variant_writer.OpenArray("a(ayq)", &array_writer);
568 for (const auto& pair : set_value_) {
569 dbus::MessageWriter struct_writer(nullptr);
570 array_writer.OpenStruct(&struct_writer);
571 struct_writer.AppendArrayOfBytes(std::get<0>(pair).data(),
572 std::get<0>(pair).size());
573 struct_writer.AppendUint16(std::get<1>(pair));
574 array_writer.CloseContainer(&struct_writer);
575 }
576 variant_writer.CloseContainer(&array_writer);
577 writer->CloseContainer(&variant_writer);
578 }
satorux1 2015/02/05 08:20:15 The new functions have lots of logic. Could you ad
579
481 template class Property<uint8>; 580 template class Property<uint8>;
482 template class Property<bool>; 581 template class Property<bool>;
483 template class Property<int16>; 582 template class Property<int16>;
484 template class Property<uint16>; 583 template class Property<uint16>;
485 template class Property<int32>; 584 template class Property<int32>;
486 template class Property<uint32>; 585 template class Property<uint32>;
487 template class Property<int64>; 586 template class Property<int64>;
488 template class Property<uint64>; 587 template class Property<uint64>;
489 template class Property<double>; 588 template class Property<double>;
490 template class Property<std::string>; 589 template class Property<std::string>;
491 template class Property<ObjectPath>; 590 template class Property<ObjectPath>;
492 template class Property<std::vector<std::string> >; 591 template class Property<std::vector<std::string> >;
493 template class Property<std::vector<ObjectPath> >; 592 template class Property<std::vector<ObjectPath> >;
494 template class Property<std::vector<uint8> >; 593 template class Property<std::vector<uint8> >;
594 template class Property<std::map<std::string, std::string>>;
595 template class Property<
596 std::vector<std::tuple<std::vector<uint8_t>, uint16_t>>>;
495 597
496 } // namespace dbus 598 } // namespace dbus
OLDNEW
« dbus/property.h ('K') | « dbus/property.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698