os/kernelhwsrv/kerneltest/e32test/debug/d_perflogger_ldd.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of the License "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// A helper test driver for testing Kernel Performance Logger implementation.
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
/**
sl@0
    19
 @file
sl@0
    20
*/
sl@0
    21
sl@0
    22
sl@0
    23
#include "d_perflogger_ldd.h"
sl@0
    24
#include <kernperflogger.h>
sl@0
    25
sl@0
    26
_LIT(KDFCThreadName,"D_PL_DFC_THREAD");
sl@0
    27
const TInt KDFCThreadPriority=27;
sl@0
    28
sl@0
    29
//-----------------------------------------------------------------------------------
sl@0
    30
sl@0
    31
sl@0
    32
DKPLoggerTestHelperLDD* DKPLoggerTestHelperLDD::pSelf = NULL;	//-- static pointer to the single instance of the logical channel class
sl@0
    33
sl@0
    34
//-----------------------------------------------------------------------------------
sl@0
    35
sl@0
    36
DLogTicker::DLogTicker() : iTimer(LogTimerCallback,this)  //-- initialize log events generator
sl@0
    37
	{
sl@0
    38
    iLogDFC = NULL;
sl@0
    39
    iRequest = NULL;
sl@0
    40
    iUserThreadContext = NULL;
sl@0
    41
	}
sl@0
    42
sl@0
    43
DLogTicker::~DLogTicker()
sl@0
    44
	{
sl@0
    45
    Cancel(); //-- cancel user request, DFC, timers etc.
sl@0
    46
	Kern::DestroyClientRequest(iRequest);
sl@0
    47
    delete  iLogDFC;
sl@0
    48
	}
sl@0
    49
sl@0
    50
//-----------------------------------------------------------------------------------
sl@0
    51
sl@0
    52
/**
sl@0
    53
	Construct ticker object. Creates appropriate TDfc object for dealing with IDFC or DFC
sl@0
    54
sl@0
    55
	@param  apUserThreadContext pointer to the user thread context where the request will be completed in
sl@0
    56
	@param  apDfcQ              pointer to the DFC queue this object will be using.
sl@0
    57
	@param  aLogContext         specfies the context (ISR, DFC or IDFC) the logging will be made from. Can be NKern::EIDFC, NKern::EThread, NKern::EInterrupt
sl@0
    58
*/
sl@0
    59
void DLogTicker::Construct(DThread* aUserThreadContext, TDfcQue* aDfcQ, NKern::TContext aLogContext)
sl@0
    60
	{
sl@0
    61
    __NK_ASSERT_DEBUG(aUserThreadContext && aDfcQ);
sl@0
    62
	
sl@0
    63
    iLogContext = aLogContext;
sl@0
    64
    if(aLogContext == NKern::EIDFC)
sl@0
    65
		{//-- we will deal with IDFC, create appropriate DFC object
sl@0
    66
        iLogDFC = new TDfc(LogDFC, this);
sl@0
    67
		}
sl@0
    68
    else
sl@0
    69
		{
sl@0
    70
		if(aLogContext == NKern::EThread || aLogContext == NKern::EInterrupt)
sl@0
    71
			{//-- we will deal with DFC or ISR
sl@0
    72
			iLogDFC = new TDfc(LogDFC, this, aDfcQ, 0);
sl@0
    73
			}
sl@0
    74
		else
sl@0
    75
			{//-- wrong value
sl@0
    76
			__PRINT("#KPLogTest:DLogTicker::Construct() wrong context request !");
sl@0
    77
			__NK_ASSERT_DEBUG(0);
sl@0
    78
			}
sl@0
    79
		}
sl@0
    80
		
sl@0
    81
	__NK_ASSERT_ALWAYS(iLogDFC);
sl@0
    82
sl@0
    83
	TInt r = Kern::CreateClientRequest(iRequest);
sl@0
    84
	__NK_ASSERT_ALWAYS(r == KErrNone);
sl@0
    85
		
sl@0
    86
	iUserThreadContext = aUserThreadContext; //-- store user thread context co complete requests correctly
sl@0
    87
//	iLogDFC->SetDfcQ(aDfcQ); //-- attach to the given DFC queue. !!!!DON'T DO THIS FOR IDFC!!!!!
sl@0
    88
	}
sl@0
    89
sl@0
    90
//-----------------------------------------------------------------------------------
sl@0
    91
sl@0
    92
/**
sl@0
    93
	Start the state machine by scheduling a DFC (or IDFC)
sl@0
    94
sl@0
    95
	@param  apLogControl    log parameters structure
sl@0
    96
	@param  apRqStat        pointer to the user request staus object that will be completed when all loggings done.
sl@0
    97
*/
sl@0
    98
void DLogTicker::Start(const TTestLogCtrl* aLogControl, TRequestStatus* aRqStat)
sl@0
    99
	{
sl@0
   100
    __NK_ASSERT_DEBUG(aLogControl && aRqStat && iLogDFC);
sl@0
   101
    kumemget32(&iLogControl, aLogControl, sizeof(TTestLogCtrl)); //-- copy control structure from the user side
sl@0
   102
	
sl@0
   103
	__NK_ASSERT_DEBUG(iLogControl.iLogsNum>=0);
sl@0
   104
	__PRINT1("#KPLogTest:DLogTicker::Start() for %d loggings",iLogControl.iLogsNum);
sl@0
   105
sl@0
   106
	if (iRequest->SetStatus(aRqStat) != KErrNone)
sl@0
   107
		{//-- current request is pending, panic client thread
sl@0
   108
        __PRINT("#KPLogTest:DLogTicker::Start() request is already pending !");
sl@0
   109
        Kern::PanicCurrentThread(KPLoggerHelperTestDrv, EReqAlreadyPending);
sl@0
   110
		}
sl@0
   111
	
sl@0
   112
    if(iLogContext == NKern::EIDFC)
sl@0
   113
		{//-- DLogTicker::LogDFC() will be called as IDFC 
sl@0
   114
        NKern::Lock();   
sl@0
   115
        iLogDFC->Add();  //-- start
sl@0
   116
        NKern::Unlock();
sl@0
   117
		}
sl@0
   118
    else
sl@0
   119
		{//-- DLogTicker::LogDFC() will be called as DFC 
sl@0
   120
        iLogDFC->Enque(); //-- start
sl@0
   121
		}
sl@0
   122
	
sl@0
   123
	}
sl@0
   124
sl@0
   125
//-----------------------------------------------------------------------------------
sl@0
   126
sl@0
   127
/**
sl@0
   128
	Complete the user request when all logging done.
sl@0
   129
	This can be called from 2 concurrent places - DFC & NTimer callback, either of them can complete the request
sl@0
   130
sl@0
   131
	@param aCompletionCode request completion code
sl@0
   132
*/
sl@0
   133
void DLogTicker::CompleteRequest(TInt aCompletionCode/*=KErrNone*/)
sl@0
   134
	{
sl@0
   135
	Kern::QueueRequestComplete(iUserThreadContext, iRequest, aCompletionCode);
sl@0
   136
	}
sl@0
   137
sl@0
   138
//-----------------------------------------------------------------------------------
sl@0
   139
sl@0
   140
/**
sl@0
   141
	Cancel everything
sl@0
   142
*/
sl@0
   143
void DLogTicker::Cancel(void)
sl@0
   144
	{
sl@0
   145
    CompleteRequest(KErrCancel); //-- cancel user request
sl@0
   146
	iLogControl.iLogsNum = 0;	 // Prevent DFC from restarting the timer
sl@0
   147
	iTimer.Cancel();    //-- cancel Timer
sl@0
   148
	iLogDFC->Cancel(); //-- cancel DFC
sl@0
   149
	}
sl@0
   150
sl@0
   151
//-----------------------------------------------------------------------------------
sl@0
   152
sl@0
   153
/**
sl@0
   154
	Ticker timer callback. Can be called in ISR or DFC context.
sl@0
   155
	If called in ISR context, makes logging, and schedules a DFC to complete the request if needed.
sl@0
   156
	If called in DFC context, makes logging for DFC (not for IDFC) mode and completes the request if needed.
sl@0
   157
sl@0
   158
	@param  apSelf pointer to the DLogTicker object
sl@0
   159
*/
sl@0
   160
