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