• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

traintastic / traintastic / 23669027368

27 Mar 2026 09:50PM UTC coverage: 26.198% (+0.02%) from 26.176%
23669027368

push

github

reinder
Merge remote-tracking branch 'origin/master' into cbus

11 of 144 new or added lines in 34 files covered. (7.64%)

1 existing line in 1 file now uncovered.

8256 of 31514 relevant lines covered (26.2%)

182.55 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/server/src/hardware/protocol/z21/kernel.cpp
1
/**
2
 * server/src/hardware/protocol/z21/kernel.cpp
3
 *
4
 * This file is part of the traintastic source code.
5
 *
6
 * Copyright (C) 2019-2023 Reinder Feenstra
7
 *
8
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation; either version 2
11
 * of the License, or (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21
 */
22

23
#include "kernel.hpp"
24
#include "messages.hpp"
25
#include "../xpressnet/messages.hpp"
26
#include "../../decoder/decoder.hpp"
27
#include "../../decoder/decoderchangeflags.hpp"
28
#include "../../input/inputcontroller.hpp"
29
#include "../../../utils/setthreadname.hpp"
30
#include "../../../core/eventloop.hpp"
31
#include "../../../log/log.hpp"
32
#include "../../../log/logmessageexception.hpp"
33

34
namespace Z21 {
35

36
Kernel::Kernel(std::string logId_)
×
37
  : KernelBase(std::move(logId_))
×
38
{
39
}
×
40

41
void Kernel::start()
×
42
{
43
  assert(m_ioHandler);
×
44
  assert(!m_started);
×
45

46
  m_thread = std::thread(
×
47
    [this]()
×
48
    {
49
      setThreadName("z21");
×
NEW
50
      boost::asio::executor_work_guard<decltype(m_ioContext.get_executor())> work{m_ioContext.get_executor()};
×
51
      m_ioContext.run();
×
52
    });
×
53

NEW
54
  boost::asio::post(m_ioContext, 
×
55
    [this]()
×
56
    {
57
      try
58
      {
59
        m_ioHandler->start();
×
60
      }
61
      catch(const LogMessageException& e)
×
62
      {
63
        EventLoop::call(
×
64
          [this, e]()
×
65
          {
66
            Log::log(logId, e.message(), e.args());
×
67
            error();
×
68
          });
×
69
        return;
×
70
      }
×
71

72
      onStart();
×
73

74
      started();
×
75
    });
76

77
#ifndef NDEBUG
78
  m_started = true;
×
79
#endif
80
}
×
81

82
void Kernel::stop()
×
83
{
NEW
84
  boost::asio::post(m_ioContext, 
×
85
    [this]()
×
86
    {
87
      onStop();
×
88

89
      m_ioHandler->stop();
×
90
    });
×
91

92
  m_ioContext.stop();
×
93

94
  m_thread.join();
×
95

96
#ifndef NDEBUG
97
  m_started = false;
×
98
#endif
99
}
×
100

101
void Kernel::setIOHandler(std::unique_ptr<IOHandler> handler)
×
102
{
103
  assert(handler);
×
104
  assert(!m_ioHandler);
×
105
  m_ioHandler = std::move(handler);
×
106
}
×
107

108
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc