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