resourcemgmt/hwresourcesmgr/common/src/hwrmuipluginresolver.cpp
changeset 0 4e1aa6a622a0
equal deleted inserted replaced
-1:000000000000 0:4e1aa6a622a0
       
     1 // Copyright (c) 2006-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 // trpdispatchresolver.cpp
       
    15 // Implementation of class CHwrmUiPluginResolver. It encapsulates the logic to select which TRP ECOM plugin to load.
       
    16 // 
       
    17 //
       
    18 
       
    19 /**
       
    20  @file
       
    21 */
       
    22 
       
    23 #include "hwrmuipluginresolver.h"
       
    24 #include <ecom/ecom.h>
       
    25 #include <utf.h>
       
    26 #include "inifile.h"
       
    27 #include "HWRMtrace.h"
       
    28 
       
    29 _LIT(KTestFile,"testuiplugins.ini");
       
    30 
       
    31 /**
       
    32 Factory function. Leaves instantiated object on cleanup stack.
       
    33 */
       
    34 EXPORT_C CHwrmUiPluginResolver* CHwrmUiPluginResolver::NewLC()
       
    35 	{
       
    36 	COMPONENT_TRACE1(_L("CHwrmUiPluginResolver::NewLC"));
       
    37 	CHwrmUiPluginResolver* self = new (ELeave) CHwrmUiPluginResolver();
       
    38 	CleanupStack::PushL(self);
       
    39 	self->ConstructL();
       
    40 	COMPONENT_TRACE1(_L("CHwrmUiPluginResolver::NewLC - return"));
       
    41 	return self;
       
    42 	}
       
    43 
       
    44 /**
       
    45 Factory function.
       
    46 */
       
    47 EXPORT_C CHwrmUiPluginResolver* CHwrmUiPluginResolver::NewL()
       
    48 	{
       
    49 	COMPONENT_TRACE1(_L("CHwrmUiPluginResolver::NewL"));
       
    50 	CHwrmUiPluginResolver* self = NewLC();
       
    51 	CleanupStack::Pop(self);
       
    52 	COMPONENT_TRACE1(_L("CHwrmUiPluginResolver::NewL - return"));
       
    53 	return self;
       
    54 	}
       
    55 
       
    56 /**
       
    57 First-phase constructor.
       
    58 */
       
    59 CHwrmUiPluginResolver::CHwrmUiPluginResolver()
       
    60 	{
       
    61 	}
       
    62 
       
    63 /**
       
    64 Second-phase constructor.
       
    65 */		
       
    66 void CHwrmUiPluginResolver::ConstructL()
       
    67 	{
       
    68 	COMPONENT_TRACE1(_L("CHwrmUiPluginResolver::ConstructL"));
       
    69 	User::LeaveIfError(iFs.Connect());
       
    70 	COMPONENT_TRACE1(_L("CHwrmUiPluginResolver::ConstructL - return"));
       
    71 	}
       
    72 
       
    73 /**
       
    74 Destructor.
       
    75 */	
       
    76 EXPORT_C CHwrmUiPluginResolver::~CHwrmUiPluginResolver()
       
    77 	{
       
    78 	COMPONENT_TRACE1(_L("CHwrmUiPluginResolver::~CHwrmUiPluginResolver"));
       
    79 	
       
    80 	iFs.Close();
       
    81 	
       
    82 	COMPONENT_TRACE1(_L("CHwrmUiPluginResolver::~CHwrmUiPluginResolver - return"));
       
    83 	}
       
    84 
       
    85 EXPORT_C TInt CHwrmUiPluginResolver::GetDesiredPluginL(TUid& aImplUid)
       
    86 	{
       
    87 	COMPONENT_TRACE1(_L("CHwrmUiPluginResolver::GetDesiredPlugin"));
       
    88 	TFileName fullFilePath;
       
    89 	GetTestFilePath(fullFilePath);
       
    90 	
       
    91 	if (IsTestFilePresent(fullFilePath) == EFalse)
       
    92 		{
       
    93 		return KErrNotFound;
       
    94 		}
       
    95 
       
    96 	CIniFile* iniFile = NULL;
       
    97 	TRAPD(err, iniFile = CIniFile::NewL(KTestFile,fullFilePath));
       
    98 	if (err != KErrNone)
       
    99 		{
       
   100 		return KErrNotFound;
       
   101 		}
       
   102 
       
   103 	TFileName exeFileName = RProcess().FileName();
       
   104 	TParsePtrC parser(exeFileName);
       
   105 	exeFileName = parser.Name();
       
   106 		
       
   107 	COMPONENT_TRACE4(_L("Searching for %S in config file in %S%S"),&exeFileName,&fullFilePath,&KTestFile);
       
   108 		
       
   109 	TPtrC16 dataPtr;
       
   110 	_LIT(KUiPluginSection,"Plugin");
       
   111 	TBool found = iniFile->FindVar(KUiPluginSection,exeFileName,dataPtr);
       
   112 	if (found)
       
   113 		{
       
   114 		TLex lex(dataPtr);
       
   115 		TInt uidInt;
       
   116 		lex.Val(uidInt);
       
   117 		aImplUid = TUid::Uid(uidInt);
       
   118 		}
       
   119 
       
   120 	delete iniFile;
       
   121 	
       
   122 	COMPONENT_TRACE1(_L("CHwrmUiPluginResolver::GetDesiredPluginDataL - return"));
       
   123 	return found ? KErrNone : KErrNotFound;
       
   124 	}
       
   125 
       
   126 void CHwrmUiPluginResolver::GetTestFilePath(TDes& aFilePath)
       
   127 	{
       
   128 	COMPONENT_TRACE1(_L("CHwrmUiPluginResolver::GetTestFilePath"));
       
   129 	_LIT(KTestDataPath,"z:\\testdata\\");
       
   130 	aFilePath.Copy(KTestDataPath);
       
   131 	COMPONENT_TRACE1(_L("CHwrmUiPluginResolver::GetTestFilePath - present"));
       
   132 	}
       
   133 
       
   134 /**
       
   135 Checks for the presence of the file that indicates that this is a test run.
       
   136 
       
   137 @return ETrue if test file present. EFalse otherwise.
       
   138 */	
       
   139 TBool CHwrmUiPluginResolver::IsTestFilePresent(const TDesC& aFilePath)
       
   140 	{
       
   141 	COMPONENT_TRACE1(_L("CHwrmUiPluginResolver::IsTestFilePresent"));
       
   142 	COMPONENT_TRACE2(_L("Searching for test file in %S"),&aFilePath);
       
   143 
       
   144 	TFindFile finder(iFs);	
       
   145 	TInt err = finder.FindByPath(KTestFile,&aFilePath);
       
   146 	
       
   147 	COMPONENT_TRACE1(_L("CHwrmUiPluginResolver::IsTestFilePresent - return"));
       
   148 	return (err == KErrNone);	
       
   149 	}