perfsrv/piprofiler/plugins/DiskWriterPlugin/src/DiskWriterPlugin.cpp
author hgs
Tue, 26 Oct 2010 16:20:32 +0300
changeset 62 1c2bb2fc7c87
parent 51 98307c651589
permissions -rw-r--r--
201043
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
20
hgs
parents:
diff changeset
     1
/*
hgs
parents:
diff changeset
     2
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
hgs
parents:
diff changeset
     3
* All rights reserved.
hgs
parents:
diff changeset
     4
* This component and the accompanying materials are made available
hgs
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
hgs
parents:
diff changeset
     6
* which accompanies this distribution, and is available
hgs
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
hgs
parents:
diff changeset
     8
*
hgs
parents:
diff changeset
     9
* Initial Contributors:
hgs
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
hgs
parents:
diff changeset
    11
*
hgs
parents:
diff changeset
    12
* Contributors:
hgs
parents:
diff changeset
    13
*
hgs
parents:
diff changeset
    14
* Description:  
hgs
parents:
diff changeset
    15
*
hgs
parents:
diff changeset
    16
*/
hgs
parents:
diff changeset
    17
hgs
parents:
diff changeset
    18
hgs
parents:
diff changeset
    19
//  Include Files  
hgs
parents:
diff changeset
    20
hgs
parents:
diff changeset
    21
#include "DiskWriterPlugin.h"	// CDiskWriterPlugin
hgs
parents:
diff changeset
    22
#include <e32base.h>
hgs
parents:
diff changeset
    23
#include <sysutil.h>
hgs
parents:
diff changeset
    24
//#include <piprofiler/EngineUIDs.h>
hgs
parents:
diff changeset
    25
hgs
parents:
diff changeset
    26
// constants
hgs
parents:
diff changeset
    27
const TUid KDiskWriterPluginUid = { 0x2001E5BB };   // own UID
hgs
parents:
diff changeset
    28
hgs
parents:
diff changeset
    29
// engine properties
hgs
parents:
diff changeset
    30
const TUid KEngineStatusPropertyCat={0x2001E5AD};
hgs
parents:
diff changeset
    31
enum TEnginePropertyKeys
hgs
parents:
diff changeset
    32
    {
hgs
parents:
diff changeset
    33
    EProfilerEngineStatus = 8,
hgs
parents:
diff changeset
    34
    EProfilerErrorStatus
hgs
parents:
diff changeset
    35
    };
hgs
parents:
diff changeset
    36
hgs
parents:
diff changeset
    37
/*
hgs
parents:
diff changeset
    38
 *
hgs
parents:
diff changeset
    39
 *	Class CDiskWriterPlugin implementation
hgs
parents:
diff changeset
    40
 *
hgs
parents:
diff changeset
    41
 */
hgs
parents:
diff changeset
    42
hgs
parents:
diff changeset
    43
//  Member Functions
62
hgs
parents: 51
diff changeset
    44
EXPORT_C CDiskWriterPlugin* CDiskWriterPlugin::NewL(const TUid /*aImplementationUid*/, TAny* /*aInitParams*/)
20
hgs
parents:
diff changeset
    45
    {
hgs
parents:
diff changeset
    46
	LOGTEXT(_L("CDiskWriterPlugin::NewL() - entry"));
hgs
parents:
diff changeset
    47
	CDiskWriterPlugin* self = new (ELeave) CDiskWriterPlugin(KDiskWriterPluginUid);
hgs
parents:
diff changeset
    48
    CleanupStack::PushL( self );
hgs
parents:
diff changeset
    49
    self->ConstructL();
hgs
parents:
diff changeset
    50
    CleanupStack::Pop();
hgs
parents:
diff changeset
    51
	LOGTEXT(_L("CDiskWriterPlugin::NewL() - exit"));
hgs
parents:
diff changeset
    52
    return self;
hgs
parents:
diff changeset
    53
    }
hgs
parents:
diff changeset
    54
hgs
parents:
diff changeset
    55
CDiskWriterPlugin::CDiskWriterPlugin(const TUid aImplementationUid) :
hgs
parents:
diff changeset
    56
	iWriterType(aImplementationUid.iUid)
hgs
parents:
diff changeset
    57
    {
hgs
parents:
diff changeset
    58
    LOGTEXT(_L("CDiskWriterPlugin::CDiskWriterPlugin - entry"));
hgs
parents:
diff changeset
    59
    isEnabled = EFalse;
hgs
parents:
diff changeset
    60
    iWriterId = Id().iUid;
hgs
parents:
diff changeset
    61
    LOGTEXT(_L("CDiskWriterPlugin::CDiskWriterPlugin - exit"));
hgs
parents:
diff changeset
    62
    }
