51
|
1 |
/*
|
|
2 |
* Copyright (c) 2009 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 "MemSpyEngineOutputSinkFile.h"
|
|
19 |
|
|
20 |
// System includes
|
|
21 |
#include <e32svr.h>
|
|
22 |
|
|
23 |
// User includes
|
|
24 |
#include <memspy/engine/memspyenginelogger.h>
|
|
25 |
#include <memspy/engine/memspyengineutils.h>
|
|
26 |
|
|
27 |
// Constants
|
|
28 |
const TInt KMemSpyLineBufferLength = 1024;
|
|
29 |
const TInt KMemSpyFileServerBufferExpandSize = 1024 * 32;
|
|
30 |
|
|
31 |
// Literal constants
|
|
32 |
_LIT8( KMemSpyCRLF, "\r\n" );
|
|
33 |
|
|
34 |
|
|
35 |
CMemSpyEngineOutputSinkFile::CMemSpyEngineOutputSinkFile( CMemSpyEngine& aEngine )
|
|
36 |
: CMemSpyEngineOutputSink( aEngine )
|
|
37 |
{
|
|
38 |
}
|
|
39 |
|
|
40 |
|
|
41 |
CMemSpyEngineOutputSinkFile::~CMemSpyEngineOutputSinkFile()
|
|
42 |
{
|
|
43 |
TRACE( RDebug::Printf( "CMemSpyEngineOutputSinkFile::~CMemSpyEngineOutputSinkFile() - START" ) );
|
|
44 |
|
|
45 |
delete iRoot;
|
|
46 |
|
|
47 |
TRACE( RDebug::Printf( "CMemSpyEngineOutputSinkFile::~CMemSpyEngineOutputSinkFile() - destroying normal logs..." ) );
|
|
48 |
iLogs.ResetAndDestroy();
|
|
49 |
iLogs.Close();
|
|
50 |
|
|
51 |
TRACE( RDebug::Printf( "CMemSpyEngineOutputSinkFile::~CMemSpyEngineOutputSinkFile() - destroying limbo logs..." ) );
|
|
52 |
iLogsPendingDestruction.ResetAndDestroy();
|
|
53 |
iLogsPendingDestruction.Close();
|
|
54 |
|
|
55 |
iFsSession.Close();
|
|
56 |
|
|
57 |
TRACE( RDebug::Printf( "CMemSpyEngineOutputSinkFile::~CMemSpyEngineOutputSinkFile() - END" ) );
|
|
58 |
}
|
|
59 |
|
|
60 |
|
|
61 |
void CMemSpyEngineOutputSinkFile::ConstructL( const TDesC& aRootFolder )
|
|
62 |
{
|
|
63 |
TRACE( RDebug::Printf( "CMemSpyEngineOutputSinkFile::ConstructL() - START" ) );
|
|
64 |
|
|
65 |
iRoot = aRootFolder.AllocL();
|
|
66 |
|
|
67 |
BaseConstructL();
|
|
68 |
|
|
69 |
// Identify the file server process id
|
|
70 |
TRACE( RDebug::Printf( "CMemSpyEngineOutputSinkFile::ConstructL() - identifying f32 process id..." ) );
|
|
71 |
iFileServerProcessId = MemSpyEngineUtils::IdentifyFileServerProcessIdL();
|
|
72 |
|
|
73 |
// Create the standard output file
|
|
74 |
TRACE( RDebug::Printf( "CMemSpyEngineOutputSinkFile::ConstructL() - connecting to f32..." ) );
|
|
75 |
User::LeaveIfError( iFsSession.Connect() );
|
|
76 |
|
|
77 |
// Make default log file
|
|
78 |
TRACE( RDebug::Printf( "CMemSpyEngineOutputSinkFile::ConstructL() - preparing default log..." ) );
|
|
79 |
ConstructDefaultLogFileL();
|
|
80 |
|
|
81 |
TRACE( RDebug::Printf( "CMemSpyEngineOutputSinkFile::ConstructL() - END" ) );
|
|
82 |
}
|
|
83 |
|
|
84 |
|
|
85 |
CMemSpyEngineOutputSinkFile* CMemSpyEngineOutputSinkFile::NewL( CMemSpyEngine& aEngine, const TDesC& aRootFolder )
|
|
86 |
{
|
|
87 |
CMemSpyEngineOutputSinkFile* self = new(ELeave) CMemSpyEngineOutputSinkFile( aEngine );
|
|
88 |
CleanupStack::PushL( self );
|
|
89 |
self->ConstructL( aRootFolder );
|
|
90 |
CleanupStack::Pop( self );
|
|
91 |
return self;
|
|
92 |
}
|
|
93 |
|
|
94 |
|
|
95 |
void CMemSpyEngineOutputSinkFile::ProcessSuspendedL( TProcessId aId )
|
|
96 |
{
|
|
97 |
TRACE( RDebug::Print( _L("CMemSpyEngineOutputSinkFile::ProcessSuspendedL() - START - aId: %d, iFileServerSuspended: %d, iFileServerProcessId: %d"), (TUint) aId, iFileServerSuspended, (TUint) iFileServerProcessId ) );
|
|
98 |
|
|
99 |
iFileServerSuspended = ( (TUint) aId == iFileServerProcessId );
|
|
100 |
if ( iFileServerSuspended )
|
|
101 |
{
|
|
102 |
const TInt count = iLogs.Count();
|
|
103 |
TRACE( RDebug::Print( _L("CMemSpyEngineOutputSinkFile::ProcessSuspendedL() - enabling buffers for %d logs"), count ) );
|
|
104 |
for( TInt i=0; i<count; i++ )
|
|
105 |
{
|
|
106 |
CMemSpyEngineFileHolder* log = iLogs[i];
|
|
107 |
log->EnableBufferL();
|
|
108 |
}
|
|
109 |
}
|
|
110 |
|
|
111 |
TRACE( RDebug::Print( _L("CMemSpyEngineOutputSinkFile::ProcessSuspendedL() - END - aId: %d, iFileServerSuspended: %d"), (TUint) aId, iFileServerSuspended ) );
|
|
112 |
}
|
|
113 |
|
|
114 |
|
|
115 |
void CMemSpyEngineOutputSinkFile::ProcessResumed( TProcessId aId )
|
|
116 |
{
|
|
117 |
const TBool isF32Process = ( (TUint) aId == iFileServerProcessId );
|
|
118 |
TRACE( RDebug::Print( _L("CMemSpyEngineOutputSinkFile::ProcessResumed() - START - aId: %d, iFileServerSuspended: %d, isF32Process: %d"), (TUint) aId, iFileServerSuspended, isF32Process ) );
|
|
119 |
//
|
|
120 |
if ( iFileServerSuspended )
|
|
121 |
{
|
|
122 |
__ASSERT_ALWAYS( isF32Process, User::Invariant() );
|
|
123 |
|
|
124 |
TRAPD( err, DisableAllBuffersAfterFileServerResumedL() );
|
|
125 |
if ( err != KErrNone )
|
|
126 |
{
|
|
127 |
TRACE( RDebug::Printf( "CMemSpyEngineOutputSinkFile::ProcessResumed() - disabled all buffers, completed with err: %d", err ) );
|
|
128 |
}
|
|
129 |
|
|
130 |
iLogsPendingDestruction.ResetAndDestroy();
|
|
131 |
TRACE( RDebug::Printf( "CMemSpyEngineOutputSinkFile::ProcessResumed() - deleted all pending destruction logs..." ) );
|
|
132 |
|
|
133 |
// Indicate file server is no longer suspended
|
|
134 |
iFileServerSuspended = EFalse;
|
|
135 |
}
|
|
136 |
|
|
137 |
TRACE( RDebug::Print( _L("CMemSpyEngineOutputSinkFile::ProcessResumed() - END - aId: %d, iFileServerSuspended: %d, isF32Process: %d"), (TUint) aId, iFileServerSuspended, isF32Process ) );
|
|
138 |
}
|
|
139 |
|
|
140 |
|
|
141 |
TMemSpySinkType CMemSpyEngineOutputSinkFile::Type() const
|
|
142 |
{
|
|
143 |
return ESinkTypeFile;
|
|
144 |
}
|
|
145 |
|
|
146 |
|
|
147 |
void CMemSpyEngineOutputSinkFile::DataStreamBeginL( const TDesC& aContext, const TDesC& aFolder, const TDesC& aExtension )
|
|
148 |
{
|
|
149 |
DataStreamBeginL( aContext, aFolder, aExtension, ETrue );
|
|
150 |
}
|
|
151 |
|
|
152 |
|
|
153 |
void CMemSpyEngineOutputSinkFile::DataStreamBeginL( const TDesC& aContext, const TDesC& aFolder, const TDesC& aExtension, TBool aOverwrite )
|
|
154 |
{
|
|
155 |
DataStreamBeginL( aContext, aFolder, aExtension, aOverwrite, ETrue );
|
|
156 |
}
|
|
157 |
|
|
158 |
|
|
159 |
void CMemSpyEngineOutputSinkFile::DataStreamBeginL( const TDesC& aContext, const TDesC& aFolder, const TDesC& aExtension, TBool aOverwrite, TBool aUseTimeStamp )
|
|
160 |
{
|
|
161 |
CMemSpyEngineSinkMetaData* meta = CMemSpyEngineSinkMetaData::NewL( iRoot->Des(), aContext, aFolder, aExtension, aOverwrite, aUseTimeStamp );
|
|
162 |
CleanupStack::PushL( meta );
|
|
163 |
|
|
164 |
TRACE( RDebug::Printf( "CMemSpyEngineOutputSinkFile::DataStreamBeginL() - START - log count: %d, iFileServerSuspended: %d", iLogs.Count(), iFileServerSuspended ) );
|
|
165 |
//
|
|
166 |
CMemSpyEngineFileHolder* log = NULL;
|
|
167 |
if ( iFileServerSuspended )
|
|
168 |
{
|
|
169 |
TRACE( RDebug::Printf( "CMemSpyEngineOutputSinkFile::DataStreamBeginL() - F32 SUSPENDED!" ) );
|
|
170 |
log = CMemSpyEngineFileHolder::NewLogToRAML( *this, meta );
|
|
171 |
}
|
|
172 |
else
|
|
173 |
{
|
|
174 |
log = CMemSpyEngineFileHolder::NewL( *this, meta );
|
|
175 |
}
|
|
176 |
//
|
|
177 |
TRACE( RDebug::Printf( "CMemSpyEngineOutputSinkFile::DataStreamBeginL() - log: 0x%08x", log ) );
|
|
178 |
CleanupStack::Pop( meta );
|
|
179 |
CleanupStack::PushL( log );
|
|
180 |
iLogs.AppendL( log );
|
|
181 |
CleanupStack::Pop( log );
|
|
182 |
//
|
|
183 |
TRACE( RDebug::Print( _L("CMemSpyEngineOutputSinkFile::DataStreamBeginL() - END - log count: %d, iFileServerSuspended: %d, fileName: [%S]"), iLogs.Count(), iFileServerSuspended, &log->FileName() ) );
|
|
184 |
}
|
|
185 |
|
|
186 |
|
|
187 |
void CMemSpyEngineOutputSinkFile::DataStreamEndL()
|
|
188 |
{
|
|
189 |
const TInt count = iLogs.Count();
|
|
190 |
TRACE( RDebug::Printf( "CMemSpyEngineOutputSinkFile::DataStreamEndL() - count: %d", count ) );
|
|
191 |
|
|
192 |
__ASSERT_ALWAYS( count > 1, User::Invariant() );
|
|
193 |
|
|
194 |
CMemSpyEngineFileHolder* headLog = iLogs[ count - 1 ];
|
|
195 |
iLogs.Remove( count - 1 );
|
|
196 |
TRACE( RDebug::Printf( "CMemSpyEngineOutputSinkFile::DataStreamEndL() - headLog: 0x%08x", headLog ) );
|
|
197 |
|
|
198 |
if ( headLog->UsingBuffer() )
|
|
199 |
{
|
|
200 |
TRACE( RDebug::Printf( "CMemSpyEngineOutputSinkFile::DataStreamEndL() - headLog is using buffer so doing deferred delete when F32 is not suspended anymore..." ) );
|
|
201 |
|
|
202 |
// Must save the log until after its safe to resume
|
|
203 |
// writing to disk.
|
|
204 |
CleanupStack::PushL( headLog );
|
|
205 |
iLogsPendingDestruction.AppendL( headLog );
|
|
206 |
CleanupStack::Pop( headLog );
|
|
207 |
}
|
|
208 |
else
|
|
209 |
{
|
|
210 |
TRACE( RDebug::Printf( "CMemSpyEngineOutputSinkFile::DataStreamEndL() - deleting head log immediately!" ) );
|
|
211 |
delete headLog;
|
|
212 |
}
|
|
213 |
|
|
214 |
TRACE( RDebug::Printf( "CMemSpyEngineOutputSinkFile::DataStreamEndL() - END" ) );
|
|
215 |
}
|
|
216 |
|
62
|
217 |
void CMemSpyEngineOutputSinkFile::FlushL()
|
|
218 |
{
|
|
219 |
HeadLog().FlushL();
|
|
220 |
}
|
51
|
221 |
|
|
222 |
void CMemSpyEngineOutputSinkFile::DoOutputLineL( const TDesC& aLine )
|
|
223 |
{
|
|
224 |
HeadLog().WriteLineL( aLine );
|
|
225 |
}
|
|
226 |
|
|
227 |
|
|
228 |
void CMemSpyEngineOutputSinkFile::DoOutputRawL( const TDesC8& aData )
|
|
229 |
{
|
|
230 |
HeadLog().WriteRawL( aData );
|
|
231 |
}
|
|
232 |
|
|
233 |
|
|
234 |
TBool CMemSpyEngineOutputSinkFile::IsPrefixAllowed( const TDesC& /*aPrefix*/ )
|
|
235 |
{
|
|
236 |
// If we are outputting to the main log, then we must allow
|
|
237 |
// the prefix. If we are outputting to a child log, then we don't
|
|
238 |
// need it.
|
|
239 |
return HeadLog().IsMainLog();
|
|
240 |
}
|
|
241 |
|
|
242 |
|
|
243 |
void CMemSpyEngineOutputSinkFile::ConstructDefaultLogFileL()
|
|
244 |
{
|
|
245 |
CMemSpyEngineFileHolder* log = CMemSpyEngineFileHolder::NewLC( *this );
|
|
246 |
|
|
247 |
TRACE( RDebug::Printf( "CMemSpyEngineOutputSinkFile::ConstructDefaultLogFileL() - START - headLog: 0x%08x", log ) );
|
|
248 |
iLogs.AppendL( log );
|
|
249 |
CleanupStack::Pop( log );
|
|
250 |
|
|
251 |
TRACE( RDebug::Printf( "CMemSpyEngineOutputSinkFile::ConstructDefaultLogFileL() - END - headLog: 0x%08x", log ) );
|
|
252 |
}
|
|
253 |
|
|
254 |
|
|
255 |
void CMemSpyEngineOutputSinkFile::DisableAllBuffersAfterFileServerResumedL()
|
|
256 |
{
|
|
257 |
const TInt count = iLogs.Count();
|
|
258 |
const TInt count2 = iLogsPendingDestruction.Count();
|
|
259 |
|
|
260 |
TRACE( RDebug::Printf( "CMemSpyEngineOutputSinkFile::DisableAllBuffersAfterFileServerResumedL() - START - logs: %d, pending: %d", count, count2 ) );
|
|
261 |
|
|
262 |
TInt err = KErrNone;
|
|
263 |
|
|
264 |
// Inform logging object that they should stop logging to RAM. This may cause files
|
|
265 |
// to be opened and data flushed.
|
|
266 |
for( TInt i=0; i<count; i++ )
|
|
267 |
{
|
|
268 |
CMemSpyEngineFileHolder* log = iLogs[ i ];
|
|
269 |
TRACE( RDebug::Print( _L("CMemSpyEngineOutputSinkFile::DisableAllBuffersAfterFileServerResumedL() - logN[%2d]: 0x%08x, name: %S"), i, log, &log->FileName() ) );
|
|
270 |
TRAP(err, log->DisableBufferL() );
|
|
271 |
if ( err != KErrNone )
|
|
272 |
{
|
|
273 |
TRACE( RDebug::Printf( "CMemSpyEngineOutputSinkFile::DisableAllBuffersAfterFileServerResumedL() - error whilst closing log: %d", err ) );
|
|
274 |
}
|
|
275 |
}
|
|
276 |
|
|
277 |
// Finalise any pending destruction log objects. These are log objects
|
|
278 |
// that were created and finalised whilst the file server was suspended.
|
|
279 |
for( TInt ii = count2-1; ii>=0; ii--)
|
|
280 |
{
|
|
281 |
CMemSpyEngineFileHolder* log = iLogsPendingDestruction[ ii ];
|
|
282 |
TRACE( RDebug::Print( _L("CMemSpyEngineOutputSinkFile::DisableAllBuffersAfterFileServerResumedL() - logPD[%2d]: 0x%08x, name: %S"), ii, log, &log->FileName() ) );
|
|
283 |
TRAP(err, log->DisableBufferL() );
|
|
284 |
if ( err != KErrNone )
|
|
285 |
{
|
|
286 |
TRACE( RDebug::Printf( "CMemSpyEngineOutputSinkFile::DisableAllBuffersAfterFileServerResumedL() - error whilst closing log: %d", err ) );
|
|
287 |
}
|
|
288 |
}
|
|
289 |
|
|
290 |
TRACE( RDebug::Printf( "CMemSpyEngineOutputSinkFile::DisableAllBuffersAfterFileServerResumedL() - END" ) );
|
|
291 |
}
|
|
292 |
|
|
293 |
|
|
294 |
CMemSpyEngineFileHolder& CMemSpyEngineOutputSinkFile::HeadLog() const
|
|
295 |
{
|
|
296 |
// Head log is always the first log
|
|
297 |
const TInt count = iLogs.Count();
|
|
298 |
__ASSERT_ALWAYS( count >= 1, User::Invariant() );
|
|
299 |
CMemSpyEngineFileHolder* headLog = iLogs[ count - 1 ];
|
|
300 |
|
|
301 |
//TRACE( RDebug::Print( _L("CMemSpyEngineOutputSinkFile::HeadLog() - headLog: 0x%08x %S"), headLog, &headLog->FileName() ) );
|
|
302 |
return *headLog;
|
|
303 |
}
|
|
304 |
|
|
305 |
|
|
306 |
|
|
307 |
|
|
308 |
|
|
309 |
|
|
310 |
|
|
311 |
|
|
312 |
|
|
313 |
|
|
314 |
|
|
315 |
|
|
316 |
|
|
317 |
|
|
318 |
|
|
319 |
|
|
320 |
|
|
321 |
|
|
322 |
|
|
323 |
|
|
324 |
|
|
325 |
|
|
326 |
|
|
327 |
|
|
328 |
|
|
329 |
|
|
330 |
|
|
331 |
|
|
332 |
|
|
333 |
|
|
334 |
|
|
335 |
|
|
336 |
|
|
337 |
|
|
338 |
CMemSpyEngineFileHolder::CMemSpyEngineFileHolder( CMemSpyEngineOutputSinkFile& aParent, CMemSpyEngineSinkMetaData* aMetaData )
|
|
339 |
: iParent( aParent ), iMetaData( aMetaData )
|
|
340 |
{
|
|
341 |
}
|
|
342 |
|
|
343 |
|
|
344 |
CMemSpyEngineFileHolder::~CMemSpyEngineFileHolder()
|
|
345 |
{
|
|
346 |
TPtrC pFileName( KNullDesC );
|
|
347 |
if ( iFileName != NULL )
|
|
348 |
{
|
|
349 |
pFileName.Set( *iFileName );
|
|
350 |
}
|
|
351 |
TRACE( RDebug::Print( _L("CMemSpyEngineFileHolder::~CMemSpyEngineFileHolder() - START - this: 0x%08x, iFileName: %S, handle: 0x%08x, iEntireFileBuffer: 0x%08x, iIsMainLog: %d"), this, &pFileName, iFile.SubSessionHandle(), iEntireFileBuffer, iIsMainLog ) );
|
|
352 |
|
|
353 |
if ( iEntireFileBuffer || iWorkingBuffer )
|
|
354 |
{
|
|
355 |
// This may actually open the file
|
|
356 |
TRACE( RDebug::Printf( "CMemSpyEngineFileHolder::~CMemSpyEngineFileHolder() - disabling file buffers..." ) );
|
|
357 |
TRAP_IGNORE( DisableBufferL() );
|
|
358 |
}
|
|
359 |
|
|
360 |
// Now close the file, deleting anything that is empty
|
|
361 |
if ( iFile.SubSessionHandle() != KNullHandle )
|
|
362 |
{
|
|
363 |
TRACE( RDebug::Printf( "CMemSpyEngineFileHolder::~CMemSpyEngineFileHolder() - flushing file..." ) );
|
|
364 |
|
|
365 |
// Flush anything that is pending and then check whether
|
|
366 |
// the file is empty. If so, delete it.
|
|
367 |
iFile.Flush(); // Ignore error
|
|
368 |
|
|
369 |
// Delete empty files
|
|
370 |
TInt size = 0;
|
|
371 |
TInt err = iFile.Size( size );
|
|
372 |
TRACE( RDebug::Printf( "CMemSpyEngineFileHolder::~CMemSpyEngineFileHolder() - size: %d, err: %d", size, err ) );
|
|
373 |
|
|
374 |
if ( err == KErrNone && size == 0 )
|
|
375 |
{
|
|
376 |
// Close the file and get F32 to delete it...
|
|
377 |
TRACE( RDebug::Printf( "CMemSpyEngineFileHolder::~CMemSpyEngineFileHolder() - deleting empty file!" ) );
|
|
378 |
iFile.Close();
|
|
379 |
err = FsSession().Delete( *iFileName );
|
|
380 |
TRACE( RDebug::Printf( "CMemSpyEngineFileHolder::~CMemSpyEngineFileHolder() - delete err: %d", err ) );
|
|
381 |
}
|
|
382 |
}
|
|
383 |
//
|
|
384 |
iFile.Close();
|
|
385 |
//
|
|
386 |
delete iLineBuffer;
|
|
387 |
delete iWorkingBuffer;
|
|
388 |
delete iEntireFileBuffer;
|
|
389 |
TRACE( RDebug::Print( _L("CMemSpyEngineFileHolder::~CMemSpyEngineFileHolder() - END - this: 0x%08x, iFileName: %S, iIsMainLog: %d"), this, &pFileName, iIsMainLog ) );
|
|
390 |
delete iFileName;
|
|
391 |
delete iMetaData;
|
|
392 |
}
|
|
393 |
|
|
394 |
|
|
395 |
void CMemSpyEngineFileHolder::CommonConstructL()
|
|
396 |
{
|
|
397 |
if ( iLineBuffer == NULL )
|
|
398 |
{
|
|
399 |
iLineBuffer = HBufC8::NewL( KMemSpyLineBufferLength );
|
|
400 |
}
|
|
401 |
if ( iWorkingBuffer == NULL )
|
|
402 |
{
|
|
403 |
iWorkingBuffer = CBufFlat::NewL( KMemSpyFileServerBufferExpandSize );
|
|
404 |
}
|
|
405 |
}
|
|
406 |
|
|
407 |
|
|
408 |
void CMemSpyEngineFileHolder::ConstructL()
|
|
409 |
{
|
|
410 |
TRACE( RDebug::Printf( "CMemSpyEngineFileHolder::ConstructL(D) - START" ) );
|
|
411 |
iIsMainLog = ETrue;
|
|
412 |
|
|
413 |
// Make emtpy meta data
|
|
414 |
ASSERT( !iMetaData );
|
|
415 |
iMetaData = CMemSpyEngineSinkMetaData::NewL( iParent.iRoot->Des(), KNullDesC, KNullDesC, KNullDesC, ETrue, ETrue );
|
|
416 |
|
|
417 |
// Prepare common details
|
|
418 |
CommonConstructL();
|
|
419 |
TRACE( RDebug::Printf( "CMemSpyEngineFileHolder::ConstructL(D) - CommonConstructL() completed okay..." ) );
|
|
420 |
|
|
421 |
// Construct the default log file.
|
|
422 |
TRACE( RDebug::Printf( "CMemSpyEngineFileHolder::ConstructL(D) - calling OpenFileL()..." ) );
|
|
423 |
OpenFileL();
|
|
424 |
TRACE( RDebug::Printf( "CMemSpyEngineFileHolder::ConstructL(D) - called OpenFileL()" ) );
|
|
425 |
|
|
426 |
TRACE( RDebug::Printf( "CMemSpyEngineFileHolder::ConstructL(D) - END - iIsMainLog: %d", iIsMainLog ) );
|
|
427 |
}
|
|
428 |
|
|
429 |
|
|
430 |
|
|
431 |
CMemSpyEngineFileHolder* CMemSpyEngineFileHolder::NewLC( CMemSpyEngineOutputSinkFile& aParent )
|
|
432 |
{
|
|
433 |
TRACE( RDebug::Printf( "CMemSpyEngineFileHolder::NewLC() - START") );
|
|
434 |
CMemSpyEngineFileHolder* self = new(ELeave) CMemSpyEngineFileHolder( aParent, NULL );
|
|
435 |
CleanupStack::PushL( self );
|
|
436 |
self->ConstructL();
|
|
437 |
return self;
|
|
438 |
}
|
|
439 |
|
|
440 |
|
|
441 |
CMemSpyEngineFileHolder* CMemSpyEngineFileHolder::NewL( CMemSpyEngineOutputSinkFile& aParent, CMemSpyEngineSinkMetaData* aMetaData )
|
|
442 |
{
|
|
443 |
TRACE( RDebug::Printf( "CMemSpyEngineFileHolder::NewL() - START") );
|
|
444 |
CMemSpyEngineFileHolder* self = new(ELeave) CMemSpyEngineFileHolder( aParent, aMetaData );
|
|
445 |
CleanupStack::PushL( self );
|
|
446 |
self->CommonConstructL();
|
|
447 |
self->OpenFileL();
|
|
448 |
CleanupStack::Pop( self );
|
|
449 |
return self;
|
|
450 |
}
|
|
451 |
|
|
452 |
|
|
453 |
CMemSpyEngineFileHolder* CMemSpyEngineFileHolder::NewLogToRAML( CMemSpyEngineOutputSinkFile& aParent, CMemSpyEngineSinkMetaData* aMetaData )
|
|
454 |
{
|
|
455 |
TRACE( RDebug::Printf( "CMemSpyEngineFileHolder::NewLogToRAML() - START") );
|
|
456 |
CMemSpyEngineFileHolder* self = new(ELeave) CMemSpyEngineFileHolder( aParent, aMetaData );
|
|
457 |
CleanupStack::PushL( self );
|
|
458 |
self->CommonConstructL();
|
|
459 |
self->EnableBufferL();
|
|
460 |
CleanupStack::Pop( self );
|
|
461 |
return self;
|
|
462 |
}
|
|
463 |
|
|
464 |
|
|
465 |
void CMemSpyEngineFileHolder::OpenFileL()
|
|
466 |
{
|
|
467 |
TInt err = KErrNone;
|
|
468 |
|
|
469 |
TRACE( RDebug::Printf( "CMemSpyEngineFileHolder::OpenFileL() - START - iMetaData: 0x%08x", iMetaData ) );
|
|
470 |
ASSERT( iMetaData );
|
|
471 |
|
|
472 |
delete iFileName;
|
|
473 |
iFileName = NULL;
|
|
474 |
if ( iFile.SubSessionHandle() != KNullHandle )
|
|
475 |
{
|
|
476 |
TRACE( RDebug::Printf( "CMemSpyEngineFileHolder::OpenFileL() - closing existing file..." ) );
|
|
477 |
iFile.Flush();
|
|
478 |
iFile.Close();
|
|
479 |
}
|
|
480 |
|
|
481 |
// First try, with current external drive
|
|
482 |
TRAP( err, PrepareFileL() );
|
|
483 |
TRACE( RDebug::Printf( "CMemSpyEngineFileHolder::OpenFileL() - PrepareFileL(1) - err: %d", err ) );
|
|
484 |
|
|
485 |
if ( err != KErrNone )
|
|
486 |
{
|
|
487 |
TRACE( RDebug::Printf( "CMemSpyEngineFileHolder::OpenFileL() - trying with forced C:\\ ..." ) );
|
|
488 |
|
|
489 |
// Try again with C:\ instead...
|
|
490 |
const TDriveNumber cDrive = EDriveC;
|
|
491 |
TRAP(err, PrepareFileL( &cDrive ) );
|
|
492 |
TRACE( RDebug::Printf( "CMemSpyEngineFileHolder::OpenFileL() - PrepareFileL(2) - err: %d", err ) );
|
|
493 |
}
|
|
494 |
|
|
495 |
TRACE( RDebug::Printf( "CMemSpyEngineFileHolder::OpenFileL() - final err: %d", err ) );
|
|
496 |
User::LeaveIfError( err );
|
|
497 |
|
|
498 |
TRACE( RDebug::Printf( "CMemSpyEngineFileHolder::OpenFileL() - END - OK - iIsMainLog: %d", iIsMainLog ) );
|
|
499 |
}
|
|
500 |
|
|
501 |
|
|
502 |
void CMemSpyEngineFileHolder::PrepareFileL( const TDriveNumber* aForceDrive )
|
|
503 |
{
|
|
504 |
TRACE( RDebug::Printf( "CMemSpyEngineFileHolder::PrepareFileL() - START - this: 0x%08x", this ) );
|
|
505 |
ASSERT( iMetaData );
|
|
506 |
|
|
507 |
iFileName = GenerateFileNameLC( aForceDrive );
|
|
508 |
CleanupStack::Pop( iFileName );
|
|
509 |
|
|
510 |
// Try to make log directory - ignore if already exists
|
|
511 |
TInt error = FsSession().MkDirAll( *iFileName );
|
|
512 |
TRACE( RDebug::Print( _L("CMemSpyEngineFileHolder::PrepareFileL() - iFileName: %S, mkDir: %d, aOverwrite: %d"), iFileName, error, iMetaData->Overwrite() ) );
|
|
513 |
|
|
514 |
if ( error == KErrNone || error == KErrAlreadyExists )
|
|
515 |
{
|
|
516 |
if ( iMetaData->Overwrite() )
|
|
517 |
{
|
|
518 |
error = iFile.Replace( FsSession(), *iFileName, EFileWrite );
|
|
519 |
TRACE( RDebug::Printf( "CMemSpyEngineFileHolder::PrepareFileL() - overwrite/replace error: %d", error ) );
|
|
520 |
}
|
|
521 |
else
|
|
522 |
{
|
|
523 |
error = iFile.Open( FsSession(), *iFileName, EFileWrite );
|
|
524 |
TRACE( RDebug::Printf( "CMemSpyEngineFileHolder::PrepareFileL() - open error: %d", error ) );
|
|
525 |
|
|
526 |
// Try creating it then...
|
|
527 |
if ( error == KErrNotFound )
|
|
528 |
{
|
|
529 |
error = iFile.Create( FsSession(), *iFileName, EFileWrite );
|
|
530 |
TRACE( RDebug::Printf( "CMemSpyEngineFileHolder::PrepareFileL() - create error: %d", error ) );
|
|
531 |
}
|
|
532 |
}
|
|
533 |
|
|
534 |
// Seek to end of file
|
|
535 |
TRACE( RDebug::Printf( "CMemSpyEngineFileHolder::PrepareFileL() - final error: %d", error ) );
|
|
536 |
if ( error == KErrNone )
|
|
537 |
{
|
|
538 |
TInt pos = 0;
|
|
539 |
error = iFile.Seek( ESeekEnd, pos );
|
|
540 |
TRACE( RDebug::Printf( "CMemSpyEngineFileHolder::PrepareFileL() - seek error: %d", error ) );
|
|
541 |
}
|
|
542 |
}
|
|
543 |
|
|
544 |
TRACE( RDebug::Printf( "CMemSpyEngineFileHolder::PrepareFileL() - END - this: 0x%08x, error: %d", this, error ) );
|
|
545 |
User::LeaveIfError( error );
|
|
546 |
}
|
|
547 |
|
|
548 |
|
|
549 |
void CMemSpyEngineFileHolder::WriteLineL( const TDesC& aData )
|
|
550 |
{
|
|
551 |
TPtr8 pText( iLineBuffer->Des() );
|
|
552 |
pText.Copy( aData );
|
|
553 |
pText.Append( KMemSpyCRLF );
|
|
554 |
|
|
555 |
if ( iWorkingBuffer != NULL )
|
|
556 |
{
|
|
557 |
AddToWorkingBufferL( pText );
|
|
558 |
}
|
|
559 |
else if ( iFile.SubSessionHandle() != KNullHandle )
|
|
560 |
{
|
|
561 |
const TInt error = iFile.Write( pText );
|
|
562 |
if ( error != KErrNone )
|
|
563 |
{
|
|
564 |
TRACE( RDebug::Printf( "CMemSpyEngineFileHolder::WriteLineL() - FILE WRITE ERROR - this: 0x%08x, error: %d", this, error ) );
|
|
565 |
}
|
|
566 |
User::LeaveIfError( error );
|
|
567 |
}
|
|
568 |
else
|
|
569 |
{
|
|
570 |
TRACE( RDebug::Printf( "CMemSpyEngineFileHolder::WriteLineL() - DISCARDING LINE!" ) );
|
|
571 |
}
|
|
572 |
}
|
|
573 |
|
|
574 |
|
|
575 |
void CMemSpyEngineFileHolder::WriteRawL( const TDesC8& aData )
|
|
576 |
{
|
|
577 |
const TInt error = iFile.Write( aData );
|
|
578 |
User::LeaveIfError( error );
|
|
579 |
}
|
|
580 |
|
|
581 |
|
|
582 |
void CMemSpyEngineFileHolder::EnableBufferL()
|
|
583 |
{
|
|
584 |
TRACE( RDebug::Printf( "CMemSpyEngineFileHolder::EnableBufferL() - START - this: 0x%08x", this ) );
|
|
585 |
if ( iEntireFileBuffer == NULL )
|
|
586 |
{
|
|
587 |
iEntireFileBuffer = CBufFlat::NewL( KMemSpyFileServerBufferExpandSize );
|
|
588 |
}
|
|
589 |
//
|
|
590 |
iEntireFileBuffer->Reset();
|
|
591 |
TRACE( RDebug::Printf( "CMemSpyEngineFileHolder::EnableBufferL() - END - this: 0x%08x", this ) );
|
|
592 |
}
|
|
593 |
|
|
594 |
|
|
595 |
void CMemSpyEngineFileHolder::DisableBufferL()
|
|
596 |
{
|
|
597 |
#ifdef _DEBUG
|
|
598 |
TInt size = 0;
|
|
599 |
if ( iFile.SubSessionHandle() != KNullHandle )
|
|
600 |
{
|
|
601 |
iFile.Size( size );
|
|
602 |
}
|
|
603 |
TInt ramBufferSize = 0;
|
|
604 |
if ( iEntireFileBuffer )
|
|
605 |
{
|
|
606 |
ramBufferSize = iEntireFileBuffer->Size();
|
|
607 |
}
|
|
608 |
//
|
|
609 |
RDebug::Printf( "CMemSpyEngineFileHolder::DisableBufferL() - START - file handle: 0x%08x, iEntireFileBuffer: 0x%08x, fileSize: %d, ramBufferSize: %d", iFile.SubSessionHandle(), iEntireFileBuffer, size, ramBufferSize );
|
|
610 |
#endif
|
|
611 |
|
|
612 |
// This will also open the file if necessary
|
|
613 |
FlushWorkingBufferL();
|
|
614 |
//
|
|
615 |
if ( iEntireFileBuffer != NULL )
|
|
616 |
{
|
|
617 |
// Probably need to open the file...
|
|
618 |
if ( iFile.SubSessionHandle() == KNullHandle )
|
|
619 |
{
|
|
620 |
TRACE( RDebug::Printf( "CMemSpyEngineFileHolder::DisableBufferL() - FILE IS NOT YET OPEN!" ) );
|
|
621 |
OpenFileL();
|
|
622 |
TRACE( RDebug::Printf( "CMemSpyEngineFileHolder::DisableBufferL() - file opened okay." ) );
|
|
623 |
}
|
|
624 |
|
|
625 |
TRACE( RDebug::Print( _L("CMemSpyEngineFileHolder::DisableBufferL() - about to write entire file buffer - file: %S"), &FileName() ) );
|
|
626 |
const TPtr8 pBuffer( iEntireFileBuffer->Ptr( 0 ) );
|
|
627 |
const TInt error = iFile.Write( pBuffer );
|
|
628 |
TRACE( RDebug::Printf( "CMemSpyEngineFileHolder::DisableBufferL() - write result: %d", error ) );
|
|
629 |
//
|
|
630 |
delete iEntireFileBuffer;
|
|
631 |
iEntireFileBuffer = NULL;
|
|
632 |
//
|
|
633 |
User::LeaveIfError( error );
|
|
634 |
}
|
|
635 |
|
|
636 |
TRACE( RDebug::Printf( "CMemSpyEngineFileHolder::DisableBufferL() - END" ) );
|
|
637 |
}
|
|
638 |
|
|
639 |
|
62
|
640 |
void CMemSpyEngineFileHolder::FlushL()
|
|
641 |
{
|
|
642 |
FlushWorkingBufferL();
|
|
643 |
}
|
|
644 |
|
51
|
645 |
void CMemSpyEngineFileHolder::FlushWorkingBufferL()
|
|
646 |
{
|
|
647 |
TRACE( RDebug::Print( _L("CMemSpyEngineFileHolder::FlushWorkingBufferL() - START - fileName: [%S], file handle: 0x%08x, iWorkingBuffer: 0x%08x"), &FileName(), iFile.SubSessionHandle(), iWorkingBuffer ) );
|
|
648 |
__ASSERT_ALWAYS( iWorkingBuffer, MemSpyEngineUtils::Panic( EMemSpyEnginePanicSinkFileWorkingFileBufferIsNull ) );
|
|
649 |
|
|
650 |
// The underlying file may not be open - it could be that we are buffering everything
|
|
651 |
// to RAM (i.e. the file server is currently suspended).
|
|
652 |
const TPtr8 pBuffer( iWorkingBuffer->Ptr(0) );
|
|
653 |
//
|
|
654 |
if ( iEntireFileBuffer )
|
|
655 |
{
|
|
656 |
__ASSERT_ALWAYS( iEntireFileBuffer, MemSpyEngineUtils::Panic( EMemSpyEnginePanicSinkFileEntireFileBufferNull ) );
|
|
657 |
|
|
658 |
TRACE( RDebug::Printf( "CMemSpyEngineFileHolder::FlushWorkingBufferL() - file not open or we are currently bufferring to RAM - copying %d bytes to entire file buffer (%d)", pBuffer.Length(), iEntireFileBuffer->Size() ) );
|
|
659 |
iEntireFileBuffer->InsertL( iEntireFileBuffer->Size(), pBuffer );
|
|
660 |
}
|
|
661 |
else if ( iFile.SubSessionHandle() != KNullHandle )
|
|
662 |
{
|
|
663 |
const TInt error = iFile.Write( pBuffer );
|
|
664 |
if ( error != KErrNone )
|
|
665 |
{
|
|
666 |
TRACE( RDebug::Printf( "CMemSpyEngineFileHolder::FlushWorkingBufferL() - write result: %d", error ) );
|
|
667 |
}
|
|
668 |
User::LeaveIfError( error );
|
|
669 |
}
|
|
670 |
|
|
671 |
iWorkingBuffer->Reset();
|
|
672 |
TRACE( RDebug::Print( _L("CMemSpyEngineFileHolder::FlushWorkingBufferL() - END - fileName: %S"), &FileName() ) );
|
|
673 |
}
|
|
674 |
|
|
675 |
|
|
676 |
void CMemSpyEngineFileHolder::AddToWorkingBufferL( const TDesC8& aText )
|
|
677 |
{
|
|
678 |
if ( iWorkingBuffer->Size() + aText.Length() > KMemSpyFileServerBufferExpandSize )
|
|
679 |
{
|
|
680 |
FlushWorkingBufferL();
|
|
681 |
}
|
|
682 |
//
|
|
683 |
iWorkingBuffer->InsertL( iWorkingBuffer->Size(), aText );
|
|
684 |
}
|
|
685 |
|
|
686 |
|
|
687 |
HBufC* CMemSpyEngineFileHolder::CleanContextInfoLC( const TDesC& aContext )
|
|
688 |
{
|
|
689 |
TRACE( RDebug::Print( _L("CMemSpyEngineFileHolder::CleanContextInfoLC() - START - %S"), &aContext ) );
|
|
690 |
TFileName fileName;
|
|
691 |
|
|
692 |
TBool seenDoubleColon = EFalse;
|
|
693 |
const TInt length = aContext.Length();
|
|
694 |
for( TInt i=0; i<length; i++ )
|
|
695 |
{
|
|
696 |
const TChar c( aContext[ i ] );
|
|
697 |
const TBool haveNextChar = ( i+1 < length );
|
|
698 |
//
|
|
699 |
//TRACE( RDebug::Print( _L("CMemSpyEngineFileHolder::CleanContextInfoLC() - c[%03d]: \'%c\', haveNextChar: %d, seenDoubleColon: %d"), i, (TUint32) c, haveNextChar, seenDoubleColon ) );
|
|
700 |
//
|
|
701 |
if ( c == ':' && haveNextChar && aContext[ i + 1 ] == ':' )
|
|
702 |
{
|
|
703 |
// Skip double colon
|
|
704 |
i++;
|
|
705 |
fileName.Append( '-' );
|
|
706 |
seenDoubleColon = ETrue;
|
|
707 |
}
|
|
708 |
else if ( c == '.' )
|
|
709 |
{
|
|
710 |
if ( seenDoubleColon )
|
|
711 |
{
|
|
712 |
break;
|
|
713 |
}
|
|
714 |
else
|
|
715 |
{
|
|
716 |
fileName.Append( '-' );
|
|
717 |
}
|
|
718 |
}
|
|
719 |
else
|
|
720 |
{
|
|
721 |
fileName.Append( c );
|
|
722 |
}
|
|
723 |
}
|
|
724 |
|
|
725 |
TRACE( RDebug::Print( _L("CMemSpyEngineFileHolder::CleanContextInfoLC() - END - %S"), &fileName ) );
|
|
726 |
return fileName.AllocLC();
|
|
727 |
}
|
|
728 |
|
|
729 |
|
|
730 |
HBufC* CMemSpyEngineFileHolder::GenerateFileNameLC( const TDriveNumber* aForceDrive )
|
|
731 |
{
|
|
732 |
TFileName name;
|
|
733 |
MemSpyEngineUtils::GetFolderL( FsSession(), name, *iMetaData, aForceDrive );
|
|
734 |
return name.AllocLC();
|
|
735 |
}
|
|
736 |
|
|
737 |
|
|
738 |
RFs& CMemSpyEngineFileHolder::FsSession()
|
|
739 |
{
|
|
740 |
return iParent.iFsSession;
|
|
741 |
}
|
|
742 |
|
|
743 |
|
|
744 |
const TDesC& CMemSpyEngineFileHolder::FileName() const
|
|
745 |
{
|
|
746 |
if ( iFileName )
|
|
747 |
{
|
|
748 |
return *iFileName;
|
|
749 |
}
|
|
750 |
//
|
|
751 |
return KNullDesC;
|
|
752 |
}
|
|
753 |
|