blob: 9d1e7ab089742b840d88d9d99a0c08154679cc3e [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
Chris Masoneb9c00592011-10-06 13:10:39 -070019 // Flush current in-memory data to disk.
20 virtual bool Flush() = 0;
21
Darin Petkov083047b2011-06-23 20:42:48 -070022 // Returns a set of all groups contained in the store.
Paul Stewart0756db92012-01-27 08:34:47 -080023 virtual std::set<std::string> GetGroups() const = 0;
Darin Petkov083047b2011-06-23 20:42:48 -070024
Paul Stewarta41e38d2011-11-11 07:47:29 -080025 // Returns the names of all groups that contain the named |key|.
Paul Stewart0756db92012-01-27 08:34:47 -080026 virtual std::set<std::string> GetGroupsWithKey(
27 const std::string &key) const = 0;
Paul Stewarta41e38d2011-11-11 07:47:29 -080028
Darin Petkov083047b2011-06-23 20:42:48 -070029 // Returns true if the store contains |group|, false otherwise.
Paul Stewart0756db92012-01-27 08:34:47 -080030 virtual bool ContainsGroup(const std::string &group) const = 0;
Darin Petkov083047b2011-06-23 20:42:48 -070031
32 // Deletes |group|:|key|. Returns true on success.
33 virtual bool DeleteKey(const std::string &group, const std::string &key) = 0;
34
35 // Deletes |group|. Returns true on success.
36 virtual bool DeleteGroup(const std::string &group) = 0;
37
Paul Stewart5dc40aa2011-10-28 19:43:43 -070038 // Sets a descriptive header on the key file.
39 virtual bool SetHeader(const std::string &header) = 0;
40
Darin Petkov083047b2011-06-23 20:42:48 -070041 // Gets a string |value| associated with |group|:|key|. Returns true on
42 // success and false on failure (including when |group|:|key| is not present
43 // in the store).
44 virtual bool GetString(const std::string &group,
45 const std::string &key,
Paul Stewart0756db92012-01-27 08:34:47 -080046 std::string *value) const = 0;
Darin Petkov083047b2011-06-23 20:42:48 -070047
48 // Associates |group|:|key| with a string |value|. Returns true on success,
49 // false otherwise.
50 virtual bool SetString(const std::string &group,
51 const std::string &key,
52 const std::string &value) = 0;
53
54 // Gets a boolean |value| associated with |group|:|key|. Returns true on
55 // success and false on failure (including when the |group|:|key| is not
56 // present in the store).
57 virtual bool GetBool(const std::string &group,
58 const std::string &key,
Paul Stewart0756db92012-01-27 08:34:47 -080059 bool *value) const = 0;
Darin Petkov083047b2011-06-23 20:42:48 -070060
61 // Associates |group|:|key| with a boolean |value|. Returns true on success,
62 // false otherwise.
63 virtual bool SetBool(const std::string &group,
64 const std::string &key,
65 bool value) = 0;
66
67 // Gets a integer |value| associated with |group|:|key|. Returns true on
68 // success and false on failure (including when the |group|:|key| is not
69 // present in the store).
70 virtual bool GetInt(const std::string &group,
71 const std::string &key,
Paul Stewart0756db92012-01-27 08:34:47 -080072 int *value) const = 0;
Darin Petkov083047b2011-06-23 20:42:48 -070073
74 // Associates |group|:|key| with an integer |value|. Returns true on success,
75 // false otherwise.
76 virtual bool SetInt(const std::string &group,
77 const std::string &key,
78 int value) = 0;
Darin Petkov86964e02011-06-29 13:49:28 -070079
Darin Petkovb2841fd2011-06-30 12:54:12 -070080 // Gets a string list |value| associated with |group|:|key|. Returns true on
81 // success and false on failure (including when |group|:|key| is not present
82 // in the store).
83 virtual bool GetStringList(const std::string &group,
84 const std::string &key,
Paul Stewart0756db92012-01-27 08:34:47 -080085 std::vector<std::string> *value) const = 0;
Darin Petkovb2841fd2011-06-30 12:54:12 -070086
87 // Associates |group|:|key| with a string list |value|. Returns true on
88 // success, false otherwise.
89 virtual bool SetStringList(const std::string &group,
90 const std::string &key,
91 const std::vector<std::string> &value) = 0;
92
Darin Petkov86964e02011-06-29 13:49:28 -070093 // Gets and decrypts string |value| associated with |group|:|key|. Returns
94 // true on success and false on failure (including when |group|:|key| is not
95 // present in the store).
96 virtual bool GetCryptedString(const std::string &group,
97 const std::string &key,
98 std::string *value) = 0;
99
100 // Associates |group|:|key| with a string |value| after encrypting it. Returns
101 // true on success, false otherwise.
102 virtual bool SetCryptedString(const std::string &group,
103 const std::string &key,
104 const std::string &value) = 0;
Darin Petkov083047b2011-06-23 20:42:48 -0700105};
106
107} // namespace shill
108
109#endif // SHILL_STORE_INTERFACE_