userlibandfileserver/fileserver/sfile/sf_plugin_man.cpp
changeset 2 4122176ea935
parent 0 a41df078684a
child 36 bbf8bed59bcb
equal deleted inserted replaced
0:a41df078684a 2:4122176ea935
   163 		}
   163 		}
   164 
   164 
   165 	err = InitPlugin(*pP);
   165 	err = InitPlugin(*pP);
   166 	if(err != KErrNone)
   166 	if(err != KErrNone)
   167 		{
   167 		{
   168 		pP->Close();
       
   169 		return err;
   168 		return err;
   170 		}
   169 		}
   171  	aPluginFactory.IncrementMounted();
   170  	aPluginFactory.IncrementMounted();
   172 
   171 
   173 	return KErrNone;
   172 	return KErrNone;
   174 	}
   173 	}
   175 
   174 
   176 /**
   175 /**
   177 Dismounts a plugin
   176 Dismounts a plugin
       
   177 
   178 Must be called with the plugin chain locked.
   178 Must be called with the plugin chain locked.
   179 */
   179 */
   180 void FsPluginManager::DismountPlugin(CFsPluginFactory& aPluginFactory,TInt aPos)
   180 void FsPluginManager::DismountPlugin(CFsPluginFactory& aPluginFactory,TInt aPos)
   181 	{
   181 	{
   182 	CFsPlugin* plugin=iPluginChain[aPos];
   182 	CFsPlugin* plugin=iPluginChain[aPos];
   186 		// Check if there is any requests for this plugin
   186 		// Check if there is any requests for this plugin
   187 		// if so, deliver them to the next supporting plugin
   187 		// if so, deliver them to the next supporting plugin
   188 		TransferRequests(plugin->iThreadP);
   188 		TransferRequests(plugin->iThreadP);
   189 
   189 
   190 		plugin->iThreadP=NULL;
   190 		plugin->iThreadP=NULL;
   191 
   191 		
       
   192 		//Remove the plugin from the chain
   192 		iPluginChain.Remove(aPos);
   193 		iPluginChain.Remove(aPos);
   193 		iPluginChain.Compress();
   194 		iPluginChain.Compress();
   194 
   195 
   195 		//Need this to remove it from container
   196 	    //Close the plugin (destructed when CPluginThread is destructed).
   196 		//plugin->Close() deletes plugin.
       
   197  		plugin->Close();
   197  		plugin->Close();
   198 		plugin=NULL;
   198 		plugin=NULL;
   199 		}
   199 		}
   200 	else
   200 	else
   201 		{
   201 		{
   232 
   232 
   233 
   233 
   234 /**
   234 /**
   235 Transfer any outstanding requests to next/previous plugin depending on
   235 Transfer any outstanding requests to next/previous plugin depending on
   236 if it is post filter or not
   236 if it is post filter or not
       
   237 
       
   238 Must be called with the plugin chain locked.
       
   239 Attains plugin-thread's listlock.
   237 */
   240 */
   238 void FsPluginManager::TransferRequests(CPluginThread* aPluginThread)
   241 void FsPluginManager::TransferRequests(CPluginThread* aPluginThread)
   239 	{
   242 	{
   240 	aPluginThread->iListLock.Wait();
   243 	aPluginThread->iListLock.Wait();
   241 	
   244 	
   380 	return((CFsPluginFactory*)iPluginFactories->At(h));
   383 	return((CFsPluginFactory*)iPluginFactories->At(h));
   381 	}
   384 	}
   382 
   385 
   383 /**
   386 /**
   384 Find the next plugin that supports the operation
   387 Find the next plugin that supports the operation
       
   388 
       
   389 @param aPlugin - On calling the function this may contain either NULL or the current plugin.
       
   390                  If it is called with NULL, then we start to look for plugins from the beginning of the chain.
       
   391                  If is is called with a plugin then we start to look after that plugin for the next one.
       
   392                  On return, aPlugin shall contain either a plugin or NULL.
       
   393                  
       
   394 @param aLock - If this is set to ETRUE, then the function shall lock the plugin chain.
       
   395                If this is set to EFALSE, then the caller of the function MUST already hold the lock.
       
   396 
   385 @param aCheckCurrentOperation - Optional, if false, will return the next plugin,
   397 @param aCheckCurrentOperation - Optional, if false, will return the next plugin,
   386  								whether the plugin is currently registered
   398  								whether the plugin is currently registered
   387 								for the current function of not. (so long as mounted on the current drive)
   399 								for the current function or not. (so long as mounted on the current drive)
   388 */
   400 */
   389 TInt FsPluginManager::NextPlugin(CFsPlugin*& aPlugin, CFsMessageRequest* aMsgRequest,TBool aLock, TBool aCheckCurrentOperation)
   401 TInt FsPluginManager::NextPlugin(CFsPlugin*& aPlugin, CFsMessageRequest* aMsgRequest,TBool aLock, TBool aCheckCurrentOperation)
   390 	{
   402 	{
   391 	if(aMsgRequest->DirectToDrive())
   403 	if(aMsgRequest->DirectToDrive())
   392 		{
   404 		{
   393 		aPlugin = NULL;
   405 		aPlugin = NULL;
   394 		return KErrNotFound;
   406 		return KErrNotFound;
   395 		}
   407 		}
   396 
   408 
   397 	TInt r = KErrNone;
       
   398 	TInt start;
   409 	TInt start;
   399 	TInt function = aMsgRequest->Operation()->Function();
   410 	TInt function = aMsgRequest->Operation()->Function();
   400 	TInt drive = aMsgRequest->DriveNumber();
   411 	TInt drive = aMsgRequest->DriveNumber();
   401 
   412 
   402 	if(aLock)
   413 	if(aLock)
   403 	    LockChain();
   414 	    LockChain();
   404 	
   415 	
       
   416 	//the plugin chain lock must be held by this point.
   405 	TInt count = iPluginChain.Count();
   417 	TInt count = iPluginChain.Count();
   406 
   418 
   407 	if(aPlugin == NULL)
   419 	if(aPlugin == NULL)
   408 		start=0;
   420 		start=0;
   409 	else
   421 	else
   419 					{
   431 					{
   420 
   432 
   421 					aPlugin = iPluginChain[i];
   433 					aPlugin = iPluginChain[i];
   422 					if(aLock)
   434 					if(aLock)
   423 					    UnlockChain();
   435 					    UnlockChain();
   424 					return(r);
   436 					return KErrNone;
   425 					}
   437 					}
   426 				}
   438 				}
   427 			}
   439 			}
   428 		}
   440 		}
   429 	aPlugin = NULL;
   441 	aPlugin = NULL;
   430 	if(aLock)
   442 	if(aLock)
   431 	    UnlockChain();
   443 	    UnlockChain();
   432 	return(KErrNotFound);
   444 	return KErrNotFound;
   433 	}
   445 	}
   434 
   446 
   435 /**
   447 /**
   436 Find the next plugin that supports the operation
   448 Find the next plugin that supports the operation
       
   449 
       
   450 @see FsPluginManager::NextPlugin
   437 */
   451 */
   438 TInt FsPluginManager::PrevPlugin(CFsPlugin*& aPlugin, CFsMessageRequest* aMsgRequest, TBool aLock)
   452 TInt FsPluginManager::PrevPlugin(CFsPlugin*& aPlugin, CFsMessageRequest* aMsgRequest, TBool aLock)
   439 	{
   453 	{
   440 	if(aMsgRequest->DirectToDrive() && (aMsgRequest->CurrentOperationPtr() != NULL))
   454 	if(aMsgRequest->DirectToDrive() && (aMsgRequest->CurrentOperationPtr() != NULL))
   441 		{
   455 		{
   442 		aPlugin = NULL;
   456 		aPlugin = NULL;
   443 		return KErrNotFound;
   457 		return KErrNotFound;
   444 		}
   458 		}
   445 
   459 
   446 	TInt r = KErrNone;
       
   447 	TInt start;
   460 	TInt start;
   448 	TInt function = aMsgRequest->Operation()->Function();
   461 	TInt function = aMsgRequest->Operation()->Function();
   449 	TInt drive = aMsgRequest->DriveNumber();
   462 	TInt drive = aMsgRequest->DriveNumber();
   450 
   463 
   451 	if(aLock)
   464 	if(aLock)
   452 	    LockChain();
   465 	    LockChain();
   453 	
   466 	
       
   467 	//the plugin chain lock must be held by this point.
   454 	TInt count= iPluginChain.Count();
   468 	TInt count= iPluginChain.Count();
   455 
   469 
   456 	if(aPlugin == NULL)
   470 	if(aPlugin == NULL)
   457 		start = count-1;
   471 		start = count-1;
   458 	else
   472 	else
   472 					{
   486 					{
   473 
   487 
   474 					aPlugin = iPluginChain[i];
   488 					aPlugin = iPluginChain[i];
   475 					if(aLock)
   489 					if(aLock)
   476 					    UnlockChain();
   490 					    UnlockChain();
   477 					return(r);
   491 					return KErrNone;
   478 					}
   492 					}
   479 				}
   493 				}
   480 			}
   494 			}
   481 		}
   495 		}
   482 	aPlugin = NULL;
   496 	aPlugin = NULL;
   483 	if(aLock)
   497 	if(aLock)
   484 	    UnlockChain();
   498 	    UnlockChain();
   485 	return(KErrNotFound);
   499 	return KErrNotFound;
   486 	}
   500 	}
   487 /**
   501 /**
   488 Inserts the plugin in the stack (chain)
   502 Inserts the plugin in the stack (chain)
   489 
   503 
   490 if aPos absolute postion, it simply inserts it
   504 if aPos absolute postion, it simply inserts it
   592 	{
   606 	{
   593 	CFsPlugin* pP = FindByUniquePosition(aUniquePosition);
   607 	CFsPlugin* pP = FindByUniquePosition(aUniquePosition);
   594 	if(pP != NULL)
   608 	if(pP != NULL)
   595 		{
   609 		{
   596 		CFsPluginConn* pC = pP->NewPluginConnL();
   610 		CFsPluginConn* pC = pP->NewPluginConnL();
       
   611 		CleanupStack::PushL(pC);
   597 		pC->iPluginP = pP;
   612 		pC->iPluginP = pP;
   598 		pC->iClientId = aClientId;
   613 		pC->iClientId = aClientId;
   599 		iPluginConns->AddL(pC, ETrue);
   614 		iPluginConns->AddL(pC, ETrue);
       
   615 		CleanupStack::Pop(pC);
   600 		return pC;
   616 		return pC;
   601 		}
   617 		}
   602 
   618 
   603 	User::Leave(KErrNotFound);
   619 	User::Leave(KErrNotFound);
   604 	return NULL;
   620 	return NULL;
   717 		}
   733 		}
   718 	}
   734 	}
   719 
   735 
   720 void FsPluginManager::CompleteSessionRequests(CSessionFs* aSession, TInt aValue, CFsInternalRequest* aRequest)
   736 void FsPluginManager::CompleteSessionRequests(CSessionFs* aSession, TInt aValue, CFsInternalRequest* aRequest)
   721 /**
   737 /**
   722 Complete outstanding requests for the specified session
   738  * Complete outstanding requests for the specified session
   723 */
   739  */
   724 	{
   740 	{
   725 	__PRINT2(_L("FsPluginManager::CompleteSessionRequests(%08x, %d)"), aSession, aValue);
   741 	__PRINT2(_L("FsPluginManager::CompleteSessionRequests(%08x, %d)"), aSession, aValue);
   726 
   742 
   727 	// Iterate through all plugins, cancelling outstanding session requests
   743 	// Iterate through all plugins, cancelling outstanding session requests
   728 	aRequest->Set(CancelPluginOp, aSession);
   744 	aRequest->Set(CancelPluginOp, aSession);