piprofiler/engine/src/WriterController.cpp
author hgs
Fri, 27 Aug 2010 11:37:29 +0300
changeset 42 0ff24a8f6ca2
parent 20 a71a3e32a2ae
permissions -rw-r--r--
201033
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 <piprofiler/EngineUIDs.h>
hgs
parents:
diff changeset
    20
#include <piprofiler/ProfilerTraces.h>
hgs
parents:
diff changeset
    21
hgs
parents:
diff changeset
    22
#include "WriterController.h"
hgs
parents:
diff changeset
    23
hgs
parents:
diff changeset
    24
const TInt KMaxWriterPluginCount = 10;
hgs
parents:
diff changeset
    25
hgs
parents:
diff changeset
    26
hgs
parents:
diff changeset
    27
CWriterController* CWriterController::NewL(CProfilerSampleStream& aStream)
hgs
parents:
diff changeset
    28
    {
hgs
parents:
diff changeset
    29
    CWriterController* self = new( ELeave ) CWriterController(aStream);
hgs
parents:
diff changeset
    30
    CleanupStack::PushL( self );
hgs
parents:
diff changeset
    31
    self->ConstructL( );
hgs
parents:
diff changeset
    32
    CleanupStack::Pop( self );
hgs
parents:
diff changeset
    33
    return self;
hgs
parents:
diff changeset
    34
    }
hgs
parents:
diff changeset
    35
hgs
parents:
diff changeset
    36
CWriterController::CWriterController(CProfilerSampleStream& aStream) : 
hgs
parents:
diff changeset
    37
    iStream(aStream)
hgs
parents:
diff changeset
    38
    {
hgs
parents:
diff changeset
    39
    }
hgs
parents:
diff changeset
    40
hgs
parents:
diff changeset
    41
void CWriterController::ConstructL()
hgs
parents:
diff changeset
    42
	{
hgs
parents:
diff changeset
    43
	// initiate writer plugin list
hgs
parents:
diff changeset
    44
hgs
parents:
diff changeset
    45
	}
hgs
parents:
diff changeset
    46
hgs
parents:
diff changeset
    47
hgs
parents:
diff changeset
    48
void CWriterController::InitialiseWriterListL()
hgs
parents:
diff changeset
    49
    {
hgs
parents:
diff changeset
    50
    // create new writer plugin array
hgs
parents:
diff changeset
    51
    iPluginArray = new(ELeave) CArrayPtrFlat<CWriterPluginInterface>( KMaxWriterPluginCount );
hgs
parents:
diff changeset
    52
    
hgs
parents:
diff changeset
    53
    // create new writer plugin loader
hgs
parents:
diff changeset
    54
    iPluginLoader = CWriterPluginLoader::NewL();
hgs
parents:
diff changeset
    55
    iPluginLoader->SetObserver( this );
hgs
parents:
diff changeset
    56
    iPluginLoader->LoadAsyncL( iPluginArray );
hgs
parents:
diff changeset
    57
hgs
parents:
diff changeset
    58
    LOGTEXT(_L(" RWriterController::InitialiseWriterList - exit"));	
hgs
parents:
diff changeset
    59
    }
hgs
parents:
diff changeset
    60
hgs
parents:
diff changeset
    61
CWriterController::~CWriterController()
hgs
parents:
diff changeset
    62
    {
hgs
parents:
diff changeset
    63
    LOGTEXT(_L("RWriterController::~RWriterController" ));
hgs
parents:
diff changeset
    64
    if ( iPluginArray )
hgs
parents:
diff changeset
    65
        {
hgs
parents:
diff changeset
    66
        // destroy the plugin instances
hgs
parents:
diff changeset
    67
        // empty loaded plugins from array
hgs
parents:
diff changeset
    68
        for(TInt i(0);i<iPluginArray->Count();i++)
hgs
parents:
diff changeset
    69
            {
hgs
parents:
diff changeset
    70
            if(iPluginArray->At(i))
hgs
parents:
diff changeset
    71
                {
hgs
parents:
diff changeset
    72
                delete iPluginArray->At(i);
hgs
parents:
diff changeset
    73
                iPluginArray->At(i) = NULL;
hgs
parents:
diff changeset
    74
                }
hgs
parents:
diff changeset
    75
            }
hgs
parents:
diff changeset
    76
        iPluginArray->Reset();
hgs
parents:
diff changeset
    77
        delete iPluginArray;
hgs
parents:
diff changeset
    78
        iPluginArray = NULL;
hgs
parents:
diff changeset
    79
        }
hgs
parents:
diff changeset
    80
    
hgs
parents:
diff changeset
    81
    if ( iPluginLoader )
hgs
parents:
diff changeset
    82
        {
hgs
parents:
diff changeset
    83
        iPluginLoader->AbortAsyncLoad();
hgs
parents:
diff changeset
    84
        delete iPluginLoader;
hgs
parents:
diff changeset
    85
        iPluginLoader = NULL;
hgs
parents:
diff changeset
    86
        }
hgs
parents:
diff changeset
    87
hgs
parents:
diff changeset
    88
    }