hgs
parents:
diff changeset
    63
hgs
parents:
diff changeset
    64
CDiskWriterPlugin::~CDiskWriterPlugin()
hgs
parents:
diff changeset
    65
    {
hgs
parents:
diff changeset
    66
    LOGTEXT(_L("CDiskWriterPlugin::~CDiskWriterPlugin - entry"));
hgs
parents:
diff changeset
    67
hgs
parents:
diff changeset
    68
    iErrorStatus.Close();
hgs
parents:
diff changeset
    69
    
hgs
parents:
diff changeset
    70
    if(iWriterHandler)
hgs
parents:
diff changeset
    71
        {
hgs
parents:
diff changeset
    72
        iWriterHandler->Cancel();
hgs
parents:
diff changeset
    73
        delete iWriterHandler;
hgs
parents:
diff changeset
    74
        }
hgs
parents:
diff changeset
    75
    LOGTEXT(_L("CDiskWriterPlugin::~CDiskWriterPlugin - exit"));
hgs
parents:
diff changeset
    76
    }
hgs
parents:
diff changeset
    77
hgs
parents:
diff changeset
    78
void CDiskWriterPlugin::ConstructL()
hgs
parents:
diff changeset
    79
	{
hgs
parents:
diff changeset
    80
	// second phase constructor, anything that may leave must be constructed here
hgs
parents:
diff changeset
    81
	LOGTEXT(_L("CDiskWriterPlugin::ConstructL() - entry"));
hgs
parents:
diff changeset
    82
	iWriterHandler = CDiskWriterHandler::NewL(this);
hgs
parents:
diff changeset
    83
	User::LeaveIfError(iErrorStatus.Attach(KEngineStatusPropertyCat, EProfilerErrorStatus));
hgs
parents:
diff changeset
    84
	LOGTEXT(_L("CDiskWriterPlugin::ConstructL() - exit"));
hgs
parents:
diff changeset
    85
	}
hgs
parents:
diff changeset
    86
hgs
parents:
diff changeset
    87
TUid CDiskWriterPlugin::Id() const 
hgs
parents:
diff changeset
    88
	{
hgs
parents:
diff changeset
    89
    LOGSTRING2("CDiskWriterPlugin::Id():0x%X", KDiskWriterPluginUid.iUid );
hgs
parents:
diff changeset
    90
    return KDiskWriterPluginUid;
hgs
parents:
diff changeset
    91
	}
hgs
parents:
diff changeset
    92
	 
hgs
parents:
diff changeset
    93
void CDiskWriterPlugin::GetWriterVersion(TDes* aDes)
hgs
parents:
diff changeset
    94
	{
hgs
parents:
diff changeset
    95
	_LIT(KDiskWriterVersion, "1.0.0");
hgs
parents:
diff changeset
    96
	aDes->Append(KDiskWriterVersion);
hgs
parents:
diff changeset
    97
	}
hgs
parents:
diff changeset
    98
hgs
parents:
diff changeset
    99
TInt CDiskWriterPlugin::Start()
hgs
parents:
diff changeset
   100
	{
hgs
parents:
diff changeset
   101
//	if(isEnabled)
hgs
parents:
diff changeset
   102
//		{
hgs
parents:
diff changeset
   103
//		TRAPD(err, iWriterHandler->StartL());
hgs
parents:
diff changeset
   104
//		if( err != KErrNone)
hgs
parents:
diff changeset
   105
//		    {
hgs
parents:
diff changeset
   106
//		    LOGTEXT(_L("Could not start writer plugin"));
hgs
parents:
diff changeset
   107
//		    return err;
hgs
parents:
diff changeset
   108
//		    }
hgs
parents:
diff changeset
   109
//		}
hgs
parents:
diff changeset
   110
	return KErrNone;
hgs
parents:
diff changeset
   111
	}
hgs
parents:
diff changeset
   112
hgs
parents:
diff changeset
   113
void CDiskWriterPlugin::Stop()
hgs
parents:
diff changeset
   114
	{
hgs
parents:
diff changeset
   115
	// stop writer handler normally
hgs
parents:
diff changeset
   116
	iWriterHandler->Stop();
hgs
parents:
diff changeset
   117
	}
hgs
parents:
diff changeset
   118
hgs
parents:
diff changeset
   119
