ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkLoggerThreadWrapper.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
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  * http://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 
25 #include "itkObjectFactory.h"
26 #include <mutex>
27 
28 namespace itk
29 {
40 template< typename SimpleLoggerType >
41 class ITK_TEMPLATE_EXPORT LoggerThreadWrapper:public SimpleLoggerType
42 {
43 public:
44 
46  using Superclass = SimpleLoggerType;
49 
51  itkTypeMacro(LoggerThreadWrapper, SimpleLoggerType);
52 
54  itkNewMacro(Self);
55 
56  using OutputType = typename SimpleLoggerType::OutputType;
57  using PriorityLevelType = typename SimpleLoggerType::PriorityLevelType;
58  using DelayType = unsigned int;
59 
61  typedef enum {
65  WRITE
66  } OperationType;
67 
71  void SetPriorityLevel(PriorityLevelType level) override;
72 
76  PriorityLevelType GetPriorityLevel() const override;
77 
78  void SetLevelForFlushing(PriorityLevelType level) override;
79 
80  PriorityLevelType GetLevelForFlushing() const override;
81 
85  virtual void SetDelay(DelayType delay);
86 
90  virtual DelayType GetDelay() const;
91 
93  void AddLogOutput(OutputType *output) override;
94 
95  void Write(PriorityLevelType level, std::string const & content) override;
96 
97  void Flush() override;
98 
99 protected:
100 
103 
105  ~LoggerThreadWrapper() override;
106 
108  void PrintSelf(std::ostream & os, Indent indent) const override;
109 
110  void ThreadFunction();
111 
112 private:
113 
114  using OperationContainerType = std::queue< OperationType >;
115 
116  using MessageContainerType = std::queue< std::string >;
117 
118  using LevelContainerType = std::queue< PriorityLevelType >;
119 
120  using OutputContainerType = std::queue< typename OutputType::Pointer >;
121 
122  std::thread m_Thread;
123 
125 
127 
129 
131 
133 
134  mutable std::mutex m_Mutex;
135 
137 
138 }; // class LoggerThreadWrapper
139 } // namespace itk
140 
141 #ifndef ITK_MANUAL_INSTANTIATION
142 #include "itkLoggerThreadWrapper.hxx"
143 #endif
144 
145 #endif // itkLoggerThreadWrapper_h
std::queue< PriorityLevelType > LevelContainerType
Used for providing logging service as a separate thread.
typename SimpleLoggerType::OutputType OutputType
std::queue< std::string > MessageContainerType
std::queue< typename OutputType::Pointer > OutputContainerType
typename SimpleLoggerType::PriorityLevelType PriorityLevelType
OperationContainerType m_OperationQ
std::queue< OperationType > OperationContainerType
Control indentation during Print() invocation.
Definition: itkIndent.h:49
MessageContainerType m_MessageQ