00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef __itkLoggerThreadWrapper_h
00019 #define __itkLoggerThreadWrapper_h
00020
00021 #if defined(_MSC_VER)
00022
00023 #pragma warning( disable : 4786 )
00024
00025 #pragma warning ( disable : 4503 )
00026 #endif
00027 #if ! ( defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ <= 2) ))//NOTE: This class does not work under MSVS6, or gnu 2.95
00028
00029
00030 #include <string>
00031 #include <queue>
00032
00033 #include "itkMacro.h"
00034 #include "itkMultiThreader.h"
00035 #include "itkSimpleFastMutexLock.h"
00036
00037 namespace itk
00038 {
00039
00049
00050 template < class SimpleLoggerType >
00051 class LoggerThreadWrapper : public SimpleLoggerType
00052 {
00053
00054 public:
00055
00056 typedef LoggerThreadWrapper Self;
00057 typedef SimpleLoggerType Superclass;
00058 typedef SmartPointer<Self> Pointer;
00059 typedef SmartPointer<const Self> ConstPointer;
00060
00062 itkTypeMacro( LoggerThreadWrapper, SimpleLoggerType );
00063
00065 itkNewMacro( Self );
00066
00067 typedef typename SimpleLoggerType::OutputType OutputType;
00068 typedef typename SimpleLoggerType::PriorityLevelType PriorityLevelType;
00069
00071 typedef enum
00072 {
00073 SET_PRIORITY_LEVEL,
00074 SET_LEVEL_FOR_FLUSHING,
00075 ADD_LOG_OUTPUT,
00076 WRITE,
00077 FLUSH
00078 } OperationType;
00079
00080
00084 virtual void SetPriorityLevel( PriorityLevelType level );
00085
00089 virtual PriorityLevelType GetPriorityLevel() const;
00090
00091 virtual void SetLevelForFlushing( PriorityLevelType level );
00092 virtual PriorityLevelType GetLevelForFlushing() const;
00093
00095 virtual void AddLogOutput( OutputType* output );
00096
00097 virtual void Write(PriorityLevelType level, std::string const & content);
00098
00099 virtual void Flush();
00100
00101 protected:
00102
00104 LoggerThreadWrapper();
00105
00107 virtual ~LoggerThreadWrapper();
00108
00110 virtual void PrintSelf(std::ostream &os, Indent indent) const;
00111
00112 static ITK_THREAD_RETURN_TYPE ThreadFunction(void*);
00113
00114 private:
00115
00116 typedef std::queue<OperationType> OperationContainerType;
00117
00118 typedef std::queue<std::string> MessageContainerType;
00119
00120 typedef std::queue<PriorityLevelType> LevelContainerType;
00121
00122 typedef std::queue<typename OutputType::Pointer> OutputContainerType;
00123
00124 MultiThreader::Pointer m_Threader;
00125
00126 int m_ThreadID;
00127
00128 OperationContainerType m_OperationQ;
00129
00130 MessageContainerType m_MessageQ;
00131
00132 LevelContainerType m_LevelQ;
00133
00134 OutputContainerType m_OutputQ;
00135
00136 SimpleFastMutexLock m_Mutex;
00137
00138 SimpleFastMutexLock m_WaitMutex;
00139
00140 };
00141 }
00142
00143 #ifndef ITK_MANUAL_INSTANTIATION
00144 #include "itkLoggerThreadWrapper.txx"
00145 #endif
00146
00147
00148
00149 #endif // !defined (_MSC_VER)
00150 #endif // __itkLoggerThreadWrapper_h