Alex Deymo | aea4c1c | 2015-08-19 20:24:43 -0700 | [diff] [blame^] | 1 | // |
| 2 | // Copyright (C) 2011 The Android Open Source Project |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | // |
Darin Petkov | 3003059 | 2010-07-27 13:53:20 -0700 | [diff] [blame] | 16 | |
Gilad Arnold | cf175a0 | 2014-07-10 16:48:47 -0700 | [diff] [blame] | 17 | #ifndef UPDATE_ENGINE_PREFS_INTERFACE_H_ |
| 18 | #define UPDATE_ENGINE_PREFS_INTERFACE_H_ |
Darin Petkov | 3003059 | 2010-07-27 13:53:20 -0700 | [diff] [blame] | 19 | |
Ben Chan | 9abb763 | 2014-08-07 00:10:53 -0700 | [diff] [blame] | 20 | #include <stdint.h> |
| 21 | |
Darin Petkov | 3003059 | 2010-07-27 13:53:20 -0700 | [diff] [blame] | 22 | #include <string> |
| 23 | |
| 24 | namespace chromeos_update_engine { |
| 25 | |
| 26 | // The prefs interface allows access to a persistent preferences |
| 27 | // store. The two reasons for providing this as an interface are |
| 28 | // testing as well as easier switching to a new implementation in the |
| 29 | // future, if necessary. |
| 30 | |
| 31 | class PrefsInterface { |
| 32 | public: |
Alex Deymo | 610277e | 2014-11-11 21:18:11 -0800 | [diff] [blame] | 33 | virtual ~PrefsInterface() {} |
| 34 | |
Darin Petkov | 3003059 | 2010-07-27 13:53:20 -0700 | [diff] [blame] | 35 | // Gets a string |value| associated with |key|. Returns true on |
| 36 | // success, false on failure (including when the |key| is not |
| 37 | // present in the store). |
| 38 | virtual bool GetString(const std::string& key, std::string* value) = 0; |
| 39 | |
| 40 | // Associates |key| with a string |value|. Returns true on success, |
| 41 | // false otherwise. |
| 42 | virtual bool SetString(const std::string& key, const std::string& value) = 0; |
| 43 | |
Ben Chan | 9abb763 | 2014-08-07 00:10:53 -0700 | [diff] [blame] | 44 | // Gets an int64_t |value| associated with |key|. Returns true on |
Darin Petkov | 3003059 | 2010-07-27 13:53:20 -0700 | [diff] [blame] | 45 | // success, false on failure (including when the |key| is not |
| 46 | // present in the store). |
| 47 | virtual bool GetInt64(const std::string& key, int64_t* value) = 0; |
| 48 | |
Ben Chan | 9abb763 | 2014-08-07 00:10:53 -0700 | [diff] [blame] | 49 | // Associates |key| with an int64_t |value|. Returns true on success, |
Darin Petkov | 3003059 | 2010-07-27 13:53:20 -0700 | [diff] [blame] | 50 | // false otherwise. |
| 51 | virtual bool SetInt64(const std::string& key, const int64_t value) = 0; |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 52 | |
Alex Deymo | efb7c4c | 2013-07-09 14:34:00 -0700 | [diff] [blame] | 53 | // Gets a boolean |value| associated with |key|. Returns true on |
| 54 | // success, false on failure (including when the |key| is not |
| 55 | // present in the store). |
| 56 | virtual bool GetBoolean(const std::string& key, bool* value) = 0; |
| 57 | |
| 58 | // Associates |key| with a boolean |value|. Returns true on success, |
| 59 | // false otherwise. |
| 60 | virtual bool SetBoolean(const std::string& key, const bool value) = 0; |
| 61 | |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 62 | // Returns true if the setting exists (i.e. a file with the given key |
| 63 | // exists in the prefs directory) |
| 64 | virtual bool Exists(const std::string& key) = 0; |
| 65 | |
| 66 | // Returns true if successfully deleted the file corresponding to |
| 67 | // this key. Calling with non-existent keys does nothing. |
| 68 | virtual bool Delete(const std::string& key) = 0; |
Darin Petkov | 3003059 | 2010-07-27 13:53:20 -0700 | [diff] [blame] | 69 | }; |
| 70 | |
| 71 | } // namespace chromeos_update_engine |
| 72 | |
Gilad Arnold | cf175a0 | 2014-07-10 16:48:47 -0700 | [diff] [blame] | 73 | #endif // UPDATE_ENGINE_PREFS_INTERFACE_H_ |