perfsrv/piprofiler/engine/src/SamplerController.cpp
author hgs
Mon, 06 Sep 2010 15:00:47 +0300
changeset 51 98307c651589
child 62 1c2bb2fc7c87
permissions -rw-r--r--
201035
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
51
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 "SamplerController.h"
hgs
parents:
diff changeset
    20
//#include <piprofiler/EngineUIDs.h>
hgs
parents:
diff changeset
    21
hgs
parents:
diff changeset
    22
// CONSTANTS
hgs
parents:
diff changeset
    23
const TInt KMaxSamplerPluginCount = 20;
hgs
parents:
diff changeset
    24
const TInt KMaxExtraSettingsItemCount = 6;
hgs
parents:
diff changeset
    25
hgs
parents:
diff changeset
    26
// LITERALS
hgs
parents:
diff changeset
    27
_LIT8(KSamplingPeriod, "sampling_period_ms");
hgs
parents:
diff changeset
    28
_LIT8(KNewLine8, "\n");
hgs
parents:
diff changeset
    29
_LIT8(KEquals8, "=");
hgs
parents:
diff changeset
    30
_LIT8(KSettingsText, " settings");
hgs
parents:
diff changeset
    31
_LIT(KNewLine, "\n");
hgs
parents:
diff changeset
    32
_LIT(KEquals, "=");
hgs
parents:
diff changeset
    33
_LIT(KCommentSeparator, " ; ");
hgs
parents:
diff changeset
    34
hgs
parents:
diff changeset
    35
CSamplerController* CSamplerController::NewL(CProfilerSampleStream& aStream)
hgs
parents:
diff changeset
    36
    {
hgs
parents:
diff changeset
    37
    CSamplerController* self = new( ELeave ) CSamplerController(aStream);
hgs
parents:
diff changeset
    38
    CleanupStack::PushL( self );
hgs
parents:
diff changeset
    39
    self->ConstructL( );
hgs
parents:
diff changeset
    40
    CleanupStack::Pop( self );
hgs
parents:
diff changeset
    41
    return self;
hgs
parents:
diff changeset
    42
    }
hgs
parents:
diff changeset
    43
hgs
parents:
diff changeset
    44
void CSamplerController::ConstructL()
hgs
parents:
diff changeset
    45
	{
hgs
parents:
diff changeset
    46
	// initiate sampler plugin list
hgs
parents:
diff changeset
    47
	InitialiseSamplerListL();
hgs
parents:
diff changeset
    48
	}
hgs
parents:
diff changeset
    49
hgs
parents:
diff changeset
    50
hgs
parents:
diff changeset
    51
CSamplerController::CSamplerController(CProfilerSampleStream& aStream) : 
hgs
parents:
diff changeset
    52
    iStream(aStream)
hgs
parents:
diff changeset
    53
	{
hgs
parents:
diff changeset
    54
	}
hgs
parents:
diff changeset
    55
hgs
parents:
diff changeset
    56
void CSamplerController::InitialiseSamplerListL()
hgs
parents:
diff changeset
    57
    {
hgs
parents:
diff changeset
    58
    // create new sampler plugin array
hgs
parents:
diff changeset
    59
    iPluginArray = new (ELeave) CArrayPtrFlat<CSamplerPluginInterface>( KMaxSamplerPluginCount );
hgs
parents:
diff changeset
    60
    
hgs
parents:
diff changeset
    61
    // create plugin loader instance
hgs
parents:
diff changeset
    62
    iPluginLoader = CSamplerPluginLoader::NewL();
hgs
parents:
diff changeset
    63
    
hgs
parents:
diff changeset
    64
    // register sampler controller to get notifications of succesfull plugin load
hgs
parents:
diff changeset
    65
    iPluginLoader->SetObserver( this );
hgs
parents:
diff changeset
    66
    
hgs
parents:
diff changeset
    67
    // load sampler plugins asynchronously
hgs
parents:
diff changeset
    68
    iPluginLoader->LoadAsyncL( iPluginArray );
hgs
parents:
diff changeset
    69
    
hgs
parents:
diff changeset
    70
    LOGTEXT(_L(" RSamplerController::InitialiseUserSideSamplerList - exit"));	
hgs
parents:
diff changeset
    71
    }
hgs
parents:
diff changeset
    72
hgs
parents:
diff changeset
    73
