libadc-cxx 1.0.0
Structured logging for scientific computing
Loading...
Searching...
No Matches
multi_publisher.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 */
5#ifndef adc_publisher_ipp
6#define adc_publisher_ipp
7
8namespace adc {
9
10
12{
13public:
14 enum state {
16 err
17 };
18private:
19 const string vers;
20 const std::vector<string> tags;
21 enum state state;
22 int debug;
24
25public:
26 multi_publisher() : vers("1.0.0") , tags({"none"}), state(ok), debug(0) {
27 const char *env = getenv("ADC_MULTI_PUBLISHER_DEBUG");
28 if (env && !strcmp(env,"1") ) {
29 debug = 1;
30 } else {
31 debug = 0;
32 }
33 }
34
35
37 return vers;
38 }
39
40 void add(std::shared_ptr<publisher_api> p) {
41 if (!p && debug) {
42 std::cout <<
43 "multi_publisher: null publisher add ignored."
44 << std::endl;
45 }
46 pvec.push_back(p);
47 if (debug) {
48 std::cout << "publisher added: "
49 << p->name() << std::endl;
50 }
51 }
52
53 int publish(std::shared_ptr<builder_api> b)
54 {
55 if (state != ok)
56 return EBADFD;
57 int err = 0;
58 for (auto& element : pvec) {
59 int e = element->publish(b);
60 if (e) {
61 err += 1;
62 if (debug) {
63 std::cout << "publish failed (" << e <<
64 ") for plugin "
65 << element->name() << std::endl;
66 }
67 }
68 }
69 return err;
70 }
71
72 void terminate()
73 {
74 for (auto& element : pvec) {
75 element->finalize();
76 }
77 pvec.clear();
78 }
79
80 void pause()
81 {
82 for (auto& element : pvec) {
83 element->pause();
84 }
85 }
86
87 void resume()
88 {
89 for (auto& element : pvec) {
90 element->resume();
91 }
92 }
93}; // class multi_publisher
94
95} // namespace adc
96#endif // adc_multi_publisher_ipp
Interface for a group of publishers all being fed the same message(s).
void pause()
Pause all publishers.
string_view version() const
Get the version.
void add(std::shared_ptr< publisher_api > p)
Add a configured and initialized publisher.
void resume()
Resume all publishers.
void terminate()
Finalize all added publishers.
int publish(std::shared_ptr< builder_api > b)
Publish the same message to all added publishers.
std::vector< std::shared_ptr< publisher_api > > publisher_vector
list of publishers
Definition adc.hpp:82
std::string_view string_view
Definition curl.ipp:18