blob: 2634bed5227e01d72d8933ce8b43746b4e5270b4 [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
Paul Stewart5b9ec982013-01-18 14:12:14 -080014class KeyValueStore;
15
Darin Petkov083047b2011-06-23 20:42:48 -070016// An interface to a persistent store implementation.
17class StoreInterface {
18 public:
19 virtual ~StoreInterface() {}
20
Chris Masoneb9c00592011-10-06 13:10:39 -070021 // Flush current in-memory data to disk.
22 virtual bool Flush() = 0;
23
Darin Petkov083047b2011-06-23 20:42:48 -070024 // Returns a set of all groups contained in the store.
Paul Stewart0756db92012-01-27 08:34:47 -080025 virtual std::set<std::string> GetGroups() const = 0;
Darin Petkov083047b2011-06-23 20:42:48 -070026
Paul Stewarta41e38d2011-11-11 07:47:29 -080027 // Returns the names of all groups that contain the named |key|.
Paul Stewart0756db92012-01-27 08:34:47 -080028 virtual std::set<std::string> GetGroupsWithKey(
29 const std::string &key) const = 0;
Paul Stewarta41e38d2011-11-11 07:47:29 -080030
Paul Stewart5b9ec982013-01-18 14:12:14 -080031 // Returns the names of all groups that contain the named |properties|.
32 // Only the Bool, Int and String properties are checked.
33 virtual std::set<std::string> GetGroupsWithProperties(
34 const KeyValueStore &properties) const = 0;
35
Darin Petkov083047b2011-06-23 20:42:48 -070036 // Returns true if the store contains |group|, false otherwise.
Paul Stewart0756db92012-01-27 08:34:47 -080037 virtual bool ContainsGroup(const std::string &group) const = 0;
Darin Petkov083047b2011-06-23 20:42:48 -070038
39 // Deletes |group|:|key|. Returns true on success.
40 virtual bool DeleteKey(const std::string &group, const std::string &key) = 0;
41
42 // Deletes |group|. Returns true on success.
43 virtual bool DeleteGroup(const std::string &group) = 0;
44
Paul Stewart5dc40aa2011-10-28 19:43:43 -070045 // Sets a descriptive header on the key file.
46 virtual bool SetHeader(const std::string &header) = 0;
47
Darin Petkov083047b2011-06-23 20:42:48 -070048 // Gets a string |value| associated with |group|:|key|. Returns true on
49 // success and false on failure (including when |group|:|key| is not present
Paul Stewart85aea152013-01-22 09:31:56 -080050 // in the store). It is not an error to pass NULL as |value| to simply
51 // test for the presence of this value.
Darin Petkov083047b2011-06-23 20:42:48 -070052 virtual bool GetString(const std::string &group,
53 const std::string &key,
Paul Stewart0756db92012-01-27 08:34:47 -080054 std::string *value) const = 0;
Darin Petkov083047b2011-06-23 20:42:48 -070055
56 // Associates |group|:|key| with a string |value|. Returns true on success,
57 // false otherwise.
58 virtual bool SetString(const std::string &group,
59 const std::string &key,
60 const std::string &value) = 0;
61
62 // Gets a boolean |value| associated with |group|:|key|. Returns true on
63 // success and false on failure (including when the |group|:|key| is not
Paul Stewart85aea152013-01-22 09:31:56 -080064 // present in the store). It is not an error to pass NULL as |value| to
65 // simply test for the presence of this value.
66
Darin Petkov083047b2011-06-23 20:42:48 -070067 virtual bool GetBool(const std::string &group,
68 const std::string &key,
Paul Stewart0756db92012-01-27 08:34:47 -080069 bool *value) const = 0;
Darin Petkov083047b2011-06-23 20:42:48 -070070
71 // Associates |group|:|key| with a boolean |value|. Returns true on success,
72 // false otherwise.
73 virtual bool SetBool(const std::string &group,
74 const std::string &key,
75 bool value) = 0;
76
77 // Gets a integer |value| associated with |group|:|key|. Returns true on
78 // success and false on failure (including when the |group|:|key| is not
Paul Stewart85aea152013-01-22 09:31:56 -080079 // present in the store). It is not an error to pass NULL as |value| to
80 // simply test for the presence of this value.
Darin Petkov083047b2011-06-23 20:42:48 -070081 virtual bool GetInt(const std::string &group,
82 const std::string &key,
Paul Stewart0756db92012-01-27 08:34:47 -080083 int *value) const = 0;
Darin Petkov083047b2011-06-23 20:42:48 -070084
85 // Associates |group|:|key| with an integer |value|. Returns true on success,
86 // false otherwise.
87 virtual bool SetInt(const std::string &group,
88 const std::string &key,
89 int value) = 0;
Darin Petkov86964e02011-06-29 13:49:28 -070090
Paul Stewartdab3b5a2012-07-11 18:25:10 -070091 // Gets a 64-bit unsigned integer |value| associated with |group|:|key|.
92 // Returns true on success and false on failure (including when the
Paul Stewart85aea152013-01-22 09:31:56 -080093 // |group|:|key| is not present in the store). It is not an error to
94 // pass NULL as |value| to simply test for the presence of this value.
Paul Stewartdab3b5a2012-07-11 18:25:10 -070095 virtual bool GetUint64(const std::string &group,
96 const std::string &key,
97 uint64 *value) const = 0;
98
99 // Associates |group|:|key| with a 64-bit unsigned integer |value|. Returns
100 // true on success, false otherwise.
101 virtual bool SetUint64(const std::string &group,
102 const std::string &key,
103 uint64 value) = 0;
104
Darin Petkovb2841fd2011-06-30 12:54:12 -0700105 // Gets a string list |value| associated with |group|:|key|. Returns true on
106 // success and false on failure (including when |group|:|key| is not present
Paul Stewart85aea152013-01-22 09:31:56 -0800107 // in the store). It is not an error to pass NULL as |value| to simply test
108 // for the presence of this value.
Darin Petkovb2841fd2011-06-30 12:54:12 -0700109 virtual bool GetStringList(const std::string &group,
110 const std::string &key,
Paul Stewart0756db92012-01-27 08:34:47 -0800111 std::vector<std::string> *value) const = 0;
Darin Petkovb2841fd2011-06-30 12:54:12 -0700112
113 // Associates |group|:|key| with a string list |value|. Returns true on
114 // success, false otherwise.
115 virtual bool SetStringList(const std::string &group,
116 const std::string &key,
117 const std::vector<std::string> &value) = 0;
118
Darin Petkov86964e02011-06-29 13:49:28 -0700119 // Gets and decrypts string |value| associated with |group|:|key|. Returns
120 // true on success and false on failure (including when |group|:|key| is not
Paul Stewart85aea152013-01-22 09:31:56 -0800121 // present in the store). It is not an error to pass NULL as |value| to
122 // simply test for the presence of this value.
Darin Petkov86964e02011-06-29 13:49:28 -0700123 virtual bool GetCryptedString(const std::string &group,
124 const std::string &key,
125 std::string *value) = 0;
126
127 // Associates |group|:|key| with a string |value| after encrypting it. Returns
128 // true on success, false otherwise.
129 virtual bool SetCryptedString(const std::string &group,
130 const std::string &key,
131 const std::string &value) = 0;
Darin Petkov083047b2011-06-23 20:42:48 -0700132};
133
134} // namespace shill
135
136#endif // SHILL_STORE_INTERFACE_