CSamplerController::~CSamplerController()
hgs
parents:
diff changeset
    74
	{
hgs
parents:
diff changeset
    75
	LOGTEXT(_L("CSamplerController::~CSamplerController - entry" ));
hgs
parents:
diff changeset
    76
	
hgs
parents:
diff changeset
    77
    if ( iPluginArray )
hgs
parents:
diff changeset
    78
        {
hgs
parents:
diff changeset
    79
        // destroy the plugin instances
hgs
parents:
diff changeset
    80
        // empty loaded plugins from array
hgs
parents:
diff changeset
    81
        for(TInt i(0);i<iPluginArray->Count();i++)
hgs
parents:
diff changeset
    82
            {
hgs
parents:
diff changeset
    83
            if(iPluginArray->At(i))
hgs
parents:
diff changeset
    84
                {
hgs
parents:
diff changeset
    85
                delete iPluginArray->At(i);
hgs
parents:
diff changeset
    86
                iPluginArray->At(i) = NULL;
hgs
parents:
diff changeset
    87
                }
hgs
parents:
diff changeset
    88
            }
hgs
parents:
diff changeset
    89
        iPluginArray->Reset();
hgs
parents:
diff changeset
    90
        delete iPluginArray;
hgs
parents:
diff changeset
    91
        iPluginArray = NULL;
hgs
parents:
diff changeset
    92
        }
hgs
parents:
diff changeset
    93
	
hgs
parents:
diff changeset
    94
	if ( iPluginLoader )
hgs
parents:
diff changeset
    95
	    {
hgs
parents:
diff changeset
    96
	    iPluginLoader->AbortAsyncLoad();
hgs
parents:
diff changeset
    97
	    delete iPluginLoader;
hgs
parents:
diff changeset
    98
	    iPluginLoader = NULL;
hgs
parents:
diff changeset
    99
	    }
hgs
parents:
diff changeset
   100
    
hgs
parents:
diff changeset
   101
	LOGTEXT(_L("CSamplerController::~CSamplerController - exit" ));
hgs
parents:
diff changeset
   102
	}
hgs
parents:
diff changeset
   103
hgs
parents:
diff changeset
   104
void CSamplerController::SetObserver(MSamplerControllerObserver* aObserver)
hgs
parents:
diff changeset
   105
    {
hgs
parents:
diff changeset
   106
    iObserver = aObserver;
hgs
parents:
diff changeset
   107
    }
hgs
parents:
diff changeset
   108
    
hgs
parents:
diff changeset
   109
TInt CSamplerController::UpdateSavedSamplerAttributesL(CDesC8ArrayFlat* aSavedLineArray, CArrayFixFlat<TSamplerAttributes>* aAttributes)
hgs
parents:
diff changeset
   110
    {
hgs
parents:
diff changeset
   111
    TInt err(KErrNone);
hgs
parents:
diff changeset
   112
    TInt count(iPluginArray->Count());
hgs
parents:
diff changeset
   113
    // all plugins get their own settings among whole lump of setting strings
hgs
parents:
diff changeset
   114
    CSamplerPluginInterface* plugin = NULL;
hgs
parents:
diff changeset
   115
    
hgs
parents:
diff changeset
   116
    // loop through the plugin array
hgs
parents:
diff changeset
   117
    for(TInt i(0);i<count;i++)
hgs
parents:
diff changeset
   118
        {
hgs
parents:
diff changeset
   119
        // get each plugin at a time
hgs
parents:
diff changeset
   120
        plugin = iPluginArray->At(i);
hgs
parents:
diff changeset
   121
        
hgs
parents:
diff changeset
   122
        // call each plugin to sort out its own settings 
hgs
parents:
diff changeset
   123
        err = plugin->ConvertRawSettingsToAttributes(aSavedLineArray);
hgs
parents:
diff changeset
   124
        
hgs
parents:
diff changeset
   125
        // get plugin specific attributes, array may contain attributes of several sub samplers
hgs
parents:
diff changeset
   126
        plugin->GetAttributesL(aAttributes); 
hgs
parents:
diff changeset
   127
        }
hgs
parents:
diff changeset
   128
    
hgs
parents:
diff changeset
   129
    return err;
hgs
parents:
diff changeset
   130
    }
hgs
parents:
diff changeset
   131
hgs
parents:
diff changeset
   132
TInt CSamplerController::SetSamplerSettingsL(TInt aUid, TSamplerAttributes& aAttributes)
hgs
parents:
diff changeset
   133
    {
hgs
parents:
diff changeset
   134
    // parse right plugin based on UID
hgs
parents:
diff changeset
   135
    CSamplerPluginInterface* plugin = GetPlugin(TUid::Uid(aUid));
hgs
parents:
diff changeset
   136
    
hgs
parents:
diff changeset
   137
    // set the sampler attributes of a sampler plugin
hgs
parents:
diff changeset
   138
    plugin->SetAttributesL(aAttributes);
hgs
parents:
diff changeset
   139
    
hgs
parents:
diff changeset
   140
    return KErrNone;
hgs
parents:
diff changeset
   141
    }
hgs
parents:
diff changeset
   142
hgs
parents:
diff changeset
   143
void CSamplerController::GetSamplerAttributesL(CArrayFixFlat<TSamplerAttributes>* aAttributes)
hgs
parents:
diff changeset
   144
    {
hgs
parents:
diff changeset
   145
    CSamplerPluginInterface* plugin = NULL;
hgs
parents:
diff changeset
   146
    
hgs
parents:
diff changeset
   147
    TInt count(iPluginArray->Count());
hgs
parents:
diff changeset
   148
    
hgs
parents:
diff changeset
   149
    // get first all the attributes from all the sampler plugins listed in iPluginArray
hgs
parents:
diff changeset
   150
    for(TInt i(0);i<count;i++)
hgs
parents:
diff changeset
   151
        {
hgs
parents:
diff changeset
   152
        // get the plugin first
hgs
parents:
diff changeset
   153
        plugin = iPluginArray->At(i);
hgs
parents:
diff changeset
   154
        
hgs
parents:
diff changeset
   155
        // get plugin specific attributes, array may contain attributes of several sub samplers
hgs
parents:
diff changeset
   156
        plugin->GetAttributesL(aAttributes); 
hgs
parents:
diff changeset
   157
        }
hgs
parents:
diff changeset
   158
    }
hgs
parents:
diff changeset
   159
hgs
parents:
diff changeset
   160
void CSamplerController::ComposeAttributesToSettingsFileFormat(RFile& aFile, CArrayFixFlat<TSamplerAttributes>* aAttributes)
hgs
parents:
diff changeset
   161
    {
hgs
parents:
diff changeset
   162
    // write immediately to settings file
hgs
parents:
diff changeset
   163
    ComposeSettingsText(aFile, aAttributes);
hgs
parents:
diff changeset
   164
    }
hgs
parents:
diff changeset
   165
hgs
parents:
diff changeset
   166
