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 | |
| 14 | // An interface to a persistent store implementation. |
| 15 | class StoreInterface { |
| 16 | public: |
| 17 | virtual ~StoreInterface() {} |
| 18 | |
Chris Masone | b9c0059 | 2011-10-06 13:10:39 -0700 | [diff] [blame] | 19 | // Flush current in-memory data to disk. |
| 20 | virtual bool Flush() = 0; |
| 21 | |
Darin Petkov | 083047b | 2011-06-23 20:42:48 -0700 | [diff] [blame] | 22 | // Returns a set of all groups contained in the store. |
Paul Stewart | 0756db9 | 2012-01-27 08:34:47 -0800 | [diff] [blame] | 23 | virtual std::set<std::string> GetGroups() const = 0; |
Darin Petkov | 083047b | 2011-06-23 20:42:48 -0700 | [diff] [blame] | 24 | |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 25 | // Returns the names of all groups that contain the named |key|. |
Paul Stewart | 0756db9 | 2012-01-27 08:34:47 -0800 | [diff] [blame] | 26 | virtual std::set<std::string> GetGroupsWithKey( |
| 27 | const std::string &key) const = 0; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 28 | |
Darin Petkov | 083047b | 2011-06-23 20:42:48 -0700 | [diff] [blame] | 29 | // Returns true if the store contains |group|, false otherwise. |
Paul Stewart | 0756db9 | 2012-01-27 08:34:47 -0800 | [diff] [blame] | 30 | virtual bool ContainsGroup(const std::string &group) const = 0; |
Darin Petkov | 083047b | 2011-06-23 20:42:48 -0700 | [diff] [blame] | 31 | |
| 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 Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 38 | // Sets a descriptive header on the key file. |
| 39 | virtual bool SetHeader(const std::string &header) = 0; |
| 40 | |
Darin Petkov | 083047b | 2011-06-23 20:42:48 -0700 | [diff] [blame] | 41 | // 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 Stewart | 0756db9 | 2012-01-27 08:34:47 -0800 | [diff] [blame] | 46 | std::string *value) const = 0; |
Darin Petkov | 083047b | 2011-06-23 20:42:48 -0700 | [diff] [blame] | 47 | |
| 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 Stewart | 0756db9 | 2012-01-27 08:34:47 -0800 | [diff] [blame] | 59 | bool *value) const = 0; |
Darin Petkov | 083047b | 2011-06-23 20:42:48 -0700 | [diff] [blame] | 60 | |
| 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 Stewart | 0756db9 | 2012-01-27 08:34:47 -0800 | [diff] [blame] | 72 | int *value) const = 0; |
Darin Petkov | 083047b | 2011-06-23 20:42:48 -0700 | [diff] [blame] | 73 | |
| 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 Petkov | 86964e0 | 2011-06-29 13:49:28 -0700 | [diff] [blame] | 79 | |
Paul Stewart | dab3b5a | 2012-07-11 18:25:10 -0700 | [diff] [blame] | 80 | // Gets a 64-bit unsigned integer |value| associated with |group|:|key|. |
| 81 | // Returns true on success and false on failure (including when the |
| 82 | // |group|:|key| is not present in the store). |
| 83 | virtual bool GetUint64(const std::string &group, |
| 84 | const std::string &key, |
| 85 | uint64 *value) const = 0; |
| 86 | |
| 87 | // Associates |group|:|key| with a 64-bit unsigned integer |value|. Returns |
| 88 | // true on success, false otherwise. |
| 89 | virtual bool SetUint64(const std::string &group, |
| 90 | const std::string &key, |
| 91 | uint64 value) = 0; |
| 92 | |
Darin Petkov | b2841fd | 2011-06-30 12:54:12 -0700 | [diff] [blame] | 93 | // Gets a string list |value| associated with |group|:|key|. Returns true on |
| 94 | // success and false on failure (including when |group|:|key| is not present |
| 95 | // in the store). |
| 96 | virtual bool GetStringList(const std::string &group, |
| 97 | const std::string &key, |
Paul Stewart | 0756db9 | 2012-01-27 08:34:47 -0800 | [diff] [blame] | 98 | std::vector<std::string> *value) const = 0; |
Darin Petkov | b2841fd | 2011-06-30 12:54:12 -0700 | [diff] [blame] | 99 | |
| 100 | // Associates |group|:|key| with a string list |value|. Returns true on |
| 101 | // success, false otherwise. |
| 102 | virtual bool SetStringList(const std::string &group, |
| 103 | const std::string &key, |
| 104 | const std::vector<std::string> &value) = 0; |
| 105 | |
Darin Petkov | 86964e0 | 2011-06-29 13:49:28 -0700 | [diff] [blame] | 106 | // Gets and decrypts string |value| associated with |group|:|key|. Returns |
| 107 | // true on success and false on failure (including when |group|:|key| is not |
| 108 | // present in the store). |
| 109 | virtual bool GetCryptedString(const std::string &group, |
| 110 | const std::string &key, |
| 111 | std::string *value) = 0; |
| 112 | |
| 113 | // Associates |group|:|key| with a string |value| after encrypting it. Returns |
| 114 | // true on success, false otherwise. |
| 115 | virtual bool SetCryptedString(const std::string &group, |
| 116 | const std::string &key, |
| 117 | const std::string &value) = 0; |
Darin Petkov | 083047b | 2011-06-23 20:42:48 -0700 | [diff] [blame] | 118 | }; |
| 119 | |
| 120 | } // namespace shill |
| 121 | |
| 122 | #endif // SHILL_STORE_INTERFACE_ |