void DLogTicker::LogTimerCallback(TAny* aSelf)
sl@0
   161
	{
sl@0
   162
    DLogTicker *pSelf = (DLogTicker*)aSelf;
sl@0
   163
    __NK_ASSERT_DEBUG(pSelf);
sl@0
   164
    
sl@0
   165
    TTestLogCtrl& logClontrol = pSelf->iLogControl;
sl@0
   166
    __NK_ASSERT_DEBUG(logClontrol.iLogsNum >=0);
sl@0
   167
	
sl@0
   168
    TInt context = NKern::CurrentContext();
sl@0
   169
    if(context == NKern::EInterrupt)
sl@0
   170
		{//-- This callback is from ISR
sl@0
   171
        
sl@0
   172
        //-- make logging from ISR context, category field is ignored, it will be FastTrace::EKernPerfLog
sl@0
   173
        PERF_LOG(logClontrol.iSubCategory, logClontrol.iUserData, logClontrol.iUserData2);
sl@0
   174
		
sl@0
   175
        //-- kick DFC, it will probaly complete the request. 
sl@0
   176
        pSelf->iLogDFC->Add();  
sl@0
   177
		}
sl@0
   178
    else
sl@0
   179
		{//-- this is a DFC callback, but the DFC object could also have been ceated as IDFC
sl@0
   180
		//-- complete user request here if necessarily.
sl@0
   181
        if(pSelf->iLogDFC->IsIDFC())
sl@0
   182
			{//-- the logging will be made in IDFC function.
sl@0
   183
            if(pSelf->iLogControl.iLogsNum == 0)
sl@0
   184
				{//-- all done, complete the request here, because we can't do in in IDFC
sl@0
   185
                pSelf->CompleteRequest();
sl@0
   186
				}
sl@0
   187
            else
sl@0
   188
				{//-- this callback came from IDFC object, kick IDFC in a special way.
sl@0
   189
                NKern::Lock();
sl@0
   190
                pSelf->iLogDFC->Add(); 
sl@0
   191
                NKern::Unlock();
sl@0
   192
				}
sl@0
   193
			}
sl@0
   194
        else
sl@0
   195
			{//-- this callback came from IDFC object, make logging from DFC context
sl@0
   196
            //-- category field is ignored, it will be FastTrace::EKernPerfLog
sl@0
   197
            PERF_LOG(logClontrol.iSubCategory, logClontrol.iUserData, logClontrol.iUserData2);    
sl@0
   198
			
sl@0
   199
            pSelf->iLogDFC->Enque(); //-- kick DFC 
sl@0
   200
			}
sl@0
   201
        
sl@0
   202
		}
sl@0
   203
	
sl@0
   204
	}
sl@0
   205
sl@0
   206
//-----------------------------------------------------------------------------------
sl@0
   207
sl@0
   208
/**
sl@0
   209
	Ticker DFC or IDFC function. Kicks the timer; 
sl@0
   210
	If is called as IDFC, makes logging in this context and schedules a timer callback in DFC context to complete the request.
sl@0
   211
	If is called as DFC, schedules timer callback in DFC or ISR context. 
sl@0
   212
sl@0
   213
	@param  apSelf pointer to the DLogTicker object
sl@0
   214
*/
sl@0
   215
void DLogTicker::LogDFC(TAny* aSelf)
sl@0
   216
	{
sl@0
   217
    DLogTicker *pSelf = (DLogTicker*)aSelf;
sl@0
   218
    __NK_ASSERT_DEBUG(pSelf);
sl@0
   219
	
sl@0
   220
    TInt context = NKern::CurrentContext();
sl@0
   221
    (void)context; //-- avoid warning in release mode
sl@0
   222
	
sl@0
   223
    if(pSelf->iLogControl.iLogsNum <= 0)
sl@0
   224
		{//-- complete user request, all done. The request can also be completed in LogTimerCallback()
sl@0
   225
		//-- in case if this is a IDFC and callback is a DFC
sl@0
   226
        pSelf->CompleteRequest();    
sl@0
   227
		}
sl@0
   228
    else
sl@0
   229
		{
sl@0
   230
        TTestLogCtrl& logClontrol = pSelf->iLogControl;
sl@0
   231
        logClontrol.iLogsNum--; //-- decrease remaining number of loggings
sl@0
   232
		
sl@0
   233
        if(pSelf->iLogDFC->IsIDFC())
sl@0
   234
			{//-- we are in IDFC context, make logging from here, timer callback won't be IDFC
sl@0
   235
            __NK_ASSERT_DEBUG(context == NKern::EIDFC);
sl@0
   236
			
sl@0
   237
            //-- category field is ignored, it will be FastTrace::EKernPerfLog
sl@0
   238
            PERF_LOG(logClontrol.iSubCategory, logClontrol.iUserData, logClontrol.iUserData2);
sl@0
   239
			
sl@0
   240
            //-- kick the timer to have a callback in a specified time in DFC context
sl@0
   241
            //-- timer's DFC will complete the request if necessarily.
sl@0
   242
            pSelf->iTimer.OneShot(logClontrol.iLogPeriodTick, ETrue); 
sl@0
   243
			}
sl@0
   244
        else
sl@0
   245
			{//-- we are in DFC context, kick the timer to have a callback in a specified time in ISR or DFC context
sl@0
   246
            pSelf->iTimer.OneShot(logClontrol.iLogPeriodTick, !(pSelf->iLogContext == NKern::EInterrupt));
sl@0
   247
			}
sl@0
   248
		}
sl@0
   249
	}
sl@0
   250
sl@0
   251
sl@0
   252
//-----------------------------------------------------------------------------------
sl@0
   253
sl@0
   254
sl@0
   255
//###################################################################################
sl@0
   256
//#            DKPLoggerTestHelperLDD   class implementation
sl@0
   257
//###################################################################################
sl@0
   258
sl@0
   259
DKPLoggerTestHelperLDD::DKPLoggerTestHelperLDD()
sl@0
   260
sl@0
   261
	{
sl@0
   262
    //-- store the pointer to the current thread for request completion from ISR->DFC
sl@0
   263
    iClientThread = &Kern::CurrentThread();
sl@0
   264
	
sl@0
   265
    __NK_ASSERT_DEBUG(iClientThread);
sl@0
   266
	
sl@0
   267
	//-- Open client's user thread, incrementing ref. counter 
sl@0
   268
	TInt nRes = iClientThread->Open();
sl@0
   269
	__NK_ASSERT_DEBUG(nRes == KErrNone);
sl@0
   270
	(void)nRes;//-- avoid warning in release mode
sl@0
   271
sl@0
   272
sl@0
   273
    //-- initialize DFC machinery
sl@0
   274
    //iDfcQ = Kern::DfcQue0();   //-- attach to the low priority DFC queue
sl@0
   275
	if (!iDfcQ)
sl@0
   276
 		{
sl@0
   277
 		TInt r = Kern::DynamicDfcQCreate(iDfcQ, KDFCThreadPriority, KDFCThreadName);
sl@0
   278
		if (r!= KErrNone)
sl@0
   279
			{
sl@0
   280
			return;
sl@0
   281
			}
sl@0
   282
sl@0
   283
#ifdef CPU_AFFINITY_ANY
sl@0
   284
		NKern::ThreadSetCpuAffinity((NThread*)(iDfcQ->iThread), KCpuAffinityAny);			
sl@0
   285
#endif
sl@0
   286
 		}	
sl@0
   287
    
sl@0
   288
    iIsrLogTicker.Construct (iClientThread, iDfcQ, NKern::EInterrupt);//-- construct ISR log ticker
sl@0
   289
    iDfcLogTicker.Construct (iClientThread, iDfcQ, NKern::EThread);   //-- construct DFC log ticker
sl@0
   290
    iIDfcLogTicker.Construct(iClientThread, iDfcQ, NKern::EIDFC);     //-- construct IDFC log ticker
sl@0
   291
	}
sl@0
   292
sl@0
   293
//-----------------------------------------------------------------------------------
sl@0
   294
sl@0
   295
DKPLoggerTestHelperLDD::~DKPLoggerTestHelperLDD()
sl@0
   296
	{
sl@0
   297
    __PRINT("#KPLogTest:~DKPLoggerTestHelperLDD()");
sl@0
   298
	
sl@0
   299
	iClientThread->Close(NULL);
sl@0
   300
sl@0
   301
	if (iDfcQ)
sl@0
   302
		iDfcQ->Destroy();
sl@0
   303
		
sl@0
   304
	pSelf = NULL;  //-- clear the pointer to this class instance
sl@0
   305
	}
sl@0
   306
sl@0
   307
//-----------------------------------------------------------------------------------
sl@0
   308
sl@0
   309
/**
sl@0
   310
	static factory function for the LDD.
sl@0
   311
sl@0
   312
	@return pointer to the created (or existing) instance of the class
sl@0
   313
*/
sl@0
   314
