blob: 2edc333e0a8600ec9417e095dade66cbe7905d79 [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:
Chris Masone27c4aa52011-07-02 13:10:14 -070023 PropertyStore();
Chris Masoneb925cc82011-06-22 15:39:57 -070024 virtual ~PropertyStore();
25
mukesh agrawalde29fa82011-09-16 16:16:36 -070026 virtual bool Contains(const std::string& property) const;
Chris Masoneb925cc82011-06-22 15:39:57 -070027
28 // Methods to allow the setting, by name, of properties stored in this object.
29 // The property names are declared in chromeos/dbus/service_constants.h,
30 // so that they may be shared with libcros.
31 // Upon success, these methods return true and leave |error| untouched.
32 // Upon failure, they return false and set |error| appropriately, if it
33 // is non-NULL.
34 virtual bool SetBoolProperty(const std::string& name,
35 bool value,
36 Error *error);
37
38 virtual bool SetInt16Property(const std::string& name,
39 int16 value,
40 Error *error);
41
42 virtual bool SetInt32Property(const std::string& name,
43 int32 value,
44 Error *error);
45
46 virtual bool SetStringProperty(const std::string& name,
47 const std::string& value,
48 Error *error);
49
50 virtual bool SetStringmapProperty(
51 const std::string& name,
52 const std::map<std::string, std::string>& values,
53 Error *error);
54
55 virtual bool SetStringsProperty(const std::string& name,
56 const std::vector<std::string>& values,
57 Error *error);
58
59 virtual bool SetUint8Property(const std::string& name,
60 uint8 value,
61 Error *error);
62
63 virtual bool SetUint16Property(const std::string& name,
64 uint16 value,
65 Error *error);
66
67 virtual bool SetUint32Property(const std::string& name,
68 uint32 value,
69 Error *error);
70
Chris Masonea8a2c252011-06-27 22:16:30 -070071 // Accessors for iterators over property maps.
mukesh agrawalde29fa82011-09-16 16:16:36 -070072 PropertyConstIterator<bool> GetBoolPropertiesIter() const;
73 PropertyConstIterator<int16> GetInt16PropertiesIter() const;
74 PropertyConstIterator<int32> GetInt32PropertiesIter() const;
75 PropertyConstIterator<std::string> GetStringPropertiesIter() const;
76 PropertyConstIterator<Stringmap> GetStringmapPropertiesIter() const;
77 PropertyConstIterator<Stringmaps> GetStringmapsPropertiesIter() const;
78 PropertyConstIterator<StrIntPair> GetStrIntPairPropertiesIter() const;
79 PropertyConstIterator<Strings> GetStringsPropertiesIter() const;
80 PropertyConstIterator<uint8> GetUint8PropertiesIter() const;
81 PropertyConstIterator<uint16> GetUint16PropertiesIter() const;
82 PropertyConstIterator<uint32> GetUint32PropertiesIter() const;
Chris Masonea8a2c252011-06-27 22:16:30 -070083
Chris Masoneb925cc82011-06-22 15:39:57 -070084 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);
Darin Petkovc0865312011-09-16 15:31:20 -070094 void RegisterStringmaps(const std::string &name, Stringmaps *prop);
95 void RegisterConstStringmaps(const std::string &name, const Stringmaps *prop);
Chris Masone43b48a12011-07-01 13:37:07 -070096 void RegisterStrings(const std::string &name, Strings *prop);
Chris Masone889666b2011-07-03 12:58:50 -070097 void RegisterConstStrings(const std::string &name, const Strings *prop);
98 void RegisterUint8(const std::string &name, uint8 *prop);
Chris Masoneb925cc82011-06-22 15:39:57 -070099 void RegisterConstUint8(const std::string &name, const uint8 *prop);
100 void RegisterUint16(const std::string &name, uint16 *prop);
101 void RegisterConstUint16(const std::string &name, const uint16 *prop);
102
Chris Masone27c4aa52011-07-02 13:10:14 -0700103 void RegisterDerivedBool(const std::string &name,
104 const BoolAccessor &accessor);
105 void RegisterDerivedString(const std::string &name,
106 const StringAccessor &accessor);
Chris Masone889666b2011-07-03 12:58:50 -0700107 void RegisterDerivedStringmaps(const std::string &name,
108 const StringmapsAccessor &accessor);
Chris Masone27c4aa52011-07-02 13:10:14 -0700109 void RegisterDerivedStrings(const std::string &name,
110 const StringsAccessor &accessor);
Chris Masone889666b2011-07-03 12:58:50 -0700111 void RegisterDerivedStrIntPair(const std::string &name,
112 const StrIntPairAccessor &accessor);
Chris Masone27c4aa52011-07-02 13:10:14 -0700113
114 private:
Chris Masoneb925cc82011-06-22 15:39:57 -0700115 // These are std::maps instead of something cooler because the common
116 // operation is iterating through them and returning all properties.
117 std::map<std::string, BoolAccessor> bool_properties_;
118 std::map<std::string, Int16Accessor> int16_properties_;
119 std::map<std::string, Int32Accessor> int32_properties_;
120 std::map<std::string, StringAccessor> string_properties_;
121 std::map<std::string, StringmapAccessor> stringmap_properties_;
Chris Masone889666b2011-07-03 12:58:50 -0700122 std::map<std::string, StringmapsAccessor> stringmaps_properties_;
Chris Masoneb925cc82011-06-22 15:39:57 -0700123 std::map<std::string, StringsAccessor> strings_properties_;
Chris Masone889666b2011-07-03 12:58:50 -0700124 std::map<std::string, StrIntPairAccessor> strintpair_properties_;
Chris Masoneb925cc82011-06-22 15:39:57 -0700125 std::map<std::string, Uint8Accessor> uint8_properties_;
126 std::map<std::string, Uint16Accessor> uint16_properties_;
127 std::map<std::string, Uint32Accessor> uint32_properties_;
128
Chris Masoneb925cc82011-06-22 15:39:57 -0700129 DISALLOW_COPY_AND_ASSIGN(PropertyStore);
130};
131
132} // namespace shill
133
134#endif // SHILL_PROPERTY_STORE_