logsui/AppSrc/CLogsExtensionLoader.cpp
branchRCL_3
changeset 20 f4a778e096c2
parent 0 e686773b3f54
equal deleted inserted replaced
19:5b6f26637ad3 20:f4a778e096c2
       
     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 *       Implementation for extension dll loader.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "CLogsExtensionLoader.h"
       
    22 #include "TLogsDummyExtensionFactory.h"
       
    23 #include "ExtensionUID.h"
       
    24 #include <data_caging_path_literals.hrh>  //KDC_APP_BITMAP_DIR and KDC_SHARED_LIB_DIR
       
    25 #include <featmgr.h>
       
    26 
       
    27 // MODULE DATA STRUCTURES
       
    28 typedef MLogsExtensionFactory* (*TExtensionEntryPoint)();
       
    29 
       
    30 
       
    31 // ================= MEMBER FUNCTIONS =======================
       
    32 inline CLogsExtensionLoader::CLogsExtensionLoader()
       
    33     {
       
    34     }
       
    35 
       
    36 inline void CLogsExtensionLoader::ConstructL()
       
    37     {
       
    38     //Tries to load the extension dll and initialise iFactory to point to the loaded dll
       
    39     TRAPD(err, LoadExtensionDllL());
       
    40     
       
    41     //If dll is not part of rom image then initialise iFactory to point to dummy implementation instead
       
    42     if (err)
       
    43         {    
       
    44         if ( iFactory )
       
    45             {
       
    46             iFactory->Release();
       
    47             iFactory = NULL;
       
    48             }
       
    49         iFactory = TLogsDummyExtensionFactory::NewL();
       
    50         }
       
    51     }
       
    52 
       
    53 CLogsExtensionLoader* CLogsExtensionLoader::NewL()
       
    54     {
       
    55     CLogsExtensionLoader* self = new (ELeave) CLogsExtensionLoader;
       
    56     CleanupStack::PushL(self);
       
    57     self->ConstructL();
       
    58     CleanupStack::Pop(self);
       
    59     return self;
       
    60     }
       
    61 
       
    62 CLogsExtensionLoader::~CLogsExtensionLoader()
       
    63     {      
       
    64     if ( iFactory )
       
    65         {
       
    66         iFactory->Release();
       
    67         iFactory = NULL;
       
    68         }
       
    69     iDll.Close(); // This has to be last 
       
    70     }
       
    71 
       
    72 //Returns refrence to loaded dll's factory functionality or default implementation
       
    73 MLogsExtensionFactory& CLogsExtensionLoader::ExtensionFactory()
       
    74     {    
       
    75     return *iFactory;
       
    76     }
       
    77 
       
    78 TUidType CLogsExtensionLoader::UidType()
       
    79     {
       
    80     return TUidType(KNullUid, TUid::Uid(KExtensionDllUID2), KNullUid);
       
    81     }
       
    82 
       
    83 void CLogsExtensionLoader::LoadExtensionDllL()
       
    84     {
       
    85     // If voip is not supported then don't try to load the
       
    86     // extension dll, leave will cause the dummy extension to be
       
    87     // used instead
       
    88     if ( !FeatureManager::FeatureSupported(KFeatureIdCommonVoip))
       
    89         {
       
    90         User::Leave(KErrNotFound);
       
    91         }        
       
    92     else
       
    93         {
       
    94         // Set up path+filename for extension dll
       
    95         TFileName dllFileWithPath;
       
    96 
       
    97         dllFileWithPath += KDC_SHARED_LIB_DIR;
       
    98         dllFileWithPath += KLogsUiExtensionDllFile;  
       
    99 
       
   100         User::LeaveIfError(iDll.Load(dllFileWithPath, UidType()));  
       
   101     
       
   102         // Get the 1st entry point from the DLL
       
   103         TExtensionEntryPoint createExtensionFactoryL =
       
   104             reinterpret_cast<TExtensionEntryPoint>(iDll.Lookup(1));
       
   105         
       
   106         if (!createExtensionFactoryL)
       
   107             {
       
   108             User::Leave(KErrNotFound);
       
   109             }
       
   110 
       
   111          // Call the entry point to create the test suite
       
   112         iFactory = createExtensionFactoryL();
       
   113         if (!iFactory)
       
   114             {
       
   115             User::Leave(KErrNotFound);
       
   116             }
       
   117         }
       
   118     }
       
   119 
       
   120 // End of File