sl@0: // Copyright (c) 2006-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: // Name : loadeddlls.cpp sl@0: // Part of : libdl library sl@0: // Implements and maintains the list of opened dll. sl@0: // sl@0: // sl@0: sl@0: // INCLUDE FILES sl@0: #include "loadeddlls.h" sl@0: sl@0: //----------------------------------------------------------------------------- sl@0: //Function Name : CLoadedDlls::CLoadedDlls() sl@0: //Description : Constructor sl@0: //----------------------------------------------------------------------------- sl@0: CLoadedDlls::CLoadedDlls() sl@0: { sl@0: const TInt error = CreateLock(); sl@0: //if error creating lock, panic. sl@0: if ( KErrNone != error ) sl@0: { sl@0: User::Panic(_L(""), error); sl@0: } sl@0: } sl@0: sl@0: //----------------------------------------------------------------------------- sl@0: //Function Name : CLoadedDlls::~CLoadedDlls() sl@0: //Description : Destructor sl@0: //----------------------------------------------------------------------------- sl@0: CLoadedDlls::~CLoadedDlls() sl@0: { sl@0: iLock.Close(); sl@0: iHandleList.Close(); sl@0: } sl@0: sl@0: //----------------------------------------------------------------------------- sl@0: //Function Name : TInt CLoadedDlls::Add(const TDllEntry& aDllEntry) sl@0: //Description : To add the dll to the list. sl@0: //Return Value : KErrNone if added successfully else system wide error sl@0: //----------------------------------------------------------------------------- sl@0: TInt CLoadedDlls::Add(const TDllEntry& aDllEntry) sl@0: { sl@0: return iHandleList.Append(aDllEntry); sl@0: } sl@0: sl@0: //----------------------------------------------------------------------------- sl@0: //Function Name : void CLoadedDlls::Remove(const TInt aIndex) sl@0: //Description : To remove the dll from the list. sl@0: //----------------------------------------------------------------------------- sl@0: void CLoadedDlls::Remove(const TInt aIndex) sl@0: { sl@0: iHandleList.Remove(aIndex); sl@0: iHandleList.GranularCompress(); sl@0: } sl@0: sl@0: //----------------------------------------------------------------------------- sl@0: //Function Name : TDllEntry& CLoadedDlls::At(const TInt aIndex) sl@0: //Description : Get DllEntry& at particular index. This function assumes that sl@0: // index is valid. sl@0: //Return Value : TDllEntry& DllEntry corresponding to aIndex sl@0: //----------------------------------------------------------------------------- sl@0: TDllEntry& CLoadedDlls::At(const TInt aIndex) sl@0: { sl@0: return iHandleList[aIndex]; sl@0: } sl@0: sl@0: //----------------------------------------------------------------------------- sl@0: //Function Name : TInt CLoadedDlls::Find(const void* aHandle) const sl@0: //Description : Finds if dll with this handle exist or not sl@0: //Return Value : Index in list if found else KErrNotFound sl@0: //----------------------------------------------------------------------------- sl@0: TInt CLoadedDlls::Find(const void* aHandle) const sl@0: { sl@0: TDllEntry tempDllEntry((TInt) aHandle); sl@0: return iHandleList.Find(tempDllEntry, TIdentityRelation(TDllEntry::CompareByHandle)); sl@0: } sl@0: sl@0: //----------------------------------------------------------------------------- sl@0: //Function Name : TInt CLoadedDlls::Find(const RLibrary& aLibrary) const sl@0: //Description : Finds if dll with this library i.e. same path exist or not sl@0: //Return Value : Index in list if found else KErrNotFound sl@0: //----------------------------------------------------------------------------- sl@0: TInt CLoadedDlls::Find(const RLibrary& aLibrary) const sl@0: { sl@0: TDllEntry tempDllEntry(aLibrary); sl@0: return iHandleList.Find(tempDllEntry,TIdentityRelation(TDllEntry::CompareByPath)); sl@0: } sl@0: sl@0: //----------------------------------------------------------------------------- sl@0: //Function Name : TBool TDllEntry::CompareByHandle(const TDllEntry& aEntry) sl@0: //Description : Comparator function, compares iLibrary.Handle() of two sl@0: // TDllEntry. sl@0: //Return Value : ETrue if Handle of both TDllEntry's RLibrary's matches sl@0: // else EFalse. sl@0: //----------------------------------------------------------------------------- sl@0: TBool TDllEntry::CompareByHandle(const TDllEntry& aEntry1, const TDllEntry& aEntry2) sl@0: { sl@0: if (aEntry1.iLibrary.Handle() == aEntry2.iLibrary.Handle()) sl@0: { sl@0: return ETrue; sl@0: } sl@0: return EFalse; sl@0: } sl@0: sl@0: //----------------------------------------------------------------------------- sl@0: //Function Name : TBool TDllEntry::CompareByPath(const TDllEntry& aEntry) sl@0: //Description : Comparator function, compares path corresponding to two sl@0: // TDllEntry. sl@0: //Return Value : ETrue if file name of both TDllEntry's RLibrary's matches sl@0: // else EFalse. sl@0: //----------------------------------------------------------------------------- sl@0: TBool TDllEntry::CompareByPath(const TDllEntry& aEntry1, const TDllEntry& aEntry2) sl@0: { sl@0: if (aEntry1.iLibrary.FileName().Compare(aEntry2.iLibrary.FileName())) sl@0: { sl@0: return EFalse; sl@0: } sl@0: return ETrue; sl@0: } sl@0: sl@0: //----------------------------------------------------------------------------- sl@0: //Function Name : TDllEntry::TDllEntry(const RLibrary aLibrary, const TInt aFlag) sl@0: //Description : constructor. to initialise library by RLibrary object sl@0: //----------------------------------------------------------------------------- sl@0: TDllEntry::TDllEntry(const RLibrary& aLibrary, const TInt aFlag) : iLibrary(aLibrary), iFlags(aFlag), iRefCount(1) sl@0: { sl@0: }