blob: b03d3c0bd86ac1b7bfbddedd6f2113893c47c2ea [file] [log] [blame]
Darin Petkov083047b2011-06-23 20:42:48 -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_STORE_INTERFACE_
6#define SHILL_STORE_INTERFACE_
7
8#include <set>
9#include <string>
Darin Petkovb2841fd2011-06-30 12:54:12 -070010#include <vector>
Darin Petkov083047b2011-06-23 20:42:48 -070011
12namespace shill {
13
14// An interface to a persistent store implementation.
15class StoreInterface {
16 public:
17 virtual ~StoreInterface() {}
18
19 // Opens the store. Returns true on success. This method must be invoked
20 // before using any of the getters or setters. This method is not required
21 // complete gracefully if invoked on a store that has been opened already but
22 // not closed yet.
23 virtual bool Open() = 0;
24
25 // Closes the store and flushes it to persistent storage. Returns true on
26 // success. Note that the store is considered closed even if Close returns
27 // false. This method is not required to complete gracefully if invoked on a
28 // store that has not been opened successfully or has been closed already.
29 virtual bool Close() = 0;
30
31 // Returns a set of all groups contained in the store.
32 virtual std::set<std::string> GetGroups() = 0;
33
34 // Returns true if the store contains |group|, false otherwise.
35 virtual bool ContainsGroup(const std::string &group) = 0;
36
37 // Deletes |group|:|key|. Returns true on success.
38 virtual bool DeleteKey(const std::string &group, const std::string &key) = 0;
39
40 // Deletes |group|. Returns true on success.
41 virtual bool DeleteGroup(const std::string &group) = 0;
42
43 // Gets a string |value| associated with |group|:|key|. Returns true on
44 // success and false on failure (including when |group|:|key| is not present
45 // in the store).
46 virtual bool GetString(const std::string &group,
47 const std::string &key,
48 std::string *value) = 0;
49
50 // Associates |group|:|key| with a string |value|. Returns true on success,
51 // false otherwise.
52 virtual bool SetString(const std::string &group,
53 const std::string &key,
54 const std::string &value) = 0;
55
56 // Gets a boolean |value| associated with |group|:|key|. Returns true on
57 // success and false on failure (including when the |group|:|key| is not
58 // present in the store).
59 virtual bool GetBool(const std::string &group,
60 const std::string &key,
61 bool *value) = 0;
62
63 // Associates |group|:|key| with a boolean |value|. Returns true on success,
64 // false otherwise.
65 virtual bool SetBool(const std::string &group,
66 const std::string &key,
67 bool value) = 0;
68
69 // Gets a integer |value| associated with |group|:|key|. Returns true on
70 // success and false on failure (including when the |group|:|key| is not
71 // present in the store).
72 virtual bool GetInt(const std::string &group,
73 const std::string &key,
74 int *value) = 0;
75
76 // Associates |group|:|key| with an integer |value|. Returns true on success,
77 // false otherwise.
78 virtual bool SetInt(const std::string &group,
79 const std::string &key,
80 int value) = 0;
Darin Petkov86964e02011-06-29 13:49:28 -070081
Darin Petkovb2841fd2011-06-30 12:54:12 -070082 // Gets a string list |value| associated with |group|:|key|. Returns true on
83 // success and false on failure (including when |group|:|key| is not present
84 // in the store).
85 virtual bool GetStringList(const std::string &group,
86 const std::string &key,
87 std::vector<std::string> *value) = 0;
88
89 // Associates |group|:|key| with a string list |value|. Returns true on
90 // success, false otherwise.
91 virtual bool SetStringList(const std::string &group,
92 const std::string &key,
93 const std::vector<std::string> &value) = 0;
94
Darin Petkov86964e02011-06-29 13:49:28 -070095 // Gets and decrypts string |value| associated with |group|:|key|. Returns
96 // true on success and false on failure (including when |group|:|key| is not
97 // present in the store).
98 virtual bool GetCryptedString(const std::string &group,
99 const std::string &key,
100 std::string *value) = 0;
101
102 // Associates |group|:|key| with a string |value| after encrypting it. Returns
103 // true on success, false otherwise.
104 virtual bool SetCryptedString(const std::string &group,
105 const std::string &key,
106 const std::string &value) = 0;
Darin Petkov083047b2011-06-23 20:42:48 -0700107};
108
109} // namespace shill
110
111#endif // SHILL_STORE_INTERFACE_