blob: 9ee2f281261154ab785a2c2663f66d6dbec3e74c [file] [log] [blame]
Ben Chanc46c4552013-06-10 18:55:13 -07001// 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 Chan956f79b2014-08-06 17:11:01 -07008#include <stdint.h>
9
Ben Chanb9087322014-08-25 16:37:43 -070010#include <memory>
11
Ben Chandcc0c7a2014-02-05 18:03:39 -080012#include <base/files/file_path.h>
Ben Chan4746c8a2014-09-02 20:34:58 -070013#include <base/macros.h>
Ben Chanc46c4552013-06-10 18:55:13 -070014#include <gtest/gtest_prod.h>
15
16namespace mist {
17
18class Config;
19class 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.
25class ConfigLoader {
26 public:
27 ConfigLoader();
Qijiang Fan6bc59e12020-11-11 02:51:06 +090028 ConfigLoader(const ConfigLoader&) = delete;
29 ConfigLoader& operator=(const ConfigLoader&) = delete;
30
Ben Chan42065c52013-06-14 17:41:10 -070031 virtual ~ConfigLoader();
Ben Chanc46c4552013-06-10 18:55:13 -070032
Ben Chan866571e2013-06-12 18:06:20 -070033 // Loads the default configuration. Returns true on success.
Ben Chan42065c52013-06-14 17:41:10 -070034 virtual bool LoadDefaultConfig();
Ben Chan866571e2013-06-12 18:06:20 -070035
Ben Chanc46c4552013-06-10 18:55:13 -070036 // Loads a configuration from |config_file|. Returns true on success.
Ben Chan42065c52013-06-14 17:41:10 -070037 virtual bool LoadConfig(const base::FilePath& config_file);
Ben Chanc46c4552013-06-10 18:55:13 -070038
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 Chan956f79b2014-08-06 17:11:01 -070044 virtual const UsbModemInfo* GetUsbModemInfo(uint16_t vendor_id,
45 uint16_t product_id) const;
Ben Chanc46c4552013-06-10 18:55:13 -070046
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 Chanb9087322014-08-25 16:37:43 -070054 std::unique_ptr<Config> config_;
Ben Chanc46c4552013-06-10 18:55:13 -070055};
56
57} // namespace mist
58
59#endif // MIST_CONFIG_LOADER_H_