libadc-cxx 1.0.0
Structured logging for scientific computing
Loading...
Searching...
No Matches
adcHelloWorldAuto.cpp
Go to the documentation of this file.
1/* Copyright 2026 NTESS. See the top-level LICENSE.txt file for details.
2 *
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5#include "adc/factory.hpp"
6#include <cstring>
7#include <cerrno>
8#include <limits>
9
10/*! \file adcHelloWorldAuto.cpp
11 * This demonstrates using the adc::factory API to build and publish a message.
12 * The message sent includes the bare minimum, plus hello world.
13 * This exammple captures the case where control of publication methods is deferred to
14 * the application environment variables seen at runtime.
15 */
16
17/** \addtogroup examples
18 * @{
19 */
20
21namespace adc_examples {
22namespace adcHelloWorldAuto {
23
24/**
25 * \brief adc c++ hello world without hard-coded publisher choices.
26 */
27int main(int /* argc */, char ** /* argv */) {
28 std::cout << "adc pub version: " << adc::publisher_api_version.name << std::endl;
29 std::cout << "adc builder version: " << adc::builder_api_version.name << std::endl;
30 std::cout << "adc enum version: " << adc::enum_version.name << std::endl;
31
32 // create a factory
34
35 // create a message and add header
36 std::shared_ptr< adc::builder_api > b = f.get_builder();
37 b->add_header_section("cxx_demo_1");
38
39 // add an application-defined payload to the message
40 auto app_data = f.get_builder();
41 app_data->add("hello", "world");
42 b->add_app_data_section(app_data);
43
44 // could add lots of other sections, as needed.
45
46 std::cout << "Available publishers are: ";
47 for (auto n : f.get_publisher_names()) {
48 std::cout << " " << n;
49 }
50 std::cout << std::endl;
51
52 // create publishers following runtime environment variables and defaults
53 auto mp = f.get_multi_publisher_from_env("");
54
55 // send built message b to all publishers found as default configured
56 int err = mp->publish(b);
57 if (err) {
58 std::cout << "got " << err << " publication errors." << std::endl;
59 }
60
61 // clean up all publishers
62 mp->terminate();
63
64 return 0;
65}
66
67} // adcHelloWorldAuto
68} // adc_examples
69
70/** @}*/
71/** @}*/
72
73int main(int argc, char **argv)
74{
76}
int main(int argc, char **argv)
provides publishers and builders of application metadata.
Definition factory.hpp:34
const std::set< std::string > & get_publisher_names()
Definition factory.ipp:294
std::shared_ptr< multi_publisher_api > get_multi_publisher_from_env(const std::string &env_name)
Definition factory.ipp:121
std::shared_ptr< builder_api > get_builder()
Definition factory.ipp:300
version enum_version("1.0.0", {"none"})
the version number of enum scalar_type and object_type
version publisher_api_version("1.0.0", {"none"})
version builder_api_version("1.0.0", {"none"})
int main(int, char **)
adc c++ hello world without hard-coded publisher choices.
const std::string name
Definition types.hpp:29