blob: 3ba6530949e5b959b75a1f5f2f50c8612708da30 [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"
15
16namespace shill {
17
18class Error;
19
20class PropertyStore {
21 public:
22 virtual ~PropertyStore();
23
24 virtual bool Contains(const std::string& property);
25
26 // Methods to allow the setting, by name, of properties stored in this object.
27 // The property names are declared in chromeos/dbus/service_constants.h,
28 // so that they may be shared with libcros.
29 // Upon success, these methods return true and leave |error| untouched.
30 // Upon failure, they return false and set |error| appropriately, if it
31 // is non-NULL.
32 virtual bool SetBoolProperty(const std::string& name,
33 bool value,
34 Error *error);
35
36 virtual bool SetInt16Property(const std::string& name,
37 int16 value,
38 Error *error);
39
40 virtual bool SetInt32Property(const std::string& name,
41 int32 value,
42 Error *error);
43
44 virtual bool SetStringProperty(const std::string& name,
45 const std::string& value,
46 Error *error);
47
48 virtual bool SetStringmapProperty(
49 const std::string& name,
50 const std::map<std::string, std::string>& values,
51 Error *error);
52
53 virtual bool SetStringsProperty(const std::string& name,
54 const std::vector<std::string>& values,
55 Error *error);
56
57 virtual bool SetUint8Property(const std::string& name,
58 uint8 value,
59 Error *error);
60
61 virtual bool SetUint16Property(const std::string& name,
62 uint16 value,
63 Error *error);
64
65 virtual bool SetUint32Property(const std::string& name,
66 uint32 value,
67 Error *error);
68
69 protected:
70 PropertyStore();
71
72 void RegisterBool(const std::string &name, bool *prop);
73 void RegisterConstBool(const std::string &name, const bool *prop);
74 void RegisterInt16(const std::string &name, int16 *prop);
75 void RegisterConstInt16(const std::string &name, const int16 *prop);
76 void RegisterInt32(const std::string &name, int32 *prop);
77 void RegisterConstInt32(const std::string &name, const int32 *prop);
78 void RegisterString(const std::string &name, std::string *prop);
79 void RegisterConstString(const std::string &name, const std::string *prop);
80 void RegisterStringmap(const std::string &name,
81 std::map<std::string, std::string> *prop);
82 void RegisterConstStringmap(const std::string &name,
83 const std::map<std::string, std::string> *prop);
84 void RegisterConstUint8(const std::string &name, const uint8 *prop);
85 void RegisterUint16(const std::string &name, uint16 *prop);
86 void RegisterConstUint16(const std::string &name, const uint16 *prop);
87
88 // These are std::maps instead of something cooler because the common
89 // operation is iterating through them and returning all properties.
90 std::map<std::string, BoolAccessor> bool_properties_;
91 std::map<std::string, Int16Accessor> int16_properties_;
92 std::map<std::string, Int32Accessor> int32_properties_;
93 std::map<std::string, StringAccessor> string_properties_;
94 std::map<std::string, StringmapAccessor> stringmap_properties_;
95 std::map<std::string, StringsAccessor> strings_properties_;
96 std::map<std::string, Uint8Accessor> uint8_properties_;
97 std::map<std::string, Uint16Accessor> uint16_properties_;
98 std::map<std::string, Uint32Accessor> uint32_properties_;
99
100 private:
101 bool ReturnError(const std::string& name, Error *error);
102
103 DISALLOW_COPY_AND_ASSIGN(PropertyStore);
104};
105
106} // namespace shill
107
108#endif // SHILL_PROPERTY_STORE_