blob: 348120a0f666b6545fc829008473fc9a7ea485a9 [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();
Ben Chan42065c52013-06-14 17:41:10 -070028 virtual ~ConfigLoader();
Ben Chanc46c4552013-06-10 18:55:13 -070029
Ben Chan866571e2013-06-12 18:06:20 -070030 // Loads the default configuration. Returns true on success.
Ben Chan42065c52013-06-14 17:41:10 -070031 virtual bool LoadDefaultConfig();
Ben Chan866571e2013-06-12 18:06:20 -070032
Ben Chanc46c4552013-06-10 18:55:13 -070033 // Loads a configuration from |config_file|. Returns true on success.
Ben Chan42065c52013-06-14 17:41:10 -070034 virtual bool LoadConfig(const base::FilePath& config_file);
Ben Chanc46c4552013-06-10 18:55:13 -070035
36 // Returns the info of the USB modem with its vendor ID equal to |vendor_id|
37 // and its product ID equal to |product_id| from the loaded configuration.
38 // Returns NULL if no matching USB modem is found. The returned UsbModemInfo
39 // object becomes invalid, and thus should not be held, beyond the lifetime
40 // of the loaded configuration held by |config_|.
Ben Chan956f79b2014-08-06 17:11:01 -070041 virtual const UsbModemInfo* GetUsbModemInfo(uint16_t vendor_id,
42 uint16_t product_id) const;
Ben Chanc46c4552013-06-10 18:55:13 -070043
44 private:
45 FRIEND_TEST(ConfigLoaderTest, GetUsbModemInfo);
46 FRIEND_TEST(ConfigLoaderTest, LoadEmptyConfigFile);
47 FRIEND_TEST(ConfigLoaderTest, LoadInvalidConfigFile);
48 FRIEND_TEST(ConfigLoaderTest, LoadNonExistentConfigFile);
49 FRIEND_TEST(ConfigLoaderTest, LoadValidConfigFile);
50
Ben Chanb9087322014-08-25 16:37:43 -070051 std::unique_ptr<Config> config_;
Ben Chanc46c4552013-06-10 18:55:13 -070052
53 DISALLOW_COPY_AND_ASSIGN(ConfigLoader);
54};
55
56} // namespace mist
57
58#endif // MIST_CONFIG_LOADER_H_