piprofiler/plugins/BUPplugin/src/BupPlugin.cpp
author hgs
Thu, 13 May 2010 23:59:27 +0300
changeset 20 a71a3e32a2ae
child 49 7fdc9a71d314
permissions -rw-r--r--
201019
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 "BupPlugin.h"	
hgs
parents:
diff changeset
    20
//#include <piprofiler/EngineUIDs.h>
hgs
parents:
diff changeset
    21
hgs
parents:
diff changeset
    22
#include <w32std.h> 	// for listening key events
hgs
parents:
diff changeset
    23
hgs
parents:
diff changeset
    24
	
hgs
parents:
diff changeset
    25
// LITERALS
hgs
parents:
diff changeset
    26
// CONSTANTS
hgs
parents:
diff changeset
    27
const TUid KSamplerBupPluginUid = { 0x2001E5B6 };
hgs
parents:
diff changeset
    28
hgs
parents:
diff changeset
    29
/*
hgs
parents:
diff changeset
    30
 *	
hgs
parents:
diff changeset
    31
 *	class CBupPlugin implementation
hgs
parents:
diff changeset
    32
 * 
hgs
parents:
diff changeset
    33
 */
hgs
parents:
diff changeset
    34
hgs
parents:
diff changeset
    35
CBupPlugin* CBupPlugin::NewL(const TUid /*aImplementationUid*/, TAny* /*aInitParams*/)
hgs
parents:
diff changeset
    36
	{
hgs
parents:
diff changeset
    37
	LOGTEXT(_L("CBupPlugin::NewL() - entry"));
hgs
parents:
diff changeset
    38
    CBupPlugin* self = new (ELeave) CBupPlugin();
hgs
parents:
diff changeset
    39
    CleanupStack::PushL( self );
hgs
parents:
diff changeset
    40
    self->ConstructL();
hgs
parents:
diff changeset
    41
    CleanupStack::Pop();
hgs
parents:
diff changeset
    42
	LOGTEXT(_L("CBupPlugin::NewL() - exit"));
hgs
parents:
diff changeset
    43
    return self;
hgs
parents:
diff changeset
    44
	}
hgs
parents:
diff changeset
    45
hgs
parents:
diff changeset
    46
CBupPlugin::CBupPlugin() :
hgs
parents:
diff changeset
    47
	iVersionDescriptor(&(this->iVersion[1]),0,19), 	
hgs
parents:
diff changeset
    48
	iSamplerType(PROFILER_USER_MODE_SAMPLER)
hgs
parents:
diff changeset
    49
	{
hgs
parents:
diff changeset
    50
	iSamplerId = PROFILER_BUP_SAMPLER_ID;
hgs
parents:
diff changeset
    51
    iEnabled = EFalse;
hgs
parents:
diff changeset
    52
	LOGTEXT(_L("CBupPlugin::CBupPlugin() - konstruktori"));
hgs
parents:
diff changeset
    53
	}
hgs
parents:
diff changeset
    54
hgs
parents:
diff changeset
    55
void CBupPlugin::ConstructL() 
hgs
parents:
diff changeset
    56
	{
hgs
parents:
diff changeset
    57
	LOGTEXT(_L("CBupPlugin::ConstructL() - entry"));
hgs
parents:
diff changeset
    58
	
hgs
parents:
diff changeset
    59
	// initiate sampler attributes array
hgs
parents:
diff changeset
    60
	iSamplerAttributes = new(ELeave) CArrayFixFlat<TSamplerAttributes>(1); // only one sampler
hgs
parents:
diff changeset
    61
	
hgs
parents:
diff changeset
    62
	// insert default attributes to array
hgs
parents:
diff changeset
    63
	InitiateSamplerAttributesL();
hgs
parents:
diff changeset
    64
	
hgs
parents:
diff changeset
    65
	LOGTEXT(_L("CBupPlugin::ConstructL() - exit"));
hgs
parents:
diff changeset
    66
	}
hgs
parents:
diff changeset
    67
hgs
parents:
diff changeset
    68
hgs
parents:
diff changeset
    69
CBupPlugin::~CBupPlugin()
hgs
parents:
diff changeset
    70
	{
hgs
parents:
diff changeset
    71
	LOGTEXT(_L("CBupPlugin::~CBupPlugin() - entry"));
hgs
parents:
diff changeset
    72
	if(iButtonListener)
hgs
parents:
diff changeset
    73
	    {
hgs
parents:
diff changeset
    74
	    // check if button listener still running
hgs
parents:
diff changeset
    75
	    if(Enabled())
hgs
parents:
diff changeset
    76
	        {
hgs
parents:
diff changeset
    77
	        // stop profiling
hgs
parents:
diff changeset
    78
	        iButtonListener->Stop();
hgs
parents:
diff changeset
    79
	        }
hgs
parents:
diff changeset
    80
        delete iButtonListener;
hgs
parents:
diff changeset
    81
	    }
hgs
parents:
diff changeset
    82
	
hgs
parents:
diff changeset
    83
	if(iSamplerAttributes)
hgs
parents:
diff changeset
    84
	    {
hgs
parents:
diff changeset
    85
	    iSamplerAttributes->Reset();
hgs
parents:
diff changeset
    86
	    }
hgs
parents:
diff changeset
    87
    delete iSamplerAttributes;
hgs
parents:
diff changeset
    88
	
hgs
parents:
diff changeset
    89
	LOGTEXT(_L("CBupPlugin::~CBupPlugin() - exit"));
hgs
parents:
diff changeset
    90
	}
