mukesh agrawal | 4d0401c | 2012-01-06 16:05:31 -0800 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 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 "shill/property_store.h" |
| 6 | |
| 7 | #include <map> |
| 8 | #include <string> |
| 9 | #include <vector> |
| 10 | |
| 11 | #include <base/basictypes.h> |
Eric Shienbrood | 3e20a23 | 2012-02-16 11:35:56 -0500 | [diff] [blame] | 12 | #include <base/stl_util.h> |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 13 | |
| 14 | #include "shill/error.h" |
Christopher Wiley | b691efd | 2012-08-09 13:51:51 -0700 | [diff] [blame] | 15 | #include "shill/logging.h" |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 16 | #include "shill/property_accessor.h" |
| 17 | |
| 18 | using std::map; |
| 19 | using std::string; |
| 20 | using std::vector; |
| 21 | |
| 22 | namespace shill { |
| 23 | |
| 24 | PropertyStore::PropertyStore() {} |
| 25 | |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 26 | PropertyStore::PropertyStore(PropertyChangeCallback on_property_changed) : |
| 27 | property_changed_callback_(on_property_changed) {} |
| 28 | |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 29 | PropertyStore::~PropertyStore() {} |
| 30 | |
mukesh agrawal | 66b0aca | 2012-01-30 15:28:28 -0800 | [diff] [blame] | 31 | bool PropertyStore::Contains(const string &prop) const { |
| 32 | return (ContainsKey(bool_properties_, prop) || |
| 33 | ContainsKey(int16_properties_, prop) || |
| 34 | ContainsKey(int32_properties_, prop) || |
| 35 | ContainsKey(key_value_store_properties_, prop) || |
| 36 | ContainsKey(string_properties_, prop) || |
| 37 | ContainsKey(stringmap_properties_, prop) || |
| 38 | ContainsKey(stringmaps_properties_, prop) || |
| 39 | ContainsKey(strings_properties_, prop) || |
| 40 | ContainsKey(uint8_properties_, prop) || |
| 41 | ContainsKey(uint16_properties_, prop) || |
Jason Glasgow | acdc11f | 2012-03-30 14:12:22 -0400 | [diff] [blame] | 42 | ContainsKey(uint32_properties_, prop) || |
Paul Stewart | e18c33b | 2012-07-10 20:48:44 -0700 | [diff] [blame] | 43 | ContainsKey(uint64_properties_, prop) || |
Jason Glasgow | acdc11f | 2012-03-30 14:12:22 -0400 | [diff] [blame] | 44 | ContainsKey(rpc_identifier_properties_, prop) || |
| 45 | ContainsKey(rpc_identifiers_properties_, prop)); |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 46 | } |
| 47 | |
Paul Stewart | e6e8e49 | 2013-01-17 11:00:50 -0800 | [diff] [blame] | 48 | bool PropertyStore::GetBoolProperty(const string &name, |
| 49 | bool *value, |
| 50 | Error *error) const { |
| 51 | return GetProperty(name, value, error, bool_properties_, "a bool"); |
| 52 | } |
| 53 | |
| 54 | bool PropertyStore::GetInt16Property(const string &name, |
| 55 | int16 *value, |
| 56 | Error *error) const { |
| 57 | return GetProperty(name, value, error, int16_properties_, "an int16"); |
| 58 | } |
| 59 | |
| 60 | bool PropertyStore::GetInt32Property(const string &name, |
| 61 | int32 *value, |
| 62 | Error *error) const { |
| 63 | return GetProperty(name, value, error, int32_properties_, "an int32"); |
| 64 | } |
| 65 | |
| 66 | bool PropertyStore::GetKeyValueStoreProperty(const string &name, |
| 67 | KeyValueStore *value, |
| 68 | Error *error) const { |
| 69 | return GetProperty(name, value, error, key_value_store_properties_, |
| 70 | "a key value store"); |
| 71 | } |
| 72 | |
| 73 | bool PropertyStore::GetRpcIdentifierProperty(const string &name, |
| 74 | RpcIdentifier *value, |
| 75 | Error *error) const { |
| 76 | return GetProperty(name, value, error, rpc_identifier_properties_, |
| 77 | "an rpc_identifier"); |
| 78 | } |
| 79 | |
| 80 | bool PropertyStore::GetStringProperty(const string &name, |
| 81 | string *value, |
| 82 | Error *error) const { |
| 83 | return GetProperty(name, value, error, string_properties_, "a string"); |
| 84 | } |
| 85 | |
| 86 | bool PropertyStore::GetStringmapProperty(const string &name, |
| 87 | Stringmap *values, |
| 88 | Error *error) const { |
| 89 | return GetProperty(name, values, error, stringmap_properties_, |
| 90 | "a string map"); |
| 91 | } |
| 92 | |
| 93 | bool PropertyStore::GetStringmapsProperty(const string &name, |
| 94 | Stringmaps *values, |
| 95 | Error *error) const { |
| 96 | return GetProperty(name, values, error, stringmaps_properties_, |
| 97 | "a string map list"); |
| 98 | } |
| 99 | |
| 100 | bool PropertyStore::GetStringsProperty(const string &name, |
| 101 | Strings *values, |
| 102 | Error *error) const { |
| 103 | return GetProperty(name, values, error, strings_properties_, "a string list"); |
| 104 | } |
| 105 | |
| 106 | bool PropertyStore::GetUint8Property(const string &name, |
| 107 | uint8 *value, |
| 108 | Error *error) const { |
| 109 | return GetProperty(name, value, error, uint8_properties_, "a uint8"); |
| 110 | } |
| 111 | |
| 112 | bool PropertyStore::GetUint16Property(const string &name, |
| 113 | uint16 *value, |
| 114 | Error *error) const { |
| 115 | return GetProperty(name, value, error, uint16_properties_, "a uint16"); |
| 116 | } |
| 117 | |
| 118 | bool PropertyStore::GetUint32Property(const string &name, |
| 119 | uint32 *value, |
| 120 | Error *error) const { |
| 121 | return GetProperty(name, value, error, uint32_properties_, "a uint32"); |
| 122 | } |
| 123 | |
| 124 | bool PropertyStore::GetUint64Property(const string &name, |
| 125 | uint64 *value, |
| 126 | Error *error) const { |
| 127 | return GetProperty(name, value, error, uint64_properties_, "a uint64"); |
| 128 | } |
| 129 | |
mukesh agrawal | 66b0aca | 2012-01-30 15:28:28 -0800 | [diff] [blame] | 130 | bool PropertyStore::SetBoolProperty(const string &name, |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 131 | bool value, |
| 132 | Error *error) { |
mukesh agrawal | ffa3d04 | 2011-10-06 15:26:10 -0700 | [diff] [blame] | 133 | return SetProperty(name, value, error, bool_properties_, "a bool"); |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 134 | } |
| 135 | |
mukesh agrawal | 66b0aca | 2012-01-30 15:28:28 -0800 | [diff] [blame] | 136 | bool PropertyStore::SetInt16Property(const string &name, |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 137 | int16 value, |
| 138 | Error *error) { |
mukesh agrawal | ffa3d04 | 2011-10-06 15:26:10 -0700 | [diff] [blame] | 139 | return SetProperty(name, value, error, int16_properties_, "an int16"); |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 140 | } |
| 141 | |
mukesh agrawal | 66b0aca | 2012-01-30 15:28:28 -0800 | [diff] [blame] | 142 | bool PropertyStore::SetInt32Property(const string &name, |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 143 | int32 value, |
| 144 | Error *error) { |
mukesh agrawal | ffa3d04 | 2011-10-06 15:26:10 -0700 | [diff] [blame] | 145 | return SetProperty(name, value, error, int32_properties_, "an int32."); |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 146 | } |
| 147 | |
mukesh agrawal | 66b0aca | 2012-01-30 15:28:28 -0800 | [diff] [blame] | 148 | bool PropertyStore::SetStringProperty(const string &name, |
| 149 | const string &value, |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 150 | Error *error) { |
mukesh agrawal | ffa3d04 | 2011-10-06 15:26:10 -0700 | [diff] [blame] | 151 | return SetProperty(name, value, error, string_properties_, "a string"); |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 152 | } |
| 153 | |
mukesh agrawal | 66b0aca | 2012-01-30 15:28:28 -0800 | [diff] [blame] | 154 | bool PropertyStore::SetStringmapProperty(const string &name, |
| 155 | const map<string, string> &values, |
| 156 | Error *error) { |
mukesh agrawal | ffa3d04 | 2011-10-06 15:26:10 -0700 | [diff] [blame] | 157 | return SetProperty(name, values, error, stringmap_properties_, |
| 158 | "a string map"); |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 159 | } |
| 160 | |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 161 | bool PropertyStore::SetStringmapsProperty( |
| 162 | const string &name, |
| 163 | const vector<map<string, string> > &values, |
| 164 | Error *error) { |
| 165 | return SetProperty(name, values, error, stringmaps_properties_, |
| 166 | "a stringmaps"); |
| 167 | } |
| 168 | |
mukesh agrawal | 66b0aca | 2012-01-30 15:28:28 -0800 | [diff] [blame] | 169 | bool PropertyStore::SetStringsProperty(const string &name, |
| 170 | const vector<string> &values, |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 171 | Error *error) { |
mukesh agrawal | ffa3d04 | 2011-10-06 15:26:10 -0700 | [diff] [blame] | 172 | return SetProperty(name, values, error, strings_properties_, "a string list"); |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 173 | } |
| 174 | |
mukesh agrawal | 66b0aca | 2012-01-30 15:28:28 -0800 | [diff] [blame] | 175 | bool PropertyStore::SetUint8Property(const string &name, |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 176 | uint8 value, |
| 177 | Error *error) { |
mukesh agrawal | ffa3d04 | 2011-10-06 15:26:10 -0700 | [diff] [blame] | 178 | return SetProperty(name, value, error, uint8_properties_, "a uint8"); |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 179 | } |
| 180 | |
mukesh agrawal | 66b0aca | 2012-01-30 15:28:28 -0800 | [diff] [blame] | 181 | bool PropertyStore::SetUint16Property(const string &name, |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 182 | uint16 value, |
| 183 | Error *error) { |
mukesh agrawal | ffa3d04 | 2011-10-06 15:26:10 -0700 | [diff] [blame] | 184 | return SetProperty(name, value, error, uint16_properties_, "a uint16"); |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 185 | } |
| 186 | |
mukesh agrawal | 66b0aca | 2012-01-30 15:28:28 -0800 | [diff] [blame] | 187 | bool PropertyStore::SetUint32Property(const string &name, |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 188 | uint32 value, |
| 189 | Error *error) { |
mukesh agrawal | ffa3d04 | 2011-10-06 15:26:10 -0700 | [diff] [blame] | 190 | return SetProperty(name, value, error, uint32_properties_, "a uint32"); |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 191 | } |
| 192 | |
Paul Stewart | e18c33b | 2012-07-10 20:48:44 -0700 | [diff] [blame] | 193 | bool PropertyStore::SetUint64Property(const string &name, |
| 194 | uint64 value, |
| 195 | Error *error) { |
| 196 | return SetProperty(name, value, error, uint64_properties_, "a uint64"); |
| 197 | } |
| 198 | |
Jason Glasgow | acdc11f | 2012-03-30 14:12:22 -0400 | [diff] [blame] | 199 | bool PropertyStore::SetRpcIdentifierProperty(const string &name, |
| 200 | const RpcIdentifier &value, |
| 201 | Error *error) { |
| 202 | return SetProperty(name, value, error, rpc_identifier_properties_, |
| 203 | "an rpc_identifier"); |
| 204 | } |
| 205 | |
mukesh agrawal | 4d260da | 2012-01-30 11:53:52 -0800 | [diff] [blame] | 206 | bool PropertyStore::ClearProperty(const string &name, Error *error) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 207 | SLOG(Property, 2) << "Clearing " << name << "."; |
mukesh agrawal | 4d260da | 2012-01-30 11:53:52 -0800 | [diff] [blame] | 208 | |
| 209 | if (ContainsKey(bool_properties_, name)) { |
| 210 | bool_properties_[name]->Clear(error); |
| 211 | } else if (ContainsKey(int16_properties_, name)) { |
| 212 | int16_properties_[name]->Clear(error); |
| 213 | } else if (ContainsKey(int32_properties_, name)) { |
| 214 | int32_properties_[name]->Clear(error); |
| 215 | } else if (ContainsKey(key_value_store_properties_, name)) { |
| 216 | key_value_store_properties_[name]->Clear(error); |
| 217 | } else if (ContainsKey(string_properties_, name)) { |
| 218 | string_properties_[name]->Clear(error); |
| 219 | } else if (ContainsKey(stringmap_properties_, name)) { |
| 220 | stringmap_properties_[name]->Clear(error); |
| 221 | } else if (ContainsKey(stringmaps_properties_, name)) { |
| 222 | stringmaps_properties_[name]->Clear(error); |
| 223 | } else if (ContainsKey(strings_properties_, name)) { |
| 224 | strings_properties_[name]->Clear(error); |
| 225 | } else if (ContainsKey(uint8_properties_, name)) { |
| 226 | uint8_properties_[name]->Clear(error); |
| 227 | } else if (ContainsKey(uint16_properties_, name)) { |
| 228 | uint16_properties_[name]->Clear(error); |
| 229 | } else if (ContainsKey(uint32_properties_, name)) { |
| 230 | uint32_properties_[name]->Clear(error); |
Paul Stewart | e18c33b | 2012-07-10 20:48:44 -0700 | [diff] [blame] | 231 | } else if (ContainsKey(uint64_properties_, name)) { |
| 232 | uint64_properties_[name]->Clear(error); |
Jason Glasgow | acdc11f | 2012-03-30 14:12:22 -0400 | [diff] [blame] | 233 | } else if (ContainsKey(rpc_identifier_properties_, name)) { |
| 234 | rpc_identifier_properties_[name]->Clear(error); |
| 235 | } else if (ContainsKey(rpc_identifiers_properties_, name)) { |
| 236 | rpc_identifiers_properties_[name]->Clear(error); |
mukesh agrawal | 4d260da | 2012-01-30 11:53:52 -0800 | [diff] [blame] | 237 | } else { |
| 238 | error->Populate( |
| 239 | Error::kInvalidProperty, "Property " + name + " does not exist."); |
| 240 | } |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 241 | if (error->IsSuccess()) { |
| 242 | if (!property_changed_callback_.is_null()) { |
| 243 | property_changed_callback_.Run(name); |
| 244 | } |
| 245 | } |
mukesh agrawal | 4d260da | 2012-01-30 11:53:52 -0800 | [diff] [blame] | 246 | return error->IsSuccess(); |
| 247 | } |
| 248 | |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 249 | ReadablePropertyConstIterator<bool> PropertyStore::GetBoolPropertiesIter() |
mukesh agrawal | de29fa8 | 2011-09-16 16:16:36 -0700 | [diff] [blame] | 250 | const { |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 251 | return ReadablePropertyConstIterator<bool>(bool_properties_); |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 252 | } |
| 253 | |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 254 | ReadablePropertyConstIterator<int16> PropertyStore::GetInt16PropertiesIter() |
mukesh agrawal | de29fa8 | 2011-09-16 16:16:36 -0700 | [diff] [blame] | 255 | const { |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 256 | return ReadablePropertyConstIterator<int16>(int16_properties_); |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 257 | } |
| 258 | |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 259 | ReadablePropertyConstIterator<int32> PropertyStore::GetInt32PropertiesIter() |
mukesh agrawal | de29fa8 | 2011-09-16 16:16:36 -0700 | [diff] [blame] | 260 | const { |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 261 | return ReadablePropertyConstIterator<int32>(int32_properties_); |
Chris Masone | 889666b | 2011-07-03 12:58:50 -0700 | [diff] [blame] | 262 | } |
| 263 | |
Darin Petkov | 63138a9 | 2012-02-06 14:09:15 +0100 | [diff] [blame] | 264 | ReadablePropertyConstIterator<KeyValueStore> |
| 265 | PropertyStore::GetKeyValueStorePropertiesIter() const { |
| 266 | return |
| 267 | ReadablePropertyConstIterator<KeyValueStore>(key_value_store_properties_); |
| 268 | } |
| 269 | |
Jason Glasgow | acdc11f | 2012-03-30 14:12:22 -0400 | [diff] [blame] | 270 | ReadablePropertyConstIterator<RpcIdentifier> |
| 271 | PropertyStore::GetRpcIdentifierPropertiesIter() const { |
| 272 | return ReadablePropertyConstIterator<RpcIdentifier>( |
| 273 | rpc_identifier_properties_); |
| 274 | } |
| 275 | |
mukesh agrawal | 2366eed | 2012-03-20 18:21:50 -0700 | [diff] [blame] | 276 | ReadablePropertyConstIterator<RpcIdentifiers> |
| 277 | PropertyStore::GetRpcIdentifiersPropertiesIter() const { |
| 278 | return ReadablePropertyConstIterator<RpcIdentifiers>( |
| 279 | rpc_identifiers_properties_); |
| 280 | } |
| 281 | |
mukesh agrawal | 66b0aca | 2012-01-30 15:28:28 -0800 | [diff] [blame] | 282 | ReadablePropertyConstIterator<string> |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 283 | PropertyStore::GetStringPropertiesIter() const { |
mukesh agrawal | 66b0aca | 2012-01-30 15:28:28 -0800 | [diff] [blame] | 284 | return ReadablePropertyConstIterator<string>(string_properties_); |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 285 | } |
| 286 | |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 287 | ReadablePropertyConstIterator<Stringmap> |
| 288 | PropertyStore::GetStringmapPropertiesIter() const { |
| 289 | return ReadablePropertyConstIterator<Stringmap>(stringmap_properties_); |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 290 | } |
| 291 | |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 292 | ReadablePropertyConstIterator<Stringmaps> |
| 293 | PropertyStore::GetStringmapsPropertiesIter() |
| 294 | const { |
| 295 | return ReadablePropertyConstIterator<Stringmaps>(stringmaps_properties_); |
| 296 | } |
| 297 | |
| 298 | ReadablePropertyConstIterator<Strings> PropertyStore::GetStringsPropertiesIter() |
| 299 | const { |
| 300 | return ReadablePropertyConstIterator<Strings>(strings_properties_); |
| 301 | } |
| 302 | |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 303 | ReadablePropertyConstIterator<uint8> PropertyStore::GetUint8PropertiesIter() |
| 304 | const { |
| 305 | return ReadablePropertyConstIterator<uint8>(uint8_properties_); |
| 306 | } |
| 307 | |
| 308 | ReadablePropertyConstIterator<uint16> PropertyStore::GetUint16PropertiesIter() |
| 309 | const { |
| 310 | return ReadablePropertyConstIterator<uint16>(uint16_properties_); |
| 311 | } |
| 312 | |
| 313 | ReadablePropertyConstIterator<uint32> PropertyStore::GetUint32PropertiesIter() |
| 314 | const { |
| 315 | return ReadablePropertyConstIterator<uint32>(uint32_properties_); |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 316 | } |
| 317 | |
Paul Stewart | e18c33b | 2012-07-10 20:48:44 -0700 | [diff] [blame] | 318 | ReadablePropertyConstIterator<uint64> PropertyStore::GetUint64PropertiesIter() |
| 319 | const { |
| 320 | return ReadablePropertyConstIterator<uint64>(uint64_properties_); |
| 321 | } |
| 322 | |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 323 | void PropertyStore::RegisterBool(const string &name, bool *prop) { |
mukesh agrawal | 4d260da | 2012-01-30 11:53:52 -0800 | [diff] [blame] | 324 | DCHECK(!Contains(name) || ContainsKey(bool_properties_, name)) |
| 325 | << "(Already registered " << name << ")"; |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 326 | bool_properties_[name] = BoolAccessor(new PropertyAccessor<bool>(prop)); |
| 327 | } |
| 328 | |
| 329 | void PropertyStore::RegisterConstBool(const string &name, const bool *prop) { |
mukesh agrawal | 4d260da | 2012-01-30 11:53:52 -0800 | [diff] [blame] | 330 | DCHECK(!Contains(name) || ContainsKey(bool_properties_, name)) |
| 331 | << "(Already registered " << name << ")"; |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 332 | bool_properties_[name] = BoolAccessor(new ConstPropertyAccessor<bool>(prop)); |
| 333 | } |
| 334 | |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 335 | void PropertyStore::RegisterWriteOnlyBool(const string &name, bool *prop) { |
mukesh agrawal | 4d260da | 2012-01-30 11:53:52 -0800 | [diff] [blame] | 336 | DCHECK(!Contains(name) || ContainsKey(bool_properties_, name)) |
| 337 | << "(Already registered " << name << ")"; |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 338 | bool_properties_[name] = BoolAccessor( |
| 339 | new WriteOnlyPropertyAccessor<bool>(prop)); |
| 340 | } |
| 341 | |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 342 | void PropertyStore::RegisterInt16(const string &name, int16 *prop) { |
mukesh agrawal | 4d260da | 2012-01-30 11:53:52 -0800 | [diff] [blame] | 343 | DCHECK(!Contains(name) || ContainsKey(int16_properties_, name)) |
| 344 | << "(Already registered " << name << ")"; |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 345 | int16_properties_[name] = Int16Accessor(new PropertyAccessor<int16>(prop)); |
| 346 | } |
| 347 | |
| 348 | void PropertyStore::RegisterConstInt16(const string &name, const int16 *prop) { |
mukesh agrawal | 4d260da | 2012-01-30 11:53:52 -0800 | [diff] [blame] | 349 | DCHECK(!Contains(name) || ContainsKey(int16_properties_, name)) |
| 350 | << "(Already registered " << name << ")"; |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 351 | int16_properties_[name] = |
| 352 | Int16Accessor(new ConstPropertyAccessor<int16>(prop)); |
| 353 | } |
| 354 | |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 355 | void PropertyStore::RegisterWriteOnlyInt16(const string &name, int16 *prop) { |
mukesh agrawal | 4d260da | 2012-01-30 11:53:52 -0800 | [diff] [blame] | 356 | DCHECK(!Contains(name) || ContainsKey(int16_properties_, name)) |
| 357 | << "(Already registered " << name << ")"; |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 358 | int16_properties_[name] = |
| 359 | Int16Accessor(new WriteOnlyPropertyAccessor<int16>(prop)); |
| 360 | } |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 361 | void PropertyStore::RegisterInt32(const string &name, int32 *prop) { |
mukesh agrawal | 4d260da | 2012-01-30 11:53:52 -0800 | [diff] [blame] | 362 | DCHECK(!Contains(name) || ContainsKey(int32_properties_, name)) |
| 363 | << "(Already registered " << name << ")"; |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 364 | int32_properties_[name] = Int32Accessor(new PropertyAccessor<int32>(prop)); |
| 365 | } |
| 366 | |
| 367 | void PropertyStore::RegisterConstInt32(const string &name, const int32 *prop) { |
mukesh agrawal | 4d260da | 2012-01-30 11:53:52 -0800 | [diff] [blame] | 368 | DCHECK(!Contains(name) || ContainsKey(int32_properties_, name)) |
| 369 | << "(Already registered " << name << ")"; |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 370 | int32_properties_[name] = |
| 371 | Int32Accessor(new ConstPropertyAccessor<int32>(prop)); |
| 372 | } |
| 373 | |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 374 | void PropertyStore::RegisterWriteOnlyInt32(const string &name, int32 *prop) { |
mukesh agrawal | 4d260da | 2012-01-30 11:53:52 -0800 | [diff] [blame] | 375 | DCHECK(!Contains(name) || ContainsKey(int32_properties_, name)) |
| 376 | << "(Already registered " << name << ")"; |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 377 | int32_properties_[name] = |
| 378 | Int32Accessor(new WriteOnlyPropertyAccessor<int32>(prop)); |
| 379 | } |
| 380 | |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 381 | void PropertyStore::RegisterString(const string &name, string *prop) { |
mukesh agrawal | 4d260da | 2012-01-30 11:53:52 -0800 | [diff] [blame] | 382 | DCHECK(!Contains(name) || ContainsKey(string_properties_, name)) |
| 383 | << "(Already registered " << name << ")"; |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 384 | string_properties_[name] = StringAccessor(new PropertyAccessor<string>(prop)); |
| 385 | } |
| 386 | |
| 387 | void PropertyStore::RegisterConstString(const string &name, |
| 388 | const string *prop) { |
mukesh agrawal | 4d260da | 2012-01-30 11:53:52 -0800 | [diff] [blame] | 389 | DCHECK(!Contains(name) || ContainsKey(string_properties_, name)) |
| 390 | << "(Already registered " << name << ")"; |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 391 | string_properties_[name] = |
| 392 | StringAccessor(new ConstPropertyAccessor<string>(prop)); |
| 393 | } |
| 394 | |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 395 | void PropertyStore::RegisterWriteOnlyString(const string &name, string *prop) { |
mukesh agrawal | 4d260da | 2012-01-30 11:53:52 -0800 | [diff] [blame] | 396 | DCHECK(!Contains(name) || ContainsKey(string_properties_, name)) |
| 397 | << "(Already registered " << name << ")"; |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 398 | string_properties_[name] = |
| 399 | StringAccessor(new WriteOnlyPropertyAccessor<string>(prop)); |
| 400 | } |
| 401 | |
Chris Masone | 43b48a1 | 2011-07-01 13:37:07 -0700 | [diff] [blame] | 402 | void PropertyStore::RegisterStringmap(const string &name, Stringmap *prop) { |
mukesh agrawal | 4d260da | 2012-01-30 11:53:52 -0800 | [diff] [blame] | 403 | DCHECK(!Contains(name) || ContainsKey(stringmap_properties_, name)) |
| 404 | << "(Already registered " << name << ")"; |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 405 | stringmap_properties_[name] = |
Chris Masone | 43b48a1 | 2011-07-01 13:37:07 -0700 | [diff] [blame] | 406 | StringmapAccessor(new PropertyAccessor<Stringmap>(prop)); |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 407 | } |
| 408 | |
| 409 | void PropertyStore::RegisterConstStringmap(const string &name, |
Chris Masone | 43b48a1 | 2011-07-01 13:37:07 -0700 | [diff] [blame] | 410 | const Stringmap *prop) { |
mukesh agrawal | 4d260da | 2012-01-30 11:53:52 -0800 | [diff] [blame] | 411 | DCHECK(!Contains(name) || ContainsKey(stringmap_properties_, name)) |
| 412 | << "(Already registered " << name << ")"; |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 413 | stringmap_properties_[name] = |
Chris Masone | 43b48a1 | 2011-07-01 13:37:07 -0700 | [diff] [blame] | 414 | StringmapAccessor(new ConstPropertyAccessor<Stringmap>(prop)); |
| 415 | } |
| 416 | |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 417 | void PropertyStore::RegisterWriteOnlyStringmap(const string &name, |
| 418 | Stringmap *prop) { |
mukesh agrawal | 4d260da | 2012-01-30 11:53:52 -0800 | [diff] [blame] | 419 | DCHECK(!Contains(name) || ContainsKey(stringmap_properties_, name)) |
| 420 | << "(Already registered " << name << ")"; |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 421 | stringmap_properties_[name] = |
| 422 | StringmapAccessor(new WriteOnlyPropertyAccessor<Stringmap>(prop)); |
| 423 | } |
| 424 | |
Darin Petkov | c086531 | 2011-09-16 15:31:20 -0700 | [diff] [blame] | 425 | void PropertyStore::RegisterStringmaps(const string &name, Stringmaps *prop) { |
mukesh agrawal | 4d260da | 2012-01-30 11:53:52 -0800 | [diff] [blame] | 426 | DCHECK(!Contains(name) || ContainsKey(stringmaps_properties_, name)) |
| 427 | << "(Already registered " << name << ")"; |
Darin Petkov | c086531 | 2011-09-16 15:31:20 -0700 | [diff] [blame] | 428 | stringmaps_properties_[name] = |
| 429 | StringmapsAccessor(new PropertyAccessor<Stringmaps>(prop)); |
| 430 | } |
| 431 | |
| 432 | void PropertyStore::RegisterConstStringmaps(const string &name, |
| 433 | const Stringmaps *prop) { |
mukesh agrawal | 4d260da | 2012-01-30 11:53:52 -0800 | [diff] [blame] | 434 | DCHECK(!Contains(name) || ContainsKey(stringmaps_properties_, name)) |
| 435 | << "(Already registered " << name << ")"; |
Darin Petkov | c086531 | 2011-09-16 15:31:20 -0700 | [diff] [blame] | 436 | stringmaps_properties_[name] = |
| 437 | StringmapsAccessor(new ConstPropertyAccessor<Stringmaps>(prop)); |
| 438 | } |
| 439 | |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 440 | void PropertyStore::RegisterWriteOnlyStringmaps(const string &name, |
| 441 | Stringmaps *prop) { |
mukesh agrawal | 4d260da | 2012-01-30 11:53:52 -0800 | [diff] [blame] | 442 | DCHECK(!Contains(name) || ContainsKey(stringmaps_properties_, name)) |
| 443 | << "(Already registered " << name << ")"; |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 444 | stringmaps_properties_[name] = |
| 445 | StringmapsAccessor(new WriteOnlyPropertyAccessor<Stringmaps>(prop)); |
| 446 | } |
| 447 | |
Chris Masone | 43b48a1 | 2011-07-01 13:37:07 -0700 | [diff] [blame] | 448 | void PropertyStore::RegisterStrings(const string &name, Strings *prop) { |
mukesh agrawal | 4d260da | 2012-01-30 11:53:52 -0800 | [diff] [blame] | 449 | DCHECK(!Contains(name) || ContainsKey(strings_properties_, name)) |
| 450 | << "(Already registered " << name << ")"; |
Chris Masone | 43b48a1 | 2011-07-01 13:37:07 -0700 | [diff] [blame] | 451 | strings_properties_[name] = |
| 452 | StringsAccessor(new PropertyAccessor<Strings>(prop)); |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 453 | } |
| 454 | |
Chris Masone | 889666b | 2011-07-03 12:58:50 -0700 | [diff] [blame] | 455 | void PropertyStore::RegisterConstStrings(const string &name, |
| 456 | const Strings *prop) { |
mukesh agrawal | 4d260da | 2012-01-30 11:53:52 -0800 | [diff] [blame] | 457 | DCHECK(!Contains(name) || ContainsKey(strings_properties_, name)) |
| 458 | << "(Already registered " << name << ")"; |
Chris Masone | 889666b | 2011-07-03 12:58:50 -0700 | [diff] [blame] | 459 | strings_properties_[name] = |
| 460 | StringsAccessor(new ConstPropertyAccessor<Strings>(prop)); |
| 461 | } |
| 462 | |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 463 | void PropertyStore::RegisterWriteOnlyStrings(const string &name, |
| 464 | Strings *prop) { |
mukesh agrawal | 4d260da | 2012-01-30 11:53:52 -0800 | [diff] [blame] | 465 | DCHECK(!Contains(name) || ContainsKey(strings_properties_, name)) |
| 466 | << "(Already registered " << name << ")"; |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 467 | strings_properties_[name] = |
| 468 | StringsAccessor(new WriteOnlyPropertyAccessor<Strings>(prop)); |
| 469 | } |
| 470 | |
Chris Masone | 889666b | 2011-07-03 12:58:50 -0700 | [diff] [blame] | 471 | void PropertyStore::RegisterUint8(const string &name, uint8 *prop) { |
mukesh agrawal | 4d260da | 2012-01-30 11:53:52 -0800 | [diff] [blame] | 472 | DCHECK(!Contains(name) || ContainsKey(uint8_properties_, name)) |
| 473 | << "(Already registered " << name << ")"; |
Chris Masone | 889666b | 2011-07-03 12:58:50 -0700 | [diff] [blame] | 474 | uint8_properties_[name] = Uint8Accessor(new PropertyAccessor<uint8>(prop)); |
| 475 | } |
| 476 | |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 477 | void PropertyStore::RegisterConstUint8(const string &name, const uint8 *prop) { |
mukesh agrawal | 4d260da | 2012-01-30 11:53:52 -0800 | [diff] [blame] | 478 | DCHECK(!Contains(name) || ContainsKey(uint8_properties_, name)) |
| 479 | << "(Already registered " << name << ")"; |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 480 | uint8_properties_[name] = |
| 481 | Uint8Accessor(new ConstPropertyAccessor<uint8>(prop)); |
| 482 | } |
| 483 | |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 484 | void PropertyStore::RegisterWriteOnlyUint8(const string &name, uint8 *prop) { |
mukesh agrawal | 4d260da | 2012-01-30 11:53:52 -0800 | [diff] [blame] | 485 | DCHECK(!Contains(name) || ContainsKey(uint8_properties_, name)) |
| 486 | << "(Already registered " << name << ")"; |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 487 | uint8_properties_[name] = |
| 488 | Uint8Accessor(new WriteOnlyPropertyAccessor<uint8>(prop)); |
| 489 | } |
| 490 | |
mukesh agrawal | 66b0aca | 2012-01-30 15:28:28 -0800 | [diff] [blame] | 491 | void PropertyStore::RegisterUint16(const string &name, uint16 *prop) { |
mukesh agrawal | 4d260da | 2012-01-30 11:53:52 -0800 | [diff] [blame] | 492 | DCHECK(!Contains(name) || ContainsKey(uint16_properties_, name)) |
| 493 | << "(Already registered " << name << ")"; |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 494 | uint16_properties_[name] = Uint16Accessor(new PropertyAccessor<uint16>(prop)); |
| 495 | } |
| 496 | |
mukesh agrawal | 4d260da | 2012-01-30 11:53:52 -0800 | [diff] [blame] | 497 | void PropertyStore::RegisterUint32(const std::string &name, uint32 *prop) { |
| 498 | DCHECK(!Contains(name) || ContainsKey(uint32_properties_, name)) |
| 499 | << "(Already registered " << name << ")"; |
| 500 | uint32_properties_[name] = Uint32Accessor(new PropertyAccessor<uint32>(prop)); |
| 501 | } |
| 502 | |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 503 | void PropertyStore::RegisterConstUint16(const string &name, |
| 504 | const uint16 *prop) { |
mukesh agrawal | 4d260da | 2012-01-30 11:53:52 -0800 | [diff] [blame] | 505 | DCHECK(!Contains(name) || ContainsKey(uint16_properties_, name)) |
| 506 | << "(Already registered " << name << ")"; |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 507 | uint16_properties_[name] = |
| 508 | Uint16Accessor(new ConstPropertyAccessor<uint16>(prop)); |
| 509 | } |
| 510 | |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 511 | void PropertyStore::RegisterWriteOnlyUint16(const string &name, uint16 *prop) { |
mukesh agrawal | 4d260da | 2012-01-30 11:53:52 -0800 | [diff] [blame] | 512 | DCHECK(!Contains(name) || ContainsKey(uint16_properties_, name)) |
| 513 | << "(Already registered " << name << ")"; |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 514 | uint16_properties_[name] = |
| 515 | Uint16Accessor(new WriteOnlyPropertyAccessor<uint16>(prop)); |
| 516 | } |
| 517 | |
mukesh agrawal | 66b0aca | 2012-01-30 15:28:28 -0800 | [diff] [blame] | 518 | void PropertyStore::RegisterDerivedBool(const string &name, |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 519 | const BoolAccessor &accessor) { |
mukesh agrawal | 4d260da | 2012-01-30 11:53:52 -0800 | [diff] [blame] | 520 | DCHECK(!Contains(name) || ContainsKey(bool_properties_, name)) |
| 521 | << "(Already registered " << name << ")"; |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 522 | bool_properties_[name] = accessor; |
| 523 | } |
| 524 | |
mukesh agrawal | 66b0aca | 2012-01-30 15:28:28 -0800 | [diff] [blame] | 525 | void PropertyStore::RegisterDerivedInt32(const string &name, |
mukesh agrawal | 4d0401c | 2012-01-06 16:05:31 -0800 | [diff] [blame] | 526 | const Int32Accessor &accessor) { |
mukesh agrawal | 4d260da | 2012-01-30 11:53:52 -0800 | [diff] [blame] | 527 | DCHECK(!Contains(name) || ContainsKey(int32_properties_, name)) |
| 528 | << "(Already registered " << name << ")"; |
mukesh agrawal | 4d0401c | 2012-01-06 16:05:31 -0800 | [diff] [blame] | 529 | int32_properties_[name] = accessor; |
| 530 | } |
| 531 | |
Darin Petkov | 63138a9 | 2012-02-06 14:09:15 +0100 | [diff] [blame] | 532 | void PropertyStore::RegisterDerivedKeyValueStore( |
mukesh agrawal | 66b0aca | 2012-01-30 15:28:28 -0800 | [diff] [blame] | 533 | const string &name, |
Darin Petkov | 63138a9 | 2012-02-06 14:09:15 +0100 | [diff] [blame] | 534 | const KeyValueStoreAccessor &acc) { |
mukesh agrawal | 4d260da | 2012-01-30 11:53:52 -0800 | [diff] [blame] | 535 | DCHECK(!Contains(name) || ContainsKey(key_value_store_properties_, name)) |
| 536 | << "(Already registered " << name << ")"; |
Darin Petkov | 63138a9 | 2012-02-06 14:09:15 +0100 | [diff] [blame] | 537 | key_value_store_properties_[name] = acc; |
| 538 | } |
| 539 | |
Jason Glasgow | acdc11f | 2012-03-30 14:12:22 -0400 | [diff] [blame] | 540 | void PropertyStore::RegisterDerivedRpcIdentifier( |
| 541 | const string &name, |
| 542 | const RpcIdentifierAccessor &acc) { |
| 543 | DCHECK(!Contains(name) || ContainsKey(rpc_identifier_properties_, name)) |
| 544 | << "(Already registered " << name << ")"; |
| 545 | rpc_identifier_properties_[name] = acc; |
| 546 | } |
| 547 | |
mukesh agrawal | 2366eed | 2012-03-20 18:21:50 -0700 | [diff] [blame] | 548 | void PropertyStore::RegisterDerivedRpcIdentifiers( |
| 549 | const string &name, |
| 550 | const RpcIdentifiersAccessor &accessor) { |
| 551 | DCHECK(!Contains(name) || ContainsKey(rpc_identifiers_properties_, name)) |
| 552 | << "(Already registered " << name << ")"; |
| 553 | rpc_identifiers_properties_[name] = accessor; |
| 554 | } |
| 555 | |
mukesh agrawal | 66b0aca | 2012-01-30 15:28:28 -0800 | [diff] [blame] | 556 | void PropertyStore::RegisterDerivedString(const string &name, |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 557 | const StringAccessor &accessor) { |
mukesh agrawal | 4d260da | 2012-01-30 11:53:52 -0800 | [diff] [blame] | 558 | DCHECK(!Contains(name) || ContainsKey(string_properties_, name)) |
| 559 | << "(Already registered " << name << ")"; |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 560 | string_properties_[name] = accessor; |
| 561 | } |
| 562 | |
mukesh agrawal | 66b0aca | 2012-01-30 15:28:28 -0800 | [diff] [blame] | 563 | void PropertyStore::RegisterDerivedStrings(const string &name, |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 564 | const StringsAccessor &accessor) { |
mukesh agrawal | 4d260da | 2012-01-30 11:53:52 -0800 | [diff] [blame] | 565 | DCHECK(!Contains(name) || ContainsKey(strings_properties_, name)) |
| 566 | << "(Already registered " << name << ")"; |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 567 | strings_properties_[name] = accessor; |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 568 | } |
| 569 | |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 570 | void PropertyStore::RegisterDerivedStringmap(const string &name, |
| 571 | const StringmapAccessor &acc) { |
| 572 | DCHECK(!Contains(name) || ContainsKey(stringmap_properties_, name)) |
| 573 | << "(Already registered " << name << ")"; |
| 574 | stringmap_properties_[name] = acc; |
| 575 | } |
| 576 | |
mukesh agrawal | 66b0aca | 2012-01-30 15:28:28 -0800 | [diff] [blame] | 577 | void PropertyStore::RegisterDerivedStringmaps(const string &name, |
Chris Masone | 889666b | 2011-07-03 12:58:50 -0700 | [diff] [blame] | 578 | const StringmapsAccessor &acc) { |
mukesh agrawal | 4d260da | 2012-01-30 11:53:52 -0800 | [diff] [blame] | 579 | DCHECK(!Contains(name) || ContainsKey(stringmaps_properties_, name)) |
| 580 | << "(Already registered " << name << ")"; |
Chris Masone | 889666b | 2011-07-03 12:58:50 -0700 | [diff] [blame] | 581 | stringmaps_properties_[name] = acc; |
| 582 | } |
| 583 | |
mukesh agrawal | 66b0aca | 2012-01-30 15:28:28 -0800 | [diff] [blame] | 584 | void PropertyStore::RegisterDerivedUint16(const string &name, |
Paul Stewart | be5f5b3 | 2011-12-07 17:11:11 -0800 | [diff] [blame] | 585 | const Uint16Accessor &acc) { |
mukesh agrawal | 4d260da | 2012-01-30 11:53:52 -0800 | [diff] [blame] | 586 | DCHECK(!Contains(name) || ContainsKey(uint16_properties_, name)) |
| 587 | << "(Already registered " << name << ")"; |
Paul Stewart | be5f5b3 | 2011-12-07 17:11:11 -0800 | [diff] [blame] | 588 | uint16_properties_[name] = acc; |
| 589 | } |
| 590 | |
Paul Stewart | e18c33b | 2012-07-10 20:48:44 -0700 | [diff] [blame] | 591 | void PropertyStore::RegisterDerivedUint64(const string &name, |
| 592 | const Uint64Accessor &acc) { |
| 593 | DCHECK(!Contains(name) || ContainsKey(uint64_properties_, name)) |
| 594 | << "(Already registered " << name << ")"; |
| 595 | uint64_properties_[name] = acc; |
| 596 | } |
| 597 | |
mukesh agrawal | 66b0aca | 2012-01-30 15:28:28 -0800 | [diff] [blame] | 598 | // private methods |
| 599 | |
mukesh agrawal | ffa3d04 | 2011-10-06 15:26:10 -0700 | [diff] [blame] | 600 | template <class V> |
Paul Stewart | e6e8e49 | 2013-01-17 11:00:50 -0800 | [diff] [blame] | 601 | bool PropertyStore::GetProperty( |
| 602 | const string &name, |
| 603 | V *value, |
| 604 | Error *error, |
| 605 | const map< string, std::tr1::shared_ptr< |
| 606 | AccessorInterface<V> > >&collection, |
| 607 | const string &value_type_english) const { |
| 608 | SLOG(Property, 2) << "Getting " << name << " as " << value_type_english |
| 609 | << "."; |
| 610 | typename map< string, std::tr1::shared_ptr< |
| 611 | AccessorInterface<V> > >::const_iterator it = collection.find(name); |
| 612 | if (it != collection.end()) { |
| 613 | V val = it->second->Get(error); |
| 614 | if (error->IsSuccess()) { |
| 615 | *value = val; |
| 616 | } |
| 617 | } else { |
| 618 | if (Contains(name)) { |
| 619 | error->Populate( |
| 620 | Error::kInvalidArguments, |
| 621 | "Property " + name + " is not " + value_type_english + "."); |
| 622 | } else { |
| 623 | error->Populate( |
| 624 | Error::kInvalidProperty, "Property " + name + " does not exist."); |
| 625 | } |
| 626 | } |
| 627 | return error->IsSuccess(); |
| 628 | }; |
| 629 | |
| 630 | template <class V> |
mukesh agrawal | ffa3d04 | 2011-10-06 15:26:10 -0700 | [diff] [blame] | 631 | bool PropertyStore::SetProperty( |
| 632 | const string &name, |
| 633 | const V &value, |
| 634 | Error *error, |
| 635 | map< string, std::tr1::shared_ptr< AccessorInterface<V> > >&collection, |
| 636 | const string &value_type_english) { |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 637 | bool ret = false; |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 638 | SLOG(Property, 2) << "Setting " << name << " as " << value_type_english |
| 639 | << "."; |
mukesh agrawal | ffa3d04 | 2011-10-06 15:26:10 -0700 | [diff] [blame] | 640 | if (ContainsKey(collection, name)) { |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 641 | ret = collection[name]->Set(value, error); |
| 642 | if (ret) { |
| 643 | if (!property_changed_callback_.is_null()) { |
| 644 | property_changed_callback_.Run(name); |
| 645 | } |
| 646 | } |
mukesh agrawal | ffa3d04 | 2011-10-06 15:26:10 -0700 | [diff] [blame] | 647 | } else { |
| 648 | if (Contains(name)) { |
| 649 | error->Populate( |
| 650 | Error::kInvalidArguments, |
| 651 | "Property " + name + " is not " + value_type_english + "."); |
| 652 | } else { |
| 653 | error->Populate( |
| 654 | Error::kInvalidProperty, "Property " + name + " does not exist."); |
| 655 | } |
| 656 | } |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 657 | return ret; |
mukesh agrawal | ffa3d04 | 2011-10-06 15:26:10 -0700 | [diff] [blame] | 658 | }; |
| 659 | |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 660 | } // namespace shill |