blob: bb1a87c7bdbc9b802366deb0dae08251cd02c6b6 [file] [log] [blame]
mukesh agrawal4d0401c2012-01-06 16:05:31 -08001// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
Chris Masoneb925cc82011-06-22 15:39:57 -07002// 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 Shienbrood3e20a232012-02-16 11:35:56 -050012#include <base/stl_util.h>
Chris Masoneb925cc82011-06-22 15:39:57 -070013
14#include "shill/error.h"
Christopher Wileyb691efd2012-08-09 13:51:51 -070015#include "shill/logging.h"
Chris Masoneb925cc82011-06-22 15:39:57 -070016#include "shill/property_accessor.h"
17
18using std::map;
19using std::string;
20using std::vector;
21
22namespace shill {
23
24PropertyStore::PropertyStore() {}
25
26PropertyStore::~PropertyStore() {}
27
mukesh agrawal66b0aca2012-01-30 15:28:28 -080028bool PropertyStore::Contains(const string &prop) const {
29 return (ContainsKey(bool_properties_, prop) ||
30 ContainsKey(int16_properties_, prop) ||
31 ContainsKey(int32_properties_, prop) ||
32 ContainsKey(key_value_store_properties_, prop) ||
33 ContainsKey(string_properties_, prop) ||
34 ContainsKey(stringmap_properties_, prop) ||
35 ContainsKey(stringmaps_properties_, prop) ||
36 ContainsKey(strings_properties_, prop) ||
37 ContainsKey(uint8_properties_, prop) ||
38 ContainsKey(uint16_properties_, prop) ||
Jason Glasgowacdc11f2012-03-30 14:12:22 -040039 ContainsKey(uint32_properties_, prop) ||
Paul Stewarte18c33b2012-07-10 20:48:44 -070040 ContainsKey(uint64_properties_, prop) ||
Jason Glasgowacdc11f2012-03-30 14:12:22 -040041 ContainsKey(rpc_identifier_properties_, prop) ||
42 ContainsKey(rpc_identifiers_properties_, prop));
Chris Masoneb925cc82011-06-22 15:39:57 -070043}
44
mukesh agrawal66b0aca2012-01-30 15:28:28 -080045bool PropertyStore::SetBoolProperty(const string &name,
Chris Masoneb925cc82011-06-22 15:39:57 -070046 bool value,
47 Error *error) {
mukesh agrawalffa3d042011-10-06 15:26:10 -070048 return SetProperty(name, value, error, bool_properties_, "a bool");
Chris Masoneb925cc82011-06-22 15:39:57 -070049}
50
mukesh agrawal66b0aca2012-01-30 15:28:28 -080051bool PropertyStore::SetInt16Property(const string &name,
Chris Masoneb925cc82011-06-22 15:39:57 -070052 int16 value,
53 Error *error) {
mukesh agrawalffa3d042011-10-06 15:26:10 -070054 return SetProperty(name, value, error, int16_properties_, "an int16");
Chris Masoneb925cc82011-06-22 15:39:57 -070055}
56
mukesh agrawal66b0aca2012-01-30 15:28:28 -080057bool PropertyStore::SetInt32Property(const string &name,
Chris Masoneb925cc82011-06-22 15:39:57 -070058 int32 value,
59 Error *error) {
mukesh agrawalffa3d042011-10-06 15:26:10 -070060 return SetProperty(name, value, error, int32_properties_, "an int32.");
Chris Masoneb925cc82011-06-22 15:39:57 -070061}
62
mukesh agrawal66b0aca2012-01-30 15:28:28 -080063bool PropertyStore::SetStringProperty(const string &name,
64 const string &value,
Chris Masoneb925cc82011-06-22 15:39:57 -070065 Error *error) {
mukesh agrawalffa3d042011-10-06 15:26:10 -070066 return SetProperty(name, value, error, string_properties_, "a string");
Chris Masoneb925cc82011-06-22 15:39:57 -070067}
68
mukesh agrawal66b0aca2012-01-30 15:28:28 -080069bool PropertyStore::SetStringmapProperty(const string &name,
70 const map<string, string> &values,
71 Error *error) {
mukesh agrawalffa3d042011-10-06 15:26:10 -070072 return SetProperty(name, values, error, stringmap_properties_,
73 "a string map");
Chris Masoneb925cc82011-06-22 15:39:57 -070074}
75
mukesh agrawal66b0aca2012-01-30 15:28:28 -080076bool PropertyStore::SetStringsProperty(const string &name,
77 const vector<string> &values,
Chris Masoneb925cc82011-06-22 15:39:57 -070078 Error *error) {
mukesh agrawalffa3d042011-10-06 15:26:10 -070079 return SetProperty(name, values, error, strings_properties_, "a string list");
Chris Masoneb925cc82011-06-22 15:39:57 -070080}
81
mukesh agrawal66b0aca2012-01-30 15:28:28 -080082bool PropertyStore::SetUint8Property(const string &name,
Chris Masoneb925cc82011-06-22 15:39:57 -070083 uint8 value,
84 Error *error) {
mukesh agrawalffa3d042011-10-06 15:26:10 -070085 return SetProperty(name, value, error, uint8_properties_, "a uint8");
Chris Masoneb925cc82011-06-22 15:39:57 -070086}
87
mukesh agrawal66b0aca2012-01-30 15:28:28 -080088bool PropertyStore::SetUint16Property(const string &name,
Chris Masoneb925cc82011-06-22 15:39:57 -070089 uint16 value,
90 Error *error) {
mukesh agrawalffa3d042011-10-06 15:26:10 -070091 return SetProperty(name, value, error, uint16_properties_, "a uint16");
Chris Masoneb925cc82011-06-22 15:39:57 -070092}
93
mukesh agrawal66b0aca2012-01-30 15:28:28 -080094bool PropertyStore::SetUint32Property(const string &name,
Chris Masoneb925cc82011-06-22 15:39:57 -070095 uint32 value,
96 Error *error) {
mukesh agrawalffa3d042011-10-06 15:26:10 -070097 return SetProperty(name, value, error, uint32_properties_, "a uint32");
Chris Masoneb925cc82011-06-22 15:39:57 -070098}
99
Paul Stewarte18c33b2012-07-10 20:48:44 -0700100bool PropertyStore::SetUint64Property(const string &name,
101 uint64 value,
102 Error *error) {
103 return SetProperty(name, value, error, uint64_properties_, "a uint64");
104}
105
Jason Glasgowacdc11f2012-03-30 14:12:22 -0400106bool PropertyStore::SetRpcIdentifierProperty(const string &name,
107 const RpcIdentifier &value,
108 Error *error) {
109 return SetProperty(name, value, error, rpc_identifier_properties_,
110 "an rpc_identifier");
111}
112
mukesh agrawal4d260da2012-01-30 11:53:52 -0800113bool PropertyStore::ClearProperty(const string &name, Error *error) {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700114 SLOG(Property, 2) << "Clearing " << name << ".";
mukesh agrawal4d260da2012-01-30 11:53:52 -0800115
116 if (ContainsKey(bool_properties_, name)) {
117 bool_properties_[name]->Clear(error);
118 } else if (ContainsKey(int16_properties_, name)) {
119 int16_properties_[name]->Clear(error);
120 } else if (ContainsKey(int32_properties_, name)) {
121 int32_properties_[name]->Clear(error);
122 } else if (ContainsKey(key_value_store_properties_, name)) {
123 key_value_store_properties_[name]->Clear(error);
124 } else if (ContainsKey(string_properties_, name)) {
125 string_properties_[name]->Clear(error);
126 } else if (ContainsKey(stringmap_properties_, name)) {
127 stringmap_properties_[name]->Clear(error);
128 } else if (ContainsKey(stringmaps_properties_, name)) {
129 stringmaps_properties_[name]->Clear(error);
130 } else if (ContainsKey(strings_properties_, name)) {
131 strings_properties_[name]->Clear(error);
132 } else if (ContainsKey(uint8_properties_, name)) {
133 uint8_properties_[name]->Clear(error);
134 } else if (ContainsKey(uint16_properties_, name)) {
135 uint16_properties_[name]->Clear(error);
136 } else if (ContainsKey(uint32_properties_, name)) {
137 uint32_properties_[name]->Clear(error);
Paul Stewarte18c33b2012-07-10 20:48:44 -0700138 } else if (ContainsKey(uint64_properties_, name)) {
139 uint64_properties_[name]->Clear(error);
Jason Glasgowacdc11f2012-03-30 14:12:22 -0400140 } else if (ContainsKey(rpc_identifier_properties_, name)) {
141 rpc_identifier_properties_[name]->Clear(error);
142 } else if (ContainsKey(rpc_identifiers_properties_, name)) {
143 rpc_identifiers_properties_[name]->Clear(error);
mukesh agrawal4d260da2012-01-30 11:53:52 -0800144 } else {
145 error->Populate(
146 Error::kInvalidProperty, "Property " + name + " does not exist.");
147 }
148 return error->IsSuccess();
149}
150
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800151ReadablePropertyConstIterator<bool> PropertyStore::GetBoolPropertiesIter()
mukesh agrawalde29fa82011-09-16 16:16:36 -0700152 const {
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800153 return ReadablePropertyConstIterator<bool>(bool_properties_);
Chris Masonea8a2c252011-06-27 22:16:30 -0700154}
155
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800156ReadablePropertyConstIterator<int16> PropertyStore::GetInt16PropertiesIter()
mukesh agrawalde29fa82011-09-16 16:16:36 -0700157 const {
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800158 return ReadablePropertyConstIterator<int16>(int16_properties_);
Chris Masonea8a2c252011-06-27 22:16:30 -0700159}
160
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800161ReadablePropertyConstIterator<int32> PropertyStore::GetInt32PropertiesIter()
mukesh agrawalde29fa82011-09-16 16:16:36 -0700162 const {
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800163 return ReadablePropertyConstIterator<int32>(int32_properties_);
Chris Masone889666b2011-07-03 12:58:50 -0700164}
165
Darin Petkov63138a92012-02-06 14:09:15 +0100166ReadablePropertyConstIterator<KeyValueStore>
167PropertyStore::GetKeyValueStorePropertiesIter() const {
168 return
169 ReadablePropertyConstIterator<KeyValueStore>(key_value_store_properties_);
170}
171
Jason Glasgowacdc11f2012-03-30 14:12:22 -0400172ReadablePropertyConstIterator<RpcIdentifier>
173PropertyStore::GetRpcIdentifierPropertiesIter() const {
174 return ReadablePropertyConstIterator<RpcIdentifier>(
175 rpc_identifier_properties_);
176}
177
mukesh agrawal2366eed2012-03-20 18:21:50 -0700178ReadablePropertyConstIterator<RpcIdentifiers>
179PropertyStore::GetRpcIdentifiersPropertiesIter() const {
180 return ReadablePropertyConstIterator<RpcIdentifiers>(
181 rpc_identifiers_properties_);
182}
183
mukesh agrawal66b0aca2012-01-30 15:28:28 -0800184ReadablePropertyConstIterator<string>
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800185PropertyStore::GetStringPropertiesIter() const {
mukesh agrawal66b0aca2012-01-30 15:28:28 -0800186 return ReadablePropertyConstIterator<string>(string_properties_);
Chris Masonea8a2c252011-06-27 22:16:30 -0700187}
188
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800189ReadablePropertyConstIterator<Stringmap>
190PropertyStore::GetStringmapPropertiesIter() const {
191 return ReadablePropertyConstIterator<Stringmap>(stringmap_properties_);
Chris Masonea8a2c252011-06-27 22:16:30 -0700192}
193
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800194ReadablePropertyConstIterator<Stringmaps>
195PropertyStore::GetStringmapsPropertiesIter()
196 const {
197 return ReadablePropertyConstIterator<Stringmaps>(stringmaps_properties_);
198}
199
200ReadablePropertyConstIterator<Strings> PropertyStore::GetStringsPropertiesIter()
201 const {
202 return ReadablePropertyConstIterator<Strings>(strings_properties_);
203}
204
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800205ReadablePropertyConstIterator<uint8> PropertyStore::GetUint8PropertiesIter()
206 const {
207 return ReadablePropertyConstIterator<uint8>(uint8_properties_);
208}
209
210ReadablePropertyConstIterator<uint16> PropertyStore::GetUint16PropertiesIter()
211 const {
212 return ReadablePropertyConstIterator<uint16>(uint16_properties_);
213}
214
215ReadablePropertyConstIterator<uint32> PropertyStore::GetUint32PropertiesIter()
216 const {
217 return ReadablePropertyConstIterator<uint32>(uint32_properties_);
Chris Masonea8a2c252011-06-27 22:16:30 -0700218}
219
Paul Stewarte18c33b2012-07-10 20:48:44 -0700220ReadablePropertyConstIterator<uint64> PropertyStore::GetUint64PropertiesIter()
221 const {
222 return ReadablePropertyConstIterator<uint64>(uint64_properties_);
223}
224
Chris Masoneb925cc82011-06-22 15:39:57 -0700225void PropertyStore::RegisterBool(const string &name, bool *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800226 DCHECK(!Contains(name) || ContainsKey(bool_properties_, name))
227 << "(Already registered " << name << ")";
Chris Masoneb925cc82011-06-22 15:39:57 -0700228 bool_properties_[name] = BoolAccessor(new PropertyAccessor<bool>(prop));
229}
230
231void PropertyStore::RegisterConstBool(const string &name, const bool *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800232 DCHECK(!Contains(name) || ContainsKey(bool_properties_, name))
233 << "(Already registered " << name << ")";
Chris Masoneb925cc82011-06-22 15:39:57 -0700234 bool_properties_[name] = BoolAccessor(new ConstPropertyAccessor<bool>(prop));
235}
236
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800237void PropertyStore::RegisterWriteOnlyBool(const string &name, bool *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800238 DCHECK(!Contains(name) || ContainsKey(bool_properties_, name))
239 << "(Already registered " << name << ")";
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800240 bool_properties_[name] = BoolAccessor(
241 new WriteOnlyPropertyAccessor<bool>(prop));
242}
243
Chris Masoneb925cc82011-06-22 15:39:57 -0700244void PropertyStore::RegisterInt16(const string &name, int16 *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800245 DCHECK(!Contains(name) || ContainsKey(int16_properties_, name))
246 << "(Already registered " << name << ")";
Chris Masoneb925cc82011-06-22 15:39:57 -0700247 int16_properties_[name] = Int16Accessor(new PropertyAccessor<int16>(prop));
248}
249
250void PropertyStore::RegisterConstInt16(const string &name, const int16 *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800251 DCHECK(!Contains(name) || ContainsKey(int16_properties_, name))
252 << "(Already registered " << name << ")";
Chris Masoneb925cc82011-06-22 15:39:57 -0700253 int16_properties_[name] =
254 Int16Accessor(new ConstPropertyAccessor<int16>(prop));
255}
256
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800257void PropertyStore::RegisterWriteOnlyInt16(const string &name, int16 *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800258 DCHECK(!Contains(name) || ContainsKey(int16_properties_, name))
259 << "(Already registered " << name << ")";
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800260 int16_properties_[name] =
261 Int16Accessor(new WriteOnlyPropertyAccessor<int16>(prop));
262}
Chris Masoneb925cc82011-06-22 15:39:57 -0700263void PropertyStore::RegisterInt32(const string &name, int32 *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800264 DCHECK(!Contains(name) || ContainsKey(int32_properties_, name))
265 << "(Already registered " << name << ")";
Chris Masoneb925cc82011-06-22 15:39:57 -0700266 int32_properties_[name] = Int32Accessor(new PropertyAccessor<int32>(prop));
267}
268
269void PropertyStore::RegisterConstInt32(const string &name, const int32 *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800270 DCHECK(!Contains(name) || ContainsKey(int32_properties_, name))
271 << "(Already registered " << name << ")";
Chris Masoneb925cc82011-06-22 15:39:57 -0700272 int32_properties_[name] =
273 Int32Accessor(new ConstPropertyAccessor<int32>(prop));
274}
275
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800276void PropertyStore::RegisterWriteOnlyInt32(const string &name, int32 *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800277 DCHECK(!Contains(name) || ContainsKey(int32_properties_, name))
278 << "(Already registered " << name << ")";
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800279 int32_properties_[name] =
280 Int32Accessor(new WriteOnlyPropertyAccessor<int32>(prop));
281}
282
Chris Masoneb925cc82011-06-22 15:39:57 -0700283void PropertyStore::RegisterString(const string &name, string *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800284 DCHECK(!Contains(name) || ContainsKey(string_properties_, name))
285 << "(Already registered " << name << ")";
Chris Masoneb925cc82011-06-22 15:39:57 -0700286 string_properties_[name] = StringAccessor(new PropertyAccessor<string>(prop));
287}
288
289void PropertyStore::RegisterConstString(const string &name,
290 const string *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800291 DCHECK(!Contains(name) || ContainsKey(string_properties_, name))
292 << "(Already registered " << name << ")";
Chris Masoneb925cc82011-06-22 15:39:57 -0700293 string_properties_[name] =
294 StringAccessor(new ConstPropertyAccessor<string>(prop));
295}
296
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800297void PropertyStore::RegisterWriteOnlyString(const string &name, string *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800298 DCHECK(!Contains(name) || ContainsKey(string_properties_, name))
299 << "(Already registered " << name << ")";
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800300 string_properties_[name] =
301 StringAccessor(new WriteOnlyPropertyAccessor<string>(prop));
302}
303
Chris Masone43b48a12011-07-01 13:37:07 -0700304void PropertyStore::RegisterStringmap(const string &name, Stringmap *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800305 DCHECK(!Contains(name) || ContainsKey(stringmap_properties_, name))
306 << "(Already registered " << name << ")";
Chris Masoneb925cc82011-06-22 15:39:57 -0700307 stringmap_properties_[name] =
Chris Masone43b48a12011-07-01 13:37:07 -0700308 StringmapAccessor(new PropertyAccessor<Stringmap>(prop));
Chris Masoneb925cc82011-06-22 15:39:57 -0700309}
310
311void PropertyStore::RegisterConstStringmap(const string &name,
Chris Masone43b48a12011-07-01 13:37:07 -0700312 const Stringmap *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800313 DCHECK(!Contains(name) || ContainsKey(stringmap_properties_, name))
314 << "(Already registered " << name << ")";
Chris Masoneb925cc82011-06-22 15:39:57 -0700315 stringmap_properties_[name] =
Chris Masone43b48a12011-07-01 13:37:07 -0700316 StringmapAccessor(new ConstPropertyAccessor<Stringmap>(prop));
317}
318
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800319void PropertyStore::RegisterWriteOnlyStringmap(const string &name,
320 Stringmap *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800321 DCHECK(!Contains(name) || ContainsKey(stringmap_properties_, name))
322 << "(Already registered " << name << ")";
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800323 stringmap_properties_[name] =
324 StringmapAccessor(new WriteOnlyPropertyAccessor<Stringmap>(prop));
325}
326
Darin Petkovc0865312011-09-16 15:31:20 -0700327void PropertyStore::RegisterStringmaps(const string &name, Stringmaps *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800328 DCHECK(!Contains(name) || ContainsKey(stringmaps_properties_, name))
329 << "(Already registered " << name << ")";
Darin Petkovc0865312011-09-16 15:31:20 -0700330 stringmaps_properties_[name] =
331 StringmapsAccessor(new PropertyAccessor<Stringmaps>(prop));
332}
333
334void PropertyStore::RegisterConstStringmaps(const string &name,
335 const Stringmaps *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800336 DCHECK(!Contains(name) || ContainsKey(stringmaps_properties_, name))
337 << "(Already registered " << name << ")";
Darin Petkovc0865312011-09-16 15:31:20 -0700338 stringmaps_properties_[name] =
339 StringmapsAccessor(new ConstPropertyAccessor<Stringmaps>(prop));
340}
341
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800342void PropertyStore::RegisterWriteOnlyStringmaps(const string &name,
343 Stringmaps *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800344 DCHECK(!Contains(name) || ContainsKey(stringmaps_properties_, name))
345 << "(Already registered " << name << ")";
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800346 stringmaps_properties_[name] =
347 StringmapsAccessor(new WriteOnlyPropertyAccessor<Stringmaps>(prop));
348}
349
Chris Masone43b48a12011-07-01 13:37:07 -0700350void PropertyStore::RegisterStrings(const string &name, Strings *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800351 DCHECK(!Contains(name) || ContainsKey(strings_properties_, name))
352 << "(Already registered " << name << ")";
Chris Masone43b48a12011-07-01 13:37:07 -0700353 strings_properties_[name] =
354 StringsAccessor(new PropertyAccessor<Strings>(prop));
Chris Masoneb925cc82011-06-22 15:39:57 -0700355}
356
Chris Masone889666b2011-07-03 12:58:50 -0700357void PropertyStore::RegisterConstStrings(const string &name,
358 const Strings *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800359 DCHECK(!Contains(name) || ContainsKey(strings_properties_, name))
360 << "(Already registered " << name << ")";
Chris Masone889666b2011-07-03 12:58:50 -0700361 strings_properties_[name] =
362 StringsAccessor(new ConstPropertyAccessor<Strings>(prop));
363}
364
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800365void PropertyStore::RegisterWriteOnlyStrings(const string &name,
366 Strings *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800367 DCHECK(!Contains(name) || ContainsKey(strings_properties_, name))
368 << "(Already registered " << name << ")";
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800369 strings_properties_[name] =
370 StringsAccessor(new WriteOnlyPropertyAccessor<Strings>(prop));
371}
372
Chris Masone889666b2011-07-03 12:58:50 -0700373void PropertyStore::RegisterUint8(const string &name, uint8 *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800374 DCHECK(!Contains(name) || ContainsKey(uint8_properties_, name))
375 << "(Already registered " << name << ")";
Chris Masone889666b2011-07-03 12:58:50 -0700376 uint8_properties_[name] = Uint8Accessor(new PropertyAccessor<uint8>(prop));
377}
378
Chris Masoneb925cc82011-06-22 15:39:57 -0700379void PropertyStore::RegisterConstUint8(const string &name, const uint8 *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800380 DCHECK(!Contains(name) || ContainsKey(uint8_properties_, name))
381 << "(Already registered " << name << ")";
Chris Masoneb925cc82011-06-22 15:39:57 -0700382 uint8_properties_[name] =
383 Uint8Accessor(new ConstPropertyAccessor<uint8>(prop));
384}
385
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800386void PropertyStore::RegisterWriteOnlyUint8(const string &name, uint8 *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800387 DCHECK(!Contains(name) || ContainsKey(uint8_properties_, name))
388 << "(Already registered " << name << ")";
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800389 uint8_properties_[name] =
390 Uint8Accessor(new WriteOnlyPropertyAccessor<uint8>(prop));
391}
392
mukesh agrawal66b0aca2012-01-30 15:28:28 -0800393void PropertyStore::RegisterUint16(const string &name, uint16 *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800394 DCHECK(!Contains(name) || ContainsKey(uint16_properties_, name))
395 << "(Already registered " << name << ")";
Chris Masoneb925cc82011-06-22 15:39:57 -0700396 uint16_properties_[name] = Uint16Accessor(new PropertyAccessor<uint16>(prop));
397}
398
mukesh agrawal4d260da2012-01-30 11:53:52 -0800399void PropertyStore::RegisterUint32(const std::string &name, uint32 *prop) {
400 DCHECK(!Contains(name) || ContainsKey(uint32_properties_, name))
401 << "(Already registered " << name << ")";
402 uint32_properties_[name] = Uint32Accessor(new PropertyAccessor<uint32>(prop));
403}
404
Chris Masoneb925cc82011-06-22 15:39:57 -0700405void PropertyStore::RegisterConstUint16(const string &name,
406 const uint16 *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800407 DCHECK(!Contains(name) || ContainsKey(uint16_properties_, name))
408 << "(Already registered " << name << ")";
Chris Masoneb925cc82011-06-22 15:39:57 -0700409 uint16_properties_[name] =
410 Uint16Accessor(new ConstPropertyAccessor<uint16>(prop));
411}
412
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800413void PropertyStore::RegisterWriteOnlyUint16(const string &name, uint16 *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800414 DCHECK(!Contains(name) || ContainsKey(uint16_properties_, name))
415 << "(Already registered " << name << ")";
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800416 uint16_properties_[name] =
417 Uint16Accessor(new WriteOnlyPropertyAccessor<uint16>(prop));
418}
419
mukesh agrawal66b0aca2012-01-30 15:28:28 -0800420void PropertyStore::RegisterDerivedBool(const string &name,
Chris Masone27c4aa52011-07-02 13:10:14 -0700421 const BoolAccessor &accessor) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800422 DCHECK(!Contains(name) || ContainsKey(bool_properties_, name))
423 << "(Already registered " << name << ")";
Chris Masone27c4aa52011-07-02 13:10:14 -0700424 bool_properties_[name] = accessor;
425}
426
mukesh agrawal66b0aca2012-01-30 15:28:28 -0800427void PropertyStore::RegisterDerivedInt32(const string &name,
mukesh agrawal4d0401c2012-01-06 16:05:31 -0800428 const Int32Accessor &accessor) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800429 DCHECK(!Contains(name) || ContainsKey(int32_properties_, name))
430 << "(Already registered " << name << ")";
mukesh agrawal4d0401c2012-01-06 16:05:31 -0800431 int32_properties_[name] = accessor;
432}
433
Darin Petkov63138a92012-02-06 14:09:15 +0100434void PropertyStore::RegisterDerivedKeyValueStore(
mukesh agrawal66b0aca2012-01-30 15:28:28 -0800435 const string &name,
Darin Petkov63138a92012-02-06 14:09:15 +0100436 const KeyValueStoreAccessor &acc) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800437 DCHECK(!Contains(name) || ContainsKey(key_value_store_properties_, name))
438 << "(Already registered " << name << ")";
Darin Petkov63138a92012-02-06 14:09:15 +0100439 key_value_store_properties_[name] = acc;
440}
441
Jason Glasgowacdc11f2012-03-30 14:12:22 -0400442void PropertyStore::RegisterDerivedRpcIdentifier(
443 const string &name,
444 const RpcIdentifierAccessor &acc) {
445 DCHECK(!Contains(name) || ContainsKey(rpc_identifier_properties_, name))
446 << "(Already registered " << name << ")";
447 rpc_identifier_properties_[name] = acc;
448}
449
mukesh agrawal2366eed2012-03-20 18:21:50 -0700450void PropertyStore::RegisterDerivedRpcIdentifiers(
451 const string &name,
452 const RpcIdentifiersAccessor &accessor) {
453 DCHECK(!Contains(name) || ContainsKey(rpc_identifiers_properties_, name))
454 << "(Already registered " << name << ")";
455 rpc_identifiers_properties_[name] = accessor;
456}
457
mukesh agrawal66b0aca2012-01-30 15:28:28 -0800458void PropertyStore::RegisterDerivedString(const string &name,
Chris Masone27c4aa52011-07-02 13:10:14 -0700459 const StringAccessor &accessor) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800460 DCHECK(!Contains(name) || ContainsKey(string_properties_, name))
461 << "(Already registered " << name << ")";
Chris Masone27c4aa52011-07-02 13:10:14 -0700462 string_properties_[name] = accessor;
463}
464
mukesh agrawal66b0aca2012-01-30 15:28:28 -0800465void PropertyStore::RegisterDerivedStrings(const string &name,
Chris Masone27c4aa52011-07-02 13:10:14 -0700466 const StringsAccessor &accessor) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800467 DCHECK(!Contains(name) || ContainsKey(strings_properties_, name))
468 << "(Already registered " << name << ")";
Chris Masone27c4aa52011-07-02 13:10:14 -0700469 strings_properties_[name] = accessor;
Chris Masoneb925cc82011-06-22 15:39:57 -0700470}
471
Eric Shienbrood30bc0ec2012-03-21 18:19:46 -0400472void PropertyStore::RegisterDerivedStringmap(const string &name,
473 const StringmapAccessor &acc) {
474 DCHECK(!Contains(name) || ContainsKey(stringmap_properties_, name))
475 << "(Already registered " << name << ")";
476 stringmap_properties_[name] = acc;
477}
478
mukesh agrawal66b0aca2012-01-30 15:28:28 -0800479void PropertyStore::RegisterDerivedStringmaps(const string &name,
Chris Masone889666b2011-07-03 12:58:50 -0700480 const StringmapsAccessor &acc) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800481 DCHECK(!Contains(name) || ContainsKey(stringmaps_properties_, name))
482 << "(Already registered " << name << ")";
Chris Masone889666b2011-07-03 12:58:50 -0700483 stringmaps_properties_[name] = acc;
484}
485
mukesh agrawal66b0aca2012-01-30 15:28:28 -0800486void PropertyStore::RegisterDerivedUint16(const string &name,
Paul Stewartbe5f5b32011-12-07 17:11:11 -0800487 const Uint16Accessor &acc) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800488 DCHECK(!Contains(name) || ContainsKey(uint16_properties_, name))
489 << "(Already registered " << name << ")";
Paul Stewartbe5f5b32011-12-07 17:11:11 -0800490 uint16_properties_[name] = acc;
491}
492
Paul Stewarte18c33b2012-07-10 20:48:44 -0700493void PropertyStore::RegisterDerivedUint64(const string &name,
494 const Uint64Accessor &acc) {
495 DCHECK(!Contains(name) || ContainsKey(uint64_properties_, name))
496 << "(Already registered " << name << ")";
497 uint64_properties_[name] = acc;
498}
499
mukesh agrawal66b0aca2012-01-30 15:28:28 -0800500// private methods
501
mukesh agrawalffa3d042011-10-06 15:26:10 -0700502template <class V>
503bool PropertyStore::SetProperty(
504 const string &name,
505 const V &value,
506 Error *error,
507 map< string, std::tr1::shared_ptr< AccessorInterface<V> > >&collection,
508 const string &value_type_english) {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700509 SLOG(Property, 2) << "Setting " << name << " as " << value_type_english
510 << ".";
mukesh agrawalffa3d042011-10-06 15:26:10 -0700511 if (ContainsKey(collection, name)) {
512 collection[name]->Set(value, error);
513 } else {
514 if (Contains(name)) {
515 error->Populate(
516 Error::kInvalidArguments,
517 "Property " + name + " is not " + value_type_english + ".");
518 } else {
519 error->Populate(
520 Error::kInvalidProperty, "Property " + name + " does not exist.");
521 }
522 }
523 return error->IsSuccess();
524};
525
Chris Masoneb925cc82011-06-22 15:39:57 -0700526} // namespace shill