KWStyle - itkLoggerThreadWrapper.h
 
Matrix View
Description

1 /*=========================================================================
2
3   Program:   Insight Segmentation & Registration Toolkit
4   Module:    $RCSfile: itkLoggerThreadWrapper.h.html,v $
5   Language:  C++
6   Date:      $Date: 2006/01/17 19:15:41 $
7   Version:   $Revision: 1.4 $
8
9   Copyright (c) Insight Software Consortium. All rights reserved.
10   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
11
12      This software is distributed WITHOUT ANY WARRANTY; without even
13      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14      PURPOSE.  See the above copyright notices for more information.
15
16 =========================================================================*/
17
18 #ifndef __itkLoggerThreadWrapper_h
19 #define __itkLoggerThreadWrapper_h
20
21 #if defined(_MSC_VER)
22 LEN,IND ***//Warning about: identifier was truncated to '255' characters in the debug information (MVC6.0 Debug)
23 IND ***#pragma warning( disable : 4786 )
24 LEN,IND **// warning C4503: 'insert' : decorated name length exceeded, name was truncated
25 IND **#pragma warning ( disable : 4503 )
26 #endif
27 LEN #if ! ( defined(_MSC_VER)  ||   (defined(__GNUC__) && (__GNUC__ <= 2) ))//NOTE: This class does not work under MSVS6, or gnu 2.95
28
29
30 #include <string>
31 #include <queue>
32
33 #include "itkMacro.h"
34 #include "itkMultiThreader.h"
35 #include "itkSimpleFastMutexLock.h"
36
37 namespace itk
38 {
39
40 /** \class LoggerThreadWrapper
41 LEN  *  \brief Class LoggerThreadWrapper is meant for providing logging service as a separate thread.
42  *
43  * \author Hee-Su Kim, Compute Science Dept. Kyungpook National University,
44  *                     ISIS Center, Georgetown University.
45  *
46  *  \ingroup OSSystemObjects LoggingObjects
47  */
48
49 // MSVS6 can't do this type of nested template
50 template < class SimpleLoggerType >
51 class LoggerThreadWrapper : public SimpleLoggerType
52 {
53
54 public:
55
56   typedef LoggerThreadWrapper  Self;
57 TDA   typedef SimpleLoggerType  Superclass;
58 TDA   typedef SmartPointer<Self>  Pointer;
59 TDA   typedef SmartPointer<const Self>  ConstPointer;
60
61   /** Run-time type information (and related methods). */
62   itkTypeMacro( LoggerThreadWrapper, SimpleLoggerType );
63
64   /** New macro for creation of through a Smart Pointer */
65   itkNewMacro( Self );
66
67   typedef  typename SimpleLoggerType::OutputType   OutputType;
68 TDA   typedef  typename SimpleLoggerType::PriorityLevelType  PriorityLevelType;
69
70   /** Definition of types of operations for LoggerThreadWrapper. */
71   typedef enum
72 IND **{
73     SET_PRIORITY_LEVEL,
74     SET_LEVEL_FOR_FLUSHING,
75     ADD_LOG_OUTPUT,
76     WRITE,
77     FLUSH
78 IND **} OperationType;
79
80
81   /** Set the priority level for the current logger. Only messages that have
82    * priorities equal or greater than the one set here will be posted to the
83    * current outputs */
84   virtual void SetPriorityLevel( PriorityLevelType level );
85
86   /** Get the priority level for the current logger. Only messages that have
87    * priorities equal or greater than the one set here will be posted to the
88    * current outputs */
89   virtual PriorityLevelType GetPriorityLevel() const;
90
91   virtual void SetLevelForFlushing( PriorityLevelType level );
92   virtual PriorityLevelType GetLevelForFlushing() const;
93
94   /** Registers another output stream with the multiple output. */
95   virtual void AddLogOutput( OutputType* output );
96
97   virtual void Write(PriorityLevelType level, std::string const & content);
98
99   virtual void Flush();
100
101 protected:
102
103   /** Constructor */
104   LoggerThreadWrapper();
105
106   /** Destructor */
107   virtual ~LoggerThreadWrapper();
108
109   /** Print contents of a LoggerThreadWrapper */
110   virtual void PrintSelf(std::ostream &os, Indent indent) const;
111
112   static ITK_THREAD_RETURN_TYPE ThreadFunction(void*);
113
114 private:
115
116   typedef std::queue<OperationType> OperationContainerType;
117
118   typedef std::queue<std::string>  MessageContainerType;
119
120   typedef std::queue<PriorityLevelType>  LevelContainerType;
121
122   typedef std::queue<typename OutputType::Pointer>  OutputContainerType;
123
124   MultiThreader::Pointer  m_Threader;
125
126   int m_ThreadID;
127
128   OperationContainerType  m_OperationQ;
129
130   MessageContainerType  m_MessageQ;
131
132   LevelContainerType  m_LevelQ;
133
134   OutputContainerType m_OutputQ;
135
136   SimpleFastMutexLock m_Mutex;
137
138   SimpleFastMutexLock m_WaitMutex;
139
140 };  // class LoggerThreadWrapper
141 // namespace itk
142
143 #ifndef ITK_MANUAL_INSTANTIATION
144 #include "itkLoggerThreadWrapper.txx"
145 #endif
146
147
148 EML
149 #endif  // !defined (_MSC_VER)
150 #endif  // __itkLoggerThreadWrapper_h
151

Generated by KWStyle 1.0b on Tuesday January,17 at 02:14:20PM
© Kitware Inc.