os/ossrv/genericopenlibs/openenvcore/libdl/src/loadeddlls.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/genericopenlibs/openenvcore/libdl/src/loadeddlls.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,138 @@
     1.4 +// Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// Name        : loadeddlls.cpp
    1.18 +// Part of     : libdl library
    1.19 +// Implements and maintains the list of opened dll.
    1.20 +// 
    1.21 +//
    1.22 +
    1.23 +// INCLUDE FILES
    1.24 +#include "loadeddlls.h"
    1.25 +	
    1.26 +//-----------------------------------------------------------------------------
    1.27 +//Function Name : CLoadedDlls::CLoadedDlls()
    1.28 +//Description   : Constructor
    1.29 +//-----------------------------------------------------------------------------
    1.30 +CLoadedDlls::CLoadedDlls()
    1.31 +	{
    1.32 +	const TInt error = CreateLock();  
    1.33 +	//if error creating lock, panic.
    1.34 +	if ( KErrNone != error )
    1.35 +		{
    1.36 +		User::Panic(_L(""), error);
    1.37 +		}
    1.38 +	}
    1.39 +	
    1.40 +//-----------------------------------------------------------------------------
    1.41 +//Function Name : CLoadedDlls::~CLoadedDlls()
    1.42 +//Description   : Destructor
    1.43 +//-----------------------------------------------------------------------------
    1.44 +CLoadedDlls::~CLoadedDlls()
    1.45 +	{
    1.46 +	iLock.Close();
    1.47 +	iHandleList.Close();
    1.48 +	}
    1.49 +
    1.50 +//-----------------------------------------------------------------------------
    1.51 +//Function Name : TInt CLoadedDlls::Add(const TDllEntry& aDllEntry)
    1.52 +//Description   : To add the dll to the list.
    1.53 +//Return Value  : KErrNone if added successfully else system wide error
    1.54 +//-----------------------------------------------------------------------------
    1.55 +TInt CLoadedDlls::Add(const TDllEntry& aDllEntry) 
    1.56 +	{
    1.57 +	return iHandleList.Append(aDllEntry);
    1.58 +	}
    1.59 +
    1.60 +//-----------------------------------------------------------------------------
    1.61 +//Function Name : void CLoadedDlls::Remove(const TInt aIndex)
    1.62 +//Description   : To remove the dll from the list.
    1.63 +//-----------------------------------------------------------------------------
    1.64 +void CLoadedDlls::Remove(const TInt aIndex)
    1.65 +	{
    1.66 +	iHandleList.Remove(aIndex);
    1.67 +	iHandleList.GranularCompress();
    1.68 +	}
    1.69 +	
    1.70 +//-----------------------------------------------------------------------------
    1.71 +//Function Name : TDllEntry& CLoadedDlls::At(const TInt aIndex)
    1.72 +//Description   : Get DllEntry& at particular index. This function assumes that
    1.73 +//				  index is valid.
    1.74 +//Return Value  : TDllEntry& DllEntry corresponding to aIndex
    1.75 +//-----------------------------------------------------------------------------
    1.76 +TDllEntry& CLoadedDlls::At(const TInt aIndex)
    1.77 +	{
    1.78 +	return iHandleList[aIndex];
    1.79 +	}
    1.80 +	
    1.81 +//-----------------------------------------------------------------------------
    1.82 +//Function Name : TInt CLoadedDlls::Find(const void* aHandle) const
    1.83 +//Description   : Finds if dll with this handle exist or not
    1.84 +//Return Value  : Index in list if found else KErrNotFound
    1.85 +//-----------------------------------------------------------------------------
    1.86 +TInt CLoadedDlls::Find(const void* aHandle) const
    1.87 +	{
    1.88 +	TDllEntry tempDllEntry((TInt) aHandle);
    1.89 +	return iHandleList.Find(tempDllEntry, TIdentityRelation<TDllEntry>(TDllEntry::CompareByHandle));
    1.90 +	}
    1.91 +
    1.92 +//-----------------------------------------------------------------------------
    1.93 +//Function Name : TInt CLoadedDlls::Find(const RLibrary& aLibrary) const
    1.94 +//Description   : Finds if dll with this library i.e. same path exist or not
    1.95 +//Return Value  : Index in list if found else KErrNotFound
    1.96 +//-----------------------------------------------------------------------------
    1.97 +TInt CLoadedDlls::Find(const RLibrary& aLibrary) const
    1.98 +	{
    1.99 +	TDllEntry tempDllEntry(aLibrary);
   1.100 +	return iHandleList.Find(tempDllEntry,TIdentityRelation<TDllEntry>(TDllEntry::CompareByPath));
   1.101 +	}
   1.102 +
   1.103 +//-----------------------------------------------------------------------------
   1.104 +//Function Name : TBool TDllEntry::CompareByHandle(const TDllEntry& aEntry) 
   1.105 +//Description   : Comparator function, compares iLibrary.Handle() of two
   1.106 +//				  TDllEntry.
   1.107 +//Return Value  : ETrue if Handle of both TDllEntry's RLibrary's matches
   1.108 +//				  else EFalse.
   1.109 +//-----------------------------------------------------------------------------
   1.110 +TBool TDllEntry::CompareByHandle(const TDllEntry& aEntry1, const TDllEntry& aEntry2)
   1.111 +	{
   1.112 +	if (aEntry1.iLibrary.Handle() == aEntry2.iLibrary.Handle())
   1.113 +		{
   1.114 +		return ETrue;
   1.115 +		}
   1.116 +	return EFalse;
   1.117 +	}
   1.118 +	
   1.119 +//-----------------------------------------------------------------------------
   1.120 +//Function Name : TBool TDllEntry::CompareByPath(const TDllEntry& aEntry)
   1.121 +//Description   : Comparator function, compares path corresponding to two
   1.122 +//				  TDllEntry.
   1.123 +//Return Value  : ETrue if file name of both TDllEntry's RLibrary's matches
   1.124 +//				  else EFalse.
   1.125 +//-----------------------------------------------------------------------------
   1.126 +TBool TDllEntry::CompareByPath(const TDllEntry& aEntry1, const TDllEntry& aEntry2)
   1.127 +	{
   1.128 +	if (aEntry1.iLibrary.FileName().Compare(aEntry2.iLibrary.FileName()))
   1.129 +		{
   1.130 +		return EFalse;
   1.131 +		}
   1.132 +	return ETrue;
   1.133 +	}		
   1.134 +		
   1.135 +//-----------------------------------------------------------------------------
   1.136 +//Function Name : TDllEntry::TDllEntry(const RLibrary aLibrary, const TInt aFlag)
   1.137 +//Description   : constructor. to initialise library by RLibrary object
   1.138 +//-----------------------------------------------------------------------------
   1.139 +TDllEntry::TDllEntry(const RLibrary& aLibrary, const TInt aFlag) : iLibrary(aLibrary), iFlags(aFlag), iRefCount(1)
   1.140 +	{
   1.141 +	}