hgs
parents:
diff changeset
    91
hgs
parents:
diff changeset
    92
TUid CBupPlugin::Id(TInt /*aUid*/) const
hgs
parents:
diff changeset
    93
	{
hgs
parents:
diff changeset
    94
    LOGSTRING2("CBupPlugin::Id():0x%X", KSamplerBupPluginUid.iUid );
hgs
parents:
diff changeset
    95
    return KSamplerBupPluginUid;
hgs
parents:
diff changeset
    96
	}
hgs
parents:
diff changeset
    97
hgs
parents:
diff changeset
    98
void CBupPlugin::InitiateSamplerAttributesL()
hgs
parents:
diff changeset
    99
    {
hgs
parents:
diff changeset
   100
    // create sampler attribute container
hgs
parents:
diff changeset
   101
    TSamplerAttributes attr(KSamplerBupPluginUid.iUid,
hgs
parents:
diff changeset
   102
            KBUPShortName(),
hgs
parents:
diff changeset
   103
            KBUPLongName(),
hgs
parents:
diff changeset
   104
            KBUPDescription(),
hgs
parents:
diff changeset
   105
            -1,
hgs
parents:
diff changeset
   106
            ETrue,
hgs
parents:
diff changeset
   107
            EFalse,
hgs
parents:
diff changeset
   108
            0); // default item count
hgs
parents:
diff changeset
   109
    this->iSamplerAttributes->AppendL(attr);
hgs
parents:
diff changeset
   110
    }
hgs
parents:
diff changeset
   111
hgs
parents:
diff changeset
   112
// returns setting array
hgs
parents:
diff changeset
   113
void CBupPlugin::GetAttributesL(CArrayFixFlat<TSamplerAttributes>* aAttributes)
hgs
parents:
diff changeset
   114
    {
hgs
parents:
diff changeset
   115
    // append my own attributes to complete array, requested by profiler engine
hgs
parents:
diff changeset
   116
    aAttributes->AppendL(iSamplerAttributes->At(0));
hgs
parents:
diff changeset
   117
    }
hgs
parents:
diff changeset
   118
hgs
parents:
diff changeset
   119
TInt CBupPlugin::SetAttributesL(TSamplerAttributes aAttributes)
hgs
parents:
diff changeset
   120
    {
hgs
parents:
diff changeset
   121
    TSamplerAttributes attr;
hgs
parents:
diff changeset
   122
hgs
parents:
diff changeset
   123
    attr = iSamplerAttributes->At(0);
hgs
parents:
diff changeset
   124
    // if UIDs match replace the old 
hgs
parents:
diff changeset
   125
    if(attr.iUid == aAttributes.iUid)
hgs
parents:
diff changeset
   126
        {
hgs
parents:
diff changeset
   127
        // replace the old attribute container
hgs
parents:
diff changeset
   128
        iSamplerAttributes->Delete(0);
hgs
parents:
diff changeset
   129
        iSamplerAttributes->InsertL(0, aAttributes);
hgs
parents:
diff changeset
   130
        return KErrNone;
hgs
parents:
diff changeset
   131
        }
hgs
parents:
diff changeset
   132
    return KErrNotFound;
hgs
parents:
diff changeset
   133
    }
hgs
parents:
diff changeset
   134
hgs
parents:
diff changeset
   135
/* 
hgs
parents:
diff changeset
   136
 * Method for parsing and transforming text array settings into TSamplerAttributes (per each sub sampler),
hgs
parents:
diff changeset
   137
 * called by CSamplerController class
hgs
parents:
diff changeset
   138
 * 
hgs
parents:
diff changeset
   139
 * @param array of raw text setting lines, e.g. [gpp]\nenabled=true\nsampling_period_ms=1\n
hgs
parents:
diff changeset
   140
 */
hgs
parents:
diff changeset
   141
TInt CBupPlugin::ConvertRawSettingsToAttributes(CDesC8ArrayFlat* aAllSettingsArray)
hgs
parents:
diff changeset
   142
    {
hgs
parents:
diff changeset
   143
    // local literals
hgs
parents:
diff changeset
   144
    _LIT8(KBUPShort, "bup");
hgs
parents:
diff changeset
   145
hgs
parents:
diff changeset
   146
    TInt err(KErrNone);
hgs
parents:
diff changeset
   147
    TBuf8<16> samplerSearchName;
hgs
parents:
diff changeset
   148
    samplerSearchName.Copy(KBUPShort);
hgs
parents:
diff changeset
   149
    
hgs
parents:
diff changeset
   150
    // get sampler specific settings  
hgs
parents:
diff changeset
   151
    err = DoSetSamplerSettings(aAllSettingsArray, samplerSearchName, 0);
hgs
parents:
diff changeset
   152
    
hgs
parents:
diff changeset
   153
    // returns KErrNone if settings found, otherwise KErrNotFound
hgs
parents:
diff changeset
   154
    return err;
hgs
parents:
diff changeset
   155
    }
hgs
parents:
diff changeset
   156
hgs
parents:
diff changeset
   157