hgs
parents:
diff changeset
    89
hgs
parents:
diff changeset
    90
hgs
parents:
diff changeset
    91
void CWriterController::InitialisePluginStream()
hgs
parents:
diff changeset
    92
	{
hgs
parents:
diff changeset
    93
	LOGTEXT(_L("RWriterController::InitialisePluginStream - entry"));
hgs
parents:
diff changeset
    94
	if( iPluginArray )
hgs
parents:
diff changeset
    95
		{
hgs
parents:
diff changeset
    96
		TInt pluginCount(iPluginArray->Count());
hgs
parents:
diff changeset
    97
	
hgs
parents:
diff changeset
    98
		LOGSTRING2("RWriterController::InitialisePluginStream - plugin count %d, searching through", pluginCount);
hgs
parents:
diff changeset
    99
	  	for(TInt i=0;i<pluginCount;i++)
hgs
parents:
diff changeset
   100
	  	    {
hgs
parents:
diff changeset
   101
  			LOGSTRING2("RWriterController::InitialisePluginStream - getting plugin n:o: %d...", i);
hgs
parents:
diff changeset
   102
	    	CWriterPluginInterface* plugin = iPluginArray->At(i);
hgs
parents:
diff changeset
   103
	  		LOGSTRING2("RWriterController::InitialisePluginStream - writer found, 0x%x, initializing stream...", plugin->Id());
hgs
parents:
diff changeset
   104
    		plugin->SetStream(iStream);
hgs
parents:
diff changeset
   105
	  		LOGTEXT(_L("RSamplerController::InitialisePluginStream - succeeded!"));
hgs
parents:
diff changeset
   106
	  	    }
hgs
parents:
diff changeset
   107
	  	}
hgs
parents:
diff changeset
   108
	LOGTEXT(_L("RSamplerController::InitialisePluginStream - exit"));
hgs
parents:
diff changeset
   109
hgs
parents:
diff changeset
   110
	}
hgs
parents:
diff changeset
   111
hgs
parents:
diff changeset
   112
CArrayPtrFlat<CWriterPluginInterface>* CWriterController::GetPluginList()
hgs
parents:
diff changeset
   113
    {
hgs
parents:
diff changeset
   114
	return iPluginArray;
hgs
parents:
diff changeset
   115
    }
hgs
parents:
diff changeset
   116
hgs
parents:
diff changeset
   117
void CWriterController::HandlePluginLoaded( KWriterPluginLoaderStatus aStatus )
hgs
parents:
diff changeset
   118
    {
hgs
parents:
diff changeset
   119
    
hgs
parents:
diff changeset
   120
    switch(aStatus)
hgs
parents:
diff changeset
   121
        {
hgs
parents:
diff changeset
   122
        case 0:
hgs
parents:
diff changeset
   123
            LOGSTRING2("RWriterController - one plugin loaded, status: %d", aStatus);
hgs
parents:
diff changeset
   124
            break;
hgs
parents:
diff changeset
   125
        case 1:
hgs
parents:
diff changeset
   126
            LOGSTRING2("RWriterController - a plugin load failed: %d", aStatus);
hgs
parents:
diff changeset
   127
            break;
hgs
parents:
diff changeset
   128
        case 2:
hgs
parents:
diff changeset
   129
            LOGSTRING2("RWriterController - plugin loading aborted: %d", aStatus);
hgs
parents:
diff changeset
   130
            break;
hgs
parents:
diff changeset
   131
        case 3:
hgs
parents:
diff changeset
   132
            LOGSTRING2("RWriterController - all plugins loaded: %d", aStatus);
hgs
parents:
diff changeset
   133
            // set stream after all loaded writer plugins
hgs
parents:
diff changeset
   134
            InitialisePluginStream();
hgs
parents:
diff changeset
   135
            break;
hgs
parents:
diff changeset
   136
        case 4:
hgs
parents:
diff changeset
   137
            LOGSTRING2("RWriterController - error in loading plugins: %d", aStatus);
hgs
parents:
diff changeset
   138
            break;
hgs
parents:
diff changeset
   139
        default:
hgs
parents:
diff changeset
   140
            break;
hgs
parents:
diff changeset
   141
        }
hgs
parents:
diff changeset
   142
    }
hgs
parents:
diff changeset
   143
hgs
parents:
diff changeset
   144
hgs
parents:
diff changeset
   145
hgs
parents:
diff changeset
   146