DKPLoggerTestHelperLDD* DKPLoggerTestHelperLDD::CreateInstance()
sl@0
   315
	{
sl@0
   316
    __PRINT("#KPLogTest:DKPLoggerTestHelperLDD::CreateInstance()");
sl@0
   317
    
sl@0
   318
    //-- create LDD channel instance
sl@0
   319
    if(pSelf)
sl@0
   320
	    {//-- this is a singleton, can't have more than one instance
sl@0
   321
        __PRINT("#DKPLoggerTestHelperLDD::CreateInstance(): Attempt to create a second instance of a singleton!");
sl@0
   322
        return pSelf;
sl@0
   323
		}
sl@0
   324
sl@0
   325
	pSelf = new DKPLoggerTestHelperLDD;
sl@0
   326
	
sl@0
   327
    if(!pSelf)
sl@0
   328
		{//-- OOM 
sl@0
   329
        __PRINT("#KPLogTest:DKPLoggerTestHelperLDD::CreateInstance(): Unable to create class instance !");
sl@0
   330
		}
sl@0
   331
	
sl@0
   332
    return pSelf;
sl@0
   333
	}
sl@0
   334
sl@0
   335
//-----------------------------------------------------------------------------------
sl@0
   336
sl@0
   337
/**
sl@0
   338
	LDD second stage constructor
sl@0
   339
*/
sl@0
   340
TInt DKPLoggerTestHelperLDD::DoCreate(TInt /*aUnit*/, const TDesC8* /*anInfo*/, const TVersion& aVer)
sl@0
   341
	{
sl@0
   342
	//-- check if the version aVer is supported
sl@0
   343
    if (!Kern::QueryVersionSupported(TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber),aVer))
sl@0
   344
		return KErrNotSupported;
sl@0
   345
	
sl@0
   346
    return KErrNone;
sl@0
   347
	}
sl@0
   348
sl@0
   349
//-----------------------------------------------------------------------------------
sl@0
   350
sl@0
   351
/**
sl@0
   352
	Requests processing function.
sl@0
   353
	@return     request processing error code.
sl@0
   354
*/
sl@0
   355
TInt DKPLoggerTestHelperLDD::Request(TInt aFunction, TAny* a1, TAny* a2)
sl@0
   356
	{
sl@0
   357
    TInt nRes = KErrNone;
sl@0
   358
	
sl@0
   359
	if (aFunction == KMaxTInt)
sl@0
   360
		{//-- this is DoCancel()
sl@0
   361
		
sl@0
   362
        TUint reqMask = (TUint)a1;
sl@0
   363
        DoCancel(reqMask);
sl@0
   364
		return KErrNone;
sl@0
   365
		}
sl@0
   366
	
sl@0
   367
    if(aFunction < 0)
sl@0
   368
		{//-- This is DoRequest()
sl@0
   369
        
sl@0
   370
        //-- extract request parameters
sl@0
   371
        TRequestStatus* pRqStat=(TRequestStatus*)a1;
sl@0
   372
        
sl@0
   373
        TAny* params[2];
sl@0
   374
        kumemget32(params, a2, sizeof(params));
sl@0
   375
        
sl@0
   376
        nRes = DoRequest(~aFunction, pRqStat, params[0], params[1]); 
sl@0
   377
		}
sl@0
   378
    else
sl@0
   379
		{//-- This is DoControl()
sl@0
   380
        nRes = DoControl(aFunction, a1, a2);
sl@0
   381
		}
sl@0
   382
	
sl@0
   383
	
sl@0
   384
    return nRes;
sl@0
   385
	}
sl@0
   386
sl@0
   387
//-----------------------------------------------------------------------------------
sl@0
   388
sl@0
   389
/**
sl@0
   390
	Cancel outstanding request(s)
sl@0
   391
	@param  aReqNumber	request number to cancel
sl@0
   392
*/
sl@0
   393
void DKPLoggerTestHelperLDD::DoCancel(TUint aReqNumber)
sl@0
   394
	{
sl@0
   395
	
sl@0
   396
    switch (aReqNumber)
sl@0
   397
		{
sl@0
   398
		//-- cancel logging from ISR.
sl@0
   399
		case RKPLoggerTestHelper::EDoLogFromISR:  
sl@0
   400
			iIsrLogTicker.Cancel();
sl@0
   401
			break;
sl@0
   402
			
sl@0
   403
			//-- cancel logging from IDFC.
sl@0
   404
		case RKPLoggerTestHelper::EDoLogFromIDFC: 
sl@0
   405
			iIDfcLogTicker.Cancel();
sl@0
   406
			break;
sl@0
   407
			
sl@0
   408
			//-- cancel logging from DFC.
sl@0
   409
		case RKPLoggerTestHelper::EDoLogFromDFC:  
sl@0
   410
			iDfcLogTicker.Cancel();
sl@0
   411
			break;
sl@0
   412
			
sl@0
   413
		default:
sl@0
   414
			__PRINT1("#KPLogTest:DKPLoggerTestHelperLDD::DoCancel Cancelling a wrong request number:%d!", aReqMask);
sl@0
   415
			Kern::PanicCurrentThread(KPLoggerHelperTestDrv, EWrongRequest);
sl@0
   416
			break;
sl@0
   417
			
sl@0
   418
		}
sl@0
   419
	}