TInt CBupPlugin::DoSetSamplerSettings(CDesC8ArrayFlat* aAllSettings, TDesC8& aSamplerName, TInt aIndex)
hgs
parents:
diff changeset
   158
    {
hgs
parents:
diff changeset
   159
    // 
hgs
parents:
diff changeset
   160
    TBuf8<16> samplerSearch;
hgs
parents:
diff changeset
   161
    samplerSearch.Copy(KBracketOpen);
hgs
parents:
diff changeset
   162
    samplerSearch.Append(aSamplerName);
hgs
parents:
diff changeset
   163
    samplerSearch.Append(KBracketClose);
hgs
parents:
diff changeset
   164
    
hgs
parents:
diff changeset
   165
    // read a line
hgs
parents:
diff changeset
   166
    for (TInt i(0); i<aAllSettings->MdcaCount(); i++)
hgs
parents:
diff changeset
   167
        {
hgs
parents:
diff changeset
   168
        // check if this line has a setting block start, i.e. contains [xxx] in it
hgs
parents:
diff changeset
   169
        if (aAllSettings->MdcaPoint(i).CompareF(samplerSearch) == 0)
hgs
parents:
diff changeset
   170
            {
hgs
parents:
diff changeset
   171
            // right settings block found, now loop until the next block is found
hgs
parents:
diff changeset
   172
            for(TInt j(i+1);j<aAllSettings->MdcaCount();j++)
hgs
parents:
diff changeset
   173
                {
hgs
parents:
diff changeset
   174
                // check if the next settings block was found
hgs
parents:
diff changeset
   175
                if(aAllSettings->MdcaPoint(j).Left(1).CompareF(KBracketOpen) != 0)
hgs
parents:
diff changeset
   176
                    {
hgs
parents:
diff changeset
   177
                    // save found setting value directly to its owners attributes
hgs
parents:
diff changeset
   178
                    SaveSettingToAttributes(aAllSettings->MdcaPoint(j), aIndex);
hgs
parents:
diff changeset
   179
                    }
hgs
parents:
diff changeset
   180
                else
hgs
parents:
diff changeset
   181
                    {
hgs
parents:
diff changeset
   182
                    // next block found, return KErrNone
hgs
parents:
diff changeset
   183
                    return KErrNone;
hgs
parents:
diff changeset
   184
                    }
hgs
parents:
diff changeset
   185
                }
hgs
parents:
diff changeset
   186
            }
hgs
parents:
diff changeset
   187
        }
hgs
parents:
diff changeset
   188
    
hgs
parents:
diff changeset
   189
    return KErrNotFound;
hgs
parents:
diff changeset
   190
    }
hgs
parents:
diff changeset
   191
hgs
parents:
diff changeset
   192
/**
hgs
parents:
diff changeset
   193
 * Method for setting a specific descriptor (from settings file) to attribute structure
hgs
parents:
diff changeset
   194
 * 
hgs
parents:
diff changeset
   195
 * @param aSetting  
hgs
parents:
diff changeset
   196
 * @param aName  
hgs
parents:
diff changeset
   197
 */
hgs
parents:
diff changeset
   198
void CBupPlugin::SaveSettingToAttributes(const TDesC8& aSetting, TInt aIndex)
hgs
parents:
diff changeset
   199
    {
hgs
parents:
diff changeset
   200
    // find the equal mark from the setting line
hgs
parents:
diff changeset
   201
    TInt sepPos = aSetting.Find(KSettingItemSeparator);
hgs
parents:
diff changeset
   202
    // check that '=' is found
hgs
parents:
diff changeset
   203
    if (sepPos > 0)
hgs
parents:
diff changeset
   204
        {
hgs
parents:
diff changeset
   205
        // check that the element matches
hgs
parents:
diff changeset
   206
        if (aSetting.Left(sepPos).CompareF(KEnabled) == 0)
hgs
parents:
diff changeset
   207
            {
hgs
parents:
diff changeset
   208
            TBool en;
hgs
parents:
diff changeset
   209
            CSamplerPluginInterface::Str2Bool(aSetting.Right(aSetting.Length()-sepPos-1), en);
hgs
parents:
diff changeset
   210
            if(iSamplerAttributes->At(aIndex).iEnabled != en)
hgs
parents:
diff changeset
   211
                {
hgs
parents:
diff changeset
   212
                iSamplerAttributes->At(aIndex).iEnabled = en;
hgs
parents:
diff changeset
   213
                }
hgs
parents:
diff changeset
   214
            }
hgs
parents:
diff changeset
   215
        }
hgs
parents:
diff changeset
   216
    }
hgs
parents:
diff changeset
   217
hgs
parents:
diff changeset
   218
TInt CBupPlugin::GetSamplerType()
hgs
parents:
diff changeset
   219
	{
hgs
parents:
diff changeset
   220
	return iSamplerType;
hgs
parents:
diff changeset
   221
	}
hgs
parents:
diff changeset
   222
hgs
parents:
diff changeset
   223
