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