forked from npshub/mantid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TopicInfo.cpp
76 lines (66 loc) · 2.27 KB
/
TopicInfo.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright © 2019 ISIS Rutherford Appleton Laboratory UKRI,
// NScD Oak Ridge National Laboratory, European Spallation Source,
// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
// SPDX - License - Identifier: GPL - 3.0 +
#include "MantidKernel/TopicInfo.h"
#include "MantidKernel/InstrumentInfo.h"
#include "MantidKernel/Logger.h"
#include <Poco/DOM/Element.h>
#include <utility>
namespace Mantid::Kernel {
namespace {
// static logger object
Logger g_log("TopicInfo");
std::string typeToString(TopicType type) {
switch (type) {
case TopicType::Event:
return "Event";
case TopicType::Monitor:
return "Monitor";
case TopicType::Sample:
return "Sample";
case TopicType::Chopper:
return "Chopper";
case TopicType::Run:
return "Run";
default:
return "unspecified";
}
}
} // namespace
TopicInfo::TopicInfo(InstrumentInfo *inst, const Poco::XML::Element *elem) {
m_name = elem->getAttribute("name");
if (m_name.empty())
g_log.warning() << "Kafka topic provided without a suitable name for instrument " << inst->name()
<< ". No attempts will be made to connect to this topic." << std::endl;
std::string type = elem->getAttribute("type");
if (type == "event")
m_type = TopicType::Event;
else if (type == "chopper")
m_type = TopicType::Chopper;
else if (type == "sample")
m_type = TopicType::Sample;
else if (type == "run")
m_type = TopicType::Run;
else if (type == "monitor")
m_type = TopicType::Monitor;
else
g_log.warning() << "Kafka topic provided without a suitable type for instrument " << inst->name()
<< ". No attempts will be made to connect to this topic." << std::endl;
}
TopicInfo::TopicInfo(std::string name, TopicType type) : m_name(std::move(name)), m_type(type) {}
/**
* Prints the listener to the stream.
*
* @param buffer :: A reference to an output stream
* @param topic :: A reference to a TopicInfo object
* @return A reference to the stream written to
*/
std::ostream &operator<<(std::ostream &buffer, const TopicInfo &topic) {
buffer << topic.name() << "(" << typeToString(topic.type()) << ", "
<< ")";
return buffer;
}
} // namespace Mantid::Kernel