TBool CDiskWriterPlugin::GetEnabled()
hgs
parents:
diff changeset
   120
	{
hgs
parents:
diff changeset
   121
	return isEnabled;
hgs
parents:
diff changeset
   122
	}
hgs
parents:
diff changeset
   123
hgs
parents:
diff changeset
   124
TUint32 CDiskWriterPlugin::GetWriterType()
hgs
parents:
diff changeset
   125
	{
hgs
parents:
diff changeset
   126
	return iWriterType;
hgs
parents:
diff changeset
   127
	}
hgs
parents:
diff changeset
   128
hgs
parents:
diff changeset
   129
hgs
parents:
diff changeset
   130
void CDiskWriterPlugin::SetValue( const TWriterPluginValueKeys aKey,
hgs
parents:
diff changeset
   131
                                    TDes& aValue )
hgs
parents:
diff changeset
   132
    {
hgs
parents:
diff changeset
   133
    TRAP_IGNORE( SetValueL( aKey, aValue ) );
hgs
parents:
diff changeset
   134
    }
hgs
parents:
diff changeset
   135
hgs
parents:
diff changeset
   136
hgs
parents:
diff changeset
   137
void CDiskWriterPlugin::GetValue( const TWriterPluginValueKeys aKey,
hgs
parents:
diff changeset
   138
                                    TDes& aValue )
hgs
parents:
diff changeset
   139
    {
hgs
parents:
diff changeset
   140
    TRAP_IGNORE( GetValueL( aKey, aValue ) );
hgs
parents:
diff changeset
   141
    }
hgs
parents:
diff changeset
   142
hgs
parents:
diff changeset
   143
void CDiskWriterPlugin::SetValueL( const TWriterPluginValueKeys aKey, TDes& aValue )
hgs
parents:
diff changeset
   144
    {
hgs
parents:
diff changeset
   145
    TInt error(KErrNone);
hgs
parents:
diff changeset
   146
    
hgs
parents:
diff changeset
   147
    switch( aKey )
hgs
parents:
diff changeset
   148
        {
hgs
parents:
diff changeset
   149
        case EWriterPluginEnabled:
hgs
parents:
diff changeset
   150
            isEnabled = ETrue;
hgs
parents:
diff changeset
   151
        	LOGTEXT(_L("CDebOutWriterPlugin::SetValueL - plugin enabled"));
hgs
parents:
diff changeset
   152
        	break;
hgs
parents:
diff changeset
   153
        case EWriterPluginDisabled:
hgs
parents:
diff changeset
   154
            isEnabled = EFalse;
hgs
parents:
diff changeset
   155
        	LOGTEXT(_L("CDebOutWriterPlugin::SetValueL - plugin disabled"));	
hgs
parents:
diff changeset
   156
            break;
hgs
parents:
diff changeset
   157
        case EWriterPluginSettings:	// file name in case of disk writer plugin
hgs
parents:
diff changeset
   158
        	iFileName.Zero();
hgs
parents:
diff changeset
   159
        	iFileName.Append(aValue);
hgs
parents:
diff changeset
   160
        	error = iWriterHandler->TestFile(iFileName);
hgs
parents:
diff changeset
   161
        		User::LeaveIfError(error);
hgs
parents:
diff changeset
   162
        	break;
hgs
parents:
diff changeset
   163
        default:
hgs
parents:
diff changeset
   164
        	break;
hgs
parents:
diff changeset
   165
        }
hgs
parents:
diff changeset
   166
    }
hgs
parents:
diff changeset
   167
hgs
parents:
diff changeset
   168
void CDiskWriterPlugin::GetValueL( const TWriterPluginValueKeys aKey, TDes& aValue )
hgs
parents:
diff changeset
   169
    {
hgs
parents:
diff changeset
   170
    switch( aKey )
hgs
parents:
diff changeset
   171
        {
hgs
parents:
diff changeset
   172
        case EWriterPluginVersion:
hgs
parents:
diff changeset
   173
        	GetWriterVersion(&aValue);
hgs
parents:
diff changeset
   174
        	break;
hgs
parents:
diff changeset
   175
        case EWriterPluginType:
hgs
parents:
diff changeset
   176
        	break;
hgs
parents:
diff changeset
   177
        case EWriterPluginSettings:	// file name in disk writer case
hgs
parents:
diff changeset
   178
        	aValue.Copy(iFileName);
hgs
parents:
diff changeset
   179
           default:
hgs
parents:
diff changeset
   180
                break;
hgs
parents:
diff changeset
   181
        }
hgs
parents:
diff changeset
   182
    }
