journalthreader.h
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 #ifndef JOURNALTHREADER_H
66 #define JOURNALTHREADER_H
67 
68 #include "xscommon_config.h"
69 #include <string>
70 #include "journalloglevel.h"
71 #if JOURNALLER_WITH_THREAD_SUPPORT
72  #include <map>
73  #include "xsens_mutex.h"
74 #endif
75 
76 class FileInfo;
77 class JournalFile;
78 
80 {
81 public:
84 
85  void flushAll(JournalFile* file);
86  void writeLine(int thread, JournalFile* file);
87  JournalLogLevel setLineLevel(int thread, JournalLogLevel level);
88  JournalLogLevel lineLevel(int thread);
89  std::string& line(int thread);
90  void cleanup(int id);
91 
92 private:
95  class ThreadLine
96  {
97  public:
98  std::string m_line;
100 
103  };
104 
105 #if JOURNALLER_WITH_THREAD_SUPPORT
106  std::map<int, ThreadLine> m_map;
108 
110  inline ThreadLine& threadLine(int thread)
111  {
112  xsens::Lock lock(&m_mutex);
113  return m_map[thread];
114  }
115 
118  {
119  xsens::Lock lock(&m_mutex);
120  for (auto it = m_map.begin(); it != m_map.end(); ++it)
121  if (!it->second.m_line.empty())
122  return it->second;
123  return threadLine(0);
124  }
125 
126 #else
127 
128  ThreadLine m_line;
129 
130  inline ThreadLine& threadLine(int)
131  {
132  return m_line;
133  }
134 
136  inline ThreadLine& nextLine()
137  {
138  return m_line;
139  }
140 #endif
141 };
142 
143 #endif
JLL_Write
@ JLL_Write
only log 'write' messages
Definition: journalloglevel.h:95
journalloglevel.h
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::ThreadLine::m_level
JournalLogLevel m_level
The level of this log line.
Definition: journalthreader.h:99
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
xsens_mutex.h
JournalFile
A class containing a journal file and some meta-data.
Definition: journalfile.h:73
JournalThreader::ThreadLine::ThreadLine
ThreadLine()
Constructor, creates an empty line at WRITE log level.
Definition: journalthreader.h:102
xsens::Mutex
A base mutex class.
Definition: xsens_mutex.h:132
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
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
JournalThreader::ThreadLine::m_line
std::string m_line
The contained text for this log line.
Definition: journalthreader.h:98
xsens::Lock
A base class for a Lock.
Definition: xsens_mutex.h:947
xscommon_config.h
JournalThreader::m_map
std::map< int, ThreadLine > m_map
The contained lines, one for each thread.
Definition: journalthreader.h:106
JournalThreader
Manages threaded writes for the Journaller objects.
Definition: journalthreader.h:79
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