Go to the documentation of this file.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 #include "itkMacro.h"
00022 #include "itkMultiThreader.h"
00023 #include "itkLogger.h"
00024 #include "itkSimpleFastMutexLock.h"
00025
00026 #include <string>
00027 #include <queue>
00028
00029 namespace itk
00030 {
00043 class ITKCommon_EXPORT ThreadLogger : public Logger
00044 {
00045
00046 public:
00047
00048 typedef ThreadLogger Self;
00049 typedef Logger Superclass;
00050 typedef SmartPointer<Self> Pointer;
00051 typedef SmartPointer<const Self> ConstPointer;
00052
00054 itkTypeMacro( ThreadLogger, Logger );
00055
00057 itkNewMacro( Self );
00058
00059 typedef Logger::OutputType OutputType;
00060
00061 typedef Logger::PriorityLevelType PriorityLevelType;
00062
00064 typedef enum
00065 {
00066 SET_PRIORITY_LEVEL,
00067 SET_LEVEL_FOR_FLUSHING,
00068 ADD_LOG_OUTPUT,
00069 WRITE,
00070 FLUSH
00071 } OperationType;
00072
00076 virtual void SetPriorityLevel( PriorityLevelType level );
00077
00081 virtual PriorityLevelType GetPriorityLevel() const;
00082
00083 virtual void SetLevelForFlushing( PriorityLevelType level );
00084
00085 virtual PriorityLevelType GetLevelForFlushing() const;
00086
00088 virtual void AddLogOutput( OutputType* output );
00089
00090 virtual void Write(PriorityLevelType level, std::string const & content);
00091
00092 virtual void Flush();
00093
00094 protected:
00095
00097 ThreadLogger();
00098
00100 virtual ~ThreadLogger();
00101
00103 virtual void PrintSelf(std::ostream &os, Indent indent) const;
00104
00105 static ITK_THREAD_RETURN_TYPE ThreadFunction(void*);
00106
00107 private:
00108
00109 typedef std::queue<OperationType> OperationContainerType;
00110
00111 typedef std::queue<std::string> MessageContainerType;
00112
00113 typedef std::queue<PriorityLevelType> LevelContainerType;
00114
00115 typedef std::queue<OutputType::Pointer> OutputContainerType;
00116
00117 MultiThreader::Pointer m_Threader;
00118
00119 int m_ThreadID;
00120
00121 OperationContainerType m_OperationQ;
00122
00123 MessageContainerType m_MessageQ;
00124
00125 LevelContainerType m_LevelQ;
00126
00127 OutputContainerType m_OutputQ;
00128
00129 SimpleFastMutexLock m_Mutex;
00130
00131 SimpleFastMutexLock m_WaitMutex;
00132
00133 };
00134
00135
00136 }
00137
00138
00139 #endif // __itkThreadLogger_h
00140