os/persistentdata/traceservices/tracefw/ulogger/src/command/uloggercommands.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/persistentdata/traceservices/tracefw/ulogger/src/command/uloggercommands.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,215 @@
     1.4 +// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// ULogger commands
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +/**
    1.22 + @file
    1.23 + @internalTechnology
    1.24 + @prototype
    1.25 +*/
    1.26 +
    1.27 +#include "uloggercommands.h"
    1.28 +#include "uloggershared.h"
    1.29 +using namespace Ulogger;
    1.30 +
    1.31 +CCommand::CCommand(MCommandImpl* aCommandImpl)
    1.32 +: iCommandImpl(aCommandImpl)
    1.33 +	{
    1.34 +	}
    1.35 +
    1.36 +EXPORT_C CCommand::~CCommand()
    1.37 +	{
    1.38 +	iCommandsLookup.Close();
    1.39 +	}
    1.40 +
    1.41 +EXPORT_C CCommand* CCommand::NewL(MCommandImpl* aCommandImpl)
    1.42 +	{
    1.43 +	CCommand* obj = CCommand::NewLC(aCommandImpl);
    1.44 +	CleanupStack::Pop( obj );
    1.45 +	return obj;
    1.46 +	}
    1.47 +
    1.48 +EXPORT_C CCommand* CCommand::NewLC(MCommandImpl* aCommandImpl)
    1.49 +	{
    1.50 +	CCommand* obj = new (ELeave) CCommand(aCommandImpl);
    1.51 +	CleanupStack::PushL( obj );
    1.52 +	obj->ConstructL();
    1.53 +	return obj;
    1.54 +	}
    1.55 +
    1.56 +EXPORT_C void CCommand::ConstructL()
    1.57 +	{
    1.58 +	iVerbose = EFalse;
    1.59 +	
    1.60 +	//fill the lookup table
    1.61 +	//two command matters
    1.62 +	iCommandsLookup.Append( TCommandLookup(&KCmdEnable, &KCmdPrimaryFilter, ESetPrimaryFilter) ); // -ef 
    1.63 +	iCommandsLookup.Append( TCommandLookup(&KCmdEnable, &KCmdSecondaryFilter, ESetSecondaryFilter) ); // -es 
    1.64 +	iCommandsLookup.Append( TCommandLookup(&KCmdEnable, &KCmdSecondaryFilterToggle, EEnableSecondaryFiltering) ); // -eS 
    1.65 +	iCommandsLookup.Append( TCommandLookup(&KCmdDisable, &KCmdSecondaryFilterToggle, EDisableSecondaryFiltering) ); // -dS 
    1.66 +	iCommandsLookup.Append( TCommandLookup(&KCmdDisable, &KCmdPluginConfigurations, ERemovePluginSettings) ); // -dc 
    1.67 +	iCommandsLookup.Append( TCommandLookup(&KCmdList, &KCmdOutputPlugin, EGetInstalledPlugins) ); // -lo 
    1.68 +	iCommandsLookup.Append( TCommandLookup(&KCmdList, &KCmdPluginConfigurations, EGetPluginSettings) ); // -lc 
    1.69 +	iCommandsLookup.Append( TCommandLookup(&KCmdList, &KCmdPrimaryFilter, EGetPrimaryFilters) ); // -lf 
    1.70 +	iCommandsLookup.Append( TCommandLookup(&KCmdList, &KCmdSecondaryFilter, EGetSecondaryFilters) ); // -ls 
    1.71 +	iCommandsLookup.Append( TCommandLookup(&KCmdList, &KCmdSecondaryFilterToggle, EGetSecondaryFiltering) ); // -lS 
    1.72 +	iCommandsLookup.Append( TCommandLookup(&KCmdEnable, &KCmdBuffer, EResizeTraceBuffer) ); // -eb 
    1.73 +	iCommandsLookup.Append( TCommandLookup(&KCmdList, &KCmdBuffer, EGetTraceBufferSize) ); // -lb 
    1.74 +	iCommandsLookup.Append( TCommandLookup(&KCmdEnable, &KCmdBufferMode, ESetBufferMode) ); // -em
    1.75 +	iCommandsLookup.Append( TCommandLookup(&KCmdList, &KCmdBufferMode, EGetBufferMode) ); // -lm 
    1.76 +	iCommandsLookup.Append( TCommandLookup(&KCmdEnable, &KCmdNotification, ESetDataNotificationSize) );// -en
    1.77 +	iCommandsLookup.Append( TCommandLookup(&KCmdList, &KCmdNotification, EGetDataNotificationSize) ); // -ln 
    1.78 +	iCommandsLookup.Append( TCommandLookup(&KCmdDisable, &KCmdPrimaryFilter, ERemovePrimaryFilter) ); // -df 
    1.79 +	iCommandsLookup.Append( TCommandLookup(&KCmdDisable, &KCmdSecondaryFilter, ERemoveSecondaryFilter) ); // -ds 
    1.80 +	iCommandsLookup.Append( TCommandLookup(&KCmdEnable, &KCmdPluginConfigurations, ESetPluginSettings) ); // -ec 
    1.81 +	iCommandsLookup.Append( TCommandLookup(&KCmdEnable, &KCmdOutputPlugin, ESetActivePlugin) ); // -eo 
    1.82 +	iCommandsLookup.Append( TCommandLookup(&KCmdEnable, &KCmdInputPlugin, ESetActiveInputPlugin) ); // -ei 
    1.83 +	iCommandsLookup.Append( TCommandLookup(&KCmdDisable, &KCmdInputPlugin, EDeactivateInputPlugin) ); // -di 
    1.84 +	iCommandsLookup.Append( TCommandLookup(&KCmdList, &KCmdInputPlugin, EGetInputPlugins) ); // -li 
    1.85 +	//only main command matters
    1.86 +	iCommandsLookup.Append( TCommandLookup(&KCmdStart, &KNullDesC, EStart) ); // -r 
    1.87 +	iCommandsLookup.Append( TCommandLookup(&KCmdStop, &KNullDesC, EStop) ); // -q 
    1.88 +	iCommandsLookup.Append( TCommandLookup(&KCmdRestart, &KNullDesC, ERestart) ); // -t   	
    1.89 +	iCommandsLookup.Append( TCommandLookup(&KCmdOutputPlugin, &KNullDesC, EGetActivePlugin) ); // -o 
    1.90 +	iCommandsLookup.Append( TCommandLookup(&KCmdInputPlugin, &KNullDesC, EGetActiveInputPlugin) ); // -i 
    1.91 +	iCommandsLookup.Append( TCommandLookup(&KCmdHelp, &KNullDesC, EHelp) ); // -h 
    1.92 +	iCommandsLookup.Append( TCommandLookup(&KCmdMan, &KNullDesC, EManPage) ); // -H 
    1.93 +	iCommandsLookup.Append( TCommandLookup(&KCmdVersion, &KNullDesC, EVersion) ); // -version 
    1.94 +	
    1.95 +	}
    1.96 +
    1.97 +/**
    1.98 +This function parses commands given as a parameter and generates TCommand value.
    1.99 +The function is responsible also for triggering event for MCommandImpl
   1.100 +
   1.101 +@param aArgs array of arguments to parse
   1.102 +@return KErrNone if commands were parsed successfully and event was triggered, system wide error code otherwise
   1.103 + */
   1.104 +EXPORT_C TInt CCommand::HandleCommandL(const RArray<TPtrC>& aArgs)
   1.105 +	{	
   1.106 +	TBool optionsConsumed = EFalse;
   1.107 +	RArray<TPtrC> commands;
   1.108 +	CleanupClosePushL( commands );
   1.109 +	RBuf command;
   1.110 +	CleanupClosePushL(command);
   1.111 +	TInt maxSize=2;
   1.112 +	for(TInt k=0; k<aArgs.Count(); ++k) //calculate max command length
   1.113 +		maxSize += aArgs[k].Length();
   1.114 +	User::LeaveIfError(command.Create(maxSize));
   1.115 +	
   1.116 +	for(TInt i=0; i<aArgs.Count(); ++i)
   1.117 +		{
   1.118 +		TPtrC argPtr(aArgs[i]);
   1.119 +		
   1.120 +		//the 'version' command is the special case
   1.121 +		if(!argPtr.Mid(1).Compare(KCmdVersion))
   1.122 +			{
   1.123 +			TPtrC ptr(argPtr.Mid(1));
   1.124 +			commands.AppendL(ptr);
   1.125 +			continue;
   1.126 +			}
   1.127 +		
   1.128 +		//check if we have to parse combined commands (like -ca)
   1.129 +		//other arguments are added to new array for further processing
   1.130 +		TBuf<1> cmdChecker;
   1.131 +		cmdChecker.Copy( argPtr.Mid(0,1) );
   1.132 +		if(!cmdChecker.Compare(KCmdIndicator) && !optionsConsumed)
   1.133 +			{			
   1.134 +			//if there is option 'v' (verbose), this option shoul be removed
   1.135 +			//desc:
   1.136 +			//command data format: 'command param1 param2 paramN'
   1.137 +			//where:
   1.138 +			//command: ia string with commands letters, for example: 'lf', 'esv'
   1.139 +			//paramN: is parameter string, for example 'uloggerserialplugin'
   1.140 +			//array example: 'ec uloggerserialplugin output_port 3'
   1.141 +			
   1.142 +			for(TInt k=1; k<argPtr.Length(); ++k)
   1.143 +				{
   1.144 +				TPtrC ptr(argPtr.Mid(k,1));
   1.145 +				if(!ptr.Compare(KCmdVerboseMode))
   1.146 +					iVerbose = ETrue;
   1.147 +				else
   1.148 +					command.AppendFormat(_L("%S"), &ptr);
   1.149 +				}
   1.150 +			//put command as a first element in array
   1.151 +			if(commands.Count() > 0)
   1.152 +				{
   1.153 +				commands.Remove(0);
   1.154 +				User::LeaveIfError(commands.Insert(command, 0));
   1.155 +				}
   1.156 +			else
   1.157 +				commands.AppendL(command);
   1.158 +			
   1.159 +			
   1.160 +			optionsConsumed = ETrue;
   1.161 +			}
   1.162 +		else
   1.163 +			commands.AppendL(argPtr);
   1.164 +		}
   1.165 +	
   1.166 +	TInt errCode = PrepareCommandL( commands );	
   1.167 +	CleanupStack::PopAndDestroy(2); //command, commands
   1.168 +	return errCode;
   1.169 +	}
   1.170 +
   1.171 +
   1.172 +/** This method uses lookup table to translate user readable commands into TCommand value.
   1.173 +@param aArgs Array of arguments.
   1.174 +@return KErrNone if command was preapared correctly and system wide error code otherwise
   1.175 + */
   1.176 +TInt CCommand::PrepareCommandL(RArray<TPtrC>& aArgs)
   1.177 +	{
   1.178 +	TInt i;
   1.179 +	TInt lookupArraySize = iCommandsLookup.Count();
   1.180 +	
   1.181 +	if(aArgs.Count() == 0)
   1.182 +		return iCommandImpl->DoCommandL(EUnknown, aArgs);
   1.183 +	
   1.184 +	//first elements contains command letters
   1.185 +	TPtrC cmd(aArgs[0]);
   1.186 +	if(cmd.Length() <= KMaxNumberOfLettersInCommand) //we want precise command 
   1.187 +		{
   1.188 +		//check two arguments - 1st pass
   1.189 +		for(i=0; i<lookupArraySize; ++i)
   1.190 +			{
   1.191 +			if(cmd.Length() == 2) 
   1.192 +				if(!iCommandsLookup[i].iMainCommand->Compare(cmd.Mid(0,1)))
   1.193 +					if(!iCommandsLookup[i].iSubCommand->Compare(cmd.Mid(1,1)))
   1.194 +						{
   1.195 +						aArgs.Remove(0);
   1.196 +						return iCommandImpl->DoCommandL(iCommandsLookup[i].iCommand, aArgs);
   1.197 +						}
   1.198 +			}
   1.199 +
   1.200 +		//check two arguments - 2nd pass
   1.201 +		for(i=0; i<lookupArraySize; ++i)
   1.202 +			{
   1.203 +			//check one argument
   1.204 +			if(cmd.Length() == 1) 
   1.205 +				if(!iCommandsLookup[i].iMainCommand->Compare(cmd.Mid(0,1)))
   1.206 +					{
   1.207 +					//make sure that none of the 'two letters commands' will not be called
   1.208 +					if(iCommandsLookup[i].iSubCommand->Compare(KNullDesC))
   1.209 +						continue;
   1.210 +					aArgs.Remove(0);
   1.211 +					return iCommandImpl->DoCommandL(iCommandsLookup[i].iCommand, aArgs);
   1.212 +					}
   1.213 +			}
   1.214 +		}
   1.215 +	
   1.216 +	return iCommandImpl->DoCommandL(EUnknown, aArgs);
   1.217 +	}
   1.218 +