TInt CBupPlugin::ResetAndActivateL(CProfilerSampleStream& aStream) 
hgs
parents:
diff changeset
   224
	{
hgs
parents:
diff changeset
   225
	LOGTEXT(_L("CBupPlugin::ResetAndActivate() - entry"));
hgs
parents:
diff changeset
   226
	TInt ret(KErrNone);
hgs
parents:
diff changeset
   227
	
hgs
parents:
diff changeset
   228
	// check if sampler enabled
hgs
parents:
diff changeset
   229
	if(iSamplerAttributes->At(0).iEnabled)
hgs
parents:
diff changeset
   230
	    {
hgs
parents:
diff changeset
   231
        // create first the listener instance
hgs
parents:
diff changeset
   232
        iButtonListener = CProfilerButtonListener::NewL(this);
hgs
parents:
diff changeset
   233
        
hgs
parents:
diff changeset
   234
        LOGTEXT(_L("CBupPlugin::ResetAndActivate() - listener created"));
hgs
parents:
diff changeset
   235
        
hgs
parents:
diff changeset
   236
        iStream = &aStream;
hgs
parents:
diff changeset
   237
        TInt length = this->CreateFirstSample();
hgs
parents:
diff changeset
   238
        iVersion[0] = (TUint8)length;
hgs
parents:
diff changeset
   239
        LOGSTRING2("CBupPlugin::ResetAndActivate() - AddSample, length %d",length);
hgs
parents:
diff changeset
   240
        ret = AddSample(iVersion, length+1, 0);
hgs
parents:
diff changeset
   241
        if(ret != KErrNone)
hgs
parents:
diff changeset
   242
            return ret;
hgs
parents:
diff changeset
   243
        
hgs
parents:
diff changeset
   244
        // activate button listener
hgs
parents:
diff changeset
   245
        ret = iButtonListener->StartL();
hgs
parents:
diff changeset
   246
hgs
parents:
diff changeset
   247
        iEnabled = ETrue;
hgs
parents:
diff changeset
   248
        
hgs
parents:
diff changeset
   249
        LOGTEXT(_L("CBupPlugin::ResetAndActivate() - exit"));
hgs
parents:
diff changeset
   250
	    }
hgs
parents:
diff changeset
   251
	return ret;
hgs
parents:
diff changeset
   252
hgs
parents:
diff changeset
   253
	}
hgs
parents:
diff changeset
   254
	
hgs
parents:
diff changeset
   255
TInt CBupPlugin::CreateFirstSample()
hgs
parents:
diff changeset
   256
	{
hgs
parents:
diff changeset
   257
	LOGTEXT(_L("CBupPlugin::CreateFirstSample - entry"));
hgs
parents:
diff changeset
   258
	this->iVersionDescriptor.Zero();
hgs
parents:
diff changeset
   259
	this->iVersionDescriptor.Append(_L8("Bappea_BUP_V"));
hgs
parents:
diff changeset
   260
	this->iVersionDescriptor.Append(PROFILER_BUP_SAMPLER_VERSION);
hgs
parents:
diff changeset
   261
	LOGTEXT(_L("CBupPlugin::CreateFirstSample - exit"));
hgs
parents:
diff changeset
   262
	return (TInt)(this->iVersionDescriptor.Length());
hgs
parents:
diff changeset
   263
	}
hgs
parents:
diff changeset
   264
hgs
parents:
diff changeset
   265
TInt CBupPlugin::StopSampling() 
hgs
parents:
diff changeset
   266
	{
hgs
parents:
diff changeset
   267
	if(iButtonListener)
hgs
parents:
diff changeset
   268
		{
hgs
parents:
diff changeset
   269
		iButtonListener->Stop();
hgs
parents:
diff changeset
   270
		delete iButtonListener;	// delete listener after every trace
hgs
parents:
diff changeset
   271
		iButtonListener = NULL;
hgs
parents:
diff changeset
   272
		}
hgs
parents:
diff changeset
   273
	
hgs
parents:
diff changeset
   274
    // set disabled
hgs
parents:
diff changeset
   275
    iEnabled = EFalse;
hgs
parents:
diff changeset
   276
hgs
parents:
diff changeset
   277
	return KErrNone;
hgs
parents:
diff changeset
   278
	}
hgs
parents:
diff changeset
   279
hgs
parents:
diff changeset
   280
void CBupPlugin::FillThisStreamBuffer(TBapBuf* /*aBapBuf*/, TRequestStatus& /*aStatus*/)
hgs
parents:
diff changeset
   281
	{
hgs
parents:
diff changeset
   282
	}
hgs
parents:
diff changeset
   283
hgs
parents:
diff changeset
   284
/*
hgs
parents:
diff changeset
   285
 * 
hgs
parents:
diff changeset
   286
 * Implementation of class CProfilerButtonListener
hgs
parents:
diff changeset
   287
 * 
hgs
parents:
diff changeset
   288
 */
hgs
parents:
diff changeset
   289
CProfilerButtonListener::CProfilerButtonListener(CBupPlugin* aSampler) 
hgs
parents:
diff changeset
   290
	{
hgs
parents:
diff changeset
   291
	LOGTEXT(_L("CProfilerButtonListener::CProfilerButtonListener() - konstuktori"));
hgs
parents:
diff changeset
   292
	this->iSampler = aSampler;
hgs
parents:
diff changeset
   293
	iSampleStartTime = 0;
hgs
parents:
diff changeset
   294
	LOGTEXT(_L("CProfilerButtonListener::CProfilerButtonListener() - konstuktori exit"));
hgs
parents:
diff changeset
   295
	}
hgs
parents:
diff changeset
   296
hgs
parents:
diff changeset
   297
CProfilerButtonListener* CProfilerButtonListener::NewL(CBupPlugin* aSampler)
hgs
parents:
diff changeset
   298
	{
hgs
parents:
diff changeset
   299
	LOGTEXT(_L("CProfilerButtonListener::NewL() - entry"));
hgs
parents:
diff changeset
   300
	CProfilerButtonListener* self = new (ELeave) CProfilerButtonListener(aSampler);
hgs
parents:
diff changeset
   301
	CleanupStack::PushL( self );
hgs
parents:
diff changeset
   302
	self->ConstructL();
hgs
parents:
diff changeset
   303
	CleanupStack::Pop();
hgs
parents:
diff changeset
   304
	LOGTEXT(_L("CProfilerButtonListener::NewL() - exit"));
hgs
parents:
diff changeset
   305
	return self;
hgs
parents:
diff changeset
   306
	}
