author | William Roberts <williamr@symbian.org> |
Mon, 04 Oct 2010 16:16:03 +0100 | |
changeset 282 | 664ff9a1a8fa |
parent 273 | 6a75fa55495f |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). |
2 |
// All rights reserved. |
|
3 |
// This component and the accompanying materials are made available |
|
4 |
// under the terms of the License "Eclipse Public License v1.0" |
|
5 |
// which accompanies this distribution, and is available |
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 |
// |
|
8 |
// Initial Contributors: |
|
9 |
// Nokia Corporation - initial contribution. |
|
10 |
// |
|
11 |
// Contributors: |
|
12 |
// |
|
13 |
// Description: |
|
14 |
// f32\sfile\sf_plugin.cpp |
|
15 |
// |
|
16 |
// |
|
17 |
||
18 |
#include <e32std.h> |
|
19 |
#include "sf_std.h" |
|
20 |
#include "sf_plugin_priv.h" |
|
21 |
||
22 |
CFsObjectCon* FsPluginManager::iPluginFactories = NULL; |
|
23 |
CFsObjectCon* FsPluginManager::iPluginConns = NULL; |
|
243 | 24 |
RReadWriteLock FsPluginManager::iChainLock; |
0 | 25 |
RPointerArray<CFsPlugin> FsPluginManager::iPluginChain; |
26 |
CFsSyncMessageScheduler* FsPluginManager::iScheduler = NULL; |
|
27 |
||
28 |
TBool IsPagableDrive(TInt aDrive) |
|
29 |
{ |
|
30 |
if(LocalDrives::IsValidDriveMapping(aDrive)) |
|
31 |
{ |
|
32 |
TLocalDriveCapsBuf capsBuf; |
|
33 |
if(!LocalDrives::IsProxyDrive(aDrive) && LocalDrives::GetLocalDrive(aDrive).Caps(capsBuf) && capsBuf().iDriveAtt & KDriveAttPageable) |
|
34 |
{ |
|
35 |
return (TBool)ETrue; |
|
36 |
} |
|
37 |
} |
|
38 |
return (TBool) EFalse; |
|
39 |
} |
|
40 |
||
41 |
/* |
|
42 |
@param aNonPagableDriveMask - a drive mask of the drives a plugin wishes to mount on |
|
43 |
@return A drive mask of the drives a plugin wishes to mount on not containing any pagable drives. |
|
44 |
*/ |
|
45 |
TInt NonPagableDrivesMask(TInt aNonPagableDriveMask) |
|
46 |
{ |
|
47 |
TInt driveMask = aNonPagableDriveMask; |
|
48 |
for(TInt i = 0; i < KMaxDrives; i++) |
|
49 |
{ |
|
50 |
//If we're interested in this drive |
|
51 |
if((aNonPagableDriveMask & 1<<i) && IsPagableDrive(i)) |
|
52 |
{ |
|
53 |
driveMask ^= 1<<i; //remove this drive |
|
54 |
} |
|
55 |
} |
|
56 |
return driveMask; |
|
57 |
} |
|
58 |
||
59 |
TInt FsPluginManager::UpdateMountedDrive(CFsPlugin* aPlugin, CFsPluginFactory* aFactory,TInt aDrive) |
|
60 |
{ |
|
61 |
if(aDrive==KPluginAutoAttach) //KPluginAutoAttach |
|
62 |
{ |
|
63 |
if(!(aFactory->SupportedDrives()&KPluginVersionTwo)) |
|
64 |
{ //Version 1 Plugin - Mount on all (except Z and pagble drives) |
|
65 |
TInt drivesAToY = (KPluginSupportAllDrives>>1); |
|
66 |
aPlugin->iMountedOn = NonPagableDrivesMask(drivesAToY); |
|
67 |
} |
|
68 |
else |
|
69 |
{ //Version 2 Plugin - Mount on what the plugin supports (except pagable drives) |
|
70 |
aPlugin->iMountedOn = NonPagableDrivesMask((aFactory->SupportedDrives()&(~KPluginVersionTwo))); |
|
71 |
} |
|
72 |
||
73 |
if(!(aPlugin->iMountedOn &(~KPluginVersionTwo))) |
|
74 |
{ //Are we mounted on anything? |
|
75 |
return KErrNotSupported; |
|
76 |
} |
|
77 |
return KErrNone; |
|
78 |
} |
|
79 |
||
80 |
// DriveZ special handling |
|
81 |
if(aDrive==KPluginMountDriveZ) |
|
82 |
aDrive = EDriveZ; |
|
83 |
||
84 |
//Mounting on a single drive |
|
85 |
if(!IsPagableDrive(aDrive)) |
|
86 |
{ |
|
87 |
aPlugin->iMountedOn |= 1<<aDrive; |
|
88 |
return KErrNone; |
|
89 |
} |
|
90 |
||
91 |
return KErrNotSupported; |
|
92 |
} |
|
93 |
||
94 |
/** |
|
95 |
FsPluginManager::Initialise |
|
96 |
*/ |
|
97 |
void FsPluginManager::InitialiseL() |
|
98 |
{ |
|
99 |
iPluginFactories = TheContainer->CreateL(); |
|
100 |
iPluginConns = TheContainer->CreateL(); |
|
101 |
iPluginChain.Reset(); |
|
102 |
User::LeaveIfError(iChainLock.CreateLocal()); |
|
103 |
||
104 |
// Create and install the synchronous message scheduler |
|
105 |
// - Messages are dispatched here from plugin threads if they are |
|
106 |
// to be executed in the context of the main file server thread. |
|
107 |
iScheduler = CFsSyncMessageScheduler::NewL(); |
|
108 |
iScheduler->RunL(); |
|
109 |
} |
|
110 |
||
111 |
/** |
|
112 |
FsPluginManager::MountPlugin |
|
113 |
*/ |
|
114 |
TInt FsPluginManager::MountPlugin(CFsPluginFactory& aPluginFactory, TInt aDrive, TInt aPos) |
|
115 |
{ |
|
116 |
TInt uniquePosition = aPluginFactory.UniquePosition(); |
|
117 |
CFsPlugin* pP = NULL; |
|
118 |
CFsPluginFactory* pF = &aPluginFactory; |
|
119 |
||
120 |
//Version1 plugins could either been mounted on 1 or all drives. |
|
121 |
//This isn't particularily desirable. |
|
122 |
// Thus - |
|
123 |
//For version2 plugins: |
|
124 |
//Check whether this plugin has already been mounted |
|
125 |
pP = FindByUniquePosition(uniquePosition); |
|
126 |
if(pP && (aPluginFactory.iSupportedDrives&KPluginVersionTwo)) |
|
127 |
{ |
|
128 |
//if this plugin has already been mounted then |
|
129 |
//Instead of trying to mount and failing with KErrInUse, |
|
130 |
//lets update the iMountedOn instead. |
|
131 |
return UpdateMountedDrive(pP,pF,aDrive); |
|
132 |
} |
|
133 |
||
134 |
||
135 |
TRAPD(err, pP = aPluginFactory.NewPluginL()); |
|
136 |
if(err != KErrNone) |
|
137 |
{ |
|
138 |
if(pP) |
|
139 |
pP->Close(); |
|
140 |
return err; |
|
141 |
} |
|
142 |
||
143 |
TFullName name = aPluginFactory.Name(); |
|
144 |
pP->SetName(&name); |
|
145 |
pP->iUniquePos=aPluginFactory.UniquePosition(); |
|
146 |
pP->SetDrive(aDrive); |
|
147 |
||
148 |
//Set which drive(s?) this plugin is mounted on. |
|
149 |
err = UpdateMountedDrive(pP,pF,aDrive); |
|
150 |
if(err != KErrNone) |
|
151 |
{ |
|
152 |
pP->Close(); |
|
153 |
return err; |
|
154 |
} |
|
155 |
||
243 | 156 |
WriteLockChain(); |
0 | 157 |
err = InsertInPluginStack(pP,aPos); |
158 |
UnlockChain(); |
|
159 |
if(err != KErrNone) |
|
160 |
{ |
|
161 |
pP->Close(); |
|
162 |
return err; |
|
163 |
} |
|
164 |
||
148 | 165 |
err = InitPlugin(*pP, aPluginFactory.Library()); |
0 | 166 |
if(err != KErrNone) |
167 |
{ |
|
168 |
return err; |
|
169 |
} |
|
170 |
aPluginFactory.IncrementMounted(); |
|
171 |
||
172 |
return KErrNone; |
|
173 |
} |
|
174 |
||
175 |
/** |
|
176 |
Dismounts a plugin |
|
15
4122176ea935
Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
0
diff
changeset
|
177 |
|
0 | 178 |
Must be called with the plugin chain locked. |
179 |
*/ |
|
180 |
void FsPluginManager::DismountPlugin(CFsPluginFactory& aPluginFactory,TInt aPos) |
|
181 |
{ |
|
182 |
CFsPlugin* plugin=iPluginChain[aPos]; |
|
183 |
||
184 |
if (plugin != NULL) |
|
185 |
{ |
|
186 |
// Check if there is any requests for this plugin |
|
187 |
// if so, deliver them to the next supporting plugin |
|
188 |
TransferRequests(plugin->iThreadP); |
|
189 |
||
190 |
plugin->iThreadP=NULL; |
|
15
4122176ea935
Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
0
diff
changeset
|
191 |
|
4122176ea935
Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
0
diff
changeset
|
192 |
//Remove the plugin from the chain |
0 | 193 |
iPluginChain.Remove(aPos); |
194 |
iPluginChain.Compress(); |
|
195 |
||
15
4122176ea935
Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
0
diff
changeset
|
196 |
//Close the plugin (destructed when CPluginThread is destructed). |
0 | 197 |
plugin->Close(); |
198 |
plugin=NULL; |
|
199 |
} |
|
200 |
else |
|
201 |
{ |
|
202 |
ASSERT(0); // force panic in debug mode |
|
203 |
} |
|
204 |
||
205 |
aPluginFactory.DecrementMounted(); |
|
206 |
} |
|
207 |
||
208 |
||
209 |
||
210 |
||
211 |
||
212 |
/** |
|
213 |
Transfer any outstanding requests to next/previous plugin depending on |
|
214 |
if it is post filter or not |
|
15
4122176ea935
Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
0
diff
changeset
|
215 |
|
243 | 216 |
Must be called with the plugin chain write-locked. |
15
4122176ea935
Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
0
diff
changeset
|
217 |
Attains plugin-thread's listlock. |
0 | 218 |
*/ |
219 |
void FsPluginManager::TransferRequests(CPluginThread* aPluginThread) |
|
220 |
{ |
|
221 |
aPluginThread->iListLock.Wait(); |
|
222 |
||
223 |
__THRD_PRINT(_L("FsPluginManager::TransferRequests - moving requests")); |
|
224 |
||
225 |
/* |
|
226 |
* We are transferring requests up and down the chain |
|
227 |
* because this plugin is being removed. |
|
228 |
* |
|
273 | 229 |
* ToDo: This next 'while' might be able to be replaced with a call to |
230 |
* DispatchToPlugin/DispatchToDrive instead. |
|
0 | 231 |
*/ |
273 | 232 |
while(!aPluginThread->iList.IsEmpty()) |
0 | 233 |
{ |
273 | 234 |
CFsRequest* pR=aPluginThread->iList.First(); |
235 |
CFsMessageRequest& mR = *(CFsMessageRequest*) pR; |
|
236 |
pR->iLink.Deque(); |
|
237 |
pR->iCurrentPlugin=NULL; |
|
238 |
||
239 |
if(pR->IsPluginSpecific()) |
|
0 | 240 |
{ |
273 | 241 |
pR->Complete(KErrCancel); |
242 |
continue; |
|
0 | 243 |
} |
244 |
||
273 | 245 |
if(pR->IsPostOperation()) |
246 |
{ |
|
247 |
//[set the plugin to] pass the request backwards in the chain |
|
248 |
PrevPlugin(pR->iCurrentPlugin, &mR); |
|
249 |
} |
|
250 |
else //IsPreOperations |
|
0 | 251 |
{ |
273 | 252 |
//[set the plugin to] pass the request forwards in the chain |
253 |
NextPlugin(pR->iCurrentPlugin, &mR); |
|
254 |
} |
|
0 | 255 |
|
273 | 256 |
if(pR->iCurrentPlugin) |
257 |
{ |
|
258 |
pR->iCurrentPlugin->iThreadP->DeliverBack(pR); |
|
259 |
} |
|
260 |
else |
|
261 |
{ |
|
262 |
if(!pR->IsPostOperation() && (pR->DriveNumber()>=EDriveA && pR->DriveNumber()<=EDriveZ)) |
|
0 | 263 |
{ |
273 | 264 |
//Deliver to drive thread |
265 |
CDriveThread* dT=NULL; |
|
266 |
TInt r=FsThreadManager::GetDriveThread(pR->DriveNumber(),&dT); |
|
267 |
__ASSERT_ALWAYS(r==KErrNone && dT,Fault(EFsDriveThreadError)); |
|
268 |
CRequestThread* pT = (CRequestThread*)dT; |
|
269 |
pT->DeliverBack(pR); |
|
0 | 270 |
} |
271 |
else |
|
272 |
{ |
|
273 | 273 |
pR->Complete(KErrCancel); |
0 | 274 |
} |
275 |
} |
|
276 |
} |
|
277 |
||
278 |
aPluginThread->iExit = ETrue; |
|
279 |
aPluginThread->iListLock.Signal(); |
|
280 |
||
281 |
__THRD_PRINT(_L("FsPluginManager::TransferRequests - all requests moved/cancelled")); |
|
282 |
} |
|
283 |
||
284 |
/** |
|
285 |
Install a plugin factory |
|
286 |
*/ |
|
287 |
TInt FsPluginManager::InstallPluginFactory(CFsPluginFactory* aFactory,RLibrary aLib) |
|
288 |
{ |
|
289 |
TInt r=aFactory->Install(); |
|
290 |
__PRINT1TEMP(_L("InstallPluginFactory %S"),aFactory->Name()); |
|
291 |
if (r==KErrNone) |
|
292 |
{TRAP(r,iPluginFactories->AddL(aFactory,ETrue))} |
|
293 |
if (r!=KErrNone) |
|
294 |
aFactory->Remove(); |
|
295 |
if (r==KErrNone) |
|
296 |
aFactory->SetLibrary(aLib); |
|
297 |
else |
|
298 |
aFactory->Close(); |
|
299 |
return(r); |
|
300 |
} |
|
301 |
||
302 |
/** |
|
303 |
Find a plugin factory by name |
|
304 |
*/ |
|
305 |
CFsPluginFactory* FsPluginManager::GetPluginFactory(const TDesC& aName) |
|
306 |
{ |
|
307 |
||
308 |
TInt h=0; |
|
309 |
TInt r=iPluginFactories->FindByName(h,aName); |
|
310 |
if (r!=KErrNone) |
|
311 |
return(NULL); |
|
312 |
return((CFsPluginFactory*)iPluginFactories->At(h)); |
|
313 |
} |
|
314 |
||
315 |
/** |
|
316 |
Find the next plugin that supports the operation |
|
15
4122176ea935
Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
0
diff
changeset
|
317 |
|
243 | 318 |
Must be called with the plugin chain (at least read-) locked. |
319 |
||
15
4122176ea935
Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
0
diff
changeset
|
320 |
@param aPlugin - On calling the function this may contain either NULL or the current plugin. |
4122176ea935
Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
0
diff
changeset
|
321 |
If it is called with NULL, then we start to look for plugins from the beginning of the chain. |
4122176ea935
Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
0
diff
changeset
|
322 |
If is is called with a plugin then we start to look after that plugin for the next one. |
4122176ea935
Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
0
diff
changeset
|
323 |
On return, aPlugin shall contain either a plugin or NULL. |
4122176ea935
Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
0
diff
changeset
|
324 |
|
0 | 325 |
@param aCheckCurrentOperation - Optional, if false, will return the next plugin, |
326 |
whether the plugin is currently registered |
|
15
4122176ea935
Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
0
diff
changeset
|
327 |
for the current function or not. (so long as mounted on the current drive) |
0 | 328 |
*/ |
243 | 329 |
TInt FsPluginManager::NextPlugin(CFsPlugin*& aPlugin, CFsMessageRequest* aMsgRequest, TBool aCheckCurrentOperation) |
0 | 330 |
{ |
331 |
if(aMsgRequest->DirectToDrive()) |
|
332 |
{ |
|
333 |
aPlugin = NULL; |
|
334 |
return KErrNotFound; |
|
335 |
} |
|
336 |
||
337 |
TInt start; |
|
338 |
TInt function = aMsgRequest->Operation()->Function(); |
|
339 |
TInt drive = aMsgRequest->DriveNumber(); |
|
340 |
||
15
4122176ea935
Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
0
diff
changeset
|
341 |
//the plugin chain lock must be held by this point. |
0 | 342 |
TInt count = iPluginChain.Count(); |
343 |
||
344 |
if(aPlugin == NULL) |
|
345 |
start=0; |
|
346 |
else |
|
347 |
start = iPluginChain.Find(aPlugin)+1; |
|
348 |
||
349 |
if(start!=KErrNotFound) |
|
350 |
{ |
|
351 |
for(TInt i=start;i<count;i++) |
|
352 |
{ |
|
353 |
if(!aCheckCurrentOperation || iPluginChain[i]->IsRegistered(function, CFsPlugin::EPreIntercept)) |
|
354 |
{ |
|
355 |
if((function == EFsDismountPlugin) || (iPluginChain[i]->IsMounted(drive))) |
|
356 |
{ |
|
357 |
||
358 |
aPlugin = iPluginChain[i]; |
|
15
4122176ea935
Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
0
diff
changeset
|
359 |
return KErrNone; |
0 | 360 |
} |
361 |
} |
|
362 |
} |
|
363 |
} |
|
364 |
aPlugin = NULL; |
|
15
4122176ea935
Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
0
diff
changeset
|
365 |
return KErrNotFound; |
0 | 366 |
} |
367 |
||
368 |
/** |
|
369 |
Find the next plugin that supports the operation |
|
243 | 370 |
Must be called with the plugin chain (at least read-) locked. |
15
4122176ea935
Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
0
diff
changeset
|
371 |
|
4122176ea935
Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
0
diff
changeset
|
372 |
@see FsPluginManager::NextPlugin |
0 | 373 |
*/ |
243 | 374 |
TInt FsPluginManager::PrevPlugin(CFsPlugin*& aPlugin, CFsMessageRequest* aMsgRequest) |
0 | 375 |
{ |
376 |
if(aMsgRequest->DirectToDrive() && (aMsgRequest->CurrentOperationPtr() != NULL)) |
|
377 |
{ |
|
378 |
aPlugin = NULL; |
|
379 |
return KErrNotFound; |
|
380 |
} |
|
381 |
||
382 |
TInt start; |
|
383 |
TInt function = aMsgRequest->Operation()->Function(); |
|
384 |
TInt drive = aMsgRequest->DriveNumber(); |
|
385 |
||
15
4122176ea935
Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
0
diff
changeset
|
386 |
//the plugin chain lock must be held by this point. |
0 | 387 |
TInt count= iPluginChain.Count(); |
388 |
||
389 |
if(aPlugin == NULL) |
|
390 |
start = count-1; |
|
391 |
else |
|
392 |
start = iPluginChain.Find(aPlugin)-1; |
|
393 |
||
394 |
if(start!=KErrNotFound) |
|
395 |
{ |
|
396 |
for(TInt i=start;i>=0;i--) |
|
397 |
{ |
|
398 |
CFsPlugin* owner = aMsgRequest->iOwnerPlugin; |
|
399 |
if(owner == iPluginChain[i]) |
|
400 |
break; |
|
401 |
||
402 |
if(iPluginChain[i]->IsRegistered(function, CFsPlugin::EPostIntercept)) |
|
403 |
{ |
|
404 |
if((function == EFsDismountPlugin) || (iPluginChain[i]->IsMounted(drive))) |
|
405 |
{ |
|
406 |
||
407 |
aPlugin = iPluginChain[i]; |
|
15
4122176ea935
Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
0
diff
changeset
|
408 |
return KErrNone; |
0 | 409 |
} |
410 |
} |
|
411 |
} |
|
412 |
} |
|
413 |
aPlugin = NULL; |
|
15
4122176ea935
Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
0
diff
changeset
|
414 |
return KErrNotFound; |
0 | 415 |
} |
416 |
/** |
|
417 |
Inserts the plugin in the stack (chain) |
|
418 |
||
419 |
if aPos absolute postion, it simply inserts it |
|
420 |
if aPos unique position, it walks through chain and checks the unique positions |
|
421 |
*/ |
|
422 |
TInt FsPluginManager::InsertInPluginStack(CFsPlugin*& aPlugin,TInt aPos) |
|
423 |
{ |
|
424 |
TInt ret=KErrNone; |
|
425 |
TInt count= iPluginChain.Count(); |
|
426 |
if(aPos == KPluginAutoLocate) |
|
427 |
{ |
|
428 |
TInt uPos= aPlugin->iUniquePos; |
|
429 |
for(TInt i=0;i<count;i++) |
|
430 |
{ |
|
431 |
if(uPos == iPluginChain[i]->iUniquePos) |
|
432 |
{ |
|
433 |
return KErrInUse; |
|
434 |
} |
|
435 |
||
436 |
if(uPos < iPluginChain[i]->iUniquePos) |
|
437 |
{ |
|
438 |
ret=iPluginChain.Insert(aPlugin,i); |
|
439 |
return ret; |
|
440 |
} |
|
441 |
} |
|
442 |
ret=iPluginChain.Append(aPlugin); |
|
443 |
} |
|
444 |
else |
|
445 |
{ |
|
446 |
// Absolute position |
|
447 |
||
448 |
if(aPos > count) |
|
449 |
return(KErrNotFound); |
|
450 |
if(aPos == count) |
|
451 |
{ |
|
452 |
ret=iPluginChain.Append(aPlugin); |
|
453 |
return ret; |
|
454 |
} |
|
455 |
ret=iPluginChain.Insert(aPlugin,aPos); |
|
456 |
} |
|
457 |
return ret; |
|
458 |
} |
|
459 |
||
460 |
/** |
|
461 |
Looks for a plugin in the chain |
|
462 |
*/ |
|
463 |
TInt FsPluginManager::IsInChain(TInt aUPos,TInt aPos, TInt aDrive, CFsPluginFactory* aPluginFactory) |
|
464 |
{ |
|
465 |
TInt count= iPluginChain.Count(); |
|
466 |
||
467 |
if(aPos == KPluginAutoLocate) |
|
468 |
{ |
|
469 |
for(TInt i=0;i<count;i++) |
|
470 |
{ |
|
471 |
CFsPlugin* pP = iPluginChain[i]; |
|
472 |
if(aPluginFactory->SupportedDrives()&KPluginVersionTwo) //Version2 |
|
473 |
{ |
|
474 |
//If KPluginAutoAttach, then we're dismounted from all drives. |
|
475 |
//If KPluginMountDriveZ, then check against 25 explicitly (cannot change aDrive:=Z as that==KPluginAutoAttach)) |
|
476 |
//If any other drive mounted. |
|
477 |
if(aUPos == pP->iUniquePos && (aDrive==KPluginAutoAttach || (aDrive==KPluginMountDriveZ && pP->iMountedOn & (1<<EDriveZ)) || pP->iMountedOn & (1<<aDrive))) |
|
478 |
return i; |
|
479 |
} |
|
480 |
else //version1 |
|
481 |
{ |
|
482 |
if(aUPos == pP->iUniquePos && (aDrive==KPluginAutoAttach || pP->iMountedOn & (1<<aDrive))) |
|
483 |
return i; |
|
484 |
} |
|
485 |
} |
|
486 |
return KErrNotFound; |
|
487 |
} |
|
488 |
||
489 |
if(aPos+1>iPluginChain.Count()) |
|
490 |
return(KErrNotFound); |
|
491 |
||
492 |
if(iPluginChain[aPos]->iUniquePos == aUPos && aDrive==iPluginChain[aPos]->Drive()) |
|
493 |
return aPos; |
|
494 |
return KErrNotFound; |
|
495 |
} |
|
496 |
||
497 |
/** |
|
498 |
Finds a plugin by unique position |
|
499 |
*/ |
|
500 |
CFsPlugin* FsPluginManager::FindByUniquePosition(TInt aUniquePosition) |
|
501 |
{ |
|
243 | 502 |
ReadLockChain(); |
0 | 503 |
CFsPlugin* plugin = NULL; |
504 |
TInt count= iPluginChain.Count(); |
|
505 |
for(TInt i=0;i<count;i++) |
|
506 |
{ |
|
507 |
if(aUniquePosition == iPluginChain[i]->iUniquePos) |
|
508 |
{ |
|
509 |
plugin = iPluginChain[i]; |
|
510 |
break; |
|
511 |
} |
|
512 |
} |
|
513 |
UnlockChain(); |
|
514 |
return plugin; |
|
515 |
} |
|
516 |
||
517 |
/** |
|
518 |
Create a connection to a plugin |
|
519 |
*/ |
|
520 |
CFsPluginConn* FsPluginManager::CreatePluginConnL(TInt aUniquePosition, TUint aClientId) |
|
521 |
{ |
|
522 |
CFsPlugin* pP = FindByUniquePosition(aUniquePosition); |
|
523 |
if(pP != NULL) |
|
524 |
{ |
|
525 |
CFsPluginConn* pC = pP->NewPluginConnL(); |
|
15
4122176ea935
Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
0
diff
changeset
|
526 |
CleanupStack::PushL(pC); |
0 | 527 |
pC->iPluginP = pP; |
528 |
pC->iClientId = aClientId; |
|
529 |
iPluginConns->AddL(pC, ETrue); |
|
15
4122176ea935
Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
0
diff
changeset
|
530 |
CleanupStack::Pop(pC); |
0 | 531 |
return pC; |
532 |
} |
|
533 |
||
534 |
User::Leave(KErrNotFound); |
|
535 |
return NULL; |
|
536 |
} |
|
537 |
||
538 |
/** |
|
539 |
Create a plugin thread |
|
540 |
Should only by called from main file server thread with plugin thread unavailable |
|
541 |
*/ |
|
148 | 542 |
TInt FsPluginManager::InitPlugin(CFsPlugin& aPlugin, RLibrary aLibrary) |
0 | 543 |
{ |
544 |
TInt err = KErrNone; |
|
545 |
||
546 |
if(!aPlugin.iThreadP) |
|
547 |
{ |
|
148 | 548 |
TRAP(err,aPlugin.iThreadP=CPluginThread::NewL(aPlugin, aLibrary)); |
0 | 549 |
if(err!=KErrNone) |
550 |
return err; |
|
551 |
} |
|
552 |
||
553 |
aPlugin.iThreadId = aPlugin.iThreadP->StartL(); |
|
554 |
return err; |
|
555 |
} |
|
556 |
||
557 |
/** |
|
558 |
Gets number of plugins in the plugin stack |
|
559 |
*/ |
|
560 |
TInt FsPluginManager::ChainCount() |
|
561 |
{ |
|
562 |
return(iPluginChain.Count()); |
|
563 |
} |
|
564 |
||
565 |
/** |
|
566 |
* Returns a CFsPlugin* from aPos in the plugin chain. |
|
567 |
* |
|
568 |
* To be called whilst already holding the iChainLock. |
|
569 |
* |
|
570 |
* @returns (via parameter) CFsPlugin*& aPlugin |
|
571 |
*/ |
|
572 |
TInt FsPluginManager::Plugin(CFsPlugin*& aPlugin, TInt aPos) |
|
573 |
{ |
|
574 |
if(aPos >= iPluginChain.Count() || aPos < 0) |
|
575 |
return KErrNotFound; |
|
576 |
||
577 |
aPlugin = iPluginChain[aPos]; |
|
578 |
return KErrNone; |
|
579 |
} |
|
580 |
||
581 |
/** |
|
243 | 582 |
Locks the chain for reading |
0 | 583 |
*/ |
243 | 584 |
void FsPluginManager::ReadLockChain() |
0 | 585 |
{ |
243 | 586 |
iChainLock.ReadLock(); |
0 | 587 |
} |
588 |
||
589 |
/** |
|
243 | 590 |
Locks the chain for writing |
591 |
*/ |
|
592 |
void FsPluginManager::WriteLockChain() |
|
593 |
{ |
|
594 |
iChainLock.WriteLock(); |
|
595 |
} |
|
596 |
||
597 |
/** |
|
0 | 598 |
Unlocks the chain |
599 |
*/ |
|
600 |
void FsPluginManager::UnlockChain() |
|
601 |
{ |
|
243 | 602 |
iChainLock.Unlock(); |
0 | 603 |
} |
604 |
||
605 |
/** |
|
606 |
Gets plugin conn from handle |
|
607 |
*/ |
|
608 |
CFsPluginConn* FsPluginManager::GetPluginConnFromHandle(CSessionFs* aSession, TInt aHandle) |
|
609 |
{ |
|
610 |
return((CFsPluginConn*)(SessionObjectFromHandle(aHandle,iPluginConns->UniqueID(),aSession))); |
|
611 |
} |
|
612 |
||
613 |
/** |
|
614 |
Checks if the current thread is plugin conn's thread |
|
615 |
*/ |
|
616 |
TBool FsPluginManager::IsPluginConnThread(TThreadId tid, CFsPlugin* aPlugin) |
|
617 |
{ |
|
618 |
iPluginConns->Lock(); |
|
619 |
TInt count = iPluginConns->Count(); |
|
620 |
while(count--) |
|
621 |
{ |
|
622 |
CFsPluginConn* conn = (CFsPluginConn*)(*iPluginConns)[count]; |
|
623 |
if(conn->Plugin() == aPlugin) |
|
624 |
{ |
|
625 |
if(conn->ClientId() == tid) |
|
626 |
{ |
|
627 |
iPluginConns->Unlock(); |
|
628 |
return ETrue; |
|
629 |
} |
|
630 |
} |
|
631 |
} |
|
632 |
iPluginConns->Unlock(); |
|
633 |
return EFalse; |
|
634 |
} |
|
635 |
||
636 |
/** |
|
637 |
Dispatch a synchronous message |
|
638 |
*/ |
|
639 |
void FsPluginManager::DispatchSync(CFsRequest* aRequest) |
|
640 |
{ |
|
641 |
__THRD_PRINT(_L("FsPluginManager::DispatchSync")); |
|
642 |
if(!FsThreadManager::IsMainThread() && iScheduler) |
|
643 |
{ |
|
644 |
iScheduler->Dispatch(aRequest); |
|
645 |
} |
|
646 |
else |
|
647 |
{ |
|
648 |
aRequest->Process(); |
|
649 |
} |
|
650 |
} |
|
651 |
||
652 |