author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Wed, 13 Oct 2010 14:53:46 +0300 | |
branch | RCL_3 |
changeset 130 | 67f2ed48ad91 |
parent 122 | 6cadd6867c17 |
permissions | -rw-r--r-- |
114 | 1 |
/* |
2 |
* Copyright (c) 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 |
||
19 |
#include "cpdebug.h" |
|
20 |
||
21 |
const TUint KMemDataSize( 100 ); |
|
22 |
const TUint KBufMaxSize( 512 ); |
|
23 |
const TUint KThousand( 1000 ); |
|
24 |
||
25 |
// ======== MEMBER FUNCTIONS ======== |
|
26 |
||
27 |
// --------------------------------------------------------------------------- |
|
28 |
// |
|
29 |
// --------------------------------------------------------------------------- |
|
30 |
// |
|
31 |
void CCPDebug::ConstructL( const TDesC& aFile ) |
|
32 |
{ |
|
33 |
iData = new (ELeave) DebugData(); |
|
34 |
iData->iLogEnabled = EFalse; |
|
35 |
iData->iFirstUpdateTime.UniversalTime( ); |
|
36 |
iData->iFileName.Create( aFile.Length( ) ); |
|
37 |
iData->iFileName = aFile; |
|
38 |
Dll::SetTls( iData ); |
|
39 |
User::LeaveIfError( iData->iFs.Connect( ) ); |
|
40 |
EnableLogging( EFalse ); |
|
41 |
} |
|
42 |
||
43 |
// --------------------------------------------------------------------------- |
|
44 |
// |
|
45 |
// --------------------------------------------------------------------------- |
|
46 |
// |
|
47 |
EXPORT_C CCPDebug* CCPDebug::NewL( const TDesC& aFile ) |
|
48 |
{ |
|
49 |
CCPDebug* self = NewLC( aFile ); |
|
50 |
CleanupStack::Pop(self); |
|
51 |
return self; |
|
52 |
} |
|
53 |
||
54 |
// --------------------------------------------------------------------------- |
|
55 |
// |
|
56 |
// --------------------------------------------------------------------------- |
|
57 |
// |
|
58 |
EXPORT_C CCPDebug* CCPDebug::NewLC( const TDesC& aFile ) |
|
59 |
{ |
|
60 |
CCPDebug* self = new (ELeave) CCPDebug(); |
|
61 |
CleanupStack::PushL(self); |
|
62 |
self->ConstructL( aFile ); |
|
63 |
return self; |
|
64 |
} |
|
65 |
||
66 |
// --------------------------------------------------------------------------- |
|
67 |
// |
|
68 |
// --------------------------------------------------------------------------- |
|
69 |
// |
|
70 |
CCPDebug::CCPDebug() |
|
71 |
{ |
|
72 |
||
73 |
} |
|
74 |
||
75 |
// --------------------------------------------------------------------------- |
|
76 |
// |
|
77 |
// --------------------------------------------------------------------------- |
|
78 |
// |
|
79 |
CCPDebug::~CCPDebug() |
|
80 |
{ |
|
81 |
if ( iData ) |
|
82 |
{ |
|
83 |
iData->iFileName.Close( ); |
|
84 |
iData->iLogFile.Close( ); |
|
85 |
iData->iFs.Close( ); |
|
86 |
} |
|
87 |
Dll::FreeTls( ); |
|
88 |
delete iData; |
|
89 |
} |
|
90 |
||
91 |
// --------------------------------------------------------------------------- |
|
92 |
// |
|
93 |
// --------------------------------------------------------------------------- |
|
94 |
// |
|
95 |
EXPORT_C TBool CCPDebug::Enable() |
|
96 |
{ |
|
97 |
DebugData* data = Data(); |
|
98 |
if(!data) |
|
99 |
{ |
|
100 |
return false; |
|
101 |
} |
|
102 |
else |
|
103 |
{ |
|
104 |
return true; |
|
105 |
} |
|
106 |
} |
|
107 |
||
108 |
// --------------------------------------------------------------------------- |
|
109 |
// |
|
110 |
// --------------------------------------------------------------------------- |
|
111 |
// |
|
112 |
EXPORT_C void CCPDebug::EnableLogging(TBool aEnable) |
|
113 |
{ |
|
114 |
DebugData* data = Data(); |
|
115 |
if(aEnable && !data->iLogEnabled) |
|
116 |
{ |
|
117 |
if( data->iLogFile.Replace(data->iFs, data->iFileName, EFileWrite) == KErrNone ) |
|
118 |
{ |
|
119 |
data->iLogEnabled = ETrue; |
|
120 |
Printf(_L8("CCPDebug::EnableLogging()")); |
|
121 |
} |
|
122 |
} |
|
123 |
else if(!aEnable && data->iLogEnabled) |
|
124 |
{ |
|
125 |
data->iLogFile.Close(); |
|
126 |
data->iLogEnabled = EFalse; |
|
127 |
} |
|
128 |
} |
|
129 |
||
130 |
// --------------------------------------------------------------------------- |
|
131 |
// |
|
132 |
// --------------------------------------------------------------------------- |
|
133 |
// |
|
134 |
EXPORT_C void CCPDebug::Printf(TRefByValue<const TDesC8> aFormat, ...) |
|
135 |
{ |
|
136 |
DebugData* data = Data(); |
|
137 |
if(!data || !data->iLogEnabled) |
|
138 |
{ |
|
139 |
return; |
|
140 |
} |
|
141 |
TTime now; |
|
142 |
now.UniversalTime(); |
|
143 |
TInt32 elapsed = (TInt32)(now.MicroSecondsFrom(data->iFirstUpdateTime).Int64() / KThousand); |
|
144 |
||
145 |
TBuf8<KMemDataSize> memData; |
|
146 |
memData.Format(_L8("% 2d,%03d "), elapsed / KThousand, elapsed % KThousand); |
|
147 |
||
148 |
TBuf8<KBufMaxSize> buf; |
|
149 |
VA_LIST list; |
|
150 |
VA_START(list, aFormat); |
|
151 |
buf.FormatList(aFormat, list); |
|
152 |
VA_END(list); |
|
153 |
buf.Insert(0, memData); |
|
154 |
buf.Append(_L8("\n")); |
|
155 |
||
156 |
data->iLogFile.Write(buf); |
|
157 |
data->iLogFile.Flush(); |
|
158 |
} |
|
159 |
||
160 |
// --------------------------------------------------------------------------- |
|
161 |
// |
|
162 |
// --------------------------------------------------------------------------- |
|
163 |
// |
|
164 |
EXPORT_C void CCPDebug::ExtendedPrint( const char* aStringParam, |
|
165 |
const CLiwGenericParamList& aInParamList ) |
|
166 |
{ |
|
167 |
RDebug::Printf( "CPS Client::Request %s Parameters: \n", aStringParam ); |
|
168 |
for ( TInt i = 0; i < aInParamList.Count( ); i++ ) |
|
169 |
{ |
|
130
67f2ed48ad91
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
122
diff
changeset
|
170 |
TLiwGenericParam tempParam; |
67f2ed48ad91
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
122
diff
changeset
|
171 |
tempParam.PushL(); |
67f2ed48ad91
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
122
diff
changeset
|
172 |
TRAP_IGNORE( aInParamList.AtL(i ,tempParam) ); |
67f2ed48ad91
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
122
diff
changeset
|
173 |
Dump( tempParam.Value() ); |
67f2ed48ad91
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
122
diff
changeset
|
174 |
CleanupStack::Pop(&tempParam); |
67f2ed48ad91
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
122
diff
changeset
|
175 |
tempParam.Reset(); |
114 | 176 |
} |
177 |
} |
|
178 |
||
179 |
// --------------------------------------------------------------------------- |
|
180 |
// |
|
181 |
// --------------------------------------------------------------------------- |
|
182 |
// |
|
183 |
EXPORT_C DebugData* CCPDebug::Data() |
|
184 |
{ |
|
185 |
return static_cast<DebugData*>(Dll::Tls()); |
|
186 |
} |
|
187 |
||
188 |
// End of File |