void CSamplerController::ComposeSettingsText(RFile& aFile, CArrayFixFlat<TSamplerAttributes>* aAttrArray)
hgs
parents:
diff changeset
   167
    {
hgs
parents:
diff changeset
   168
    // temporary buffer for a setting line
hgs
parents:
diff changeset
   169
    TBuf<384> settingLine;
hgs
parents:
diff changeset
   170
    TBuf8<384> settingLine8;
hgs
parents:
diff changeset
   171
    TInt itemCount(0);
hgs
parents:
diff changeset
   172
    TBuf<266> tBuf;
hgs
parents:
diff changeset
   173
    
hgs
parents:
diff changeset
   174
    TSamplerAttributes attr;
hgs
parents:
diff changeset
   175
    
hgs
parents:
diff changeset
   176
    for(TInt i(0);i<aAttrArray->Count();i++)
hgs
parents:
diff changeset
   177
        {
hgs
parents:
diff changeset
   178
        // get the attribute container 
hgs
parents:
diff changeset
   179
        attr = aAttrArray->At(i);
hgs
parents:
diff changeset
   180
        
hgs
parents:
diff changeset
   181
        // add the name and description of the sampler in brackets first
hgs
parents:
diff changeset
   182
        settingLine8.Copy(KBracketOpen);
hgs
parents:
diff changeset
   183
        settingLine8.Append(attr.iShortName);
hgs
parents:
diff changeset
   184
        settingLine8.Append(KBracketClose);
hgs
parents:
diff changeset
   185
        settingLine8.Append(KCommentSeparator());
hgs
parents:
diff changeset
   186
        settingLine8.Append(attr.iName);
hgs
parents:
diff changeset
   187
        settingLine8.Append(KSettingsText);
hgs
parents:
diff changeset
   188
        settingLine8.Append(KNewLine8);
hgs
parents:
diff changeset
   189
        aFile.Write(settingLine8);
hgs
parents:
diff changeset
   190
        
hgs
parents:
diff changeset
   191
        // enabled
hgs
parents:
diff changeset
   192
        settingLine8.Copy(KEnabled);
hgs
parents:
diff changeset
   193
        settingLine8.Append(KEquals8);
hgs
parents:
diff changeset
   194
        settingLine8.Append(Bool2Str(attr.iEnabled));
hgs
parents:
diff changeset
   195
        settingLine8.Append(KNewLine8);
hgs
parents:
diff changeset
   196
        aFile.Write(settingLine8);
hgs
parents:
diff changeset
   197
        
hgs
parents:
diff changeset
   198
        // sampling rate (if set)
hgs
parents:
diff changeset
   199
        if( attr.iSampleRate != -1 )
hgs
parents:
diff changeset
   200
            {
hgs
parents:
diff changeset
   201
            settingLine8.Copy(KSamplingPeriod);
hgs
parents:
diff changeset
   202
            settingLine8.Append(KEquals8);
hgs
parents:
diff changeset
   203
            settingLine8.Append(Int2Str(attr.iSampleRate));
hgs
parents:
diff changeset
   204
            settingLine8.Append(KNewLine8);
hgs
parents:
diff changeset
   205
            aFile.Write(settingLine8);
hgs
parents:
diff changeset
   206
            }
hgs
parents:
diff changeset
   207
        
hgs
parents:
diff changeset
   208
        itemCount = attr.iItemCount;
hgs
parents:
diff changeset
   209
        
hgs
parents:
diff changeset
   210
        // check if item count set is sane, max extra settings item count 6
hgs
parents:
diff changeset
   211
        if(itemCount > KMaxExtraSettingsItemCount)
hgs
parents:
diff changeset
   212
            {
hgs
parents:
diff changeset
   213
            // probably forgot to set the item count value in plugin => safe to set it 0
hgs
parents:
diff changeset
   214
            itemCount = 0;
hgs
parents:
diff changeset
   215
            }
hgs
parents:
diff changeset
   216
        
hgs
parents:
diff changeset
   217
        // setting items
hgs
parents:
diff changeset
   218
        for (TInt j(0);j<itemCount;j++)
hgs
parents:
diff changeset
   219
            {
hgs
parents:
diff changeset
   220
            switch(j)
hgs
parents:
diff changeset
   221
                {
hgs
parents:
diff changeset
   222
                case 0: // settingItem1
hgs
parents:
diff changeset
   223
                    {
hgs
parents:
diff changeset
   224
                    settingLine.Copy(attr.iSettingItem1.iSettingText);
hgs
parents:
diff changeset
   225
                    settingLine.Append(KEquals());
hgs
parents:
diff changeset
   226
                    settingLine.Append(attr.iSettingItem1.iValue);
hgs
parents:
diff changeset
   227
                    settingLine.Append(KCommentSeparator());
hgs
parents:
diff changeset
   228
                    settingLine.Append(attr.iSettingItem1.iUIText);
hgs
parents:
diff changeset
   229
                    settingLine.Append(KNewLine());
hgs
parents:
diff changeset
   230
                    CnvUtfConverter::ConvertFromUnicodeToUtf8(settingLine8, settingLine);
hgs
parents:
diff changeset
   231
                    aFile.Write(settingLine8);
hgs
parents:
diff changeset
   232
                    break;
hgs
parents:
diff changeset
   233
                    }
hgs
parents:
diff changeset
   234
                case 1: // settingItem2
hgs
parents:
diff changeset
   235
                    {
hgs
parents:
diff changeset
   236
                    settingLine.Copy(attr.iSettingItem2.iSettingText);
hgs
parents:
diff changeset
   237
                    settingLine.Append(KEquals());
hgs
parents:
diff changeset
   238
                    settingLine.Append(attr.iSettingItem2.iValue);
hgs
parents:
diff changeset
   239
                    settingLine.Append(KCommentSeparator());
hgs
parents:
diff changeset
   240
                    settingLine.Append(attr.iSettingItem2.iUIText);
hgs
parents:
diff changeset
   241
                    settingLine.Append(KNewLine());
hgs
parents:
diff changeset
   242
                    CnvUtfConverter::ConvertFromUnicodeToUtf8(settingLine8, settingLine);
hgs
parents:
diff changeset
   243
                    aFile.Write(settingLine8);
hgs
parents:
diff changeset
   244
                    break;
hgs
parents:
diff changeset
   245
                    }
hgs
parents:
diff changeset
   246
                case 2: // settingItem3
hgs
parents:
diff changeset
   247
                    {
hgs
parents:
diff changeset
   248
                    settingLine.Copy(attr.iSettingItem3.iSettingText);
hgs
parents:
diff changeset
   249
                    settingLine.Append(KEquals());
hgs
parents:
diff changeset
   250
                    settingLine.Append(attr.iSettingItem3.iValue);
hgs
parents:
diff changeset
   251
                    settingLine.Append(KCommentSeparator());
hgs
parents:
diff changeset
   252
                    settingLine.Append(attr.iSettingItem3.iUIText);
hgs
parents:
diff changeset
   253
                    settingLine.Append(KNewLine());
hgs
parents:
diff changeset
   254
                    CnvUtfConverter::ConvertFromUnicodeToUtf8(settingLine8, settingLine);
hgs
parents:
diff changeset
   255
                    aFile.Write(settingLine8);
hgs
parents:
diff changeset
   256
                    break;
hgs
parents:
diff changeset
   257
                    }
hgs
parents:
diff changeset
   258
                case 3: // settingItem4
hgs
parents:
diff changeset
   259
                    {
hgs
parents:
diff changeset
   260
                    settingLine.Copy(attr.iSettingItem4.iSettingText);
hgs
parents:
diff changeset
   261
                    settingLine.Append(KEquals());
hgs
parents:
diff changeset
   262
                    settingLine.Append(attr.iSettingItem4.iValue);
hgs
parents:
diff changeset
   263
                    settingLine.Append(KCommentSeparator());
hgs
parents:
diff changeset
   264
                    settingLine.Append(attr.iSettingItem4.iUIText);
hgs
parents:
diff changeset
   265
                    settingLine.Append(KNewLine());
hgs
parents:
diff changeset
   266
                    CnvUtfConverter::ConvertFromUnicodeToUtf8(settingLine8, settingLine);
hgs
parents:
diff changeset
   267
                    aFile.Write(settingLine8);
hgs
parents:
diff changeset
   268
                    break;
hgs
parents:
diff changeset
   269
                    }
hgs
parents:
diff changeset
   270
                case 4: // settingItem5
hgs
parents:
diff changeset
   271
                    {
hgs
parents:
diff changeset
   272
                    settingLine.Copy(attr.iSettingItem5.iSettingText);
hgs
parents:
diff changeset
   273
                    settingLine.Append(KEquals());
hgs
parents:
diff changeset
   274
                    settingLine.Append(attr.iSettingItem5.iValue);
hgs
parents:
diff changeset
   275
                    settingLine.Append(KCommentSeparator());
hgs
parents:
diff changeset
   276
                    settingLine.Append(attr.iSettingItem5.iUIText);
hgs
parents:
diff changeset
   277
                    settingLine.Append(KNewLine());
hgs
parents:
diff changeset
   278
                    CnvUtfConverter::ConvertFromUnicodeToUtf8(settingLine8, settingLine);
hgs
parents:
diff changeset
   279
                    aFile.Write(settingLine8);
hgs
parents:
diff changeset
   280
                    break;
hgs
parents:
diff changeset
   281
                    }
hgs
parents:
diff changeset
   282
                case 5: // settingItem6
hgs
parents:
diff changeset
   283
                    {
hgs
parents:
diff changeset
   284
                    settingLine.Copy(attr.iSettingItem6.iSettingText);
hgs
parents:
diff changeset
   285
                    settingLine.Append(KEquals());
hgs
parents:
diff changeset
   286
                    settingLine.Append(attr.iSettingItem6.iValue);
hgs
parents:
diff changeset
   287
                    settingLine.Append(KCommentSeparator());
hgs
parents:
diff changeset
   288
                    settingLine.Append(attr.iSettingItem6.iUIText);
hgs
parents:
diff changeset
   289
                    settingLine.Append(KNewLine());
hgs
parents:
diff changeset
   290
                    CnvUtfConverter::ConvertFromUnicodeToUtf8(settingLine8, settingLine);
hgs
parents:
diff changeset
   291
                    aFile.Write(settingLine8);
hgs
parents:
diff changeset
   292
                    break;
hgs
parents:
diff changeset
   293
                    }
hgs
parents:
diff changeset
   294
                }
hgs
parents:
diff changeset
   295
            }
hgs
parents:
diff changeset
   296
        }
hgs
parents:
diff changeset
   297
    }