hgs
parents:
diff changeset
   183
hgs
parents:
diff changeset
   184
void CDiskWriterPlugin::DoCancel()
hgs
parents:
diff changeset
   185
    {
hgs
parents:
diff changeset
   186
	LOGTEXT(_L("CDebOutWriterPlugin::DoCancel - entry"));
hgs
parents:
diff changeset
   187
    }
hgs
parents:
diff changeset
   188
hgs
parents:
diff changeset
   189
void CDiskWriterPlugin::WriteData()
hgs
parents:
diff changeset
   190
    {
hgs
parents:
diff changeset
   191
    // Activate handler to write data from buffer to output
hgs
parents:
diff changeset
   192
    LOGTEXT(_L("CDiskWriterPlugin::WriteData() - entry"));
hgs
parents:
diff changeset
   193
    TRAP_IGNORE(iWriterHandler->StartL());
hgs
parents:
diff changeset
   194
    LOGTEXT(_L("CDiskWriterPlugin::WriteData() - exit"));
hgs
parents:
diff changeset
   195
    }
hgs
parents:
diff changeset
   196
hgs
parents:
diff changeset
   197
void CDiskWriterPlugin::HandleError(TInt aError)
hgs
parents:
diff changeset
   198
    {
hgs
parents:
diff changeset
   199
    TInt err(KErrNone);
hgs
parents:
diff changeset
   200
    RDebug::Print(_L("CDiskWriterPlugin::HandleError() - error received: %d"), aError);
hgs
parents:
diff changeset
   201
    err = iErrorStatus.Set(aError);
hgs
parents:
diff changeset
   202
    if(err != KErrNone)
hgs
parents:
diff changeset
   203
        {
hgs
parents:
diff changeset
   204
        RDebug::Print(_L("CDiskWriterPlugin::HandleError() - error in updating property: %d"), err);
hgs
parents:
diff changeset
   205
        }
hgs
parents:
diff changeset
   206
    }
hgs
parents:
diff changeset
   207
hgs
parents:
diff changeset
   208
/*
hgs
parents:
diff changeset
   209
 * 
hgs
parents:
diff changeset
   210
 * Implementation of class CDiskWriterHandler
hgs
parents:
diff changeset
   211
 * 
hgs
parents:
diff changeset
   212
 */
hgs
parents:
diff changeset
   213
hgs
parents:
diff changeset
   214
CDiskWriterHandler* CDiskWriterHandler::NewL(CDiskWriterPlugin* aWriter)
hgs
parents:
diff changeset
   215
    {
hgs
parents:
diff changeset
   216
	LOGTEXT(_L("CDiskWriterHandler::NewL() - entry"));
hgs
parents:
diff changeset
   217
	CDiskWriterHandler* self = new (ELeave) CDiskWriterHandler(aWriter);
hgs
parents:
diff changeset
   218
    CleanupStack::PushL( self );
hgs
parents:
diff changeset
   219
    self->ConstructL();
hgs
parents:
diff changeset
   220
    CleanupStack::Pop();
hgs
parents:
diff changeset
   221
	LOGTEXT(_L("CDiskWriterHandler::NewL() - exit"));
hgs
parents:
diff changeset
   222
    return self;
hgs
parents:
diff changeset
   223
    }
hgs
parents:
diff changeset
   224
hgs
parents:
diff changeset
   225
CDiskWriterHandler::CDiskWriterHandler(CDiskWriterPlugin* aWriter)  :
hgs
parents:
diff changeset
   226
    CActive(EPriorityStandard)
hgs
parents:
diff changeset
   227
    {
hgs
parents:
diff changeset
   228
    LOGTEXT(_L("CDiskWriterHandler::CDiskWriterHandler - entry"));
hgs
parents:
diff changeset
   229
hgs
parents:
diff changeset
   230
    iWriter = aWriter;
hgs
parents:
diff changeset
   231
    
hgs
parents:
diff changeset
   232
    // set initial mode to non-stopping
hgs
parents:
diff changeset
   233
    iStopping = EFalse;
hgs
parents:
diff changeset
   234
    
hgs
parents:
diff changeset
   235
    // add the handler to the active scheduler
hgs
parents:
diff changeset
   236
    CActiveScheduler::Add(this);
hgs
parents:
diff changeset
   237
    
hgs
parents:
diff changeset
   238
    LOGTEXT(_L("CDiskWriterHandler::CDiskWriterHandler - exit"));
hgs
parents:
diff changeset
   239
    }