hgs
parents:
diff changeset
   307
hgs
parents:
diff changeset
   308
CProfilerButtonListener::~CProfilerButtonListener() 
hgs
parents:
diff changeset
   309
	{
hgs
parents:
diff changeset
   310
	LOGTEXT(_L("CProfilerButtonListener::~CProfilerButtonListener() - entry af"));
hgs
parents:
diff changeset
   311
hgs
parents:
diff changeset
   312
	if(iMainWindow)
hgs
parents:
diff changeset
   313
		{
hgs
parents:
diff changeset
   314
		LOGTEXT(_L("CProfilerButtonListener::~CProfilerButtonListener(): flushing iWs"));
hgs
parents:
diff changeset
   315
		iWs.Flush();
hgs
parents:
diff changeset
   316
		LOGTEXT(_L("CProfilerButtonListener::~CProfilerButtonListener(): finishing"));
hgs
parents:
diff changeset
   317
		}
hgs
parents:
diff changeset
   318
	delete iMainWindow;
hgs
parents:
diff changeset
   319
	LOGTEXT(_L("CProfilerButtonListener::~CProfilerButtonListener() - exit"));
hgs
parents:
diff changeset
   320
	}
hgs
parents:
diff changeset
   321
	
hgs
parents:
diff changeset
   322
void CProfilerButtonListener::ConstructMainWindowL()
hgs
parents:
diff changeset
   323
	{
hgs
parents:
diff changeset
   324
    LOGTEXT(_L("CProfilerButtonListener::ConstructMainWindowL() - Entry"));
hgs
parents:
diff changeset
   325
hgs
parents:
diff changeset
   326
    CWindow* window = new (ELeave) CWindow(this);
hgs
parents:
diff changeset
   327
    CleanupStack::PushL( window );
hgs
parents:
diff changeset
   328
	window->ConstructL(TRect(TPoint(0,0), TSize(0,0)));
hgs
parents:
diff changeset
   329
    delete iMainWindow;
hgs
parents:
diff changeset
   330
    iMainWindow = window;
hgs
parents:
diff changeset
   331
    CleanupStack::Pop( window );
hgs
parents:
diff changeset
   332
	
hgs
parents:
diff changeset
   333
    LOGTEXT(_L("CProfilerButtonListener::ConstructMainWindowL() - Exit"));
hgs
parents:
diff changeset
   334
	}
hgs
parents:
diff changeset
   335
hgs
parents:
diff changeset
   336
void CProfilerButtonListener::HandleKeyEventL (TKeyEvent& /*aKeyEvent*/)
hgs
parents:
diff changeset
   337
    {
hgs
parents:
diff changeset
   338
    LOGTEXT(_L("CProfilerButtonListener::HandleKeyEventL() - Start"));
hgs
parents:
diff changeset
   339
    LOGTEXT(_L("CProfilerButtonListener::HandleKeyEventL() - End"));
hgs
parents:
diff changeset
   340
	}
hgs
parents:
diff changeset
   341
hgs
parents:
diff changeset
   342
hgs
parents:
diff changeset
   343
TInt CProfilerButtonListener::RunError(TInt aError)
hgs
parents:
diff changeset
   344
    {
hgs
parents:
diff changeset
   345
    // get rid of everything we allocated
hgs
parents:
diff changeset
   346
    // deactivate the anim dll before killing window, otherwise anim dll dies too early
hgs
parents:
diff changeset
   347
    iAnim->Deactivate();
hgs
parents:
diff changeset
   348
    iAnim->Close();
hgs
parents:
diff changeset
   349
hgs
parents:
diff changeset
   350
    iAnimDll->Close();
hgs
parents:
diff changeset
   351
    
hgs
parents:
diff changeset
   352
    return aError;
hgs
parents:
diff changeset
   353
    }
hgs
parents:
diff changeset
   354
hgs
parents:
diff changeset
   355
void CProfilerButtonListener::RunL() 
hgs
parents:
diff changeset
   356
	{	
hgs
parents:
diff changeset
   357
    // resubscribe before processing new value to prevent missing updates
hgs
parents:
diff changeset
   358
	IssueRequest();
hgs
parents:
diff changeset
   359
	
hgs
parents:
diff changeset
   360
	TInt c = 0;
hgs
parents:
diff changeset
   361
	if(RProperty::Get(KProfilerKeyEventPropertyCat, EProfilerKeyEventPropertySample, c) == KErrNone)
hgs
parents:
diff changeset
   362
		{
hgs
parents:
diff changeset
   363
		// do something with event
hgs
parents:
diff changeset
   364
		LOGSTRING2("CProfilerButtonListener::RunL() - event [%d] received",c);
hgs
parents:
diff changeset
   365
	
hgs
parents:
diff changeset
   366
		iSample[0] = c;
hgs
parents:
diff changeset
   367
		iSample[1] = c >> 8;
hgs
parents:
diff changeset
   368
		iSample[2] = c >> 16;
hgs
parents:
diff changeset
   369
		iSample[3] = c >> 24;
hgs
parents:
diff changeset
   370
		
hgs
parents:
diff changeset
   371
		// Space for GPP sample time		
hgs
parents:
diff changeset
   372
		TUint32 sampleTime = User::NTickCount() - iSampleStartTime; 
hgs
parents:
diff changeset
   373
		LOGSTRING2("CProfilerButtonListener::RunL() - sample time is %d",sampleTime);
hgs
parents:
diff changeset
   374
		
hgs
parents:
diff changeset
   375
		iSample[4] = sampleTime;
hgs
parents:
diff changeset
   376
		iSample[5] = sampleTime >> 8;
hgs
parents:
diff changeset
   377
		iSample[6] = sampleTime >> 16;
hgs
parents:
diff changeset
   378
		iSample[7] = sampleTime >> 24;
hgs
parents:
diff changeset
   379
		
hgs
parents:
diff changeset
   380
		iSampler->AddSample(iSample, 8, 0xb0);
hgs
parents:
diff changeset
   381
		}
hgs
parents:
diff changeset
   382
	}
