ITK  4.6.0
Insight Segmentation and Registration Toolkit
itkThreadLogger.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 __itkThreadLogger_h
19 #define __itkThreadLogger_h
20 
21 #include "itkMultiThreader.h"
22 #include "itkLogger.h"
23 #include "itkSimpleFastMutexLock.h"
24 
25 #include <string>
26 #include <queue>
27 
28 namespace itk
29 {
40 class ITKCommon_EXPORT ThreadLogger:public Logger
41 {
42 public:
43 
44  typedef ThreadLogger Self;
45  typedef Logger Superclass;
48 
50  itkTypeMacro(ThreadLogger, Logger);
51 
53  itkNewMacro(Self);
54 
56 
58 
59  typedef unsigned int DelayType;
60 
62  typedef enum
63  {
68  FLUSH
69  }
70  OperationType;
71 
75  virtual void SetPriorityLevel(PriorityLevelType level) ITK_OVERRIDE;
76 
80  virtual PriorityLevelType GetPriorityLevel() const ITK_OVERRIDE;
81 
82  virtual void SetLevelForFlushing(PriorityLevelType level) ITK_OVERRIDE;
83 
84  virtual PriorityLevelType GetLevelForFlushing() const ITK_OVERRIDE;
85 
89  virtual void SetDelay(DelayType delay);
90 
94  virtual DelayType GetDelay() const;
95 
97  virtual void AddLogOutput(OutputType *output) ITK_OVERRIDE;
98 
99  virtual void Write(PriorityLevelType level, std::string const & content) ITK_OVERRIDE;
100 
101  virtual void Flush() ITK_OVERRIDE;
102 
103 protected:
104 
106  ThreadLogger();
107 
109  virtual ~ThreadLogger();
110 
112  virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
113 
114  static ITK_THREAD_RETURN_TYPE ThreadFunction(void *);
115 
116 private:
117 
118  void InternalFlush();
119 
120  typedef std::queue< OperationType > OperationContainerType;
121 
122  typedef std::queue< std::string > MessageContainerType;
123 
124  typedef std::queue< PriorityLevelType > LevelContainerType;
125 
126  typedef std::queue< OutputType::Pointer > OutputContainerType;
127 
128  MultiThreader::Pointer m_Threader;
129 
130  ThreadIdType m_ThreadID;
131 
132  OperationContainerType m_OperationQ;
133 
134  MessageContainerType m_MessageQ;
135 
136  LevelContainerType m_LevelQ;
137 
138  OutputContainerType m_OutputQ;
139 
141 
142  DelayType m_Delay;
143 
144 }; // class ThreadLogger
145 } // namespace itk
146 
147 #endif // __itkThreadLogger_h
Critical section locking class that can be allocated on the stack.
Logger::OutputType OutputType
Light weight base class for most itk classes.
Logger::PriorityLevelType PriorityLevelType
SmartPointer< Self > Pointer
ThreadLogger Self
Represents an output stream.
Definition: itkLogOutput.h:39
Providing logging service as a separate thread.
std::queue< OperationType > OperationContainerType
#define ITK_THREAD_RETURN_TYPE
std::queue< std::string > MessageContainerType
Control indentation during Print() invocation.
Definition: itkIndent.h:49
std::queue< PriorityLevelType > LevelContainerType
unsigned int DelayType
std::queue< OutputType::Pointer > OutputContainerType
SmartPointer< const Self > ConstPointer
Used for logging information during a run.
Definition: itkLogger.h:36
unsigned int ThreadIdType
Definition: itkIntTypes.h:159