blob: 933be700b12d844ae347d865c9be1637de8d82bd [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>
12#include <base/logging.h>
Eric Shienbrood3e20a232012-02-16 11:35:56 -050013#include <base/stl_util.h>
Chris Masoneb925cc82011-06-22 15:39:57 -070014
15#include "shill/error.h"
16#include "shill/property_accessor.h"
Ben Chanfad4a0b2012-04-18 15:49:59 -070017#include "shill/scope_logger.h"
Chris Masoneb925cc82011-06-22 15:39:57 -070018
19using std::map;
20using std::string;
21using std::vector;
22
23namespace shill {
24
25PropertyStore::PropertyStore() {}
26
27PropertyStore::~PropertyStore() {}
28
mukesh agrawal66b0aca2012-01-30 15:28:28 -080029bool PropertyStore::Contains(const string &prop) const {
30 return (ContainsKey(bool_properties_, prop) ||
31 ContainsKey(int16_properties_, prop) ||
32 ContainsKey(int32_properties_, prop) ||
33 ContainsKey(key_value_store_properties_, prop) ||
34 ContainsKey(string_properties_, prop) ||
35 ContainsKey(stringmap_properties_, prop) ||
36 ContainsKey(stringmaps_properties_, prop) ||
37 ContainsKey(strings_properties_, prop) ||
38 ContainsKey(uint8_properties_, prop) ||
39 ContainsKey(uint16_properties_, prop) ||
Jason Glasgowacdc11f2012-03-30 14:12:22 -040040 ContainsKey(uint32_properties_, prop) ||
41 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
Jason Glasgowacdc11f2012-03-30 14:12:22 -0400100bool PropertyStore::SetRpcIdentifierProperty(const string &name,
101 const RpcIdentifier &value,
102 Error *error) {
103 return SetProperty(name, value, error, rpc_identifier_properties_,
104 "an rpc_identifier");
105}
106
mukesh agrawal4d260da2012-01-30 11:53:52 -0800107bool PropertyStore::ClearProperty(const string &name, Error *error) {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700108 SLOG(Property, 2) << "Clearing " << name << ".";
mukesh agrawal4d260da2012-01-30 11:53:52 -0800109
110 if (ContainsKey(bool_properties_, name)) {
111 bool_properties_[name]->Clear(error);
112 } else if (ContainsKey(int16_properties_, name)) {
113 int16_properties_[name]->Clear(error);
114 } else if (ContainsKey(int32_properties_, name)) {
115 int32_properties_[name]->Clear(error);
116 } else if (ContainsKey(key_value_store_properties_, name)) {
117 key_value_store_properties_[name]->Clear(error);
118 } else if (ContainsKey(string_properties_, name)) {
119 string_properties_[name]->Clear(error);
120 } else if (ContainsKey(stringmap_properties_, name)) {
121 stringmap_properties_[name]->Clear(error);
122 } else if (ContainsKey(stringmaps_properties_, name)) {
123 stringmaps_properties_[name]->Clear(error);
124 } else if (ContainsKey(strings_properties_, name)) {
125 strings_properties_[name]->Clear(error);
126 } else if (ContainsKey(uint8_properties_, name)) {
127 uint8_properties_[name]->Clear(error);
128 } else if (ContainsKey(uint16_properties_, name)) {
129 uint16_properties_[name]->Clear(error);
130 } else if (ContainsKey(uint32_properties_, name)) {
131 uint32_properties_[name]->Clear(error);
Jason Glasgowacdc11f2012-03-30 14:12:22 -0400132 } else if (ContainsKey(rpc_identifier_properties_, name)) {
133 rpc_identifier_properties_[name]->Clear(error);
134 } else if (ContainsKey(rpc_identifiers_properties_, name)) {
135 rpc_identifiers_properties_[name]->Clear(error);
mukesh agrawal4d260da2012-01-30 11:53:52 -0800136 } else {
137 error->Populate(
138 Error::kInvalidProperty, "Property " + name + " does not exist.");
139 }
140 return error->IsSuccess();
141}
142
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800143ReadablePropertyConstIterator<bool> PropertyStore::GetBoolPropertiesIter()
mukesh agrawalde29fa82011-09-16 16:16:36 -0700144 const {
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800145 return ReadablePropertyConstIterator<bool>(bool_properties_);
Chris Masonea8a2c252011-06-27 22:16:30 -0700146}
147
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800148ReadablePropertyConstIterator<int16> PropertyStore::GetInt16PropertiesIter()
mukesh agrawalde29fa82011-09-16 16:16:36 -0700149 const {
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800150 return ReadablePropertyConstIterator<int16>(int16_properties_);
Chris Masonea8a2c252011-06-27 22:16:30 -0700151}
152
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800153ReadablePropertyConstIterator<int32> PropertyStore::GetInt32PropertiesIter()
mukesh agrawalde29fa82011-09-16 16:16:36 -0700154 const {
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800155 return ReadablePropertyConstIterator<int32>(int32_properties_);
Chris Masone889666b2011-07-03 12:58:50 -0700156}
157
Darin Petkov63138a92012-02-06 14:09:15 +0100158ReadablePropertyConstIterator<KeyValueStore>
159PropertyStore::GetKeyValueStorePropertiesIter() const {
160 return
161 ReadablePropertyConstIterator<KeyValueStore>(key_value_store_properties_);
162}
163
Jason Glasgowacdc11f2012-03-30 14:12:22 -0400164ReadablePropertyConstIterator<RpcIdentifier>
165PropertyStore::GetRpcIdentifierPropertiesIter() const {
166 return ReadablePropertyConstIterator<RpcIdentifier>(
167 rpc_identifier_properties_);
168}
169
mukesh agrawal2366eed2012-03-20 18:21:50 -0700170ReadablePropertyConstIterator<RpcIdentifiers>
171PropertyStore::GetRpcIdentifiersPropertiesIter() const {
172 return ReadablePropertyConstIterator<RpcIdentifiers>(
173 rpc_identifiers_properties_);
174}
175
mukesh agrawal66b0aca2012-01-30 15:28:28 -0800176ReadablePropertyConstIterator<string>
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800177PropertyStore::GetStringPropertiesIter() const {
mukesh agrawal66b0aca2012-01-30 15:28:28 -0800178 return ReadablePropertyConstIterator<string>(string_properties_);
Chris Masonea8a2c252011-06-27 22:16:30 -0700179}
180
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800181ReadablePropertyConstIterator<Stringmap>
182PropertyStore::GetStringmapPropertiesIter() const {
183 return ReadablePropertyConstIterator<Stringmap>(stringmap_properties_);
Chris Masonea8a2c252011-06-27 22:16:30 -0700184}
185
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800186ReadablePropertyConstIterator<Stringmaps>
187PropertyStore::GetStringmapsPropertiesIter()
188 const {
189 return ReadablePropertyConstIterator<Stringmaps>(stringmaps_properties_);
190}
191
192ReadablePropertyConstIterator<Strings> PropertyStore::GetStringsPropertiesIter()
193 const {
194 return ReadablePropertyConstIterator<Strings>(strings_properties_);
195}
196
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800197ReadablePropertyConstIterator<uint8> PropertyStore::GetUint8PropertiesIter()
198 const {
199 return ReadablePropertyConstIterator<uint8>(uint8_properties_);
200}
201
202ReadablePropertyConstIterator<uint16> PropertyStore::GetUint16PropertiesIter()
203 const {
204 return ReadablePropertyConstIterator<uint16>(uint16_properties_);
205}
206
207ReadablePropertyConstIterator<uint32> PropertyStore::GetUint32PropertiesIter()
208 const {
209 return ReadablePropertyConstIterator<uint32>(uint32_properties_);
Chris Masonea8a2c252011-06-27 22:16:30 -0700210}
211
Chris Masoneb925cc82011-06-22 15:39:57 -0700212void PropertyStore::RegisterBool(const string &name, bool *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800213 DCHECK(!Contains(name) || ContainsKey(bool_properties_, name))
214 << "(Already registered " << name << ")";
Chris Masoneb925cc82011-06-22 15:39:57 -0700215 bool_properties_[name] = BoolAccessor(new PropertyAccessor<bool>(prop));
216}
217
218void PropertyStore::RegisterConstBool(const string &name, const bool *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800219 DCHECK(!Contains(name) || ContainsKey(bool_properties_, name))
220 << "(Already registered " << name << ")";
Chris Masoneb925cc82011-06-22 15:39:57 -0700221 bool_properties_[name] = BoolAccessor(new ConstPropertyAccessor<bool>(prop));
222}
223
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800224void PropertyStore::RegisterWriteOnlyBool(const string &name, bool *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800225 DCHECK(!Contains(name) || ContainsKey(bool_properties_, name))
226 << "(Already registered " << name << ")";
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800227 bool_properties_[name] = BoolAccessor(
228 new WriteOnlyPropertyAccessor<bool>(prop));
229}
230
Chris Masoneb925cc82011-06-22 15:39:57 -0700231void PropertyStore::RegisterInt16(const string &name, int16 *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800232 DCHECK(!Contains(name) || ContainsKey(int16_properties_, name))
233 << "(Already registered " << name << ")";
Chris Masoneb925cc82011-06-22 15:39:57 -0700234 int16_properties_[name] = Int16Accessor(new PropertyAccessor<int16>(prop));
235}
236
237void PropertyStore::RegisterConstInt16(const string &name, const int16 *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800238 DCHECK(!Contains(name) || ContainsKey(int16_properties_, name))
239 << "(Already registered " << name << ")";
Chris Masoneb925cc82011-06-22 15:39:57 -0700240 int16_properties_[name] =
241 Int16Accessor(new ConstPropertyAccessor<int16>(prop));
242}
243
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800244void PropertyStore::RegisterWriteOnlyInt16(const string &name, int16 *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800245 DCHECK(!Contains(name) || ContainsKey(int16_properties_, name))
246 << "(Already registered " << name << ")";
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800247 int16_properties_[name] =
248 Int16Accessor(new WriteOnlyPropertyAccessor<int16>(prop));
249}
Chris Masoneb925cc82011-06-22 15:39:57 -0700250void PropertyStore::RegisterInt32(const string &name, int32 *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800251 DCHECK(!Contains(name) || ContainsKey(int32_properties_, name))
252 << "(Already registered " << name << ")";
Chris Masoneb925cc82011-06-22 15:39:57 -0700253 int32_properties_[name] = Int32Accessor(new PropertyAccessor<int32>(prop));
254}
255
256void PropertyStore::RegisterConstInt32(const string &name, const int32 *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800257 DCHECK(!Contains(name) || ContainsKey(int32_properties_, name))
258 << "(Already registered " << name << ")";
Chris Masoneb925cc82011-06-22 15:39:57 -0700259 int32_properties_[name] =
260 Int32Accessor(new ConstPropertyAccessor<int32>(prop));
261}
262
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800263void PropertyStore::RegisterWriteOnlyInt32(const string &name, int32 *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800264 DCHECK(!Contains(name) || ContainsKey(int32_properties_, name))
265 << "(Already registered " << name << ")";
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800266 int32_properties_[name] =
267 Int32Accessor(new WriteOnlyPropertyAccessor<int32>(prop));
268}
269
Chris Masoneb925cc82011-06-22 15:39:57 -0700270void PropertyStore::RegisterString(const string &name, string *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800271 DCHECK(!Contains(name) || ContainsKey(string_properties_, name))
272 << "(Already registered " << name << ")";
Chris Masoneb925cc82011-06-22 15:39:57 -0700273 string_properties_[name] = StringAccessor(new PropertyAccessor<string>(prop));
274}
275
276void PropertyStore::RegisterConstString(const string &name,
277 const string *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800278 DCHECK(!Contains(name) || ContainsKey(string_properties_, name))
279 << "(Already registered " << name << ")";
Chris Masoneb925cc82011-06-22 15:39:57 -0700280 string_properties_[name] =
281 StringAccessor(new ConstPropertyAccessor<string>(prop));
282}
283
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800284void PropertyStore::RegisterWriteOnlyString(const string &name, string *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800285 DCHECK(!Contains(name) || ContainsKey(string_properties_, name))
286 << "(Already registered " << name << ")";
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800287 string_properties_[name] =
288 StringAccessor(new WriteOnlyPropertyAccessor<string>(prop));
289}
290
Chris Masone43b48a12011-07-01 13:37:07 -0700291void PropertyStore::RegisterStringmap(const string &name, Stringmap *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800292 DCHECK(!Contains(name) || ContainsKey(stringmap_properties_, name))
293 << "(Already registered " << name << ")";
Chris Masoneb925cc82011-06-22 15:39:57 -0700294 stringmap_properties_[name] =
Chris Masone43b48a12011-07-01 13:37:07 -0700295 StringmapAccessor(new PropertyAccessor<Stringmap>(prop));
Chris Masoneb925cc82011-06-22 15:39:57 -0700296}
297
298void PropertyStore::RegisterConstStringmap(const string &name,
Chris Masone43b48a12011-07-01 13:37:07 -0700299 const Stringmap *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800300 DCHECK(!Contains(name) || ContainsKey(stringmap_properties_, name))
301 << "(Already registered " << name << ")";
Chris Masoneb925cc82011-06-22 15:39:57 -0700302 stringmap_properties_[name] =
Chris Masone43b48a12011-07-01 13:37:07 -0700303 StringmapAccessor(new ConstPropertyAccessor<Stringmap>(prop));
304}
305
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800306void PropertyStore::RegisterWriteOnlyStringmap(const string &name,
307 Stringmap *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800308 DCHECK(!Contains(name) || ContainsKey(stringmap_properties_, name))
309 << "(Already registered " << name << ")";
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800310 stringmap_properties_[name] =
311 StringmapAccessor(new WriteOnlyPropertyAccessor<Stringmap>(prop));
312}
313
Darin Petkovc0865312011-09-16 15:31:20 -0700314void PropertyStore::RegisterStringmaps(const string &name, Stringmaps *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800315 DCHECK(!Contains(name) || ContainsKey(stringmaps_properties_, name))
316 << "(Already registered " << name << ")";
Darin Petkovc0865312011-09-16 15:31:20 -0700317 stringmaps_properties_[name] =
318 StringmapsAccessor(new PropertyAccessor<Stringmaps>(prop));
319}
320
321void PropertyStore::RegisterConstStringmaps(const string &name,
322 const Stringmaps *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800323 DCHECK(!Contains(name) || ContainsKey(stringmaps_properties_, name))
324 << "(Already registered " << name << ")";
Darin Petkovc0865312011-09-16 15:31:20 -0700325 stringmaps_properties_[name] =
326 StringmapsAccessor(new ConstPropertyAccessor<Stringmaps>(prop));
327}
328
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800329void PropertyStore::RegisterWriteOnlyStringmaps(const string &name,
330 Stringmaps *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800331 DCHECK(!Contains(name) || ContainsKey(stringmaps_properties_, name))
332 << "(Already registered " << name << ")";
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800333 stringmaps_properties_[name] =
334 StringmapsAccessor(new WriteOnlyPropertyAccessor<Stringmaps>(prop));
335}
336
Chris Masone43b48a12011-07-01 13:37:07 -0700337void PropertyStore::RegisterStrings(const string &name, Strings *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800338 DCHECK(!Contains(name) || ContainsKey(strings_properties_, name))
339 << "(Already registered " << name << ")";
Chris Masone43b48a12011-07-01 13:37:07 -0700340 strings_properties_[name] =
341 StringsAccessor(new PropertyAccessor<Strings>(prop));
Chris Masoneb925cc82011-06-22 15:39:57 -0700342}
343
Chris Masone889666b2011-07-03 12:58:50 -0700344void PropertyStore::RegisterConstStrings(const string &name,
345 const Strings *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800346 DCHECK(!Contains(name) || ContainsKey(strings_properties_, name))
347 << "(Already registered " << name << ")";
Chris Masone889666b2011-07-03 12:58:50 -0700348 strings_properties_[name] =
349 StringsAccessor(new ConstPropertyAccessor<Strings>(prop));
350}
351
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800352void PropertyStore::RegisterWriteOnlyStrings(const string &name,
353 Strings *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800354 DCHECK(!Contains(name) || ContainsKey(strings_properties_, name))
355 << "(Already registered " << name << ")";
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800356 strings_properties_[name] =
357 StringsAccessor(new WriteOnlyPropertyAccessor<Strings>(prop));
358}
359
Chris Masone889666b2011-07-03 12:58:50 -0700360void PropertyStore::RegisterUint8(const string &name, uint8 *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800361 DCHECK(!Contains(name) || ContainsKey(uint8_properties_, name))
362 << "(Already registered " << name << ")";
Chris Masone889666b2011-07-03 12:58:50 -0700363 uint8_properties_[name] = Uint8Accessor(new PropertyAccessor<uint8>(prop));
364}
365
Chris Masoneb925cc82011-06-22 15:39:57 -0700366void PropertyStore::RegisterConstUint8(const string &name, const uint8 *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800367 DCHECK(!Contains(name) || ContainsKey(uint8_properties_, name))
368 << "(Already registered " << name << ")";
Chris Masoneb925cc82011-06-22 15:39:57 -0700369 uint8_properties_[name] =
370 Uint8Accessor(new ConstPropertyAccessor<uint8>(prop));
371}
372
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800373void PropertyStore::RegisterWriteOnlyUint8(const string &name, uint8 *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800374 DCHECK(!Contains(name) || ContainsKey(uint8_properties_, name))
375 << "(Already registered " << name << ")";
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800376 uint8_properties_[name] =
377 Uint8Accessor(new WriteOnlyPropertyAccessor<uint8>(prop));
378}
379
mukesh agrawal66b0aca2012-01-30 15:28:28 -0800380void PropertyStore::RegisterUint16(const string &name, uint16 *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800381 DCHECK(!Contains(name) || ContainsKey(uint16_properties_, name))
382 << "(Already registered " << name << ")";
Chris Masoneb925cc82011-06-22 15:39:57 -0700383 uint16_properties_[name] = Uint16Accessor(new PropertyAccessor<uint16>(prop));
384}
385
mukesh agrawal4d260da2012-01-30 11:53:52 -0800386void PropertyStore::RegisterUint32(const std::string &name, uint32 *prop) {
387 DCHECK(!Contains(name) || ContainsKey(uint32_properties_, name))
388 << "(Already registered " << name << ")";
389 uint32_properties_[name] = Uint32Accessor(new PropertyAccessor<uint32>(prop));
390}
391
Chris Masoneb925cc82011-06-22 15:39:57 -0700392void PropertyStore::RegisterConstUint16(const string &name,
393 const 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] =
397 Uint16Accessor(new ConstPropertyAccessor<uint16>(prop));
398}
399
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800400void PropertyStore::RegisterWriteOnlyUint16(const string &name, uint16 *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800401 DCHECK(!Contains(name) || ContainsKey(uint16_properties_, name))
402 << "(Already registered " << name << ")";
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800403 uint16_properties_[name] =
404 Uint16Accessor(new WriteOnlyPropertyAccessor<uint16>(prop));
405}
406
mukesh agrawal66b0aca2012-01-30 15:28:28 -0800407void PropertyStore::RegisterDerivedBool(const string &name,
Chris Masone27c4aa52011-07-02 13:10:14 -0700408 const BoolAccessor &accessor) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800409 DCHECK(!Contains(name) || ContainsKey(bool_properties_, name))
410 << "(Already registered " << name << ")";
Chris Masone27c4aa52011-07-02 13:10:14 -0700411 bool_properties_[name] = accessor;
412}
413
mukesh agrawal66b0aca2012-01-30 15:28:28 -0800414void PropertyStore::RegisterDerivedInt32(const string &name,
mukesh agrawal4d0401c2012-01-06 16:05:31 -0800415 const Int32Accessor &accessor) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800416 DCHECK(!Contains(name) || ContainsKey(int32_properties_, name))
417 << "(Already registered " << name << ")";
mukesh agrawal4d0401c2012-01-06 16:05:31 -0800418 int32_properties_[name] = accessor;
419}
420
Darin Petkov63138a92012-02-06 14:09:15 +0100421void PropertyStore::RegisterDerivedKeyValueStore(
mukesh agrawal66b0aca2012-01-30 15:28:28 -0800422 const string &name,
Darin Petkov63138a92012-02-06 14:09:15 +0100423 const KeyValueStoreAccessor &acc) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800424 DCHECK(!Contains(name) || ContainsKey(key_value_store_properties_, name))
425 << "(Already registered " << name << ")";
Darin Petkov63138a92012-02-06 14:09:15 +0100426 key_value_store_properties_[name] = acc;
427}
428
Jason Glasgowacdc11f2012-03-30 14:12:22 -0400429void PropertyStore::RegisterDerivedRpcIdentifier(
430 const string &name,
431 const RpcIdentifierAccessor &acc) {
432 DCHECK(!Contains(name) || ContainsKey(rpc_identifier_properties_, name))
433 << "(Already registered " << name << ")";
434 rpc_identifier_properties_[name] = acc;
435}
436
mukesh agrawal2366eed2012-03-20 18:21:50 -0700437void PropertyStore::RegisterDerivedRpcIdentifiers(
438 const string &name,
439 const RpcIdentifiersAccessor &accessor) {
440 DCHECK(!Contains(name) || ContainsKey(rpc_identifiers_properties_, name))
441 << "(Already registered " << name << ")";
442 rpc_identifiers_properties_[name] = accessor;
443}
444
mukesh agrawal66b0aca2012-01-30 15:28:28 -0800445void PropertyStore::RegisterDerivedString(const string &name,
Chris Masone27c4aa52011-07-02 13:10:14 -0700446 const StringAccessor &accessor) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800447 DCHECK(!Contains(name) || ContainsKey(string_properties_, name))
448 << "(Already registered " << name << ")";
Chris Masone27c4aa52011-07-02 13:10:14 -0700449 string_properties_[name] = accessor;
450}
451
mukesh agrawal66b0aca2012-01-30 15:28:28 -0800452void PropertyStore::RegisterDerivedStrings(const string &name,
Chris Masone27c4aa52011-07-02 13:10:14 -0700453 const StringsAccessor &accessor) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800454 DCHECK(!Contains(name) || ContainsKey(strings_properties_, name))
455 << "(Already registered " << name << ")";
Chris Masone27c4aa52011-07-02 13:10:14 -0700456 strings_properties_[name] = accessor;
Chris Masoneb925cc82011-06-22 15:39:57 -0700457}
458
Eric Shienbrood30bc0ec2012-03-21 18:19:46 -0400459void PropertyStore::RegisterDerivedStringmap(const string &name,
460 const StringmapAccessor &acc) {
461 DCHECK(!Contains(name) || ContainsKey(stringmap_properties_, name))
462 << "(Already registered " << name << ")";
463 stringmap_properties_[name] = acc;
464}
465
mukesh agrawal66b0aca2012-01-30 15:28:28 -0800466void PropertyStore::RegisterDerivedStringmaps(const string &name,
Chris Masone889666b2011-07-03 12:58:50 -0700467 const StringmapsAccessor &acc) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800468 DCHECK(!Contains(name) || ContainsKey(stringmaps_properties_, name))
469 << "(Already registered " << name << ")";
Chris Masone889666b2011-07-03 12:58:50 -0700470 stringmaps_properties_[name] = acc;
471}
472
mukesh agrawal66b0aca2012-01-30 15:28:28 -0800473void PropertyStore::RegisterDerivedUint16(const string &name,
Paul Stewartbe5f5b32011-12-07 17:11:11 -0800474 const Uint16Accessor &acc) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800475 DCHECK(!Contains(name) || ContainsKey(uint16_properties_, name))
476 << "(Already registered " << name << ")";
Paul Stewartbe5f5b32011-12-07 17:11:11 -0800477 uint16_properties_[name] = acc;
478}
479
mukesh agrawal66b0aca2012-01-30 15:28:28 -0800480// private methods
481
mukesh agrawalffa3d042011-10-06 15:26:10 -0700482template <class V>
483bool PropertyStore::SetProperty(
484 const string &name,
485 const V &value,
486 Error *error,
487 map< string, std::tr1::shared_ptr< AccessorInterface<V> > >&collection,
488 const string &value_type_english) {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700489 SLOG(Property, 2) << "Setting " << name << " as " << value_type_english
490 << ".";
mukesh agrawalffa3d042011-10-06 15:26:10 -0700491 if (ContainsKey(collection, name)) {
492 collection[name]->Set(value, error);
493 } else {
494 if (Contains(name)) {
495 error->Populate(
496 Error::kInvalidArguments,
497 "Property " + name + " is not " + value_type_english + ".");
498 } else {
499 error->Populate(
500 Error::kInvalidProperty, "Property " + name + " does not exist.");
501 }
502 }
503 return error->IsSuccess();
504};
505
Chris Masoneb925cc82011-06-22 15:39:57 -0700506} // namespace shill