blob: 106749aad3b231db858cf02aca90c31e81def35e [file] [log] [blame]
Paul Stewart8e7e4592012-04-29 09:47:48 -07001// Copyright (c) 2012 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#include "shill/property_store_inspector.h"
6
7#include "shill/error.h"
8
9using std::map;
10using std::string;
11using std::vector;
12
13namespace shill {
14
15PropertyStoreInspector::PropertyStoreInspector() {}
16
17PropertyStoreInspector::PropertyStoreInspector(const PropertyStore *store)
18 : store_(store) {}
19
20PropertyStoreInspector::~PropertyStoreInspector() {}
21
22bool PropertyStoreInspector::GetBoolProperty(const string &name,
23 bool *value,
24 Error *error) {
25 return GetProperty(name, value, error, &PropertyStore::GetBoolPropertiesIter);
26}
27
28bool PropertyStoreInspector::GetInt16Property(const string &name,
29 int16 *value,
30 Error *error) {
31 return GetProperty(name, value, error,
32 &PropertyStore::GetInt16PropertiesIter);
33}
34
35bool PropertyStoreInspector::GetInt32Property(const string &name,
36 int32 *value,
37 Error *error) {
38 return GetProperty(name, value, error,
39 &PropertyStore::GetInt32PropertiesIter);
40}
41
42bool PropertyStoreInspector::GetKeyValueStoreProperty(const string &name,
43 KeyValueStore *value,
44 Error *error) {
45 return GetProperty(name, value, error,
46 &PropertyStore::GetKeyValueStorePropertiesIter);
47}
48
49bool PropertyStoreInspector::GetStringProperty(const string &name,
50 string *value,
51 Error *error) {
52 return GetProperty(name, value, error,
53 &PropertyStore::GetStringPropertiesIter);
54}
55
56bool PropertyStoreInspector::GetStringmapProperty(const string &name,
57 map<string, string> *values,
58 Error *error) {
59 return GetProperty(name, values, error,
60 &PropertyStore::GetStringmapPropertiesIter);
61}
62
63bool PropertyStoreInspector::GetStringsProperty(const string &name,
64 vector<string> *values,
65 Error *error) {
66 return GetProperty(name, values, error,
67 &PropertyStore::GetStringsPropertiesIter);
68}
69
70bool PropertyStoreInspector::GetUint8Property(const string &name,
71 uint8 *value,
72 Error *error) {
73 return GetProperty(name, value, error,
74 &PropertyStore::GetUint8PropertiesIter);
75}
76
77bool PropertyStoreInspector::GetUint16Property(const string &name,
78 uint16 *value,
79 Error *error) {
80 return GetProperty(name, value, error,
81 &PropertyStore::GetUint16PropertiesIter);
82}
83
84bool PropertyStoreInspector::GetUint32Property(const string &name,
85 uint32 *value,
86 Error *error) {
87 return GetProperty(name, value, error,
88 &PropertyStore::GetUint32PropertiesIter);
89}
90
91bool PropertyStoreInspector::GetRpcIdentifierProperty(const string &name,
92 RpcIdentifier *value,
93 Error *error) {
94 return GetProperty(name, value, error,
95 &PropertyStore::GetRpcIdentifierPropertiesIter);
96}
97
98bool PropertyStoreInspector::ContainsBoolProperty(const string &name) {
99 return ContainsProperty(name, &PropertyStore::GetBoolPropertiesIter);
100}
101
102bool PropertyStoreInspector::ContainsInt16Property(const string &name) {
103 return ContainsProperty(name, &PropertyStore::GetInt16PropertiesIter);
104}
105
106bool PropertyStoreInspector::ContainsInt32Property(const string &name) {
107 return ContainsProperty(name, &PropertyStore::GetInt32PropertiesIter);
108}
109
110bool PropertyStoreInspector::ContainsKeyValueStoreProperty(const string &name) {
111 return ContainsProperty(name, &PropertyStore::GetKeyValueStorePropertiesIter);
112}
113
114bool PropertyStoreInspector::ContainsStringProperty(const string &name) {
115 return ContainsProperty(name, &PropertyStore::GetStringPropertiesIter);
116}
117
118bool PropertyStoreInspector::ContainsStringmapProperty(const string &name) {
119 return ContainsProperty(name, &PropertyStore::GetStringmapPropertiesIter);
120}
121
122bool PropertyStoreInspector::ContainsStringsProperty(const string &name) {
123 return ContainsProperty(name, &PropertyStore::GetStringsPropertiesIter);
124}
125
126bool PropertyStoreInspector::ContainsUint8Property(const string &name) {
127 return ContainsProperty(name, &PropertyStore::GetUint8PropertiesIter);
128}
129
130bool PropertyStoreInspector::ContainsUint16Property(const string &name) {
131 return ContainsProperty(name, &PropertyStore::GetUint16PropertiesIter);
132}
133
134bool PropertyStoreInspector::ContainsUint32Property(const string &name) {
135 return ContainsProperty(name, &PropertyStore::GetUint32PropertiesIter);
136}
137
138bool PropertyStoreInspector::ContainsRpcIdentifierProperty(const string &name) {
139 return ContainsProperty(name, &PropertyStore::GetRpcIdentifierPropertiesIter);
140}
141
142template <class V>
143bool PropertyStoreInspector::GetProperty(
144 const string &name,
145 V *value,
146 Error *error,
147 ReadablePropertyConstIterator<V>(PropertyStore::*getter)() const) {
148 ReadablePropertyConstIterator<V> it = ((*store_).*getter)();
149 for ( ; !it.AtEnd(); it.Advance()) {
150 if (it.Key() == name) {
151 *value = it.Value(error);
152 return error->IsSuccess();
153 }
154 }
155 error->Populate(Error::kNotFound);
156 return false;
157};
158
159template <class V>
160bool PropertyStoreInspector::ContainsProperty(
161 const std::string &name,
162 ReadablePropertyConstIterator<V>(PropertyStore::*getter)() const) {
163 V value;
164 Error error;
165 GetProperty(name, &value, &error, getter);
166 return error.type() != Error::kNotFound;
167}
168
169} // namespace shill