DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
qdebugstream.cpp
Go to the documentation of this file.
2#include "streambuf"
3//using namespace daq::QTUtils;
4std::streamsize QDebugStream::xsputn(const char *p, std::streamsize n) {
5 QMutexLocker locker(m_mutex);
6 m_string.append(p, p + n);
7
8 uint pos = 0;
9 while (pos != std::string::npos) {
10 pos = m_string.find('\n');
11 if (pos != std::string::npos) {
12 std::string tmp(m_string.begin(), m_string.begin() + pos);
13 m_text.append(tmp.c_str()).append("\n");
14 m_string.erase(m_string.begin(), m_string.begin() + pos + 1);
15 }
16 }
17 QCoreApplication::postEvent(this, new QEvent(QEvent::User));
18 return n;
19}
20bool QDebugStream::event(QEvent* event) {
21 if (event->type() == QEvent::User) {
22 {
23 QMutexLocker locker(m_mutex);
24 if (!m_text.isEmpty())
25 log_window->append(m_text);
26 m_text.clear();
27 }
28 event->accept();
29 return true;
30 }
31 return false;
32}
33
34std::streambuf::int_type QDebugStream::overflow(int_type v) {
35 QMutexLocker locker(m_mutex);
36 if (v == '\n') {
37 m_text.append(m_string.c_str()).append("\n");
38 m_string.erase(m_string.begin(), m_string.end());
39 } else {
40 m_string += v;
41 }
42 QCoreApplication::postEvent(this, new QEvent(QEvent::User));
43 return v;
44}