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