hgs
parents:
diff changeset
   383
	
hgs
parents:
diff changeset
   384
TInt CProfilerButtonListener::StartL()
hgs
parents:
diff changeset
   385
	{
hgs
parents:
diff changeset
   386
	LOGTEXT(_L("CProfilerButtonListener::StartL() - Activate touch server dll"));
hgs
parents:
diff changeset
   387
	TInt err(KErrNone);
hgs
parents:
diff changeset
   388
	
hgs
parents:
diff changeset
   389
	// get the property value
hgs
parents:
diff changeset
   390
	TInt r = RProperty::Get(KGppPropertyCat, EGppPropertySyncSampleNumber, iSampleStartTime);
hgs
parents:
diff changeset
   391
	if(r != KErrNone)
hgs
parents:
diff changeset
   392
		{
hgs
parents:
diff changeset
   393
		LOGSTRING2("CProfilerButtonListener::StartL() - getting iSyncOffset failed, error %d", r);
hgs
parents:
diff changeset
   394
		}
hgs
parents:
diff changeset
   395
	
hgs
parents:
diff changeset
   396
	iAnimDll = new (ELeave) RAnimDll(iWs);
hgs
parents:
diff changeset
   397
	LOGTEXT(_L("CProfilerButtonListener::StartL() - #1"));
hgs
parents:
diff changeset
   398
	
hgs
parents:
diff changeset
   399
	TParse* fp = new (ELeave) TParse();
hgs
parents:
diff changeset
   400
	CleanupStack::PushL(fp);
hgs
parents:
diff changeset
   401
	fp->Set( KDllName, &KDC_SHARED_LIB_DIR , NULL );    
hgs
parents:
diff changeset
   402
	LOGSTRING2("CProfilerButtonListener::StartL() - touch event server: %S" , &(fp->FullName()));
hgs
parents:
diff changeset
   403
hgs
parents:
diff changeset
   404
	err = iAnimDll->Load(fp->FullName());
hgs
parents:
diff changeset
   405
	// check if anim dll load failed
hgs
parents:
diff changeset
   406
	if(err != KErrNone)
hgs
parents:
diff changeset
   407
	    {
hgs
parents:
diff changeset
   408
        CleanupStack::PopAndDestroy(fp);
hgs
parents:
diff changeset
   409
	    // stop plugin if failed
hgs
parents:
diff changeset
   410
	    iAnimDll->Close();
hgs
parents:
diff changeset
   411
	    return KErrGeneral;
hgs
parents:
diff changeset
   412
	    }
hgs
parents:
diff changeset
   413
    CleanupStack::PopAndDestroy(fp);
hgs
parents:
diff changeset
   414
 	LOGTEXT(_L("CProfilerButtonListener::StartL() - #2"));
hgs
parents:
diff changeset
   415
hgs
parents:
diff changeset
   416
	iAnim = new (ELeave) RProfilerTouchEventAnim(*iAnimDll);
hgs
parents:
diff changeset
   417
 	LOGTEXT(_L("CProfilerButtonListener::StartL() - #3"));
hgs
parents:
diff changeset
   418
	iAnim->ConstructL(iMainWindow->Window());
hgs
parents:
diff changeset
   419
	
hgs
parents:
diff changeset
   420
	// activate the animation dll for collecting touch and key events
hgs
parents:
diff changeset
   421
	iAnim->Activate();
hgs
parents:
diff changeset
   422
hgs
parents:
diff changeset
   423
	// wait for a new sample
hgs
parents:
diff changeset
   424
	IssueRequest();
hgs
parents:
diff changeset
   425
	
hgs
parents:
diff changeset
   426
	// hide this window group from the app switcher
hgs
parents:
diff changeset
   427
	iMainWindow->Client()->Group().SetOrdinalPosition(-1);
hgs
parents:
diff changeset
   428
	iMainWindow->Client()->Group().EnableReceiptOfFocus(EFalse);
hgs
parents:
diff changeset
   429
	return KErrNone;
hgs
parents:
diff changeset
   430
	}
hgs
parents:
diff changeset
   431
hgs
parents:
diff changeset
   432
TInt CProfilerButtonListener::Stop() 
hgs
parents:
diff changeset
   433
	{
hgs
parents:
diff changeset
   434
	LOGTEXT(_L("CProfilerButtonListener::Stop() - enter"));
hgs
parents:
diff changeset
   435
	// deactivate the anim dll before killing window, otherwise anim dll dies too early
hgs
parents:
diff changeset
   436
	iAnim->Deactivate();
hgs
parents:
diff changeset
   437
	iAnim->Close();
hgs
parents:
diff changeset
   438
hgs
parents:
diff changeset
   439
	iAnimDll->Close();
hgs
parents:
diff changeset
   440
hgs
parents:
diff changeset
   441
	Cancel();
hgs
parents:
diff changeset
   442
	LOGTEXT(_L("CProfilerButtonListener::Stop() - exit"));
hgs
parents:
diff changeset
   443
	return KErrNone;
hgs
parents:
diff changeset
   444
	}
