Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 1 | // 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 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: |
| 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 Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 70 | // 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 Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 81 | 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); |
| 92 | void RegisterStringmap(const std::string &name, |
| 93 | std::map<std::string, std::string> *prop); |
| 94 | void RegisterConstStringmap(const std::string &name, |
| 95 | const std::map<std::string, std::string> *prop); |
| 96 | void RegisterConstUint8(const std::string &name, const uint8 *prop); |
| 97 | void RegisterUint16(const std::string &name, uint16 *prop); |
| 98 | void RegisterConstUint16(const std::string &name, const uint16 *prop); |
| 99 | |
| 100 | // These are std::maps instead of something cooler because the common |
| 101 | // operation is iterating through them and returning all properties. |
| 102 | std::map<std::string, BoolAccessor> bool_properties_; |
| 103 | std::map<std::string, Int16Accessor> int16_properties_; |
| 104 | std::map<std::string, Int32Accessor> int32_properties_; |
| 105 | std::map<std::string, StringAccessor> string_properties_; |
| 106 | std::map<std::string, StringmapAccessor> stringmap_properties_; |
| 107 | std::map<std::string, StringsAccessor> strings_properties_; |
| 108 | std::map<std::string, Uint8Accessor> uint8_properties_; |
| 109 | std::map<std::string, Uint16Accessor> uint16_properties_; |
| 110 | std::map<std::string, Uint32Accessor> uint32_properties_; |
| 111 | |
| 112 | private: |
| 113 | bool ReturnError(const std::string& name, Error *error); |
| 114 | |
| 115 | DISALLOW_COPY_AND_ASSIGN(PropertyStore); |
| 116 | }; |
| 117 | |
| 118 | } // namespace shill |
| 119 | |
| 120 | #endif // SHILL_PROPERTY_STORE_ |