sl@0
   420
sl@0
   421
//-----------------------------------------------------------------------------------
sl@0
   422
sl@0
   423
/**
sl@0
   424
	Asynchronous request processing. 
sl@0
   425
sl@0
   426
	@param aFunction    request function number, see RKPLoggerTestHelper::TControl
sl@0
   427
  
sl@0
   428
    @param apRqStat     pointer to the user's request status object.
sl@0
   429
    @param apArg1       pointer to the 1st parameter in RKPLoggerTestHelper::DoRequest
sl@0
   430
    @param apArg2       pointer to the 2nd parameter in RKPLoggerTestHelper::DoRequest
sl@0
   431
	
sl@0
   432
	@return request scheduling result, system-wide error code.
sl@0
   433
	  
sl@0
   434
*/
sl@0
   435
TInt DKPLoggerTestHelperLDD::DoRequest(TInt aReqNumber, TRequestStatus* aRqStat, TAny* aArg1, TAny* /*apArg2*/)
sl@0
   436
	{
sl@0
   437
    switch (aReqNumber)
sl@0
   438
		{
sl@0
   439
		//-- make logging from ISR.
sl@0
   440
		case RKPLoggerTestHelper::EDoLogFromISR:  
sl@0
   441
			{   
sl@0
   442
			__PRINT("#KPLogTest: making loggings from ISR context");
sl@0
   443
			iIsrLogTicker.Start((const TTestLogCtrl*)aArg1, aRqStat);
sl@0
   444
			}
sl@0
   445
			break;
sl@0
   446
			
sl@0
   447
			//-- make logging from IDFC.
sl@0
   448
		case RKPLoggerTestHelper::EDoLogFromIDFC: 
sl@0
   449
			{   
sl@0
   450
			__PRINT("#KPLogTest: making loggings from IDFC context");			
sl@0
   451
			iIDfcLogTicker.Start((const TTestLogCtrl*)aArg1, aRqStat);
sl@0
   452
			}			
sl@0
   453
			break;
sl@0
   454
			
sl@0
   455
			//-- make logging from DFC.
sl@0
   456
		case RKPLoggerTestHelper::EDoLogFromDFC:  
sl@0
   457
			{   
sl@0
   458
			__PRINT("#KPLogTest: making loggings from DFC context");			
sl@0
   459
			iDfcLogTicker.Start((const TTestLogCtrl*)aArg1, aRqStat);
sl@0
   460
			}
sl@0
   461
			break;
sl@0
   462
			
sl@0
   463
			
sl@0
   464
		default:
sl@0
   465
			__PRINT1("#KPLogTest:DKPLoggerTestHelperLDD::DoRequest() Wrong request number:%d!", aReqNumber);
sl@0
   466
			Kern::PanicCurrentThread(KPLoggerHelperTestDrv, EWrongRequest);
sl@0
   467
			break;
sl@0
   468
		}
sl@0
   469
    
sl@0
   470
    return KErrNone;
sl@0
   471
	}
sl@0
   472
sl@0
   473
//-----------------------------------------------------------------------------------
sl@0
   474
sl@0
   475
/**
sl@0
   476
	Synchronous requests processing. 
sl@0
   477
sl@0
   478
	@param aFunction    request function number, see RKernPerfLogger::TControl
sl@0
   479
	@param apArg1       pointer to the 1st parameter in RKernPerfLogger::DoControl
sl@0
   480
	@param apArg2       pointer to the 2n parameter in RKernPerfLogger::DoControl 
sl@0
   481
  
sl@0
   482
    @return request processing result
sl@0
   483
*/
sl@0
   484
