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