00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef __itkThreadLogger_h
00019 #define __itkThreadLogger_h
00020
00021 #if defined(_MSC_VER)
00022
00023 #pragma warning( disable : 4786 )
00024
00025 #pragma warning ( disable : 4503 )
00026 #endif
00027
00028
00029 #include <string>
00030 #include <queue>
00031
00032 #include "itkMacro.h"
00033 #include "itkMultiThreader.h"
00034 #include "itkLogger.h"
00035 #include "itkSimpleFastMutexLock.h"
00036
00037
00038
00039 namespace itk
00040 {
00053 class ITKCommon_EXPORT ThreadLogger : public Logger
00054 {
00055
00056 public:
00057
00058 typedef ThreadLogger Self;
00059 typedef Logger Superclass;
00060 typedef SmartPointer<Self> Pointer;
00061 typedef SmartPointer<const Self> ConstPointer;
00062
00064 itkTypeMacro( ThreadLogger, Logger );
00065
00067 itkNewMacro( Self );
00068
00069 typedef Logger::OutputType OutputType;
00070
00071 typedef Logger::PriorityLevelType PriorityLevelType;
00072
00074 typedef enum
00075 {
00076 SET_PRIORITY_LEVEL,
00077 SET_LEVEL_FOR_FLUSHING,
00078 ADD_LOG_OUTPUT,
00079 WRITE,
00080 FLUSH
00081 } OperationType;
00082
00083
00087 virtual void SetPriorityLevel( PriorityLevelType level );
00088
00092 virtual PriorityLevelType GetPriorityLevel() const;
00093
00094 virtual void SetLevelForFlushing( PriorityLevelType level );
00095
00096 virtual PriorityLevelType GetLevelForFlushing() const;
00097
00099 virtual void AddLogOutput( OutputType* output );
00100
00101 virtual void Write(PriorityLevelType level, std::string const & content);
00102
00103 virtual void Flush();
00104
00105 protected:
00106
00108 ThreadLogger();
00109
00111 virtual ~ThreadLogger();
00112
00114 virtual void PrintSelf(std::ostream &os, Indent indent) const;
00115
00116 static ITK_THREAD_RETURN_TYPE ThreadFunction(void*);
00117
00118 private:
00119
00120 typedef std::queue<OperationType> OperationContainerType;
00121
00122 typedef std::queue<std::string> MessageContainerType;
00123
00124 typedef std::queue<PriorityLevelType> LevelContainerType;
00125
00126 typedef std::queue<OutputType::Pointer> OutputContainerType;
00127
00128 MultiThreader::Pointer m_Threader;
00129
00130 int m_ThreadID;
00131
00132 OperationContainerType m_OperationQ;
00133
00134 MessageContainerType m_MessageQ;
00135
00136 LevelContainerType m_LevelQ;
00137
00138 OutputContainerType m_OutputQ;
00139
00140 SimpleFastMutexLock m_Mutex;
00141
00142 SimpleFastMutexLock m_WaitMutex;
00143
00144 };
00145
00146
00147 }
00148
00149
00150 #endif // __itkThreadLogger_h