Bertrand SIMONNET | 601ecf8 | 2014-10-06 13:14:27 -0700 | [diff] [blame] | 1 | // Copyright 2014 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 | // Wrapper around /etc/os-release and /etc/os-release.d. |
| 6 | // Standard fields can come from both places depending on how we set them. They |
| 7 | // should always be accessed through this interface. |
| 8 | |
Alex Vakulenko | fed60b0 | 2015-10-27 09:53:05 -0700 | [diff] [blame] | 9 | #ifndef LIBBRILLO_BRILLO_OSRELEASE_READER_H_ |
| 10 | #define LIBBRILLO_BRILLO_OSRELEASE_READER_H_ |
Bertrand SIMONNET | 601ecf8 | 2014-10-06 13:14:27 -0700 | [diff] [blame] | 11 | |
| 12 | #include <string> |
| 13 | |
Alex Vakulenko | 9ed0cab | 2015-10-12 15:21:28 -0700 | [diff] [blame] | 14 | #include <brillo/brillo_export.h> |
| 15 | #include <brillo/key_value_store.h> |
Bertrand SIMONNET | 601ecf8 | 2014-10-06 13:14:27 -0700 | [diff] [blame] | 16 | #include <gtest/gtest_prod.h> |
| 17 | |
Alex Vakulenko | 9ed0cab | 2015-10-12 15:21:28 -0700 | [diff] [blame] | 18 | namespace brillo { |
Bertrand SIMONNET | 601ecf8 | 2014-10-06 13:14:27 -0700 | [diff] [blame] | 19 | |
Alex Vakulenko | 9ed0cab | 2015-10-12 15:21:28 -0700 | [diff] [blame] | 20 | class BRILLO_EXPORT OsReleaseReader final { |
Bertrand SIMONNET | 601ecf8 | 2014-10-06 13:14:27 -0700 | [diff] [blame] | 21 | public: |
| 22 | // Create an empty reader |
| 23 | OsReleaseReader() = default; |
| 24 | |
| 25 | // Loads the key=value pairs from either /etc/os-release.d/<KEY> or |
| 26 | // /etc/os-release. |
Nathan Bullock | 18da777 | 2014-10-17 10:03:52 -0400 | [diff] [blame] | 27 | void Load(); |
Bertrand SIMONNET | 601ecf8 | 2014-10-06 13:14:27 -0700 | [diff] [blame] | 28 | |
| 29 | // Same as the private Load method. |
| 30 | // This need to be public so that services can use it in testing mode (for |
| 31 | // autotest tests for example). |
| 32 | // This should not be used in production so suffix it with TestingOnly to |
| 33 | // make it obvious. |
Nathan Bullock | 18da777 | 2014-10-17 10:03:52 -0400 | [diff] [blame] | 34 | void LoadTestingOnly(const base::FilePath& root_dir); |
Bertrand SIMONNET | 601ecf8 | 2014-10-06 13:14:27 -0700 | [diff] [blame] | 35 | |
| 36 | // Getter for the given key. Returns whether the key was found on the store. |
| 37 | bool GetString(const std::string& key, std::string* value) const; |
| 38 | |
| 39 | private: |
| 40 | // The map storing all the key-value pairs. |
| 41 | KeyValueStore store_; |
| 42 | |
| 43 | // os-release can be lazily loaded if need be. |
| 44 | bool initialized_; |
| 45 | |
Nathan Bullock | 18da777 | 2014-10-17 10:03:52 -0400 | [diff] [blame] | 46 | // Load the data from a given root_dir. |
Alex Vakulenko | 9ed0cab | 2015-10-12 15:21:28 -0700 | [diff] [blame] | 47 | BRILLO_PRIVATE void Load(const base::FilePath& root_dir); |
Bertrand SIMONNET | 601ecf8 | 2014-10-06 13:14:27 -0700 | [diff] [blame] | 48 | |
| 49 | DISALLOW_COPY_AND_ASSIGN(OsReleaseReader); |
| 50 | }; |
| 51 | |
Alex Vakulenko | 9ed0cab | 2015-10-12 15:21:28 -0700 | [diff] [blame] | 52 | } // namespace brillo |
Bertrand SIMONNET | 601ecf8 | 2014-10-06 13:14:27 -0700 | [diff] [blame] | 53 | |
Alex Vakulenko | fed60b0 | 2015-10-27 09:53:05 -0700 | [diff] [blame] | 54 | #endif // LIBBRILLO_BRILLO_OSRELEASE_READER_H_ |