hgs
parents:
diff changeset
   240
hgs
parents:
diff changeset
   241
hgs
parents:
diff changeset
   242
CDiskWriterHandler::~CDiskWriterHandler()
hgs
parents:
diff changeset
   243
    {
hgs
parents:
diff changeset
   244
	LOGTEXT(_L("CDiskWriterHandler::~CDiskWriterHandler - entry"));
hgs
parents:
diff changeset
   245
hgs
parents:
diff changeset
   246
	LOGTEXT(_L("CDiskWriterHandler::~CDiskWriterHandler - exit"));
hgs
parents:
diff changeset
   247
    }    
hgs
parents:
diff changeset
   248
    
hgs
parents:
diff changeset
   249
void CDiskWriterHandler::ConstructL()
hgs
parents:
diff changeset
   250
	{
hgs
parents:
diff changeset
   251
	}
hgs
parents:
diff changeset
   252
hgs
parents:
diff changeset
   253
TInt CDiskWriterHandler::TestFile(const TDesC& totalPrefix) 
hgs
parents:
diff changeset
   254
    {
hgs
parents:
diff changeset
   255
    TParse parse;
hgs
parents:
diff changeset
   256
hgs
parents:
diff changeset
   257
    TInt err(KErrNone);
hgs
parents:
diff changeset
   258
    if((err = parse.Set(totalPrefix, NULL, NULL)) != KErrNone)
hgs
parents:
diff changeset
   259
        return err;
hgs
parents:
diff changeset
   260
hgs
parents:
diff changeset
   261
    err = iFs.Connect();
hgs
parents:
diff changeset
   262
    if(err != KErrNone)
hgs
parents:
diff changeset
   263
        {
hgs
parents:
diff changeset
   264
        LOGTEXT(_L("CDiskWriterHandler::TestFile() - Failed to open a session to file server"));
hgs
parents:
diff changeset
   265
        return KErrNotFound;
hgs
parents:
diff changeset
   266
        }
hgs
parents:
diff changeset
   267
    
hgs
parents:
diff changeset
   268
    iFs.MkDirAll(parse.FullName());
hgs
parents:
diff changeset
   269
    
hgs
parents:
diff changeset
   270
    err = iFile.Replace(iFs,parse.FullName(),EFileWrite);
hgs
parents:
diff changeset
   271
    if(err != KErrNone)
hgs
parents:
diff changeset
   272
        {
hgs
parents:
diff changeset
   273
        iFs.Close();
hgs
parents:
diff changeset
   274
        return KErrNotFound;
hgs
parents:
diff changeset
   275
        }
hgs
parents:
diff changeset
   276
    
hgs
parents:
diff changeset
   277
    iFileName.Copy(parse.FullName());
hgs
parents:
diff changeset
   278
hgs
parents:
diff changeset
   279
    return KErrNone;
hgs
parents:
diff changeset
   280
    }
hgs
parents:
diff changeset
   281
hgs
parents:
diff changeset
   282
void CDiskWriterHandler::Reset()
hgs
parents:
diff changeset
   283
    {
hgs
parents:
diff changeset
   284
    // cancel active object
hgs
parents:
diff changeset
   285
    Cancel();
hgs
parents:
diff changeset
   286
    
hgs
parents:
diff changeset
   287
    // start writing new buffer if there is one available
hgs
parents:
diff changeset
   288
    TBapBuf* nextBuf = iWriter->iStream->GetNextFilledBuffer();
hgs
parents:
diff changeset
   289
    
hgs
parents:
diff changeset
   290
    // empty the rest of the buffers synchronously
hgs
parents:
diff changeset
   291
    while(nextBuf != 0)
hgs
parents:
diff changeset
   292
        {
hgs
parents:
diff changeset
   293
        LOGTEXT(_L("CDiskWriterHandler::Reset - writing to file"));
hgs
parents:
diff changeset
   294
        if(nextBuf->iDataSize != 0)
hgs
parents:
diff changeset
   295
            {
hgs
parents:
diff changeset
   296
            LOGTEXT(_L("CDiskWriterHandler::Reset - writing to file"));
hgs
parents:
diff changeset
   297
            WriteMemBufferToFile(*(nextBuf->iBufDes),iStatus);
hgs
parents:
diff changeset
   298
            }
hgs
parents:
diff changeset
   299
        
hgs
parents:
diff changeset
   300
        // empty buffers when profiling stopped
hgs
parents:
diff changeset
   301
        iWriter->iStream->AddToFreeBuffers(nextBuf);
hgs
parents:
diff changeset
   302
hgs
parents:
diff changeset
   303
        LOGTEXT(_L("CDiskWriterHandler::Reset - get next full buffer"));
hgs
parents:
diff changeset
   304
        // start writing new buffer if there is one available
hgs
parents:
diff changeset
   305
        nextBuf = iWriter->iStream->GetNextFilledBuffer();
hgs
parents:
diff changeset
   306
        LOGSTRING2("CDiskWriterHandler::Reset - got next filled 0x%x",nextBuf);
hgs
parents:
diff changeset
   307
        }
hgs
parents:
diff changeset
   308
    }
