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