blob: 32f77d345375fb7e6ed4ce572c82a4828eca6d89 [file] [log] [blame]
// Copyright 2022 The Flutter 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 <lib/sys/inspect/cpp/component.h>
#include <memory>
#include <mutex>
namespace dart_utils {
// This singleton object offers a way to create a new inspect node under the
// root node in a thread safe way.
// Usage notes:
// RootInspectNode::Initialize() must be invoked once in the program's
// main before trying to obtain a child node.
class RootInspectNode {
RootInspectNode() = default;
~RootInspectNode() = default;
// Initializes the underlying component inspector. Must be invoked at least
// once before calling CreateRootChild().
static void Initialize(sys::ComponentContext* context);
// Creates an inspect node which is a child of the component's root inspect
// node with the provided |name|.
static inspect::Node CreateRootChild(const std::string& name);
// Gets an instance to the component's inspector.
static inspect::Inspector* GetInspector();
static std::unique_ptr<sys::ComponentInspector> inspector_;
static std::mutex mutex_;
} // namespace dart_utils