hgs
parents:
diff changeset
   298
hgs
parents:
diff changeset
   299
// ----------------------------------------------------------------------------
hgs
parents:
diff changeset
   300
// Converts given descriptor into TBool value.
hgs
parents:
diff changeset
   301
// ----------------------------------------------------------------------------
hgs
parents:
diff changeset
   302
//
hgs
parents:
diff changeset
   303
inline void CSamplerController::Str2Bool(const TDesC8& aBuf, TBool& aValue)
hgs
parents:
diff changeset
   304
    {
hgs
parents:
diff changeset
   305
    if (aBuf.CompareF(KFalse) == 0)
hgs
parents:
diff changeset
   306
        aValue = EFalse;
hgs
parents:
diff changeset
   307
    else
hgs
parents:
diff changeset
   308
        aValue = ETrue;
hgs
parents:
diff changeset
   309
    }
hgs
parents:
diff changeset
   310
hgs
parents:
diff changeset
   311
// ----------------------------------------------------------------------------
hgs
parents:
diff changeset
   312
// Converts given descriptor into TInt value.
hgs
parents:
diff changeset
   313
// ----------------------------------------------------------------------------
hgs
parents:
diff changeset
   314
//
hgs
parents:
diff changeset
   315
inline void CSamplerController::Str2Int(const TDesC8& aBuf, TInt& aValue)
hgs
parents:
diff changeset
   316
    {
hgs
parents:
diff changeset
   317
    TLex8 conv;
hgs
parents:
diff changeset
   318
    conv.Assign(aBuf);
hgs
parents:
diff changeset
   319
    
hgs
parents:
diff changeset
   320
    if (conv.Val(aValue) != KErrNone)
hgs
parents:
diff changeset
   321
        aValue = 0;
hgs
parents:
diff changeset
   322
    }
