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