TUid CWriterController::GetPluginUID(TInt traceId)
hgs
parents:
diff changeset
   147
    {
hgs
parents:
diff changeset
   148
	LOGSTRING2(" RWriterController::GetPluginUID - checking UID for traceId = %d",traceId);	
hgs
parents:
diff changeset
   149
	// this part has to be changed for each new writer
hgs
parents:
diff changeset
   150
hgs
parents:
diff changeset
   151
    if( iPluginArray && iPluginArray->Count() > 0 )
hgs
parents:
diff changeset
   152
        {
hgs
parents:
diff changeset
   153
        for(TInt i=0;i<iPluginArray->Count();i++)
hgs
parents:
diff changeset
   154
            {
hgs
parents:
diff changeset
   155
            CWriterPluginInterface* plugin = iPluginArray->At(i); 
hgs
parents:
diff changeset
   156
            if(plugin->Id().iUid == traceId)
hgs
parents:
diff changeset
   157
                {
hgs
parents:
diff changeset
   158
                LOGSTRING2(" RWriterController::GetPluginUID - got: 0x%X",plugin->Id());	
hgs
parents:
diff changeset
   159
                return plugin->Id();
hgs
parents:
diff changeset
   160
                }
hgs
parents:
diff changeset
   161
            }
hgs
parents:
diff changeset
   162
        }	
hgs
parents:
diff changeset
   163
	return KWriterNoneSelected;
hgs
parents:
diff changeset
   164
hgs
parents:
diff changeset
   165
    }
hgs
parents:
diff changeset
   166
hgs
parents:
diff changeset
   167
CWriterPluginInterface* CWriterController::GetActiveWriter()
hgs
parents:
diff changeset
   168
    {
hgs
parents:
diff changeset
   169
    CWriterPluginInterface* plugin = NULL;
hgs
parents:
diff changeset
   170
hgs
parents:
diff changeset
   171
	if( iPluginArray )
hgs
parents:
diff changeset
   172
		{
hgs
parents:
diff changeset
   173
		TInt count(iPluginArray->Count());
hgs
parents:
diff changeset
   174
		
hgs
parents:
diff changeset
   175
		for(TInt i=0;i<count;i++)
hgs
parents:
diff changeset
   176
			{
hgs
parents:
diff changeset
   177
			plugin = iPluginArray->At(i); 
hgs
parents:
diff changeset
   178
			if(plugin->GetEnabled())
hgs
parents:
diff changeset
   179
				{
hgs
parents:
diff changeset
   180
				return plugin;
hgs
parents:
diff changeset
   181
				}
hgs
parents:
diff changeset
   182
			}
hgs
parents:
diff changeset
   183
		}
hgs
parents:
diff changeset
   184
hgs
parents:
diff changeset
   185
    return (CWriterPluginInterface*)0;
hgs
parents:
diff changeset
   186
    }
hgs
parents:
diff changeset
   187
hgs
parents:
diff changeset
   188
TUint32 CWriterController::GetWriterType(TUint32 writerId)
hgs
parents:
diff changeset
   189
    {
hgs
parents:
diff changeset
   190
    TUid id;
hgs
parents:
diff changeset
   191
    
hgs
parents:
diff changeset
   192
    id = this->GetPluginUID(writerId);
hgs
parents:
diff changeset
   193
    
hgs
parents:
diff changeset
   194
    if(id != KWriterNoneSelected)
hgs
parents:
diff changeset
   195
        return GetPlugin(id)->GetWriterType();
hgs
parents:
diff changeset
   196
    else
hgs
parents:
diff changeset
   197
        return 0;
hgs
parents:
diff changeset
   198
    }
hgs
parents:
diff changeset
   199
hgs
parents:
diff changeset
   200
CWriterPluginInterface* CWriterController::GetPlugin(TUid aUid)
hgs
parents:
diff changeset
   201
    {
hgs
parents:
diff changeset
   202
    if( iPluginArray && iPluginArray->Count() > 0 )
hgs
parents:
diff changeset
   203
        {
hgs
parents:
diff changeset
   204
        for(TInt i=0;i<iPluginArray->Count();i++)
hgs
parents:
diff changeset
   205
            {
hgs
parents:
diff changeset
   206
            CWriterPluginInterface* plugin = iPluginArray->At(i); 
hgs
parents:
diff changeset
   207
            // check if searched uid found
hgs
parents:
diff changeset
   208
            if(plugin->Id().iUid == aUid.iUid)
hgs
parents:
diff changeset
   209
                {
hgs
parents:
diff changeset
   210
                // return pointer to found plugin
hgs
parents:
diff changeset
   211
                return plugin;
hgs
parents:
diff changeset
   212
                }
hgs
parents:
diff changeset
   213
            }
hgs
parents:
diff changeset
   214
        }
hgs
parents:
diff changeset
   215
    // return null plugin
hgs
parents:
diff changeset
   216
	return (CWriterPluginInterface*)0;
hgs
parents:
diff changeset
   217
    }
