libadc-cxx 1.0.0
Structured logging for scientific computing
Loading...
Searching...
No Matches
libadiak_many.ipp
Go to the documentation of this file.
1/* Copyright 2025 NTESS. See the top-level LICENSE.txt file for details.
2 *
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
7#include <cstdlib>
8#include "adiak.hpp"
9#if 0
10#include <iostream>
11#include <fstream>
12#include <filesystem>
13#endif
14
15namespace adc {
16
18{
19 scalar_type result;
20 // fixme ; implement adc::adiak_type_to_adc_type(adiak_type_t)
21 return result;
22}
23
24// see also
25// Adiak/tools/adc-single
26
27/*! \brief Terminal output publisher_api implementation.
28 This plugin sends messages to libadiak synchronously.
29 Multiple independent instances of this plugin may be used simultaneously,
30 but message integrity depends on the behavior of libadiak_many.
31 As of 6/2025, adiak objects assume the caller is single-threaded.
32 */
34 enum state {
35 ok,
36 err
37 };
38
39private:
40 const std::string vers;
41 const std::vector<std::string> tags;
42 enum state state;
43 bool paused;
44 std::string separator;
45
46 inline static const char *adc_libadiak_many_plugin_separator_default = "/";
47 const std::map< const string, const string > plugin_config_defaults =
48 {
49 {"SEPARATOR", adc_libadiak_many_plugin_separator_default}
50 };
51 inline static const char *plugin_prefix = "ADC_ADIAK_MANY_PLUGIN_";
52
53 void write_adiak(std::string_view sv, const field& f)
54 {
55 // is there an adiak context we should have created here?
56 // f.kt (none, section, value), f.st f.vp f.count
57 // fixme: pending adiak api changes; libadiak_many_plugin::write_adiak
58 // something like adiak::value(av,
59 // adiak_type_to_adc_type ( f.st),
60 // f.vp, f.count);
61 }
62
63 void walk_builder(std::string name, std::shared_ptr<builder_api> b)
64 {
65 // walk fields
66 std::vector<std::string> fnames = b->get_field_names();
67 for (auto& n : fnames) {
68 field f = b->get_value(n);
69 std::string prefix = name + "/" + n;
70 write_adiak(prefix, f);
71 }
72 // walk sections
73 std::vector<std::string> names = b->get_section_names();
74 for (auto& n : names) {
75 std::string prefix = name + "/" + n;
76 walk_builder(prefix, b->get_section(n));
77 }
78 }
79
80 int config(std::string sep)
81 {
82 separator = sep;
83 return 0;
84 }
85
86 // find field in m, then with prefix in env, then the default.
87 const string get(const std::map< string, string >& m,
88 string fieldname, string_view env_prefix) {
89 // fields not defined in config_defaults raise an exception.
90 auto it = m.find(fieldname);
91 if (it != m.end()) {
92 return it->second;
93 }
94 string en = string(env_prefix) += fieldname;
95 char *ec = getenv(en.c_str());
96 if (!ec) {
97 return plugin_config_defaults.at(fieldname);
98 } else {
99 return string(ec);
100 }
101 }
102
103public:
104 libadiak_many_plugin() : vers("1.0.0") , tags({"none"}), state(ok), paused(false) {
105 std::cout << "Constructing libadiak_many_plugin" << std::endl;
106 separator = adc_libadiak_many_plugin_separator_default;
107 }
108
109 int publish(std::shared_ptr<builder_api> b) {
110 if (paused)
111 return 0;
112 if (state != ok)
113 return 1;
114 walk_builder("adc", b);
115 return 0;
116 }
117
118 int config(const std::map< std::string, std::string >& m) {
119 string prog = get(m, "SEPARATOR", plugin_prefix);
120 return 0;
121 }
122
123 int config(const std::map< std::string, std::string >& m, std::string_view env_prefix) {
124 string prog = get(m, "SEPARATOR", env_prefix);
125 return 0;
126 }
127
128 const std::map< const std::string, const std::string> & get_option_defaults() {
129 return plugin_config_defaults;
130 }
131
133 return 0;
134 }
135
136 void finalize() {
137 }
138
139 void pause() {
140 paused = true;
141 }
142
143 void resume() {
144 paused = false;
145 }
146
147 std::string_view name() const {
148 return "libadiak_many";
149 }
150
151 std::string_view version() const {
152 return vers;
153 }
154
156 std::cout << "Destructing libadiak_many_plugin" << std::endl;
157 }
158};
159
160
161} // adc
Terminal output publisher_api implementation. This plugin sends messages to libadiak synchronously....
const std::map< const std::string, const std::string > & get_option_defaults()
Look up the settable options and their defaults.
void finalize()
Stop publishing and release any resources held for managing publication.
int publish(std::shared_ptr< builder_api > b)
Publish the content of the builder.
std::string_view version() const
void resume()
Resume publishing Duplicate calls are allowed.
int config(const std::map< std::string, std::string > &m, std::string_view env_prefix)
Configure the plugin with the options given and the corresponding environment variables.
int initialize()
Ready the plugin to publish following the configuration options set or defaulted.
int config(const std::map< std::string, std::string > &m)
Configure the plugin with the options given.
void pause()
Pause publishing until a call to resume. Duplicate calls are allowed.
std::string_view name() const
Publisher plugin interface.
Definition publisher.hpp:48
scalar_type
field types for scientific data encode/decode with json.
Definition types.hpp:62
Definition adc.hpp:82
std::string_view string_view
Definition curl.ipp:18
std::string string
Definition curl.ipp:17
scalar_type adiak_type_to_adc_type(adiak_type_t at)