blob: 485f429c84a5300459134eea2729125df1713b92 [file] [log] [blame]
Chris Masoneb925cc82011-06-22 15:39:57 -07001// Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef SHILL_PROPERTY_STORE_
6#define SHILL_PROPERTY_STORE_
7
8#include <map>
9#include <string>
10#include <vector>
11
12#include <base/basictypes.h>
13
14#include "shill/accessor_interface.h"
Chris Masonea8a2c252011-06-27 22:16:30 -070015#include "shill/property_iterator.h"
Chris Masoneb925cc82011-06-22 15:39:57 -070016
17namespace shill {
18
19class Error;
20
21class PropertyStore {
22 public:
23 virtual ~PropertyStore();
24
25 virtual bool Contains(const std::string& property);
26
27 // Methods to allow the setting, by name, of properties stored in this object.
28 // The property names are declared in chromeos/dbus/service_constants.h,
29 // so that they may be shared with libcros.
30 // Upon success, these methods return true and leave |error| untouched.
31 // Upon failure, they return false and set |error| appropriately, if it
32 // is non-NULL.
33 virtual bool SetBoolProperty(const std::string& name,
34 bool value,
35 Error *error);
36
37 virtual bool SetInt16Property(const std::string& name,
38 int16 value,
39 Error *error);
40
41 virtual bool SetInt32Property(const std::string& name,
42 int32 value,
43 Error *error);
44
45 virtual bool SetStringProperty(const std::string& name,
46 const std::string& value,
47 Error *error);
48
49 virtual bool SetStringmapProperty(
50 const std::string& name,
51 const std::map<std::string, std::string>& values,
52 Error *error);
53
54 virtual bool SetStringsProperty(const std::string& name,
55 const std::vector<std::string>& values,
56 Error *error);
57
58 virtual bool SetUint8Property(const std::string& name,
59 uint8 value,
60 Error *error);
61
62 virtual bool SetUint16Property(const std::string& name,
63 uint16 value,
64 Error *error);
65
66 virtual bool SetUint32Property(const std::string& name,
67 uint32 value,
68 Error *error);
69
Chris Masonea8a2c252011-06-27 22:16:30 -070070 // Accessors for iterators over property maps.
71 PropertyConstIterator<bool> GetBoolPropertiesIter();
72 PropertyConstIterator<int16> GetInt16PropertiesIter();
73 PropertyConstIterator<int32> GetInt32PropertiesIter();
74 PropertyConstIterator<std::string> GetStringPropertiesIter();
75 PropertyConstIterator<Stringmap> GetStringmapPropertiesIter();
76 PropertyConstIterator<Strings> GetStringsPropertiesIter();
77 PropertyConstIterator<uint8> GetUint8PropertiesIter();
78 PropertyConstIterator<uint16> GetUint16PropertiesIter();
79 PropertyConstIterator<uint32> GetUint32PropertiesIter();
80
Chris Masoneb925cc82011-06-22 15:39:57 -070081 protected:
82 PropertyStore();
83
84 void RegisterBool(const std::string &name, bool *prop);
85 void RegisterConstBool(const std::string &name, const bool *prop);
86 void RegisterInt16(const std::string &name, int16 *prop);
87 void RegisterConstInt16(const std::string &name, const int16 *prop);
88 void RegisterInt32(const std::string &name, int32 *prop);
89 void RegisterConstInt32(const std::string &name, const int32 *prop);
90 void RegisterString(const std::string &name, std::string *prop);
91 void RegisterConstString(const std::string &name, const std::string *prop);
Chris Masone43b48a12011-07-01 13:37:07 -070092 void RegisterStringmap(const std::string &name, Stringmap *prop);
93 void RegisterConstStringmap(const std::string &name, const Stringmap *prop);
94 void RegisterStrings(const std::string &name, Strings *prop);
Chris Masoneb925cc82011-06-22 15:39:57 -070095 void RegisterConstUint8(const std::string &name, const uint8 *prop);
96 void RegisterUint16(const std::string &name, uint16 *prop);
97 void RegisterConstUint16(const std::string &name, const uint16 *prop);
98
99 // These are std::maps instead of something cooler because the common
100 // operation is iterating through them and returning all properties.
101 std::map<std::string, BoolAccessor> bool_properties_;
102 std::map<std::string, Int16Accessor> int16_properties_;
103 std::map<std::string, Int32Accessor> int32_properties_;
104 std::map<std::string, StringAccessor> string_properties_;
105 std::map<std::string, StringmapAccessor> stringmap_properties_;
106 std::map<std::string, StringsAccessor> strings_properties_;
107 std::map<std::string, Uint8Accessor> uint8_properties_;
108 std::map<std::string, Uint16Accessor> uint16_properties_;
109 std::map<std::string, Uint32Accessor> uint32_properties_;
110
111 private:
112 bool ReturnError(const std::string& name, Error *error);
113
114 DISALLOW_COPY_AND_ASSIGN(PropertyStore);
115};
116
117} // namespace shill
118
119#endif // SHILL_PROPERTY_STORE_