keybuk@chromium.org | 7e0c493 | 2012-02-15 13:21:08 +0900 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "dbus/property.h" |
| 6 | |
avi | 0ad0ce0 | 2015-12-23 03:12:45 +0900 | [diff] [blame] | 7 | #include <stddef.h> |
| 8 | |
puthik | 90fd20c | 2016-10-06 14:03:03 +0900 | [diff] [blame] | 9 | #include <memory> |
| 10 | |
keybuk@chromium.org | 7e0c493 | 2012-02-15 13:21:08 +0900 | [diff] [blame] | 11 | #include "base/bind.h" |
| 12 | #include "base/logging.h" |
| 13 | |
| 14 | #include "dbus/message.h" |
| 15 | #include "dbus/object_path.h" |
| 16 | #include "dbus/object_proxy.h" |
| 17 | |
| 18 | namespace dbus { |
| 19 | |
| 20 | // |
| 21 | // PropertyBase implementation. |
| 22 | // |
| 23 | |
derat | 3f868a4 | 2015-07-17 00:06:44 +0900 | [diff] [blame] | 24 | PropertyBase::PropertyBase() : property_set_(nullptr), is_valid_(false) {} |
| 25 | |
Chris Watkins | 635e890 | 2017-11-29 16:44:11 +0900 | [diff] [blame] | 26 | PropertyBase::~PropertyBase() = default; |
derat | 3f868a4 | 2015-07-17 00:06:44 +0900 | [diff] [blame] | 27 | |
keybuk@chromium.org | 7e0c493 | 2012-02-15 13:21:08 +0900 | [diff] [blame] | 28 | void PropertyBase::Init(PropertySet* property_set, const std::string& name) { |
| 29 | DCHECK(!property_set_); |
| 30 | property_set_ = property_set; |
jpawlowski | 77e73fc | 2015-05-11 20:07:04 +0900 | [diff] [blame] | 31 | is_valid_ = false; |
keybuk@chromium.org | 7e0c493 | 2012-02-15 13:21:08 +0900 | [diff] [blame] | 32 | name_ = name; |
| 33 | } |
| 34 | |
keybuk@chromium.org | 7e0c493 | 2012-02-15 13:21:08 +0900 | [diff] [blame] | 35 | // |
| 36 | // PropertySet implementation. |
| 37 | // |
| 38 | |
keybuk@chromium.org | b45e529 | 2012-08-15 10:03:30 +0900 | [diff] [blame] | 39 | PropertySet::PropertySet( |
| 40 | ObjectProxy* object_proxy, |
| 41 | const std::string& interface, |
| 42 | const PropertyChangedCallback& property_changed_callback) |
keybuk@chromium.org | 7e0c493 | 2012-02-15 13:21:08 +0900 | [diff] [blame] | 43 | : object_proxy_(object_proxy), |
| 44 | interface_(interface), |
| 45 | property_changed_callback_(property_changed_callback), |
| 46 | weak_ptr_factory_(this) {} |
| 47 | |
Chris Watkins | 635e890 | 2017-11-29 16:44:11 +0900 | [diff] [blame] | 48 | PropertySet::~PropertySet() = default; |
keybuk@chromium.org | 7e0c493 | 2012-02-15 13:21:08 +0900 | [diff] [blame] | 49 | |
| 50 | void PropertySet::RegisterProperty(const std::string& name, |
| 51 | PropertyBase* property) { |
| 52 | property->Init(this, name); |
| 53 | properties_map_[name] = property; |
| 54 | } |
| 55 | |
| 56 | void PropertySet::ConnectSignals() { |
| 57 | DCHECK(object_proxy_); |
| 58 | object_proxy_->ConnectToSignal( |
| 59 | kPropertiesInterface, |
| 60 | kPropertiesChanged, |
| 61 | base::Bind(&PropertySet::ChangedReceived, |
| 62 | weak_ptr_factory_.GetWeakPtr()), |
| 63 | base::Bind(&PropertySet::ChangedConnected, |
| 64 | weak_ptr_factory_.GetWeakPtr())); |
| 65 | } |
| 66 | |
| 67 | |
| 68 | void PropertySet::ChangedReceived(Signal* signal) { |
keybuk@chromium.org | 7e0c493 | 2012-02-15 13:21:08 +0900 | [diff] [blame] | 69 | DCHECK(signal); |
keybuk@chromium.org | 7e0c493 | 2012-02-15 13:21:08 +0900 | [diff] [blame] | 70 | MessageReader reader(signal); |
| 71 | |
| 72 | std::string interface; |
| 73 | if (!reader.PopString(&interface)) { |
| 74 | LOG(WARNING) << "Property changed signal has wrong parameters: " |
| 75 | << "expected interface name: " << signal->ToString(); |
| 76 | return; |
| 77 | } |
| 78 | |
| 79 | if (interface != this->interface()) |
| 80 | return; |
| 81 | |
| 82 | if (!UpdatePropertiesFromReader(&reader)) { |
| 83 | LOG(WARNING) << "Property changed signal has wrong parameters: " |
| 84 | << "expected dictionary: " << signal->ToString(); |
| 85 | } |
| 86 | |
jpawlowski | 77e73fc | 2015-05-11 20:07:04 +0900 | [diff] [blame] | 87 | if (!InvalidatePropertiesFromReader(&reader)) { |
| 88 | LOG(WARNING) << "Property changed signal has wrong parameters: " |
| 89 | << "expected array to invalidate: " << signal->ToString(); |
| 90 | } |
keybuk@chromium.org | 7e0c493 | 2012-02-15 13:21:08 +0900 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | void PropertySet::ChangedConnected(const std::string& interface_name, |
| 94 | const std::string& signal_name, |
| 95 | bool success) { |
| 96 | LOG_IF(WARNING, !success) << "Failed to connect to " << signal_name |
| 97 | << "signal."; |
| 98 | } |
| 99 | |
| 100 | |
keybuk@chromium.org | 56028ac | 2012-06-29 03:43:30 +0900 | [diff] [blame] | 101 | void PropertySet::Get(PropertyBase* property, GetCallback callback) { |
| 102 | MethodCall method_call(kPropertiesInterface, kPropertiesGet); |
| 103 | MessageWriter writer(&method_call); |
| 104 | writer.AppendString(interface()); |
| 105 | writer.AppendString(property->name()); |
| 106 | |
| 107 | DCHECK(object_proxy_); |
| 108 | object_proxy_->CallMethod(&method_call, |
| 109 | ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 110 | base::Bind(&PropertySet::OnGet, |
| 111 | GetWeakPtr(), |
| 112 | property, |
| 113 | callback)); |
| 114 | } |
| 115 | |
| 116 | void PropertySet::OnGet(PropertyBase* property, GetCallback callback, |
| 117 | Response* response) { |
| 118 | if (!response) { |
| 119 | LOG(WARNING) << property->name() << ": Get: failed."; |
| 120 | return; |
| 121 | } |
| 122 | |
| 123 | MessageReader reader(response); |
jpawlowski | 77e73fc | 2015-05-11 20:07:04 +0900 | [diff] [blame] | 124 | if (property->PopValueFromReader(&reader)) { |
| 125 | property->set_valid(true); |
keybuk@chromium.org | 56028ac | 2012-06-29 03:43:30 +0900 | [diff] [blame] | 126 | NotifyPropertyChanged(property->name()); |
jpawlowski | 77e73fc | 2015-05-11 20:07:04 +0900 | [diff] [blame] | 127 | } else { |
| 128 | if (property->is_valid()) { |
| 129 | property->set_valid(false); |
| 130 | NotifyPropertyChanged(property->name()); |
| 131 | } |
| 132 | } |
keybuk@chromium.org | 56028ac | 2012-06-29 03:43:30 +0900 | [diff] [blame] | 133 | |
| 134 | if (!callback.is_null()) |
| 135 | callback.Run(response); |
| 136 | } |
| 137 | |
nywang | 80f2716 | 2015-09-29 07:46:36 +0900 | [diff] [blame] | 138 | bool PropertySet::GetAndBlock(PropertyBase* property) { |
| 139 | MethodCall method_call(kPropertiesInterface, kPropertiesGet); |
| 140 | MessageWriter writer(&method_call); |
| 141 | writer.AppendString(interface()); |
| 142 | writer.AppendString(property->name()); |
| 143 | |
| 144 | DCHECK(object_proxy_); |
dcheng | 30c5a17 | 2016-04-09 07:55:04 +0900 | [diff] [blame] | 145 | std::unique_ptr<dbus::Response> response(object_proxy_->CallMethodAndBlock( |
| 146 | &method_call, ObjectProxy::TIMEOUT_USE_DEFAULT)); |
nywang | 80f2716 | 2015-09-29 07:46:36 +0900 | [diff] [blame] | 147 | |
| 148 | if (!response.get()) { |
| 149 | LOG(WARNING) << property->name() << ": GetAndBlock: failed."; |
| 150 | return false; |
| 151 | } |
| 152 | |
| 153 | MessageReader reader(response.get()); |
| 154 | if (property->PopValueFromReader(&reader)) { |
| 155 | property->set_valid(true); |
| 156 | NotifyPropertyChanged(property->name()); |
| 157 | } else { |
| 158 | if (property->is_valid()) { |
| 159 | property->set_valid(false); |
| 160 | NotifyPropertyChanged(property->name()); |
| 161 | } |
| 162 | } |
| 163 | return true; |
| 164 | } |
| 165 | |
keybuk@chromium.org | 7e0c493 | 2012-02-15 13:21:08 +0900 | [diff] [blame] | 166 | void PropertySet::GetAll() { |
| 167 | MethodCall method_call(kPropertiesInterface, kPropertiesGetAll); |
| 168 | MessageWriter writer(&method_call); |
| 169 | writer.AppendString(interface()); |
| 170 | |
| 171 | DCHECK(object_proxy_); |
| 172 | object_proxy_->CallMethod(&method_call, |
| 173 | ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 174 | base::Bind(&PropertySet::OnGetAll, |
| 175 | weak_ptr_factory_.GetWeakPtr())); |
| 176 | } |
| 177 | |
| 178 | void PropertySet::OnGetAll(Response* response) { |
keybuk@chromium.org | 7e0c493 | 2012-02-15 13:21:08 +0900 | [diff] [blame] | 179 | if (!response) { |
stevenjb@chromium.org | fa639cc | 2014-07-17 14:03:53 +0900 | [diff] [blame] | 180 | LOG(WARNING) << "GetAll request failed for: " << interface_; |
keybuk@chromium.org | 7e0c493 | 2012-02-15 13:21:08 +0900 | [diff] [blame] | 181 | return; |
| 182 | } |
| 183 | |
| 184 | MessageReader reader(response); |
| 185 | if (!UpdatePropertiesFromReader(&reader)) { |
| 186 | LOG(WARNING) << "GetAll response has wrong parameters: " |
| 187 | << "expected dictionary: " << response->ToString(); |
| 188 | } |
| 189 | } |
| 190 | |
keybuk@chromium.org | 56028ac | 2012-06-29 03:43:30 +0900 | [diff] [blame] | 191 | void PropertySet::Set(PropertyBase* property, SetCallback callback) { |
| 192 | MethodCall method_call(kPropertiesInterface, kPropertiesSet); |
| 193 | MessageWriter writer(&method_call); |
| 194 | writer.AppendString(interface()); |
| 195 | writer.AppendString(property->name()); |
| 196 | property->AppendSetValueToWriter(&writer); |
| 197 | |
| 198 | DCHECK(object_proxy_); |
| 199 | object_proxy_->CallMethod(&method_call, |
| 200 | ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 201 | base::Bind(&PropertySet::OnSet, |
| 202 | GetWeakPtr(), |
| 203 | property, |
| 204 | callback)); |
| 205 | } |
| 206 | |
nywang | f119681 | 2015-09-23 09:06:40 +0900 | [diff] [blame] | 207 | bool PropertySet::SetAndBlock(PropertyBase* property) { |
| 208 | MethodCall method_call(kPropertiesInterface, kPropertiesSet); |
| 209 | MessageWriter writer(&method_call); |
| 210 | writer.AppendString(interface()); |
| 211 | writer.AppendString(property->name()); |
| 212 | property->AppendSetValueToWriter(&writer); |
| 213 | |
| 214 | DCHECK(object_proxy_); |
dcheng | 30c5a17 | 2016-04-09 07:55:04 +0900 | [diff] [blame] | 215 | std::unique_ptr<dbus::Response> response(object_proxy_->CallMethodAndBlock( |
| 216 | &method_call, ObjectProxy::TIMEOUT_USE_DEFAULT)); |
nywang | f119681 | 2015-09-23 09:06:40 +0900 | [diff] [blame] | 217 | if (response.get()) |
| 218 | return true; |
| 219 | return false; |
| 220 | } |
| 221 | |
stevenjb@chromium.org | fa639cc | 2014-07-17 14:03:53 +0900 | [diff] [blame] | 222 | void PropertySet::OnSet(PropertyBase* property, |
| 223 | SetCallback callback, |
keybuk@chromium.org | 56028ac | 2012-06-29 03:43:30 +0900 | [diff] [blame] | 224 | Response* response) { |
| 225 | LOG_IF(WARNING, !response) << property->name() << ": Set: failed."; |
| 226 | if (!callback.is_null()) |
| 227 | callback.Run(response); |
| 228 | } |
keybuk@chromium.org | 7e0c493 | 2012-02-15 13:21:08 +0900 | [diff] [blame] | 229 | |
| 230 | bool PropertySet::UpdatePropertiesFromReader(MessageReader* reader) { |
| 231 | DCHECK(reader); |
Ben Chan | 333256c | 2017-11-10 05:20:16 +0900 | [diff] [blame] | 232 | MessageReader array_reader(nullptr); |
keybuk@chromium.org | 7e0c493 | 2012-02-15 13:21:08 +0900 | [diff] [blame] | 233 | if (!reader->PopArray(&array_reader)) |
| 234 | return false; |
| 235 | |
| 236 | while (array_reader.HasMoreData()) { |
Ben Chan | 333256c | 2017-11-10 05:20:16 +0900 | [diff] [blame] | 237 | MessageReader dict_entry_reader(nullptr); |
keybuk@chromium.org | 683dd8c | 2012-03-23 05:34:05 +0900 | [diff] [blame] | 238 | if (array_reader.PopDictEntry(&dict_entry_reader)) |
| 239 | UpdatePropertyFromReader(&dict_entry_reader); |
keybuk@chromium.org | 7e0c493 | 2012-02-15 13:21:08 +0900 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | return true; |
| 243 | } |
| 244 | |
| 245 | bool PropertySet::UpdatePropertyFromReader(MessageReader* reader) { |
| 246 | DCHECK(reader); |
| 247 | |
| 248 | std::string name; |
| 249 | if (!reader->PopString(&name)) |
| 250 | return false; |
| 251 | |
| 252 | PropertiesMap::iterator it = properties_map_.find(name); |
| 253 | if (it == properties_map_.end()) |
| 254 | return false; |
| 255 | |
| 256 | PropertyBase* property = it->second; |
| 257 | if (property->PopValueFromReader(reader)) { |
jpawlowski | 77e73fc | 2015-05-11 20:07:04 +0900 | [diff] [blame] | 258 | property->set_valid(true); |
keybuk@chromium.org | 7e0c493 | 2012-02-15 13:21:08 +0900 | [diff] [blame] | 259 | NotifyPropertyChanged(name); |
| 260 | return true; |
| 261 | } else { |
jpawlowski | 77e73fc | 2015-05-11 20:07:04 +0900 | [diff] [blame] | 262 | if (property->is_valid()) { |
| 263 | property->set_valid(false); |
| 264 | NotifyPropertyChanged(property->name()); |
| 265 | } |
keybuk@chromium.org | 7e0c493 | 2012-02-15 13:21:08 +0900 | [diff] [blame] | 266 | return false; |
| 267 | } |
| 268 | } |
| 269 | |
jpawlowski | 77e73fc | 2015-05-11 20:07:04 +0900 | [diff] [blame] | 270 | bool PropertySet::InvalidatePropertiesFromReader(MessageReader* reader) { |
| 271 | DCHECK(reader); |
Ben Chan | 333256c | 2017-11-10 05:20:16 +0900 | [diff] [blame] | 272 | MessageReader array_reader(nullptr); |
jpawlowski | 77e73fc | 2015-05-11 20:07:04 +0900 | [diff] [blame] | 273 | if (!reader->PopArray(&array_reader)) |
| 274 | return false; |
| 275 | |
| 276 | while (array_reader.HasMoreData()) { |
| 277 | std::string name; |
| 278 | if (!array_reader.PopString(&name)) |
| 279 | return false; |
| 280 | |
| 281 | PropertiesMap::iterator it = properties_map_.find(name); |
| 282 | if (it == properties_map_.end()) |
| 283 | continue; |
| 284 | |
| 285 | PropertyBase* property = it->second; |
| 286 | if (property->is_valid()) { |
| 287 | property->set_valid(false); |
| 288 | NotifyPropertyChanged(property->name()); |
| 289 | } |
| 290 | } |
| 291 | |
| 292 | return true; |
| 293 | } |
keybuk@chromium.org | 7e0c493 | 2012-02-15 13:21:08 +0900 | [diff] [blame] | 294 | |
| 295 | void PropertySet::NotifyPropertyChanged(const std::string& name) { |
| 296 | if (!property_changed_callback_.is_null()) |
| 297 | property_changed_callback_.Run(name); |
| 298 | } |
| 299 | |
| 300 | // |
| 301 | // Property<Byte> specialization. |
| 302 | // |
| 303 | |
| 304 | template <> |
avi | 0ad0ce0 | 2015-12-23 03:12:45 +0900 | [diff] [blame] | 305 | Property<uint8_t>::Property() |
| 306 | : value_(0) {} |
keybuk@chromium.org | 7e0c493 | 2012-02-15 13:21:08 +0900 | [diff] [blame] | 307 | |
| 308 | template <> |
avi | 0ad0ce0 | 2015-12-23 03:12:45 +0900 | [diff] [blame] | 309 | bool Property<uint8_t>::PopValueFromReader(MessageReader* reader) { |
keybuk@chromium.org | 7e0c493 | 2012-02-15 13:21:08 +0900 | [diff] [blame] | 310 | return reader->PopVariantOfByte(&value_); |
| 311 | } |
| 312 | |
| 313 | template <> |
avi | 0ad0ce0 | 2015-12-23 03:12:45 +0900 | [diff] [blame] | 314 | void Property<uint8_t>::AppendSetValueToWriter(MessageWriter* writer) { |
keybuk@chromium.org | 56028ac | 2012-06-29 03:43:30 +0900 | [diff] [blame] | 315 | writer->AppendVariantOfByte(set_value_); |
keybuk@chromium.org | 7e0c493 | 2012-02-15 13:21:08 +0900 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | // |
| 319 | // Property<bool> specialization. |
| 320 | // |
| 321 | |
| 322 | template <> |
keybuk@chromium.org | 56028ac | 2012-06-29 03:43:30 +0900 | [diff] [blame] | 323 | Property<bool>::Property() : value_(false) { |
keybuk@chromium.org | 7e0c493 | 2012-02-15 13:21:08 +0900 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | template <> |
| 327 | bool Property<bool>::PopValueFromReader(MessageReader* reader) { |
| 328 | return reader->PopVariantOfBool(&value_); |
| 329 | } |
| 330 | |
| 331 | template <> |
keybuk@chromium.org | 56028ac | 2012-06-29 03:43:30 +0900 | [diff] [blame] | 332 | void Property<bool>::AppendSetValueToWriter(MessageWriter* writer) { |
| 333 | writer->AppendVariantOfBool(set_value_); |
keybuk@chromium.org | 7e0c493 | 2012-02-15 13:21:08 +0900 | [diff] [blame] | 334 | } |
| 335 | |
| 336 | // |
avi | 0ad0ce0 | 2015-12-23 03:12:45 +0900 | [diff] [blame] | 337 | // Property<int16_t> specialization. |
keybuk@chromium.org | 7e0c493 | 2012-02-15 13:21:08 +0900 | [diff] [blame] | 338 | // |
| 339 | |
| 340 | template <> |
avi | 0ad0ce0 | 2015-12-23 03:12:45 +0900 | [diff] [blame] | 341 | Property<int16_t>::Property() |
| 342 | : value_(0) {} |
keybuk@chromium.org | 7e0c493 | 2012-02-15 13:21:08 +0900 | [diff] [blame] | 343 | |
| 344 | template <> |
avi | 0ad0ce0 | 2015-12-23 03:12:45 +0900 | [diff] [blame] | 345 | bool Property<int16_t>::PopValueFromReader(MessageReader* reader) { |
keybuk@chromium.org | 7e0c493 | 2012-02-15 13:21:08 +0900 | [diff] [blame] | 346 | return reader->PopVariantOfInt16(&value_); |
| 347 | } |
| 348 | |
| 349 | template <> |
avi | 0ad0ce0 | 2015-12-23 03:12:45 +0900 | [diff] [blame] | 350 | void Property<int16_t>::AppendSetValueToWriter(MessageWriter* writer) { |
keybuk@chromium.org | 56028ac | 2012-06-29 03:43:30 +0900 | [diff] [blame] | 351 | writer->AppendVariantOfInt16(set_value_); |
keybuk@chromium.org | 7e0c493 | 2012-02-15 13:21:08 +0900 | [diff] [blame] | 352 | } |
| 353 | |
| 354 | // |
avi | 0ad0ce0 | 2015-12-23 03:12:45 +0900 | [diff] [blame] | 355 | // Property<uint16_t> specialization. |
keybuk@chromium.org | 7e0c493 | 2012-02-15 13:21:08 +0900 | [diff] [blame] | 356 | // |
| 357 | |
| 358 | template <> |
avi | 0ad0ce0 | 2015-12-23 03:12:45 +0900 | [diff] [blame] | 359 | Property<uint16_t>::Property() |
| 360 | : value_(0) {} |
keybuk@chromium.org | 7e0c493 | 2012-02-15 13:21:08 +0900 | [diff] [blame] | 361 | |
| 362 | template <> |
avi | 0ad0ce0 | 2015-12-23 03:12:45 +0900 | [diff] [blame] | 363 | bool Property<uint16_t>::PopValueFromReader(MessageReader* reader) { |
keybuk@chromium.org | 7e0c493 | 2012-02-15 13:21:08 +0900 | [diff] [blame] | 364 | return reader->PopVariantOfUint16(&value_); |
| 365 | } |
| 366 | |
| 367 | template <> |
avi | 0ad0ce0 | 2015-12-23 03:12:45 +0900 | [diff] [blame] | 368 | void Property<uint16_t>::AppendSetValueToWriter(MessageWriter* writer) { |
keybuk@chromium.org | 56028ac | 2012-06-29 03:43:30 +0900 | [diff] [blame] | 369 | writer->AppendVariantOfUint16(set_value_); |
keybuk@chromium.org | 7e0c493 | 2012-02-15 13:21:08 +0900 | [diff] [blame] | 370 | } |
| 371 | |
| 372 | // |
avi | 0ad0ce0 | 2015-12-23 03:12:45 +0900 | [diff] [blame] | 373 | // Property<int32_t> specialization. |
keybuk@chromium.org | 7e0c493 | 2012-02-15 13:21:08 +0900 | [diff] [blame] | 374 | // |
| 375 | |
| 376 | template <> |
avi | 0ad0ce0 | 2015-12-23 03:12:45 +0900 | [diff] [blame] | 377 | Property<int32_t>::Property() |
| 378 | : value_(0) {} |
keybuk@chromium.org | 7e0c493 | 2012-02-15 13:21:08 +0900 | [diff] [blame] | 379 | |
| 380 | template <> |
avi | 0ad0ce0 | 2015-12-23 03:12:45 +0900 | [diff] [blame] | 381 | bool Property<int32_t>::PopValueFromReader(MessageReader* reader) { |
keybuk@chromium.org | 7e0c493 | 2012-02-15 13:21:08 +0900 | [diff] [blame] | 382 | return reader->PopVariantOfInt32(&value_); |
| 383 | } |
| 384 | |
| 385 | template <> |
avi | 0ad0ce0 | 2015-12-23 03:12:45 +0900 | [diff] [blame] | 386 | void Property<int32_t>::AppendSetValueToWriter(MessageWriter* writer) { |
keybuk@chromium.org | 56028ac | 2012-06-29 03:43:30 +0900 | [diff] [blame] | 387 | writer->AppendVariantOfInt32(set_value_); |
keybuk@chromium.org | 7e0c493 | 2012-02-15 13:21:08 +0900 | [diff] [blame] | 388 | } |
| 389 | |
| 390 | // |
avi | 0ad0ce0 | 2015-12-23 03:12:45 +0900 | [diff] [blame] | 391 | // Property<uint32_t> specialization. |
keybuk@chromium.org | 7e0c493 | 2012-02-15 13:21:08 +0900 | [diff] [blame] | 392 | // |
| 393 | |
| 394 | template <> |
avi | 0ad0ce0 | 2015-12-23 03:12:45 +0900 | [diff] [blame] | 395 | Property<uint32_t>::Property() |
| 396 | : value_(0) {} |
keybuk@chromium.org | 7e0c493 | 2012-02-15 13:21:08 +0900 | [diff] [blame] | 397 | |
| 398 | template <> |
avi | 0ad0ce0 | 2015-12-23 03:12:45 +0900 | [diff] [blame] | 399 | bool Property<uint32_t>::PopValueFromReader(MessageReader* reader) { |
keybuk@chromium.org | 7e0c493 | 2012-02-15 13:21:08 +0900 | [diff] [blame] | 400 | return reader->PopVariantOfUint32(&value_); |
| 401 | } |
| 402 | |
| 403 | template <> |
avi | 0ad0ce0 | 2015-12-23 03:12:45 +0900 | [diff] [blame] | 404 | void Property<uint32_t>::AppendSetValueToWriter(MessageWriter* writer) { |
keybuk@chromium.org | 56028ac | 2012-06-29 03:43:30 +0900 | [diff] [blame] | 405 | writer->AppendVariantOfUint32(set_value_); |
keybuk@chromium.org | 7e0c493 | 2012-02-15 13:21:08 +0900 | [diff] [blame] | 406 | } |
| 407 | |
| 408 | // |
avi | 0ad0ce0 | 2015-12-23 03:12:45 +0900 | [diff] [blame] | 409 | // Property<int64_t> specialization. |
keybuk@chromium.org | 7e0c493 | 2012-02-15 13:21:08 +0900 | [diff] [blame] | 410 | // |
| 411 | |
| 412 | template <> |
avi | 0ad0ce0 | 2015-12-23 03:12:45 +0900 | [diff] [blame] | 413 | Property<int64_t>::Property() |
| 414 | : value_(0), set_value_(0) {} |
keybuk@chromium.org | 7e0c493 | 2012-02-15 13:21:08 +0900 | [diff] [blame] | 415 | |
| 416 | template <> |
avi | 0ad0ce0 | 2015-12-23 03:12:45 +0900 | [diff] [blame] | 417 | bool Property<int64_t>::PopValueFromReader(MessageReader* reader) { |
keybuk@chromium.org | 7e0c493 | 2012-02-15 13:21:08 +0900 | [diff] [blame] | 418 | return reader->PopVariantOfInt64(&value_); |
| 419 | } |
| 420 | |
| 421 | template <> |
avi | 0ad0ce0 | 2015-12-23 03:12:45 +0900 | [diff] [blame] | 422 | void Property<int64_t>::AppendSetValueToWriter(MessageWriter* writer) { |
keybuk@chromium.org | 56028ac | 2012-06-29 03:43:30 +0900 | [diff] [blame] | 423 | writer->AppendVariantOfInt64(set_value_); |
keybuk@chromium.org | 7e0c493 | 2012-02-15 13:21:08 +0900 | [diff] [blame] | 424 | } |
| 425 | |
| 426 | // |
avi | 0ad0ce0 | 2015-12-23 03:12:45 +0900 | [diff] [blame] | 427 | // Property<uint64_t> specialization. |
keybuk@chromium.org | 7e0c493 | 2012-02-15 13:21:08 +0900 | [diff] [blame] | 428 | // |
| 429 | |
| 430 | template <> |
avi | 0ad0ce0 | 2015-12-23 03:12:45 +0900 | [diff] [blame] | 431 | Property<uint64_t>::Property() |
| 432 | : value_(0) {} |
keybuk@chromium.org | 7e0c493 | 2012-02-15 13:21:08 +0900 | [diff] [blame] | 433 | |
| 434 | template <> |
avi | 0ad0ce0 | 2015-12-23 03:12:45 +0900 | [diff] [blame] | 435 | bool Property<uint64_t>::PopValueFromReader(MessageReader* reader) { |
keybuk@chromium.org | 7e0c493 | 2012-02-15 13:21:08 +0900 | [diff] [blame] | 436 | return reader->PopVariantOfUint64(&value_); |
| 437 | } |
| 438 | |
| 439 | template <> |
avi | 0ad0ce0 | 2015-12-23 03:12:45 +0900 | [diff] [blame] | 440 | void Property<uint64_t>::AppendSetValueToWriter(MessageWriter* writer) { |
keybuk@chromium.org | 56028ac | 2012-06-29 03:43:30 +0900 | [diff] [blame] | 441 | writer->AppendVariantOfUint64(set_value_); |
keybuk@chromium.org | 7e0c493 | 2012-02-15 13:21:08 +0900 | [diff] [blame] | 442 | } |
| 443 | |
| 444 | // |
| 445 | // Property<double> specialization. |
| 446 | // |
| 447 | |
| 448 | template <> |
keybuk@chromium.org | 56028ac | 2012-06-29 03:43:30 +0900 | [diff] [blame] | 449 | Property<double>::Property() : value_(0.0) { |
keybuk@chromium.org | 7e0c493 | 2012-02-15 13:21:08 +0900 | [diff] [blame] | 450 | } |
| 451 | |
| 452 | template <> |
| 453 | bool Property<double>::PopValueFromReader(MessageReader* reader) { |
| 454 | return reader->PopVariantOfDouble(&value_); |
| 455 | } |
| 456 | |
| 457 | template <> |
keybuk@chromium.org | 56028ac | 2012-06-29 03:43:30 +0900 | [diff] [blame] | 458 | void Property<double>::AppendSetValueToWriter(MessageWriter* writer) { |
| 459 | writer->AppendVariantOfDouble(set_value_); |
keybuk@chromium.org | 7e0c493 | 2012-02-15 13:21:08 +0900 | [diff] [blame] | 460 | } |
| 461 | |
| 462 | // |
| 463 | // Property<std::string> specialization. |
| 464 | // |
| 465 | |
| 466 | template <> |
| 467 | bool Property<std::string>::PopValueFromReader(MessageReader* reader) { |
| 468 | return reader->PopVariantOfString(&value_); |
| 469 | } |
| 470 | |
| 471 | template <> |
keybuk@chromium.org | 56028ac | 2012-06-29 03:43:30 +0900 | [diff] [blame] | 472 | void Property<std::string>::AppendSetValueToWriter(MessageWriter* writer) { |
| 473 | writer->AppendVariantOfString(set_value_); |
keybuk@chromium.org | 7e0c493 | 2012-02-15 13:21:08 +0900 | [diff] [blame] | 474 | } |
| 475 | |
| 476 | // |
| 477 | // Property<ObjectPath> specialization. |
| 478 | // |
| 479 | |
| 480 | template <> |
| 481 | bool Property<ObjectPath>::PopValueFromReader(MessageReader* reader) { |
| 482 | return reader->PopVariantOfObjectPath(&value_); |
| 483 | } |
| 484 | |
| 485 | template <> |
keybuk@chromium.org | 56028ac | 2012-06-29 03:43:30 +0900 | [diff] [blame] | 486 | void Property<ObjectPath>::AppendSetValueToWriter(MessageWriter* writer) { |
| 487 | writer->AppendVariantOfObjectPath(set_value_); |
keybuk@chromium.org | 7e0c493 | 2012-02-15 13:21:08 +0900 | [diff] [blame] | 488 | } |
| 489 | |
| 490 | // |
Ben Chan | df19e68 | 2017-11-08 10:50:21 +0900 | [diff] [blame] | 491 | // Property<std::vector<std::string>> specialization. |
keybuk@chromium.org | 7e0c493 | 2012-02-15 13:21:08 +0900 | [diff] [blame] | 492 | // |
| 493 | |
| 494 | template <> |
Ben Chan | df19e68 | 2017-11-08 10:50:21 +0900 | [diff] [blame] | 495 | bool Property<std::vector<std::string>>::PopValueFromReader( |
keybuk@chromium.org | 7e0c493 | 2012-02-15 13:21:08 +0900 | [diff] [blame] | 496 | MessageReader* reader) { |
Ben Chan | 333256c | 2017-11-10 05:20:16 +0900 | [diff] [blame] | 497 | MessageReader variant_reader(nullptr); |
keybuk@chromium.org | 7e0c493 | 2012-02-15 13:21:08 +0900 | [diff] [blame] | 498 | if (!reader->PopVariant(&variant_reader)) |
| 499 | return false; |
| 500 | |
keybuk@google.com | f056b96 | 2012-03-22 08:43:45 +0900 | [diff] [blame] | 501 | value_.clear(); |
keybuk@chromium.org | 7e0c493 | 2012-02-15 13:21:08 +0900 | [diff] [blame] | 502 | return variant_reader.PopArrayOfStrings(&value_); |
| 503 | } |
| 504 | |
| 505 | template <> |
Ben Chan | df19e68 | 2017-11-08 10:50:21 +0900 | [diff] [blame] | 506 | void Property<std::vector<std::string>>::AppendSetValueToWriter( |
keybuk@chromium.org | 56028ac | 2012-06-29 03:43:30 +0900 | [diff] [blame] | 507 | MessageWriter* writer) { |
Ben Chan | 333256c | 2017-11-10 05:20:16 +0900 | [diff] [blame] | 508 | MessageWriter variant_writer(nullptr); |
keybuk@chromium.org | 7e0c493 | 2012-02-15 13:21:08 +0900 | [diff] [blame] | 509 | writer->OpenVariant("as", &variant_writer); |
keybuk@chromium.org | 56028ac | 2012-06-29 03:43:30 +0900 | [diff] [blame] | 510 | variant_writer.AppendArrayOfStrings(set_value_); |
keybuk@chromium.org | 7e0c493 | 2012-02-15 13:21:08 +0900 | [diff] [blame] | 511 | writer->CloseContainer(&variant_writer); |
| 512 | } |
| 513 | |
| 514 | // |
Ben Chan | df19e68 | 2017-11-08 10:50:21 +0900 | [diff] [blame] | 515 | // Property<std::vector<ObjectPath>> specialization. |
keybuk@chromium.org | 7e0c493 | 2012-02-15 13:21:08 +0900 | [diff] [blame] | 516 | // |
| 517 | |
| 518 | template <> |
Ben Chan | df19e68 | 2017-11-08 10:50:21 +0900 | [diff] [blame] | 519 | bool Property<std::vector<ObjectPath>>::PopValueFromReader( |
keybuk@chromium.org | 7e0c493 | 2012-02-15 13:21:08 +0900 | [diff] [blame] | 520 | MessageReader* reader) { |
Ben Chan | 333256c | 2017-11-10 05:20:16 +0900 | [diff] [blame] | 521 | MessageReader variant_reader(nullptr); |
keybuk@chromium.org | 7e0c493 | 2012-02-15 13:21:08 +0900 | [diff] [blame] | 522 | if (!reader->PopVariant(&variant_reader)) |
| 523 | return false; |
| 524 | |
keybuk@google.com | f056b96 | 2012-03-22 08:43:45 +0900 | [diff] [blame] | 525 | value_.clear(); |
keybuk@chromium.org | 7e0c493 | 2012-02-15 13:21:08 +0900 | [diff] [blame] | 526 | return variant_reader.PopArrayOfObjectPaths(&value_); |
| 527 | } |
| 528 | |
| 529 | template <> |
Ben Chan | df19e68 | 2017-11-08 10:50:21 +0900 | [diff] [blame] | 530 | void Property<std::vector<ObjectPath>>::AppendSetValueToWriter( |
keybuk@chromium.org | 56028ac | 2012-06-29 03:43:30 +0900 | [diff] [blame] | 531 | MessageWriter* writer) { |
Ben Chan | 333256c | 2017-11-10 05:20:16 +0900 | [diff] [blame] | 532 | MessageWriter variant_writer(nullptr); |
keybuk@chromium.org | 7e0c493 | 2012-02-15 13:21:08 +0900 | [diff] [blame] | 533 | writer->OpenVariant("ao", &variant_writer); |
keybuk@chromium.org | 56028ac | 2012-06-29 03:43:30 +0900 | [diff] [blame] | 534 | variant_writer.AppendArrayOfObjectPaths(set_value_); |
keybuk@chromium.org | 7e0c493 | 2012-02-15 13:21:08 +0900 | [diff] [blame] | 535 | writer->CloseContainer(&variant_writer); |
| 536 | } |
| 537 | |
armansito@chromium.org | 11e1274 | 2014-03-15 16:40:49 +0900 | [diff] [blame] | 538 | // |
Ben Chan | df19e68 | 2017-11-08 10:50:21 +0900 | [diff] [blame] | 539 | // Property<std::vector<uint8_t>> specialization. |
armansito@chromium.org | 11e1274 | 2014-03-15 16:40:49 +0900 | [diff] [blame] | 540 | // |
| 541 | |
| 542 | template <> |
avi | 0ad0ce0 | 2015-12-23 03:12:45 +0900 | [diff] [blame] | 543 | bool Property<std::vector<uint8_t>>::PopValueFromReader(MessageReader* reader) { |
Ben Chan | 333256c | 2017-11-10 05:20:16 +0900 | [diff] [blame] | 544 | MessageReader variant_reader(nullptr); |
armansito@chromium.org | 11e1274 | 2014-03-15 16:40:49 +0900 | [diff] [blame] | 545 | if (!reader->PopVariant(&variant_reader)) |
| 546 | return false; |
| 547 | |
| 548 | value_.clear(); |
Ben Chan | 333256c | 2017-11-10 05:20:16 +0900 | [diff] [blame] | 549 | const uint8_t* bytes = nullptr; |
armansito@chromium.org | 11e1274 | 2014-03-15 16:40:49 +0900 | [diff] [blame] | 550 | size_t length = 0; |
| 551 | if (!variant_reader.PopArrayOfBytes(&bytes, &length)) |
| 552 | return false; |
| 553 | value_.assign(bytes, bytes + length); |
| 554 | return true; |
| 555 | } |
| 556 | |
| 557 | template <> |
avi | 0ad0ce0 | 2015-12-23 03:12:45 +0900 | [diff] [blame] | 558 | void Property<std::vector<uint8_t>>::AppendSetValueToWriter( |
armansito@chromium.org | 11e1274 | 2014-03-15 16:40:49 +0900 | [diff] [blame] | 559 | MessageWriter* writer) { |
Ben Chan | 333256c | 2017-11-10 05:20:16 +0900 | [diff] [blame] | 560 | MessageWriter variant_writer(nullptr); |
armansito@chromium.org | 11e1274 | 2014-03-15 16:40:49 +0900 | [diff] [blame] | 561 | writer->OpenVariant("ay", &variant_writer); |
| 562 | variant_writer.AppendArrayOfBytes(set_value_.data(), set_value_.size()); |
| 563 | writer->CloseContainer(&variant_writer); |
| 564 | } |
| 565 | |
dtapuska | 95f7172 | 2015-02-10 01:02:55 +0900 | [diff] [blame] | 566 | // |
| 567 | // Property<std::map<std::string, std::string>> specialization. |
| 568 | // |
| 569 | |
| 570 | template <> |
| 571 | bool Property<std::map<std::string, std::string>>::PopValueFromReader( |
| 572 | MessageReader* reader) { |
Ben Chan | 333256c | 2017-11-10 05:20:16 +0900 | [diff] [blame] | 573 | MessageReader variant_reader(nullptr); |
| 574 | MessageReader array_reader(nullptr); |
dtapuska | 95f7172 | 2015-02-10 01:02:55 +0900 | [diff] [blame] | 575 | if (!reader->PopVariant(&variant_reader) || |
| 576 | !variant_reader.PopArray(&array_reader)) |
| 577 | return false; |
| 578 | value_.clear(); |
| 579 | while (array_reader.HasMoreData()) { |
Ben Chan | 333256c | 2017-11-10 05:20:16 +0900 | [diff] [blame] | 580 | dbus::MessageReader dict_entry_reader(nullptr); |
dtapuska | 95f7172 | 2015-02-10 01:02:55 +0900 | [diff] [blame] | 581 | if (!array_reader.PopDictEntry(&dict_entry_reader)) |
| 582 | return false; |
| 583 | std::string key; |
| 584 | std::string value; |
| 585 | if (!dict_entry_reader.PopString(&key) || |
| 586 | !dict_entry_reader.PopString(&value)) |
| 587 | return false; |
| 588 | value_[key] = value; |
| 589 | } |
| 590 | return true; |
| 591 | } |
| 592 | |
| 593 | template <> |
| 594 | void Property<std::map<std::string, std::string>>::AppendSetValueToWriter( |
| 595 | MessageWriter* writer) { |
Ben Chan | 333256c | 2017-11-10 05:20:16 +0900 | [diff] [blame] | 596 | MessageWriter variant_writer(nullptr); |
| 597 | MessageWriter dict_writer(nullptr); |
dtapuska | 95f7172 | 2015-02-10 01:02:55 +0900 | [diff] [blame] | 598 | writer->OpenVariant("a{ss}", &variant_writer); |
| 599 | variant_writer.OpenArray("{ss}", &dict_writer); |
| 600 | for (const auto& pair : set_value_) { |
Ben Chan | 333256c | 2017-11-10 05:20:16 +0900 | [diff] [blame] | 601 | dbus::MessageWriter entry_writer(nullptr); |
dtapuska | 95f7172 | 2015-02-10 01:02:55 +0900 | [diff] [blame] | 602 | dict_writer.OpenDictEntry(&entry_writer); |
| 603 | entry_writer.AppendString(pair.first); |
| 604 | entry_writer.AppendString(pair.second); |
| 605 | dict_writer.CloseContainer(&entry_writer); |
| 606 | } |
| 607 | variant_writer.CloseContainer(&dict_writer); |
| 608 | writer->CloseContainer(&variant_writer); |
| 609 | } |
| 610 | |
| 611 | // |
| 612 | // Property<std::vector<std::pair<std::vector<uint8_t>, uint16_t>>> |
| 613 | // specialization. |
| 614 | // |
| 615 | |
| 616 | template <> |
| 617 | bool Property<std::vector<std::pair<std::vector<uint8_t>, uint16_t>>>:: |
| 618 | PopValueFromReader(MessageReader* reader) { |
Ben Chan | 333256c | 2017-11-10 05:20:16 +0900 | [diff] [blame] | 619 | MessageReader variant_reader(nullptr); |
| 620 | MessageReader array_reader(nullptr); |
dtapuska | 95f7172 | 2015-02-10 01:02:55 +0900 | [diff] [blame] | 621 | if (!reader->PopVariant(&variant_reader) || |
| 622 | !variant_reader.PopArray(&array_reader)) |
| 623 | return false; |
| 624 | |
| 625 | value_.clear(); |
| 626 | while (array_reader.HasMoreData()) { |
Ben Chan | 333256c | 2017-11-10 05:20:16 +0900 | [diff] [blame] | 627 | dbus::MessageReader struct_reader(nullptr); |
dtapuska | 95f7172 | 2015-02-10 01:02:55 +0900 | [diff] [blame] | 628 | if (!array_reader.PopStruct(&struct_reader)) |
| 629 | return false; |
| 630 | |
| 631 | std::pair<std::vector<uint8_t>, uint16_t> entry; |
Ben Chan | 333256c | 2017-11-10 05:20:16 +0900 | [diff] [blame] | 632 | const uint8_t* bytes = nullptr; |
dtapuska | 95f7172 | 2015-02-10 01:02:55 +0900 | [diff] [blame] | 633 | size_t length = 0; |
| 634 | if (!struct_reader.PopArrayOfBytes(&bytes, &length)) |
| 635 | return false; |
| 636 | entry.first.assign(bytes, bytes + length); |
| 637 | if (!struct_reader.PopUint16(&entry.second)) |
| 638 | return false; |
| 639 | value_.push_back(entry); |
| 640 | } |
| 641 | return true; |
| 642 | } |
| 643 | |
| 644 | template <> |
| 645 | void Property<std::vector<std::pair<std::vector<uint8_t>, uint16_t>>>:: |
| 646 | AppendSetValueToWriter(MessageWriter* writer) { |
Ben Chan | 333256c | 2017-11-10 05:20:16 +0900 | [diff] [blame] | 647 | MessageWriter variant_writer(nullptr); |
| 648 | MessageWriter array_writer(nullptr); |
dtapuska | 95f7172 | 2015-02-10 01:02:55 +0900 | [diff] [blame] | 649 | writer->OpenVariant("a(ayq)", &variant_writer); |
| 650 | variant_writer.OpenArray("(ayq)", &array_writer); |
| 651 | for (const auto& pair : set_value_) { |
| 652 | dbus::MessageWriter struct_writer(nullptr); |
| 653 | array_writer.OpenStruct(&struct_writer); |
| 654 | struct_writer.AppendArrayOfBytes(std::get<0>(pair).data(), |
| 655 | std::get<0>(pair).size()); |
| 656 | struct_writer.AppendUint16(std::get<1>(pair)); |
| 657 | array_writer.CloseContainer(&struct_writer); |
| 658 | } |
| 659 | variant_writer.CloseContainer(&array_writer); |
| 660 | writer->CloseContainer(&variant_writer); |
| 661 | } |
| 662 | |
puthik | 90fd20c | 2016-10-06 14:03:03 +0900 | [diff] [blame] | 663 | // |
puthik | 6558aab | 2016-11-05 04:38:17 +0900 | [diff] [blame] | 664 | // Property<std::unordered_map<std::string, std::vector<uint8_t>>> |
puthik | 90fd20c | 2016-10-06 14:03:03 +0900 | [diff] [blame] | 665 | // specialization. |
| 666 | // |
| 667 | |
| 668 | template <> |
| 669 | bool Property<std::unordered_map<std::string, std::vector<uint8_t>>>:: |
| 670 | PopValueFromReader(MessageReader* reader) { |
| 671 | MessageReader variant_reader(nullptr); |
| 672 | MessageReader dict_reader(nullptr); |
| 673 | if (!reader->PopVariant(&variant_reader) || |
| 674 | !variant_reader.PopArray(&dict_reader)) |
| 675 | return false; |
| 676 | |
| 677 | value_.clear(); |
| 678 | while (dict_reader.HasMoreData()) { |
| 679 | MessageReader entry_reader(nullptr); |
| 680 | if (!dict_reader.PopDictEntry(&entry_reader)) |
| 681 | return false; |
| 682 | |
| 683 | std::string key; |
| 684 | MessageReader value_varient_reader(nullptr); |
| 685 | if (!entry_reader.PopString(&key) || |
| 686 | !entry_reader.PopVariant(&value_varient_reader)) |
| 687 | return false; |
| 688 | |
| 689 | const uint8_t* bytes = nullptr; |
| 690 | size_t length = 0; |
| 691 | if (!value_varient_reader.PopArrayOfBytes(&bytes, &length)) |
| 692 | return false; |
| 693 | |
| 694 | value_[key].assign(bytes, bytes + length); |
| 695 | } |
| 696 | return true; |
| 697 | } |
| 698 | |
| 699 | template <> |
| 700 | void Property<std::unordered_map<std::string, std::vector<uint8_t>>>:: |
| 701 | AppendSetValueToWriter(MessageWriter* writer) { |
| 702 | MessageWriter variant_writer(nullptr); |
| 703 | MessageWriter dict_writer(nullptr); |
| 704 | |
| 705 | writer->OpenVariant("a{sv}", &variant_writer); |
| 706 | variant_writer.OpenArray("{sv}", &dict_writer); |
| 707 | |
| 708 | for (const auto& pair : set_value_) { |
| 709 | MessageWriter entry_writer(nullptr); |
| 710 | dict_writer.OpenDictEntry(&entry_writer); |
| 711 | |
| 712 | entry_writer.AppendString(pair.first); |
| 713 | |
| 714 | MessageWriter value_varient_writer(nullptr); |
| 715 | entry_writer.OpenVariant("ay", &value_varient_writer); |
| 716 | value_varient_writer.AppendArrayOfBytes(pair.second.data(), |
| 717 | pair.second.size()); |
| 718 | entry_writer.CloseContainer(&value_varient_writer); |
| 719 | |
| 720 | dict_writer.CloseContainer(&entry_writer); |
| 721 | } |
| 722 | |
| 723 | variant_writer.CloseContainer(&dict_writer); |
| 724 | writer->CloseContainer(&variant_writer); |
| 725 | } |
| 726 | |
puthik | 6558aab | 2016-11-05 04:38:17 +0900 | [diff] [blame] | 727 | // |
| 728 | // Property<std::unordered_map<uint16_t, std::vector<uint8_t>>> |
| 729 | // specialization. |
| 730 | // |
| 731 | |
| 732 | template <> |
| 733 | bool Property<std::unordered_map<uint16_t, std::vector<uint8_t>>>:: |
| 734 | PopValueFromReader(MessageReader* reader) { |
| 735 | MessageReader variant_reader(nullptr); |
| 736 | MessageReader dict_reader(nullptr); |
| 737 | if (!reader->PopVariant(&variant_reader) || |
| 738 | !variant_reader.PopArray(&dict_reader)) |
| 739 | return false; |
| 740 | |
| 741 | value_.clear(); |
| 742 | while (dict_reader.HasMoreData()) { |
| 743 | MessageReader entry_reader(nullptr); |
| 744 | if (!dict_reader.PopDictEntry(&entry_reader)) |
| 745 | return false; |
| 746 | |
| 747 | uint16_t key; |
| 748 | MessageReader value_varient_reader(nullptr); |
| 749 | if (!entry_reader.PopUint16(&key) || |
| 750 | !entry_reader.PopVariant(&value_varient_reader)) |
| 751 | return false; |
| 752 | |
| 753 | const uint8_t* bytes = nullptr; |
| 754 | size_t length = 0; |
| 755 | if (!value_varient_reader.PopArrayOfBytes(&bytes, &length)) |
| 756 | return false; |
| 757 | |
| 758 | value_[key].assign(bytes, bytes + length); |
| 759 | } |
| 760 | return true; |
| 761 | } |
| 762 | |
| 763 | template <> |
| 764 | void Property<std::unordered_map<uint16_t, std::vector<uint8_t>>>:: |
| 765 | AppendSetValueToWriter(MessageWriter* writer) { |
| 766 | MessageWriter variant_writer(nullptr); |
| 767 | MessageWriter dict_writer(nullptr); |
| 768 | |
| 769 | writer->OpenVariant("a{qv}", &variant_writer); |
| 770 | variant_writer.OpenArray("{qv}", &dict_writer); |
| 771 | |
| 772 | for (const auto& pair : set_value_) { |
| 773 | MessageWriter entry_writer(nullptr); |
| 774 | dict_writer.OpenDictEntry(&entry_writer); |
| 775 | |
| 776 | entry_writer.AppendUint16(pair.first); |
| 777 | |
| 778 | MessageWriter value_varient_writer(nullptr); |
| 779 | entry_writer.OpenVariant("ay", &value_varient_writer); |
| 780 | value_varient_writer.AppendArrayOfBytes(pair.second.data(), |
| 781 | pair.second.size()); |
| 782 | entry_writer.CloseContainer(&value_varient_writer); |
| 783 | |
| 784 | dict_writer.CloseContainer(&entry_writer); |
| 785 | } |
| 786 | |
| 787 | variant_writer.CloseContainer(&dict_writer); |
| 788 | writer->CloseContainer(&variant_writer); |
| 789 | } |
| 790 | |
avi | 0ad0ce0 | 2015-12-23 03:12:45 +0900 | [diff] [blame] | 791 | template class Property<uint8_t>; |
tzik@chromium.org | 1dc2943 | 2014-07-25 13:04:27 +0900 | [diff] [blame] | 792 | template class Property<bool>; |
avi | 0ad0ce0 | 2015-12-23 03:12:45 +0900 | [diff] [blame] | 793 | template class Property<int16_t>; |
| 794 | template class Property<uint16_t>; |
| 795 | template class Property<int32_t>; |
| 796 | template class Property<uint32_t>; |
| 797 | template class Property<int64_t>; |
| 798 | template class Property<uint64_t>; |
tzik@chromium.org | 1dc2943 | 2014-07-25 13:04:27 +0900 | [diff] [blame] | 799 | template class Property<double>; |
| 800 | template class Property<std::string>; |
| 801 | template class Property<ObjectPath>; |
Ben Chan | df19e68 | 2017-11-08 10:50:21 +0900 | [diff] [blame] | 802 | template class Property<std::vector<std::string>>; |
| 803 | template class Property<std::vector<ObjectPath>>; |
avi | 0ad0ce0 | 2015-12-23 03:12:45 +0900 | [diff] [blame] | 804 | template class Property<std::vector<uint8_t>>; |
dtapuska | 95f7172 | 2015-02-10 01:02:55 +0900 | [diff] [blame] | 805 | template class Property<std::map<std::string, std::string>>; |
| 806 | template class Property<std::vector<std::pair<std::vector<uint8_t>, uint16_t>>>; |
puthik | 90fd20c | 2016-10-06 14:03:03 +0900 | [diff] [blame] | 807 | template class Property<std::unordered_map<std::string, std::vector<uint8_t>>>; |
puthik | 6558aab | 2016-11-05 04:38:17 +0900 | [diff] [blame] | 808 | template class Property<std::unordered_map<uint16_t, std::vector<uint8_t>>>; |
tzik@chromium.org | 1dc2943 | 2014-07-25 13:04:27 +0900 | [diff] [blame] | 809 | |
keybuk@chromium.org | 7e0c493 | 2012-02-15 13:21:08 +0900 | [diff] [blame] | 810 | } // namespace dbus |