|
1 // Copyright (c) 2002-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 // $Header$ |
|
15 // This header file introduces the CLogFile amnd the CLogFilePile classes. |
|
16 // |
|
17 // |
|
18 |
|
19 #ifndef __CLOGFILE_H__ |
|
20 #define __CLOGFILE_H__ |
|
21 |
|
22 //----------------------------------------------------------------------------- |
|
23 // INCLUDES |
|
24 |
|
25 #include <e32base.h> |
|
26 #include <f32file.h> |
|
27 |
|
28 //----------------------------------------------------------------------------- |
|
29 |
|
30 class TLogFileOverflow : public TDes16Overflow |
|
31 { |
|
32 public: |
|
33 |
|
34 virtual void Overflow( TDes16& aDes ); |
|
35 }; |
|
36 |
|
37 //----------------------------------------------------------------------------- |
|
38 |
|
39 class CLogFile : public CBase |
|
40 { |
|
41 public: // Constructors and destructors |
|
42 |
|
43 // aMaxLength sets the maximum length of formatted output. |
|
44 static CLogFile* NewL ( TInt aMaxLength = 512 ); |
|
45 static CLogFile* NewLC( TInt aMaxLength = 512 ); |
|
46 ~CLogFile( ); |
|
47 |
|
48 private: // Constructors and destructors |
|
49 |
|
50 void ConstructL( TInt aMaxLength = 512 ); |
|
51 CLogFile( ) {}; |
|
52 |
|
53 public: // New functions |
|
54 |
|
55 // Open. Closes the present file. |
|
56 TInt Open( const TDesC& aFileName ); |
|
57 |
|
58 // Reopen after closed. |
|
59 TInt Open( ); |
|
60 |
|
61 // Close iff is open. Preserves the file name. |
|
62 void Close( ); |
|
63 |
|
64 // Is open? |
|
65 TBool IsOpen( ); |
|
66 |
|
67 // Get file name. |
|
68 TPtrC FileName( ) const; |
|
69 |
|
70 // Get last error code; is set by Open and Prints. |
|
71 TInt Error( ); |
|
72 |
|
73 // Print standard format heading iff file is open. |
|
74 void PrintHeading( ); |
|
75 |
|
76 // Print unformatted text iff file is open. |
|
77 // Will be removed - please use the Writes. |
|
78 void Print ( const TDesC& aText ); |
|
79 void Println( const TDesC& aText ); |
|
80 void Println( ); // end-line = \r\n |
|
81 |
|
82 // Write unformatted text iff file is open. |
|
83 void Write ( const TDesC& aText ); |
|
84 void Writeln( const TDesC& aText ); |
|
85 void Writeln(); |
|
86 |
|
87 // Printf formatted text iff file is open. |
|
88 void Printf( TRefByValue<const TDesC> aFmt, ... ); |
|
89 void Printf( TRefByValue<const TDesC> aFmt, VA_LIST& aList ); |
|
90 |
|
91 private: |
|
92 |
|
93 // Open file. |
|
94 TInt DoOpen ( ); |
|
95 |
|
96 // Close file. |
|
97 void DoClose( ); |
|
98 |
|
99 // Flush file. |
|
100 TInt DoFlush( ); |
|
101 |
|
102 // Write heading. |
|
103 TInt DoHeading( ); |
|
104 |
|
105 // Write formatted. |
|
106 TInt DoWrite( TRefByValue<const TDesC> aFmt, VA_LIST& aList ); |
|
107 |
|
108 // Write unformatted. |
|
109 TInt DoWrite( const TDesC& aText ); |
|
110 |
|
111 #ifdef _UNICODE |
|
112 // Write 8-bit string. |
|
113 TInt DoWrite( const TDesC8& aText ); |
|
114 #endif |
|
115 |
|
116 private: // Data |
|
117 |
|
118 // Is open? |
|
119 TBool iIsOpen; |
|
120 |
|
121 // File name. |
|
122 TFileName iFileName; |
|
123 |
|
124 // File server session. |
|
125 RFs iFs; |
|
126 |
|
127 // File handle. |
|
128 RFile iFile; |
|
129 |
|
130 // Last error. |
|
131 TInt iError; |
|
132 |
|
133 // Buffer length. |
|
134 TInt iBufLength; |
|
135 |
|
136 // Buffer itself. |
|
137 HBufC* iBuffer; |
|
138 |
|
139 // Overflow handler. |
|
140 TLogFileOverflow iOverflow; |
|
141 |
|
142 }; |
|
143 |
|
144 //----------------------------------------------------------------------------- |
|
145 |
|
146 #endif //__CLOGFILE_H__ |
|
147 |
|
148 //----------------------------------------------------------------------------- |
|
149 // End of File |
|
150 //----------------------------------------------------------------------------- |