hgs
parents:
diff changeset
   218
hgs
parents:
diff changeset
   219
TInt CWriterController::StartSelectedPlugin()
hgs
parents:
diff changeset
   220
	{
hgs
parents:
diff changeset
   221
	LOGTEXT(_L("RWriterController::StartSelectedPlugin - entry"));
hgs
parents:
diff changeset
   222
	
hgs
parents:
diff changeset
   223
    CWriterPluginInterface* plugin = GetActiveWriter();
hgs
parents:
diff changeset
   224
    
hgs
parents:
diff changeset
   225
    if(plugin)
hgs
parents:
diff changeset
   226
        {
hgs
parents:
diff changeset
   227
        return plugin->Start();
hgs
parents:
diff changeset
   228
		}
hgs
parents:
diff changeset
   229
    
hgs
parents:
diff changeset
   230
	LOGTEXT(_L("RWriterController::StartSelectedPlugin - exit"));
hgs
parents:
diff changeset
   231
	return KErrNotFound;
hgs
parents:
diff changeset
   232
	}
hgs
parents:
diff changeset
   233
hgs
parents:
diff changeset
   234
void CWriterController::StopSelectedPlugin()
hgs
parents:
diff changeset
   235
	{
hgs
parents:
diff changeset
   236
	LOGTEXT(_L("RWriterController::StopSelectedPlugin - entry"));
hgs
parents:
diff changeset
   237
    
hgs
parents:
diff changeset
   238
    CWriterPluginInterface* plugin = GetActiveWriter();
hgs
parents:
diff changeset
   239
    
hgs
parents:
diff changeset
   240
	if(plugin)
hgs
parents:
diff changeset
   241
		{
hgs
parents:
diff changeset
   242
		plugin->Stop();
hgs
parents:
diff changeset
   243
		}
hgs
parents:
diff changeset
   244
	LOGTEXT(_L("RWriterController::StopSelectedPlugin - exit"));
hgs
parents:
diff changeset
   245
	}
hgs
parents:
diff changeset
   246
hgs
parents:
diff changeset
   247
/** Set selected plugin active **/
hgs
parents:
diff changeset
   248
void CWriterController::SetPluginActive(TUid uid, const TWriterPluginValueKeys aKey)
hgs
parents:
diff changeset
   249
    {
hgs
parents:
diff changeset
   250
	CWriterPluginInterface* plugin = NULL;
hgs
parents:
diff changeset
   251
	_LIT(KDummy, "");
hgs
parents:
diff changeset
   252
	TBuf<1> buf;
hgs
parents:
diff changeset
   253
	buf.Append(KDummy);
hgs
parents:
diff changeset
   254
hgs
parents:
diff changeset
   255
	for(TInt i(0);i<iPluginArray->Count();i++)
hgs
parents:
diff changeset
   256
	    {
hgs
parents:
diff changeset
   257
	    plugin = iPluginArray->At(i);
hgs
parents:
diff changeset
   258
	    if(plugin->Id().iUid == uid.iUid)
hgs
parents:
diff changeset
   259
	        {
hgs
parents:
diff changeset
   260
	        plugin->SetValue(aKey, buf);
hgs
parents:
diff changeset
   261
	        }
hgs
parents:
diff changeset
   262
	    else
hgs
parents:
diff changeset
   263
	        {
hgs
parents:
diff changeset
   264
	        plugin->SetValue(EWriterPluginDisabled, buf);
hgs
parents:
diff changeset
   265
	        }
hgs
parents:
diff changeset
   266
	    }
hgs
parents:
diff changeset
   267
    }
hgs
parents:
diff changeset
   268
hgs
parents:
diff changeset
   269
TInt CWriterController::SetPluginSettings(TUid aUid, TDes& aDes)
hgs
parents:
diff changeset
   270
    {
hgs
parents:
diff changeset
   271
	LOGSTRING2(" CWriterController::SetPluginSettings, traceId = 0x%X", aUid.iUid);	
hgs
parents:
diff changeset
   272
	GetPlugin(aUid)->SetValue(EWriterPluginSettings, aDes);
hgs
parents:
diff changeset
   273
	return KErrNone;
hgs
parents:
diff changeset
   274
    }
hgs
parents:
diff changeset
   275
hgs
parents:
diff changeset
   276
/** Get settings for a specific plugin **/
hgs
parents:
diff changeset
   277
void CWriterController::GetPluginSettings(TUid uid, TDes& aVal)
hgs
parents:
diff changeset
   278
    {
hgs
parents:
diff changeset
   279
	GetPlugin(uid)->GetValue(EWriterPluginSettings, aVal);
hgs
parents:
diff changeset
   280
    }
hgs
parents:
diff changeset
   281
hgs
parents:
diff changeset
   282
hgs
parents:
diff changeset
   283
// end of file