ITK  6.0.0
Insight Toolkit
itkLoggerThreadWrapper.h
Go to the documentation of this file.
1/*=========================================================================
2 *
3 * Copyright NumFOCUS
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * https://www.apache.org/licenses/LICENSE-2.0.txt
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 *=========================================================================*/
18#ifndef itkLoggerThreadWrapper_h
19#define itkLoggerThreadWrapper_h
20
21#include <string>
22#include <queue>
23#include <thread>
24#include <atomic>
25
26#include "itkObjectFactory.h"
27#include <mutex>
28#include "ITKCommonExport.h"
29
30namespace itk
31{
32
38{
39public:
44 enum class Operation : uint8_t
45 {
46 SET_PRIORITY_LEVEL,
47 SET_LEVEL_FOR_FLUSHING,
48 ADD_LOG_OUTPUT,
49 WRITE
50 };
51};
52// Define how to print enumeration
53extern ITKCommon_EXPORT std::ostream &
54 operator<<(std::ostream & out, const LoggerThreadWrapperEnums::Operation value);
55
56
67template <typename SimpleLoggerType>
68class ITK_TEMPLATE_EXPORT LoggerThreadWrapper : public SimpleLoggerType
69{
70public:
72 using Superclass = SimpleLoggerType;
75
77 itkOverrideGetNameOfClassMacro(LoggerThreadWrapper);
78
80 itkNewMacro(Self);
81
82 using OutputType = typename SimpleLoggerType::OutputType;
83 using PriorityLevelEnum = typename SimpleLoggerType::PriorityLevelEnum;
84 using DelayType = unsigned int;
85
87
88#if !defined(ITK_LEGACY_REMOVE)
89 using LoggerThreadWrapperOperationType = OperationEnum;
90
91 static constexpr OperationEnum SET_PRIORITY_LEVEL = OperationEnum::SET_PRIORITY_LEVEL;
92 static constexpr OperationEnum SET_LEVEL_FOR_FLUSHING = OperationEnum::SET_LEVEL_FOR_FLUSHING;
93 static constexpr OperationEnum ADD_LOG_OUTPUT = OperationEnum::ADD_LOG_OUTPUT;
94 static constexpr OperationEnum WRITE = OperationEnum::WRITE;
95#endif
96
100 void
102
107 GetPriorityLevel() const override;
108
109 void
111
113 GetLevelForFlushing() const override;
114
118 virtual void
120
124 virtual DelayType
125 GetDelay() const;
126
128 void
129 AddLogOutput(OutputType * output) override;
130
131 void
132 Write(PriorityLevelEnum level, std::string const & content) override;
133
134 void
135 Flush() override;
136
137protected:
138 void
139 PrivateFlush() override;
140
143
146
148 void
149 PrintSelf(std::ostream & os, Indent indent) const override;
150
151 void
153
154private:
155 std::thread m_Thread{};
156
157 std::atomic<bool> m_TerminationRequested{};
158
159 std::queue<OperationEnum> m_OperationQ{};
160
161 std::queue<std::string> m_MessageQ{};
162
163 std::queue<PriorityLevelEnum> m_LevelQ{};
164
165 std::queue<typename OutputType::Pointer> m_OutputQ{};
166
167 mutable std::mutex m_Mutex{};
168
169 DelayType m_Delay{};
170
171}; // class LoggerThreadWrapper
172
173} // namespace itk
174
175#ifndef ITK_MANUAL_INSTANTIATION
176# include "itkLoggerThreadWrapper.hxx"
177#endif
178
179#endif // itkLoggerThreadWrapper_h
Control indentation during Print() invocation.
Definition: itkIndent.h:50
enums for LoggerThreadWrapper
Used for providing logging service as a separate thread.
typename SimpleLoggerType::OutputType OutputType
void Flush() override
void SetLevelForFlushing(PriorityLevelEnum level) override
PriorityLevelEnum GetLevelForFlushing() const override
void PrivateFlush() override
PriorityLevelEnum GetPriorityLevel() const override
~LoggerThreadWrapper() override
virtual void SetDelay(DelayType delay)
void SetPriorityLevel(PriorityLevelEnum level) override
void PrintSelf(std::ostream &os, Indent indent) const override
void AddLogOutput(OutputType *output) override
void Write(PriorityLevelEnum level, std::string const &content) override
typename SimpleLoggerType::PriorityLevelEnum PriorityLevelEnum
virtual DelayType GetDelay() const
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
std::ostream & operator<<(std::ostream &os, const Array< TValue > &arr)
Definition: itkArray.h:216