phonebookui/Phonebook/PbkExt/src/CPbkExtGlobals.cpp
changeset 0 e686773b3f54
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 /*
       
     2 * Copyright (c) 2002 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *       PbkExt.dll global variables. A singleton class.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "CPbkExtGlobals.h"
       
    22 #include "CPbkMultiExtensionFactory.h"
       
    23 #include "CPbkExtensionLoader.h"
       
    24 
       
    25 // Debugging headers
       
    26 #include <PbkDebug.h>
       
    27 #include "PbkProfiling.h"
       
    28 
       
    29 #include <ecom/ecom.h>
       
    30 
       
    31 // Unnamed namespace for local definitions
       
    32 namespace {
       
    33 
       
    34 const TInt KExtensionGranularity = 1;
       
    35 
       
    36 /**
       
    37  * Returns global instance of CPbkExtGlobals
       
    38  */
       
    39 inline CPbkExtGlobals* Instance()
       
    40     {
       
    41     return static_cast<CPbkExtGlobals*>(Dll::Tls());
       
    42     }
       
    43 
       
    44 } // namespace
       
    45 
       
    46 
       
    47 // ==================== MEMBER FUNCTIONS ====================                 
       
    48 CPbkExtGlobals::CPbkExtGlobals() :
       
    49     iExtensions(KExtensionGranularity)
       
    50     {
       
    51 	}	
       
    52 
       
    53 CPbkExtGlobals::~CPbkExtGlobals()
       
    54     {
       
    55     delete iMultiFactory;
       
    56     iExtensions.ResetAndDestroy();
       
    57 
       
    58     // Cleanup ECom session
       
    59     REComSession::FinalClose();
       
    60     }
       
    61 
       
    62 CPbkExtGlobals* CPbkExtGlobals::NewLC()
       
    63     {
       
    64     CPbkExtGlobals* self = new (ELeave) CPbkExtGlobals;
       
    65     CleanupStack::PushL( self );
       
    66 
       
    67     return self;
       
    68     }
       
    69 
       
    70 void CPbkExtGlobals::IncRef()
       
    71     {
       
    72     ++iRefCount;
       
    73     }
       
    74 
       
    75 TInt CPbkExtGlobals::DecRef()
       
    76     {
       
    77     return --iRefCount;
       
    78     }
       
    79 
       
    80 EXPORT_C CPbkExtGlobals* CPbkExtGlobals::InstanceL()
       
    81     {
       
    82     CPbkExtGlobals* instance = Instance();
       
    83 
       
    84     if (!instance)
       
    85         {
       
    86         instance = CPbkExtGlobals::NewLC();
       
    87         User::LeaveIfError(Dll::SetTls(instance));
       
    88         CleanupStack::Pop(instance);
       
    89         }
       
    90 
       
    91     instance->IncRef();
       
    92 
       
    93     return instance;
       
    94     }
       
    95 
       
    96 EXPORT_C MPbkExtensionFactory& CPbkExtGlobals::FactoryL()
       
    97     {    
       
    98     if (!iMultiFactory)
       
    99 		{
       
   100         __PBK_PROFILE_START(PbkProfiling::EPbkExtGlobalsScannerConstruct);
       
   101         // Make sure that there are no extensions when scanning
       
   102         iExtensions.ResetAndDestroy();
       
   103         // If scanning fails we leave here so that iMultiFactory
       
   104         // doesn't get created. So when calling this function
       
   105         // again scanning is tried again.
       
   106         CPbkExtensionScanner* scanner = 
       
   107             CPbkExtensionScanner::NewLC(iExtensions);
       
   108         __PBK_PROFILE_END(PbkProfiling::EPbkExtGlobalsScannerConstruct);
       
   109         __PBK_PROFILE_START(PbkProfiling::EExtensionScan);
       
   110         scanner->ScanL();
       
   111         CleanupStack::PopAndDestroy(scanner);
       
   112         __PBK_PROFILE_END(PbkProfiling::EExtensionScan);
       
   113 
       
   114         __PBK_PROFILE_START(PbkProfiling::EMultiFactoryConstruct);
       
   115 		iMultiFactory = CPbkMultiExtensionFactory::NewL();
       
   116 
       
   117 		const TInt count = iExtensions.Count();
       
   118 		for (TInt i=0; i<count; ++i)
       
   119 			{
       
   120 			iMultiFactory->AppendL(iExtensions.At(i)->ExtensionFactory());
       
   121 			}
       
   122         __PBK_PROFILE_END(PbkProfiling::EMultiFactoryConstruct);
       
   123 		}
       
   124 
       
   125     return *iMultiFactory;
       
   126     }
       
   127 
       
   128 void CPbkExtGlobals::DoRelease()
       
   129     {
       
   130     if (DecRef() == 0)
       
   131         {
       
   132         Dll::SetTls(NULL);
       
   133         delete this;
       
   134         }
       
   135     }
       
   136 
       
   137 // End of File