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