blob: dd289abb5e79ebbf5c16ee16565d1ca7ed7ff192 [file] [log] [blame]
// Copyright 2018 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.
#include <string>
#include <unordered_map>
#include <fbl/unique_fd.h>
#include "src/lib/fxl/macros.h"
#include "src/lib/json_parser/json_parser.h"
namespace component {
// Represents a mapping from file scheme to component type. Generated from
// scheme_map configuration file.
class SchemeMap {
SchemeMap() = default;
// Parses a scheme map from a directory containing scheme map config files.
// Each file adds more scheme->launcher mappings.
bool ParseFromDirectory(const std::string& path);
// Like |ParseFromDirectory|, but with a path relative to an open directory,
// rather than relative to an implicit working directory.
bool ParseFromDirectoryAt(fbl::unique_fd& dir, const std::string& path);
bool HasError() const { return json_parser_.HasError(); }
std::string error_str() const { return json_parser_.error_str(); }
// Returns the launcher type for a given scheme, or "" if none.
std::string LookUp(const std::string& scheme) const;
static const char kConfigDirPath[];
void ParseDocument(rapidjson::Document document);
std::unordered_map<std::string, std::string> internal_map_;
json::JSONParser json_parser_;
} // namespace component