journalthreader.cpp
Go to the documentation of this file.
1 
2 // Copyright (c) 2003-2021 Xsens Technologies B.V. or subsidiaries worldwide.
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without modification,
6 // are permitted provided that the following conditions are met:
7 //
8 // 1. Redistributions of source code must retain the above copyright notice,
9 // this list of conditions, and the following disclaimer.
10 //
11 // 2. Redistributions in binary form must reproduce the above copyright notice,
12 // this list of conditions, and the following disclaimer in the documentation
13 // and/or other materials provided with the distribution.
14 //
15 // 3. Neither the names of the copyright holders nor the names of their contributors
16 // may be used to endorse or promote products derived from this software without
17 // specific prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
20 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
22 // THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
24 // OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR
26 // TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.THE LAWS OF THE NETHERLANDS
28 // SHALL BE EXCLUSIVELY APPLICABLE AND ANY DISPUTES SHALL BE FINALLY SETTLED UNDER THE RULES
29 // OF ARBITRATION OF THE INTERNATIONAL CHAMBER OF COMMERCE IN THE HAGUE BY ONE OR MORE
30 // ARBITRATORS APPOINTED IN ACCORDANCE WITH SAID RULES.
31 //
32 
33 
34 // Copyright (c) 2003-2021 Xsens Technologies B.V. or subsidiaries worldwide.
35 // All rights reserved.
36 //
37 // Redistribution and use in source and binary forms, with or without modification,
38 // are permitted provided that the following conditions are met:
39 //
40 // 1. Redistributions of source code must retain the above copyright notice,
41 // this list of conditions, and the following disclaimer.
42 //
43 // 2. Redistributions in binary form must reproduce the above copyright notice,
44 // this list of conditions, and the following disclaimer in the documentation
45 // and/or other materials provided with the distribution.
46 //
47 // 3. Neither the names of the copyright holders nor the names of their contributors
48 // may be used to endorse or promote products derived from this software without
49 // specific prior written permission.
50 //
51 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
52 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
53 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
54 // THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
55 // SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
56 // OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
57 // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR
58 // TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
59 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.THE LAWS OF THE NETHERLANDS
60 // SHALL BE EXCLUSIVELY APPLICABLE AND ANY DISPUTES SHALL BE FINALLY SETTLED UNDER THE RULES
61 // OF ARBITRATION OF THE INTERNATIONAL CHAMBER OF COMMERCE IN THE HAGUE BY ONE OR MORE
62 // ARBITRATORS APPOINTED IN ACCORDANCE WITH SAID RULES.
63 //
64 
65 #include "journalthreader.h"
66 #include "journalfile.h"
67 
68 #ifndef XSENS_WINDOWS
69 static void OutputDebugStringA(const char* msg)
70 {
71  (void)fprintf(stderr, "%s", msg);
72 }
73 #endif
74 
81 {
82 }
83 
87 {
88 }
89 
94 {
95  while (true)
96  {
98  if (line.m_line.empty())
99  return;
100 
101  if (file)
102  *file << line.m_line;
103  else
104  OutputDebugStringA(line.m_line.c_str());
105  line.m_line.clear();
106  }
107 }
108 
114 {
115  ThreadLine& line = threadLine(thread);
116  if (line.m_line.empty())
117  return;
118 
119  if (file)
120  *file << line.m_line;
121  else
122  OutputDebugStringA(line.m_line.c_str());
123 }
124 
131 {
132  ThreadLine& line = threadLine(thread);
133  auto old = line.m_level;
134  line.m_level = level;
135  return old;
136 }
137 
142 {
143  ThreadLine& line = threadLine(thread);
144  return line.m_level;
145 }
146 
150 std::string& JournalThreader::line(int thread)
151 {
152  ThreadLine& line = threadLine(thread);
153  return line.m_line;
154 }
155 
160 {
161  xsens::Lock lock(&m_mutex);
162  m_map.erase(id);
163  lock.unlock();
164 }
msg
msg
OutputDebugStringA
static void OutputDebugStringA(const char *msg)
Definition: journalthreader.cpp:69
JournalLogLevel
JournalLogLevel
Definition: journalloglevel.h:88
JournalThreader::lineLevel
JournalLogLevel lineLevel(int thread)
Definition: journalthreader.cpp:141
JournalThreader::flushAll
void flushAll(JournalFile *file)
Flush all available non-empty lines to the supplied file, clearing lines as they are flushed.
Definition: journalthreader.cpp:93
JournalThreader::JournalThreader
JournalThreader()
Constructor, sets up the necessary structures for threaded logging.
Definition: journalthreader.cpp:80
JournalThreader::~JournalThreader
~JournalThreader()
Destructor, flushes all remaining data.
Definition: journalthreader.cpp:86
JournalThreader::cleanup
void cleanup(int id)
Remove the thread-local storage for thread id.
Definition: journalthreader.cpp:159
JournalThreader::threadLine
ThreadLine & threadLine(int thread)
Get the line object for the supplied thread, typically for the current thread.
Definition: journalthreader.h:110
JournalFile
A class containing a journal file and some meta-data.
Definition: journalfile.h:73
journalthreader.h
journalfile.h
JournalThreader::setLineLevel
JournalLogLevel setLineLevel(int thread, JournalLogLevel level)
Set the log level of the queued line.
Definition: journalthreader.cpp:130
JournalThreader::nextLine
ThreadLine & nextLine()
Get the next non-empty line object from the map of all threads, returns an empty line object if no no...
Definition: journalthreader.h:117
JournalThreader::line
std::string & line(int thread)
Definition: journalthreader.cpp:150
xsens::Lock::unlock
bool unlock() noexcept
Unlocks the locked mutex.
Definition: xsens_mutex.h:1032
JournalThreader::writeLine
void writeLine(int thread, JournalFile *file)
Write the line for thread thread to file file.
Definition: journalthreader.cpp:113
JournalThreader::ThreadLine
Storage for logging queue of a specific thread.
Definition: journalthreader.h:95
xsens::Lock
A base class for a Lock.
Definition: xsens_mutex.h:947
JournalThreader::m_map
std::map< int, ThreadLine > m_map
The contained lines, one for each thread.
Definition: journalthreader.h:106
JournalThreader::m_mutex
xsens::Mutex m_mutex
A mutex guarding access to the map (not to the lines)
Definition: journalthreader.h:107


xsens_mti_driver
Author(s):
autogenerated on Sun Sep 3 2023 02:43:20