commands/wslog/wslog.cpp
changeset 0 7f656887cf89
child 96 dae66483be2b
equal deleted inserted replaced
-1:000000000000 0:7f656887cf89
       
     1 // wslog.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/ioutils.h>
       
    14 #include <bautils.h>
       
    15 #include <W32STD.H>
       
    16 #include <fshell/ltkutils.h>
       
    17 
       
    18 using namespace IoUtils;
       
    19 
       
    20 class CCmdWslog : public CCommandBase
       
    21 	{
       
    22 public:
       
    23 	static CCommandBase* NewLC();
       
    24 	~CCmdWslog();
       
    25 private:
       
    26 	CCmdWslog();
       
    27 	void CmdL(const TDesC& aCommand, const TDesC& aArgs);
       
    28 private: // From CCommandBase.
       
    29 	virtual const TDesC& Name() const;
       
    30 	virtual void DoRunL();
       
    31 	virtual void ArgumentsL(RCommandArgumentList& aArguments);
       
    32 	virtual void OptionsL(RCommandOptionList& aOptions);
       
    33 private:
       
    34 	RWsSession iWs;
       
    35 	enum 
       
    36 		{
       
    37 		EStatus,
       
    38 		EEnable,
       
    39 		EDisable,
       
    40 		EMessage,
       
    41 		EDump,
       
    42 		} iOperation;
       
    43 	HBufC* iMessage;
       
    44 	};
       
    45 
       
    46 CCommandBase* CCmdWslog::NewLC()
       
    47 	{
       
    48 	CCmdWslog* self = new(ELeave) CCmdWslog();
       
    49 	CleanupStack::PushL(self);
       
    50 	self->BaseConstructL();
       
    51 	return self;
       
    52 	}
       
    53 
       
    54 CCmdWslog::~CCmdWslog()
       
    55 	{
       
    56 	iWs.Close();
       
    57 	delete iMessage;
       
    58 	}
       
    59 
       
    60 CCmdWslog::CCmdWslog()
       
    61 	{
       
    62 	}
       
    63 
       
    64 const TDesC& CCmdWslog::Name() const
       
    65 	{
       
    66 	_LIT(KName, "wslog");
       
    67 	return KName;
       
    68 	}
       
    69 
       
    70 void CCmdWslog::ArgumentsL(RCommandArgumentList& aArguments)
       
    71 	{
       
    72 	_LIT(KOperation, "operation");
       
    73 	aArguments.AppendEnumL((TInt&)iOperation, KOperation);
       
    74 	_LIT(KMessage, "message");
       
    75 	aArguments.AppendStringL(iMessage, KMessage);
       
    76 	}
       
    77 
       
    78 void CCmdWslog::OptionsL(RCommandOptionList&)
       
    79 	{
       
    80 	}
       
    81 
       
    82 EXE_BOILER_PLATE(CCmdWslog)
       
    83 
       
    84 void CCmdWslog::DoRunL()
       
    85 	{
       
    86 	if (iMessage && iOperation != EMessage)
       
    87 		{
       
    88 		LeaveIfErr(KErrArgument, _L("Message can only be specified if operation is 'message'"));
       
    89 		}
       
    90 	
       
    91 	LeaveIfErr(iWs.Connect(FsL()), _L("Couldn't connect to wserv"));
       
    92 
       
    93 	switch (iOperation)
       
    94 		{
       
    95 		case EEnable:
       
    96 			iWs.LogCommand(RWsSession::ELoggingEnable);
       
    97 			break;
       
    98 		case EDisable:
       
    99 			iWs.LogCommand(RWsSession::ELoggingDisable);
       
   100 			break;
       
   101 		case EMessage:
       
   102 			{
       
   103 			if (!iMessage)
       
   104 				{
       
   105 				LeaveIfErr(KErrArgument, _L("A message must be provided for operation 'message'"));
       
   106 				}
       
   107 			TLogMessageText message = *iMessage;
       
   108 			iWs.LogMessage(message);
       
   109 			}
       
   110 			break;
       
   111 		case EStatus:
       
   112 			{
       
   113 			Printf(_L("LtkUtils::W32CrackIsEnabled reports: %d\r\n"), LtkUtils::W32CrackIsEnabled());
       
   114 
       
   115 			//_LIT(KWsIniFile, "z:\\system\\data\\wsini.ini");
       
   116 			_LIT(KCWsIniFile, "c:\\system\\data\\wsini.ini");
       
   117 
       
   118 			if (BaflUtils::FileExists(FsL(), KCWsIniFile))
       
   119 				{
       
   120 				Printf(_L("C drive wsini log lines:\r\n"));
       
   121 				CmdL(_L("fshell.exe"), _L("-e 'cat c:\\system\\data\\wsini.ini | grep LOG*'"));
       
   122 				}
       
   123 			else
       
   124 				{
       
   125 				Printf(_L("(No C drive wsini)\r\n"));
       
   126 				}
       
   127 			Printf(_L("Z drive wsini log lines:\r\n"));
       
   128 			CmdL(_L("fshell.exe"), _L("-e 'cat z:\\system\\data\\wsini.ini | grep LOG*'"));
       
   129 
       
   130 			Printf(_L("Possible logging DLLs (none means logging probably not enabled):\r\n"));
       
   131 			CmdL(_L("kerninfo.exe"), _L("codeseg -m DLOG*"));
       
   132 			}
       
   133 			break;
       
   134 		case EDump:
       
   135 			//__DEBUGGER();
       
   136 			iWs.LogCommand(RWsSession::ELoggingStatusDump);
       
   137 			break;
       
   138 		};
       
   139 	iWs.Flush();
       
   140 	}
       
   141 
       
   142 void CCmdWslog::CmdL(const TDesC& aCommand, const TDesC& aArgs)
       
   143 	{
       
   144 	RChildProcess proc;
       
   145 	TRequestStatus stat;
       
   146 	proc.CreateL(aCommand, aArgs, IoSession(), Stdin(), Stdout(), Stderr());
       
   147 	proc.Run(stat);
       
   148 
       
   149 	User::WaitForRequest(stat);
       
   150 	proc.Close();
       
   151 	}