|
1 /* |
|
2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "tracer.h" |
|
19 |
|
20 #ifdef __WINS__ |
|
21 // Yes, I know this does not compile for Arm, but at least we can use it in Wins |
|
22 static TInt ii; |
|
23 #endif |
|
24 |
|
25 #ifdef FILE_LOGGING_SUPPORT |
|
26 _LIT(KTracerLogFilePath, "c:\\logs\\xn3trace.log"); |
|
27 #endif |
|
28 |
|
29 EXPORT_C TTracer::TTracer() |
|
30 { |
|
31 #ifdef FILE_LOGGING_SUPPORT |
|
32 RFs fs; |
|
33 TInt err(fs.Connect()); |
|
34 if (KErrNone == err) |
|
35 { |
|
36 RFile file; |
|
37 file.Replace(fs, KTracerLogFilePath, EFileWrite); |
|
38 file.Close(); |
|
39 fs.Close(); |
|
40 } |
|
41 #endif |
|
42 |
|
43 #ifdef __WINS__ |
|
44 ii = 0; |
|
45 #endif |
|
46 } |
|
47 |
|
48 EXPORT_C TTracer::TTracer(TPtrC aString) |
|
49 { |
|
50 #ifdef FILE_LOGGING_SUPPORT |
|
51 TInt err (iFs.Connect()); |
|
52 if (KErrNone == err) |
|
53 { |
|
54 RFile file; |
|
55 err (file.Open(iFs, KTracerLogFilePath, EFileWrite)); |
|
56 if (KErrNone == err) |
|
57 { |
|
58 TFileText tfile; |
|
59 tfile.Set(file); |
|
60 #endif |
|
61 |
|
62 TBuf<255> str=_L(""); |
|
63 TTime currentTime; // set current time to now |
|
64 currentTime.HomeTime(); |
|
65 TBuf<25> strCurTime; |
|
66 TRAP_IGNORE( currentTime.FormatL(strCurTime, _L("%H:%T:%S:%*C3 ")) ); |
|
67 |
|
68 str.Copy(strCurTime); |
|
69 |
|
70 #ifdef __WINS__ |
|
71 for(int i=0;i<ii;i++) |
|
72 { |
|
73 str.Append(_L(" ")); |
|
74 } |
|
75 #else |
|
76 str.Append(_L(" ")); |
|
77 #endif |
|
78 |
|
79 iString = aString; |
|
80 str.Append(_L("Enter: ")); |
|
81 str.Append(iString); |
|
82 |
|
83 #ifdef FILE_LOGGING_SUPPORT |
|
84 str.Append(_L("\r")); // carriage return |
|
85 tfile.Seek(ESeekEnd); |
|
86 tfile.Write(str); |
|
87 } |
|
88 file.Close(); |
|
89 } |
|
90 #endif |
|
91 |
|
92 #ifdef __WINS__ |
|
93 ii++; |
|
94 #endif |
|
95 } |
|
96 |
|
97 |
|
98 EXPORT_C TTracer::~TTracer() |
|
99 { |
|
100 #ifdef __WINS__ |
|
101 if(ii > 0) |
|
102 { |
|
103 --ii; |
|
104 #endif |
|
105 |
|
106 #ifdef FILE_LOGGING_SUPPORT |
|
107 RFile file; |
|
108 TInt err (file.Open(iFs, KTracerLogFilePath, EFileWrite)); |
|
109 if (KErrNone == err) |
|
110 { |
|
111 TFileText tfile; |
|
112 tfile.Set(file); |
|
113 #endif |
|
114 |
|
115 TBuf<255> str=_L(""); |
|
116 TTime currentTime; // set current time to now |
|
117 currentTime.HomeTime(); |
|
118 TBuf<25> strCurTime; |
|
119 TRAP_IGNORE( currentTime.FormatL(strCurTime, _L("%H:%T:%S:%*C3 ")) ); |
|
120 |
|
121 str.Copy(strCurTime); |
|
122 |
|
123 #ifdef __WINS__ |
|
124 for(int i=0;i<ii;i++) |
|
125 { |
|
126 str.Append(_L(" ")); |
|
127 } |
|
128 #else |
|
129 str.Append(_L(" ")); |
|
130 #endif |
|
131 str.Append(_L("Leave: ")); |
|
132 str.Append(iString); |
|
133 |
|
134 #ifdef FILE_LOGGING_SUPPORT |
|
135 str.Append(_L("\r")); // carriage return |
|
136 tfile.Seek(ESeekEnd); |
|
137 tfile.Write(str); |
|
138 } |
|
139 file.Close(); |
|
140 iFs.Close(); |
|
141 #endif |
|
142 #ifdef __WINS__ |
|
143 } |
|
144 #endif |
|
145 } |
|
146 |
|
147 EXPORT_C void TTracer::Print(TPtrC aString) |
|
148 { |
|
149 #ifdef FILE_LOGGING_SUPPORT |
|
150 RFs fs; |
|
151 TInt err(fs.Connect()); |
|
152 if (KErrNone == err) |
|
153 { |
|
154 RFile file; |
|
155 TInt err(file.Open(fs, KTracerLogFilePath, EFileWrite)); |
|
156 if (KErrNone == err) |
|
157 { |
|
158 TFileText tfile; |
|
159 tfile.Set(file); |
|
160 #endif |
|
161 TBuf<255> str=_L(""); |
|
162 TTime currentTime; // set current time to now |
|
163 currentTime.HomeTime(); |
|
164 TBuf<25> strCurTime; |
|
165 TRAP_IGNORE( currentTime.FormatL(strCurTime, _L("%H:%T:%S:%*C3 ")) ); |
|
166 |
|
167 str.Copy(strCurTime); |
|
168 |
|
169 str.Append(_L(" ")); |
|
170 str.Append(aString); |
|
171 #ifdef FILE_LOGGING_SUPPORT |
|
172 str.Append(_L("\r")); // carriage return |
|
173 tfile.Seek(ESeekEnd); |
|
174 tfile.Write(str); |
|
175 } |
|
176 file.Close(); |
|
177 fs.Close(); |
|
178 } |
|
179 #endif |
|
180 } |
|
181 |