sl@0: // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // concrete file finders for MIME type recognizers sl@0: // sl@0: // sl@0: sl@0: #include "APMFNDR.H" sl@0: sl@0: #include sl@0: #include "APMPAN.H" sl@0: sl@0: #ifdef USING_ECOM_RECOGS sl@0: #include sl@0: #endif sl@0: sl@0: const TInt KRecognizerDllGranularity=2; sl@0: sl@0: #ifdef USING_ECOM_RECOGS sl@0: const TUid KUidDataRecogInterFaceUid = {0x101F7D87}; sl@0: #endif sl@0: sl@0: // sl@0: // class TRecognizer sl@0: // sl@0: sl@0: CApaScanningDataRecognizer::TRecognizer::TRecognizer(HBufC* aName) sl@0: { sl@0: iName=aName; sl@0: } sl@0: sl@0: // sl@0: // class CApaRecognizerDll sl@0: // sl@0: sl@0: CApaRecognizerDll::~CApaRecognizerDll() sl@0: { sl@0: delete iId.iName; sl@0: iLibrary.Close(); sl@0: delete iNext; sl@0: } sl@0: sl@0: CApaRecognizerDll::CApaRecognizerDll(HBufC* aName) sl@0: : iId(aName) sl@0: { sl@0: } sl@0: sl@0: #ifdef USING_ECOM_RECOGS sl@0: // Used for cleanup support of locally declared arrays sl@0: void CleanUpEComInfoArray(TAny* aInfoArray) sl@0: { sl@0: RImplInfoPtrArray* infoArray = (static_cast(aInfoArray)); sl@0: infoArray->ResetAndDestroy(); sl@0: infoArray->Close(); sl@0: } sl@0: #endif sl@0: sl@0: // class CApaBackupOperationObserver sl@0: CApaScanningDataRecognizer::CApaBackupOperationObserver::CApaBackupOperationObserver(CApaScanningDataRecognizer& aRecognizer) sl@0: : iRecognizer(aRecognizer) sl@0: { sl@0: TRAP_IGNORE(iSession = CBaBackupSessionWrapper::NewL()); sl@0: } sl@0: sl@0: CApaScanningDataRecognizer::CApaBackupOperationObserver::~CApaBackupOperationObserver() sl@0: { sl@0: if( iSession ) sl@0: { sl@0: iSession->DeRegisterBackupOperationObserver(*this); sl@0: delete iSession; sl@0: } sl@0: } sl@0: sl@0: void CApaScanningDataRecognizer::CApaBackupOperationObserver::RegisterObserverL() sl@0: { sl@0: if(iSession) sl@0: { sl@0: iSession->RegisterBackupOperationObserverL(*this); sl@0: } sl@0: } sl@0: sl@0: void CApaScanningDataRecognizer::CApaBackupOperationObserver::HandleBackupOperationEventL(const TBackupOperationAttributes& aBackupOperationAttributes) sl@0: { sl@0: if (!iRecognizer.iExtra->iRecognizersLoaded) sl@0: { sl@0: // Then the recognizers have been unloaded, so there's nothing to do sl@0: return; sl@0: } sl@0: sl@0: if ((aBackupOperationAttributes.iFileFlag == MBackupObserver::EReleaseLockReadOnly || sl@0: aBackupOperationAttributes.iFileFlag == MBackupObserver::EReleaseLockNoAccess) sl@0: && aBackupOperationAttributes.iOperation == EStart) sl@0: { sl@0: // release recognisers not in rom sl@0: TInt count = iRecognizer.RecognizerCount(); sl@0: for (TInt i=count-1; i>=0; i--) sl@0: { sl@0: CApaRecognizerDll* lib=iRecognizer.iRecognizerLib[i]; sl@0: TDriveUnit drive(lib->iId.iDrive); sl@0: TChar driveName=drive.Name()[0]; sl@0: if(driveName != TChar('Z')) sl@0: { sl@0: iRecognizer.RemoveRecognizer(lib); // ignore any errors sl@0: } sl@0: } sl@0: } sl@0: sl@0: if (aBackupOperationAttributes.iFileFlag == MBackupObserver::ETakeLock && sl@0: (aBackupOperationAttributes.iOperation == EEnd || sl@0: aBackupOperationAttributes.iOperation == EAbort)) sl@0: { sl@0: iRecognizer.ScanForRecognizersL(); sl@0: } sl@0: } sl@0: sl@0: TInt CApaScanningDataRecognizer::CApaBackupOperationObserver::UpdateCounter() const sl@0: { sl@0: return iUpdateCounter; sl@0: } sl@0: sl@0: void CApaScanningDataRecognizer::CApaBackupOperationObserver::SetUpdateCounter(TInt aValue) sl@0: { sl@0: iUpdateCounter = aValue; sl@0: } sl@0: sl@0: sl@0: // sl@0: // class CApaScanningDataRecognizer sl@0: // sl@0: sl@0: EXPORT_C CApaScanningDataRecognizer* CApaScanningDataRecognizer::NewL(RFs& aFs) sl@0: { sl@0: return NewL(aFs,ETrue); sl@0: } sl@0: sl@0: /** sl@0: @internalTechnology sl@0: */ sl@0: EXPORT_C CApaScanningDataRecognizer* CApaScanningDataRecognizer::NewL(RFs& aFs, TBool aLoadDataRecognizers) sl@0: { sl@0: CApaScanningDataRecognizer* self=new(ELeave) CApaScanningDataRecognizer(aFs); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(aLoadDataRecognizers); sl@0: CleanupStack::Pop(); // self sl@0: return self; sl@0: } sl@0: sl@0: EXPORT_C CApaScanningDataRecognizer::~CApaScanningDataRecognizer() sl@0: { sl@0: UnloadRecognizers(); sl@0: delete iExtra->iObserver; sl@0: delete iExtra; sl@0: } sl@0: sl@0: EXPORT_C void CApaScanningDataRecognizer::ScanForRecognizersL() sl@0: { sl@0: // set all recognizers to not present - pending rediscovery sl@0: TInt count=iRecognizerLib.Count(); sl@0: TInt i; sl@0: for (i=0; iiPresent=CApaRecognizerDll::ENotPresent; sl@0: sl@0: ScanForEcomRecognizersL(); sl@0: // sl@0: // remove any recognizers that are no longer present sl@0: for (TInt ii=iRecognizerLib.Count()-1;ii>=0;ii--) sl@0: { sl@0: CApaRecognizerDll* lib=iRecognizerLib[ii]; sl@0: if (lib->iPresent==CApaRecognizerDll::ENotPresent) sl@0: { sl@0: RemoveRecognizer(lib); // ignore any errors sl@0: } sl@0: } sl@0: iMaxBufferSize = -1; // Recognizers were re-loaded so need to recalculate the maximum buffer size sl@0: } sl@0: sl@0: EXPORT_C TInt CApaScanningDataRecognizer::RecognizerCount() sl@0: { sl@0: return iRecognizerLib.Count(); sl@0: } sl@0: sl@0: EXPORT_C CApaScanningDataRecognizer::CRecognizerArray* CApaScanningDataRecognizer::RecognizerListLC()const sl@0: { sl@0: CRecognizerArray* list=new(ELeave) CArrayFixFlat(2); sl@0: CleanupStack::PushL(list); sl@0: TInt count=iRecognizerLib.Count(); sl@0: for (TInt i=0; iAppendL(iRecognizerLib[i]->iId); sl@0: return list; sl@0: } sl@0: sl@0: EXPORT_C const CApaScanningDataRecognizer::TRecognizer& CApaScanningDataRecognizer::operator[](TInt aIndex)const sl@0: { sl@0: return iRecognizerLib[aIndex]->iId; sl@0: } sl@0: sl@0: EXPORT_C TInt CApaScanningDataRecognizer::UpdateCounter()const sl@0: { sl@0: return iExtra->iObserver->UpdateCounter(); sl@0: } sl@0: sl@0: sl@0: EXPORT_C CApaScanningDataRecognizer::CApaScanningDataRecognizer(RFs& aFs) sl@0: :CApaDataRecognizer(aFs), sl@0: iRecognizerLib(KRecognizerDllGranularity) sl@0: { sl@0: __DECLARE_NAME(_S("CApaScanningDataRecognizer")); sl@0: } sl@0: sl@0: EXPORT_C void CApaScanningDataRecognizer::ConstructL() sl@0: { sl@0: ConstructL(ETrue); sl@0: } sl@0: sl@0: void CApaScanningDataRecognizer::ConstructL(TBool aLoadDataRecognizers) sl@0: { sl@0: iExtra = new (ELeave) CApaScanningDataRecognizerExtra(); sl@0: iExtra->iObserver = new (ELeave) CApaBackupOperationObserver( *this ); sl@0: iExtra->iObserver->RegisterObserverL(); sl@0: if(aLoadDataRecognizers) sl@0: { sl@0: LoadRecognizersL(); sl@0: } sl@0: } sl@0: sl@0: EXPORT_C void CApaScanningDataRecognizer::SetEcomRecognizersFromListL(const CRecognizerArray& aList) sl@0: { sl@0: //for ecom style sl@0: for (TInt i=0 ; i0,User::Invariant()); sl@0: // try to remove the recognizer from the list sl@0: TInt ret=RemoveDataRecognizerType(aDll->iRec); sl@0: if (ret!=KErrNone && ret!=KErrNotFound) sl@0: return ret; sl@0: // sl@0: // get a handle to the previous entry in the list sl@0: TInt count=iRecognizerLib.Count(); sl@0: TInt i; sl@0: for (i=0; iiObserver) sl@0: iExtra->iObserver->SetUpdateCounter(iExtra->iObserver->UpdateCounter() +1); sl@0: return KErrNone; sl@0: } sl@0: sl@0: #ifdef USING_ECOM_RECOGS sl@0: sl@0: //load the ecom style data recognizer sl@0: void CApaScanningDataRecognizer::LoadEcomRecognizerL(TDriveUnit& aDrive,TUid aUid) sl@0: { sl@0: //Get implementation information of the recognizer with UID aUid sl@0: RImplInfoPtrArray implementationInfoArray; sl@0: TCleanupItem cleanup(CleanUpEComInfoArray, &implementationInfoArray); sl@0: CleanupStack::PushL(cleanup); sl@0: REComSession::ListImplementationsL(KUidDataRecogInterFaceUid,implementationInfoArray); sl@0: const TInt availCount = implementationInfoArray.Count(); sl@0: CImplementationInformation* info=NULL; sl@0: TInt ii; sl@0: for (ii=0;iiImplementationUid(); sl@0: sl@0: if(uid.iUid == aUid.iUid ) sl@0: { sl@0: break; sl@0: } sl@0: } sl@0: sl@0: //If the implementation not found just return sl@0: if(ii==availCount) sl@0: { sl@0: CleanupStack::PopAndDestroy(&implementationInfoArray); sl@0: return; sl@0: } sl@0: sl@0: //Get the version of implementation sl@0: TInt version=info->Version(); sl@0: sl@0: // check we haven't loaded this one already sl@0: TInt count=iRecognizerLib.Count(); sl@0: TInt i; sl@0: CApaRecognizerDll* lib=NULL; // the previous one in the list sl@0: for (i=0; iiId.iUid==aUid) sl@0: {// we may have to override one sl@0: if (lib->iPresent!=CApaRecognizerDll::ENotPresent) sl@0: { sl@0: CleanupStack::PopAndDestroy(&implementationInfoArray); sl@0: return; // already found sl@0: } sl@0: else sl@0: { sl@0: if (lib->iVersion < version) sl@0: { sl@0: //Upgrade a plugin if a plugin with higher version than loaded plugin is installed. sl@0: lib->iPresent = CApaRecognizerDll::ESuperseded; sl@0: break; sl@0: } sl@0: else sl@0: { sl@0: CleanupStack::PopAndDestroy(&implementationInfoArray); sl@0: lib->iPresent = CApaRecognizerDll::EIsPresent; sl@0: return; sl@0: } sl@0: } sl@0: } sl@0: } sl@0: //Remove the old version and let it continue to load new version sl@0: if ((iiPresent==CApaRecognizerDll::ESuperseded)) sl@0: { sl@0: RemoveRecognizer(lib); sl@0: } sl@0: sl@0: // load the library sl@0: HBufC* recogName=info->DisplayName().AllocL(); sl@0: CleanupStack::PushL(recogName); sl@0: lib=NULL; sl@0: lib = new(ELeave) CApaRecognizerDll(recogName); sl@0: CleanupStack::Pop(recogName); sl@0: CleanupStack::PushL(lib); sl@0: TRAPD(error,lib->iRec = CApaDataRecognizerType::CreateDataRecognizerL(aUid)); sl@0: if(!error && lib->iRec) sl@0: { sl@0: lib->iPresent = CApaRecognizerDll::EIsPresent; sl@0: AddDataRecognizerTypeL(lib->iRec); sl@0: lib->iId.iUid = aUid; sl@0: lib->iId.iDrive = aDrive; sl@0: lib->iVersion=version; sl@0: iExtra->iObserver->SetUpdateCounter(iExtra->iObserver->UpdateCounter() + 1); sl@0: // sl@0: // add lib to the library list sl@0: iRecognizerLib.AppendL(lib); sl@0: CleanupStack::Pop(lib); // lib sl@0: } sl@0: else sl@0: { sl@0: CleanupStack::PopAndDestroy(lib); // lib sl@0: } sl@0: CleanupStack::PopAndDestroy(&implementationInfoArray); sl@0: } sl@0: #else sl@0: void CApaScanningDataRecognizer::LoadEcomRecognizerL(TDriveUnit&,TUid) sl@0: { sl@0: } sl@0: #endif sl@0: sl@0: void CApaScanningDataRecognizer::ScanForEcomRecognizersL() sl@0: { sl@0: #ifdef USING_ECOM_RECOGS sl@0: //scan ecom plugin sl@0: RImplInfoPtrArray implementationArray; sl@0: TCleanupItem cleanup(CleanUpEComInfoArray, &implementationArray); sl@0: CleanupStack::PushL(cleanup); sl@0: REComSession::ListImplementationsL(KUidDataRecogInterFaceUid,implementationArray); sl@0: const TInt availCount = implementationArray.Count(); sl@0: for (TInt count=0;countImplementationUid(); sl@0: TDriveUnit drive=info-> Drive(); sl@0: TRAP_IGNORE(LoadEcomRecognizerL(drive,uid)); sl@0: } sl@0: CleanupStack::PopAndDestroy(&implementationArray); sl@0: #endif sl@0: } sl@0: sl@0: /** sl@0: @internalTechnology sl@0: */ sl@0: EXPORT_C void CApaScanningDataRecognizer::LoadRecognizersL() sl@0: { sl@0: iExtra->iRecognizersLoaded = ETrue; sl@0: ScanForRecognizersL(); sl@0: UpdateDataTypesL(); sl@0: } sl@0: sl@0: /** sl@0: @internalTechnology sl@0: */ sl@0: EXPORT_C void CApaScanningDataRecognizer::UnloadRecognizers() sl@0: { sl@0: iExtra->iRecognizersLoaded = EFalse; sl@0: DestroyRecognizerList(); sl@0: iRecognizerLib.ResetAndDestroy(); sl@0: } sl@0: