blob: c1365c3aec2e5bd33eb21cc4c9672488affbbe10 [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>
Chris Masone27c4aa52011-07-02 13:10:14 -070013#include <base/stl_util-inl.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) ||
39 ContainsKey(uint32_properties_, prop));
Chris Masoneb925cc82011-06-22 15:39:57 -070040}
41
mukesh agrawal66b0aca2012-01-30 15:28:28 -080042bool PropertyStore::SetBoolProperty(const string &name,
Chris Masoneb925cc82011-06-22 15:39:57 -070043 bool value,
44 Error *error) {
mukesh agrawalffa3d042011-10-06 15:26:10 -070045 return SetProperty(name, value, error, bool_properties_, "a bool");
Chris Masoneb925cc82011-06-22 15:39:57 -070046}
47
mukesh agrawal66b0aca2012-01-30 15:28:28 -080048bool PropertyStore::SetInt16Property(const string &name,
Chris Masoneb925cc82011-06-22 15:39:57 -070049 int16 value,
50 Error *error) {
mukesh agrawalffa3d042011-10-06 15:26:10 -070051 return SetProperty(name, value, error, int16_properties_, "an int16");
Chris Masoneb925cc82011-06-22 15:39:57 -070052}
53
mukesh agrawal66b0aca2012-01-30 15:28:28 -080054bool PropertyStore::SetInt32Property(const string &name,
Chris Masoneb925cc82011-06-22 15:39:57 -070055 int32 value,
56 Error *error) {
mukesh agrawalffa3d042011-10-06 15:26:10 -070057 return SetProperty(name, value, error, int32_properties_, "an int32.");
Chris Masoneb925cc82011-06-22 15:39:57 -070058}
59
mukesh agrawal66b0aca2012-01-30 15:28:28 -080060bool PropertyStore::SetStringProperty(const string &name,
61 const string &value,
Chris Masoneb925cc82011-06-22 15:39:57 -070062 Error *error) {
mukesh agrawalffa3d042011-10-06 15:26:10 -070063 return SetProperty(name, value, error, string_properties_, "a string");
Chris Masoneb925cc82011-06-22 15:39:57 -070064}
65
mukesh agrawal66b0aca2012-01-30 15:28:28 -080066bool PropertyStore::SetStringmapProperty(const string &name,
67 const map<string, string> &values,
68 Error *error) {
mukesh agrawalffa3d042011-10-06 15:26:10 -070069 return SetProperty(name, values, error, stringmap_properties_,
70 "a string map");
Chris Masoneb925cc82011-06-22 15:39:57 -070071}
72
mukesh agrawal66b0aca2012-01-30 15:28:28 -080073bool PropertyStore::SetStringsProperty(const string &name,
74 const vector<string> &values,
Chris Masoneb925cc82011-06-22 15:39:57 -070075 Error *error) {
mukesh agrawalffa3d042011-10-06 15:26:10 -070076 return SetProperty(name, values, error, strings_properties_, "a string list");
Chris Masoneb925cc82011-06-22 15:39:57 -070077}
78
mukesh agrawal66b0aca2012-01-30 15:28:28 -080079bool PropertyStore::SetUint8Property(const string &name,
Chris Masoneb925cc82011-06-22 15:39:57 -070080 uint8 value,
81 Error *error) {
mukesh agrawalffa3d042011-10-06 15:26:10 -070082 return SetProperty(name, value, error, uint8_properties_, "a uint8");
Chris Masoneb925cc82011-06-22 15:39:57 -070083}
84
mukesh agrawal66b0aca2012-01-30 15:28:28 -080085bool PropertyStore::SetUint16Property(const string &name,
Chris Masoneb925cc82011-06-22 15:39:57 -070086 uint16 value,
87 Error *error) {
mukesh agrawalffa3d042011-10-06 15:26:10 -070088 return SetProperty(name, value, error, uint16_properties_, "a uint16");
Chris Masoneb925cc82011-06-22 15:39:57 -070089}
90
mukesh agrawal66b0aca2012-01-30 15:28:28 -080091bool PropertyStore::SetUint32Property(const string &name,
Chris Masoneb925cc82011-06-22 15:39:57 -070092 uint32 value,
93 Error *error) {
mukesh agrawalffa3d042011-10-06 15:26:10 -070094 return SetProperty(name, value, error, uint32_properties_, "a uint32");
Chris Masoneb925cc82011-06-22 15:39:57 -070095}
96
mukesh agrawal4d260da2012-01-30 11:53:52 -080097bool PropertyStore::ClearProperty(const string &name, Error *error) {
98 VLOG(2) << "Clearing " << name << ".";
99
100 if (ContainsKey(bool_properties_, name)) {
101 bool_properties_[name]->Clear(error);
102 } else if (ContainsKey(int16_properties_, name)) {
103 int16_properties_[name]->Clear(error);
104 } else if (ContainsKey(int32_properties_, name)) {
105 int32_properties_[name]->Clear(error);
106 } else if (ContainsKey(key_value_store_properties_, name)) {
107 key_value_store_properties_[name]->Clear(error);
108 } else if (ContainsKey(string_properties_, name)) {
109 string_properties_[name]->Clear(error);
110 } else if (ContainsKey(stringmap_properties_, name)) {
111 stringmap_properties_[name]->Clear(error);
112 } else if (ContainsKey(stringmaps_properties_, name)) {
113 stringmaps_properties_[name]->Clear(error);
114 } else if (ContainsKey(strings_properties_, name)) {
115 strings_properties_[name]->Clear(error);
116 } else if (ContainsKey(uint8_properties_, name)) {
117 uint8_properties_[name]->Clear(error);
118 } else if (ContainsKey(uint16_properties_, name)) {
119 uint16_properties_[name]->Clear(error);
120 } else if (ContainsKey(uint32_properties_, name)) {
121 uint32_properties_[name]->Clear(error);
122 } else {
123 error->Populate(
124 Error::kInvalidProperty, "Property " + name + " does not exist.");
125 }
126 return error->IsSuccess();
127}
128
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800129ReadablePropertyConstIterator<bool> PropertyStore::GetBoolPropertiesIter()
mukesh agrawalde29fa82011-09-16 16:16:36 -0700130 const {
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800131 return ReadablePropertyConstIterator<bool>(bool_properties_);
Chris Masonea8a2c252011-06-27 22:16:30 -0700132}
133
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800134ReadablePropertyConstIterator<int16> PropertyStore::GetInt16PropertiesIter()
mukesh agrawalde29fa82011-09-16 16:16:36 -0700135 const {
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800136 return ReadablePropertyConstIterator<int16>(int16_properties_);
Chris Masonea8a2c252011-06-27 22:16:30 -0700137}
138
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800139ReadablePropertyConstIterator<int32> PropertyStore::GetInt32PropertiesIter()
mukesh agrawalde29fa82011-09-16 16:16:36 -0700140 const {
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800141 return ReadablePropertyConstIterator<int32>(int32_properties_);
Chris Masone889666b2011-07-03 12:58:50 -0700142}
143
Darin Petkov63138a92012-02-06 14:09:15 +0100144ReadablePropertyConstIterator<KeyValueStore>
145PropertyStore::GetKeyValueStorePropertiesIter() const {
146 return
147 ReadablePropertyConstIterator<KeyValueStore>(key_value_store_properties_);
148}
149
mukesh agrawal66b0aca2012-01-30 15:28:28 -0800150ReadablePropertyConstIterator<string>
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800151PropertyStore::GetStringPropertiesIter() const {
mukesh agrawal66b0aca2012-01-30 15:28:28 -0800152 return ReadablePropertyConstIterator<string>(string_properties_);
Chris Masonea8a2c252011-06-27 22:16:30 -0700153}
154
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800155ReadablePropertyConstIterator<Stringmap>
156PropertyStore::GetStringmapPropertiesIter() const {
157 return ReadablePropertyConstIterator<Stringmap>(stringmap_properties_);
Chris Masonea8a2c252011-06-27 22:16:30 -0700158}
159
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800160ReadablePropertyConstIterator<Stringmaps>
161PropertyStore::GetStringmapsPropertiesIter()
162 const {
163 return ReadablePropertyConstIterator<Stringmaps>(stringmaps_properties_);
164}
165
166ReadablePropertyConstIterator<Strings> PropertyStore::GetStringsPropertiesIter()
167 const {
168 return ReadablePropertyConstIterator<Strings>(strings_properties_);
169}
170
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800171ReadablePropertyConstIterator<uint8> PropertyStore::GetUint8PropertiesIter()
172 const {
173 return ReadablePropertyConstIterator<uint8>(uint8_properties_);
174}
175
176ReadablePropertyConstIterator<uint16> PropertyStore::GetUint16PropertiesIter()
177 const {
178 return ReadablePropertyConstIterator<uint16>(uint16_properties_);
179}
180
181ReadablePropertyConstIterator<uint32> PropertyStore::GetUint32PropertiesIter()
182 const {
183 return ReadablePropertyConstIterator<uint32>(uint32_properties_);
Chris Masonea8a2c252011-06-27 22:16:30 -0700184}
185
Chris Masoneb925cc82011-06-22 15:39:57 -0700186void PropertyStore::RegisterBool(const string &name, bool *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800187 DCHECK(!Contains(name) || ContainsKey(bool_properties_, name))
188 << "(Already registered " << name << ")";
Chris Masoneb925cc82011-06-22 15:39:57 -0700189 bool_properties_[name] = BoolAccessor(new PropertyAccessor<bool>(prop));
190}
191
192void PropertyStore::RegisterConstBool(const string &name, const bool *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800193 DCHECK(!Contains(name) || ContainsKey(bool_properties_, name))
194 << "(Already registered " << name << ")";
Chris Masoneb925cc82011-06-22 15:39:57 -0700195 bool_properties_[name] = BoolAccessor(new ConstPropertyAccessor<bool>(prop));
196}
197
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800198void PropertyStore::RegisterWriteOnlyBool(const string &name, bool *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800199 DCHECK(!Contains(name) || ContainsKey(bool_properties_, name))
200 << "(Already registered " << name << ")";
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800201 bool_properties_[name] = BoolAccessor(
202 new WriteOnlyPropertyAccessor<bool>(prop));
203}
204
Chris Masoneb925cc82011-06-22 15:39:57 -0700205void PropertyStore::RegisterInt16(const string &name, int16 *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800206 DCHECK(!Contains(name) || ContainsKey(int16_properties_, name))
207 << "(Already registered " << name << ")";
Chris Masoneb925cc82011-06-22 15:39:57 -0700208 int16_properties_[name] = Int16Accessor(new PropertyAccessor<int16>(prop));
209}
210
211void PropertyStore::RegisterConstInt16(const string &name, const int16 *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800212 DCHECK(!Contains(name) || ContainsKey(int16_properties_, name))
213 << "(Already registered " << name << ")";
Chris Masoneb925cc82011-06-22 15:39:57 -0700214 int16_properties_[name] =
215 Int16Accessor(new ConstPropertyAccessor<int16>(prop));
216}
217
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800218void PropertyStore::RegisterWriteOnlyInt16(const string &name, int16 *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800219 DCHECK(!Contains(name) || ContainsKey(int16_properties_, name))
220 << "(Already registered " << name << ")";
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800221 int16_properties_[name] =
222 Int16Accessor(new WriteOnlyPropertyAccessor<int16>(prop));
223}
Chris Masoneb925cc82011-06-22 15:39:57 -0700224void PropertyStore::RegisterInt32(const string &name, int32 *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800225 DCHECK(!Contains(name) || ContainsKey(int32_properties_, name))
226 << "(Already registered " << name << ")";
Chris Masoneb925cc82011-06-22 15:39:57 -0700227 int32_properties_[name] = Int32Accessor(new PropertyAccessor<int32>(prop));
228}
229
230void PropertyStore::RegisterConstInt32(const string &name, const int32 *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800231 DCHECK(!Contains(name) || ContainsKey(int32_properties_, name))
232 << "(Already registered " << name << ")";
Chris Masoneb925cc82011-06-22 15:39:57 -0700233 int32_properties_[name] =
234 Int32Accessor(new ConstPropertyAccessor<int32>(prop));
235}
236
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800237void PropertyStore::RegisterWriteOnlyInt32(const string &name, int32 *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800238 DCHECK(!Contains(name) || ContainsKey(int32_properties_, name))
239 << "(Already registered " << name << ")";
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800240 int32_properties_[name] =
241 Int32Accessor(new WriteOnlyPropertyAccessor<int32>(prop));
242}
243
Chris Masoneb925cc82011-06-22 15:39:57 -0700244void PropertyStore::RegisterString(const string &name, string *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800245 DCHECK(!Contains(name) || ContainsKey(string_properties_, name))
246 << "(Already registered " << name << ")";
Chris Masoneb925cc82011-06-22 15:39:57 -0700247 string_properties_[name] = StringAccessor(new PropertyAccessor<string>(prop));
248}
249
250void PropertyStore::RegisterConstString(const string &name,
251 const string *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800252 DCHECK(!Contains(name) || ContainsKey(string_properties_, name))
253 << "(Already registered " << name << ")";
Chris Masoneb925cc82011-06-22 15:39:57 -0700254 string_properties_[name] =
255 StringAccessor(new ConstPropertyAccessor<string>(prop));
256}
257
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800258void PropertyStore::RegisterWriteOnlyString(const string &name, string *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800259 DCHECK(!Contains(name) || ContainsKey(string_properties_, name))
260 << "(Already registered " << name << ")";
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800261 string_properties_[name] =
262 StringAccessor(new WriteOnlyPropertyAccessor<string>(prop));
263}
264
Chris Masone43b48a12011-07-01 13:37:07 -0700265void PropertyStore::RegisterStringmap(const string &name, Stringmap *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800266 DCHECK(!Contains(name) || ContainsKey(stringmap_properties_, name))
267 << "(Already registered " << name << ")";
Chris Masoneb925cc82011-06-22 15:39:57 -0700268 stringmap_properties_[name] =
Chris Masone43b48a12011-07-01 13:37:07 -0700269 StringmapAccessor(new PropertyAccessor<Stringmap>(prop));
Chris Masoneb925cc82011-06-22 15:39:57 -0700270}
271
272void PropertyStore::RegisterConstStringmap(const string &name,
Chris Masone43b48a12011-07-01 13:37:07 -0700273 const Stringmap *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800274 DCHECK(!Contains(name) || ContainsKey(stringmap_properties_, name))
275 << "(Already registered " << name << ")";
Chris Masoneb925cc82011-06-22 15:39:57 -0700276 stringmap_properties_[name] =
Chris Masone43b48a12011-07-01 13:37:07 -0700277 StringmapAccessor(new ConstPropertyAccessor<Stringmap>(prop));
278}
279
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800280void PropertyStore::RegisterWriteOnlyStringmap(const string &name,
281 Stringmap *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800282 DCHECK(!Contains(name) || ContainsKey(stringmap_properties_, name))
283 << "(Already registered " << name << ")";
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800284 stringmap_properties_[name] =
285 StringmapAccessor(new WriteOnlyPropertyAccessor<Stringmap>(prop));
286}
287
Darin Petkovc0865312011-09-16 15:31:20 -0700288void PropertyStore::RegisterStringmaps(const string &name, Stringmaps *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800289 DCHECK(!Contains(name) || ContainsKey(stringmaps_properties_, name))
290 << "(Already registered " << name << ")";
Darin Petkovc0865312011-09-16 15:31:20 -0700291 stringmaps_properties_[name] =
292 StringmapsAccessor(new PropertyAccessor<Stringmaps>(prop));
293}
294
295void PropertyStore::RegisterConstStringmaps(const string &name,
296 const Stringmaps *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800297 DCHECK(!Contains(name) || ContainsKey(stringmaps_properties_, name))
298 << "(Already registered " << name << ")";
Darin Petkovc0865312011-09-16 15:31:20 -0700299 stringmaps_properties_[name] =
300 StringmapsAccessor(new ConstPropertyAccessor<Stringmaps>(prop));
301}
302
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800303void PropertyStore::RegisterWriteOnlyStringmaps(const string &name,
304 Stringmaps *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800305 DCHECK(!Contains(name) || ContainsKey(stringmaps_properties_, name))
306 << "(Already registered " << name << ")";
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800307 stringmaps_properties_[name] =
308 StringmapsAccessor(new WriteOnlyPropertyAccessor<Stringmaps>(prop));
309}
310
Chris Masone43b48a12011-07-01 13:37:07 -0700311void PropertyStore::RegisterStrings(const string &name, Strings *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800312 DCHECK(!Contains(name) || ContainsKey(strings_properties_, name))
313 << "(Already registered " << name << ")";
Chris Masone43b48a12011-07-01 13:37:07 -0700314 strings_properties_[name] =
315 StringsAccessor(new PropertyAccessor<Strings>(prop));
Chris Masoneb925cc82011-06-22 15:39:57 -0700316}
317
Chris Masone889666b2011-07-03 12:58:50 -0700318void PropertyStore::RegisterConstStrings(const string &name,
319 const Strings *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800320 DCHECK(!Contains(name) || ContainsKey(strings_properties_, name))
321 << "(Already registered " << name << ")";
Chris Masone889666b2011-07-03 12:58:50 -0700322 strings_properties_[name] =
323 StringsAccessor(new ConstPropertyAccessor<Strings>(prop));
324}
325
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800326void PropertyStore::RegisterWriteOnlyStrings(const string &name,
327 Strings *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800328 DCHECK(!Contains(name) || ContainsKey(strings_properties_, name))
329 << "(Already registered " << name << ")";
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800330 strings_properties_[name] =
331 StringsAccessor(new WriteOnlyPropertyAccessor<Strings>(prop));
332}
333
Chris Masone889666b2011-07-03 12:58:50 -0700334void PropertyStore::RegisterUint8(const string &name, uint8 *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800335 DCHECK(!Contains(name) || ContainsKey(uint8_properties_, name))
336 << "(Already registered " << name << ")";
Chris Masone889666b2011-07-03 12:58:50 -0700337 uint8_properties_[name] = Uint8Accessor(new PropertyAccessor<uint8>(prop));
338}
339
Chris Masoneb925cc82011-06-22 15:39:57 -0700340void PropertyStore::RegisterConstUint8(const string &name, const uint8 *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800341 DCHECK(!Contains(name) || ContainsKey(uint8_properties_, name))
342 << "(Already registered " << name << ")";
Chris Masoneb925cc82011-06-22 15:39:57 -0700343 uint8_properties_[name] =
344 Uint8Accessor(new ConstPropertyAccessor<uint8>(prop));
345}
346
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800347void PropertyStore::RegisterWriteOnlyUint8(const string &name, uint8 *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800348 DCHECK(!Contains(name) || ContainsKey(uint8_properties_, name))
349 << "(Already registered " << name << ")";
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800350 uint8_properties_[name] =
351 Uint8Accessor(new WriteOnlyPropertyAccessor<uint8>(prop));
352}
353
mukesh agrawal66b0aca2012-01-30 15:28:28 -0800354void PropertyStore::RegisterUint16(const string &name, uint16 *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800355 DCHECK(!Contains(name) || ContainsKey(uint16_properties_, name))
356 << "(Already registered " << name << ")";
Chris Masoneb925cc82011-06-22 15:39:57 -0700357 uint16_properties_[name] = Uint16Accessor(new PropertyAccessor<uint16>(prop));
358}
359
mukesh agrawal4d260da2012-01-30 11:53:52 -0800360void PropertyStore::RegisterUint32(const std::string &name, uint32 *prop) {
361 DCHECK(!Contains(name) || ContainsKey(uint32_properties_, name))
362 << "(Already registered " << name << ")";
363 uint32_properties_[name] = Uint32Accessor(new PropertyAccessor<uint32>(prop));
364}
365
Chris Masoneb925cc82011-06-22 15:39:57 -0700366void PropertyStore::RegisterConstUint16(const string &name,
367 const uint16 *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800368 DCHECK(!Contains(name) || ContainsKey(uint16_properties_, name))
369 << "(Already registered " << name << ")";
Chris Masoneb925cc82011-06-22 15:39:57 -0700370 uint16_properties_[name] =
371 Uint16Accessor(new ConstPropertyAccessor<uint16>(prop));
372}
373
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800374void PropertyStore::RegisterWriteOnlyUint16(const string &name, uint16 *prop) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800375 DCHECK(!Contains(name) || ContainsKey(uint16_properties_, name))
376 << "(Already registered " << name << ")";
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800377 uint16_properties_[name] =
378 Uint16Accessor(new WriteOnlyPropertyAccessor<uint16>(prop));
379}
380
mukesh agrawal66b0aca2012-01-30 15:28:28 -0800381void PropertyStore::RegisterDerivedBool(const string &name,
Chris Masone27c4aa52011-07-02 13:10:14 -0700382 const BoolAccessor &accessor) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800383 DCHECK(!Contains(name) || ContainsKey(bool_properties_, name))
384 << "(Already registered " << name << ")";
Chris Masone27c4aa52011-07-02 13:10:14 -0700385 bool_properties_[name] = accessor;
386}
387
mukesh agrawal66b0aca2012-01-30 15:28:28 -0800388void PropertyStore::RegisterDerivedInt32(const string &name,
mukesh agrawal4d0401c2012-01-06 16:05:31 -0800389 const Int32Accessor &accessor) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800390 DCHECK(!Contains(name) || ContainsKey(int32_properties_, name))
391 << "(Already registered " << name << ")";
mukesh agrawal4d0401c2012-01-06 16:05:31 -0800392 int32_properties_[name] = accessor;
393}
394
Darin Petkov63138a92012-02-06 14:09:15 +0100395void PropertyStore::RegisterDerivedKeyValueStore(
mukesh agrawal66b0aca2012-01-30 15:28:28 -0800396 const string &name,
Darin Petkov63138a92012-02-06 14:09:15 +0100397 const KeyValueStoreAccessor &acc) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800398 DCHECK(!Contains(name) || ContainsKey(key_value_store_properties_, name))
399 << "(Already registered " << name << ")";
Darin Petkov63138a92012-02-06 14:09:15 +0100400 key_value_store_properties_[name] = acc;
401}
402
mukesh agrawal66b0aca2012-01-30 15:28:28 -0800403void PropertyStore::RegisterDerivedString(const string &name,
Chris Masone27c4aa52011-07-02 13:10:14 -0700404 const StringAccessor &accessor) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800405 DCHECK(!Contains(name) || ContainsKey(string_properties_, name))
406 << "(Already registered " << name << ")";
Chris Masone27c4aa52011-07-02 13:10:14 -0700407 string_properties_[name] = accessor;
408}
409
mukesh agrawal66b0aca2012-01-30 15:28:28 -0800410void PropertyStore::RegisterDerivedStrings(const string &name,
Chris Masone27c4aa52011-07-02 13:10:14 -0700411 const StringsAccessor &accessor) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800412 DCHECK(!Contains(name) || ContainsKey(strings_properties_, name))
413 << "(Already registered " << name << ")";
Chris Masone27c4aa52011-07-02 13:10:14 -0700414 strings_properties_[name] = accessor;
Chris Masoneb925cc82011-06-22 15:39:57 -0700415}
416
mukesh agrawal66b0aca2012-01-30 15:28:28 -0800417void PropertyStore::RegisterDerivedStringmaps(const string &name,
Chris Masone889666b2011-07-03 12:58:50 -0700418 const StringmapsAccessor &acc) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800419 DCHECK(!Contains(name) || ContainsKey(stringmaps_properties_, name))
420 << "(Already registered " << name << ")";
Chris Masone889666b2011-07-03 12:58:50 -0700421 stringmaps_properties_[name] = acc;
422}
423
mukesh agrawal66b0aca2012-01-30 15:28:28 -0800424void PropertyStore::RegisterDerivedUint16(const string &name,
Paul Stewartbe5f5b32011-12-07 17:11:11 -0800425 const Uint16Accessor &acc) {
mukesh agrawal4d260da2012-01-30 11:53:52 -0800426 DCHECK(!Contains(name) || ContainsKey(uint16_properties_, name))
427 << "(Already registered " << name << ")";
Paul Stewartbe5f5b32011-12-07 17:11:11 -0800428 uint16_properties_[name] = acc;
429}
430
mukesh agrawal66b0aca2012-01-30 15:28:28 -0800431// private methods
432
mukesh agrawalffa3d042011-10-06 15:26:10 -0700433template <class V>
434bool PropertyStore::SetProperty(
435 const string &name,
436 const V &value,
437 Error *error,
438 map< string, std::tr1::shared_ptr< AccessorInterface<V> > >&collection,
439 const string &value_type_english) {
440 VLOG(2) << "Setting " << name << " as " << value_type_english << ".";
441 if (ContainsKey(collection, name)) {
442 collection[name]->Set(value, error);
443 } else {
444 if (Contains(name)) {
445 error->Populate(
446 Error::kInvalidArguments,
447 "Property " + name + " is not " + value_type_english + ".");
448 } else {
449 error->Populate(
450 Error::kInvalidProperty, "Property " + name + " does not exist.");
451 }
452 }
453 return error->IsSuccess();
454};
455
Chris Masoneb925cc82011-06-22 15:39:57 -0700456} // namespace shill