Directory: | ./ |
---|---|
File: | pdserv/src/msrproto/Event.cpp |
Date: | 2025-08-17 04:10:43 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 51 | 67 | 76.1% |
Branches: | 80 | 190 | 42.1% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | /***************************************************************************** | ||
2 | * | ||
3 | * Copyright 2010-2019 Richard Hacker (lerichi at gmx dot net) | ||
4 | * | ||
5 | * This file is part of the pdserv library. | ||
6 | * | ||
7 | * The pdserv library is free software: you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU Lesser General Public License as published | ||
9 | * by the Free Software Foundation, either version 3 of the License, or (at | ||
10 | * your option) any later version. | ||
11 | * | ||
12 | * The pdserv library is distributed in the hope that it will be useful, but | ||
13 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | ||
14 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public | ||
15 | * License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU Lesser General Public License | ||
18 | * along with the pdserv library. If not, see <http://www.gnu.org/licenses/>. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | #include "Session.h" | ||
23 | #include "Event.h" | ||
24 | #include "XmlElement.h" | ||
25 | |||
26 | using namespace MsrProto; | ||
27 | |||
28 | ///////////////////////////////////////////////////////////////////////////// | ||
29 | 9632 | bool Event::toXml(Session* session, const PdServ::EventData& eventData, | |
30 | XmlElement* parent) | ||
31 | { | ||
32 | 9632 | const PdServ::Event* event = eventData.event; | |
33 | |||
34 |
2/2✓ Branch 0 taken 48 times.
✓ Branch 1 taken 9584 times.
|
9632 | if (event) { |
35 | const char* tag = | ||
36 |
5/8✗ Branch 1 not taken.
✓ Branch 2 taken 48 times.
✓ Branch 3 taken 29 times.
✓ Branch 4 taken 19 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 29 times.
✓ Branch 9 taken 29 times.
✗ Branch 10 not taken.
|
48 | eventData.state ? getTagName(eventData.priority) : "reset"; |
37 | 48 | XmlElement msg( | |
38 | parent ? parent->createChild(tag) : | ||
39 |
4/6✓ Branch 0 taken 18 times.
✓ Branch 1 taken 30 times.
✓ Branch 3 taken 18 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 30 times.
✗ Branch 7 not taken.
|
96 | session->createElement(tag)); |
40 | |||
41 |
2/4✓ Branch 2 taken 48 times.
✗ Branch 3 not taken.
✓ Branch 7 taken 48 times.
✗ Branch 8 not taken.
|
48 | XmlElement::Attribute(msg, "name").setEscaped(event->path); |
42 |
2/2✓ Branch 2 taken 29 times.
✓ Branch 3 taken 19 times.
|
48 | if (event->nelem() > 1) |
43 |
2/4✓ Branch 2 taken 29 times.
✗ Branch 3 not taken.
✓ Branch 7 taken 29 times.
✗ Branch 8 not taken.
|
29 | XmlElement::Attribute(msg, "index") << eventData.index; |
44 |
2/4✓ Branch 2 taken 48 times.
✗ Branch 3 not taken.
✓ Branch 7 taken 48 times.
✗ Branch 8 not taken.
|
48 | XmlElement::Attribute(msg, "seq") << eventData.seqNo; |
45 |
3/4✗ Branch 1 not taken.
✓ Branch 2 taken 48 times.
✓ Branch 3 taken 29 times.
✓ Branch 4 taken 19 times.
|
48 | if (eventData.state) |
46 |
1/2✓ Branch 1 taken 29 times.
✗ Branch 2 not taken.
|
58 | XmlElement::Attribute(msg, "prio") |
47 |
3/6✗ Branch 4 not taken.
✓ Branch 5 taken 29 times.
✓ Branch 7 taken 29 times.
✗ Branch 8 not taken.
✓ Branch 11 taken 29 times.
✗ Branch 12 not taken.
|
58 | << getPrioInt(eventData.priority); |
48 |
2/4✓ Branch 2 taken 48 times.
✗ Branch 3 not taken.
✓ Branch 7 taken 48 times.
✗ Branch 8 not taken.
|
48 | XmlElement::Attribute(msg, "time") << eventData.time; |
49 |
3/4✗ Branch 1 not taken.
✓ Branch 2 taken 48 times.
✓ Branch 3 taken 29 times.
✓ Branch 4 taken 19 times.
|
96 | if (eventData.state |
50 |
3/4✓ Branch 0 taken 29 times.
✓ Branch 1 taken 19 times.
✓ Branch 7 taken 29 times.
✗ Branch 8 not taken.
|
48 | and not event->messages[eventData.index].empty()) |
51 |
1/2✓ Branch 1 taken 29 times.
✗ Branch 2 not taken.
|
58 | XmlElement::Attribute(msg, "text") |
52 |
1/2✓ Branch 7 taken 29 times.
✗ Branch 8 not taken.
|
58 | .setEscaped(event->messages[eventData.index]); |
53 | } | ||
54 | |||
55 | 9632 | return event; | |
56 | } | ||
57 | |||
58 | ///////////////////////////////////////////////////////////////////////////// | ||
59 | 29 | const char *Event::getTagName(PdServ::Event::Priority priority) | |
60 | { | ||
61 | ✗ | struct Map: std::map<PdServ::Event::Priority, const char*> { | |
62 | 14 | Map() { | |
63 | 14 | const char* crit_error = "crit_error"; | |
64 | 14 | const char* error = "error"; | |
65 | 14 | const char* warn = "warn"; | |
66 | 14 | const char* info = "info"; | |
67 | |||
68 |
2/4✓ Branch 5 taken 14 times.
✗ Branch 6 not taken.
✓ Branch 9 taken 14 times.
✗ Branch 10 not taken.
|
14 | insert(std::make_pair(PdServ::Event::Emergency, crit_error)); |
69 |
2/4✓ Branch 5 taken 14 times.
✗ Branch 6 not taken.
✓ Branch 9 taken 14 times.
✗ Branch 10 not taken.
|
14 | insert(std::make_pair(PdServ::Event::Alert, crit_error)); |
70 |
2/4✓ Branch 5 taken 14 times.
✗ Branch 6 not taken.
✓ Branch 9 taken 14 times.
✗ Branch 10 not taken.
|
14 | insert(std::make_pair(PdServ::Event::Critical, crit_error)); |
71 |
2/4✓ Branch 5 taken 14 times.
✗ Branch 6 not taken.
✓ Branch 9 taken 14 times.
✗ Branch 10 not taken.
|
14 | insert(std::make_pair(PdServ::Event::Error, error)); |
72 |
2/4✓ Branch 5 taken 14 times.
✗ Branch 6 not taken.
✓ Branch 9 taken 14 times.
✗ Branch 10 not taken.
|
14 | insert(std::make_pair(PdServ::Event::Warning, warn)); |
73 |
2/4✓ Branch 5 taken 14 times.
✗ Branch 6 not taken.
✓ Branch 9 taken 14 times.
✗ Branch 10 not taken.
|
14 | insert(std::make_pair(PdServ::Event::Notice, info)); |
74 |
2/4✓ Branch 5 taken 14 times.
✗ Branch 6 not taken.
✓ Branch 9 taken 14 times.
✗ Branch 10 not taken.
|
14 | insert(std::make_pair(PdServ::Event::Info, info)); |
75 |
2/4✓ Branch 5 taken 14 times.
✗ Branch 6 not taken.
✓ Branch 9 taken 14 times.
✗ Branch 10 not taken.
|
14 | insert(std::make_pair(PdServ::Event::Debug, info)); |
76 | 14 | } | |
77 | }; | ||
78 | |||
79 |
4/8✓ Branch 0 taken 14 times.
✓ Branch 1 taken 15 times.
✓ Branch 3 taken 14 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 14 times.
✗ Branch 7 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
|
29 | static const Map map; |
80 | |||
81 |
1/2✓ Branch 2 taken 29 times.
✗ Branch 3 not taken.
|
58 | Map::const_iterator it = map.find(priority); |
82 |
1/2✓ Branch 4 taken 29 times.
✗ Branch 5 not taken.
|
58 | return it != map.end() ? it->second : "message"; |
83 | } | ||
84 | |||
85 | ///////////////////////////////////////////////////////////////////////////// | ||
86 | ✗ | const char *Event::getPrioStr(PdServ::Event::Priority priority) | |
87 | { | ||
88 | ✗ | struct Map: std::map<PdServ::Event::Priority, const char*> { | |
89 | ✗ | Map() { | |
90 | ✗ | insert(std::make_pair(PdServ::Event::Emergency, "emergency")); | |
91 | ✗ | insert(std::make_pair(PdServ::Event::Alert, "alert")); | |
92 | ✗ | insert(std::make_pair(PdServ::Event::Critical, "critical")); | |
93 | ✗ | insert(std::make_pair(PdServ::Event::Error, "error")); | |
94 | ✗ | insert(std::make_pair(PdServ::Event::Warning, "warning")); | |
95 | ✗ | insert(std::make_pair(PdServ::Event::Notice, "notice")); | |
96 | ✗ | insert(std::make_pair(PdServ::Event::Info, "info")); | |
97 | ✗ | insert(std::make_pair(PdServ::Event::Debug, "debug")); | |
98 | } | ||
99 | }; | ||
100 | ✗ | static const Map map; | |
101 | |||
102 | ✗ | Map::const_iterator it = map.find(priority); | |
103 | ✗ | return it != map.end() ? it->second : "unknown"; | |
104 | } | ||
105 | |||
106 | ///////////////////////////////////////////////////////////////////////////// | ||
107 | 29 | int Event::getPrioInt(PdServ::Event::Priority priority) | |
108 | { | ||
109 | ✗ | struct Map: std::map<PdServ::Event::Priority, int> { | |
110 | 14 | Map() { | |
111 |
2/4✓ Branch 7 taken 14 times.
✗ Branch 8 not taken.
✓ Branch 11 taken 14 times.
✗ Branch 12 not taken.
|
14 | insert(std::make_pair(PdServ::Event::Emergency, 0)); |
112 |
2/4✓ Branch 7 taken 14 times.
✗ Branch 8 not taken.
✓ Branch 11 taken 14 times.
✗ Branch 12 not taken.
|
14 | insert(std::make_pair(PdServ::Event::Alert, 1)); |
113 |
2/4✓ Branch 7 taken 14 times.
✗ Branch 8 not taken.
✓ Branch 11 taken 14 times.
✗ Branch 12 not taken.
|
14 | insert(std::make_pair(PdServ::Event::Critical, 2)); |
114 |
2/4✓ Branch 7 taken 14 times.
✗ Branch 8 not taken.
✓ Branch 11 taken 14 times.
✗ Branch 12 not taken.
|
14 | insert(std::make_pair(PdServ::Event::Error, 3)); |
115 |
2/4✓ Branch 7 taken 14 times.
✗ Branch 8 not taken.
✓ Branch 11 taken 14 times.
✗ Branch 12 not taken.
|
14 | insert(std::make_pair(PdServ::Event::Warning, 4)); |
116 |
2/4✓ Branch 7 taken 14 times.
✗ Branch 8 not taken.
✓ Branch 11 taken 14 times.
✗ Branch 12 not taken.
|
14 | insert(std::make_pair(PdServ::Event::Notice, 5)); |
117 |
2/4✓ Branch 7 taken 14 times.
✗ Branch 8 not taken.
✓ Branch 11 taken 14 times.
✗ Branch 12 not taken.
|
14 | insert(std::make_pair(PdServ::Event::Info, 6)); |
118 |
2/4✓ Branch 7 taken 14 times.
✗ Branch 8 not taken.
✓ Branch 11 taken 14 times.
✗ Branch 12 not taken.
|
14 | insert(std::make_pair(PdServ::Event::Debug, 7)); |
119 | 14 | } | |
120 | }; | ||
121 |
4/8✓ Branch 0 taken 14 times.
✓ Branch 1 taken 15 times.
✓ Branch 3 taken 14 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 14 times.
✗ Branch 7 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
|
29 | static const Map map; |
122 | |||
123 |
1/2✓ Branch 2 taken 29 times.
✗ Branch 3 not taken.
|
58 | Map::const_iterator it = map.find(priority); |
124 |
1/2✓ Branch 4 taken 29 times.
✗ Branch 5 not taken.
|
58 | return it != map.end() ? it->second : 7; |
125 | } | ||
126 |