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