Ben Chan | c46c455 | 2013-06-10 18:55:13 -0700 | [diff] [blame] | 1 | // Copyright (c) 2013 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 | #ifndef MIST_CONFIG_LOADER_H_ |
| 6 | #define MIST_CONFIG_LOADER_H_ |
| 7 | |
Ben Chan | 956f79b | 2014-08-06 17:11:01 -0700 | [diff] [blame] | 8 | #include <stdint.h> |
| 9 | |
Ben Chan | b908732 | 2014-08-25 16:37:43 -0700 | [diff] [blame] | 10 | #include <memory> |
| 11 | |
Ben Chan | dcc0c7a | 2014-02-05 18:03:39 -0800 | [diff] [blame] | 12 | #include <base/files/file_path.h> |
Ben Chan | 4746c8a | 2014-09-02 20:34:58 -0700 | [diff] [blame] | 13 | #include <base/macros.h> |
Ben Chan | c46c455 | 2013-06-10 18:55:13 -0700 | [diff] [blame] | 14 | #include <gtest/gtest_prod.h> |
| 15 | |
| 16 | namespace mist { |
| 17 | |
| 18 | class Config; |
| 19 | class UsbModemInfo; |
| 20 | |
| 21 | // A configuration file loader, which loads information about USB modems |
| 22 | // supported by mist from a configuration file based on the text format of |
| 23 | // protocol buffers. The protocol buffers for the configuration file are defined |
| 24 | // in proto/*.proto. |
| 25 | class ConfigLoader { |
| 26 | public: |
| 27 | ConfigLoader(); |
Qijiang Fan | 6bc59e1 | 2020-11-11 02:51:06 +0900 | [diff] [blame] | 28 | ConfigLoader(const ConfigLoader&) = delete; |
| 29 | ConfigLoader& operator=(const ConfigLoader&) = delete; |
| 30 | |
Ben Chan | 42065c5 | 2013-06-14 17:41:10 -0700 | [diff] [blame] | 31 | virtual ~ConfigLoader(); |
Ben Chan | c46c455 | 2013-06-10 18:55:13 -0700 | [diff] [blame] | 32 | |
Ben Chan | 866571e | 2013-06-12 18:06:20 -0700 | [diff] [blame] | 33 | // Loads the default configuration. Returns true on success. |
Ben Chan | 42065c5 | 2013-06-14 17:41:10 -0700 | [diff] [blame] | 34 | virtual bool LoadDefaultConfig(); |
Ben Chan | 866571e | 2013-06-12 18:06:20 -0700 | [diff] [blame] | 35 | |
Ben Chan | c46c455 | 2013-06-10 18:55:13 -0700 | [diff] [blame] | 36 | // Loads a configuration from |config_file|. Returns true on success. |
Ben Chan | 42065c5 | 2013-06-14 17:41:10 -0700 | [diff] [blame] | 37 | virtual bool LoadConfig(const base::FilePath& config_file); |
Ben Chan | c46c455 | 2013-06-10 18:55:13 -0700 | [diff] [blame] | 38 | |
| 39 | // Returns the info of the USB modem with its vendor ID equal to |vendor_id| |
| 40 | // and its product ID equal to |product_id| from the loaded configuration. |
| 41 | // Returns NULL if no matching USB modem is found. The returned UsbModemInfo |
| 42 | // object becomes invalid, and thus should not be held, beyond the lifetime |
| 43 | // of the loaded configuration held by |config_|. |
Ben Chan | 956f79b | 2014-08-06 17:11:01 -0700 | [diff] [blame] | 44 | virtual const UsbModemInfo* GetUsbModemInfo(uint16_t vendor_id, |
| 45 | uint16_t product_id) const; |
Ben Chan | c46c455 | 2013-06-10 18:55:13 -0700 | [diff] [blame] | 46 | |
| 47 | private: |
| 48 | FRIEND_TEST(ConfigLoaderTest, GetUsbModemInfo); |
| 49 | FRIEND_TEST(ConfigLoaderTest, LoadEmptyConfigFile); |
| 50 | FRIEND_TEST(ConfigLoaderTest, LoadInvalidConfigFile); |
| 51 | FRIEND_TEST(ConfigLoaderTest, LoadNonExistentConfigFile); |
| 52 | FRIEND_TEST(ConfigLoaderTest, LoadValidConfigFile); |
| 53 | |
Ben Chan | b908732 | 2014-08-25 16:37:43 -0700 | [diff] [blame] | 54 | std::unique_ptr<Config> config_; |
Ben Chan | c46c455 | 2013-06-10 18:55:13 -0700 | [diff] [blame] | 55 | }; |
| 56 | |
| 57 | } // namespace mist |
| 58 | |
| 59 | #endif // MIST_CONFIG_LOADER_H_ |