Update contrib.
1 // Copyright (c) 1997-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 "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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // concrete file finders for MIME type recognizers
23 #ifdef USING_ECOM_RECOGS
24 #include <ecom/ecom.h>
27 const TInt KRecognizerDllGranularity=2;
29 #ifdef USING_ECOM_RECOGS
30 const TUid KUidDataRecogInterFaceUid = {0x101F7D87};
37 CApaScanningDataRecognizer::TRecognizer::TRecognizer(HBufC* aName)
43 // class CApaRecognizerDll
46 CApaRecognizerDll::~CApaRecognizerDll()
53 CApaRecognizerDll::CApaRecognizerDll(HBufC* aName)
58 #ifdef USING_ECOM_RECOGS
59 // Used for cleanup support of locally declared arrays
60 void CleanUpEComInfoArray(TAny* aInfoArray)
62 RImplInfoPtrArray* infoArray = (static_cast<RImplInfoPtrArray*>(aInfoArray));
63 infoArray->ResetAndDestroy();
68 // class CApaBackupOperationObserver
69 CApaScanningDataRecognizer::CApaBackupOperationObserver::CApaBackupOperationObserver(CApaScanningDataRecognizer& aRecognizer)
70 : iRecognizer(aRecognizer)
72 TRAP_IGNORE(iSession = CBaBackupSessionWrapper::NewL());
75 CApaScanningDataRecognizer::CApaBackupOperationObserver::~CApaBackupOperationObserver()
79 iSession->DeRegisterBackupOperationObserver(*this);
84 void CApaScanningDataRecognizer::CApaBackupOperationObserver::RegisterObserverL()
88 iSession->RegisterBackupOperationObserverL(*this);
92 void CApaScanningDataRecognizer::CApaBackupOperationObserver::HandleBackupOperationEventL(const TBackupOperationAttributes& aBackupOperationAttributes)
94 if (!iRecognizer.iExtra->iRecognizersLoaded)
96 // Then the recognizers have been unloaded, so there's nothing to do
100 if ((aBackupOperationAttributes.iFileFlag == MBackupObserver::EReleaseLockReadOnly ||
101 aBackupOperationAttributes.iFileFlag == MBackupObserver::EReleaseLockNoAccess)
102 && aBackupOperationAttributes.iOperation == EStart)
104 // release recognisers not in rom
105 TInt count = iRecognizer.RecognizerCount();
106 for (TInt i=count-1; i>=0; i--)
108 CApaRecognizerDll* lib=iRecognizer.iRecognizerLib[i];
109 TDriveUnit drive(lib->iId.iDrive);
110 TChar driveName=drive.Name()[0];
111 if(driveName != TChar('Z'))
113 iRecognizer.RemoveRecognizer(lib); // ignore any errors
118 if (aBackupOperationAttributes.iFileFlag == MBackupObserver::ETakeLock &&
119 (aBackupOperationAttributes.iOperation == EEnd ||
120 aBackupOperationAttributes.iOperation == EAbort))
122 iRecognizer.ScanForRecognizersL();
126 TInt CApaScanningDataRecognizer::CApaBackupOperationObserver::UpdateCounter() const
128 return iUpdateCounter;
131 void CApaScanningDataRecognizer::CApaBackupOperationObserver::SetUpdateCounter(TInt aValue)
133 iUpdateCounter = aValue;
138 // class CApaScanningDataRecognizer
141 EXPORT_C CApaScanningDataRecognizer* CApaScanningDataRecognizer::NewL(RFs& aFs)
143 return NewL(aFs,ETrue);
149 EXPORT_C CApaScanningDataRecognizer* CApaScanningDataRecognizer::NewL(RFs& aFs, TBool aLoadDataRecognizers)
151 CApaScanningDataRecognizer* self=new(ELeave) CApaScanningDataRecognizer(aFs);
152 CleanupStack::PushL(self);
153 self->ConstructL(aLoadDataRecognizers);
154 CleanupStack::Pop(); // self
158 EXPORT_C CApaScanningDataRecognizer::~CApaScanningDataRecognizer()
161 delete iExtra->iObserver;
165 EXPORT_C void CApaScanningDataRecognizer::ScanForRecognizersL()
167 // set all recognizers to not present - pending rediscovery
168 TInt count=iRecognizerLib.Count();
170 for (i=0; i<count; i++)
171 iRecognizerLib[i]->iPresent=CApaRecognizerDll::ENotPresent;
173 ScanForEcomRecognizersL();
175 // remove any recognizers that are no longer present
176 for (TInt ii=iRecognizerLib.Count()-1;ii>=0;ii--)
178 CApaRecognizerDll* lib=iRecognizerLib[ii];
179 if (lib->iPresent==CApaRecognizerDll::ENotPresent)
181 RemoveRecognizer(lib); // ignore any errors
184 iMaxBufferSize = -1; // Recognizers were re-loaded so need to recalculate the maximum buffer size
187 EXPORT_C TInt CApaScanningDataRecognizer::RecognizerCount()
189 return iRecognizerLib.Count();
192 EXPORT_C CApaScanningDataRecognizer::CRecognizerArray* CApaScanningDataRecognizer::RecognizerListLC()const
194 CRecognizerArray* list=new(ELeave) CArrayFixFlat<TRecognizer>(2);
195 CleanupStack::PushL(list);
196 TInt count=iRecognizerLib.Count();
197 for (TInt i=0; i<count; i++)
198 list->AppendL(iRecognizerLib[i]->iId);
202 EXPORT_C const CApaScanningDataRecognizer::TRecognizer& CApaScanningDataRecognizer::operator[](TInt aIndex)const
204 return iRecognizerLib[aIndex]->iId;
207 EXPORT_C TInt CApaScanningDataRecognizer::UpdateCounter()const
209 return iExtra->iObserver->UpdateCounter();
213 EXPORT_C CApaScanningDataRecognizer::CApaScanningDataRecognizer(RFs& aFs)
214 :CApaDataRecognizer(aFs),
215 iRecognizerLib(KRecognizerDllGranularity)
217 __DECLARE_NAME(_S("CApaScanningDataRecognizer"));
220 EXPORT_C void CApaScanningDataRecognizer::ConstructL()
225 void CApaScanningDataRecognizer::ConstructL(TBool aLoadDataRecognizers)
227 iExtra = new (ELeave) CApaScanningDataRecognizerExtra();
228 iExtra->iObserver = new (ELeave) CApaBackupOperationObserver( *this );
229 iExtra->iObserver->RegisterObserverL();
230 if(aLoadDataRecognizers)
236 EXPORT_C void CApaScanningDataRecognizer::SetEcomRecognizersFromListL(const CRecognizerArray& aList)
239 for (TInt i=0 ; i<aList.Count() ; i++)
241 TDriveUnit drive(aList[i].iDrive);
242 TRAPD(ret, LoadEcomRecognizerL(drive,aList[i].iUid));
243 if (ret==KErrNoMemory)
250 EXPORT_C void CApaScanningDataRecognizer::SetEcomRecognizerL(const TRecognizer& aRecognizer)
253 TDriveUnit drive(aRecognizer.iDrive);
254 LoadEcomRecognizerL(drive,aRecognizer.iUid);
257 TInt CApaScanningDataRecognizer::RemoveRecognizer(CApaRecognizerDll* aDll)
259 __ASSERT_DEBUG(iRecognizerLib.Count()>0,User::Invariant());
260 // try to remove the recognizer from the list
261 TInt ret=RemoveDataRecognizerType(aDll->iRec);
262 if (ret!=KErrNone && ret!=KErrNotFound)
265 // get a handle to the previous entry in the list
266 TInt count=iRecognizerLib.Count();
268 for (i=0; i<count; i++)
270 if (iRecognizerLib[i]==aDll)
273 __ASSERT_ALWAYS(i<count,Panic(EPanicLibraryNotInList));
276 delete iRecognizerLib[i];
277 iRecognizerLib.Remove(i);
278 iRecognizerLib.Compress();
279 if(iExtra->iObserver)
280 iExtra->iObserver->SetUpdateCounter(iExtra->iObserver->UpdateCounter() +1);
284 #ifdef USING_ECOM_RECOGS
286 //load the ecom style data recognizer
287 void CApaScanningDataRecognizer::LoadEcomRecognizerL(TDriveUnit& aDrive,TUid aUid)
289 //Get implementation information of the recognizer with UID aUid
290 RImplInfoPtrArray implementationInfoArray;
291 TCleanupItem cleanup(CleanUpEComInfoArray, &implementationInfoArray);
292 CleanupStack::PushL(cleanup);
293 REComSession::ListImplementationsL(KUidDataRecogInterFaceUid,implementationInfoArray);
294 const TInt availCount = implementationInfoArray.Count();
295 CImplementationInformation* info=NULL;
297 for (ii=0;ii<availCount;++ii)
299 info = implementationInfoArray[ii];
300 TUid uid = info->ImplementationUid();
302 if(uid.iUid == aUid.iUid )
308 //If the implementation not found just return
311 CleanupStack::PopAndDestroy(&implementationInfoArray);
315 //Get the version of implementation
316 TInt version=info->Version();
318 // check we haven't loaded this one already
319 TInt count=iRecognizerLib.Count();
321 CApaRecognizerDll* lib=NULL; // the previous one in the list
322 for (i=0; i<count; i++)
324 lib=iRecognizerLib[i];
325 if (lib->iId.iUid==aUid)
326 {// we may have to override one
327 if (lib->iPresent!=CApaRecognizerDll::ENotPresent)
329 CleanupStack::PopAndDestroy(&implementationInfoArray);
330 return; // already found
334 if (lib->iVersion < version)
336 //Upgrade a plugin if a plugin with higher version than loaded plugin is installed.
337 lib->iPresent = CApaRecognizerDll::ESuperseded;
342 CleanupStack::PopAndDestroy(&implementationInfoArray);
343 lib->iPresent = CApaRecognizerDll::EIsPresent;
349 //Remove the old version and let it continue to load new version
350 if ((i<count)&&(lib->iPresent==CApaRecognizerDll::ESuperseded))
352 RemoveRecognizer(lib);
356 HBufC* recogName=info->DisplayName().AllocL();
357 CleanupStack::PushL(recogName);
359 lib = new(ELeave) CApaRecognizerDll(recogName);
360 CleanupStack::Pop(recogName);
361 CleanupStack::PushL(lib);
362 TRAPD(error,lib->iRec = CApaDataRecognizerType::CreateDataRecognizerL(aUid));
363 if(!error && lib->iRec)
365 lib->iPresent = CApaRecognizerDll::EIsPresent;
366 AddDataRecognizerTypeL(lib->iRec);
367 lib->iId.iUid = aUid;
368 lib->iId.iDrive = aDrive;
369 lib->iVersion=version;
370 iExtra->iObserver->SetUpdateCounter(iExtra->iObserver->UpdateCounter() + 1);
372 // add lib to the library list
373 iRecognizerLib.AppendL(lib);
374 CleanupStack::Pop(lib); // lib
378 CleanupStack::PopAndDestroy(lib); // lib
380 CleanupStack::PopAndDestroy(&implementationInfoArray);
383 void CApaScanningDataRecognizer::LoadEcomRecognizerL(TDriveUnit&,TUid)
388 void CApaScanningDataRecognizer::ScanForEcomRecognizersL()
390 #ifdef USING_ECOM_RECOGS
392 RImplInfoPtrArray implementationArray;
393 TCleanupItem cleanup(CleanUpEComInfoArray, &implementationArray);
394 CleanupStack::PushL(cleanup);
395 REComSession::ListImplementationsL(KUidDataRecogInterFaceUid,implementationArray);
396 const TInt availCount = implementationArray.Count();
397 for (TInt count=0;count<availCount;++count)
399 const CImplementationInformation* info = implementationArray[count];
400 TUid uid = info->ImplementationUid();
401 TDriveUnit drive=info-> Drive();
402 TRAP_IGNORE(LoadEcomRecognizerL(drive,uid));
404 CleanupStack::PopAndDestroy(&implementationArray);
411 EXPORT_C void CApaScanningDataRecognizer::LoadRecognizersL()
413 iExtra->iRecognizersLoaded = ETrue;
414 ScanForRecognizersL();
421 EXPORT_C void CApaScanningDataRecognizer::UnloadRecognizers()
423 iExtra->iRecognizersLoaded = EFalse;
424 DestroyRecognizerList();
425 iRecognizerLib.ResetAndDestroy();