mukesh agrawal | 4d0401c | 2012-01-06 16:05:31 -0800 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 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 Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 15 | #include "shill/property_iterator.h" |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 16 | |
| 17 | namespace shill { |
| 18 | |
| 19 | class Error; |
| 20 | |
| 21 | class PropertyStore { |
| 22 | public: |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 23 | PropertyStore(); |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 24 | virtual ~PropertyStore(); |
| 25 | |
mukesh agrawal | de29fa8 | 2011-09-16 16:16:36 -0700 | [diff] [blame] | 26 | virtual bool Contains(const std::string& property) const; |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 27 | |
| 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 | |
mukesh agrawal | ffa3d04 | 2011-10-06 15:26:10 -0700 | [diff] [blame] | 71 | // We do not provide methods for reading individual properties, |
| 72 | // because we don't need them to implement the flimflam API. (The flimflam |
| 73 | // API only allows fetching all properties at once -- not individual |
| 74 | // properties.) |
| 75 | |
| 76 | // Accessors for iterators over property maps. Useful for dumping all |
| 77 | // properties. |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 78 | ReadablePropertyConstIterator<bool> GetBoolPropertiesIter() const; |
| 79 | ReadablePropertyConstIterator<int16> GetInt16PropertiesIter() const; |
| 80 | ReadablePropertyConstIterator<int32> GetInt32PropertiesIter() const; |
| 81 | ReadablePropertyConstIterator<std::string> GetStringPropertiesIter() const; |
| 82 | ReadablePropertyConstIterator<Stringmap> GetStringmapPropertiesIter() const; |
| 83 | ReadablePropertyConstIterator<Stringmaps> GetStringmapsPropertiesIter() const; |
| 84 | ReadablePropertyConstIterator<StrIntPair> GetStrIntPairPropertiesIter() const; |
| 85 | ReadablePropertyConstIterator<Strings> GetStringsPropertiesIter() const; |
| 86 | ReadablePropertyConstIterator<uint8> GetUint8PropertiesIter() const; |
| 87 | ReadablePropertyConstIterator<uint16> GetUint16PropertiesIter() const; |
| 88 | ReadablePropertyConstIterator<uint32> GetUint32PropertiesIter() const; |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 89 | |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 90 | void RegisterBool(const std::string &name, bool *prop); |
| 91 | void RegisterConstBool(const std::string &name, const bool *prop); |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 92 | void RegisterWriteOnlyBool(const std::string &name, bool *prop); |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 93 | void RegisterInt16(const std::string &name, int16 *prop); |
| 94 | void RegisterConstInt16(const std::string &name, const int16 *prop); |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 95 | void RegisterWriteOnlyInt16(const std::string &name, int16 *prop); |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 96 | void RegisterInt32(const std::string &name, int32 *prop); |
| 97 | void RegisterConstInt32(const std::string &name, const int32 *prop); |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 98 | void RegisterWriteOnlyInt32(const std::string &name, int32 *prop); |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 99 | void RegisterString(const std::string &name, std::string *prop); |
| 100 | void RegisterConstString(const std::string &name, const std::string *prop); |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 101 | void RegisterWriteOnlyString(const std::string &name, std::string *prop); |
Chris Masone | 43b48a1 | 2011-07-01 13:37:07 -0700 | [diff] [blame] | 102 | void RegisterStringmap(const std::string &name, Stringmap *prop); |
| 103 | void RegisterConstStringmap(const std::string &name, const Stringmap *prop); |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 104 | void RegisterWriteOnlyStringmap(const std::string &name, Stringmap *prop); |
Darin Petkov | c086531 | 2011-09-16 15:31:20 -0700 | [diff] [blame] | 105 | void RegisterStringmaps(const std::string &name, Stringmaps *prop); |
| 106 | void RegisterConstStringmaps(const std::string &name, const Stringmaps *prop); |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 107 | void RegisterWriteOnlyStringmaps(const std::string &name, Stringmaps *prop); |
Chris Masone | 43b48a1 | 2011-07-01 13:37:07 -0700 | [diff] [blame] | 108 | void RegisterStrings(const std::string &name, Strings *prop); |
Chris Masone | 889666b | 2011-07-03 12:58:50 -0700 | [diff] [blame] | 109 | void RegisterConstStrings(const std::string &name, const Strings *prop); |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 110 | void RegisterWriteOnlyStrings(const std::string &name, Strings *prop); |
Chris Masone | 889666b | 2011-07-03 12:58:50 -0700 | [diff] [blame] | 111 | void RegisterUint8(const std::string &name, uint8 *prop); |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 112 | void RegisterConstUint8(const std::string &name, const uint8 *prop); |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 113 | void RegisterWriteOnlyUint8(const std::string &name, uint8 *prop); |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 114 | void RegisterUint16(const std::string &name, uint16 *prop); |
| 115 | void RegisterConstUint16(const std::string &name, const uint16 *prop); |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 116 | void RegisterWriteOnlyUint16(const std::string &name, uint16 *prop); |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 117 | |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 118 | void RegisterDerivedBool(const std::string &name, |
| 119 | const BoolAccessor &accessor); |
mukesh agrawal | 4d0401c | 2012-01-06 16:05:31 -0800 | [diff] [blame] | 120 | void RegisterDerivedInt32(const std::string &name, |
| 121 | const Int32Accessor &accessor); |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 122 | void RegisterDerivedString(const std::string &name, |
| 123 | const StringAccessor &accessor); |
Chris Masone | 889666b | 2011-07-03 12:58:50 -0700 | [diff] [blame] | 124 | void RegisterDerivedStringmaps(const std::string &name, |
| 125 | const StringmapsAccessor &accessor); |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 126 | void RegisterDerivedStrings(const std::string &name, |
| 127 | const StringsAccessor &accessor); |
Chris Masone | 889666b | 2011-07-03 12:58:50 -0700 | [diff] [blame] | 128 | void RegisterDerivedStrIntPair(const std::string &name, |
| 129 | const StrIntPairAccessor &accessor); |
Paul Stewart | be5f5b3 | 2011-12-07 17:11:11 -0800 | [diff] [blame] | 130 | void RegisterDerivedUint16(const std::string &name, |
| 131 | const Uint16Accessor &accessor); |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 132 | |
| 133 | private: |
mukesh agrawal | ffa3d04 | 2011-10-06 15:26:10 -0700 | [diff] [blame] | 134 | template <class V> |
| 135 | bool SetProperty( |
| 136 | const std::string &name, |
| 137 | const V &value, |
| 138 | Error *error, |
| 139 | std::map< std::string, std::tr1::shared_ptr< AccessorInterface<V> > > &, |
| 140 | const std::string &value_type_english); |
| 141 | |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 142 | // These are std::maps instead of something cooler because the common |
| 143 | // operation is iterating through them and returning all properties. |
| 144 | std::map<std::string, BoolAccessor> bool_properties_; |
| 145 | std::map<std::string, Int16Accessor> int16_properties_; |
| 146 | std::map<std::string, Int32Accessor> int32_properties_; |
| 147 | std::map<std::string, StringAccessor> string_properties_; |
| 148 | std::map<std::string, StringmapAccessor> stringmap_properties_; |
Chris Masone | 889666b | 2011-07-03 12:58:50 -0700 | [diff] [blame] | 149 | std::map<std::string, StringmapsAccessor> stringmaps_properties_; |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 150 | std::map<std::string, StringsAccessor> strings_properties_; |
Chris Masone | 889666b | 2011-07-03 12:58:50 -0700 | [diff] [blame] | 151 | std::map<std::string, StrIntPairAccessor> strintpair_properties_; |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 152 | std::map<std::string, Uint8Accessor> uint8_properties_; |
| 153 | std::map<std::string, Uint16Accessor> uint16_properties_; |
| 154 | std::map<std::string, Uint32Accessor> uint32_properties_; |
| 155 | |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 156 | DISALLOW_COPY_AND_ASSIGN(PropertyStore); |
| 157 | }; |
| 158 | |
| 159 | } // namespace shill |
| 160 | |
| 161 | #endif // SHILL_PROPERTY_STORE_ |