sl@0: // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // ULogger commands sl@0: // sl@0: // sl@0: sl@0: /** sl@0: @file sl@0: @internalTechnology sl@0: @prototype sl@0: */ sl@0: sl@0: #include "uloggercommands.h" sl@0: #include "uloggershared.h" sl@0: using namespace Ulogger; sl@0: sl@0: CCommand::CCommand(MCommandImpl* aCommandImpl) sl@0: : iCommandImpl(aCommandImpl) sl@0: { sl@0: } sl@0: sl@0: EXPORT_C CCommand::~CCommand() sl@0: { sl@0: iCommandsLookup.Close(); sl@0: } sl@0: sl@0: EXPORT_C CCommand* CCommand::NewL(MCommandImpl* aCommandImpl) sl@0: { sl@0: CCommand* obj = CCommand::NewLC(aCommandImpl); sl@0: CleanupStack::Pop( obj ); sl@0: return obj; sl@0: } sl@0: sl@0: EXPORT_C CCommand* CCommand::NewLC(MCommandImpl* aCommandImpl) sl@0: { sl@0: CCommand* obj = new (ELeave) CCommand(aCommandImpl); sl@0: CleanupStack::PushL( obj ); sl@0: obj->ConstructL(); sl@0: return obj; sl@0: } sl@0: sl@0: EXPORT_C void CCommand::ConstructL() sl@0: { sl@0: iVerbose = EFalse; sl@0: sl@0: //fill the lookup table sl@0: //two command matters sl@0: iCommandsLookup.Append( TCommandLookup(&KCmdEnable, &KCmdPrimaryFilter, ESetPrimaryFilter) ); // -ef sl@0: iCommandsLookup.Append( TCommandLookup(&KCmdEnable, &KCmdSecondaryFilter, ESetSecondaryFilter) ); // -es sl@0: iCommandsLookup.Append( TCommandLookup(&KCmdEnable, &KCmdSecondaryFilterToggle, EEnableSecondaryFiltering) ); // -eS sl@0: iCommandsLookup.Append( TCommandLookup(&KCmdDisable, &KCmdSecondaryFilterToggle, EDisableSecondaryFiltering) ); // -dS sl@0: iCommandsLookup.Append( TCommandLookup(&KCmdDisable, &KCmdPluginConfigurations, ERemovePluginSettings) ); // -dc sl@0: iCommandsLookup.Append( TCommandLookup(&KCmdList, &KCmdOutputPlugin, EGetInstalledPlugins) ); // -lo sl@0: iCommandsLookup.Append( TCommandLookup(&KCmdList, &KCmdPluginConfigurations, EGetPluginSettings) ); // -lc sl@0: iCommandsLookup.Append( TCommandLookup(&KCmdList, &KCmdPrimaryFilter, EGetPrimaryFilters) ); // -lf sl@0: iCommandsLookup.Append( TCommandLookup(&KCmdList, &KCmdSecondaryFilter, EGetSecondaryFilters) ); // -ls sl@0: iCommandsLookup.Append( TCommandLookup(&KCmdList, &KCmdSecondaryFilterToggle, EGetSecondaryFiltering) ); // -lS sl@0: iCommandsLookup.Append( TCommandLookup(&KCmdEnable, &KCmdBuffer, EResizeTraceBuffer) ); // -eb sl@0: iCommandsLookup.Append( TCommandLookup(&KCmdList, &KCmdBuffer, EGetTraceBufferSize) ); // -lb sl@0: iCommandsLookup.Append( TCommandLookup(&KCmdEnable, &KCmdBufferMode, ESetBufferMode) ); // -em sl@0: iCommandsLookup.Append( TCommandLookup(&KCmdList, &KCmdBufferMode, EGetBufferMode) ); // -lm sl@0: iCommandsLookup.Append( TCommandLookup(&KCmdEnable, &KCmdNotification, ESetDataNotificationSize) );// -en sl@0: iCommandsLookup.Append( TCommandLookup(&KCmdList, &KCmdNotification, EGetDataNotificationSize) ); // -ln sl@0: iCommandsLookup.Append( TCommandLookup(&KCmdDisable, &KCmdPrimaryFilter, ERemovePrimaryFilter) ); // -df sl@0: iCommandsLookup.Append( TCommandLookup(&KCmdDisable, &KCmdSecondaryFilter, ERemoveSecondaryFilter) ); // -ds sl@0: iCommandsLookup.Append( TCommandLookup(&KCmdEnable, &KCmdPluginConfigurations, ESetPluginSettings) ); // -ec sl@0: iCommandsLookup.Append( TCommandLookup(&KCmdEnable, &KCmdOutputPlugin, ESetActivePlugin) ); // -eo sl@0: iCommandsLookup.Append( TCommandLookup(&KCmdEnable, &KCmdInputPlugin, ESetActiveInputPlugin) ); // -ei sl@0: iCommandsLookup.Append( TCommandLookup(&KCmdDisable, &KCmdInputPlugin, EDeactivateInputPlugin) ); // -di sl@0: iCommandsLookup.Append( TCommandLookup(&KCmdList, &KCmdInputPlugin, EGetInputPlugins) ); // -li sl@0: //only main command matters sl@0: iCommandsLookup.Append( TCommandLookup(&KCmdStart, &KNullDesC, EStart) ); // -r sl@0: iCommandsLookup.Append( TCommandLookup(&KCmdStop, &KNullDesC, EStop) ); // -q sl@0: iCommandsLookup.Append( TCommandLookup(&KCmdRestart, &KNullDesC, ERestart) ); // -t sl@0: iCommandsLookup.Append( TCommandLookup(&KCmdOutputPlugin, &KNullDesC, EGetActivePlugin) ); // -o sl@0: iCommandsLookup.Append( TCommandLookup(&KCmdInputPlugin, &KNullDesC, EGetActiveInputPlugin) ); // -i sl@0: iCommandsLookup.Append( TCommandLookup(&KCmdHelp, &KNullDesC, EHelp) ); // -h sl@0: iCommandsLookup.Append( TCommandLookup(&KCmdMan, &KNullDesC, EManPage) ); // -H sl@0: iCommandsLookup.Append( TCommandLookup(&KCmdVersion, &KNullDesC, EVersion) ); // -version sl@0: sl@0: } sl@0: sl@0: /** sl@0: This function parses commands given as a parameter and generates TCommand value. sl@0: The function is responsible also for triggering event for MCommandImpl sl@0: sl@0: @param aArgs array of arguments to parse sl@0: @return KErrNone if commands were parsed successfully and event was triggered, system wide error code otherwise sl@0: */ sl@0: EXPORT_C TInt CCommand::HandleCommandL(const RArray& aArgs) sl@0: { sl@0: TBool optionsConsumed = EFalse; sl@0: RArray commands; sl@0: CleanupClosePushL( commands ); sl@0: RBuf command; sl@0: CleanupClosePushL(command); sl@0: TInt maxSize=2; sl@0: for(TInt k=0; k cmdChecker; sl@0: cmdChecker.Copy( argPtr.Mid(0,1) ); sl@0: if(!cmdChecker.Compare(KCmdIndicator) && !optionsConsumed) sl@0: { sl@0: //if there is option 'v' (verbose), this option shoul be removed sl@0: //desc: sl@0: //command data format: 'command param1 param2 paramN' sl@0: //where: sl@0: //command: ia string with commands letters, for example: 'lf', 'esv' sl@0: //paramN: is parameter string, for example 'uloggerserialplugin' sl@0: //array example: 'ec uloggerserialplugin output_port 3' sl@0: sl@0: for(TInt k=1; k 0) sl@0: { sl@0: commands.Remove(0); sl@0: User::LeaveIfError(commands.Insert(command, 0)); sl@0: } sl@0: else sl@0: commands.AppendL(command); sl@0: sl@0: sl@0: optionsConsumed = ETrue; sl@0: } sl@0: else sl@0: commands.AppendL(argPtr); sl@0: } sl@0: sl@0: TInt errCode = PrepareCommandL( commands ); sl@0: CleanupStack::PopAndDestroy(2); //command, commands sl@0: return errCode; sl@0: } sl@0: sl@0: sl@0: /** This method uses lookup table to translate user readable commands into TCommand value. sl@0: @param aArgs Array of arguments. sl@0: @return KErrNone if command was preapared correctly and system wide error code otherwise sl@0: */ sl@0: TInt CCommand::PrepareCommandL(RArray& aArgs) sl@0: { sl@0: TInt i; sl@0: TInt lookupArraySize = iCommandsLookup.Count(); sl@0: sl@0: if(aArgs.Count() == 0) sl@0: return iCommandImpl->DoCommandL(EUnknown, aArgs); sl@0: sl@0: //first elements contains command letters sl@0: TPtrC cmd(aArgs[0]); sl@0: if(cmd.Length() <= KMaxNumberOfLettersInCommand) //we want precise command sl@0: { sl@0: //check two arguments - 1st pass sl@0: for(i=0; iCompare(cmd.Mid(0,1))) sl@0: if(!iCommandsLookup[i].iSubCommand->Compare(cmd.Mid(1,1))) sl@0: { sl@0: aArgs.Remove(0); sl@0: return iCommandImpl->DoCommandL(iCommandsLookup[i].iCommand, aArgs); sl@0: } sl@0: } sl@0: sl@0: //check two arguments - 2nd pass sl@0: for(i=0; iCompare(cmd.Mid(0,1))) sl@0: { sl@0: //make sure that none of the 'two letters commands' will not be called sl@0: if(iCommandsLookup[i].iSubCommand->Compare(KNullDesC)) sl@0: continue; sl@0: aArgs.Remove(0); sl@0: return iCommandImpl->DoCommandL(iCommandsLookup[i].iCommand, aArgs); sl@0: } sl@0: } sl@0: } sl@0: sl@0: return iCommandImpl->DoCommandL(EUnknown, aArgs); sl@0: } sl@0: