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