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 "chromeos/dbus/ibus/ibus_object.h" | 5 #include "chromeos/dbus/ibus/ibus_object.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "dbus/message.h" | 8 #include "dbus/message.h" |
9 | 9 |
10 namespace chromeos { | 10 namespace chromeos { |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 DCHECK(contents_reader_.get()); | 85 DCHECK(contents_reader_.get()); |
86 return IsValid() && contents_reader_->PopString(out); | 86 return IsValid() && contents_reader_->PopString(out); |
87 } | 87 } |
88 | 88 |
89 bool IBusObjectReader::PopUint32(uint32* out) { | 89 bool IBusObjectReader::PopUint32(uint32* out) { |
90 DCHECK_NE(IBUS_OBJECT_NOT_CHECKED, check_result_); | 90 DCHECK_NE(IBUS_OBJECT_NOT_CHECKED, check_result_); |
91 DCHECK(contents_reader_.get()); | 91 DCHECK(contents_reader_.get()); |
92 return IsValid() && contents_reader_->PopUint32(out); | 92 return IsValid() && contents_reader_->PopUint32(out); |
93 } | 93 } |
94 | 94 |
| 95 bool IBusObjectReader::PopInt32(int32* out) { |
| 96 DCHECK_NE(IBUS_OBJECT_NOT_CHECKED, check_result_); |
| 97 DCHECK(contents_reader_.get()); |
| 98 return IsValid() && contents_reader_->PopInt32(out); |
| 99 } |
| 100 |
| 101 bool IBusObjectReader::PopBool(bool* out) { |
| 102 DCHECK_NE(IBUS_OBJECT_NOT_CHECKED, check_result_); |
| 103 DCHECK(contents_reader_.get()); |
| 104 return IsValid() && contents_reader_->PopBool(out); |
| 105 } |
| 106 |
95 bool IBusObjectReader::PopArray(dbus::MessageReader* reader) { | 107 bool IBusObjectReader::PopArray(dbus::MessageReader* reader) { |
96 DCHECK_NE(IBUS_OBJECT_NOT_CHECKED, check_result_); | 108 DCHECK_NE(IBUS_OBJECT_NOT_CHECKED, check_result_); |
97 DCHECK(contents_reader_.get()); | 109 DCHECK(contents_reader_.get()); |
98 return IsValid() && contents_reader_->PopArray(reader); | 110 return IsValid() && contents_reader_->PopArray(reader); |
99 } | 111 } |
100 | 112 |
101 bool IBusObjectReader::HasMoreData() { | 113 bool IBusObjectReader::HasMoreData() { |
102 DCHECK_NE(IBUS_OBJECT_NOT_CHECKED, check_result_); | 114 DCHECK_NE(IBUS_OBJECT_NOT_CHECKED, check_result_); |
103 DCHECK(contents_reader_.get()); | 115 DCHECK(contents_reader_.get()); |
104 return IsValid() && contents_reader_->HasMoreData(); | 116 return IsValid() && contents_reader_->HasMoreData(); |
105 } | 117 } |
106 | 118 |
107 bool IBusObjectReader::PopIBusObject(IBusObjectReader* reader) { | 119 bool IBusObjectReader::PopIBusObject(IBusObjectReader* reader) { |
108 DCHECK(contents_reader_.get()); | 120 DCHECK(contents_reader_.get()); |
109 if (!IsValid()) | 121 if (!IsValid()) |
110 return false; | 122 return false; |
111 return reader->InitWithParentReader(contents_reader_.get()); | 123 return reader->InitWithParentReader(contents_reader_.get()); |
112 } | 124 } |
113 | 125 |
114 bool IBusObjectReader::IsValid() const { | 126 bool IBusObjectReader::IsValid() const { |
115 DCHECK_NE(IBUS_OBJECT_NOT_CHECKED, check_result_); | 127 DCHECK_NE(IBUS_OBJECT_NOT_CHECKED, check_result_); |
116 return check_result_ == IBUS_OBJECT_VALID; | 128 return check_result_ == IBUS_OBJECT_VALID; |
117 } | 129 } |
118 | 130 |
| 131 dbus::MessageReader* IBusObjectReader::GetContentsReader() { |
| 132 DCHECK_NE(IBUS_OBJECT_NOT_CHECKED, check_result_); |
| 133 DCHECK(contents_reader_.get()); |
| 134 if (IsValid()) { |
| 135 return contents_reader_.get(); |
| 136 } else { |
| 137 return NULL; |
| 138 } |
| 139 } |
| 140 |
119 /////////////////////////////////////////////////////////////////////////////// | 141 /////////////////////////////////////////////////////////////////////////////// |
120 // IBusObjectWriter | 142 // IBusObjectWriter |
121 IBusObjectWriter::IBusObjectWriter(const std::string& type_name, | 143 IBusObjectWriter::IBusObjectWriter(const std::string& type_name, |
122 const std::string& signature, | 144 const std::string& signature, |
123 dbus::MessageWriter* writer) | 145 dbus::MessageWriter* writer) |
124 : type_name_(type_name), | 146 : type_name_(type_name), |
125 signature_(signature), | 147 signature_(signature), |
126 original_writer_(writer) { | 148 original_writer_(writer) { |
127 if (original_writer_) | 149 if (original_writer_) |
128 Init(); | 150 Init(); |
129 } | 151 } |
130 | 152 |
131 IBusObjectWriter::~IBusObjectWriter() { | 153 IBusObjectWriter::~IBusObjectWriter() { |
132 } | 154 } |
133 | 155 |
134 void IBusObjectWriter::AppendString(const std::string& input) { | 156 void IBusObjectWriter::AppendString(const std::string& input) { |
135 DCHECK(IsInitialized()); | 157 DCHECK(IsInitialized()); |
136 contents_writer_->AppendString(input); | 158 contents_writer_->AppendString(input); |
137 } | 159 } |
138 | 160 |
139 void IBusObjectWriter::AppendUint32(uint32 input) { | 161 void IBusObjectWriter::AppendUint32(uint32 input) { |
140 DCHECK(IsInitialized()); | 162 DCHECK(IsInitialized()); |
141 contents_writer_->AppendUint32(input); | 163 contents_writer_->AppendUint32(input); |
142 } | 164 } |
143 | 165 |
| 166 void IBusObjectWriter::AppendInt32(int32 input) { |
| 167 DCHECK(IsInitialized()); |
| 168 contents_writer_->AppendInt32(input); |
| 169 } |
| 170 |
| 171 void IBusObjectWriter::AppendBool(bool input) { |
| 172 DCHECK(IsInitialized()); |
| 173 contents_writer_->AppendBool(input); |
| 174 } |
| 175 |
144 void IBusObjectWriter::OpenArray(const std::string& signature, | 176 void IBusObjectWriter::OpenArray(const std::string& signature, |
145 dbus::MessageWriter* writer) { | 177 dbus::MessageWriter* writer) { |
146 DCHECK(IsInitialized()); | 178 DCHECK(IsInitialized()); |
147 contents_writer_->OpenArray(signature, writer); | 179 contents_writer_->OpenArray(signature, writer); |
148 } | 180 } |
149 | 181 |
150 void IBusObjectWriter::CloseContainer(dbus::MessageWriter* writer) { | 182 void IBusObjectWriter::CloseContainer(dbus::MessageWriter* writer) { |
151 DCHECK(IsInitialized()); | 183 DCHECK(IsInitialized()); |
152 contents_writer_->CloseContainer(writer); | 184 contents_writer_->CloseContainer(writer); |
153 } | 185 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 top_variant_writer_->CloseContainer(contents_writer_.get()); | 223 top_variant_writer_->CloseContainer(contents_writer_.get()); |
192 original_writer_->CloseContainer(top_variant_writer_.get()); | 224 original_writer_->CloseContainer(top_variant_writer_.get()); |
193 top_variant_writer_.reset(); | 225 top_variant_writer_.reset(); |
194 contents_writer_.reset(); | 226 contents_writer_.reset(); |
195 } | 227 } |
196 | 228 |
197 bool IBusObjectWriter::IsInitialized() const { | 229 bool IBusObjectWriter::IsInitialized() const { |
198 return contents_writer_.get() != NULL; | 230 return contents_writer_.get() != NULL; |
199 } | 231 } |
200 | 232 |
| 233 dbus::MessageWriter* IBusObjectWriter::GetContentsWriter() { |
| 234 DCHECK(contents_writer_.get()); |
| 235 if (IsInitialized()) { |
| 236 return contents_writer_.get(); |
| 237 } else { |
| 238 return NULL; |
| 239 } |
| 240 } |
| 241 |
201 } // namespace chromeos | 242 } // namespace chromeos |
OLD | NEW |