hgs
parents:
diff changeset
   309
hgs
parents:
diff changeset
   310
void CDiskWriterHandler::HandleFullBuffers()
hgs
parents:
diff changeset
   311
    {
hgs
parents:
diff changeset
   312
    LOGTEXT(_L("CDiskWriterHandler::HandleFullBuffers - entry"));
hgs
parents:
diff changeset
   313
    // previous write operation has finished
hgs
parents:
diff changeset
   314
    // release the previous buffer 
hgs
parents:
diff changeset
   315
    iWriter->iStream->AddToFreeBuffers(iBufferBeingWritten);
hgs
parents:
diff changeset
   316
hgs
parents:
diff changeset
   317
    LOGTEXT(_L("CDiskWriterHandler::HandleFullBuffers - get next full buffer"));
hgs
parents:
diff changeset
   318
    // start writing new buffer if there is one available
hgs
parents:
diff changeset
   319
    TBapBuf* nextBuf = iWriter->iStream->GetNextFilledBuffer();
hgs
parents:
diff changeset
   320
hgs
parents:
diff changeset
   321
    if(nextBuf != 0)
hgs
parents:
diff changeset
   322
        {
hgs
parents:
diff changeset
   323
        LOGTEXT(_L("CDiskWriterHandler::HandleFullBuffers - writing to file"));
hgs
parents:
diff changeset
   324
        if(nextBuf->iDataSize != 0)
hgs
parents:
diff changeset
   325
            {
hgs
parents:
diff changeset
   326
            WriteBufferToOutput(nextBuf);
hgs
parents:
diff changeset
   327
            }
hgs
parents:
diff changeset
   328
        } 
hgs
parents:
diff changeset
   329
    LOGTEXT(_L("CDiskWriterHandler::HandleFullBuffers - exit"));
hgs
parents:
diff changeset
   330
    }
hgs
parents:
diff changeset
   331
hgs
parents:
diff changeset
   332
void CDiskWriterHandler::RunL()
hgs
parents:
diff changeset
   333
    {
hgs
parents:
diff changeset
   334
    LOGTEXT(_L("CDiskWriterHandler::RunL - entry"));
hgs
parents:
diff changeset
   335
    // call function to complete full buffer handling
hgs
parents:
diff changeset
   336
    HandleFullBuffers();
hgs
parents:
diff changeset
   337
    LOGTEXT(_L("CDiskWriterHandler::RunL - exit"));
hgs
parents:
diff changeset
   338
    }
hgs
parents:
diff changeset
   339
hgs
parents:
diff changeset
   340
void CDiskWriterHandler::DoCancel()
hgs
parents:
diff changeset
   341
    {
hgs
parents:
diff changeset
   342
    
hgs
parents:
diff changeset
   343
    }
hgs
parents:
diff changeset
   344
hgs
parents:
diff changeset
   345
//-----------------------------------------------------------------------------
hgs
parents:
diff changeset
   346
// CPIProfilerTraceCoreLauncher::RunError(TInt aError)
hgs
parents:
diff changeset
   347
// Handle leaves from RunL().
hgs
parents:
diff changeset
   348
//-----------------------------------------------------------------------------
hgs
parents:
diff changeset
   349
TInt CDiskWriterHandler::RunError(TInt aError)
hgs
parents:
diff changeset
   350
    {
hgs
parents:
diff changeset
   351
    // no reason to continue if disk full or removed
hgs
parents:
diff changeset
   352
    iFile.Close();
hgs
parents:
diff changeset
   353
    // close handle to file server too
hgs
parents:
diff changeset
   354
    iFs.Close();
hgs
parents:
diff changeset
   355
    iFileName.Zero();
hgs
parents:
diff changeset
   356
    
hgs
parents:
diff changeset
   357
    iWriter->HandleError(KErrDiskFull);
hgs
parents:
diff changeset
   358
    return aError;
hgs
parents:
diff changeset
   359
    }
