Darin Petkov | 083047b | 2011-06-23 20:42:48 -0700 | [diff] [blame] | 1 | // 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 Petkov | b2841fd | 2011-06-30 12:54:12 -0700 | [diff] [blame] | 10 | #include <vector> |
Darin Petkov | 083047b | 2011-06-23 20:42:48 -0700 | [diff] [blame] | 11 | |
| 12 | namespace shill { |
| 13 | |
Paul Stewart | 5b9ec98 | 2013-01-18 14:12:14 -0800 | [diff] [blame] | 14 | class KeyValueStore; |
| 15 | |
Darin Petkov | 083047b | 2011-06-23 20:42:48 -0700 | [diff] [blame] | 16 | // An interface to a persistent store implementation. |
| 17 | class StoreInterface { |
| 18 | public: |
| 19 | virtual ~StoreInterface() {} |
| 20 | |
Chris Masone | b9c0059 | 2011-10-06 13:10:39 -0700 | [diff] [blame] | 21 | // Flush current in-memory data to disk. |
| 22 | virtual bool Flush() = 0; |
| 23 | |
Darin Petkov | 083047b | 2011-06-23 20:42:48 -0700 | [diff] [blame] | 24 | // Returns a set of all groups contained in the store. |
Paul Stewart | 0756db9 | 2012-01-27 08:34:47 -0800 | [diff] [blame] | 25 | virtual std::set<std::string> GetGroups() const = 0; |
Darin Petkov | 083047b | 2011-06-23 20:42:48 -0700 | [diff] [blame] | 26 | |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 27 | // Returns the names of all groups that contain the named |key|. |
Paul Stewart | 0756db9 | 2012-01-27 08:34:47 -0800 | [diff] [blame] | 28 | virtual std::set<std::string> GetGroupsWithKey( |
| 29 | const std::string &key) const = 0; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 30 | |
Paul Stewart | 5b9ec98 | 2013-01-18 14:12:14 -0800 | [diff] [blame] | 31 | // 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 Petkov | 083047b | 2011-06-23 20:42:48 -0700 | [diff] [blame] | 36 | // Returns true if the store contains |group|, false otherwise. |
Paul Stewart | 0756db9 | 2012-01-27 08:34:47 -0800 | [diff] [blame] | 37 | virtual bool ContainsGroup(const std::string &group) const = 0; |
Darin Petkov | 083047b | 2011-06-23 20:42:48 -0700 | [diff] [blame] | 38 | |
| 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 Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 45 | // Sets a descriptive header on the key file. |
| 46 | virtual bool SetHeader(const std::string &header) = 0; |
| 47 | |
Darin Petkov | 083047b | 2011-06-23 20:42:48 -0700 | [diff] [blame] | 48 | // 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 Stewart | 85aea15 | 2013-01-22 09:31:56 -0800 | [diff] [blame] | 50 | // in the store). It is not an error to pass NULL as |value| to simply |
| 51 | // test for the presence of this value. |
Darin Petkov | 083047b | 2011-06-23 20:42:48 -0700 | [diff] [blame] | 52 | virtual bool GetString(const std::string &group, |
| 53 | const std::string &key, |
Paul Stewart | 0756db9 | 2012-01-27 08:34:47 -0800 | [diff] [blame] | 54 | std::string *value) const = 0; |
Darin Petkov | 083047b | 2011-06-23 20:42:48 -0700 | [diff] [blame] | 55 | |
| 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 Stewart | 85aea15 | 2013-01-22 09:31:56 -0800 | [diff] [blame] | 64 | // 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 Petkov | 083047b | 2011-06-23 20:42:48 -0700 | [diff] [blame] | 67 | virtual bool GetBool(const std::string &group, |
| 68 | const std::string &key, |
Paul Stewart | 0756db9 | 2012-01-27 08:34:47 -0800 | [diff] [blame] | 69 | bool *value) const = 0; |
Darin Petkov | 083047b | 2011-06-23 20:42:48 -0700 | [diff] [blame] | 70 | |
| 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 Stewart | 85aea15 | 2013-01-22 09:31:56 -0800 | [diff] [blame] | 79 | // 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 Petkov | 083047b | 2011-06-23 20:42:48 -0700 | [diff] [blame] | 81 | virtual bool GetInt(const std::string &group, |
| 82 | const std::string &key, |
Paul Stewart | 0756db9 | 2012-01-27 08:34:47 -0800 | [diff] [blame] | 83 | int *value) const = 0; |
Darin Petkov | 083047b | 2011-06-23 20:42:48 -0700 | [diff] [blame] | 84 | |
| 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 Petkov | 86964e0 | 2011-06-29 13:49:28 -0700 | [diff] [blame] | 90 | |
Paul Stewart | dab3b5a | 2012-07-11 18:25:10 -0700 | [diff] [blame] | 91 | // Gets a 64-bit unsigned integer |value| associated with |group|:|key|. |
| 92 | // Returns true on success and false on failure (including when the |
Paul Stewart | 85aea15 | 2013-01-22 09:31:56 -0800 | [diff] [blame] | 93 | // |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 Stewart | dab3b5a | 2012-07-11 18:25:10 -0700 | [diff] [blame] | 95 | 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 Petkov | b2841fd | 2011-06-30 12:54:12 -0700 | [diff] [blame] | 105 | // 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 Stewart | 85aea15 | 2013-01-22 09:31:56 -0800 | [diff] [blame] | 107 | // in the store). It is not an error to pass NULL as |value| to simply test |
| 108 | // for the presence of this value. |
Darin Petkov | b2841fd | 2011-06-30 12:54:12 -0700 | [diff] [blame] | 109 | virtual bool GetStringList(const std::string &group, |
| 110 | const std::string &key, |
Paul Stewart | 0756db9 | 2012-01-27 08:34:47 -0800 | [diff] [blame] | 111 | std::vector<std::string> *value) const = 0; |
Darin Petkov | b2841fd | 2011-06-30 12:54:12 -0700 | [diff] [blame] | 112 | |
| 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 Petkov | 86964e0 | 2011-06-29 13:49:28 -0700 | [diff] [blame] | 119 | // 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 Stewart | 85aea15 | 2013-01-22 09:31:56 -0800 | [diff] [blame] | 121 | // 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 Petkov | 86964e0 | 2011-06-29 13:49:28 -0700 | [diff] [blame] | 123 | 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 Petkov | 083047b | 2011-06-23 20:42:48 -0700 | [diff] [blame] | 132 | }; |
| 133 | |
| 134 | } // namespace shill |
| 135 | |
| 136 | #endif // SHILL_STORE_INTERFACE_ |