ITK  4.9.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 
24 #include "itkMultiThreader.h"
25 #include "itkSimpleFastMutexLock.h"
26 
27 namespace itk
28 {
39 template< typename SimpleLoggerType >
40 class LoggerThreadWrapper:public SimpleLoggerType
41 {
42 public:
43 
45  typedef SimpleLoggerType Superclass;
48 
50  itkTypeMacro(LoggerThreadWrapper, SimpleLoggerType);
51 
53  itkNewMacro(Self);
54 
55  typedef typename SimpleLoggerType::OutputType OutputType;
56  typedef typename SimpleLoggerType::PriorityLevelType PriorityLevelType;
57  typedef unsigned int DelayType;
58 
60  typedef enum {
65  } OperationType;
66 
70  virtual void SetPriorityLevel(PriorityLevelType level) ITK_OVERRIDE;
71 
75  virtual PriorityLevelType GetPriorityLevel() const ITK_OVERRIDE;
76 
77  virtual void SetLevelForFlushing(PriorityLevelType level) ITK_OVERRIDE;
78 
79  virtual PriorityLevelType GetLevelForFlushing() const ITK_OVERRIDE;
80 
84  virtual void SetDelay(DelayType delay);
85 
89  virtual DelayType GetDelay() const;
90 
92  virtual void AddLogOutput(OutputType *output) ITK_OVERRIDE;
93 
94  virtual void Write(PriorityLevelType level, std::string const & content) ITK_OVERRIDE;
95 
96  virtual void Flush() ITK_OVERRIDE;
97 
98 protected:
99 
102 
104  virtual ~LoggerThreadWrapper();
105 
107  virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
108 
109  static ITK_THREAD_RETURN_TYPE ThreadFunction(void *);
110 
111 private:
112 
113  typedef std::queue< OperationType > OperationContainerType;
114 
115  typedef std::queue< std::string > MessageContainerType;
116 
117  typedef std::queue< PriorityLevelType > LevelContainerType;
118 
119  typedef std::queue< typename OutputType::Pointer > OutputContainerType;
120 
121  MultiThreader::Pointer m_Threader;
122 
124 
125  OperationContainerType m_OperationQ;
126 
127  MessageContainerType m_MessageQ;
128 
129  LevelContainerType m_LevelQ;
130 
131  OutputContainerType m_OutputQ;
132 
134 
136 
137 }; // class LoggerThreadWrapper
138 } // namespace itk
139 
140 #ifndef ITK_MANUAL_INSTANTIATION
141 #include "itkLoggerThreadWrapper.hxx"
142 #endif
143 
144 #endif // itkLoggerThreadWrapper_h
Critical section locking class that can be allocated on the stack.
virtual PriorityLevelType GetPriorityLevel() const override
SmartPointer< Self > Pointer
std::queue< typename OutputType::Pointer > OutputContainerType
Used for providing logging service as a separate thread.
virtual void Flush() override
virtual void Write(PriorityLevelType level, std::string const &content) override
virtual void PrintSelf(std::ostream &os, Indent indent) const override
virtual void SetLevelForFlushing(PriorityLevelType level) override
#define ITK_THREAD_RETURN_TYPE
SmartPointer< const Self > ConstPointer
virtual DelayType GetDelay() const
std::queue< PriorityLevelType > LevelContainerType
static ITK_THREAD_RETURN_TYPE ThreadFunction(void *)
MultiThreader::Pointer m_Threader
virtual void SetDelay(DelayType delay)
virtual PriorityLevelType GetLevelForFlushing() const override
unsigned int ThreadIdType
Definition: itkIntTypes.h:159
OperationContainerType m_OperationQ
std::queue< std::string > MessageContainerType
SimpleLoggerType::PriorityLevelType PriorityLevelType
std::queue< OperationType > OperationContainerType
virtual void AddLogOutput(OutputType *output) override
Control indentation during Print() invocation.
Definition: itkIndent.h:49
MessageContainerType m_MessageQ
SimpleLoggerType::OutputType OutputType
virtual void SetPriorityLevel(PriorityLevelType level) override