hgs
parents:
diff changeset
   323
hgs
parents:
diff changeset
   324
// ----------------------------------------------------------------------------
hgs
parents:
diff changeset
   325
// Converts given descriptor into TInt value.
hgs
parents:
diff changeset
   326
// ----------------------------------------------------------------------------
hgs
parents:
diff changeset
   327
//
hgs
parents:
diff changeset
   328
inline void CSamplerController::Str2Int(const TDesC8& aBuf, TUint32& aValue)
hgs
parents:
diff changeset
   329
    {
hgs
parents:
diff changeset
   330
    TInt temp(0);
hgs
parents:
diff changeset
   331
    
hgs
parents:
diff changeset
   332
    TLex8 conv;
hgs
parents:
diff changeset
   333
    conv.Assign(aBuf);
hgs
parents:
diff changeset
   334
    
hgs
parents:
diff changeset
   335
    if (conv.Val(temp) != KErrNone)
hgs
parents:
diff changeset
   336
        aValue = 0;
hgs
parents:
diff changeset
   337
    else
hgs
parents:
diff changeset
   338
        aValue = (TUint32)temp;
hgs
parents:
diff changeset
   339
    }
hgs
parents:
diff changeset
   340
hgs
parents:
diff changeset
   341
// ----------------------------------------------------------------------------
hgs
parents:
diff changeset
   342
// Converts given boolean into a descriptor.
hgs
parents:
diff changeset
   343
// ----------------------------------------------------------------------------
hgs
parents:
diff changeset
   344
//
hgs
parents:
diff changeset
   345
inline TBuf8<16> CSamplerController::Bool2Str(const TBool& aValue)
hgs
parents:
diff changeset
   346
    {
hgs
parents:
diff changeset
   347
    TBuf8<16> buf;
hgs
parents:
diff changeset
   348
    
hgs
parents:
diff changeset
   349
    if (aValue)
hgs
parents:
diff changeset
   350
        buf.Copy(KTrue);
hgs
parents:
diff changeset
   351
    else
hgs
parents:
diff changeset
   352
        buf.Copy(KFalse);
hgs
parents:
diff changeset
   353
    
hgs
parents:
diff changeset
   354
    return buf;
hgs
parents:
diff changeset
   355
    }
hgs
parents:
diff changeset
   356
hgs
parents:
diff changeset
   357
// ----------------------------------------------------------------------------
hgs
parents:
diff changeset
   358
// Converts given integer into a descriptor.
hgs
parents:
diff changeset
   359
// ----------------------------------------------------------------------------
hgs
parents:
diff changeset
   360
//
hgs
parents:
diff changeset
   361
inline TBuf8<16> CSamplerController::Int2Str(const TInt& aValue)
hgs
parents:
diff changeset
   362
    {
hgs
parents:
diff changeset
   363
    TBuf8<16> buf;
hgs
parents:
diff changeset
   364
    buf.AppendNum(aValue);
hgs
parents:
diff changeset
   365
   
hgs
parents:
diff changeset
   366
    return buf;
hgs
parents:
diff changeset
   367
    }
hgs
parents:
diff changeset
   368
hgs
parents:
diff changeset
   369
hgs
parents:
diff changeset
   370
