commands/ecom/ecom.cpp
changeset 0 7f656887cf89
child 73 dc41da2f70a4
equal deleted inserted replaced
-1:000000000000 0:7f656887cf89
       
     1 // ecom.cpp
       
     2 // 
       
     3 // Copyright (c) 2009 - 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/memoryaccesscmd.h>
       
    14 #include <ecom/ecom.h>
       
    15 #include <fshell/ltkutils.h>
       
    16 
       
    17 using namespace IoUtils;
       
    18 
       
    19 class CCmdEcom : public CMemoryAccessCommandBase
       
    20 	{
       
    21 public:
       
    22 	static CCommandBase* NewLC();
       
    23 	~CCmdEcom();
       
    24 private:
       
    25 	CCmdEcom();
       
    26 private: // From CCommandBase.
       
    27 	virtual const TDesC& Name() const;
       
    28 	virtual void DoRunL();
       
    29 	virtual void ArgumentsL(RCommandArgumentList& aArguments);
       
    30 	virtual void OptionsL(RCommandOptionList& aOptions);
       
    31 private:
       
    32 	enum TCmd
       
    33 		{
       
    34 		EList,
       
    35 		ECreate,
       
    36 		};
       
    37 	TCmd iCmd;
       
    38 	TUint iUid;
       
    39 	TBool iVerbose;
       
    40 	};
       
    41 
       
    42 
       
    43 CCommandBase* CCmdEcom::NewLC()
       
    44 	{
       
    45 	CCmdEcom* self = new(ELeave) CCmdEcom();
       
    46 	CleanupStack::PushL(self);
       
    47 	self->BaseConstructL();
       
    48 	return self;
       
    49 	}
       
    50 
       
    51 CCmdEcom::~CCmdEcom()
       
    52 	{
       
    53 	REComSession::FinalClose();
       
    54 	}
       
    55 
       
    56 CCmdEcom::CCmdEcom()
       
    57 	{
       
    58 	}
       
    59 
       
    60 const TDesC& CCmdEcom::Name() const
       
    61 	{
       
    62 	_LIT(KName, "ecom");	
       
    63 	return KName;
       
    64 	}
       
    65 
       
    66 void CCmdEcom::ArgumentsL(RCommandArgumentList& aArguments)
       
    67 	{
       
    68 	aArguments.AppendEnumL((TInt&)iCmd, _L("command"));
       
    69 	aArguments.AppendUintL(iUid, _L("uid"));
       
    70 	}
       
    71 
       
    72 void CCmdEcom::OptionsL(RCommandOptionList& aOptions)
       
    73 	{
       
    74 	aOptions.AppendBoolL(iVerbose, _L("verbose"));
       
    75 	}
       
    76 
       
    77 
       
    78 EXE_BOILER_PLATE(CCmdEcom)
       
    79 
       
    80 void CCmdEcom::DoRunL()
       
    81 	{
       
    82 	TUid uid = TUid::Uid(iUid);
       
    83 	if (iCmd == EList)
       
    84 		{
       
    85 		RImplInfoPtrArray impls;
       
    86 		LtkUtils::CleanupResetAndDestroyPushL(impls);
       
    87 		TRAPL(REComSession::ListImplementationsL(uid, impls), _L("Couldn't ListImplementations for 0x%x"), iUid);
       
    88 		if (impls.Count() == 0)
       
    89 			{
       
    90 			Printf(_L("No implementations found."));
       
    91 			}
       
    92 		else
       
    93 			{
       
    94 			for (TInt i = 0; i < impls.Count(); i++)
       
    95 				{
       
    96 				const CImplementationInformation* info = impls[i];
       
    97 				Printf(_L("0x%x: %S"), info->ImplementationUid(), &info->DisplayName());
       
    98 				TInt version = info->Version();
       
    99 				if (version != 1)
       
   100 					{
       
   101 					Printf(_L(" (v%d)"), version);
       
   102 					}
       
   103 				if (iVerbose)
       
   104 					{
       
   105 					Printf(_L("\r\nRomOnly=%d RomBased=%d Drive=%c Disabled=%d"), info->RomOnly(), info->RomBased(), 'A' + (TInt)info->Drive(), info->Disabled());
       
   106 					if (info->DataType().Length())
       
   107 						{
       
   108 						Printf(_L8("\r\nDataType: %S"), &info->DataType());
       
   109 						}
       
   110 					if (info->OpaqueData().Length())
       
   111 						{
       
   112 						Printf(_L("\r\nOpaqueData:\r\n"));
       
   113 						LtkUtils::HexDumpToOutput(info->OpaqueData(), Stdout());
       
   114 						}
       
   115 					Printf(_L("\r\n"));
       
   116 					}
       
   117 				Printf(_L("\r\n"));
       
   118 				}
       
   119 			}
       
   120 		CleanupStack::PopAndDestroy(&impls);
       
   121 		}
       
   122 	else if (iCmd == ECreate)
       
   123 		{
       
   124 		TUid implKey; // We don't care about this
       
   125 		TAny* impl = NULL;
       
   126 		TRAPL(impl = REComSession::CreateImplementationL(uid, implKey), _L("Couldn't instanciate plugin uid 0x%x"), iUid);
       
   127 		if (impl == NULL) LeaveIfErr(KErrGeneral, _L("Plugin returned NULL implementation pointer!"));
       
   128 		Printf(_L("Instanciated plugin 0x%x ok.\r\n"), iUid);
       
   129 
       
   130 #ifdef FSHELL_MEMORY_ACCESS_SUPPORT
       
   131 		if (iVerbose)
       
   132 			{
       
   133 			LoadMemoryAccessL();
       
   134 			
       
   135 			TAny* vtablePtr = *(TAny**)impl;
       
   136 			TFullName8 dllName;
       
   137 			TInt res = iMemAccess.FindAddressInCodeSegments(dllName, vtablePtr);
       
   138 			if (res < 0)
       
   139 				{
       
   140 				PrintError(res, _L("Couldn't find vtable address in code segments"));
       
   141 				}
       
   142 			else
       
   143 				{
       
   144 				Printf(_L8("Implementation is probably from DLL %S at offset %d.\r\n"), &dllName, res);
       
   145 				}
       
   146 			}
       
   147 #endif
       
   148 
       
   149 		User::Exit(KErrNone); // Don't even try and clean up - the plugin would probably crash if we did
       
   150 		}
       
   151 	}