1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/lowlevellibsandfws/pluginfw/Framework/frame/UnloadPolicy.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,117 @@
1.4 +// Copyright (c) 1997-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 +// Implementation of the CUnloadPolicy class
1.18 +//
1.19 +//
1.20 +
1.21 +/**
1.22 + @internalComponent
1.23 + @file
1.24 +*/
1.25 +#include <ecom/ecom.h>
1.26 +#include <ecom/ecomerrorcodes.h>
1.27 +#include <ecom/ecomresolverparams.h>
1.28 +#include <ecom/implementationinformation.h>
1.29 +#include "UnloadPolicy.h"
1.30 +#include "TestUtilities.h" // For __FILE__LINE__
1.31 +#include "EComUidCodes.h"
1.32 +
1.33 +// Design Note:
1.34 +// Dll text is per process.
1.35 +// RLibrary handles are per thread.
1.36 +// Therefore, data related to each loaded dll is per thread so no need for any mutex on say
1.37 +// the reference counter.
1.38 +
1.39 +CUnloadPolicy* CUnloadPolicy::NewLC(const TEntry& aDllEntry)
1.40 + {
1.41 + CUnloadPolicy* self = new(ELeave) CUnloadPolicy();
1.42 + CleanupStack::PushL(self);
1.43 + self->ConstructL(aDllEntry);
1.44 + return self;
1.45 + }
1.46 +
1.47 +// Default d'tor
1.48 +CUnloadPolicy::~CUnloadPolicy()
1.49 + {
1.50 + // Make sure the library is unloaded
1.51 + iLibrary.Close();
1.52 + // Remove the instance variable
1.53 + delete iDllEntry;
1.54 + }
1.55 +
1.56 +// Default c'tor
1.57 +CUnloadPolicy::CUnloadPolicy()
1.58 + {
1.59 + // Do nothing here
1.60 + }
1.61 +
1.62 +void CUnloadPolicy::ConstructL(const TEntry& aDllEntry)
1.63 + {
1.64 + iDllEntry = CEComEntry::NewL(aDllEntry.iName,aDllEntry.iType[1],aDllEntry.iType[2]);
1.65 + }
1.66 +
1.67 +TUnloadPolicyStatus CUnloadPolicy::DecreaseReference()
1.68 + {
1.69 + // Already finished with this DLL OR
1.70 + // Note: There could be many clients per process
1.71 + if (iReferencesInUseCount == 0 || --iReferencesInUseCount == 0)
1.72 + {
1.73 + return EDeleteMe;
1.74 + }
1.75 + return EDontDeleteMe;
1.76 + }
1.77 +
1.78 +void CUnloadPolicy::IncreaseReference()
1.79 + {
1.80 + ++iReferencesInUseCount;
1.81 + }
1.82 +
1.83 +TInt CUnloadPolicy::ReferenceCount() const
1.84 + {
1.85 + return iReferencesInUseCount;
1.86 + }
1.87 +
1.88 +TLibraryFunction CUnloadPolicy::LoadDllAndReturnProxyL()
1.89 + {
1.90 + // Function at ordinal 1 is InstantiationMethodL()
1.91 + const TInt KImplementationGroupProxy = 1;
1.92 +
1.93 + // If we have already loaded the library
1.94 + if(iReferencesInUseCount > 0)
1.95 + {
1.96 + IncreaseReference();
1.97 + return iLibrary.Lookup(KImplementationGroupProxy);
1.98 + }
1.99 + const TDesC& libraryPath = iDllEntry->GetName();
1.100 + if(libraryPath.Length())
1.101 + {
1.102 + // Load up the specified library and its default method
1.103 + // Dynamically load DLL
1.104 + User::LeaveIfError(iLibrary.Load(libraryPath, TUidType(KDynamicLibraryUid,iDllEntry->GetSecondUid(),iDllEntry->GetThirdUid())));
1.105 + // Add to the reference count now to keep the
1.106 + // library loaded for the instantiation call.
1.107 + // IF the client fails before instantiating an implementation
1.108 + // we can rely upon CEcomServerSession to correctly call
1.109 + // for an implementations reference to be removed.
1.110 + IncreaseReference();
1.111 + return iLibrary.Lookup(KImplementationGroupProxy);
1.112 + }
1.113 + return NULL;
1.114 + }
1.115 +
1.116 +const CEComEntry& CUnloadPolicy::DllEntryInformation() const
1.117 + {
1.118 + return *iDllEntry;
1.119 + }
1.120 +