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

Side by Side Diff: dbus/message.cc

Issue 8233042: Chrome OS: Attach bluetooth UI to device discovery API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 9 years, 2 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/message.h" 5 #include "dbus/message.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/format_macros.h" 8 #include "base/format_macros.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/stringprintf.h" 10 #include "base/stringprintf.h"
(...skipping 775 matching lines...) Expand 10 before | Expand all | Expand 10 after
786 return false; 786 return false;
787 while (array_reader.HasMoreData()) { 787 while (array_reader.HasMoreData()) {
788 std::string object_path; 788 std::string object_path;
789 if (!array_reader.PopObjectPath(&object_path)) 789 if (!array_reader.PopObjectPath(&object_path))
790 return false; 790 return false;
791 object_paths->push_back(object_path); 791 object_paths->push_back(object_path);
792 } 792 }
793 return true; 793 return true;
794 } 794 }
795 795
796 // TODO(vlaviano):
797 // - Can we handle integral types better?
798 // - Add support for nested complex types.
799 // - Write an equivalent function for MessageWriter.
800 // - Write unit tests.
801 bool MessageReader::PopArrayOfDictEntries(DictionaryValue* dictionary) {
802 CHECK(dictionary != NULL);
803 MessageReader array_reader(message_);
804 if (!PopArray(&array_reader)) {
805 return false;
806 }
807 while (array_reader.HasMoreData()) {
808 MessageReader dict_entry_reader(message_);
809 if (!array_reader.PopContainer(DBUS_TYPE_DICT_ENTRY, &dict_entry_reader)) {
810 return false;
811 }
812 std::string key;
813 if (!dict_entry_reader.PopString(&key)) {
814 return false;
815 }
816 MessageReader variant_reader(message_);
817 if (!dict_entry_reader.PopVariant(&variant_reader)) {
818 return false;
819 }
820 const Message::DataType type = variant_reader.GetDataType();
821 switch (type) {
822 case Message::BYTE: {
823 uint8 value = 0;
824 if (!variant_reader.PopByte(&value)) {
825 return false;
826 }
827 dictionary->SetInteger(key, value);
828 break;
829 }
830 case Message::BOOL: {
831 bool value = false;
832 if (!variant_reader.PopBool(&value)) {
833 return false;
834 }
835 dictionary->SetBoolean(key, value);
836 break;
837 }
838 case Message::INT16: {
839 int16 value = 0;
840 if (!variant_reader.PopInt16(&value)) {
841 return false;
842 }
843 dictionary->SetInteger(key, value);
844 break;
845 }
846 case Message::UINT16: {
847 uint16 value = 0;
848 if (!variant_reader.PopUint16(&value)) {
849 return false;
850 }
851 dictionary->SetInteger(key, value);
852 break;
853 }
854 case Message::INT32: {
855 int32 value = 0;
856 if (!variant_reader.PopInt32(&value)) {
857 return false;
858 }
859 dictionary->SetInteger(key, value);
860 break;
861 }
862 case Message::UINT32: {
863 uint32 value = 0;
864 if (!variant_reader.PopUint32(&value)) {
865 return false;
866 }
867 dictionary->SetInteger(key, value);
868 break;
869 }
870 case Message::INT64: {
871 int64 value = 0;
872 if (!variant_reader.PopInt64(&value)) {
873 return false;
874 }
875 dictionary->SetDouble(key, value);
876 break;
877 }
878 case Message::UINT64: {
879 uint64 value = 0;
880 if (!variant_reader.PopUint64(&value)) {
881 return false;
882 }
883 dictionary->SetDouble(key, value);
884 break;
885 }
886 case Message::DOUBLE: {
887 double value = 0;
888 if (!variant_reader.PopDouble(&value)) {
889 return false;
890 }
891 dictionary->SetDouble(key, value);
892 break;
893 }
894 case Message::STRING: {
895 std::string value;
896 if (!variant_reader.PopString(&value)) {
897 return false;
898 }
899 dictionary->SetString(key, value);
900 break;
901 }
902 case Message::OBJECT_PATH: {
903 std::string value;
904 if (!variant_reader.PopObjectPath(&value)) {
905 return false;
906 }
907 dictionary->SetString(key, value);
908 break;
909 }
910 case Message::ARRAY: {
911 // Not yet supported.
912 return false;
913 }
914 case Message::STRUCT: {
915 // Not yet supported.
916 return false;
917 }
918 case Message::DICT_ENTRY: {
919 // Not yet supported.
920 return false;
921 }
922 case Message::VARIANT: {
923 // Not yet supported.
924 return false;
925 }
926 default:
927 LOG(FATAL) << "Unknown type: " << type;
928 }
929 }
930 return true;
931 }
932
796 bool MessageReader::PopVariantOfByte(uint8* value) { 933 bool MessageReader::PopVariantOfByte(uint8* value) {
797 return PopVariantOfBasic(DBUS_TYPE_BYTE, value); 934 return PopVariantOfBasic(DBUS_TYPE_BYTE, value);
798 } 935 }
799 936
800 bool MessageReader::PopVariantOfBool(bool* value) { 937 bool MessageReader::PopVariantOfBool(bool* value) {
801 // See the comment at MessageReader::PopBool(). 938 // See the comment at MessageReader::PopBool().
802 dbus_bool_t dbus_value = FALSE; 939 dbus_bool_t dbus_value = FALSE;
803 const bool success = PopVariantOfBasic(DBUS_TYPE_BOOLEAN, &dbus_value); 940 const bool success = PopVariantOfBasic(DBUS_TYPE_BOOLEAN, &dbus_value);
804 *value = static_cast<bool>(dbus_value); 941 *value = static_cast<bool>(dbus_value);
805 return success; 942 return success;
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
888 } 1025 }
889 1026
890 bool MessageReader::PopVariantOfBasic(int dbus_type, void* value) { 1027 bool MessageReader::PopVariantOfBasic(int dbus_type, void* value) {
891 dbus::MessageReader variant_reader(message_); 1028 dbus::MessageReader variant_reader(message_);
892 if (!PopVariant(&variant_reader)) 1029 if (!PopVariant(&variant_reader))
893 return false; 1030 return false;
894 return variant_reader.PopBasic(dbus_type, value); 1031 return variant_reader.PopBasic(dbus_type, value);
895 } 1032 }
896 1033
897 } // namespace dbus 1034 } // namespace dbus
OLDNEW
« chrome/browser/resources/options/chromeos/bluetooth_list_element.js ('K') | « dbus/message.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698