-
Notifications
You must be signed in to change notification settings - Fork 78
Expand file tree
/
Copy pathconfig.h
More file actions
75 lines (57 loc) · 2.25 KB
/
config.h
File metadata and controls
75 lines (57 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Copyright 2016 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef GARNET_BIN_SYSMGR_CONFIG_H_
#define GARNET_BIN_SYSMGR_CONFIG_H_
#include <string>
#include <unordered_map>
#include <utility>
#include <fuchsia/sys/cpp/fidl.h>
#include "lib/fxl/macros.h"
#include "lib/json/json_parser.h"
#include "rapidjson/document.h"
namespace sysmgr {
// Parses configuration files. See README.md for format.
// TODO(jeffbrown): Support chaining multiple configuration files together
// via imports.
class Config {
public:
using ServiceMap =
std::unordered_map<std::string, fuchsia::sys::LaunchInfoPtr>;
using StartupServiceVector = std::vector<std::string>;
using UpdateDependencies = std::vector<std::string>;
using AppVector = std::vector<fuchsia::sys::LaunchInfoPtr>;
Config() = default;
Config(Config&&) = default;
Config& operator=(Config&&) = default;
// Initializes the Config from a config directory, merging its files together.
// Returns false if there were any errors.
bool ParseFromDirectory(const std::string& dir);
// Initializes the Config from a JSON string. |pseudo_file| is used as the
// 'file' in the error string.
bool ParseFromString(const std::string& data, const std::string& pseudo_file);
bool HasError() const;
std::string error_str() const;
ServiceMap TakeServices() { return std::move(services_); }
StartupServiceVector TakeStartupServices() {
return std::move(startup_services_);
}
UpdateDependencies TakeUpdateDependencies() {
return std::move(update_dependencies_);
}
AppVector TakeApps() { return std::move(apps_); }
private:
void ParseDocument(rapidjson::Document document);
bool ParseServiceMap(const rapidjson::Document& document,
const std::string& key, Config::ServiceMap* services);
fuchsia::sys::LaunchInfoPtr GetLaunchInfo(
const rapidjson::Document::ValueType& value, const std::string& name);
ServiceMap services_;
StartupServiceVector startup_services_;
UpdateDependencies update_dependencies_;
AppVector apps_;
json::JSONParser json_parser_;
FXL_DISALLOW_COPY_AND_ASSIGN(Config);
};
} // namespace sysmgr
#endif // GARNET_BIN_SYSMGR_CONFIG_H_