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