TInt DKPLoggerTestHelperLDD::DoControl(TInt aFunction, TAny* aArg1, TAny* /*apArg2*/)
sl@0
   485
	{
sl@0
   486
	
sl@0
   487
    switch (aFunction)
sl@0
   488
		{
sl@0
   489
        //-- make test logging from the user thread
sl@0
   490
        case RKPLoggerTestHelper::EDoLogFromUserThread:
sl@0
   491
			{    
sl@0
   492
            kumemget32(&iLogControlUserThread, aArg1, sizeof(iLogControlUserThread)); //-- copy control structure from the user side
sl@0
   493
            __PRINT1("#KPLogTest: making %d loggings from a user-thread context", iLogControlUserThread.iLogsNum);
sl@0
   494
            __NK_ASSERT_DEBUG(iLogControlUserThread.iLogsNum >=0 );
sl@0
   495
			
sl@0
   496
            //-- This context is actually, a user thread. Make logging from here
sl@0
   497
            for(TInt i=0; i<iLogControlUserThread.iLogsNum; ++i)
sl@0
   498
				{
sl@0
   499
                //-- category field is ignored, it will be FastTrace::EKernPerfLog
sl@0
   500
                PERF_LOG(iLogControlUserThread.iSubCategory, iLogControlUserThread.iUserData, iLogControlUserThread.iUserData2);
sl@0
   501
                
sl@0
   502
                NKern::Sleep(iLogControlUserThread.iLogPeriodTick);
sl@0
   503
				}
sl@0
   504
			}
sl@0
   505
			break;
sl@0
   506
			
sl@0
   507
		//-- unit test for different PERF_LOG macros
sl@0
   508
        case RKPLoggerTestHelper::EDoTestMacros:
sl@0
   509
			{
sl@0
   510
            kumemget32(&iLogControlUserThread, aArg1, sizeof(iLogControlUserThread)); //-- copy control structure from the user side
sl@0
   511
            __PRINT1("#KPLogTest: making %d loggings from a user-thread context, testing different macros", iLogControlUserThread.iLogsNum);
sl@0
   512
            __NK_ASSERT_DEBUG(iLogControlUserThread.iLogsNum >=0 );
sl@0
   513
			
sl@0
   514
            for(TInt i=0; i<iLogControlUserThread.iLogsNum; ++i)
sl@0
   515
				{
sl@0
   516
                PERF_LOG0(iLogControlUserThread.iSubCategory);
sl@0
   517
                PERF_LOG1(iLogControlUserThread.iSubCategory, iLogControlUserThread.iUserData);
sl@0
   518
                PERF_LOG (iLogControlUserThread.iSubCategory, iLogControlUserThread.iUserData, iLogControlUserThread.iUserData2);
sl@0
   519
                
sl@0
   520
                NKern::Sleep(iLogControlUserThread.iLogPeriodTick);
sl@0
   521
				}
sl@0
   522
			
sl@0
   523
			
sl@0
   524
			}
sl@0
   525
			break;
sl@0
   526
			
sl@0
   527
        default:
sl@0
   528
			__PRINT1("#KPLogTest:DKPLoggerTestHelperLDD::DoControl() Wrong function number:%d!", aFunction);
sl@0
   529
			Kern::PanicCurrentThread(KPLoggerHelperTestDrv, EWrongRequest);
sl@0
   530
			break;
sl@0
   531
			
sl@0
   532
		};
sl@0
   533
	
sl@0
   534
	
sl@0
   535
    return KErrNone;
sl@0
   536
	}
sl@0
   537
sl@0
   538
sl@0
   539
sl@0
   540
//###################################################################################
sl@0
   541
//#            LDD factory, DKPLoggerTestHelperLDDFactory class implementation 
sl@0
   542
//###################################################################################
sl@0
   543
sl@0
   544
DKPLoggerTestHelperLDDFactory::DKPLoggerTestHelperLDDFactory()
sl@0
   545
	{
sl@0
   546
    iUnitsMask = 0x00; //-- don't support units
sl@0
   547
    iVersion=TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber);	
sl@0
   548
	}
sl@0
   549
sl@0
   550
DKPLoggerTestHelperLDDFactory::~DKPLoggerTestHelperLDDFactory()
sl@0
   551
	{
sl@0
   552
    __PRINT("#KPLogTest:~DKPLoggerTestHelperLDDFactory()");
sl@0
   553
	}
sl@0
   554
sl@0
   555
//-----------------------------------------------------------------------------------
sl@0
   556
sl@0
   557
/**
sl@0
   558
	static factory function for the LDD factory.
sl@0
   559
sl@0
   560
	@return pointer to the created instance of the class
sl@0
   561
*/
sl@0
   562