hgs
parents:
diff changeset
   445
hgs
parents:
diff changeset
   446
hgs
parents:
diff changeset
   447
///////////////////////////////////////////////////////////////////////////////
hgs
parents:
diff changeset
   448
////////////////////////// CWindow implementation /////////////////////////////
hgs
parents:
diff changeset
   449
///////////////////////////////////////////////////////////////////////////////
hgs
parents:
diff changeset
   450
hgs
parents:
diff changeset
   451
CWindow::CWindow(CWsClient* aClient)
hgs
parents:
diff changeset
   452
: iClient(aClient)
hgs
parents:
diff changeset
   453
	{
hgs
parents:
diff changeset
   454
    LOGTEXT(_L("CWindow::CWindow()"));
hgs
parents:
diff changeset
   455
	}
hgs
parents:
diff changeset
   456
hgs
parents:
diff changeset
   457
void CWindow::ConstructL (const TRect& aRect, CWindow* aParent)
hgs
parents:
diff changeset
   458
	{
hgs
parents:
diff changeset
   459
	LOGTEXT(_L("CWindow::ConstructL(): Start"));
hgs
parents:
diff changeset
   460
hgs
parents:
diff changeset
   461
	// If a parent window was specified, use it; if not, use the window group
hgs
parents:
diff changeset
   462
	// (aParent defaults to 0).
hgs
parents:
diff changeset
   463
	RWindowTreeNode* parent= aParent ? (RWindowTreeNode*) &(aParent->Window()) : &(iClient->iGroup);
hgs
parents:
diff changeset
   464
	iWindow=RWindow(iClient->iWs); // use app's session to window server
hgs
parents:
diff changeset
   465
	User::LeaveIfError(iWindow.Construct(*parent,(TUint32)this));
hgs
parents:
diff changeset
   466
	LOGSTRING2("CWindow::ConstructL(): Start - window handle is: 0x%08x", this);
hgs
parents:
diff changeset
   467
	iRect = aRect;
hgs
parents:
diff changeset
   468
	iWindow.SetExtent(iRect.iTl, iRect.Size()); // set extent relative to group coords
hgs
parents:
diff changeset
   469
	iWindow.Activate(); // window is now active
hgs
parents:
diff changeset
   470
	LOGTEXT(_L("CWindow::ConstructL(): End"));
hgs
parents:
diff changeset
   471
	}
hgs
parents:
diff changeset
   472
hgs
parents:
diff changeset
   473
hgs
parents:
diff changeset
   474
CWindow::~CWindow()
hgs
parents:
diff changeset
   475
	{
hgs
parents:
diff changeset
   476
    LOGTEXT(_L("CWindow::~CWindow(): Start"));
hgs
parents:
diff changeset
   477
	iWindow.Close(); // close our window
hgs
parents:
diff changeset
   478
    LOGTEXT(_L("CWindow::~CWindow(): End"));
hgs
parents:
diff changeset
   479
	}
hgs
parents:
diff changeset
   480
hgs
parents:
diff changeset
   481
RWindow& CWindow::Window()
hgs
parents:
diff changeset
   482
	{
hgs
parents:
diff changeset
   483
    LOGTEXT(_L("CWindow::Window()"));
hgs
parents:
diff changeset
   484
	return iWindow;
hgs
parents:
diff changeset
   485
	}
hgs
parents:
diff changeset
   486
hgs
parents:
diff changeset
   487
CWindowGc* CWindow::SystemGc()
hgs
parents:
diff changeset
   488
	{
hgs
parents:
diff changeset
   489
    LOGTEXT(_L("CWindow::SystemGc()"));
hgs
parents:
diff changeset
   490
	return iClient->iGc;
hgs
parents:
diff changeset
   491
	}
hgs
parents:
diff changeset
   492
hgs
parents:
diff changeset
   493
/////////////////////////////////////////////////////////////////////////////////////
hgs
parents:
diff changeset
   494
/////////////////////////// CWsClient implementation ////////////////////////////////
hgs
parents:
diff changeset
   495
/////////////////////////////////////////////////////////////////////////////////////
hgs
parents:
diff changeset
   496
CWsClient::CWsClient()
hgs
parents:
diff changeset
   497
: CActive(CActive::EPriorityStandard)
hgs
parents:
diff changeset
   498
	{
hgs
parents:
diff changeset
   499
    LOGTEXT(_L("CWsClient::CWsClient()"));
hgs
parents:
diff changeset
   500
	}
hgs
parents:
diff changeset
   501
hgs
parents:
diff changeset
   502
