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