|
1 // Copyright (c) 1998-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 // MTCLREG.H |
|
15 // |
|
16 // |
|
17 |
|
18 #include <e32std.h> |
|
19 #include "MSVRUIDS.H" |
|
20 #include "MSVAPI.H" |
|
21 #include "MTCLBASE.H" |
|
22 #include "MTCLREG.H" |
|
23 #include "MSVPANIC.H" |
|
24 |
|
25 EXPORT_C CClientMtmRegistry* CClientMtmRegistry::NewL(CMsvSession& aMsvSession,TTimeIntervalMicroSeconds32 aTimeoutMicroSeconds32) |
|
26 /** Gets a CClientMtmRegistry object. The client should delete this object when |
|
27 it is no longer required. |
|
28 |
|
29 The registry keeps a reference count of the number of instances of each MTM |
|
30 in use. When that reference count falls to zero, the DLL that provides the |
|
31 MTM is unloaded. However, this is not done immediately, but only after the |
|
32 time specified in aTimeoutMicroSeconds32. This increases efficiency in cases |
|
33 where the DLL is required again shortly. |
|
34 |
|
35 @param aMsvSession The client's Message Server session |
|
36 @param aTimeoutMicroSeconds32 Time to wait before unloading MTM DLLs |
|
37 @leave KErrNoMemory A memory allocation failed |
|
38 @return A pointer to a newly allocated and initialised object */ |
|
39 { |
|
40 CClientMtmRegistry* self = new (ELeave) CClientMtmRegistry(aMsvSession,aTimeoutMicroSeconds32); |
|
41 CleanupStack::PushL(self); |
|
42 self->ConstructL(); |
|
43 CleanupStack::Pop(); |
|
44 return self; |
|
45 } |
|
46 |
|
47 |
|
48 void CClientMtmRegistry::ConstructL() |
|
49 { |
|
50 CObserverRegistry::ConstructL(); |
|
51 } |
|
52 |
|
53 |
|
54 /** Destructor. |
|
55 */ |
|
56 EXPORT_C CClientMtmRegistry::~CClientMtmRegistry() |
|
57 {} |
|
58 |
|
59 |
|
60 EXPORT_C CBaseMtm* CClientMtmRegistry::NewMtmL(TUid aMtmTypeUid) |
|
61 /** Creates a Client-side MTM object for the specified MTM UID. |
|
62 |
|
63 The client should delete the returned object when it is no longer required. |
|
64 |
|
65 @param aMtmTypeUid UID of MTM to obtain |
|
66 @leave KErrNotFound aMtmTypeUid does not specify a registered MTM |
|
67 @leave KErrNoMemory A memory allocation failed |
|
68 @leave KErrBadLibraryEntryPoint Malformed MTM: a library entry point was not |
|
69 of the required type |
|
70 @leave DLL loading error codes The DLL that provides the MTM cannot be loaded |
|
71 @return Client-side MTM object for specified MTM */ |
|
72 { |
|
73 if(!IsPresent(aMtmTypeUid)) |
|
74 User::Leave(KErrNotFound); |
|
75 TInt index=MtmTypeUidToIndex(aMtmTypeUid); |
|
76 CRegisteredMtmDll* registeredmtmdll=iRegisteredMtmDllArray[index]; |
|
77 RLibrary lib; |
|
78 User::LeaveIfError(registeredmtmdll->GetLibrary(iFs,lib)); |
|
79 |
|
80 CBaseMtm* newMtm = NULL; |
|
81 TInt refcount=registeredmtmdll->MtmDllRefCount(); |
|
82 TRAPD(ret, newMtm = DoNewMtmL(lib, *registeredmtmdll)); |
|
83 |
|
84 if ((ret!=KErrNone) && (registeredmtmdll->MtmDllRefCount()==refcount)) // Library not released in mtm destructor |
|
85 registeredmtmdll->ReleaseLibrary(); |
|
86 User::LeaveIfError(ret); |
|
87 |
|
88 return newMtm; |
|
89 } |
|
90 |
|
91 CBaseMtm* CClientMtmRegistry::DoNewMtmL(const RLibrary& aLib, CRegisteredMtmDll& aReg) const |
|
92 { |
|
93 TLibraryFunction libFunc = aLib.Lookup(aReg.MtmDllInfo().iEntryPointOrdinalNumber); |
|
94 if (!libFunc) |
|
95 User::Leave(KErrBadLibraryEntryPoint); |
|
96 |
|
97 MtmFactoryFunctionL* pFunc = (MtmFactoryFunctionL*) libFunc; |
|
98 return (*pFunc)(aReg, iMsvSession); |
|
99 } |
|
100 |
|
101 CClientMtmRegistry::CClientMtmRegistry(CMsvSession& aMsvSession, TTimeIntervalMicroSeconds32 aTimeoutMicroSeconds32) |
|
102 : CObserverRegistry(aMsvSession, KUidMtmClientComponent, aTimeoutMicroSeconds32) |
|
103 {} |
|
104 |
|
105 |