void CWsClient::ConstructL()
hgs
parents:
diff changeset
   503
	{
hgs
parents:
diff changeset
   504
    LOGTEXT(_L("CWsClient::ConstructL() - Start"));
hgs
parents:
diff changeset
   505
    TInt r = RProperty::Define(EProfilerKeyEventPropertySample, RProperty::EInt, KAllowAllPolicy, KCapabilityNone);
hgs
parents:
diff changeset
   506
    if (r!=KErrAlreadyExists)
hgs
parents:
diff changeset
   507
        {
hgs
parents:
diff changeset
   508
        User::LeaveIfError(r);
hgs
parents:
diff changeset
   509
        }
hgs
parents:
diff changeset
   510
    
hgs
parents:
diff changeset
   511
	CActiveScheduler::Add(this);
hgs
parents:
diff changeset
   512
hgs
parents:
diff changeset
   513
	// attach to 
hgs
parents:
diff changeset
   514
	User::LeaveIfError(iProperty.Attach(KProfilerKeyEventPropertyCat,EProfilerKeyEventPropertySample));
hgs
parents:
diff changeset
   515
    
hgs
parents:
diff changeset
   516
	// get a session going
hgs
parents:
diff changeset
   517
	User::LeaveIfError(iWs.Connect());
hgs
parents:
diff changeset
   518
hgs
parents:
diff changeset
   519
	// construct screen device and graphics context
hgs
parents:
diff changeset
   520
	iScreen=new (ELeave) CWsScreenDevice(iWs); // make device for this session
hgs
parents:
diff changeset
   521
	User::LeaveIfError(iScreen->Construct( 0 )); // and complete its construction
hgs
parents:
diff changeset
   522
	User::LeaveIfError(iScreen->CreateContext(iGc)); // create graphics context
hgs
parents:
diff changeset
   523
hgs
parents:
diff changeset
   524
	// construct our one and only window group
hgs
parents:
diff changeset
   525
	iGroup=RWindowGroup(iWs);
hgs
parents:
diff changeset
   526
	User::LeaveIfError(iGroup.Construct((TInt)this, EFalse)); // meaningless handle; enable focus
hgs
parents:
diff changeset
   527
	
hgs
parents:
diff changeset
   528
	// construct main window
hgs
parents:
diff changeset
   529
	ConstructMainWindowL();
hgs
parents:
diff changeset
   530
hgs
parents:
diff changeset
   531
	LOGTEXT(_L("CWsClient::CWsClient() - End"));
hgs
parents:
diff changeset
   532
	}
hgs
parents:
diff changeset
   533
hgs
parents:
diff changeset
   534
CWsClient::~CWsClient()
hgs
parents:
diff changeset
   535
	{
hgs
parents:
diff changeset
   536
    LOGTEXT(_L("CWsClient::~CWsClient() - Start"));
hgs
parents:
diff changeset
   537
    
hgs
parents:
diff changeset
   538
	// get rid of everything we allocated
hgs
parents:
diff changeset
   539
	delete iGc;
hgs
parents:
diff changeset
   540
	delete iScreen;
hgs
parents:
diff changeset
   541
	
hgs
parents:
diff changeset
   542
	iGroup.Close();
hgs
parents:
diff changeset
   543
	// finish with window server
hgs
parents:
diff changeset
   544
	iWs.Close();
hgs
parents:
diff changeset
   545
	
hgs
parents:
diff changeset
   546
    LOGTEXT(_L("CWsClient::~CWsClient() - Exit"));
hgs
parents:
diff changeset
   547
	}
hgs
parents:
diff changeset
   548
hgs
parents:
diff changeset
   549
void CWsClient::Exit()
hgs
parents:
diff changeset
   550
	{
hgs
parents:
diff changeset
   551
    LOGTEXT(_L("CWsClient::Exit() - Start"));
hgs
parents:
diff changeset
   552
hgs
parents:
diff changeset
   553
	// destroy window group
hgs
parents:
diff changeset
   554
	iGroup.Close();
hgs
parents:
diff changeset
   555
	// finish with window server
hgs
parents:
diff changeset
   556
    iProperty.Close();
hgs
parents:
diff changeset
   557
	iWs.Close();
hgs
parents:
diff changeset
   558
    LOGTEXT(_L("CWsClient::Exit() - Exit"));
hgs
parents:
diff changeset
   559
	}
hgs
parents:
diff changeset
   560
hgs
parents:
diff changeset
   561
void CWsClient::IssueRequest()
hgs
parents:
diff changeset
   562
	{
hgs
parents:
diff changeset
   563
    LOGTEXT(_L("CWsClient::IssueRequest() - Start"));
hgs
parents:
diff changeset
   564
    iProperty.Subscribe( iStatus );
hgs
parents:
diff changeset
   565
    SetActive(); // so we're now active
hgs
parents:
diff changeset
   566
    LOGTEXT(_L("CWsClient::IssueRequest() - Exit"));
hgs
parents:
diff changeset
   567
	}
hgs
parents:
diff changeset
   568
hgs
parents:
diff changeset
   569
void CWsClient::DoCancel()
hgs
parents:
diff changeset
   570
	{
hgs
parents:
diff changeset
   571
    LOGTEXT(_L("CWsClient::DoCancel() - Start"));
hgs
parents:
diff changeset
   572
	// clean up the sample property
hgs
parents:
diff changeset
   573
    iProperty.Cancel();
hgs
parents:
diff changeset
   574
    iProperty.Close();
hgs
parents:
diff changeset
   575
    LOGTEXT(_L("CWsClient::DoCancel() - Exit"));
hgs
parents:
diff changeset
   576
	}
hgs
parents:
diff changeset
   577
hgs
parents:
diff changeset
   578
void CWsClient::ConstructMainWindowL()
hgs
parents:
diff changeset
   579
	{
hgs
parents:
diff changeset
   580
    LOGTEXT(_L("CWsClient::ConstructMainWindowL()"));
hgs
parents:
diff changeset
   581
	}
hgs
parents:
diff changeset
   582