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