commands/load/load.cpp
changeset 0 7f656887cf89
child 87 63fd51b1ff80
equal deleted inserted replaced
-1:000000000000 0:7f656887cf89
       
     1 // load.cpp
       
     2 // 
       
     3 // Copyright (c) 2008 - 2010 Accenture. All rights reserved.
       
     4 // This component and the accompanying materials are made available
       
     5 // under the terms of the "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 // Accenture - Initial contribution
       
    11 //
       
    12 
       
    13 #include <fshell/ioutils.h>
       
    14 
       
    15 using namespace IoUtils;
       
    16 
       
    17 
       
    18 class CCmdLoad : public CCommandBase
       
    19 	{
       
    20 public:
       
    21 	static CCommandBase* NewLC();
       
    22 	~CCmdLoad();
       
    23 private:
       
    24 	CCmdLoad();
       
    25 private: // From CCommandBase.
       
    26 	virtual const TDesC& Name() const;
       
    27 	virtual void DoRunL();
       
    28 	virtual void OptionsL(RCommandOptionList& aOptions);
       
    29 	virtual void ArgumentsL(RCommandArgumentList& aArguments);
       
    30 private:
       
    31 	HBufC* iDllName;
       
    32 	RArray<TUint> iUids;
       
    33 	TUint iModuleVersion;
       
    34 	RLibrary iLibrary;
       
    35 	};
       
    36 
       
    37 
       
    38 //
       
    39 // CCmdLoad.
       
    40 //
       
    41 
       
    42 CCommandBase* CCmdLoad::NewLC()
       
    43 	{
       
    44 	CCmdLoad* self = new(ELeave) CCmdLoad();
       
    45 	CleanupStack::PushL(self);
       
    46 	self->BaseConstructL();
       
    47 	return self;
       
    48 	}
       
    49 
       
    50 CCmdLoad::~CCmdLoad()
       
    51 	{
       
    52 	iLibrary.Close();
       
    53 	delete iDllName;
       
    54 	iUids.Close();
       
    55 	}
       
    56 
       
    57 CCmdLoad::CCmdLoad() : CCommandBase(EManualComplete)
       
    58 	{
       
    59 	}
       
    60 
       
    61 const TDesC& CCmdLoad::Name() const
       
    62 	{
       
    63 	_LIT(KName, "load");
       
    64 	return KName;
       
    65 	}
       
    66 
       
    67 void CCmdLoad::DoRunL()
       
    68 	{
       
    69 	if (iUids.Count() > 3)
       
    70 		{
       
    71 		LeaveIfErr(KErrArgument, _L("Too many UIDs specified"));
       
    72 		}
       
    73 
       
    74 	while (iUids.Count() < 3)
       
    75 		{
       
    76 		iUids.AppendL(KNullUid.iUid);
       
    77 		}
       
    78 	TUidType type(TUid::Uid(iUids[0]), TUid::Uid(iUids[1]), TUid::Uid(iUids[2]));
       
    79 
       
    80 	_LIT(KError, "Unable to load \"%S\"");
       
    81 	if (iOptions.IsPresent(&iModuleVersion))
       
    82 		{
       
    83 		LeaveIfErr(iLibrary.Load(*iDllName, KNullDesC, type, iModuleVersion), KError, iDllName);
       
    84 		}
       
    85 	else
       
    86 		{
       
    87 		LeaveIfErr(iLibrary.Load(*iDllName, type), KError, iDllName);
       
    88 		}
       
    89 
       
    90 	TFileName file = iLibrary.FileName();
       
    91 	TUidType uids = iLibrary.Type();
       
    92 	Printf(_L("Loaded %S\r\n"), &file);
       
    93 	Printf(_L("Uids: 0x%x, 0x%x, 0x%x\r\n"), uids[0].iUid, uids[1].iUid, uids[2].iUid);
       
    94 	}
       
    95 
       
    96 void CCmdLoad::OptionsL(RCommandOptionList& aOptions)
       
    97 	{
       
    98 	_LIT(KCmdOptUid, "uid");
       
    99 	aOptions.AppendUintL(iUids, KCmdOptUid);
       
   100 
       
   101 	_LIT(KCmdOptVersion, "version");
       
   102 	aOptions.AppendUintL(iModuleVersion, KCmdOptVersion);
       
   103 	}
       
   104 
       
   105 void CCmdLoad::ArgumentsL(RCommandArgumentList& aArguments)
       
   106 	{
       
   107 	_LIT(KCmdArgFileName, "dll_name");
       
   108 	aArguments.AppendStringL(iDllName, KCmdArgFileName);
       
   109 	}
       
   110 
       
   111 
       
   112 EXE_BOILER_PLATE(CCmdLoad)
       
   113