ITK  4.2.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);
76 
80  virtual PriorityLevelType GetPriorityLevel() const;
81 
82  virtual void SetLevelForFlushing(PriorityLevelType level);
83 
84  virtual PriorityLevelType GetLevelForFlushing() const;
85 
89  virtual void SetDelay(DelayType delay);
90 
94  virtual DelayType GetDelay() const;
95 
97  virtual void AddLogOutput(OutputType *output);
98 
99  virtual void Write(PriorityLevelType level, std::string const & content);
100 
101  virtual void Flush();
102 
103 protected:
104 
106  ThreadLogger();
107 
109  virtual ~ThreadLogger();
110 
112  virtual void PrintSelf(std::ostream & os, Indent indent) const;
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 
131 
133 
135 
137 
139 
141 
143 
144 }; // class ThreadLogger
145 } // namespace itk
146 
147 #endif // __itkThreadLogger_h
148