void CSamplerController::HandlePluginLoaded( KSamplerPluginLoaderStatus aStatus )
hgs
parents:
diff changeset
   371
    {
hgs
parents:
diff changeset
   372
    
hgs
parents:
diff changeset
   373
    // process status value
hgs
parents:
diff changeset
   374
    switch(aStatus)
hgs
parents:
diff changeset
   375
        {
hgs
parents:
diff changeset
   376
        case 0:
hgs
parents:
diff changeset
   377
            LOGSTRING2("RSamplerController - one plugin loaded, status: %d", aStatus);
hgs
parents:
diff changeset
   378
            break;
hgs
parents:
diff changeset
   379
        case 1:
hgs
parents:
diff changeset
   380
            LOGSTRING2("RSamplerController - a plugin load failed: %d", aStatus);
hgs
parents:
diff changeset
   381
            break;
hgs
parents:
diff changeset
   382
        case 2:
hgs
parents:
diff changeset
   383
            LOGSTRING2("RSamplerController - plugin loading aborted: %d", aStatus);
hgs
parents:
diff changeset
   384
            break;
hgs
parents:
diff changeset
   385
        case 3:
hgs
parents:
diff changeset
   386
            LOGSTRING2("RSamplerController - all plugins loaded: %d", aStatus);
hgs
parents:
diff changeset
   387
            TRAPD(err, iPluginLoader->SortPluginsL(iPluginArray));
hgs
parents:
diff changeset
   388
            if(err != KErrNone)
hgs
parents:
diff changeset
   389
                {
hgs
parents:
diff changeset
   390
                LOGTEXT(_L("Sampler controller unable to sort plugins"));
hgs
parents:
diff changeset
   391
                }
hgs
parents:
diff changeset
   392
            
hgs
parents:
diff changeset
   393
            // call engine to finalize the startup
hgs
parents:
diff changeset
   394
            TRAPD(result, iObserver->HandleSamplerControllerReadyL(););
hgs
parents:
diff changeset
   395
            if(result != KErrNone)
hgs
parents:
diff changeset
   396
                {
hgs
parents:
diff changeset
   397
                LOGTEXT(_L("Failed to notify engine"));
hgs
parents:
diff changeset
   398
                }
hgs
parents:
diff changeset
   399
            break;
hgs
parents:
diff changeset
   400
        case 4:
hgs
parents:
diff changeset
   401
            LOGSTRING2("RSamplerController - error in loading plugins: %d", aStatus);
hgs
parents:
diff changeset
   402
            break;
hgs
parents:
diff changeset
   403
        default:
hgs
parents:
diff changeset
   404
            break;
hgs
parents:
diff changeset
   405
        }
hgs
parents:
diff changeset
   406
    }
hgs
parents:
diff changeset
   407
hgs
parents:
diff changeset
   408
hgs
parents:
diff changeset
   409
CSamplerPluginInterface* CSamplerController::GetPlugin(TUid aUid)
hgs
parents:
diff changeset
   410
	{
hgs
parents:
diff changeset
   411
	LOGTEXT(_L("RSamplerController::GetPlugin - entry"));
hgs
parents:
diff changeset
   412
	// check that plugin array contains samplers
hgs
parents:
diff changeset
   413
	if( iPluginArray && iPluginArray->Count() > 0 )
hgs
parents:
diff changeset
   414
	  {
hgs
parents:
diff changeset
   415
    	for(TInt i=0;i<iPluginArray->Count();i++)
hgs
parents:
diff changeset
   416
    		{
hgs
parents:
diff changeset
   417
	    	CSamplerPluginInterface* plugin = iPluginArray->At(i);
hgs
parents:
diff changeset
   418
	    	TUid uid = plugin->Id(-1);	// get parent uid first
hgs
parents:
diff changeset
   419
	    	if(uid == aUid)
hgs
parents:
diff changeset
   420
	    		{
hgs
parents:
diff changeset
   421
	    		LOGTEXT(_L("CSamplerController::GetPlugin() - main plug-in found!"));
hgs
parents:
diff changeset
   422
    			return plugin;
hgs
parents:
diff changeset
   423
				} 
hgs
parents:
diff changeset
   424
hgs
parents:
diff changeset
   425
            if(plugin->SubId(aUid) != KErrNotFound)
hgs
parents:
diff changeset
   426
                {
hgs
parents:
diff changeset
   427
                LOGTEXT(_L("CSamplerController::GetPlugin() - subsampler found!"));
hgs
parents:
diff changeset
   428
                return plugin;
hgs
parents:
diff changeset
   429
                }
hgs
parents:
diff changeset
   430
    		}
hgs
parents:
diff changeset
   431
		}	
hgs
parents:
diff changeset
   432
	LOGTEXT(_L("CSamplerController::GetPlugin() - No plug-in found for UID"));
hgs
parents:
diff changeset
   433
hgs
parents:
diff changeset
   434
	return (CSamplerPluginInterface*)0;
hgs
parents:
diff changeset
   435
	}
hgs
parents:
diff changeset
   436
