blob: a88836d98376995d023d2ab527a2d809614557de [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"
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) ||
40 ContainsKey(rpc_identifier_properties_, prop) ||
41 ContainsKey(rpc_identifiers_properties_, prop));
Chris Masoneb925cc82011-06-22 15:39:57 -070042}
43
mukesh agrawal66b0aca2012-01-30 15:28:28 -080044bool PropertyStore::SetBoolProperty(const string &name,
Chris Masoneb925cc82011-06-22 15:39:57 -070045 bool value,
46 Error *error) {
mukesh agrawalffa3d042011-10-06 15:26:10 -070047 return SetProperty(name, value, error, bool_properties_, "a bool");
Chris Masoneb925cc82011-06-22 15:39:57 -070048}
49
mukesh agrawal66b0aca2012-01-30 15:28:28 -080050bool PropertyStore::SetInt16Property(const string &name,
Chris Masoneb925cc82011-06-22 15:39:57 -070051 int16 value,
52 Error *error) {
mukesh agrawalffa3d042011-10-06 15:26:10 -070053 return SetProperty(name, value, error, int16_properties_, "an int16");
Chris Masoneb925cc82011-06-22 15:39:57 -070054}
55
mukesh agrawal66b0aca2012-01-30 15:28:28 -080056bool PropertyStore::SetInt32Property(const string &name,
Chris Masoneb925cc82011-06-22 15:39:57 -070057 int32 value,
58 Error *error) {
mukesh agrawalffa3d042011-10-06 15:26:10 -070059 return SetProperty(name, value, error, int32_properties_, "an int32.");
Chris Masoneb925cc82011-06-22 15:39:57 -070060}
61
mukesh agrawal66b0aca2012-01-30 15:28:28 -080062bool PropertyStore::SetStringProperty(const string &name,
63 const string &value,
Chris Masoneb925cc82011-06-22 15:39:57 -070064 Error *error) {
mukesh agrawalffa3d042011-10-06 15:26:10 -070065 return SetProperty(name, value, error, string_properties_, "a string");
Chris Masoneb925cc82011-06-22 15:39:57 -070066}
67
mukesh agrawal66b0aca2012-01-30 15:28:28 -080068bool PropertyStore::SetStringmapProperty(const string &name,
69 const map<string, string> &values,
70 Error *error) {
mukesh agrawalffa3d042011-10-06 15:26:10 -070071 return SetProperty(name, values, error, stringmap_properties_,
72 "a string map");
Chris Masoneb925cc82011-06-22 15:39:57 -070073}
74
mukesh agrawal66b0aca2012-01-30 15:28:28 -080075bool PropertyStore::SetStringsProperty(const string &name,
76 const vector<string> &values,
Chris Masoneb925cc82011-06-22 15:39:57 -070077 Error *error) {
mukesh agrawalffa3d042011-10-06 15:26:10 -070078 return SetProperty(name, values, error, strings_properties_, "a string list");
Chris Masoneb925cc82011-06-22 15:39:57 -070079}
80
mukesh agrawal66b0aca2012-01-30 15:28:28 -080081bool PropertyStore::SetUint8Property(const string &name,
Chris Masoneb925cc82011-06-22 15:39:57 -070082 uint8 value,
83 Error *error) {
mukesh agrawalffa3d042011-10-06 15:26:10 -070084 return SetProperty(name, value, error, uint8_properties_, "a uint8");
Chris Masoneb925cc82011-06-22 15:39:57 -070085}
86
mukesh agrawal66b0aca2012-01-30 15:28:28 -080087bool PropertyStore::SetUint16Property(const string &name,
Chris Masoneb925cc82011-06-22 15:39:57 -070088 uint16 value,
89 Error *error) {
mukesh agrawalffa3d042011-10-06 15:26:10 -070090 return SetProperty(name, value, error, uint16_properties_, "a uint16");
Chris Masoneb925cc82011-06-22 15:39:57 -070091}
92
mukesh agrawal66b0aca2012-01-30 15:28:28 -080093bool PropertyStore::SetUint32Property(const string &name,
Chris Masoneb925cc82011-06-22 15:39:57 -070094 uint32 value,
95 Error *error) {
mukesh agrawalffa3d042011-10-06 15:26:10 -070096 return SetProperty(name, value, error, uint32_properties_, "a uint32");
Chris Masoneb925cc82011-06-22 15:39:57 -070097}
98
Jason Glasgowacdc11f2012-03-30 14:12:22 -040099bool PropertyStore::SetRpcIdentifierProperty(const string &name,
100 const RpcIdentifier &value,
101 Error *error) {
102 return SetProperty(name, value, error, rpc_identifier_properties_,
103 "an rpc_identifier");
104}
105
mukesh agrawal4d260da2012-01-30 11:53:52 -0800106bool PropertyStore::ClearProperty(const string &name, Error *error) {
107 VLOG(2) << "Clearing " << name << ".";
108
109 if (ContainsKey(bool_properties_, name)) {
110 bool_properties_[name]->Clear(error);
111 } else if (ContainsKey(int16_properties_, name)) {
112 int16_properties_[name]->Clear(error);
113 } else if (ContainsKey(int32_properties_, name)) {
114 int32_properties_[name]->Clear(error);
115 } else if (ContainsKey(key_value_store_properties_, name)) {
116 key_value_store_properties_[name]->Clear(error);
117 } else if (ContainsKey(string_properties_, name)) {
118 string_properties_[name]->Clear(error);
119 } else if (ContainsKey(stringmap_properties_, name)) {
120 stringmap_properties_[name]->Clear(error);
121 } else if (ContainsKey(stringmaps_properties_, name)) {
122 stringmaps_properties_[name]->Clear(error);
123 } else if (ContainsKey(strings_properties_, name)) {
124 strings_properties_[name]->Clear(error);
125 } else if (ContainsKey(uint8_properties_, name)) {
126 uint8_properties_[name]->Clear(error);
127 } else if (ContainsKey(uint16_properties_, name)) {
128 uint16_properties_[name]->Clear(error);
129 } else if (ContainsKey(uint32_properties_, name)) {
130 uint32_properties_[name]->Clear(error);
Jason Glasgowacdc11f2012-03-30 14:12:22 -0400131 } else if (ContainsKey(rpc_identifier_properties_, name)) {
132 rpc_identifier_properties_[name]->Clear(error);
133 } else if (ContainsKey(rpc_identifiers_properties_, name)) {
134 rpc_identifiers_properties_[name]->Clear(error);
mukesh agrawal4d260da2012-01-30 11:53:52 -0800135 } else {
136 error->Populate(
137 Error::kInvalidProperty, "Property " + name + " does not exist.");
138 }
139 return error->IsSuccess();
140}
141
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800142ReadablePropertyConstIterator<bool> PropertyStore::GetBoolPropertiesIter()
mukesh agrawalde29fa82011-09-16 16:16:36 -0700143 const {
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800144 return ReadablePropertyConstIterator<bool>(bool_properties_);
Chris Masonea8a2c252011-06-27 22:16:30 -0700145}
146
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800147ReadablePropertyConstIterator<int16> PropertyStore::GetInt16PropertiesIter()
mukesh agrawalde29fa82011-09-16 16:16:36 -0700148 const {
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800149 return ReadablePropertyConstIterator<int16>(int16_properties_);
Chris Masonea8a2c252011-06-27 22:16:30 -0700150}
151
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800152ReadablePropertyConstIterator<int32> PropertyStore::GetInt32PropertiesIter()
mukesh agrawalde29fa82011-09-16 16:16:36 -0700153 const {
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800154 return ReadablePropertyConstIterator<int32>(int32_properties_);
Chris Masone889666b2011-07-03 12:58:50 -0700155}
156
Darin Petkov63138a92012-02-06 14:09:15 +0100157ReadablePropertyConstIterator<KeyValueStore>
158PropertyStore::GetKeyValueStorePropertiesIter() const {
159 return
160 ReadablePropertyConstIterator<KeyValueStore>(key_value_store_properties_);
161}
162
Jason Glasgowacdc11f2012-03-30 14:12:22 -0400163ReadablePropertyConstIterator<RpcIdentifier>
164PropertyStore::GetRpcIdentifierPropertiesIter() const {
165 return ReadablePropertyConstIterator<RpcIdentifier>(
166 rpc_identifier_properties_);
167}
168
mukesh agrawal2366eed2012-03-20 18:21:50 -0700169ReadablePropertyConstIterator<RpcIdentifiers>
170PropertyStore::GetRpcIdentifiersPropertiesIter() const {
171 return ReadablePropertyConstIterator<RpcIdentifiers>(
172 rpc_identifiers_properties_);
173}
174
mukesh agrawal66b0aca2012-01-30 15:28:28 -0800175ReadablePropertyConstIterator<string>
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800176PropertyStore::GetStringPropertiesIter() const {
mukesh agrawal66b0aca2012-01-30 15:28:28 -0800177 return ReadablePropertyConstIterator<string>(string_properties_);
Chris Masonea8a2c252011-06-27 22:16:30 -0700178}
179
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800180ReadablePropertyConstIterator<Stringmap>
181PropertyStore::GetStringmapPropertiesIter() const {
182 return ReadablePropertyConstIterator<Stringmap>(stringmap_properties_);
Chris Masonea8a2c252011-06-27 22:16:30 -0700183}
184
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800185ReadablePropertyConstIterator<Stringmaps>
186PropertyStore::GetStringmapsPropertiesIter()
187 const {
188 return ReadablePropertyConstIterator<Stringmaps>(stringmaps_properties_);
189}
190
191ReadablePropertyConstIterator<Strings> PropertyStore::GetStringsPropertiesIter()
192 const {
193 return ReadablePropertyConstIterator<Strings>(strings_properties_);
194}
195
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800196ReadablePropertyConstIterator<uint8> PropertyStore::GetUint8PropertiesIter()
197 const {
198 return ReadablePropertyConstIterator<uint8>(uint8_properties_);
199}
200
201ReadablePropertyConstIterator<uint16> PropertyStore::GetUint16PropertiesIter()
202 const {
203 return ReadablePropertyConstIterator<uint16>(uint16_properties_);
204}
205
206ReadablePropertyConstIterator<uint32> PropertyStore::GetUint32PropertiesIter()
207 const {
208 return ReadablePropertyConstIterator<uint32>(uint32_properties_);
Chris Masonea8a2c252011-06-27 22:16:30 -0700209}
210
Chris Masoneb925cc82011-06-22 15:39:57 -0700211void PropertyStore::RegisterBool(const string &name, bool *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800212 DCHECK(!Contains(name) || ContainsKey(bool_properties_, name))
213 << "(Already registered " << name << ")";
Chris Masoneb925cc82011-06-22 15:39:57 -0700214 bool_properties_[name] = BoolAccessor(new PropertyAccessor<bool>(prop));
215}
216
217void PropertyStore::RegisterConstBool(const string &name, const bool *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800218 DCHECK(!Contains(name) || ContainsKey(bool_properties_, name))
219 << "(Already registered " << name << ")";
Chris Masoneb925cc82011-06-22 15:39:57 -0700220 bool_properties_[name] = BoolAccessor(new ConstPropertyAccessor<bool>(prop));
221}
222
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800223void PropertyStore::RegisterWriteOnlyBool(const string &name, bool *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800224 DCHECK(!Contains(name) || ContainsKey(bool_properties_, name))
225 << "(Already registered " << name << ")";
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800226 bool_properties_[name] = BoolAccessor(
227 new WriteOnlyPropertyAccessor<bool>(prop));
228}
229
Chris Masoneb925cc82011-06-22 15:39:57 -0700230void PropertyStore::RegisterInt16(const string &name, int16 *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800231 DCHECK(!Contains(name) || ContainsKey(int16_properties_, name))
232 << "(Already registered " << name << ")";
Chris Masoneb925cc82011-06-22 15:39:57 -0700233 int16_properties_[name] = Int16Accessor(new PropertyAccessor<int16>(prop));
234}
235
236void PropertyStore::RegisterConstInt16(const string &name, const int16 *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800237 DCHECK(!Contains(name) || ContainsKey(int16_properties_, name))
238 << "(Already registered " << name << ")";
Chris Masoneb925cc82011-06-22 15:39:57 -0700239 int16_properties_[name] =
240 Int16Accessor(new ConstPropertyAccessor<int16>(prop));
241}
242
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800243void PropertyStore::RegisterWriteOnlyInt16(const string &name, int16 *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800244 DCHECK(!Contains(name) || ContainsKey(int16_properties_, name))
245 << "(Already registered " << name << ")";
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800246 int16_properties_[name] =
247 Int16Accessor(new WriteOnlyPropertyAccessor<int16>(prop));
248}
Chris Masoneb925cc82011-06-22 15:39:57 -0700249void PropertyStore::RegisterInt32(const string &name, int32 *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800250 DCHECK(!Contains(name) || ContainsKey(int32_properties_, name))
251 << "(Already registered " << name << ")";
Chris Masoneb925cc82011-06-22 15:39:57 -0700252 int32_properties_[name] = Int32Accessor(new PropertyAccessor<int32>(prop));
253}
254
255void PropertyStore::RegisterConstInt32(const string &name, const int32 *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800256 DCHECK(!Contains(name) || ContainsKey(int32_properties_, name))
257 << "(Already registered " << name << ")";
Chris Masoneb925cc82011-06-22 15:39:57 -0700258 int32_properties_[name] =
259 Int32Accessor(new ConstPropertyAccessor<int32>(prop));
260}
261
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800262void PropertyStore::RegisterWriteOnlyInt32(const string &name, int32 *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800263 DCHECK(!Contains(name) || ContainsKey(int32_properties_, name))
264 << "(Already registered " << name << ")";
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800265 int32_properties_[name] =
266 Int32Accessor(new WriteOnlyPropertyAccessor<int32>(prop));
267}
268
Chris Masoneb925cc82011-06-22 15:39:57 -0700269void PropertyStore::RegisterString(const string &name, string *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800270 DCHECK(!Contains(name) || ContainsKey(string_properties_, name))
271 << "(Already registered " << name << ")";
Chris Masoneb925cc82011-06-22 15:39:57 -0700272 string_properties_[name] = StringAccessor(new PropertyAccessor<string>(prop));
273}
274
275void PropertyStore::RegisterConstString(const string &name,
276 const string *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800277 DCHECK(!Contains(name) || ContainsKey(string_properties_, name))
278 << "(Already registered " << name << ")";
Chris Masoneb925cc82011-06-22 15:39:57 -0700279 string_properties_[name] =
280 StringAccessor(new ConstPropertyAccessor<string>(prop));
281}
282
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800283void PropertyStore::RegisterWriteOnlyString(const string &name, string *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800284 DCHECK(!Contains(name) || ContainsKey(string_properties_, name))
285 << "(Already registered " << name << ")";
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800286 string_properties_[name] =
287 StringAccessor(new WriteOnlyPropertyAccessor<string>(prop));
288}
289
Chris Masone43b48a12011-07-01 13:37:07 -0700290void PropertyStore::RegisterStringmap(const string &name, Stringmap *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800291 DCHECK(!Contains(name) || ContainsKey(stringmap_properties_, name))
292 << "(Already registered " << name << ")";
Chris Masoneb925cc82011-06-22 15:39:57 -0700293 stringmap_properties_[name] =
Chris Masone43b48a12011-07-01 13:37:07 -0700294 StringmapAccessor(new PropertyAccessor<Stringmap>(prop));
Chris Masoneb925cc82011-06-22 15:39:57 -0700295}
296
297void PropertyStore::RegisterConstStringmap(const string &name,
Chris Masone43b48a12011-07-01 13:37:07 -0700298 const Stringmap *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800299 DCHECK(!Contains(name) || ContainsKey(stringmap_properties_, name))
300 << "(Already registered " << name << ")";
Chris Masoneb925cc82011-06-22 15:39:57 -0700301 stringmap_properties_[name] =
Chris Masone43b48a12011-07-01 13:37:07 -0700302 StringmapAccessor(new ConstPropertyAccessor<Stringmap>(prop));
303}
304
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800305void PropertyStore::RegisterWriteOnlyStringmap(const string &name,
306 Stringmap *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800307 DCHECK(!Contains(name) || ContainsKey(stringmap_properties_, name))
308 << "(Already registered " << name << ")";
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800309 stringmap_properties_[name] =
310 StringmapAccessor(new WriteOnlyPropertyAccessor<Stringmap>(prop));
311}
312
Darin Petkovc0865312011-09-16 15:31:20 -0700313void PropertyStore::RegisterStringmaps(const string &name, Stringmaps *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800314 DCHECK(!Contains(name) || ContainsKey(stringmaps_properties_, name))
315 << "(Already registered " << name << ")";
Darin Petkovc0865312011-09-16 15:31:20 -0700316 stringmaps_properties_[name] =
317 StringmapsAccessor(new PropertyAccessor<Stringmaps>(prop));
318}
319
320void PropertyStore::RegisterConstStringmaps(const string &name,
321 const Stringmaps *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800322 DCHECK(!Contains(name) || ContainsKey(stringmaps_properties_, name))
323 << "(Already registered " << name << ")";
Darin Petkovc0865312011-09-16 15:31:20 -0700324 stringmaps_properties_[name] =
325 StringmapsAccessor(new ConstPropertyAccessor<Stringmaps>(prop));
326}
327
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800328void PropertyStore::RegisterWriteOnlyStringmaps(const string &name,
329 Stringmaps *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800330 DCHECK(!Contains(name) || ContainsKey(stringmaps_properties_, name))
331 << "(Already registered " << name << ")";
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800332 stringmaps_properties_[name] =
333 StringmapsAccessor(new WriteOnlyPropertyAccessor<Stringmaps>(prop));
334}
335
Chris Masone43b48a12011-07-01 13:37:07 -0700336void PropertyStore::RegisterStrings(const string &name, Strings *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800337 DCHECK(!Contains(name) || ContainsKey(strings_properties_, name))
338 << "(Already registered " << name << ")";
Chris Masone43b48a12011-07-01 13:37:07 -0700339 strings_properties_[name] =
340 StringsAccessor(new PropertyAccessor<Strings>(prop));
Chris Masoneb925cc82011-06-22 15:39:57 -0700341}
342
Chris Masone889666b2011-07-03 12:58:50 -0700343void PropertyStore::RegisterConstStrings(const string &name,
344 const Strings *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800345 DCHECK(!Contains(name) || ContainsKey(strings_properties_, name))
346 << "(Already registered " << name << ")";
Chris Masone889666b2011-07-03 12:58:50 -0700347 strings_properties_[name] =
348 StringsAccessor(new ConstPropertyAccessor<Strings>(prop));
349}
350
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800351void PropertyStore::RegisterWriteOnlyStrings(const string &name,
352 Strings *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800353 DCHECK(!Contains(name) || ContainsKey(strings_properties_, name))
354 << "(Already registered " << name << ")";
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800355 strings_properties_[name] =
356 StringsAccessor(new WriteOnlyPropertyAccessor<Strings>(prop));
357}
358
Chris Masone889666b2011-07-03 12:58:50 -0700359void PropertyStore::RegisterUint8(const string &name, uint8 *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800360 DCHECK(!Contains(name) || ContainsKey(uint8_properties_, name))
361 << "(Already registered " << name << ")";
Chris Masone889666b2011-07-03 12:58:50 -0700362 uint8_properties_[name] = Uint8Accessor(new PropertyAccessor<uint8>(prop));
363}
364
Chris Masoneb925cc82011-06-22 15:39:57 -0700365void PropertyStore::RegisterConstUint8(const string &name, const uint8 *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800366 DCHECK(!Contains(name) || ContainsKey(uint8_properties_, name))
367 << "(Already registered " << name << ")";
Chris Masoneb925cc82011-06-22 15:39:57 -0700368 uint8_properties_[name] =
369 Uint8Accessor(new ConstPropertyAccessor<uint8>(prop));
370}
371
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800372void PropertyStore::RegisterWriteOnlyUint8(const string &name, uint8 *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800373 DCHECK(!Contains(name) || ContainsKey(uint8_properties_, name))
374 << "(Already registered " << name << ")";
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800375 uint8_properties_[name] =
376 Uint8Accessor(new WriteOnlyPropertyAccessor<uint8>(prop));
377}
378
mukesh agrawal66b0aca2012-01-30 15:28:28 -0800379void PropertyStore::RegisterUint16(const string &name, uint16 *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800380 DCHECK(!Contains(name) || ContainsKey(uint16_properties_, name))
381 << "(Already registered " << name << ")";
Chris Masoneb925cc82011-06-22 15:39:57 -0700382 uint16_properties_[name] = Uint16Accessor(new PropertyAccessor<uint16>(prop));
383}
384
mukesh agrawal4d260da2012-01-30 11:53:52 -0800385void PropertyStore::RegisterUint32(const std::string &name, uint32 *prop) {
386 DCHECK(!Contains(name) || ContainsKey(uint32_properties_, name))
387 << "(Already registered " << name << ")";
388 uint32_properties_[name] = Uint32Accessor(new PropertyAccessor<uint32>(prop));
389}
390
Chris Masoneb925cc82011-06-22 15:39:57 -0700391void PropertyStore::RegisterConstUint16(const string &name,
392 const uint16 *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800393 DCHECK(!Contains(name) || ContainsKey(uint16_properties_, name))
394 << "(Already registered " << name << ")";
Chris Masoneb925cc82011-06-22 15:39:57 -0700395 uint16_properties_[name] =
396 Uint16Accessor(new ConstPropertyAccessor<uint16>(prop));
397}
398
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800399void PropertyStore::RegisterWriteOnlyUint16(const string &name, uint16 *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800400 DCHECK(!Contains(name) || ContainsKey(uint16_properties_, name))
401 << "(Already registered " << name << ")";
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800402 uint16_properties_[name] =
403 Uint16Accessor(new WriteOnlyPropertyAccessor<uint16>(prop));
404}
405
mukesh agrawal66b0aca2012-01-30 15:28:28 -0800406void PropertyStore::RegisterDerivedBool(const string &name,
Chris Masone27c4aa52011-07-02 13:10:14 -0700407 const BoolAccessor &accessor) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800408 DCHECK(!Contains(name) || ContainsKey(bool_properties_, name))
409 << "(Already registered " << name << ")";
Chris Masone27c4aa52011-07-02 13:10:14 -0700410 bool_properties_[name] = accessor;
411}
412
mukesh agrawal66b0aca2012-01-30 15:28:28 -0800413void PropertyStore::RegisterDerivedInt32(const string &name,
mukesh agrawal4d0401c2012-01-06 16:05:31 -0800414 const Int32Accessor &accessor) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800415 DCHECK(!Contains(name) || ContainsKey(int32_properties_, name))
416 << "(Already registered " << name << ")";
mukesh agrawal4d0401c2012-01-06 16:05:31 -0800417 int32_properties_[name] = accessor;
418}
419
Darin Petkov63138a92012-02-06 14:09:15 +0100420void PropertyStore::RegisterDerivedKeyValueStore(
mukesh agrawal66b0aca2012-01-30 15:28:28 -0800421 const string &name,
Darin Petkov63138a92012-02-06 14:09:15 +0100422 const KeyValueStoreAccessor &acc) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800423 DCHECK(!Contains(name) || ContainsKey(key_value_store_properties_, name))
424 << "(Already registered " << name << ")";
Darin Petkov63138a92012-02-06 14:09:15 +0100425 key_value_store_properties_[name] = acc;
426}
427
Jason Glasgowacdc11f2012-03-30 14:12:22 -0400428void PropertyStore::RegisterDerivedRpcIdentifier(
429 const string &name,
430 const RpcIdentifierAccessor &acc) {
431 DCHECK(!Contains(name) || ContainsKey(rpc_identifier_properties_, name))
432 << "(Already registered " << name << ")";
433 rpc_identifier_properties_[name] = acc;
434}
435
mukesh agrawal2366eed2012-03-20 18:21:50 -0700436void PropertyStore::RegisterDerivedRpcIdentifiers(
437 const string &name,
438 const RpcIdentifiersAccessor &accessor) {
439 DCHECK(!Contains(name) || ContainsKey(rpc_identifiers_properties_, name))
440 << "(Already registered " << name << ")";
441 rpc_identifiers_properties_[name] = accessor;
442}
443
mukesh agrawal66b0aca2012-01-30 15:28:28 -0800444void PropertyStore::RegisterDerivedString(const string &name,
Chris Masone27c4aa52011-07-02 13:10:14 -0700445 const StringAccessor &accessor) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800446 DCHECK(!Contains(name) || ContainsKey(string_properties_, name))
447 << "(Already registered " << name << ")";
Chris Masone27c4aa52011-07-02 13:10:14 -0700448 string_properties_[name] = accessor;
449}
450
mukesh agrawal66b0aca2012-01-30 15:28:28 -0800451void PropertyStore::RegisterDerivedStrings(const string &name,
Chris Masone27c4aa52011-07-02 13:10:14 -0700452 const StringsAccessor &accessor) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800453 DCHECK(!Contains(name) || ContainsKey(strings_properties_, name))
454 << "(Already registered " << name << ")";
Chris Masone27c4aa52011-07-02 13:10:14 -0700455 strings_properties_[name] = accessor;
Chris Masoneb925cc82011-06-22 15:39:57 -0700456}
457
Eric Shienbrood30bc0ec2012-03-21 18:19:46 -0400458void PropertyStore::RegisterDerivedStringmap(const string &name,
459 const StringmapAccessor &acc) {
460 DCHECK(!Contains(name) || ContainsKey(stringmap_properties_, name))
461 << "(Already registered " << name << ")";
462 stringmap_properties_[name] = acc;
463}
464
mukesh agrawal66b0aca2012-01-30 15:28:28 -0800465void PropertyStore::RegisterDerivedStringmaps(const string &name,
Chris Masone889666b2011-07-03 12:58:50 -0700466 const StringmapsAccessor &acc) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800467 DCHECK(!Contains(name) || ContainsKey(stringmaps_properties_, name))
468 << "(Already registered " << name << ")";
Chris Masone889666b2011-07-03 12:58:50 -0700469 stringmaps_properties_[name] = acc;
470}
471
mukesh agrawal66b0aca2012-01-30 15:28:28 -0800472void PropertyStore::RegisterDerivedUint16(const string &name,
Paul Stewartbe5f5b32011-12-07 17:11:11 -0800473 const Uint16Accessor &acc) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800474 DCHECK(!Contains(name) || ContainsKey(uint16_properties_, name))
475 << "(Already registered " << name << ")";
Paul Stewartbe5f5b32011-12-07 17:11:11 -0800476 uint16_properties_[name] = acc;
477}
478
mukesh agrawal66b0aca2012-01-30 15:28:28 -0800479// private methods
480
mukesh agrawalffa3d042011-10-06 15:26:10 -0700481template <class V>
482bool PropertyStore::SetProperty(
483 const string &name,
484 const V &value,
485 Error *error,
486 map< string, std::tr1::shared_ptr< AccessorInterface<V> > >&collection,
487 const string &value_type_english) {
488 VLOG(2) << "Setting " << name << " as " << value_type_english << ".";
489 if (ContainsKey(collection, name)) {
490 collection[name]->Set(value, error);
491 } else {
492 if (Contains(name)) {
493 error->Populate(
494 Error::kInvalidArguments,
495 "Property " + name + " is not " + value_type_english + ".");
496 } else {
497 error->Populate(
498 Error::kInvalidProperty, "Property " + name + " does not exist.");
499 }
500 }
501 return error->IsSuccess();
502};
503
Chris Masoneb925cc82011-06-22 15:39:57 -0700504} // namespace shill