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#ifndef adc_publisher_ipp
2#define adc_publisher_ipp
3
4#ifdef ADC_DEBUG_MULTI_PUBLISHER
5#define multi_publisher_debug 1
6#else
7#define multi_publisher_debug 0
8#endif
9
10namespace adc {
11
12
14{
15public:
16 enum state {
18 err
19 };
20private:
21 const string vers;
22 const std::vector<string> tags;
23 enum state state;
24 int debug;
26
27public:
28 multi_publisher() : vers("1.0.0") , tags({"none"}), state(ok), debug(multi_publisher_debug) {}
29
30
32 return vers;
33 }
34
35 void add(std::shared_ptr<publisher_api> p) {
36 pvec.push_back(p);
37 }
38
39 int publish(std::shared_ptr<builder_api> b)
40 {
41 if (state != ok)
42 return EBADFD;
43 int err = 0;
44 for (auto& element : pvec) {
45 int e = element->publish(b);
46 if (e) {
47 err += 1;
48 if (debug)
49 std::cout << "publish failed for plugin "
50 << element->name() << std::endl;
51 }
52 }
53 return err;
54 }
55
56 void terminate()
57 {
58 for (auto& element : pvec) {
59 element->finalize();
60 }
61 pvec.clear();
62 }
63
64 void pause()
65 {
66 for (auto& element : pvec) {
67 element->pause();
68 }
69 }
70
71 void resume()
72 {
73 for (auto& element : pvec) {
74 element->resume();
75 }
76 }
77}; // class multi_publisher
78
79} // namespace adc
80#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
#define multi_publisher_debug
Definition adc.hpp:75
std::string_view string_view
Definition curl.ipp:14