libadc-cxx 1.0.0
Structured logging for scientific computing
Loading...
Searching...
No Matches
publisher.hpp
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 */
5#ifndef adc_publisher_hpp
6#define adc_publisher_hpp
7#include <string>
8#include <iostream>
9#include <sstream>
10#include <map>
11#include <memory>
12#include "adc/types.hpp"
14
15namespace adc {
16
17/** \addtogroup API
18 * @{
19 */
20
21
22/**
23 * Get the default processor affinity list.
24 * This may be useful to publishers that spawn processes.
25 */
26std::string get_default_affinity();
27
28inline version publisher_api_version("1.0.0", {"none"});
29
30/*! \brief Publisher plugin interface.
31
32Life-cycle of a plugin:
33- p is created by a call to the factory. (there may be more than one instance per name).
34- p->config is called 0 or 1 times (plugins must have reasonable default behavior).
35- p->initialize is called exactly once
36- p->publish is called 0 or more times
37 - optionally, to enable dynamic application control of enabled logging:
38 - p->pause is called to suppress emissions from subsequent calls to p->publish.
39 - p->resume is called to unsuppress emissions from subsequent calls to p->publish.
40- p->finalize is called.
41
42A publisher object should not be assumed thread-safe. In particular,
43there may be conflicts among config/initialize/publish/finalize calls
44across multiple threads. Publishers which are thread-safe will document
45that fact individually.
46*/
47class ADC_VISIBLE publisher_api
48{
49public:
50 virtual ~publisher_api() {};
51 /// \return the name of the plugin
52 virtual std::string_view name() const = 0;
53
54 /// \return the version of the plugin (should follow semantic versioning practices)
55 virtual std::string_view version() const = 0;
56
57 /// \brief Publish the content of the builder
58 ///
59 /// \param b converted to a single json object and published
60 virtual int publish(std::shared_ptr<builder_api> b) = 0;
61
62 /// \brief Configure the plugin with the options given.
63 /// \param m a map with keys documented in the plugin-specific header.
64 ///
65 /// For plugin QQQ, Environment variables ADC_QQQ_PLUGIN_* will override the source code
66 /// default for any key not defined in m. Here QQQ is the uppercase version of the
67 /// plugin name.
68 virtual int config(const std::map< std::string, std::string >& m) = 0;
69
70 /// \brief Configure the plugin with the options given and the corresponding environment variables.
71 /// \param m a map with keys documented in the plugin-specific header.
72 /// \param env_prefix is prepended to the expected keys for the plugin
73 /// and values found with getenv that match are used, overriding elements of m.
74 /// Typically, env_prefix will be PPP_ADC_QQQ_PLUGIN_ if application PPP wants to
75 /// override the defaults of plugin QQQ. Here QQQ is the uppercase version of the
76 /// plugin name.
77 virtual int config(const std::map< std::string, std::string >& m, std::string_view env_prefix) = 0;
78
79 /// \brief Look up the settable options and their defaults.
80 ///
81 /// Some plugins without options will return an empty map.
82 virtual const std::map< const std::string, const std::string> & get_option_defaults() = 0;
83
84 /// \brief Ready the plugin to publish following the configuration options set or defaulted.
85 virtual int initialize() = 0; // TODO: add void* mpi_comm_p=NULL arg?
86
87 /// \brief Stop publishing and release any resources held for managing publication.
88 virtual void finalize() = 0;
89
90 /// \brief Pause publishing until a call to resume.
91 /// Duplicate calls are allowed.
92 virtual void pause() = 0;
93
94 /// \brief Resume publishing
95 /// Duplicate calls are allowed.
96 virtual void resume() = 0;
97
98};
99
100/// \brief name/plugin map.
101typedef std::map< const std::string, std::shared_ptr<publisher_api> > plugin_map;
102
103/// \brief list of publishers
104typedef std::vector< std::shared_ptr<publisher_api> > publisher_vector;
105
106/// \brief named publisher
107typedef std::pair<std::string, std::shared_ptr<publisher_api> > pair_string_publisher_api;
108
109/** @}*/
110
111} // namespace adc
112#endif // adc_publisher_hpp
Publisher plugin interface.
Definition publisher.hpp:48
virtual std::string_view name() const =0
virtual std::string_view version() const =0
virtual ~publisher_api()
Definition publisher.hpp:50
virtual void pause()=0
Pause publishing until a call to resume. Duplicate calls are allowed.
virtual int publish(std::shared_ptr< builder_api > b)=0
Publish the content of the builder.
virtual int config(const std::map< std::string, std::string > &m, std::string_view env_prefix)=0
Configure the plugin with the options given and the corresponding environment variables.
virtual int initialize()=0
Ready the plugin to publish following the configuration options set or defaulted.
virtual void finalize()=0
Stop publishing and release any resources held for managing publication.
virtual void resume()=0
Resume publishing Duplicate calls are allowed.
virtual int config(const std::map< std::string, std::string > &m)=0
Configure the plugin with the options given.
virtual const std::map< const std::string, const std::string > & get_option_defaults()=0
Look up the settable options and their defaults.
std::string get_default_affinity()
Definition builder.ipp:112
std::vector< std::shared_ptr< publisher_api > > publisher_vector
list of publishers
std::map< const std::string, std::shared_ptr< publisher_api > > plugin_map
name/plugin map.
std::pair< std::string, std::shared_ptr< publisher_api > > pair_string_publisher_api
named publisher
version publisher_api_version("1.0.0", {"none"})
Definition adc.hpp:82
A version with tags list.
Definition types.hpp:28