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