loggingservices/filelogger/INC/FLOGGER.H
changeset 0 08ec8eefde2f
child 9 667e88a979d7
equal deleted inserted replaced
-1:000000000000 0:08ec8eefde2f
       
     1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // FLogger Client side header
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file
       
    20  @internalTechnology
       
    21 */
       
    22 
       
    23 
       
    24 
       
    25 #ifndef __FLOGGER_H__
       
    26 #define __FLOGGER_H__
       
    27 
       
    28 #include <e32base.h>
       
    29 
       
    30 /** Maximum log buffer size.
       
    31 @internalTechnology */
       
    32 const TInt KLogBufferSize=150;
       
    33 
       
    34 // [All of this start up stuff copied from DBMS]
       
    35 
       
    36 class FLogger
       
    37 /** Controls the flogger server.
       
    38 @internalComponent */
       
    39 	{
       
    40 public:
       
    41 	class TSignal
       
    42 /**
       
    43 @internalComponent
       
    44 */
       
    45 		{
       
    46 		friend class FLogger;
       
    47 	public:
       
    48 		inline TSignal() {}
       
    49 		inline TInt Set(const TDesC& aCommand);
       
    50 	
       
    51 		inline TSignal(TRequestStatus& aStatus);
       
    52 
       
    53 		inline TPtrC Command() const;
       
    54 
       
    55 	private:
       
    56 		TRequestStatus* iStatus;
       
    57 		TThreadId iId;
       
    58 		};
       
    59 public:
       
    60 	static TInt Start();
       
    61 
       
    62 	IMPORT_C static TInt Run(TSignal& aSignal);
       
    63 
       
    64 private:
       
    65 	static TInt Init();
       
    66 	};
       
    67 
       
    68 
       
    69 /** The mode used to write to the log file.
       
    70 @internalTechnology */
       
    71 enum TFileLoggingMode 
       
    72 	{
       
    73 	/** Log file mode has not been explicitly set. */
       
    74 	EFileLoggingModeUnknown =0,
       
    75 	/** Open the log file in append mode. */
       
    76 	EFileLoggingModeAppend,
       
    77 	/** Open the log file in overwrite mode. */
       
    78 	EFileLoggingModeOverwrite,
       
    79 	EFileLoggingModeAppendRaw,
       
    80 	EFileLoggingModeOverwriteRaw	
       
    81 	};
       
    82 
       
    83 NONSHARABLE_CLASS(TLogFormatter16Overflow) :public TDes16Overflow
       
    84 /** Unicode overflow handler.
       
    85 @internalComponent */
       
    86 	{
       
    87 public:
       
    88 	virtual void Overflow(TDes16& aDes);
       
    89 	};
       
    90 
       
    91 NONSHARABLE_CLASS(TLogFormatter8Overflow) :public TDes8Overflow
       
    92 /** Overflow handler.
       
    93 @internalComponent */
       
    94 	{
       
    95 public:
       
    96 	virtual void Overflow(TDes8& aDes);
       
    97 	};
       
    98 
       
    99 class TLogFormatter
       
   100 /** Formatting methods for log file data.
       
   101 @internalComponent */
       
   102 	{
       
   103 public:
       
   104 	TLogFormatter();
       
   105 	void SetDateAndTime(TBool aUseDate,TBool aUseTime);
       
   106 	TInt FormatTextToWritableBuffer(TDes8& aBuf, const TDesC16& aText) const;
       
   107 	TInt FormatTextToWritableBuffer(TDes8& aBuf, const TDesC8& aText) const;
       
   108 	TInt ConvertToWritableBuffer(TDes8& aBuf, TRefByValue<const TDesC16> aFmt, VA_LIST& aList);
       
   109 	TInt ConvertToWritableBuffer(TDes8& aBuf, TRefByValue<const TDesC8> aFmt, VA_LIST& aList);
       
   110 private:
       
   111 	void GetDateAndTimeL(TDes& aDate, TDes& aTime) const;
       
   112 	void WriteL(TDes8& aTrg, const TDesC16& aSrc) const;
       
   113 	void WriteL(TDes8& aTrg, const TDesC8& aSrc) const;
       
   114 private:
       
   115 	TBool iUseDate;
       
   116 	TBool iUseTime;
       
   117 	TLogFormatter16Overflow iOverflow16;
       
   118 	TLogFormatter8Overflow iOverflow8;
       
   119 	};
       
   120 
       
   121 class TLogFile
       
   122 /** General access to packaged log files.
       
   123 @internalComponent */
       
   124 	{
       
   125 public:
       
   126 	TLogFile();
       
   127 	TLogFile(const TDesC& aDir, const TDesC& aName, TFileLoggingMode aMode);
       
   128 	TBool operator==(const TLogFile& aLogFile) const;
       
   129 	void Set(const TDesC& aDir, const TDesC& aName, TFileLoggingMode aMode);
       
   130 	inline TBool Valid() const;
       
   131 	inline TFileName Directory() const;
       
   132 	inline TFileName Name() const;
       
   133 	inline TFileLoggingMode Mode() const;
       
   134 	inline void SetValid(TBool aValid);
       
   135 private:
       
   136 	TBool iValid;
       
   137 	TFileName iDirectory;
       
   138 	TFileName iName;
       
   139 	TFileLoggingMode iMode;
       
   140 	};
       
   141 
       
   142 #include <flogger.inl>
       
   143 
       
   144 class RFileLogger : public RSessionBase
       
   145 /** Provides access methods to file logging.
       
   146 
       
   147 The file logger API contains both static and non-static versions of access 
       
   148 functions to the file logging system. 
       
   149 @internalTechnology */
       
   150 	{
       
   151 public:
       
   152 	IMPORT_C RFileLogger();
       
   153 	IMPORT_C ~RFileLogger();
       
   154 	IMPORT_C TVersion Version() const;
       
   155 	IMPORT_C TInt Connect();
       
   156 	IMPORT_C void SetDateAndTime(TBool aUseDate,TBool aUseTime);
       
   157 	IMPORT_C void CreateLog(const TDesC& aDir, const TDesC& aName, TFileLoggingMode aMode);
       
   158 	IMPORT_C void CloseLog();
       
   159 	IMPORT_C void Write(const TDesC16& aText);
       
   160 	IMPORT_C void WriteFormat(TRefByValue<const TDesC16> aFmt,...);
       
   161 	IMPORT_C void WriteFormat(TRefByValue<const TDesC16> aFmt, VA_LIST& aList);
       
   162 	IMPORT_C void Write(const TDesC8& aText);
       
   163 	IMPORT_C void WriteFormat(TRefByValue<const TDesC8> aFmt,...);
       
   164 	IMPORT_C void WriteFormat(TRefByValue<const TDesC8> aFmt, VA_LIST& aList);
       
   165 	IMPORT_C void HexDump(const TText* aHeader, const TText* aMargin, const TUint8* aPtr, TInt aLen);
       
   166 	IMPORT_C static void Write(const TDesC& aDir, const TDesC& aName, TFileLoggingMode aMode, const TDesC16& aText);
       
   167 	IMPORT_C static void WriteFormat(const TDesC& aDir, const TDesC& aName, TFileLoggingMode aMode, TRefByValue<const TDesC16> aFmt,...);
       
   168 	IMPORT_C static void WriteFormat(const TDesC& aDir, const TDesC& aName, TFileLoggingMode aMode, TRefByValue<const TDesC16> aFmt, VA_LIST& aList);
       
   169 	IMPORT_C static void Write(const TDesC& aDir, const TDesC& aName, TFileLoggingMode aMode, const TDesC8& aText);
       
   170 	IMPORT_C static void WriteFormat(const TDesC& aDir, const TDesC& aName, TFileLoggingMode aMode, TRefByValue<const TDesC8> aFmt,...);
       
   171 	IMPORT_C static void WriteFormat(const TDesC& aDir, const TDesC& aName, TFileLoggingMode aMode, TRefByValue<const TDesC8> aFmt, VA_LIST& aList);
       
   172 	IMPORT_C static void HexDump(const TDesC& aDir, const TDesC& aName, TFileLoggingMode aMode, const TText* aHeader, const TText* aMargin, const TUint8* aPtr, TInt aLen);
       
   173 	IMPORT_C TInt LastError() const;
       
   174 	IMPORT_C TBool LogValid() const;
       
   175 	IMPORT_C TBool LogSTI() const;
       
   176 
       
   177 private:
       
   178 	TInt DoConnect();
       
   179 	void DoWrite(const TDesC8& aBuf);
       
   180 	void DoStaticWrite(const TDesC8& aBuf);
       
   181 	void DoWriteFormat(TRefByValue<const TDesC16> aFmt, VA_LIST& aList);
       
   182 	void DoWriteFormat(TRefByValue<const TDesC8> aFmt, VA_LIST& aList);
       
   183 	static void DoStaticWriteFormat(const TDesC& aDir, const TDesC& aName, TFileLoggingMode aMode, TRefByValue<const TDesC16> aFmt, VA_LIST& aList);
       
   184 	static void DoStaticWriteFormat(const TDesC& aDir, const TDesC& aName, TFileLoggingMode aMode, TRefByValue<const TDesC8> aFmt, VA_LIST& aList);
       
   185 	void DoHexDump(const TText* aHeader, const TText* aMargin, const TUint8* aPtr, TInt aLen);
       
   186 private:
       
   187 	TLogFormatter iFormatter;
       
   188 	TLogFile iLogFile;
       
   189 	TInt iLastError;
       
   190 	TBool iLogSTI;	/* CR1688  	Flogger to use RDebug::Print */
       
   191 	
       
   192 	};
       
   193 
       
   194 #endif