messagingfw/msgsrvnstore/mtmbase/src/MTUDREG.CPP
changeset 0 8e480a14352b
equal deleted inserted replaced
-1:000000000000 0:8e480a14352b
       
     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 // MTUDREG.H
       
    15 //
       
    16 
       
    17 // Standard includes
       
    18 #include <e32std.h>
       
    19 #include <e32uid.h>
       
    20 
       
    21 // Messaging includes
       
    22 #include <msvapi.h>
       
    23 #include <mtclbase.h>
       
    24 #include <msvruids.h>
       
    25 
       
    26 // Specific includes
       
    27 #include "MTUDCBAS.H"
       
    28 #include "MTUDPAN.H"
       
    29 #include "MTUDREG.H"
       
    30 
       
    31 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS  
       
    32 #include "msvconsts.h"				
       
    33 #endif
       
    34 
       
    35 //
       
    36 //  CMtmUiDataRegistry  //
       
    37 //
       
    38 EXPORT_C CMtmUiDataRegistry* CMtmUiDataRegistry::NewL(CMsvSession& aMsvSession, TTimeIntervalMicroSeconds32 aTimeoutMicroSeconds32)
       
    39 /** Gets a CMtmUiDataRegistry object. 
       
    40 
       
    41 The client should delete this object when it is no longer required.
       
    42 
       
    43 The registry keeps a reference count of the number of instances of each MTM 
       
    44 in use. When that reference count falls to zero, the DLL that provides the 
       
    45 MTM is unloaded. However, this is not done immediately, but only after the 
       
    46 time specified in aTimeoutMicroSeconds32. This increases efficiency in cases 
       
    47 where the DLL is required again shortly.
       
    48 
       
    49 @param aMsvSession The client's Message Server session 
       
    50 @param aTimeoutMicroSeconds32 Time to wait before unloading MTM DLLs 
       
    51 @leave KErrNoMemory A memory allocation failed 
       
    52 @return A pointer to a newly allocated and initialised object */
       
    53 	{
       
    54 	CMtmUiDataRegistry* self = new (ELeave) CMtmUiDataRegistry(aMsvSession, aTimeoutMicroSeconds32);
       
    55 	CleanupStack::PushL(self);
       
    56 	self->ConstructL();
       
    57 	CleanupStack::Pop();
       
    58 	return self;
       
    59 	}
       
    60 
       
    61 CMtmUiDataRegistry::~CMtmUiDataRegistry()
       
    62 	{
       
    63 	}
       
    64 
       
    65 EXPORT_C CBaseMtmUiData* CMtmUiDataRegistry::NewMtmUiDataLayerL(const TUid& aMtmTypeUid)
       
    66 /** Creates a UI Data MTM object for the MTM specified by aMtmTypeUid.
       
    67 
       
    68 The client should delete the returned object when it is no longer required.
       
    69 
       
    70 @param aMtmTypeUid UID of MTM to obtain 
       
    71 @leave KErrNotFound aMtmTypeUid does not specify a registered MTM 
       
    72 @leave KErrNoMemory A memory allocation failed 
       
    73 @leave KErrBadLibraryEntryPoint Malformed MTM: a library entry point was not 
       
    74 of the required type 
       
    75 @leave DLL loading error codes The DLL that provides the MTM cannot be loaded 
       
    76 @return UI Data MTM object for specified MTM */
       
    77 	{
       
    78 	CBaseMtmUiData* newMtmUd = NULL;
       
    79 
       
    80 	if(!IsPresent(aMtmTypeUid))
       
    81 		User::Leave(KErrNotFound);
       
    82 	TInt index=MtmTypeUidToIndex(aMtmTypeUid);
       
    83 	CRegisteredMtmDll* registeredmtmdll=iRegisteredMtmDllArray[index];
       
    84 	RLibrary mtmdlllibrary;
       
    85 	User::LeaveIfError(registeredmtmdll->GetLibrary(iFs, mtmdlllibrary));
       
    86 
       
    87 	TInt refcount = registeredmtmdll->MtmDllRefCount();
       
    88 	TRAPD(ret, newMtmUd = NewMtmL(mtmdlllibrary, *registeredmtmdll));
       
    89 
       
    90 	if ((ret!=KErrNone) && (registeredmtmdll->MtmDllRefCount()==refcount))  //  Library not released in mtm destructor
       
    91 		registeredmtmdll->ReleaseLibrary();
       
    92 	User::LeaveIfError(ret);	
       
    93 	return newMtmUd;
       
    94 	}
       
    95 
       
    96 CBaseMtmUiData* CMtmUiDataRegistry::NewMtmL(const RLibrary& aLib, CRegisteredMtmDll& aReg) const
       
    97 	{
       
    98 	TInt ordinal = aReg.MtmDllInfo().iEntryPointOrdinalNumber;
       
    99 	TLibraryFunction libFunc = aLib.Lookup(ordinal);
       
   100 	if (!libFunc)
       
   101 		User::Leave(KErrBadLibraryEntryPoint);
       
   102 
       
   103 	MtmUiDataFactoryFunctionL* pFunc = (MtmUiDataFactoryFunctionL*)libFunc;
       
   104 	return (*pFunc)(aReg);
       
   105 	}
       
   106 
       
   107 // protected constructor
       
   108 CMtmUiDataRegistry::CMtmUiDataRegistry(CMsvSession& aMsvSession, TTimeIntervalMicroSeconds32 aTimeoutMicroSeconds32)
       
   109 	: CObserverRegistry(aMsvSession, KUidMtmUiDataComponent, aTimeoutMicroSeconds32)
       
   110 	{
       
   111 	__DECLARE_NAME(_S("CMtmUiDataRegistry"));
       
   112 	}
       
   113