hgs
parents:
diff changeset
   360
hgs
parents:
diff changeset
   361
void CDiskWriterHandler::WriteMemBufferToFile(TDesC8& aDes, TRequestStatus& aStatus)
hgs
parents:
diff changeset
   362
    {   
hgs
parents:
diff changeset
   363
    LOGTEXT(_L("CDiskWriterPlugin::WriteMemBufferToFile - entry"));
hgs
parents:
diff changeset
   364
hgs
parents:
diff changeset
   365
    TUint sampleSize(aDes.Length());
hgs
parents:
diff changeset
   366
    TInt err(KErrNone);
hgs
parents:
diff changeset
   367
    TInt drive(0);
hgs
parents:
diff changeset
   368
    TDriveInfo info;
hgs
parents:
diff changeset
   369
    TBool noDiskSpace(EFalse);
hgs
parents:
diff changeset
   370
    
hgs
parents:
diff changeset
   371
    err = iFile.Drive(drive,info);
hgs
parents:
diff changeset
   372
hgs
parents:
diff changeset
   373
    // test available disk space 
hgs
parents:
diff changeset
   374
    TRAP_IGNORE((noDiskSpace = SysUtil::DiskSpaceBelowCriticalLevelL(&iFs, sampleSize, drive))); 
hgs
parents:
diff changeset
   375
    // check first if still space on disk
hgs
parents:
diff changeset
   376
    if(noDiskSpace)
hgs
parents:
diff changeset
   377
        {
hgs
parents:
diff changeset
   378
        // set error to disk full
hgs
parents:
diff changeset
   379
        err = KErrDiskFull;
hgs
parents:
diff changeset
   380
        LOGTEXT(_L("CDiskWriterPlugin::WriteMemBufferToFile - disk full, cannot write"));
hgs
parents:
diff changeset
   381
        }
hgs
parents:
diff changeset
   382
    else
hgs
parents:
diff changeset
   383
        {
hgs
parents:
diff changeset
   384
        // check if profiling in stopping mode
hgs
parents:
diff changeset
   385
        if(iStopping)
hgs
parents:
diff changeset
   386
            {
hgs
parents:
diff changeset
   387
            // RDebug::Print(_L("CDiskWriterPlugin::WriteMemBufferToFile - data written, length %d, stopping"), aDes.Length());
hgs
parents:
diff changeset
   388
            // write to file without status
hgs
parents:
diff changeset
   389
            err = iFile.Write(aDes);
hgs
parents:
diff changeset
   390
            }
hgs
parents:
diff changeset
   391
        else
hgs
parents:
diff changeset
   392
            {
hgs
parents:
diff changeset
   393
            // RDebug::Print(_L("CDiskWriterPlugin::WriteMemBufferToFile - data written, length %d"), aDes.Length());
hgs
parents:
diff changeset
   394
            // write to file with status
hgs
parents:
diff changeset
   395
            iFile.Write(aDes,aStatus);
hgs
parents:
diff changeset
   396
            }
hgs
parents:
diff changeset
   397
        }
hgs
parents:
diff changeset
   398
    
hgs
parents:
diff changeset
   399
    // check if error in write
hgs
parents:
diff changeset
   400
    if(err != KErrNone)
hgs
parents:
diff changeset
   401
        {
hgs
parents:
diff changeset
   402
        // stop writer handler (and its timer) immediately, DO NOT try write data!
hgs
parents:
diff changeset
   403
        Cancel();
hgs
parents:
diff changeset
   404
        
hgs
parents:
diff changeset
   405
        // no reason to continue if disk full or removed
hgs
parents:
diff changeset
   406
        // end of stream detected, file can be closed
hgs
parents:
diff changeset
   407
        iFile.Close();
hgs
parents:
diff changeset
   408
        // close handle to file server too
hgs
parents:
diff changeset
   409
        iFs.Close();
hgs
parents:
diff changeset
   410
        iFileName.Zero();
hgs
parents:
diff changeset
   411
        
hgs
parents:
diff changeset
   412
        // set error status for engine to read
hgs
parents:
diff changeset
   413
        iWriter->HandleError(err);
hgs
parents:
diff changeset
   414
        }
hgs
parents:
diff changeset
   415
    LOGTEXT(_L("CDiskWriterPlugin::WriteMemBufferToFile - exit"));
hgs
parents:
diff changeset
   416
    }
hgs
parents:
diff changeset
   417
hgs
parents:
diff changeset
   418
