blob: d94240f6f8e7a6bf2eb16bfac9d475b89e893467 [file] [log] [blame]
// Copyright 2022 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 <lib/async-loop/cpp/loop.h>
#include <lib/async-loop/default.h>
#include <lib/inspect/component/cpp/component.h>
#include <lib/syslog/cpp/macros.h>
#include <chrono>
#include <thread>
// [START imports]
// Import the header as if it's located in the same directory as BUILD.gn:
#include "examples/components/config/cpp/example_config.h"
// [END imports]
int main(int argc, const char* argv[], char* envp[]) {
// [START get_config]
// Retrieve configuration
auto c = example_config::Config::TakeFromStartupHandle();
// [END get_config]
// Delay our print by the configured interval.
std::this_thread::sleep_for(std::chrono::milliseconds(c.delay_ms()));
// Print greeting to the log
FX_LOGS(INFO) << "Hello, " << c.greeting() << "! (from C++)";
async::Loop loop(&kAsyncLoopConfigAttachToCurrentThread);
// [START inspect]
// Record configuration to inspect
inspect::ComponentInspector inspector(loop.dispatcher(), inspect::PublishOptions{});
inspect::Node config_node = inspector.root().CreateChild("config");
c.RecordInspect(&config_node);
// [END inspect]
loop.Run();
return 0;
}
// [END code]