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