void CDiskWriterHandler::WriteBufferToOutput(TBapBuf* aBuf)
hgs
parents:
diff changeset
   419
    {
hgs
parents:
diff changeset
   420
    LOGTEXT(_L("CDiskWriterPlugin::WriteBufferToOutput - entry"));
hgs
parents:
diff changeset
   421
    iBufferBeingWritten = aBuf;
hgs
parents:
diff changeset
   422
hgs
parents:
diff changeset
   423
    // set the data length just to be sure
hgs
parents:
diff changeset
   424
    iBufferBeingWritten->iBufDes->SetLength(aBuf->iDataSize);
hgs
parents:
diff changeset
   425
hgs
parents:
diff changeset
   426
    LOGTEXT(_L("CDiskWriterPlugin::WriteBufferToOutput - writing to file"));
hgs
parents:
diff changeset
   427
    WriteMemBufferToFile(*(iBufferBeingWritten->iBufDes), iStatus);
hgs
parents:
diff changeset
   428
hgs
parents:
diff changeset
   429
    // set AO back to active, until filled buffers are emptied 
hgs
parents:
diff changeset
   430
    SetActive();
hgs
parents:
diff changeset
   431
    
hgs
parents:
diff changeset
   432
    LOGTEXT(_L("CDiskWriterPlugin::WriteBufferToOutput - exit"));
hgs
parents:
diff changeset
   433
    }
hgs
parents:
diff changeset
   434
hgs
parents:
diff changeset
   435
void CDiskWriterHandler::StartL()
hgs
parents:
diff changeset
   436
	{
hgs
parents:
diff changeset
   437
	LOGTEXT(_L("CDiskWriterHandler::StartL - entry"));
hgs
parents:
diff changeset
   438
    if(!IsActive())
hgs
parents:
diff changeset
   439
        {
hgs
parents:
diff changeset
   440
        LOGTEXT(_L("CDiskWriterHandler::StartL - is not active"));
hgs
parents:
diff changeset
   441
    
hgs
parents:
diff changeset
   442
        TBapBuf* nextBuf = iWriter->iStream->GetNextFilledBuffer();
hgs
parents:
diff changeset
   443
        LOGSTRING2("CDiskWriterHandler::StartL - got next filled 0x%x",nextBuf);
hgs
parents:
diff changeset
   444
    
hgs
parents:
diff changeset
   445
        if(nextBuf != 0)
hgs
parents:
diff changeset
   446
            {
hgs
parents:
diff changeset
   447
            LOGTEXT(_L("CDiskWriterHandler::StartL - writing to file"));
hgs
parents:
diff changeset
   448
            WriteBufferToOutput(nextBuf);
hgs
parents:
diff changeset
   449
            }
hgs
parents:
diff changeset
   450
        }
hgs
parents:
diff changeset
   451
    LOGTEXT(_L("CDiskWriterHandler::StartL - exit"));
hgs
parents:
diff changeset
   452
	}
hgs
parents:
diff changeset
   453
hgs
parents:
diff changeset
   454
void CDiskWriterHandler::Stop()
hgs
parents:
diff changeset
   455
	{
hgs
parents:
diff changeset
   456
	LOGTEXT(_L("CDiskWriterHandler::Stop - entry"));
hgs
parents:
diff changeset
   457
	
hgs
parents:
diff changeset
   458
	// set to stopping mode, needed for emptying the remaining full buffers
hgs
parents:
diff changeset
   459
	iStopping = ETrue;
hgs
parents:
diff changeset
   460
	
hgs
parents:
diff changeset
   461
	// stop the timer
hgs
parents:
diff changeset
   462
	Reset();
hgs
parents:
diff changeset
   463
hgs
parents:
diff changeset
   464
    // end of stream detected, file can be closed
hgs
parents:
diff changeset
   465
    iFile.Close();
hgs
parents:
diff changeset
   466
    // close handle to file server too
hgs
parents:
diff changeset
   467
    iFs.Close();
hgs
parents:
diff changeset
   468
    iFileName.Zero();
hgs
parents:
diff changeset
   469
    
hgs
parents:
diff changeset
   470
    // set mode back to non-stopping
hgs
parents:
diff changeset
   471
    iStopping = EFalse;
hgs
parents:
diff changeset
   472
    
hgs
parents:
diff changeset
   473
    LOGTEXT(_L("CDiskWriterHandler::Stop - exit"));
hgs
parents:
diff changeset
   474
	}
hgs
parents:
diff changeset
   475
hgs
parents:
diff changeset
   476
// end of file