ITK
4.1.0
Insight Segmentation and Registration Toolkit
|
00001 /*========================================================================= 00002 * 00003 * Copyright Insight Software Consortium 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0.txt 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 * 00017 *=========================================================================*/ 00018 #ifndef __itkLoggerThreadWrapper_h 00019 #define __itkLoggerThreadWrapper_h 00020 00021 #include <string> 00022 #include <queue> 00023 00024 #include "itkMultiThreader.h" 00025 #include "itkSimpleFastMutexLock.h" 00026 00027 namespace itk 00028 { 00039 template< class SimpleLoggerType > 00040 class LoggerThreadWrapper:public SimpleLoggerType 00041 { 00042 public: 00043 00044 typedef LoggerThreadWrapper Self; 00045 typedef SimpleLoggerType Superclass; 00046 typedef SmartPointer< Self > Pointer; 00047 typedef SmartPointer< const Self > ConstPointer; 00048 00050 itkTypeMacro(LoggerThreadWrapper, SimpleLoggerType); 00051 00053 itkNewMacro(Self); 00054 00055 typedef typename SimpleLoggerType::OutputType OutputType; 00056 typedef typename SimpleLoggerType::PriorityLevelType PriorityLevelType; 00057 typedef unsigned int DelayType; 00058 00060 typedef enum { 00061 SET_PRIORITY_LEVEL, 00062 SET_LEVEL_FOR_FLUSHING, 00063 ADD_LOG_OUTPUT, 00064 WRITE, 00065 FLUSH 00066 } OperationType; 00067 00071 virtual void SetPriorityLevel(PriorityLevelType level); 00072 00076 virtual PriorityLevelType GetPriorityLevel() const; 00077 00078 virtual void SetLevelForFlushing(PriorityLevelType level); 00079 00080 virtual PriorityLevelType GetLevelForFlushing() const; 00081 00085 virtual void SetDelay(DelayType delay); 00086 00090 virtual DelayType GetDelay() const; 00091 00093 virtual void AddLogOutput(OutputType *output); 00094 00095 virtual void Write(PriorityLevelType level, std::string const & content); 00096 00097 virtual void Flush(); 00098 00099 protected: 00100 00102 LoggerThreadWrapper(); 00103 00105 virtual ~LoggerThreadWrapper(); 00106 00108 virtual void PrintSelf(std::ostream & os, Indent indent) const; 00109 00110 static ITK_THREAD_RETURN_TYPE ThreadFunction(void *); 00111 00112 private: 00113 00114 typedef std::queue< OperationType > OperationContainerType; 00115 00116 typedef std::queue< std::string > MessageContainerType; 00117 00118 typedef std::queue< PriorityLevelType > LevelContainerType; 00119 00120 typedef std::queue< typename OutputType::Pointer > OutputContainerType; 00121 00122 MultiThreader::Pointer m_Threader; 00123 00124 ThreadIdType m_ThreadID; 00125 00126 OperationContainerType m_OperationQ; 00127 00128 MessageContainerType m_MessageQ; 00129 00130 LevelContainerType m_LevelQ; 00131 00132 OutputContainerType m_OutputQ; 00133 00134 SimpleFastMutexLock m_Mutex; 00135 00136 DelayType m_Delay; 00137 00138 }; // class LoggerThreadWrapper 00139 } // namespace itk 00140 00141 #ifndef ITK_MANUAL_INSTANTIATION 00142 #include "itkLoggerThreadWrapper.hxx" 00143 #endif 00144 00145 #endif // __itkLoggerThreadWrapper_h 00146