os/ossrv/genericopenlibs/openenvcore/libdl/src/loadeddlls.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2006-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".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 // Name        : loadeddlls.cpp
    15 // Part of     : libdl library
    16 // Implements and maintains the list of opened dll.
    17 // 
    18 //
    19 
    20 // INCLUDE FILES
    21 #include "loadeddlls.h"
    22 	
    23 //-----------------------------------------------------------------------------
    24 //Function Name : CLoadedDlls::CLoadedDlls()
    25 //Description   : Constructor
    26 //-----------------------------------------------------------------------------
    27 CLoadedDlls::CLoadedDlls()
    28 	{
    29 	const TInt error = CreateLock();  
    30 	//if error creating lock, panic.
    31 	if ( KErrNone != error )
    32 		{
    33 		User::Panic(_L(""), error);
    34 		}
    35 	}
    36 	
    37 //-----------------------------------------------------------------------------
    38 //Function Name : CLoadedDlls::~CLoadedDlls()
    39 //Description   : Destructor
    40 //-----------------------------------------------------------------------------
    41 CLoadedDlls::~CLoadedDlls()
    42 	{
    43 	iLock.Close();
    44 	iHandleList.Close();
    45 	}
    46 
    47 //-----------------------------------------------------------------------------
    48 //Function Name : TInt CLoadedDlls::Add(const TDllEntry& aDllEntry)
    49 //Description   : To add the dll to the list.
    50 //Return Value  : KErrNone if added successfully else system wide error
    51 //-----------------------------------------------------------------------------
    52 TInt CLoadedDlls::Add(const TDllEntry& aDllEntry) 
    53 	{
    54 	return iHandleList.Append(aDllEntry);
    55 	}
    56 
    57 //-----------------------------------------------------------------------------
    58 //Function Name : void CLoadedDlls::Remove(const TInt aIndex)
    59 //Description   : To remove the dll from the list.
    60 //-----------------------------------------------------------------------------
    61 void CLoadedDlls::Remove(const TInt aIndex)
    62 	{
    63 	iHandleList.Remove(aIndex);
    64 	iHandleList.GranularCompress();
    65 	}
    66 	
    67 //-----------------------------------------------------------------------------
    68 //Function Name : TDllEntry& CLoadedDlls::At(const TInt aIndex)
    69 //Description   : Get DllEntry& at particular index. This function assumes that
    70 //				  index is valid.
    71 //Return Value  : TDllEntry& DllEntry corresponding to aIndex
    72 //-----------------------------------------------------------------------------
    73 TDllEntry& CLoadedDlls::At(const TInt aIndex)
    74 	{
    75 	return iHandleList[aIndex];
    76 	}
    77 	
    78 //-----------------------------------------------------------------------------
    79 //Function Name : TInt CLoadedDlls::Find(const void* aHandle) const
    80 //Description   : Finds if dll with this handle exist or not
    81 //Return Value  : Index in list if found else KErrNotFound
    82 //-----------------------------------------------------------------------------
    83 TInt CLoadedDlls::Find(const void* aHandle) const
    84 	{
    85 	TDllEntry tempDllEntry((TInt) aHandle);
    86 	return iHandleList.Find(tempDllEntry, TIdentityRelation<TDllEntry>(TDllEntry::CompareByHandle));
    87 	}
    88 
    89 //-----------------------------------------------------------------------------
    90 //Function Name : TInt CLoadedDlls::Find(const RLibrary& aLibrary) const
    91 //Description   : Finds if dll with this library i.e. same path exist or not
    92 //Return Value  : Index in list if found else KErrNotFound
    93 //-----------------------------------------------------------------------------
    94 TInt CLoadedDlls::Find(const RLibrary& aLibrary) const
    95 	{
    96 	TDllEntry tempDllEntry(aLibrary);
    97 	return iHandleList.Find(tempDllEntry,TIdentityRelation<TDllEntry>(TDllEntry::CompareByPath));
    98 	}
    99 
   100 //-----------------------------------------------------------------------------
   101 //Function Name : TBool TDllEntry::CompareByHandle(const TDllEntry& aEntry) 
   102 //Description   : Comparator function, compares iLibrary.Handle() of two
   103 //				  TDllEntry.
   104 //Return Value  : ETrue if Handle of both TDllEntry's RLibrary's matches
   105 //				  else EFalse.
   106 //-----------------------------------------------------------------------------
   107 TBool TDllEntry::CompareByHandle(const TDllEntry& aEntry1, const TDllEntry& aEntry2)
   108 	{
   109 	if (aEntry1.iLibrary.Handle() == aEntry2.iLibrary.Handle())
   110 		{
   111 		return ETrue;
   112 		}
   113 	return EFalse;
   114 	}
   115 	
   116 //-----------------------------------------------------------------------------
   117 //Function Name : TBool TDllEntry::CompareByPath(const TDllEntry& aEntry)
   118 //Description   : Comparator function, compares path corresponding to two
   119 //				  TDllEntry.
   120 //Return Value  : ETrue if file name of both TDllEntry's RLibrary's matches
   121 //				  else EFalse.
   122 //-----------------------------------------------------------------------------
   123 TBool TDllEntry::CompareByPath(const TDllEntry& aEntry1, const TDllEntry& aEntry2)
   124 	{
   125 	if (aEntry1.iLibrary.FileName().Compare(aEntry2.iLibrary.FileName()))
   126 		{
   127 		return EFalse;
   128 		}
   129 	return ETrue;
   130 	}		
   131 		
   132 //-----------------------------------------------------------------------------
   133 //Function Name : TDllEntry::TDllEntry(const RLibrary aLibrary, const TInt aFlag)
   134 //Description   : constructor. to initialise library by RLibrary object
   135 //-----------------------------------------------------------------------------
   136 TDllEntry::TDllEntry(const RLibrary& aLibrary, const TInt aFlag) : iLibrary(aLibrary), iFlags(aFlag), iRefCount(1)
   137 	{
   138 	}