GCC Code Coverage Report


Directory: ./
File: pdserv-1.1.0/src/supervisor/Server.cpp
Date: 2026-10-18 04:09:42
Exec Total Coverage
Lines: 1 37 2.7%
Branches: 0 50 0.0%

Line Branch Exec Source
1 /*****************************************************************************
2 *
3 * $Id$
4 *
5 * Copyright 2012 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 "config.h"
25
26 #include "Server.h"
27 #include "../Main.h"
28 #include "../Event.h"
29 #include "../Debug.h"
30
31 #include <log4cplus/logger.h>
32 #include <log4cplus/loggingmacros.h>
33 #include <sstream>
34 #include <iomanip>
35 #include <cstdio>
36
37 using namespace Supervisor;
38
39 /////////////////////////////////////////////////////////////////////////////
40 ✗ Server::Server(const PdServ::Main *main, const PdServ::Config &/*config*/):
41 PdServ::Session(main),
42 main(main),
43 ✗ mutex(1)
44 {
45 ✗ start();
46 }
47
48 /////////////////////////////////////////////////////////////////////////////
49 ✗ Server::~Server()
50 {
51 }
52
53 /////////////////////////////////////////////////////////////////////////////
54 ✗ void Server::run()
55 {
56 const PdServ::Event* event;
57 ✗ bool state;
58 ✗ struct timespec t;
59 ✗ size_t index;
60 ✗ const log4cplus::Logger eventLog(log4cplus::Logger::getInstance(
61 ✗ LOG4CPLUS_STRING_TO_TSTRING("event")));
62
63 while (true) {
64 ✗ ost::Thread::sleep(100);
65
66 ✗ while ((event = main->getNextEvent(this, &index, &state, &t))) {
67
68 log4cplus::LogLevel prio;
69 ✗ switch (event->priority) {
70 ✗ case PdServ::Event::Emergency:
71 case PdServ::Event::Alert:
72 case PdServ::Event::Critical:
73 ✗ prio = log4cplus::FATAL_LOG_LEVEL;
74 ✗ break;
75 ✗ case PdServ::Event::Error:
76 ✗ prio = log4cplus::ERROR_LOG_LEVEL;
77 ✗ break;
78 ✗ case PdServ::Event::Warning:
79 ✗ prio = log4cplus::WARN_LOG_LEVEL;
80 ✗ break;
81 ✗ case PdServ::Event::Notice:
82 case PdServ::Event::Info:
83 ✗ prio = log4cplus::INFO_LOG_LEVEL;
84 ✗ break;
85 ✗ case PdServ::Event::Debug:
86 ✗ prio = log4cplus::DEBUG_LOG_LEVEL;
87 ✗ break;
88 }
89
90 ✗ if (!state)
91 ✗ continue;
92
93 ✗ if (event->message and event->message[index])
94 ✗ eventLog.log(prio,
95 ✗ LOG4CPLUS_C_STR_TO_TSTRING(event->message[index]));
96 else {
97 ✗ log4cplus::tostringstream os;
98 os << LOG4CPLUS_STRING_TO_TSTRING(event->path)
99 ✗ << '[' << index << ']';
100 ✗ eventLog.log(prio, os.str());
101 }
102 }
103 }
104 3 }
105