00001 /*========================================================================= 00002 00003 Program: Insight Segmentation & Registration Toolkit 00004 Module: $RCSfile: itkLoggerThreadWrapper.h,v $ 00005 Language: C++ 00006 Date: $Date: 2006/02/05 20:57:46 $ 00007 Version: $Revision: 1.7 $ 00008 00009 Copyright (c) Insight Software Consortium. All rights reserved. 00010 See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. 00011 00012 This software is distributed WITHOUT ANY WARRANTY; without even 00013 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00014 PURPOSE. See the above copyright notices for more information. 00015 00016 =========================================================================*/ 00017 00018 #ifndef __itkLoggerThreadWrapper_h 00019 #define __itkLoggerThreadWrapper_h 00020 00021 #if ! ( defined(_MSC_VER) || ( defined(__GNUC__) && (__GNUC__ <= 2) ))//NOTE: This class does not work under MSVS6, or gnu 2.95 00022 00023 #include "itkMacro.h" 00024 #include "itkMultiThreader.h" 00025 #include "itkSimpleFastMutexLock.h" 00026 00027 #include <string> 00028 #include <queue> 00029 00030 namespace itk 00031 { 00032 00042 // MSVS6 can't do this type of nested template 00043 template < class SimpleLoggerType > 00044 class LoggerThreadWrapper : public SimpleLoggerType 00045 { 00046 00047 public: 00048 00049 typedef LoggerThreadWrapper Self; 00050 typedef SimpleLoggerType Superclass; 00051 typedef SmartPointer<Self> Pointer; 00052 typedef SmartPointer<const Self> ConstPointer; 00053 00055 itkTypeMacro( LoggerThreadWrapper, SimpleLoggerType ); 00056 00058 itkNewMacro( Self ); 00059 00060 typedef typename SimpleLoggerType::OutputType OutputType; 00061 typedef typename SimpleLoggerType::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 00073 00077 virtual void SetPriorityLevel( PriorityLevelType level ); 00078 00082 virtual PriorityLevelType GetPriorityLevel() const; 00083 00084 virtual void SetLevelForFlushing( PriorityLevelType level ); 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 LoggerThreadWrapper(); 00098 00100 virtual ~LoggerThreadWrapper(); 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<typename 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 }; // class LoggerThreadWrapper 00134 } // namespace itk 00135 00136 #ifndef ITK_MANUAL_INSTANTIATION 00137 #include "itkLoggerThreadWrapper.txx" 00138 #endif 00139 00140 00141 00142 #endif // !defined (_MSC_VER) 00143 #endif // __itkLoggerThreadWrapper_h 00144