Darin Petkov | 4f0a07b | 2011-05-25 16:47:20 -0700 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium OS Authors. All rights reserved. |
Darin Petkov | 3003059 | 2010-07-27 13:53:20 -0700 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Gilad Arnold | cf175a0 | 2014-07-10 16:48:47 -0700 | [diff] [blame] | 5 | #ifndef UPDATE_ENGINE_PREFS_INTERFACE_H_ |
| 6 | #define UPDATE_ENGINE_PREFS_INTERFACE_H_ |
Darin Petkov | 3003059 | 2010-07-27 13:53:20 -0700 | [diff] [blame] | 7 | |
Ben Chan | 9abb763 | 2014-08-07 00:10:53 -0700 | [diff] [blame] | 8 | #include <stdint.h> |
| 9 | |
Darin Petkov | 3003059 | 2010-07-27 13:53:20 -0700 | [diff] [blame] | 10 | #include <string> |
| 11 | |
| 12 | namespace chromeos_update_engine { |
| 13 | |
| 14 | // The prefs interface allows access to a persistent preferences |
| 15 | // store. The two reasons for providing this as an interface are |
| 16 | // testing as well as easier switching to a new implementation in the |
| 17 | // future, if necessary. |
| 18 | |
| 19 | class PrefsInterface { |
| 20 | public: |
| 21 | // Gets a string |value| associated with |key|. Returns true on |
| 22 | // success, false on failure (including when the |key| is not |
| 23 | // present in the store). |
| 24 | virtual bool GetString(const std::string& key, std::string* value) = 0; |
| 25 | |
| 26 | // Associates |key| with a string |value|. Returns true on success, |
| 27 | // false otherwise. |
| 28 | virtual bool SetString(const std::string& key, const std::string& value) = 0; |
| 29 | |
Ben Chan | 9abb763 | 2014-08-07 00:10:53 -0700 | [diff] [blame] | 30 | // Gets an int64_t |value| associated with |key|. Returns true on |
Darin Petkov | 3003059 | 2010-07-27 13:53:20 -0700 | [diff] [blame] | 31 | // success, false on failure (including when the |key| is not |
| 32 | // present in the store). |
| 33 | virtual bool GetInt64(const std::string& key, int64_t* value) = 0; |
| 34 | |
Ben Chan | 9abb763 | 2014-08-07 00:10:53 -0700 | [diff] [blame] | 35 | // Associates |key| with an int64_t |value|. Returns true on success, |
Darin Petkov | 3003059 | 2010-07-27 13:53:20 -0700 | [diff] [blame] | 36 | // false otherwise. |
| 37 | virtual bool SetInt64(const std::string& key, const int64_t value) = 0; |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 38 | |
Alex Deymo | efb7c4c | 2013-07-09 14:34:00 -0700 | [diff] [blame] | 39 | // Gets a boolean |value| associated with |key|. Returns true on |
| 40 | // success, false on failure (including when the |key| is not |
| 41 | // present in the store). |
| 42 | virtual bool GetBoolean(const std::string& key, bool* value) = 0; |
| 43 | |
| 44 | // Associates |key| with a boolean |value|. Returns true on success, |
| 45 | // false otherwise. |
| 46 | virtual bool SetBoolean(const std::string& key, const bool value) = 0; |
| 47 | |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 48 | // Returns true if the setting exists (i.e. a file with the given key |
| 49 | // exists in the prefs directory) |
| 50 | virtual bool Exists(const std::string& key) = 0; |
| 51 | |
| 52 | // Returns true if successfully deleted the file corresponding to |
| 53 | // this key. Calling with non-existent keys does nothing. |
| 54 | virtual bool Delete(const std::string& key) = 0; |
| 55 | |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 56 | virtual ~PrefsInterface() {} |
Darin Petkov | 3003059 | 2010-07-27 13:53:20 -0700 | [diff] [blame] | 57 | }; |
| 58 | |
| 59 | } // namespace chromeos_update_engine |
| 60 | |
Gilad Arnold | cf175a0 | 2014-07-10 16:48:47 -0700 | [diff] [blame] | 61 | #endif // UPDATE_ENGINE_PREFS_INTERFACE_H_ |