|
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". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // Implementation of the CUnloadPolicy class |
|
15 // |
|
16 // |
|
17 |
|
18 /** |
|
19 @internalComponent |
|
20 @file |
|
21 */ |
|
22 #include <ecom/ecom.h> |
|
23 #include <ecom/ecomerrorcodes.h> |
|
24 #include <ecom/ecomresolverparams.h> |
|
25 #include <ecom/implementationinformation.h> |
|
26 #include "UnloadPolicy.h" |
|
27 #include "TestUtilities.h" // For __FILE__LINE__ |
|
28 #include "EComUidCodes.h" |
|
29 |
|
30 // Design Note: |
|
31 // Dll text is per process. |
|
32 // RLibrary handles are per thread. |
|
33 // Therefore, data related to each loaded dll is per thread so no need for any mutex on say |
|
34 // the reference counter. |
|
35 |
|
36 CUnloadPolicy* CUnloadPolicy::NewLC(const TEntry& aDllEntry) |
|
37 { |
|
38 CUnloadPolicy* self = new(ELeave) CUnloadPolicy(); |
|
39 CleanupStack::PushL(self); |
|
40 self->ConstructL(aDllEntry); |
|
41 return self; |
|
42 } |
|
43 |
|
44 // Default d'tor |
|
45 CUnloadPolicy::~CUnloadPolicy() |
|
46 { |
|
47 // Make sure the library is unloaded |
|
48 iLibrary.Close(); |
|
49 // Remove the instance variable |
|
50 delete iDllEntry; |
|
51 } |
|
52 |
|
53 // Default c'tor |
|
54 CUnloadPolicy::CUnloadPolicy() |
|
55 { |
|
56 // Do nothing here |
|
57 } |
|
58 |
|
59 void CUnloadPolicy::ConstructL(const TEntry& aDllEntry) |
|
60 { |
|
61 iDllEntry = CEComEntry::NewL(aDllEntry.iName,aDllEntry.iType[1],aDllEntry.iType[2]); |
|
62 } |
|
63 |
|
64 TUnloadPolicyStatus CUnloadPolicy::DecreaseReference() |
|
65 { |
|
66 // Already finished with this DLL OR |
|
67 // Note: There could be many clients per process |
|
68 if (iReferencesInUseCount == 0 || --iReferencesInUseCount == 0) |
|
69 { |
|
70 return EDeleteMe; |
|
71 } |
|
72 return EDontDeleteMe; |
|
73 } |
|
74 |
|
75 void CUnloadPolicy::IncreaseReference() |
|
76 { |
|
77 ++iReferencesInUseCount; |
|
78 } |
|
79 |
|
80 TInt CUnloadPolicy::ReferenceCount() const |
|
81 { |
|
82 return iReferencesInUseCount; |
|
83 } |
|
84 |
|
85 TLibraryFunction CUnloadPolicy::LoadDllAndReturnProxyL() |
|
86 { |
|
87 // Function at ordinal 1 is InstantiationMethodL() |
|
88 const TInt KImplementationGroupProxy = 1; |
|
89 |
|
90 // If we have already loaded the library |
|
91 if(iReferencesInUseCount > 0) |
|
92 { |
|
93 IncreaseReference(); |
|
94 return iLibrary.Lookup(KImplementationGroupProxy); |
|
95 } |
|
96 const TDesC& libraryPath = iDllEntry->GetName(); |
|
97 if(libraryPath.Length()) |
|
98 { |
|
99 // Load up the specified library and its default method |
|
100 // Dynamically load DLL |
|
101 User::LeaveIfError(iLibrary.Load(libraryPath, TUidType(KDynamicLibraryUid,iDllEntry->GetSecondUid(),iDllEntry->GetThirdUid()))); |
|
102 // Add to the reference count now to keep the |
|
103 // library loaded for the instantiation call. |
|
104 // IF the client fails before instantiating an implementation |
|
105 // we can rely upon CEcomServerSession to correctly call |
|
106 // for an implementations reference to be removed. |
|
107 IncreaseReference(); |
|
108 return iLibrary.Lookup(KImplementationGroupProxy); |
|
109 } |
|
110 return NULL; |
|
111 } |
|
112 |
|
113 const CEComEntry& CUnloadPolicy::DllEntryInformation() const |
|
114 { |
|
115 return *iDllEntry; |
|
116 } |
|
117 |