ITK  4.0.0
Insight Segmentation and Registration Toolkit
itkThreadLogger.h
Go to the documentation of this file.
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 __itkThreadLogger_h
00019 #define __itkThreadLogger_h
00020 
00021 #include "itkMultiThreader.h"
00022 #include "itkLogger.h"
00023 #include "itkSimpleFastMutexLock.h"
00024 
00025 #include <string>
00026 #include <queue>
00027 
00028 namespace itk
00029 {
00040 class ITKCommon_EXPORT ThreadLogger:public Logger
00041 {
00042 public:
00043 
00044   typedef ThreadLogger               Self;
00045   typedef Logger                     Superclass;
00046   typedef SmartPointer< Self >       Pointer;
00047   typedef SmartPointer< const Self > ConstPointer;
00048 
00050   itkTypeMacro(ThreadLogger, Logger);
00051 
00053   itkNewMacro(Self);
00054 
00055   typedef  Logger::OutputType OutputType;
00056 
00057   typedef  Logger::PriorityLevelType PriorityLevelType;
00058 
00059   typedef  unsigned int DelayType;
00060 
00062   typedef enum
00063   {
00064     SET_PRIORITY_LEVEL,
00065     SET_LEVEL_FOR_FLUSHING,
00066     ADD_LOG_OUTPUT,
00067     WRITE,
00068     FLUSH
00069   }
00070   OperationType;
00071 
00075   virtual void SetPriorityLevel(PriorityLevelType level);
00076 
00080   virtual PriorityLevelType GetPriorityLevel() const;
00081 
00082   virtual void SetLevelForFlushing(PriorityLevelType level);
00083 
00084   virtual PriorityLevelType GetLevelForFlushing() const;
00085 
00089   virtual void SetDelay(DelayType delay);
00090 
00094   virtual DelayType GetDelay() const;
00095 
00097   virtual void AddLogOutput(OutputType *output);
00098 
00099   virtual void Write(PriorityLevelType level, std::string const & content);
00100 
00101   virtual void Flush();
00102 
00103 protected:
00104 
00106   ThreadLogger();
00107 
00109   virtual ~ThreadLogger();
00110 
00112   virtual void PrintSelf(std::ostream & os, Indent indent) const;
00113 
00114   static ITK_THREAD_RETURN_TYPE ThreadFunction(void *);
00115 
00116 private:
00117 
00118   void InternalFlush();
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   ThreadIdType 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   DelayType m_Delay;
00143 
00144 };  // class ThreadLogger
00145 } // namespace itk
00146 
00147 #endif  // __itkThreadLogger_h
00148