diff options
author | Darin Petkov <petkov@chromium.org> | 2011-06-23 20:42:48 -0700 |
---|---|---|
committer | Darin Petkov <petkov@chromium.org> | 2011-06-24 11:30:04 -0700 |
commit | 083047b53b55abe96200705618fa724e2e3ce715 (patch) | |
tree | 542f27376fb11a6b658584087aadc9f789e24444 /key_file_store.h | |
parent | b925cc8f481d21fddd9569fc68861f6e5b6e3eae (diff) | |
download | shill-083047b53b55abe96200705618fa724e2e3ce715.tar.gz |
shill: Basic persistent store interface and key-file implementation.
The current interface and implementation support all functionality required by
the legacy network manager. The implementation uses glib's key file parser for
legacy reasons. The interface-based implementation allows us to switch to a
different format in the future, if necessary.
BUG=chromium-os:16897
TEST=unit test
Change-Id: I8fd54f47e7309c603b66ba86bbecb8d5092e8674
Reviewed-on: http://gerrit.chromium.org/gerrit/3160
Reviewed-by: Darin Petkov <petkov@chromium.org>
Tested-by: Darin Petkov <petkov@chromium.org>
Diffstat (limited to 'key_file_store.h')
-rw-r--r-- | key_file_store.h | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/key_file_store.h b/key_file_store.h new file mode 100644 index 00000000..a9e28548 --- /dev/null +++ b/key_file_store.h @@ -0,0 +1,66 @@ +// Copyright (c) 2011 The Chromium OS Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef SHILL_KEY_FILE_STORE_ +#define SHILL_KEY_FILE_STORE_ + +#include <base/file_path.h> +#include <gtest/gtest_prod.h> // for FRIEND_TEST + +#include "shill/glib.h" +#include "shill/store_interface.h" + +namespace shill { + +// A key file store implementation of the store interface. See +// http://www.gtk.org/api/2.6/glib/glib-Key-value-file-parser.html for details +// of the key file format. +class KeyFileStore : public StoreInterface { + public: + KeyFileStore(GLib *glib); + virtual ~KeyFileStore(); + + void set_path(const FilePath &path) { path_ = path; } + const FilePath &path() const { return path_; } + + // Inherited from StoreInterface. + virtual bool Open(); + virtual bool Close(); + virtual std::set<std::string> GetGroups(); + virtual bool ContainsGroup(const std::string &group); + virtual bool DeleteKey(const std::string &group, const std::string &key); + virtual bool DeleteGroup(const std::string &group); + virtual bool GetString(const std::string &group, + const std::string &key, + std::string *value); + virtual bool SetString(const std::string &group, + const std::string &key, + const std::string &value); + virtual bool GetBool(const std::string &group, + const std::string &key, + bool *value); + virtual bool SetBool(const std::string &group, + const std::string &key, + bool value); + virtual bool GetInt(const std::string &group, + const std::string &key, + int *value); + virtual bool SetInt(const std::string &group, + const std::string &key, + int value); + + private: + FRIEND_TEST(KeyFileStoreTest, OpenClose); + FRIEND_TEST(KeyFileStoreTest, OpenFail); + + void ReleaseKeyFile(); + + GLib *glib_; + GKeyFile *key_file_; + FilePath path_; +}; + +} // namespace shill + +#endif // SHILL_KEY_FILE_STORE_ |