| Line |
Branch |
Exec |
Source |
| 1 |
|
|
/***************************************************************************** |
| 2 |
|
|
* |
| 3 |
|
|
* $Id$ |
| 4 |
|
|
* |
| 5 |
|
|
* Copyright 2010 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 "Event.h" |
| 25 |
|
|
#include "XmlElement.h" |
| 26 |
|
|
|
| 27 |
|
|
using namespace MsrProto; |
| 28 |
|
|
|
| 29 |
|
|
///////////////////////////////////////////////////////////////////////////// |
| 30 |
|
✗ |
Event::Event(const PdServ::Event *e): |
| 31 |
|
✗ |
event(e) |
| 32 |
|
|
{ |
| 33 |
|
|
} |
| 34 |
|
|
|
| 35 |
|
|
///////////////////////////////////////////////////////////////////////////// |
| 36 |
|
✗ |
void Event::toXml(Session::TCPStream &tcp, const PdServ::Event* event, |
| 37 |
|
|
size_t index, bool state, const struct timespec& t) |
| 38 |
|
|
{ |
| 39 |
|
✗ |
XmlElement msg(tcp.createElement(levelString(event))); |
| 40 |
|
|
|
| 41 |
|
✗ |
XmlElement::Attribute(msg, "path").setEscaped(event->path.c_str()); |
| 42 |
|
✗ |
XmlElement::Attribute(msg, "index") << index; |
| 43 |
|
✗ |
XmlElement::Attribute(msg, "state") << state; |
| 44 |
|
✗ |
XmlElement::Attribute(msg, "time") << t; |
| 45 |
|
✗ |
if (event->message and state) |
| 46 |
|
✗ |
XmlElement::Attribute(msg, "text").setEscaped(event->message[index]); |
| 47 |
|
|
} |
| 48 |
|
|
|
| 49 |
|
|
///////////////////////////////////////////////////////////////////////////// |
| 50 |
|
✗ |
const char *Event::levelString(const PdServ::Event *e) |
| 51 |
|
|
{ |
| 52 |
|
✗ |
switch (e->priority) |
| 53 |
|
|
{ |
| 54 |
|
✗ |
case PdServ::Event::Emergency: |
| 55 |
|
|
case PdServ::Event::Alert: |
| 56 |
|
|
case PdServ::Event::Critical: |
| 57 |
|
✗ |
return "crit_error"; |
| 58 |
|
✗ |
case PdServ::Event::Error: |
| 59 |
|
✗ |
return "error"; |
| 60 |
|
✗ |
case PdServ::Event::Warning: |
| 61 |
|
✗ |
return "warn"; |
| 62 |
|
✗ |
case PdServ::Event::Notice: |
| 63 |
|
|
case PdServ::Event::Info: |
| 64 |
|
|
case PdServ::Event::Debug: |
| 65 |
|
✗ |
return "info"; |
| 66 |
|
|
} |
| 67 |
|
|
|
| 68 |
|
✗ |
return "message"; |
| 69 |
|
3 |
} |
| 70 |
|
|
|