blob: cdc6efe8a8f2dcd8c1e795da547cf67383be84f6 [file] [log] [blame]
Darin Petkov4f0a07b2011-05-25 16:47:20 -07001// Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
Darin Petkov30030592010-07-27 13:53:20 -07002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Gilad Arnoldcf175a02014-07-10 16:48:47 -07005#ifndef UPDATE_ENGINE_PREFS_INTERFACE_H_
6#define UPDATE_ENGINE_PREFS_INTERFACE_H_
Darin Petkov30030592010-07-27 13:53:20 -07007
Ben Chan9abb7632014-08-07 00:10:53 -07008#include <stdint.h>
9
Darin Petkov30030592010-07-27 13:53:20 -070010#include <string>
11
12namespace 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
19class PrefsInterface {
20 public:
Alex Deymo610277e2014-11-11 21:18:11 -080021 virtual ~PrefsInterface() {}
22
Darin Petkov30030592010-07-27 13:53:20 -070023 // Gets a string |value| associated with |key|. Returns true on
24 // success, false on failure (including when the |key| is not
25 // present in the store).
26 virtual bool GetString(const std::string& key, std::string* value) = 0;
27
28 // Associates |key| with a string |value|. Returns true on success,
29 // false otherwise.
30 virtual bool SetString(const std::string& key, const std::string& value) = 0;
31
Ben Chan9abb7632014-08-07 00:10:53 -070032 // Gets an int64_t |value| associated with |key|. Returns true on
Darin Petkov30030592010-07-27 13:53:20 -070033 // success, false on failure (including when the |key| is not
34 // present in the store).
35 virtual bool GetInt64(const std::string& key, int64_t* value) = 0;
36
Ben Chan9abb7632014-08-07 00:10:53 -070037 // Associates |key| with an int64_t |value|. Returns true on success,
Darin Petkov30030592010-07-27 13:53:20 -070038 // false otherwise.
39 virtual bool SetInt64(const std::string& key, const int64_t value) = 0;
Darin Petkov1cbd78f2010-07-29 12:38:34 -070040
Alex Deymoefb7c4c2013-07-09 14:34:00 -070041 // Gets a boolean |value| associated with |key|. Returns true on
42 // success, false on failure (including when the |key| is not
43 // present in the store).
44 virtual bool GetBoolean(const std::string& key, bool* value) = 0;
45
46 // Associates |key| with a boolean |value|. Returns true on success,
47 // false otherwise.
48 virtual bool SetBoolean(const std::string& key, const bool value) = 0;
49
Jay Srinivasan480ddfa2012-06-01 19:15:26 -070050 // Returns true if the setting exists (i.e. a file with the given key
51 // exists in the prefs directory)
52 virtual bool Exists(const std::string& key) = 0;
53
54 // Returns true if successfully deleted the file corresponding to
55 // this key. Calling with non-existent keys does nothing.
56 virtual bool Delete(const std::string& key) = 0;
Darin Petkov30030592010-07-27 13:53:20 -070057};
58
59} // namespace chromeos_update_engine
60
Gilad Arnoldcf175a02014-07-10 16:48:47 -070061#endif // UPDATE_ENGINE_PREFS_INTERFACE_H_