sysstatemgmt/systemstatemgr/sus/src/suspluginloader.cpp
changeset 0 4e1aa6a622a0
equal deleted inserted replaced
-1:000000000000 0:4e1aa6a622a0
       
     1 // Copyright (c) 2007-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 //
       
    15 
       
    16 #include <f32file.h>
       
    17 #include <ssm/ssmutility.h>
       
    18 #include <ssm/ssmsuscli.h>
       
    19 #include "suspluginloader.h"
       
    20 #include "suspluginframe.h"
       
    21 #include "ssmdebug.h"
       
    22 #include "suspanic.h"
       
    23 
       
    24 _LIT(KRomDriveLetter, "Z:");
       
    25 
       
    26 /**
       
    27  Loads the specified DLL into an RLibrary. DLL is typechecked and optionally its uid3 can be verified.
       
    28  If the RLibrariy::iHandle was opened pushed onto and left on the CleanupStack.
       
    29  */
       
    30 void SusPluginLoader::LoadDllFileLC(RLibrary& aLibrary, const TSsmSupInfo& aSupInfo)
       
    31 	{
       
    32 	//Enforce that plugins can only be loaded from ROM
       
    33 	TBuf<KMaxFileName + 2> filename = aSupInfo.FileName(); //KMaxFileName + KRomDriveLetter().Length()
       
    34 	if( filename.Left(2).CompareF(KRomDriveLetter) )
       
    35 		{
       
    36 		filename.Insert(0, KRomDriveLetter);
       
    37 		}
       
    38 	
       
    39 	const TUid expectedUid3 = aSupInfo.Identity();
       
    40 	DoLoadDllFileLC(aLibrary, filename, expectedUid3);
       
    41 	}
       
    42 
       
    43 /**
       
    44  */
       
    45 CSusPluginFrame* SusPluginLoader::CreatePluginLC(RLibrary& aLibrary, TInt aNewLOrdinal)
       
    46 	{
       
    47 	
       
    48 	CSusPluginFrame* plugin = SusPluginLoader::DoCreatePluginL(aLibrary, aNewLOrdinal);
       
    49 	CleanupStack::PushL(plugin);
       
    50 #ifdef _DEBUG 
       
    51 	TFileName name = aLibrary.FileName(); 
       
    52 #endif
       
    53 	DEBUGPRINT2(_L("Utility Plugin [%S] loaded."), &name);	
       
    54 	
       
    55 	plugin->InitializeL();
       
    56 	DEBUGPRINT2(_L("Utility Plugin [%S] initialized."), &name);	
       
    57 	
       
    58 	plugin->StartL();
       
    59 	DEBUGPRINT2(_L("Utility Plugin [%S] started."), &name);	
       
    60 	
       
    61 	return plugin;
       
    62 	}
       
    63 
       
    64 /**
       
    65  Load the DLL file from the file system.
       
    66  @leave KErrNotSupported If UID2 of the DLL is not KSsmUtilityPluginDllTypeUid
       
    67  @leave KErrNotFound If the requested policy DLL file is missing.
       
    68  @leave KErrBadName If @c aSupInfo contains an Identity different from UID3 of the DLL.
       
    69  @leave KErrCorrupt Or any other system wide error code that the fileserver can rise.
       
    70  */
       
    71 void SusPluginLoader::DoLoadDllFileLC(RLibrary& aLibrary, const TDesC& aFileName, TUid aExpectedUid3)
       
    72 	{
       
    73 	const TInt fileErr = aLibrary.Load(aFileName);
       
    74 	CleanupClosePushL(aLibrary);
       
    75 	
       
    76 	//Leave if we couldn't open aLibrary
       
    77 	if (fileErr != KErrNone)
       
    78 		{
       
    79 		DEBUGPRINT3(_L("Failed to load utility plugin DLL named %S, file error: %d"), &aFileName, fileErr);
       
    80 		User::Leave(fileErr);
       
    81 		}
       
    82 	
       
    83 	//Check that the DLL is the SUP type
       
    84 	if (aLibrary.Type()[1] != KSsmUtilityPluginDllTypeUid)
       
    85 		{
       
    86 		DEBUGPRINT4(_L("Wrong type (uid2) in the utility plugin DLL %S. Expected %x found %x"), 
       
    87 				&aFileName, KSsmUtilityPluginDllTypeUid, aLibrary.Type()[1]);;
       
    88 		User::Leave(KErrNotSupported);
       
    89 		}
       
    90 	
       
    91 	//If we were given a identity, check that the loaded file conforms
       
    92 	if ( (aExpectedUid3 != KNullUid) && (aExpectedUid3 != aLibrary.Type()[2]) )
       
    93 		{
       
    94 		DEBUGPRINT4(_L("Wrong identity (uid3) in the utility plugin DLL %S. Expected %x found %x"), 
       
    95 				&aFileName, aExpectedUid3, aLibrary.Type()[2]);
       
    96 		User::Leave(KErrBadName);
       
    97 		}
       
    98 	} //lint !e1746 suppress parameter 'aExpectedUid3' could be made const reference
       
    99 
       
   100 /**
       
   101  */
       
   102 CSusPluginFrame* SusPluginLoader::DoCreatePluginL(const RLibrary& aLibrary, TInt aNewLOrdinal)
       
   103 	{
       
   104 	__ASSERT_DEBUG(KNullHandle != aLibrary.Handle(), User::Panic(KPanicSsmSus, EPluginLoaderError1));
       
   105 	
       
   106 	CSusPluginFrame* frame = NULL;
       
   107 	TRAPD(err, frame = CSusPluginFrame::NewL(aLibrary.Lookup(aNewLOrdinal), aNewLOrdinal));
       
   108 #ifdef _DEBUG
       
   109 	if(KErrNone != err)
       
   110 		{
       
   111 		TFileName name = aLibrary.FileName();
       
   112 		DEBUGPRINT4(_L("Specified ordinal function (%d) in DLL %S didn't create a new instance, err=%d."), aNewLOrdinal, &name, err);
       
   113 		}
       
   114 #endif	
       
   115 	SSMLOGLEAVEIFERROR(err);
       
   116 	return frame;
       
   117 	}
       
   118