blob: b29a9dc3f7d825d2421b74137fcc4f563927bf82 [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
Darin Petkov4682aa82012-05-31 16:24:11 +02005#ifndef SHILL_PROPERTY_STORE_INSPECTOR_H_
6#define SHILL_PROPERTY_STORE_INSPECTOR_H_
Paul Stewart8e7e4592012-04-29 09:47:48 -07007
8#ifndef UNIT_TEST
9#error "Do not use PropertyStoreInspector in non-test code."
10#endif
11
12#include "shill/property_store.h"
13
14namespace shill {
15
16// This class supplies functions to unit tests for inspecting a PropertyStore
17// class to get single attributes. We never need to do this in the real
18// PropertyStore, since the only interface to it over the control API is
19// "GetProperties" which iterates over the entire store's properties.
20//
21// This code is done inefficiently -- if we were ever meant to retrieve
22// single properties in production code, we'd access the map directly.
23// For this reason, this class should only be used in unit tests.
24class PropertyStoreInspector {
25 public:
26 PropertyStoreInspector();
27 explicit PropertyStoreInspector(const PropertyStore *store);
28 virtual ~PropertyStoreInspector();
29
30 const PropertyStore *store() const { return store_; }
31 void set_store(const PropertyStore *store) { store_ = store; }
32
Darin Petkov4682aa82012-05-31 16:24:11 +020033 // Methods to allow the getting of properties stored in the referenced
34 // |store_| by name. Upon success, these methods return true and return the
35 // property value in |value| if non-NULL. Upon failure, they return false and
36 // leave |value| untouched.
37 bool GetBoolProperty(const std::string &name, bool *value);
38 bool GetInt16Property(const std::string &name, int16 *value);
39 bool GetInt32Property(const std::string &name, int32 *value);
40 bool GetKeyValueStoreProperty(const std::string &name, KeyValueStore *value);
41 bool GetStringProperty(const std::string &name, std::string *value);
Paul Stewart8e7e4592012-04-29 09:47:48 -070042 bool GetStringmapProperty(const std::string &name,
Darin Petkov4682aa82012-05-31 16:24:11 +020043 std::map<std::string, std::string> *values);
Paul Stewart8e7e4592012-04-29 09:47:48 -070044 bool GetStringsProperty(const std::string &name,
Darin Petkov4682aa82012-05-31 16:24:11 +020045 std::vector<std::string> *values);
46 bool GetUint8Property(const std::string &name, uint8 *value);
47 bool GetUint16Property(const std::string &name, uint16 *value);
48 bool GetUint32Property(const std::string &name, uint32 *value);
49 bool GetRpcIdentifierProperty(const std::string &name, RpcIdentifier *value);
Paul Stewart8e7e4592012-04-29 09:47:48 -070050
51 private:
52 template <class V>
53 bool GetProperty(
54 const std::string &name,
55 V *value,
Paul Stewart8e7e4592012-04-29 09:47:48 -070056 ReadablePropertyConstIterator<V>(PropertyStore::*getter)() const);
57
58 const PropertyStore *store_;
59
60 DISALLOW_COPY_AND_ASSIGN(PropertyStoreInspector);
61};
62
63} // namespace shill
64
65
Darin Petkov4682aa82012-05-31 16:24:11 +020066#endif // SHILL_PROPERTY_STORE_INSPECTOR_H_