sl@0
|
1 |
// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
// ULogger commands
|
sl@0
|
15 |
//
|
sl@0
|
16 |
//
|
sl@0
|
17 |
|
sl@0
|
18 |
/**
|
sl@0
|
19 |
@file
|
sl@0
|
20 |
@internalTechnology
|
sl@0
|
21 |
@prototype
|
sl@0
|
22 |
*/
|
sl@0
|
23 |
|
sl@0
|
24 |
#include "uloggercommands.h"
|
sl@0
|
25 |
#include "uloggershared.h"
|
sl@0
|
26 |
using namespace Ulogger;
|
sl@0
|
27 |
|
sl@0
|
28 |
CCommand::CCommand(MCommandImpl* aCommandImpl)
|
sl@0
|
29 |
: iCommandImpl(aCommandImpl)
|
sl@0
|
30 |
{
|
sl@0
|
31 |
}
|
sl@0
|
32 |
|
sl@0
|
33 |
EXPORT_C CCommand::~CCommand()
|
sl@0
|
34 |
{
|
sl@0
|
35 |
iCommandsLookup.Close();
|
sl@0
|
36 |
}
|
sl@0
|
37 |
|
sl@0
|
38 |
EXPORT_C CCommand* CCommand::NewL(MCommandImpl* aCommandImpl)
|
sl@0
|
39 |
{
|
sl@0
|
40 |
CCommand* obj = CCommand::NewLC(aCommandImpl);
|
sl@0
|
41 |
CleanupStack::Pop( obj );
|
sl@0
|
42 |
return obj;
|
sl@0
|
43 |
}
|
sl@0
|
44 |
|
sl@0
|
45 |
EXPORT_C CCommand* CCommand::NewLC(MCommandImpl* aCommandImpl)
|
sl@0
|
46 |
{
|
sl@0
|
47 |
CCommand* obj = new (ELeave) CCommand(aCommandImpl);
|
sl@0
|
48 |
CleanupStack::PushL( obj );
|
sl@0
|
49 |
obj->ConstructL();
|
sl@0
|
50 |
return obj;
|
sl@0
|
51 |
}
|
sl@0
|
52 |
|
sl@0
|
53 |
EXPORT_C void CCommand::ConstructL()
|
sl@0
|
54 |
{
|
sl@0
|
55 |
iVerbose = EFalse;
|
sl@0
|
56 |
|
sl@0
|
57 |
//fill the lookup table
|
sl@0
|
58 |
//two command matters
|
sl@0
|
59 |
iCommandsLookup.Append( TCommandLookup(&KCmdEnable, &KCmdPrimaryFilter, ESetPrimaryFilter) ); // -ef
|
sl@0
|
60 |
iCommandsLookup.Append( TCommandLookup(&KCmdEnable, &KCmdSecondaryFilter, ESetSecondaryFilter) ); // -es
|
sl@0
|
61 |
iCommandsLookup.Append( TCommandLookup(&KCmdEnable, &KCmdSecondaryFilterToggle, EEnableSecondaryFiltering) ); // -eS
|
sl@0
|
62 |
iCommandsLookup.Append( TCommandLookup(&KCmdDisable, &KCmdSecondaryFilterToggle, EDisableSecondaryFiltering) ); // -dS
|
sl@0
|
63 |
iCommandsLookup.Append( TCommandLookup(&KCmdDisable, &KCmdPluginConfigurations, ERemovePluginSettings) ); // -dc
|
sl@0
|
64 |
iCommandsLookup.Append( TCommandLookup(&KCmdList, &KCmdOutputPlugin, EGetInstalledPlugins) ); // -lo
|
sl@0
|
65 |
iCommandsLookup.Append( TCommandLookup(&KCmdList, &KCmdPluginConfigurations, EGetPluginSettings) ); // -lc
|
sl@0
|
66 |
iCommandsLookup.Append( TCommandLookup(&KCmdList, &KCmdPrimaryFilter, EGetPrimaryFilters) ); // -lf
|
sl@0
|
67 |
iCommandsLookup.Append( TCommandLookup(&KCmdList, &KCmdSecondaryFilter, EGetSecondaryFilters) ); // -ls
|
sl@0
|
68 |
iCommandsLookup.Append( TCommandLookup(&KCmdList, &KCmdSecondaryFilterToggle, EGetSecondaryFiltering) ); // -lS
|
sl@0
|
69 |
iCommandsLookup.Append( TCommandLookup(&KCmdEnable, &KCmdBuffer, EResizeTraceBuffer) ); // -eb
|
sl@0
|
70 |
iCommandsLookup.Append( TCommandLookup(&KCmdList, &KCmdBuffer, EGetTraceBufferSize) ); // -lb
|
sl@0
|
71 |
iCommandsLookup.Append( TCommandLookup(&KCmdEnable, &KCmdBufferMode, ESetBufferMode) ); // -em
|
sl@0
|
72 |
iCommandsLookup.Append( TCommandLookup(&KCmdList, &KCmdBufferMode, EGetBufferMode) ); // -lm
|
sl@0
|
73 |
iCommandsLookup.Append( TCommandLookup(&KCmdEnable, &KCmdNotification, ESetDataNotificationSize) );// -en
|
sl@0
|
74 |
iCommandsLookup.Append( TCommandLookup(&KCmdList, &KCmdNotification, EGetDataNotificationSize) ); // -ln
|
sl@0
|
75 |
iCommandsLookup.Append( TCommandLookup(&KCmdDisable, &KCmdPrimaryFilter, ERemovePrimaryFilter) ); // -df
|
sl@0
|
76 |
iCommandsLookup.Append( TCommandLookup(&KCmdDisable, &KCmdSecondaryFilter, ERemoveSecondaryFilter) ); // -ds
|
sl@0
|
77 |
iCommandsLookup.Append( TCommandLookup(&KCmdEnable, &KCmdPluginConfigurations, ESetPluginSettings) ); // -ec
|
sl@0
|
78 |
iCommandsLookup.Append( TCommandLookup(&KCmdEnable, &KCmdOutputPlugin, ESetActivePlugin) ); // -eo
|
sl@0
|
79 |
iCommandsLookup.Append( TCommandLookup(&KCmdEnable, &KCmdInputPlugin, ESetActiveInputPlugin) ); // -ei
|
sl@0
|
80 |
iCommandsLookup.Append( TCommandLookup(&KCmdDisable, &KCmdInputPlugin, EDeactivateInputPlugin) ); // -di
|
sl@0
|
81 |
iCommandsLookup.Append( TCommandLookup(&KCmdList, &KCmdInputPlugin, EGetInputPlugins) ); // -li
|
sl@0
|
82 |
//only main command matters
|
sl@0
|
83 |
iCommandsLookup.Append( TCommandLookup(&KCmdStart, &KNullDesC, EStart) ); // -r
|
sl@0
|
84 |
iCommandsLookup.Append( TCommandLookup(&KCmdStop, &KNullDesC, EStop) ); // -q
|
sl@0
|
85 |
iCommandsLookup.Append( TCommandLookup(&KCmdRestart, &KNullDesC, ERestart) ); // -t
|
sl@0
|
86 |
iCommandsLookup.Append( TCommandLookup(&KCmdOutputPlugin, &KNullDesC, EGetActivePlugin) ); // -o
|
sl@0
|
87 |
iCommandsLookup.Append( TCommandLookup(&KCmdInputPlugin, &KNullDesC, EGetActiveInputPlugin) ); // -i
|
sl@0
|
88 |
iCommandsLookup.Append( TCommandLookup(&KCmdHelp, &KNullDesC, EHelp) ); // -h
|
sl@0
|
89 |
iCommandsLookup.Append( TCommandLookup(&KCmdMan, &KNullDesC, EManPage) ); // -H
|
sl@0
|
90 |
iCommandsLookup.Append( TCommandLookup(&KCmdVersion, &KNullDesC, EVersion) ); // -version
|
sl@0
|
91 |
|
sl@0
|
92 |
}
|
sl@0
|
93 |
|
sl@0
|
94 |
/**
|
sl@0
|
95 |
This function parses commands given as a parameter and generates TCommand value.
|
sl@0
|
96 |
The function is responsible also for triggering event for MCommandImpl
|
sl@0
|
97 |
|
sl@0
|
98 |
@param aArgs array of arguments to parse
|
sl@0
|
99 |
@return KErrNone if commands were parsed successfully and event was triggered, system wide error code otherwise
|
sl@0
|
100 |
*/
|
sl@0
|
101 |
EXPORT_C TInt CCommand::HandleCommandL(const RArray<TPtrC>& aArgs)
|
sl@0
|
102 |
{
|
sl@0
|
103 |
TBool optionsConsumed = EFalse;
|
sl@0
|
104 |
RArray<TPtrC> commands;
|
sl@0
|
105 |
CleanupClosePushL( commands );
|
sl@0
|
106 |
RBuf command;
|
sl@0
|
107 |
CleanupClosePushL(command);
|
sl@0
|
108 |
TInt maxSize=2;
|
sl@0
|
109 |
for(TInt k=0; k<aArgs.Count(); ++k) //calculate max command length
|
sl@0
|
110 |
maxSize += aArgs[k].Length();
|
sl@0
|
111 |
User::LeaveIfError(command.Create(maxSize));
|
sl@0
|
112 |
|
sl@0
|
113 |
for(TInt i=0; i<aArgs.Count(); ++i)
|
sl@0
|
114 |
{
|
sl@0
|
115 |
TPtrC argPtr(aArgs[i]);
|
sl@0
|
116 |
|
sl@0
|
117 |
//the 'version' command is the special case
|
sl@0
|
118 |
if(!argPtr.Mid(1).Compare(KCmdVersion))
|
sl@0
|
119 |
{
|
sl@0
|
120 |
TPtrC ptr(argPtr.Mid(1));
|
sl@0
|
121 |
commands.AppendL(ptr);
|
sl@0
|
122 |
continue;
|
sl@0
|
123 |
}
|
sl@0
|
124 |
|
sl@0
|
125 |
//check if we have to parse combined commands (like -ca)
|
sl@0
|
126 |
//other arguments are added to new array for further processing
|
sl@0
|
127 |
TBuf<1> cmdChecker;
|
sl@0
|
128 |
cmdChecker.Copy( argPtr.Mid(0,1) );
|
sl@0
|
129 |
if(!cmdChecker.Compare(KCmdIndicator) && !optionsConsumed)
|
sl@0
|
130 |
{
|
sl@0
|
131 |
//if there is option 'v' (verbose), this option shoul be removed
|
sl@0
|
132 |
//desc:
|
sl@0
|
133 |
//command data format: 'command param1 param2 paramN'
|
sl@0
|
134 |
//where:
|
sl@0
|
135 |
//command: ia string with commands letters, for example: 'lf', 'esv'
|
sl@0
|
136 |
//paramN: is parameter string, for example 'uloggerserialplugin'
|
sl@0
|
137 |
//array example: 'ec uloggerserialplugin output_port 3'
|
sl@0
|
138 |
|
sl@0
|
139 |
for(TInt k=1; k<argPtr.Length(); ++k)
|
sl@0
|
140 |
{
|
sl@0
|
141 |
TPtrC ptr(argPtr.Mid(k,1));
|
sl@0
|
142 |
if(!ptr.Compare(KCmdVerboseMode))
|
sl@0
|
143 |
iVerbose = ETrue;
|
sl@0
|
144 |
else
|
sl@0
|
145 |
command.AppendFormat(_L("%S"), &ptr);
|
sl@0
|
146 |
}
|
sl@0
|
147 |
//put command as a first element in array
|
sl@0
|
148 |
if(commands.Count() > 0)
|
sl@0
|
149 |
{
|
sl@0
|
150 |
commands.Remove(0);
|
sl@0
|
151 |
User::LeaveIfError(commands.Insert(command, 0));
|
sl@0
|
152 |
}
|
sl@0
|
153 |
else
|
sl@0
|
154 |
commands.AppendL(command);
|
sl@0
|
155 |
|
sl@0
|
156 |
|
sl@0
|
157 |
optionsConsumed = ETrue;
|
sl@0
|
158 |
}
|
sl@0
|
159 |
else
|
sl@0
|
160 |
commands.AppendL(argPtr);
|
sl@0
|
161 |
}
|
sl@0
|
162 |
|
sl@0
|
163 |
TInt errCode = PrepareCommandL( commands );
|
sl@0
|
164 |
CleanupStack::PopAndDestroy(2); //command, commands
|
sl@0
|
165 |
return errCode;
|
sl@0
|
166 |
}
|
sl@0
|
167 |
|
sl@0
|
168 |
|
sl@0
|
169 |
/** This method uses lookup table to translate user readable commands into TCommand value.
|
sl@0
|
170 |
@param aArgs Array of arguments.
|
sl@0
|
171 |
@return KErrNone if command was preapared correctly and system wide error code otherwise
|
sl@0
|
172 |
*/
|
sl@0
|
173 |
TInt CCommand::PrepareCommandL(RArray<TPtrC>& aArgs)
|
sl@0
|
174 |
{
|
sl@0
|
175 |
TInt i;
|
sl@0
|
176 |
TInt lookupArraySize = iCommandsLookup.Count();
|
sl@0
|
177 |
|
sl@0
|
178 |
if(aArgs.Count() == 0)
|
sl@0
|
179 |
return iCommandImpl->DoCommandL(EUnknown, aArgs);
|
sl@0
|
180 |
|
sl@0
|
181 |
//first elements contains command letters
|
sl@0
|
182 |
TPtrC cmd(aArgs[0]);
|
sl@0
|
183 |
if(cmd.Length() <= KMaxNumberOfLettersInCommand) //we want precise command
|
sl@0
|
184 |
{
|
sl@0
|
185 |
//check two arguments - 1st pass
|
sl@0
|
186 |
for(i=0; i<lookupArraySize; ++i)
|
sl@0
|
187 |
{
|
sl@0
|
188 |
if(cmd.Length() == 2)
|
sl@0
|
189 |
if(!iCommandsLookup[i].iMainCommand->Compare(cmd.Mid(0,1)))
|
sl@0
|
190 |
if(!iCommandsLookup[i].iSubCommand->Compare(cmd.Mid(1,1)))
|
sl@0
|
191 |
{
|
sl@0
|
192 |
aArgs.Remove(0);
|
sl@0
|
193 |
return iCommandImpl->DoCommandL(iCommandsLookup[i].iCommand, aArgs);
|
sl@0
|
194 |
}
|
sl@0
|
195 |
}
|
sl@0
|
196 |
|
sl@0
|
197 |
//check two arguments - 2nd pass
|
sl@0
|
198 |
for(i=0; i<lookupArraySize; ++i)
|
sl@0
|
199 |
{
|
sl@0
|
200 |
//check one argument
|
sl@0
|
201 |
if(cmd.Length() == 1)
|
sl@0
|
202 |
if(!iCommandsLookup[i].iMainCommand->Compare(cmd.Mid(0,1)))
|
sl@0
|
203 |
{
|
sl@0
|
204 |
//make sure that none of the 'two letters commands' will not be called
|
sl@0
|
205 |
if(iCommandsLookup[i].iSubCommand->Compare(KNullDesC))
|
sl@0
|
206 |
continue;
|
sl@0
|
207 |
aArgs.Remove(0);
|
sl@0
|
208 |
return iCommandImpl->DoCommandL(iCommandsLookup[i].iCommand, aArgs);
|
sl@0
|
209 |
}
|
sl@0
|
210 |
}
|
sl@0
|
211 |
}
|
sl@0
|
212 |
|
sl@0
|
213 |
return iCommandImpl->DoCommandL(EUnknown, aArgs);
|
sl@0
|
214 |
}
|
sl@0
|
215 |
|