blob: 4c3d1c0eb7b3655a9531c9236812fb13bbf6293f [file] [log] [blame]
// Copyright 2018 The Chromium OS 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 <memory>
#include <string>
#include <base/macros.h>
#include <base/values.h>
#include "chromeos-config/libcros_config/cros_config_impl.h"
#include "chromeos-config/libcros_config/identity.h"
#include "chromeos-config/libcros_config/identity_arm.h"
#include "chromeos-config/libcros_config/identity_x86.h"
namespace base {
class FilePath;
} // namespace base
namespace brillo {
// JSON implementation of model configuration
class CrosConfigJson : public CrosConfigImpl {
static constexpr char kRootName[] = "chromeos";
static constexpr char kConfigListName[] = "configs";
CrosConfigJson(const CrosConfigJson&) = delete;
CrosConfigJson& operator=(const CrosConfigJson&) = delete;
~CrosConfigJson() override;
// CrosConfigInterface:
bool GetString(const std::string& path,
const std::string& prop,
std::string* val_out) override;
bool GetDeviceIndex(int* device_index_out) override;
// CrosConfigImpl:
bool SelectConfigByIdentity(const CrosConfigIdentity& identity) override;
bool ReadConfigFile(const base::FilePath& filepath) override;
// Helper used by SelectConfigByIdentity
// @identity: The identity to match
// @return: true on success, false otherwise
bool SelectConfigByIdentityInternal(const CrosConfigIdentity& identity);
base::Value json_config_;
// Owned by json_config_
const base::Value* config_dict_; // Root of configs
int device_index_;
} // namespace brillo