Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

itkLoggerThreadWrapper.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkLoggerThreadWrapper.h,v $
00005   Language:  C++
00006   Date:      $Date: 2009-02-05 19:05:01 $
00007   Version:   $Revision: 1.9 $
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 //NOTE: This class does not work under MSVS6, or gnu 2.95
00022 #if ! ( defined(_MSC_VER) || ( defined(__GNUC__) && (__GNUC__ <= 2) ))
00023 
00024 #include "itkMacro.h"
00025 #include "itkMultiThreader.h"
00026 #include "itkSimpleFastMutexLock.h"
00027 
00028 #include <string>
00029 #include <queue>
00030 
00031 namespace itk
00032 {
00033 
00044 // MSVS6 can't do this type of nested template
00045 template < class SimpleLoggerType >
00046 class LoggerThreadWrapper : public SimpleLoggerType
00047 {
00048 public:
00049   
00050   typedef LoggerThreadWrapper       Self;
00051   typedef SimpleLoggerType          Superclass;
00052   typedef SmartPointer<Self>        Pointer;
00053   typedef SmartPointer<const Self>  ConstPointer;
00054   
00056   itkTypeMacro( LoggerThreadWrapper, SimpleLoggerType );
00057 
00059   itkNewMacro( Self );
00060 
00061   typedef  typename SimpleLoggerType::OutputType         OutputType;
00062   typedef  typename SimpleLoggerType::PriorityLevelType  PriorityLevelType;
00063   
00065   typedef enum
00066     {
00067     SET_PRIORITY_LEVEL,
00068     SET_LEVEL_FOR_FLUSHING,
00069     ADD_LOG_OUTPUT,
00070     WRITE,
00071     FLUSH
00072     } OperationType;
00073 
00074   
00078   virtual void SetPriorityLevel( PriorityLevelType level );
00079 
00083   virtual PriorityLevelType GetPriorityLevel() const;
00084 
00085   virtual void SetLevelForFlushing( PriorityLevelType level );
00086   virtual PriorityLevelType GetLevelForFlushing() const;
00087   
00089   virtual void AddLogOutput( OutputType* output );
00090 
00091   virtual void Write(PriorityLevelType level, std::string const & content);
00092   
00093   virtual void Flush();
00094   
00095 protected:
00096   
00098   LoggerThreadWrapper();
00099 
00101   virtual ~LoggerThreadWrapper();
00102 
00104   virtual void PrintSelf(std::ostream &os, Indent indent) const;
00105 
00106   static ITK_THREAD_RETURN_TYPE ThreadFunction(void*);
00107   
00108 private:
00109   
00110   typedef std::queue<OperationType> OperationContainerType;
00111   
00112   typedef std::queue<std::string>  MessageContainerType;
00113   
00114   typedef std::queue<PriorityLevelType>  LevelContainerType;
00115   
00116   typedef std::queue<typename OutputType::Pointer>  OutputContainerType;
00117   
00118   MultiThreader::Pointer  m_Threader;
00119   
00120   int m_ThreadID;
00121   
00122   OperationContainerType  m_OperationQ;
00123   
00124   MessageContainerType  m_MessageQ;
00125   
00126   LevelContainerType  m_LevelQ;
00127   
00128   OutputContainerType m_OutputQ;
00129   
00130   SimpleFastMutexLock m_Mutex;
00131   
00132   SimpleFastMutexLock m_WaitMutex;
00133   
00134 };  // class LoggerThreadWrapper
00135 } // namespace itk
00136   
00137 #ifndef ITK_MANUAL_INSTANTIATION
00138 #include "itkLoggerThreadWrapper.txx"
00139 #endif
00140   
00141   
00142   
00143 #endif  // !defined (_MSC_VER)
00144 #endif  // __itkLoggerThreadWrapper_h
00145 

Generated at Sat Feb 28 12:57:03 2009 for ITK by doxygen 1.5.6 written by Dimitri van Heesch, © 1997-2000