nux-1.16.0
|
00001 /* 00002 * Copyright 2010 Inalogic® Inc. 00003 * 00004 * This program is free software: you can redistribute it and/or modify it 00005 * under the terms of the GNU Lesser General Public License, as 00006 * published by the Free Software Foundation; either version 2.1 or 3.0 00007 * of the License. 00008 * 00009 * This program is distributed in the hope that it will be useful, but 00010 * WITHOUT ANY WARRANTY; without even the implied warranties of 00011 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR 00012 * PURPOSE. See the applicable version of the GNU Lesser General Public 00013 * License for more details. 00014 * 00015 * You should have received a copy of both the GNU Lesser General Public 00016 * License along with this program. If not, see <http://www.gnu.org/licenses/> 00017 * 00018 * Authored by: Jay Taoko <jaytaoko@inalogic.com> 00019 * 00020 */ 00021 00022 00023 #ifndef NOUTPUTDEVICE_H 00024 #define NOUTPUTDEVICE_H 00025 00026 namespace nux 00027 { 00028 00029 class NSerializer; 00030 00031 class LogOutputDevice 00032 { 00033 public: 00034 LogOutputDevice (); 00035 virtual ~LogOutputDevice (); 00036 00037 BOOL m_terminated; 00038 virtual void Serialize (const TCHAR *log_data, const TCHAR *log_prefix, int severity) = 0; 00039 virtual void Flush (); 00040 virtual void Shutdown (); 00041 00042 VARARG_DECL (void/*FuncRet*/, void/*StaticFuncRet*/, {}/*Return*/, LogFunction/*FuncName*/, VARARG_NONE/*Pure*/, const TCHAR*/*FmtType*/, VARARG_EXTRA (int severity) /*ExtraDecl*/, VARARG_EXTRA (severity) /*ExtraParam*/ ); 00043 00044 void Enable (); 00045 void Disable (); 00046 00047 protected: 00048 bool _object_destroyed; 00049 bool _enabled; 00050 }; 00051 00053 class NullOutput : public LogOutputDevice 00054 { 00055 NUX_DECLARE_GLOBAL_OBJECT (NullOutput, GlobalSingletonInitializer); 00056 public: 00057 void Serialize ( const TCHAR *V, const TCHAR *LogPrefix, int severity) {} 00058 }; 00059 00061 class LogFileOutput : public LogOutputDevice 00062 { 00063 NUX_DECLARE_GLOBAL_OBJECT (LogFileOutput, GlobalSingletonInitializer); 00064 //LogFileOutput( const TCHAR* InFilename); 00065 00066 public: 00070 void Shutdown(); 00071 00075 void Flush(); 00076 00083 void Serialize (const TCHAR *log_data, const TCHAR *LogPrefix, int severity); 00084 00085 private: 00086 NSerializer *m_LogSerializer; 00087 NString m_Filename; 00088 bool m_Opened; 00089 bool m_Closed; 00090 00096 void SerializeRaw (const TCHAR *log_data); 00097 }; 00098 00100 class VisualOutputConsole : public LogOutputDevice 00101 { 00102 NUX_DECLARE_GLOBAL_OBJECT (VisualOutputConsole, GlobalSingletonInitializer); 00103 public: 00104 00106 00111 void Serialize (const TCHAR *text, const TCHAR *log_prefix, int severity); 00112 }; 00113 00115 class PrintfOutputConsole : public LogOutputDevice 00116 { 00117 NUX_DECLARE_GLOBAL_OBJECT (PrintfOutputConsole, GlobalSingletonInitializer); 00118 public: 00119 00121 00126 void Serialize (const TCHAR *text, const TCHAR *log_prefix, int severity); 00127 }; 00128 00129 class LogOutputRedirector : public LogOutputDevice 00130 { 00131 NUX_DECLARE_GLOBAL_OBJECT (LogOutputRedirector, GlobalSingletonInitializer); 00132 public: 00133 virtual void AddOutputDevice (LogOutputDevice *OutputDevice); 00134 virtual void RemoveOutputDevice (LogOutputDevice *OutputDevice); 00135 virtual bool IsRedirectingTo (LogOutputDevice *OutputDevice); 00136 void Serialize (const TCHAR *log_data, const TCHAR *log_prefix, int severity); 00137 void Flush(); 00138 00139 void Shutdown(); 00140 00141 private: 00142 std::vector<LogOutputDevice *> OutputDevices; 00143 }; 00144 00145 } 00146 00147 #endif // NOUTPUTDEVICE_H