DKPLoggerTestHelperLDDFactory* DKPLoggerTestHelperLDDFactory::CreateInstance()
sl@0
   563
	{
sl@0
   564
    __PRINT("#KPLogTest:DKPLoggerTestHelperLDDFactory::CreateInstance()");
sl@0
   565
    
sl@0
   566
    //-- create LDD factory
sl@0
   567
    DKPLoggerTestHelperLDDFactory* pSelf = new DKPLoggerTestHelperLDDFactory;
sl@0
   568
	
sl@0
   569
    if(!pSelf)
sl@0
   570
		{//-- OOM 
sl@0
   571
        __PRINT("#KPLogTest:DKPLoggerTestHelperLDDFactory::CreateInstance(): Unable to create class instance !");
sl@0
   572
		}
sl@0
   573
	
sl@0
   574
    return pSelf;
sl@0
   575
	}
sl@0
   576
sl@0
   577
//-----------------------------------------------------------------------------------
sl@0
   578
sl@0
   579
/**
sl@0
   580
*/
sl@0
   581
TInt DKPLoggerTestHelperLDDFactory::Install()
sl@0
   582
	{
sl@0
   583
    return SetName(&KPLoggerHelperTestDrv); // Set our name and return error code
sl@0
   584
	}
sl@0
   585
sl@0
   586
//-----------------------------------------------------------------------------------
sl@0
   587
sl@0
   588
/**
sl@0
   589
*/
sl@0
   590
void DKPLoggerTestHelperLDDFactory::GetCaps(TDes8& /*aDes*/) const
sl@0
   591
	{//-- not supported
sl@0
   592
	}
sl@0
   593
sl@0
   594
//-----------------------------------------------------------------------------------
sl@0
   595
sl@0
   596
/**
sl@0
   597
	LDD factory function. Creates LDD object.
sl@0
   598
	@param  aChannel    A pointer to an LDD channel object which will be initialised on return.
sl@0
   599
	@return KErrNone    if object successfully allocated, KErrNoMemory if not.
sl@0
   600
	@return KErrAlreadyExists	if the client tries to creae more than 1 instance of the channel
sl@0
   601
sl@0
   602
*/
sl@0
   603
TInt DKPLoggerTestHelperLDDFactory::Create(DLogicalChannelBase*& aChannel)
sl@0
   604
	{
sl@0
   605
sl@0
   606
	if(DKPLoggerTestHelperLDD::pSelf)
sl@0
   607
		{//-- channel is a singleton, can't have more than one instance
sl@0
   608
        __PRINT("#DKPLoggerTestHelperLDDFactory::Create: Attmpt to create another instance of the LDD!");
sl@0
   609
        return KErrAlreadyExists;
sl@0
   610
		}
sl@0
   611
    
sl@0
   612
	aChannel = DKPLoggerTestHelperLDD::CreateInstance();
sl@0
   613
    if(!aChannel)
sl@0
   614
        return KErrNoMemory;  
sl@0
   615
	
sl@0
   616
    return KErrNone;
sl@0
   617
	}
sl@0
   618
sl@0
   619
sl@0
   620
//-----------------------------------------------------------------------------------
sl@0
   621
sl@0
   622
/**
sl@0
   623
	"Standard LDD" entrypoint.
sl@0
   624
	Is called on CreateLogicalDevice() if the user calls LoadLogicalDevice(). Creates LDD factory.
sl@0
   625
sl@0
   626
	@return pointer to the LDD factory object.
sl@0
   627
*/
sl@0
   628
DECLARE_STANDARD_LDD()
sl@0
   629
	{
sl@0
   630
    DKPLoggerTestHelperLDDFactory* pLDDFactory = DKPLoggerTestHelperLDDFactory::CreateInstance();
sl@0
   631
    return  pLDDFactory;
sl@0
   632
	}
sl@0
   633
sl@0
   634
sl@0
   635
sl@0
   636
sl@0
   637
sl@0
   638
sl@0
   639
sl@0
   640
sl@0
   641
sl@0
   642
sl@0
   643
sl@0
   644
sl@0
   645
sl@0
   646
sl@0
   647
sl@0
   648
sl@0
   649
sl@0
   650
sl@0
   651
sl@0
   652
sl@0
   653
sl@0
   654
sl@0
   655
sl@0
   656
sl@0
   657
sl@0
   658
sl@0
   659
sl@0
   660
sl@0
   661