hgs
parents:
diff changeset
   437
// start user mode samplers
hgs
parents:
diff changeset
   438
void CSamplerController::StartSamplerPluginsL()
hgs
parents:
diff changeset
   439
    {
hgs
parents:
diff changeset
   440
    CSamplerPluginInterface* plugin = NULL;
hgs
parents:
diff changeset
   441
hgs
parents:
diff changeset
   442
	if( iPluginArray )
hgs
parents:
diff changeset
   443
		{
hgs
parents:
diff changeset
   444
		TInt count(iPluginArray->Count());
hgs
parents:
diff changeset
   445
	
hgs
parents:
diff changeset
   446
		for(TInt i(0);i<count;i++)
hgs
parents:
diff changeset
   447
			{
hgs
parents:
diff changeset
   448
			plugin = iPluginArray->At(i);
hgs
parents:
diff changeset
   449
			// check if some error received when starting profiling
hgs
parents:
diff changeset
   450
			TRAPD(err, plugin->ResetAndActivateL(iStream));
hgs
parents:
diff changeset
   451
			LOGSTRING2(" RSamplerController::StartSamplerPlugin - plugin activated (0x%X)", plugin->Id(-1));  
hgs
parents:
diff changeset
   452
			if( err != KErrNone)
hgs
parents:
diff changeset
   453
				{
hgs
parents:
diff changeset
   454
				LOGSTRING2(" RSamplerController::StartSamplerPlugin - error %d", i);  
hgs
parents:
diff changeset
   455
				// handle received error, need to update UI!
hgs
parents:
diff changeset
   456
				iObserver->HandleError(err);
hgs
parents:
diff changeset
   457
				}
hgs
parents:
diff changeset
   458
            }
hgs
parents:
diff changeset
   459
	    }
hgs
parents:
diff changeset
   460
    }
hgs
parents:
diff changeset
   461
hgs
parents:
diff changeset
   462
// stop user mode samplers
hgs
parents:
diff changeset
   463
TInt CSamplerController::StopSamplerPlugins()
hgs
parents:
diff changeset
   464
	{
hgs
parents:
diff changeset
   465
	TInt count(0);
hgs
parents:
diff changeset
   466
hgs
parents:
diff changeset
   467
	if( iPluginArray && iPluginArray->Count() > 0 )
hgs
parents:
diff changeset
   468
		{
hgs
parents:
diff changeset
   469
		TInt i(0);
hgs
parents:
diff changeset
   470
		CSamplerPluginInterface* plugin = NULL;
hgs
parents:
diff changeset
   471
		// stop kernel mode samplers
hgs
parents:
diff changeset
   472
    	for(;i<iPluginArray->Count();i++)
hgs
parents:
diff changeset
   473
    		{
hgs
parents:
diff changeset
   474
			plugin = iPluginArray->At(i); 
hgs
parents:
diff changeset
   475
			TUint32 id = plugin->Id(-1).iUid;
hgs
parents:
diff changeset
   476
            LOGSTRING2(" CSamplerController::StopSamplerPlugins - traceId = %d",
hgs
parents:
diff changeset
   477
                        id);
hgs
parents:
diff changeset
   478
            // stop only started samplers
hgs
parents:
diff changeset
   479
            if(plugin->Enabled())
hgs
parents:
diff changeset
   480
                {
hgs
parents:
diff changeset
   481
                // stop selected plugin
hgs
parents:
diff changeset
   482
                plugin->StopSampling();
hgs
parents:
diff changeset
   483
                // check if user mode sampler, special flush needed to direct data to stream
hgs
parents:
diff changeset
   484
                if(plugin->GetSamplerType() == PROFILER_USER_MODE_SAMPLER)
hgs
parents:
diff changeset
   485
                    {
hgs
parents:
diff changeset
   486
                    LOGTEXT(_L(" CSamplerController::StopSamplerPlugins - flushing user mode sampler stream"));
hgs
parents:
diff changeset
   487
                    plugin->Flush();
hgs
parents:
diff changeset
   488
                    }
hgs
parents:
diff changeset
   489
                }
hgs
parents:
diff changeset
   490
            count++;
hgs
parents:
diff changeset
   491
    		}
hgs
parents:
diff changeset
   492
		}
hgs
parents:
diff changeset
   493
	return count; 	
hgs
parents:
diff changeset
   494
	}
hgs
parents:
diff changeset
   495
hgs
parents:
diff changeset
   496
// end of file
hgs
parents:
diff changeset
   497
hgs
parents:
diff changeset
   498
hgs
parents:
diff changeset
   499
hgs
parents:
diff changeset
   500