|
1 // ioutils.h |
|
2 // |
|
3 // Copyright (c) 2005 - 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 #ifndef __IOUTILS_H__ |
|
14 #define __IOUTILS_H__ |
|
15 |
|
16 #include <e32std.h> |
|
17 #include <e32keys.h> |
|
18 #include <e32base.h> |
|
19 #include <e32hashtab.h> |
|
20 #include <f32file.h> |
|
21 #include <fshell/iocli.h> |
|
22 #include <fshell/iocons_writer.h> |
|
23 #include <fshell/line_editor_observer.h> |
|
24 |
|
25 class CColorConsoleBase; |
|
26 |
|
27 namespace IoUtils |
|
28 { |
|
29 |
|
30 const TUint KEnvironmentProcessSlot = 15; |
|
31 const TUint KDllCommandLineProcessSlot = 14; |
|
32 const TUint KDllNameToLoadProcessSlot = 13; |
|
33 const TUint KPipsCommandNameProcessSlot = 14; |
|
34 const TUint KPipsCommandLineProcessSlot = 13; |
|
35 |
|
36 const TUint KValueTypeBool = 0; |
|
37 const TUint KValueTypeInt = 1; |
|
38 const TUint KValueTypeUint = 2; |
|
39 const TUint KValueTypeString = 3; |
|
40 const TUint KValueTypeFileName = 4; |
|
41 const TUint KValueTypeEnum = 5; |
|
42 const TUint KValueTypeReal = 6; |
|
43 const TUint KValueTypeUint64 = 7; |
|
44 const TUint KValueTypeInt64 = 8; |
|
45 const TUint KValueTypeFlagLast = 0x20000000; ///< Tag this argument as the last one that this command handles. Can only be used with string arguments. Causes the remainder of the command line to be written to the string. |
|
46 const TUint KValueTypeFlagOptional = 0x40000000; ///< Tag this argument being optional. The command should handle the fact that the corresponding variable may not have been initialised (e.g. by calling RCommandArgumentList::IsPresent). |
|
47 |
|
48 enum TCmdBasePanic |
|
49 { |
|
50 ENoEnvironment = 0, |
|
51 EInvalidCommandOptionType = 1, |
|
52 EInvalidCommandArgumentType = 2, |
|
53 EIncorrectCommandOptionType1 = 3, |
|
54 EIncorrectCommandOptionType2 = 4, |
|
55 EIncorrectCommandOptionType3 = 5, |
|
56 EIncorrectCommandOptionType4 = 6, |
|
57 EIncorrectCommandOptionType5 = 7, |
|
58 EIncorrectCommandOptionType6 = 8, |
|
59 EIncorrectCommandOptionType7 = 9, |
|
60 EIncorrectCommandOptionType8 = 10, |
|
61 EIncorrectCommandOptionType9 = 11, |
|
62 EIncorrectCommandOptionType10 = 12, |
|
63 EIncorrectCommandOptionType11 = 13, |
|
64 ERFsNotConnected = 14, |
|
65 EAutoAborterAlreadyActive = 15, |
|
66 EInvalidArgumentIndex = 16, |
|
67 EDuplicateShortOptionName = 17, |
|
68 EUnused9 = 18, |
|
69 ENoStaticCommand = 19, |
|
70 EAlreadyCompleted = 20, |
|
71 EInvalidUseOfEnum = 21, |
|
72 EUnused10 = 22, |
|
73 ECifSubCommandParentNotFound = 23, |
|
74 EEnumValueContainsSpace = 24, |
|
75 ENonOptionalArgumentFollowsOptionalArgument = 25, |
|
76 EArgumentFollowsMultipleArgument = 26, |
|
77 EActiveObjectRunLNotOverridden = 27, |
|
78 EActiveObjectDoCancelNotOverridden = 28, |
|
79 ENotYetComplete = 29, |
|
80 EUnused1 = 30, |
|
81 EUnused2 = 31, |
|
82 EUnused3 = 32, |
|
83 EUnused4 = 33, |
|
84 EUnused5 = 34, |
|
85 EUnused6 = 35, |
|
86 EUnused7 = 36, |
|
87 EUnused8 = 37, |
|
88 EEnvVarNotFound1 = 38, |
|
89 EEnvVarNotFound2 = 39, |
|
90 EOptionTaggedAsLast = 40, |
|
91 ELastArgNotStringType = 41, |
|
92 ENoFactory = 42, |
|
93 EUnexpectedAsyncCommand = 43, |
|
94 EUnused11 = 44, |
|
95 ELastArgMultiple = 45, |
|
96 EEnumValueOutOfRange = 46, |
|
97 EEnumDescriptionMissing = 47, |
|
98 EValueTypeAlreadySet = 48, |
|
99 EValueDescriptionAlreadySet = 49, |
|
100 EEnumValueListAlreadySet = 50, |
|
101 EEnumDescriptionListAlreadySet = 51, |
|
102 EIncompleteArgumentOrOptionInitialization = 52, |
|
103 }; |
|
104 |
|
105 class CCommandBase; |
|
106 class CReaderChangeNotifier; |
|
107 class CCommandCompleter; |
|
108 class MLineReader; |
|
109 |
|
110 |
|
111 class TOverflowTruncate : public TDes16Overflow |
|
112 { |
|
113 public: |
|
114 virtual void Overflow(TDes16&) {} |
|
115 }; |
|
116 |
|
117 class TOverflowTruncate8 : public TDes8Overflow |
|
118 { |
|
119 public: |
|
120 virtual void Overflow(TDes8&) {} |
|
121 }; |
|
122 |
|
123 class TOverflowLeave : public TDes16Overflow |
|
124 { |
|
125 public: |
|
126 virtual void Overflow(TDes16&) { User::Leave(KErrOverflow); } |
|
127 }; |
|
128 |
|
129 class TOverflowLeave8 : public TDes8Overflow |
|
130 { |
|
131 public: |
|
132 virtual void Overflow(TDes8&) { User::Leave(KErrOverflow); } |
|
133 }; |
|
134 |
|
135 class TFileName2 : public TFileName |
|
136 { |
|
137 public: |
|
138 enum TType |
|
139 { |
|
140 EFile, |
|
141 EDirectory |
|
142 }; |
|
143 public: |
|
144 IMPORT_C TFileName2(); |
|
145 IMPORT_C TFileName2(TType aType); |
|
146 IMPORT_C TFileName2(const TDesC& aName); |
|
147 IMPORT_C TFileName2(const TDesC& aName, TType aType); |
|
148 IMPORT_C TBool IsAbsolute() const; |
|
149 IMPORT_C TBool IsDriveLetter() const; |
|
150 IMPORT_C TBool IsDriveRoot() const; |
|
151 IMPORT_C TBool IsWild() const; |
|
152 IMPORT_C TBool IsFile() const; |
|
153 IMPORT_C TBool IsDir() const; |
|
154 IMPORT_C TBool HasDriveLetter() const; |
|
155 IMPORT_C TBool HasLeadingSlash() const; |
|
156 IMPORT_C TBool HasTrailingSlash() const; |
|
157 IMPORT_C TPtrC Drive() const; |
|
158 IMPORT_C TPtrC Path() const; |
|
159 IMPORT_C TPtrC DriveAndPath() const; |
|
160 IMPORT_C TPtrC Name() const; |
|
161 IMPORT_C TPtrC Ext() const; |
|
162 IMPORT_C TPtrC NameAndExt() const; |
|
163 IMPORT_C void SetL(const TFileName2& aName); |
|
164 IMPORT_C void SetTypeL(TType aType); |
|
165 IMPORT_C void SetTypeL(RFs& aFs); |
|
166 IMPORT_C void SetDriveL(const TDesC& aDrive); |
|
167 IMPORT_C void SetPathL(const TDesC& aPath); |
|
168 IMPORT_C void SetNameL(const TDesC& aName); |
|
169 IMPORT_C void SetExtL(const TDesC& aExt); |
|
170 IMPORT_C void SetNameAndExtL(const TDesC& aNameAndExt); |
|
171 IMPORT_C void PrependL(const TFileName2& aName); |
|
172 IMPORT_C void AppendComponentL(const TFileName2& aName); |
|
173 IMPORT_C void AppendComponentL(const TDesC& aPathComponent, TType aPathComponentType); |
|
174 IMPORT_C void AppendComponentL(const TEntry& aEntry); |
|
175 IMPORT_C void SplitL(RArray<TFileName2>& aOutput); |
|
176 IMPORT_C void UnsplitL(const RArray<TFileName2>& aInput); |
|
177 IMPORT_C void MakeAbsoluteL(const TFileName2& aAbsoluteTo); |
|
178 IMPORT_C void MakeAbsoluteL(RFs& aFs); // Make absolute relative to aFs's session path |
|
179 IMPORT_C TBool Exists(RFs& aFs) const; |
|
180 IMPORT_C TBool IsReadOnlyL(RFs& aFs) const; |
|
181 IMPORT_C TBool IsHiddenL(RFs& aFs) const; |
|
182 IMPORT_C TBool IsSystemL(RFs& aFs) const; |
|
183 IMPORT_C TBool IsDirL(RFs& aFs) const; |
|
184 IMPORT_C TBool IsArchiveL(RFs& aFs) const; |
|
185 IMPORT_C void SetIsDirectoryL(); // Ensure the descriptor ends in a slash |
|
186 IMPORT_C TInt FindFile(RFs& aFs); |
|
187 IMPORT_C void FindFileL(RFs& aFs); |
|
188 private: |
|
189 void CheckSpaceL(TInt aLengthToAdd) const; |
|
190 private: |
|
191 TType iType; |
|
192 }; |
|
193 |
|
194 |
|
195 enum TAlignment |
|
196 { |
|
197 EUnaligned, |
|
198 EColumnAlignedLeft, |
|
199 EColumnAlignedRight |
|
200 }; |
|
201 |
|
202 enum TTabMode |
|
203 { |
|
204 EWrapLastColumn, |
|
205 ETruncateLongestColumn, |
|
206 EIgnoreAvailableWidth, |
|
207 }; |
|
208 |
|
209 NONSHARABLE_CLASS(CTextBuffer) : public CActive |
|
210 { |
|
211 public: |
|
212 IMPORT_C static CTextBuffer* NewL(TInt aExpandSize); |
|
213 IMPORT_C static CTextBuffer* NewLC(TInt aExpandSize); |
|
214 IMPORT_C ~CTextBuffer(); |
|
215 IMPORT_C virtual void Zero(); |
|
216 IMPORT_C virtual void Reset(); |
|
217 IMPORT_C virtual void ResetText(); |
|
218 IMPORT_C void SetAttributesL(TUint aAttributes, ConsoleAttributes::TColor aForegroundColor = ConsoleAttributes::EUnchanged, ConsoleAttributes::TColor aBackgroundColor = ConsoleAttributes::EUnchanged); |
|
219 IMPORT_C void SetAttributesL(const ConsoleAttributes::TAttributes& aAttributes); |
|
220 IMPORT_C void GetCurrentAttributes(TUint& aAttributes, ConsoleAttributes::TColor& aForegroundColor, ConsoleAttributes::TColor& aBackgroundColor) const; |
|
221 IMPORT_C void GetAttributes(TInt aPos, TUint& aAttributes, ConsoleAttributes::TColor& aForegroundColor, ConsoleAttributes::TColor& aBackgroundColor) const; |
|
222 IMPORT_C void AppendL(const TChar& aChar); |
|
223 IMPORT_C void AppendL(const TDesC16& aText); |
|
224 IMPORT_C void AppendL(const TDesC8& aText); |
|
225 IMPORT_C void AppendL(const CTextBuffer& aText); |
|
226 IMPORT_C void AppendL(const CTextBuffer& aText, TInt aPosition); |
|
227 IMPORT_C void AppendL(const CTextBuffer& aText, TInt aPosition, TInt aLength); |
|
228 IMPORT_C void AppendFormatL(TRefByValue<const TDesC> aFmt, ...); |
|
229 IMPORT_C void AppendFormatL(TRefByValue<const TDesC8> aFmt, ...); |
|
230 IMPORT_C void AppendFormatListL(const TDesC16& aFmt, VA_LIST& aList); |
|
231 IMPORT_C void AppendFormatListL(const TDesC8& aFmt, VA_LIST& aList); |
|
232 IMPORT_C void AppendHumanReadableSizeL(TInt aSize); |
|
233 IMPORT_C void AppendHumanReadableSizeL(TInt64 aSize); |
|
234 IMPORT_C void AppendHumanReadableSizeL(TInt aSize, TAlignment aAlignment); |
|
235 IMPORT_C void AppendHumanReadableSizeL(TInt64 aSize, TAlignment aAlignment); |
|
236 IMPORT_C void AppendSpacesL(TInt aCount); |
|
237 IMPORT_C void Delete(TInt aPos, TInt aLength); |
|
238 IMPORT_C TInt Length() const; |
|
239 IMPORT_C const TDesC& Descriptor() const; |
|
240 IMPORT_C const TDesC& Descriptor(TInt aPos, TInt aLength) const; |
|
241 IMPORT_C TPtrC8 Collapse(); |
|
242 IMPORT_C TInt Write(RIoWriteHandle& aWriteHandle) const; |
|
243 IMPORT_C void Write(RIoWriteHandle& aWriteHandle, TRequestStatus& aStatus) const; |
|
244 IMPORT_C TInt Write(RIoWriteHandle& aWriteHandle, TInt aPosition, TInt aLength) const; |
|
245 IMPORT_C void Write(RIoWriteHandle& aWriteHandle, TInt aPosition, TInt aLength, TRequestStatus& aStatus) const; |
|
246 protected: |
|
247 CTextBuffer(); |
|
248 void ConstructL(TInt aExpandSize); |
|
249 private: |
|
250 void NextBlock(TInt& aBlockIndex, const TDesC*& aText, TUint& aAttributes, ConsoleAttributes::TColor& aForegroundColor, ConsoleAttributes::TColor& aBackgroundColor) const; |
|
251 void AsyncWriteNextBlock() const; |
|
252 private: // From CActive. |
|
253 virtual void RunL(); |
|
254 virtual void DoCancel(); |
|
255 private: |
|
256 class TAttributes |
|
257 { |
|
258 public: |
|
259 TAttributes(TInt aPosition, TUint aAttributes, ConsoleAttributes::TColor aForegroundColor, ConsoleAttributes::TColor aBackgroundColor); |
|
260 TBool Matches(TUint aAttributes, ConsoleAttributes::TColor aForegroundColor, ConsoleAttributes::TColor aBackgroundColor) const; |
|
261 public: |
|
262 TInt iPosition; |
|
263 ConsoleAttributes::TAttributes iAttributes; |
|
264 }; |
|
265 private: |
|
266 CBufBase* iBuf; |
|
267 mutable TPtrC iPtr; |
|
268 HBufC* iScratchBuf; |
|
269 HBufC8* iScratchBuf8; |
|
270 RArray<TAttributes> iAttributes; |
|
271 mutable RIoConsoleWriteHandle iConsoleWriteHandle; // Not owned. |
|
272 mutable TInt iAsyncBlockIndex; |
|
273 mutable TInt iAsyncWritePos; |
|
274 mutable TInt iAsyncWriteStartPos; |
|
275 mutable TInt iAsyncWriteLength; |
|
276 mutable TPtrC iAsyncWritePtr; |
|
277 mutable TRequestStatus* iWriteStatus; |
|
278 }; |
|
279 |
|
280 |
|
281 NONSHARABLE_CLASS(CTextFormatter) : public CTextBuffer |
|
282 { |
|
283 public: |
|
284 IMPORT_C static CTextFormatter* NewL(TInt aAvailableWidth); |
|
285 IMPORT_C static CTextFormatter* NewLC(TInt aAvailableWidth); |
|
286 IMPORT_C static CTextFormatter* NewL(RIoConsoleWriteHandle& aConsoleWriteHandle); |
|
287 IMPORT_C static CTextFormatter* NewLC(RIoConsoleWriteHandle& aConsoleWriteHandle); |
|
288 IMPORT_C ~CTextFormatter(); |
|
289 IMPORT_C virtual void Zero(); |
|
290 IMPORT_C virtual void Reset(); |
|
291 IMPORT_C virtual void ResetText(); |
|
292 IMPORT_C void WrapL(TInt aIndent, const TDesC& aText); |
|
293 IMPORT_C void WrapL(TInt aStartPosition, TInt aIndent, const TDesC& aText); |
|
294 IMPORT_C void TabulateL(TInt aIndent, TInt aGap, const TDesC& aText); |
|
295 IMPORT_C void TabulateL(TInt aIndent, TInt aGap, const TDesC& aText, TTabMode aMode); |
|
296 IMPORT_C void ColumnizeL(TInt aIndent, TInt aGap, const TDesC& aText); |
|
297 IMPORT_C void ColumnizeL(TInt aIndent, TInt aGap, const TArray<TPtrC>& aItems); |
|
298 IMPORT_C void AppendPodL(const TDesC& aPod); |
|
299 IMPORT_C TInt Write(); |
|
300 private: |
|
301 CTextFormatter(TInt aAvailableWidth); |
|
302 void ConstructL(); |
|
303 void DoAppendPodL(const TDesC& aPod); |
|
304 void DecodeInteriorPodSequencesL(const TDesC& aPod, CTextBuffer& aBuffer) const; |
|
305 TBool NextColumn(TLex& aLex, TPtrC& aPtr) const; |
|
306 TBool NextLine(TLex& aLex, TPtrC& aPtr) const; |
|
307 TInt ActualLength(const TDesC& aPod) const; |
|
308 private: |
|
309 TInt iAvailableWidth; |
|
310 RIoConsoleWriteHandle* iWriteHandle; |
|
311 TBool iAttributesSupported; |
|
312 }; |
|
313 |
|
314 |
|
315 NONSHARABLE_CLASS(CEnvironment) : public CBase |
|
316 { |
|
317 public: |
|
318 IMPORT_C static CEnvironment* NewL(); |
|
319 IMPORT_C static CEnvironment* NewL(const CEnvironment& aEnv); |
|
320 IMPORT_C ~CEnvironment(); |
|
321 IMPORT_C void SetL(const TDesC& aKey, TInt aValue); |
|
322 IMPORT_C void SetL(const TDesC& aKey, const TDesC& aValue); |
|
323 IMPORT_C TInt GetAsInt(const TDesC& aKey) const; |
|
324 IMPORT_C TInt GetAsIntL(const TDesC& aKey) const; |
|
325 IMPORT_C const TDesC& GetAsDes(const TDesC& aKey) const; |
|
326 IMPORT_C const TDesC& GetAsDesL(const TDesC& aKey) const; |
|
327 IMPORT_C TInt Remove(const TDesC& aKey); |
|
328 IMPORT_C void RemoveL(const TDesC& aKey); |
|
329 IMPORT_C void RemoveAll(); // Doesn't remove anything in parent env |
|
330 IMPORT_C void InternalizeL(const TDesC8& aDes); |
|
331 IMPORT_C HBufC8* ExternalizeLC() const; |
|
332 IMPORT_C TBool IsDefined(const TDesC& aKey) const; |
|
333 IMPORT_C TBool IsInt(const TDesC& aKey) const; |
|
334 IMPORT_C TBool IsDes(const TDesC& aKey) const; |
|
335 IMPORT_C TInt Count() const; |
|
336 IMPORT_C void GetKeysL(RPointerArray<HBufC>& aResult) const; |
|
337 IMPORT_C void SetPwdL(const TDesC& aPwd); |
|
338 IMPORT_C const TDesC& Pwd() const; |
|
339 IMPORT_C TChar EscapeChar() const; |
|
340 IMPORT_C void SetLocalL(const TDesC& aKey); |
|
341 IMPORT_C CEnvironment* CreateSharedEnvironmentL(); |
|
342 private: |
|
343 CEnvironment(); |
|
344 CEnvironment(CEnvironment* aParentEnv); |
|
345 void ConstructL(); |
|
346 void WaitLC() const; |
|
347 static void Signal(TAny* aSelf); |
|
348 void Lock() const; |
|
349 void Unlock() const; |
|
350 void CopyL(const CEnvironment& aEnv); |
|
351 HBufC* Get(const TDesC& aKey) const; |
|
352 HBufC* GetL(const TDesC& aKey) const; |
|
353 private: |
|
354 TUint32 iVarsImpl[14]; |
|
355 mutable RMutex iLock; |
|
356 CEnvironment* iParentEnv; |
|
357 }; |
|
358 |
|
359 |
|
360 class MCommandBaseObserver |
|
361 { |
|
362 public: |
|
363 virtual void HandleCommandComplete(CCommandBase& aCommand, TInt aError) = 0; |
|
364 }; |
|
365 |
|
366 class TEnum |
|
367 { |
|
368 public: |
|
369 IMPORT_C TEnum(); |
|
370 IMPORT_C TEnum(const TDesC& aEnumValueList); |
|
371 IMPORT_C TEnum(const TDesC& aEnumValueList, const TDesC& aEnumDescriptionList); |
|
372 IMPORT_C TInt Parse(const TDesC& aString, TInt& aValue); |
|
373 IMPORT_C TInt ParseL(const TDesC& aString); |
|
374 IMPORT_C const TDesC& ValueList() const; |
|
375 IMPORT_C const TDesC& DescriptionList() const; |
|
376 IMPORT_C void AppendValuesL(CTextBuffer& aBuf) const; |
|
377 IMPORT_C const TPtrC GetString(TInt aIndex) const; |
|
378 IMPORT_C void SetValueList(const TDesC& aValueList); |
|
379 IMPORT_C void SetDescriptionList(const TDesC& aDescriptionList); |
|
380 IMPORT_C void operator=(const TEnum& aEnum); |
|
381 private: |
|
382 void ValidateValues() const; |
|
383 TInt GetMatches(const TDesC& aString, RArray<TInt>& aMatches, TInt& aExactMatch); |
|
384 private: |
|
385 TPtrC iEnumValueList; |
|
386 TPtrC iEnumDescriptionList; |
|
387 }; |
|
388 |
|
389 class TValue |
|
390 { |
|
391 public: |
|
392 IMPORT_C const TDesC& Name() const; |
|
393 IMPORT_C TUint Type() const; |
|
394 IMPORT_C TBool AcceptsMultiple() const; |
|
395 IMPORT_C const TDesC& EnvVar() const; |
|
396 IMPORT_C void* ValuePtr() const; |
|
397 IMPORT_C const TDesC& EnumValueList() const; |
|
398 |
|
399 TValue(TUint aValueType, void* aValuePointer, const TDesC& aName); |
|
400 TValue(TUint aValueType, void* aValuePointer, const TDesC& aName, const TDesC& aDescription, const TDesC& aEnvVar = KNullDesC); |
|
401 TValue(TUint aValueType, const TDesC& aEnumValueList, const TDesC& aEnumDescriptionList, void* aValuePointer, const TDesC& aName, const TDesC& aDescription, const TDesC& aEnvVar = KNullDesC); |
|
402 TUint ValueType() const; |
|
403 void SetValue(); |
|
404 void SetValueL(TInt aInt); |
|
405 void SetValueL(TInt64 aInt); |
|
406 void SetValueL(TUint aUint); |
|
407 void SetValueL(TUint64 aUint); |
|
408 void SetValueL(TReal64 aReal); |
|
409 void SetValueL(HBufC* aString); |
|
410 void SetValueL(const TFileName2& aFileName, RFs& aFs); |
|
411 void SetEnumValues(const TEnum& aEnum); |
|
412 TBool IsSet() const; |
|
413 const TDesC& EnumDescriptionList() const; |
|
414 const TDesC& Description() const; |
|
415 TPtrC AsString() const; |
|
416 void AppendEnumValuesL(CTextBuffer& aBuf) const; |
|
417 void Combine(const TValue& aValue); |
|
418 protected: |
|
419 TUint iValueType; |
|
420 void* iValue; |
|
421 TBool iIsSet; |
|
422 TPtrC iEnvVar; |
|
423 TEnum iEnum; |
|
424 const TPtrC iName; |
|
425 TPtrC iDescription; |
|
426 }; |
|
427 |
|
428 |
|
429 class TCommandOption : public TValue |
|
430 { |
|
431 public: |
|
432 TCommandOption(TUint aValueType, void* aValuePointer, const TDesC& aLongName); |
|
433 TCommandOption(TUint aValueType, void* aValuePointer, TChar aShortName, const TDesC& aLongName, const TDesC& aDescription, const TDesC& aEnvVar = KNullDesC); |
|
434 TCommandOption(void* aValuePointer, TUint aValueType, const TDesC& aCommaSeparatedValueList, const TDesC& aCommaSeparatedDescriptionList, TChar aShortName, const TDesC& aLongName, const TDesC& aDescription, const TDesC& aEnvVar = KNullDesC); |
|
435 TChar ShortName() const; |
|
436 void Combine(const TCommandOption& aOption); |
|
437 private: |
|
438 TChar iShortName; |
|
439 }; |
|
440 |
|
441 |
|
442 class RCommandOptionList |
|
443 { |
|
444 public: |
|
445 // Use these APIs to only partially declare options in C++ code, and to have the remaining details (e.g. documentation) read from a Command Info File (CIF). |
|
446 IMPORT_C void AppendBoolL(TBool& aBool, const TDesC& aLongName); |
|
447 IMPORT_C void AppendBoolL(RArray<TBool>& aBools, const TDesC& aLongName); |
|
448 IMPORT_C void AppendIntL(TInt& aInt, const TDesC& aLongName); |
|
449 IMPORT_C void AppendIntL(RArray<TInt>& aInts, const TDesC& aLongName); |
|
450 IMPORT_C void AppendIntL(TInt64& aInt, const TDesC& aLongName); |
|
451 IMPORT_C void AppendIntL(RArray<TInt64>& aInts, const TDesC& aLongName); |
|
452 IMPORT_C void AppendUintL(TUint& aUint, const TDesC& aLongName); |
|
453 IMPORT_C void AppendUintL(RArray<TUint>& aUints, const TDesC& aLongName); |
|
454 IMPORT_C void AppendUintL(TUint64& aUint, const TDesC& aLongName); |
|
455 IMPORT_C void AppendUintL(RArray<TUint64>& aUints, const TDesC& aLongName); |
|
456 IMPORT_C void AppendRealL(TReal64& aReal, const TDesC& aLongName); |
|
457 IMPORT_C void AppendRealL(RArray<TReal64>& aReals, const TDesC& aLongName); |
|
458 IMPORT_C void AppendStringL(HBufC*& aBuf, const TDesC& aLongName); |
|
459 IMPORT_C void AppendStringL(RPointerArray<HBufC>& aBufs, const TDesC& aLongName); |
|
460 IMPORT_C void AppendFileNameL(TFileName2& aFileName, const TDesC& aLongName); |
|
461 IMPORT_C void AppendFileNameL(RArray<TFileName2>& aFileNames, const TDesC& aLongName); |
|
462 IMPORT_C void AppendEnumL(TInt& aEnum, const TDesC& aLongName); |
|
463 IMPORT_C void AppendEnumL(TInt& aEnum, const TDesC& aLongName, const TDesC& aCommaSeparatedValueList); |
|
464 IMPORT_C void AppendEnumL(RArray<TInt>& aEnum, const TDesC& aLongName); // Be sure to pass an actual RArray<TInt>& here, not an RArray<TSomeEnum>&. Internally, CCommandBase casts whatever you pass in to an RArray<TInt> and this is a specialized template withe a different memory layout to the general version. |
|
465 IMPORT_C void AppendEnumL(RArray<TInt>& aEnum, const TDesC& aLongName, const TDesC& aCommaSeparatedValueList); // Be sure to pass an actual RArray<TInt>& here, not an RArray<TSomeEnum>&. Internally, CCommandBase casts whatever you pass in to an RArray<TInt> and this is a specialized template withe a different memory layout to the general version. |
|
466 |
|
467 // Use these APIs to fully declare options in C++ code. |
|
468 IMPORT_C void AppendBoolL(TBool& aBool, TChar aShortName, const TDesC& aLongName, const TDesC& aDescription, TUint aFlags = 0, const TDesC& aEnvVar = KNullDesC); |
|
469 IMPORT_C void AppendBoolL(RArray<TBool>& aBools, TChar aShortName, const TDesC& aLongName, const TDesC& aDescription, TUint aFlags = 0, const TDesC& aEnvVar = KNullDesC); |
|
470 IMPORT_C void AppendIntL(TInt& aInt, TChar aShortName, const TDesC& aLongName, const TDesC& aDescription, TUint aFlags = 0, const TDesC& aEnvVar = KNullDesC); |
|
471 IMPORT_C void AppendIntL(RArray<TInt>& aInts, TChar aShortName, const TDesC& aLongName, const TDesC& aDescription, TUint aFlags = 0, const TDesC& aEnvVar = KNullDesC); |
|
472 IMPORT_C void AppendIntL(TInt64& aInt, TChar aShortName, const TDesC& aLongName, const TDesC& aDescription, TUint aFlags = 0, const TDesC& aEnvVar = KNullDesC); |
|
473 IMPORT_C void AppendIntL(RArray<TInt64>& aInts, TChar aShortName, const TDesC& aLongName, const TDesC& aDescription, TUint aFlags = 0, const TDesC& aEnvVar = KNullDesC); |
|
474 IMPORT_C void AppendUintL(TUint& aUint, TChar aShortName, const TDesC& aLongName, const TDesC& aDescription, TUint aFlags = 0, const TDesC& aEnvVar = KNullDesC); |
|
475 IMPORT_C void AppendUintL(RArray<TUint>& aUints, TChar aShortName, const TDesC& aLongName, const TDesC& aDescription, TUint aFlags = 0, const TDesC& aEnvVar = KNullDesC); |
|
476 IMPORT_C void AppendUintL(TUint64& aUint, TChar aShortName, const TDesC& aLongName, const TDesC& aDescription, TUint aFlags = 0, const TDesC& aEnvVar = KNullDesC); |
|
477 IMPORT_C void AppendUintL(RArray<TUint64>& aUints, TChar aShortName, const TDesC& aLongName, const TDesC& aDescription, TUint aFlags = 0, const TDesC& aEnvVar = KNullDesC); |
|
478 IMPORT_C void AppendRealL(TReal64& aReal, TChar aShortName, const TDesC& aLongName, const TDesC& aDescription, TUint aFlags = 0, const TDesC& aEnvVar = KNullDesC); |
|
479 IMPORT_C void AppendRealL(RArray<TReal64>& aReals, TChar aShortName, const TDesC& aLongName, const TDesC& aDescription, TUint aFlags = 0, const TDesC& aEnvVar = KNullDesC); |
|
480 IMPORT_C void AppendStringL(HBufC*& aBuf, TChar aShortName, const TDesC& aLongName, const TDesC& aDescription, TUint aFlags = 0, const TDesC& aEnvVar = KNullDesC); |
|
481 IMPORT_C void AppendStringL(RPointerArray<HBufC>& aBufs, TChar aShortName, const TDesC& aLongName, const TDesC& aDescription, TUint aFlags = 0, const TDesC& aEnvVar = KNullDesC); |
|
482 IMPORT_C void AppendFileNameL(TFileName2& aFileName, TChar aShortName, const TDesC& aLongName, const TDesC& aDescription, TUint aFlags = 0, const TDesC& aEnvVar = KNullDesC); |
|
483 IMPORT_C void AppendFileNameL(RArray<TFileName2>& aFileNames, TChar aShortName, const TDesC& aLongName, const TDesC& aDescription, TUint aFlags = 0, const TDesC& aEnvVar = KNullDesC); |
|
484 IMPORT_C void AppendEnumL(TInt& aEnum, TChar aShortName, const TDesC& aLongName, const TDesC& aDescription, const TDesC& aCommaSeparatedValueList, TUint aFlags = 0, const TDesC& aEnvVar = KNullDesC); |
|
485 IMPORT_C void AppendEnumL(TInt& aEnum, TChar aShortName, const TDesC& aLongName, const TDesC& aDescription, const TDesC& aCommaSeparatedValueList, const TDesC& aCommaSeparatedDescriptionList, TUint aFlags = 0, const TDesC& aEnvVar = KNullDesC); |
|
486 IMPORT_C void AppendEnumL(RArray<TInt>& aEnum, TChar aShortName, const TDesC& aLongName, const TDesC& aDescription, const TDesC& aCommaSeparatedValueList, TUint aFlags = 0, const TDesC& aEnvVar = KNullDesC); // Be sure to pass an actual RArray<TInt>& here, not an RArray<TSomeEnum>&. Internally, CCommandBase casts whatever you pass in to an RArray<TInt> and this is a specialized template withe a different memory layout to the general version. |
|
487 IMPORT_C void AppendEnumL(RArray<TInt>& aEnum, TChar aShortName, const TDesC& aLongName, const TDesC& aDescription, const TDesC& aCommaSeparatedValueList, const TDesC& aCommaSeparatedDescriptionList, TUint aFlags = 0, const TDesC& aEnvVar = KNullDesC); // Be sure to pass an actual RArray<TInt>& here, not an RArray<TSomeEnum>&. Internally, CCommandBase casts whatever you pass in to an RArray<TInt> and this is a specialized template withe a different memory layout to the general version. |
|
488 |
|
489 IMPORT_C TBool IsPresent(void* aValuePointer) const; |
|
490 IMPORT_C TPtrC AsString(void* aValuePointer) const; |
|
491 void Close(); |
|
492 IMPORT_C TInt Count() const; |
|
493 IMPORT_C TCommandOption& operator[](TInt aIndex); |
|
494 IMPORT_C const TCommandOption& operator[](TInt aIndex) const; |
|
495 TInt FindShort(TChar aShortName) const; |
|
496 TInt Find(const TDesC& aLongName) const; |
|
497 private: |
|
498 void Validate(const TCommandOption& aOption); |
|
499 private: |
|
500 RArray<TCommandOption> iOptions; |
|
501 }; |
|
502 |
|
503 |
|
504 class TCommandArgument : public TValue |
|
505 { |
|
506 public: |
|
507 TCommandArgument(TUint aValueType, void* aValuePointer, const TDesC& aName); |
|
508 TCommandArgument(TUint aValueType, void* aValuePointer, const TDesC& aName, const TDesC& aDescription, const TDesC& aEnvVar = KNullDesC); |
|
509 TCommandArgument(void* aValuePointer, TUint aValueType, const TDesC& aName, const TDesC& aDescription, const TDesC& aCommaSeparatedValueList, const TDesC& aCommaSeparatedDescriptionList, const TDesC& aEnvVar = KNullDesC); |
|
510 TBool IsOptional() const; |
|
511 TBool IsLast() const; |
|
512 }; |
|
513 |
|
514 |
|
515 class RCommandArgumentList |
|
516 { |
|
517 public: |
|
518 // Use these APIs to only partially declare arguments in C++ code, and to have the remaining details (e.g. documentation) read from a Command Info File (CIF). |
|
519 IMPORT_C void AppendIntL(TInt& aInt, const TDesC& aName); |
|
520 IMPORT_C void AppendIntL(RArray<TInt>& aInts, const TDesC& aName); |
|
521 IMPORT_C void AppendIntL(TInt64& aInt, const TDesC& aName); |
|
522 IMPORT_C void AppendIntL(RArray<TInt64>& aInts, const TDesC& aName); |
|
523 IMPORT_C void AppendUintL(TUint& aUint, const TDesC& aName); |
|
524 IMPORT_C void AppendUintL(RArray<TUint>& aUints, const TDesC& aName); |
|
525 IMPORT_C void AppendUintL(TUint64& aUint, const TDesC& aName); |
|
526 IMPORT_C void AppendUintL(RArray<TUint64>& aUints, const TDesC& aName); |
|
527 IMPORT_C void AppendRealL(TReal64& aReal, const TDesC& aName); |
|
528 IMPORT_C void AppendRealL(RArray<TReal64>& aReals, const TDesC& aName); |
|
529 IMPORT_C void AppendStringL(HBufC*& aBuf, const TDesC& aName); |
|
530 IMPORT_C void AppendStringL(RPointerArray<HBufC>& aBufs, const TDesC& aName); |
|
531 IMPORT_C void AppendFileNameL(TFileName2& aFileName, const TDesC& aName); |
|
532 IMPORT_C void AppendFileNameL(RArray<TFileName2>& aFileNames, const TDesC& aName); |
|
533 IMPORT_C void AppendEnumL(TInt& aEnum, const TDesC& aName); |
|
534 IMPORT_C void AppendEnumL(TInt& aEnum, const TDesC& aName, const TDesC& aCommaSeparatedValueList); |
|
535 IMPORT_C void AppendEnumL(RArray<TInt>& aEnum, const TDesC& aName); // Be sure to pass an actual RArray<TInt>& here, not an RArray<TSomeEnum>&. Internally, CCommandBase casts whatever you pass in to an RArray<TInt> and this is a specialized template with a different memory layout to the general version. |
|
536 IMPORT_C void AppendEnumL(RArray<TInt>& aEnum, const TDesC& aName, const TDesC& aCommaSeparatedValueList); // Be sure to pass an actual RArray<TInt>& here, not an RArray<TSomeEnum>&. Internally, CCommandBase casts whatever you pass in to an RArray<TInt> and this is a specialized template with a different memory layout to the general version. |
|
537 |
|
538 // Use these APIs to fully declare arguments in C++ code. |
|
539 IMPORT_C void AppendIntL(TInt& aInt, const TDesC& aName, const TDesC& aDescription, TUint aFlags = 0, const TDesC& aEnvVar = KNullDesC); |
|
540 IMPORT_C void AppendIntL(RArray<TInt>& aInts, const TDesC& aName, const TDesC& aDescription, TUint aFlags = 0, const TDesC& aEnvVar = KNullDesC); |
|
541 IMPORT_C void AppendIntL(TInt64& aInt, const TDesC& aName, const TDesC& aDescription, TUint aFlags = 0, const TDesC& aEnvVar = KNullDesC); |
|
542 IMPORT_C void AppendIntL(RArray<TInt64>& aInts, const TDesC& aName, const TDesC& aDescription, TUint aFlags = 0, const TDesC& aEnvVar = KNullDesC); |
|
543 IMPORT_C void AppendUintL(TUint& aUint, const TDesC& aName, const TDesC& aDescription, TUint aFlags = 0, const TDesC& aEnvVar = KNullDesC); |
|
544 IMPORT_C void AppendUintL(RArray<TUint>& aUints, const TDesC& aName, const TDesC& aDescription, TUint aFlags = 0, const TDesC& aEnvVar = KNullDesC); |
|
545 IMPORT_C void AppendUintL(TUint64& aUint, const TDesC& aName, const TDesC& aDescription, TUint aFlags = 0, const TDesC& aEnvVar = KNullDesC); |
|
546 IMPORT_C void AppendUintL(RArray<TUint64>& aUints, const TDesC& aName, const TDesC& aDescription, TUint aFlags = 0, const TDesC& aEnvVar = KNullDesC); |
|
547 IMPORT_C void AppendRealL(TReal64& aReal, const TDesC& aName, const TDesC& aDescription, TUint aFlags = 0, const TDesC& aEnvVar = KNullDesC); |
|
548 IMPORT_C void AppendRealL(RArray<TReal64>& aReals, const TDesC& aName, const TDesC& aDescription, TUint aFlags = 0, const TDesC& aEnvVar = KNullDesC); |
|
549 IMPORT_C void AppendStringL(HBufC*& aBuf, const TDesC& aName, const TDesC& aDescription, TUint aFlags = 0, const TDesC& aEnvVar = KNullDesC); |
|
550 IMPORT_C void AppendStringL(RPointerArray<HBufC>& aBufs, const TDesC& aName, const TDesC& aDescription, TUint aFlags = 0, const TDesC& aEnvVar = KNullDesC); |
|
551 IMPORT_C void AppendFileNameL(TFileName2& aFileName, const TDesC& aName, const TDesC& aDescription, TUint aFlags = 0, const TDesC& aEnvVar = KNullDesC); |
|
552 IMPORT_C void AppendFileNameL(RArray<TFileName2>& aFileNames, const TDesC& aName, const TDesC& aDescription, TUint aFlags = 0, const TDesC& aEnvVar = KNullDesC); |
|
553 IMPORT_C void AppendEnumL(TInt& aEnum, const TDesC& aName, const TDesC& aDescription, const TDesC& aCommaSeparatedValueList, TUint aFlags = 0, const TDesC& aEnvVar = KNullDesC); |
|
554 IMPORT_C void AppendEnumL(TInt& aEnum, const TDesC& aName, const TDesC& aDescription, const TDesC& aCommaSeparatedValueList, const TDesC& aCommaSeparatedDescriptionList, TUint aFlags = 0, const TDesC& aEnvVar = KNullDesC); |
|
555 IMPORT_C void AppendEnumL(RArray<TInt>& aEnum, const TDesC& aName, const TDesC& aDescription, const TDesC& aCommaSeparatedValueList, TUint aFlags = 0, const TDesC& aEnvVar = KNullDesC); // Be sure to pass an actual RArray<TInt>& here, not an RArray<TSomeEnum>&. Internally, CCommandBase casts whatever you pass in to an RArray<TInt> and this is a specialized template with a different memory layout to the general version. |
|
556 IMPORT_C void AppendEnumL(RArray<TInt>& aEnum, const TDesC& aName, const TDesC& aDescription, const TDesC& aCommaSeparatedValueList, const TDesC& aCommaSeparatedDescriptionList, TUint aFlags = 0, const TDesC& aEnvVar = KNullDesC); // Be sure to pass an actual RArray<TInt>& here, not an RArray<TSomeEnum>&. Internally, CCommandBase casts whatever you pass in to an RArray<TInt> and this is a specialized template with a different memory layout to the general version. |
|
557 |
|
558 IMPORT_C TBool IsPresent(TInt aIndex) const; |
|
559 IMPORT_C TBool IsPresent(void* aValuePointer) const; |
|
560 IMPORT_C TPtrC AsString(void* aValuePointer) const; |
|
561 void Close(); |
|
562 IMPORT_C TInt Count() const; |
|
563 TCommandArgument& operator[](TInt aIndex); |
|
564 IMPORT_C const TCommandArgument& operator[](TInt aIndex) const; |
|
565 IMPORT_C TBool AllSet() const; |
|
566 TInt Find(const TDesC& aName) const; |
|
567 private: |
|
568 void Validate(const TCommandArgument& aArgument); |
|
569 private: |
|
570 RArray<TCommandArgument> iArguments; |
|
571 }; |
|
572 |
|
573 |
|
574 class CCommandInfoFile : public CBase |
|
575 { |
|
576 public: |
|
577 IMPORT_C static CCommandInfoFile* NewL(RFs& aFs, const TDesC& aFileName); |
|
578 IMPORT_C static CCommandInfoFile* NewL(RFs& aFs, const CEnvironment& aEnvironment, const TDesC& aCommandName); |
|
579 IMPORT_C ~CCommandInfoFile(); |
|
580 IMPORT_C const TDesC& Name() const; |
|
581 IMPORT_C const TDesC& ShortDescription() const; |
|
582 IMPORT_C const TDesC& LongDescription() const; |
|
583 IMPORT_C const TDesC& SeeAlso() const; |
|
584 IMPORT_C const TDesC& Copyright() const; |
|
585 IMPORT_C const RCommandArgumentList& Arguments(); |
|
586 IMPORT_C const RCommandOptionList& Options() const; |
|
587 IMPORT_C void AssignL(RCommandArgumentList& aArguments, RCommandOptionList& aOptions) const; |
|
588 IMPORT_C TInt NumSubCommands() const; |
|
589 IMPORT_C const CCommandInfoFile& SubCommand(TInt aIndex) const; |
|
590 IMPORT_C const CCommandInfoFile* SubCommand(const TDesC& aSubCommandName) const; |
|
591 private: |
|
592 CCommandInfoFile(const TDesC& aFileName); |
|
593 CCommandInfoFile(CCommandInfoFile& aParent); |
|
594 void ConstructL(RFs& aFs); |
|
595 void ReadFileL(RFs& aFs, const TDesC& aFileName); |
|
596 void ReadDetailsL(TLex& aLex, RFs& aFs, const TDesC& aFileName); |
|
597 void ReadArgumentL(TLex& aLex, const TDesC& aFileName); |
|
598 void ReadOptionL(TLex& aLex, const TDesC& aFileName); |
|
599 void ProcessNewChild(); |
|
600 void ProcessInclude(CCommandInfoFile& aChild); |
|
601 void AddSubCommandL(TLex& aNameLex, TLex& aDataLex, RFs& aFs, const TDesC& aFileName); |
|
602 RBuf& NewBuffer(); |
|
603 private: |
|
604 TFileName iFileName; |
|
605 TPtrC iName; |
|
606 TPtrC iShortDescription; |
|
607 TPtrC iLongDescription; |
|
608 TPtrC iSeeAlso; |
|
609 TPtrC iCopyright; |
|
610 RCommandArgumentList iArguments; |
|
611 RCommandOptionList iOptions; |
|
612 RArray<RBuf> iBufs; |
|
613 RPointerArray<CCommandInfoFile> iChildren; |
|
614 CCommandInfoFile* iParent; |
|
615 CCommandInfoFile* iCurrentChild; |
|
616 TBool iProcessInclude; |
|
617 }; |
|
618 |
|
619 |
|
620 class Stringify |
|
621 { |
|
622 public: |
|
623 enum TReadMode |
|
624 { |
|
625 EBreakOnComma = 0x00000001 // The default behaviour is to break on white space. If this flag is set both commas and white space (that are unquoted / escaped) will cause reading of the string to terminate. |
|
626 }; |
|
627 public: |
|
628 IMPORT_C static const TDesC* Error(TInt aError); |
|
629 IMPORT_C static HBufC* ReadLC(TLex& aLex, const TChar& aEscapeChar); |
|
630 IMPORT_C static HBufC* ReadLC(TLex& aLex, const TChar& aEscapeChar, CCommandBase& aErrorContext); |
|
631 IMPORT_C static HBufC* ReadLC(TLex& aLex, const TChar& aEscapeChar, TUint aReadMode); |
|
632 IMPORT_C static HBufC* ReadLC(TLex& aLex, const TChar& aEscapeChar, CCommandBase& aErrorContext, TUint aReadMode); |
|
633 IMPORT_C static HBufC* WidenLC(const TDesC8& aDes); |
|
634 IMPORT_C static HBufC8* NarrowLC(const TDesC& aDes); |
|
635 IMPORT_C static HBufC* EscapeLC(const TDesC& aDes, const TChar& aEscapeChar); |
|
636 IMPORT_C static HBufC8* EscapeLC(const TDesC8& aDes, const TChar& aEscapeChar); |
|
637 private: |
|
638 static HBufC* ReadLC(TLex& aLex, const TChar& aEscapeChar, CCommandBase* aErrorContext, TUint aReadMode); |
|
639 }; |
|
640 |
|
641 class CCommandBase : public CActive |
|
642 { |
|
643 public: |
|
644 enum TFlags |
|
645 { |
|
646 EManualComplete = 0x00000001, |
|
647 ESharableIoSession = 0x00000002, |
|
648 EReportAllErrors = 0x00000004, |
|
649 ENotifyStdinChanges = 0x00000008, |
|
650 //EDeprecated = 0x00000010, |
|
651 ECompleteOnRunL = 0x00000020, |
|
652 }; |
|
653 public: |
|
654 IMPORT_C ~CCommandBase(); |
|
655 IMPORT_C TInt RunCommand(); |
|
656 IMPORT_C void RunCommandL(); |
|
657 IMPORT_C TInt RunCommand(const TDesC* aCommandLine, CEnvironment* aEnv); |
|
658 IMPORT_C void RunCommandL(const TDesC* aCommandLine, CEnvironment* aEnv); |
|
659 IMPORT_C TInt RunCommand(RIoSession& aIoSession, RIoReadHandle& aStdin, RIoWriteHandle& aStdout, RIoWriteHandle& aStderr, const TDesC* aCommandLine, CEnvironment* aEnv); |
|
660 IMPORT_C void RunCommandL(RIoSession& aIoSession, RIoReadHandle& aStdin, RIoWriteHandle& aStdout, RIoWriteHandle& aStderr, const TDesC* aCommandLine, CEnvironment* aEnv); |
|
661 IMPORT_C void RunCommand(RIoSession& aIoSession, RIoReadHandle& aStdin, RIoWriteHandle& aStdout, RIoWriteHandle& aStderr, const TDesC* aCommandLine, CEnvironment* aEnv, MCommandBaseObserver* aObserver); |
|
662 IMPORT_C TUint Flags() const; |
|
663 IMPORT_C void SetFlags(TUint aFlags); |
|
664 IMPORT_C const RFs& Fs() const; |
|
665 IMPORT_C const RFs& FsL() const; |
|
666 IMPORT_C RFs& Fs(); |
|
667 IMPORT_C RFs& FsL(); |
|
668 IMPORT_C RIoSession& IoSession(); |
|
669 IMPORT_C RIoConsoleReadHandle& Stdin(); |
|
670 IMPORT_C RIoConsoleWriteHandle& Stdout(); |
|
671 IMPORT_C RIoConsoleWriteHandle& Stderr(); |
|
672 IMPORT_C void Complete(); |
|
673 IMPORT_C void Complete(TRefByValue<const TDesC> aFmt, ...); |
|
674 IMPORT_C void Complete(TInt aError); |
|
675 IMPORT_C void Complete(TInt aError, TRefByValue<const TDesC> aFmt, ...); |
|
676 IMPORT_C void CompleteAsync(TInt aError); |
|
677 IMPORT_C void CompleteAsync(TInt aError, TRefByValue<const TDesC> aFmt, ...); |
|
678 IMPORT_C CEnvironment& Env(); |
|
679 IMPORT_C const CEnvironment& Env() const; |
|
680 IMPORT_C void ReadL(TDes& aData); |
|
681 IMPORT_C void Write(const TDesC& aData); |
|
682 IMPORT_C void Printf(TRefByValue<const TDesC> aFmt, ...); |
|
683 IMPORT_C void Printf(TRefByValue<const TDesC8> aFmt, ...); |
|
684 IMPORT_C void PrintError(TInt aError, TRefByValue<const TDesC> aFmt, ...); |
|
685 IMPORT_C void PrintWarning(TRefByValue<const TDesC> aFmt, ...); |
|
686 IMPORT_C void LeaveIfFileExists(const TDesC& aFileName); |
|
687 IMPORT_C void LeaveIfFileNotFound(const TDesC& aFileName); |
|
688 IMPORT_C CConsoleBase* GetConsoleBaseL(); |
|
689 IMPORT_C CColorConsoleBase* GetColorConsoleBaseL(); |
|
690 IMPORT_C const TDesC* ConsoleImplementation(); |
|
691 IMPORT_C void SetErrorReported(TBool aReported); |
|
692 IMPORT_C void StartSupressingErrors(); |
|
693 IMPORT_C void StopSupressingErrors(); |
|
694 IMPORT_C TBool IsComplete() const; |
|
695 IMPORT_C TInt CompletionReason() const; |
|
696 IMPORT_C virtual void HandleLeave(TInt aError); |
|
697 IMPORT_C virtual const CTextBuffer* GetHelpTextL(); |
|
698 IMPORT_C virtual void PrintList(TRefByValue<const TDesC> aFmt, VA_LIST& aList); |
|
699 IMPORT_C virtual void PrintList(TRefByValue<const TDesC8> aFmt, VA_LIST& aList); |
|
700 IMPORT_C virtual void PrintErrorList(TInt aError, TRefByValue<const TDesC> aFmt, VA_LIST& aList); |
|
701 IMPORT_C virtual void PrintWarningList(TRefByValue<const TDesC> aFmt, VA_LIST& aList); |
|
702 IMPORT_C static CCommandBase& Static(); |
|
703 IMPORT_C static TBool HaveStatic(); |
|
704 IMPORT_C virtual void StdinChange(TUint aChange); |
|
705 IMPORT_C void DisplayHelp(); |
|
706 IMPORT_C void PageL(const CTextBuffer& aText); |
|
707 IMPORT_C void PageL(RIoReadHandle& aInput); |
|
708 IMPORT_C TBool UsingCif() const; |
|
709 |
|
710 public: |
|
711 virtual const TDesC& Name() const = 0; |
|
712 IMPORT_C virtual const TDesC& Description() const; |
|
713 protected: |
|
714 IMPORT_C CCommandBase(); |
|
715 IMPORT_C CCommandBase(TUint aFlags); |
|
716 IMPORT_C virtual void BaseConstructL(); |
|
717 IMPORT_C void CreateEnvironmentL(CEnvironment* aEnv); |
|
718 |
|
719 protected: |
|
720 virtual void DoRunL() = 0; |
|
721 IMPORT_C virtual void OptionsL(RCommandOptionList& aOptions); |
|
722 IMPORT_C virtual void ArgumentsL(RCommandArgumentList& aArguments); |
|
723 IMPORT_C virtual TInt ParseCommandLine(const TDesC& aCommandLine); |
|
724 IMPORT_C virtual void ParseCommandLineL(const TDesC& aCommandLine); |
|
725 IMPORT_C virtual TInt Extension_(TUint aExtensionId, TAny*& a0, TAny* a1); |
|
726 private: |
|
727 enum TPrivateFlags // Must not exceed 0xffff0000 (KPrivateFlagsMask). |
|
728 { |
|
729 EOwnsEnv = 0x80000000, |
|
730 EOwnsHandles = 0x40000000, |
|
731 ETlsSet = 0x20000000, |
|
732 ECompleted = 0x10000000, |
|
733 EErrorReported = 0x08000000, |
|
734 EReadCif = 0x04000000, |
|
735 ECifReadFailed = 0x02000000, |
|
736 EOwnsCif = 0x01000000 |
|
737 }; |
|
738 enum TReadStringOptions |
|
739 { |
|
740 EDisallowLeadingHyphen = 0x00000001, |
|
741 EIncludeWhiteSpace = 0x00000002, |
|
742 EBreakOnComma = 0x00000004 // The default behaviour is to break on white space. If this flag is set both commas and white space (that are unquoted / escaped) will cause reading of the string to terminate. |
|
743 }; |
|
744 protected: |
|
745 IMPORT_C void SetCif(const CCommandInfoFile& aCif); |
|
746 IMPORT_C const CCommandInfoFile* Cif() const; |
|
747 private: |
|
748 void RunCommandL(RIoSession& aIoSession, RIoReadHandle& aStdin, RIoWriteHandle& aStdout, RIoWriteHandle& aStderr, const TDesC* aCommandLine, CEnvironment* aEnv, MCommandBaseObserver* aObserver); |
|
749 void RunL(const TDesC& aCommandLine); |
|
750 void SetValueL(TLex& aLex, TValue& aValue); |
|
751 void SetValueFromEnvL(TValue& aValue); |
|
752 void ClearValueL(TValue& aValue); |
|
753 const TDesC* ReadCommandLineLC(); |
|
754 void DisplayHelpAndComplete(); |
|
755 void DisplayHelpAndComplete(TInt aError, const TDesC& aText); |
|
756 void CreateHandlesL(); |
|
757 void UpdateHandlesL(); |
|
758 void DoCreateHandlesL(RIoConsole& aConsole, RIoConsoleReadHandle& aStdin, RIoConsoleWriteHandle& aStdout, RIoConsoleWriteHandle& aStderr); |
|
759 HBufC* ReadStringLC(TLex& aLex, TUint aOptions) const; |
|
760 void FormatErrorText(TDes& aDes, TInt aError, TRefByValue<const TDesC> aFmt, VA_LIST& aList) const; |
|
761 void FormatWarningText(TDes& aDes, TRefByValue<const TDesC> aFmt, VA_LIST& aList) const; |
|
762 void CheckNewLine(); |
|
763 void FormatEnumL(const TValue& aValue, CTextBuffer& aBuffer) const; |
|
764 void PageL(MLineReader& aLineReader); |
|
765 void DoParseCommandLineL(const TDesC& aCommandLine); |
|
766 TBool CifReadRequired() const; |
|
767 void ReadCifL(); |
|
768 void DoReadCifL(); |
|
769 private: |
|
770 friend class CCommandCompleter; |
|
771 void CompleteCallback(TInt aError); |
|
772 protected: // From CActive. |
|
773 IMPORT_C virtual void RunL(); |
|
774 IMPORT_C virtual void DoCancel(); |
|
775 IMPORT_C virtual TInt RunError(TInt aError); |
|
776 protected: |
|
777 RCommandOptionList iOptions; |
|
778 RCommandArgumentList iArguments; |
|
779 private: |
|
780 TUint iFlags; |
|
781 CEnvironment* iEnv; |
|
782 MCommandBaseObserver* iObserver; |
|
783 mutable RFs iFs; |
|
784 RIoSession iIoSession; |
|
785 RIoConsoleReadHandle iStdin; |
|
786 RIoConsoleWriteHandle iStdout; |
|
787 RIoConsoleWriteHandle iStderr; |
|
788 TBool iDisplayHelp; |
|
789 TInt iSupressingErrors; |
|
790 HBufC* iConsoleImplementation; |
|
791 HBufC* iConsoleTitle; |
|
792 RArray<TUint> iConsoleSize; |
|
793 TBool* iDeleted; |
|
794 HBufC* iPersistentConsoleName; |
|
795 CCommandCompleter* iCompleter; |
|
796 CReaderChangeNotifier* iReadChangeNotifier; |
|
797 TInt iCompletionReason; |
|
798 CCommandInfoFile* iCif; |
|
799 void* iSpare1; |
|
800 void* iSpare2; |
|
801 void* iSpare3; |
|
802 void* iSpare4; |
|
803 void* iSpare5; |
|
804 }; |
|
805 |
|
806 |
|
807 /** |
|
808 * @brief A helper class for creating and running child processes that share |
|
809 * I/O handles (and hence console and / or redirected file handles) with the parent. |
|
810 * |
|
811 * Note, CreateL just creates the process; it doesn't start its main thread. This |
|
812 * can either be done by calling RChildProcess::Process().Resume() or calling |
|
813 * RChildProcess::Run. Either way it is important that the newly created process |
|
814 * is given a chance to open its I/O handles before RChildProcess::Close is called. |
|
815 * Otherwise the server side objects will be destroyed before it has had a chance |
|
816 * to claim a reference count on them. The easiest way to achieve this is by using |
|
817 * RChildProcess::Run, and waiting until the associated TRequestStatus is completed |
|
818 * before calling RChildProcess::Close. The TRequestStatus will be completed when |
|
819 * the child process exits. |
|
820 */ |
|
821 class RChildProcess |
|
822 { |
|
823 public: |
|
824 IMPORT_C void Close(); |
|
825 IMPORT_C void CreateL(const TDesC& aExecutableName, const TDesC& aCommandLine, RIoSession& aIoSession, RIoReadHandle& aStdin, RIoWriteHandle& aStdout, RIoWriteHandle& aStderr); |
|
826 IMPORT_C void CreateL(const TDesC& aExecutableName, const TDesC& aCommandLine, RIoSession& aIoSession, RIoReadHandle& aStdin, RIoWriteHandle& aStdout, RIoWriteHandle& aStderr, const CEnvironment& aEnv); |
|
827 IMPORT_C void CreateL(const TDesC& aExecutableName, const TDesC& aCommandLine, RIoSession& aIoSession, RIoConsole& aConsole, const CEnvironment* aEnv); |
|
828 IMPORT_C void Run(TRequestStatus& aStatus); |
|
829 IMPORT_C void Detach(); |
|
830 IMPORT_C RProcess& Process(); |
|
831 IMPORT_C const RProcess& Process() const; |
|
832 private: |
|
833 void NameHandles(const TDesC& aExecutableName, RIoSession& aIoSession); |
|
834 void DoCreateL(const TDesC& aExecutableName, const TDesC& aCommandLine, RIoSession& aIoSession, RIoReadHandle& aStdin, RIoWriteHandle& aStdout, RIoWriteHandle& aStderr, const CEnvironment* aEnv); |
|
835 void ProcessCreateL(const TDesC& aExecutableName, const TDesC& aCommandLine, const CEnvironment* aEnv); |
|
836 private: |
|
837 RProcess iProcess; |
|
838 RIoReadHandle iStdin; |
|
839 RIoWriteHandle iStdout; |
|
840 RIoWriteHandle iStderr; |
|
841 }; |
|
842 |
|
843 IMPORT_C CConsoleBase* NewConsole(); // Only for use by iocons |
|
844 IMPORT_C void ReadL(TDes& aData); |
|
845 IMPORT_C void Write(const TDesC& aData); |
|
846 IMPORT_C void Printf(TRefByValue<const TDesC> aFmt, ...); |
|
847 IMPORT_C void Printf(TRefByValue<const TDesC8> aFmt, ...); |
|
848 IMPORT_C void PrintError(TInt aError, TRefByValue<const TDesC> aFmt, ...); |
|
849 IMPORT_C void PrintWarning(TRefByValue<const TDesC> aFmt, ...); |
|
850 |
|
851 |
|
852 class CServerWatcher; |
|
853 class CServerReader; |
|
854 class CServerWriter; |
|
855 |
|
856 /** |
|
857 * @brief The base class for command server client commands. |
|
858 * |
|
859 * Normally, CCommandBase derived objects are run in the context of a separate |
|
860 * process (or possibly thread). This process (or thread) only exists until |
|
861 * the command completes. This makes it difficult of such commands to maintain |
|
862 * state between repeated invokations. |
|
863 * |
|
864 * Command servers are a means of addressing this limitation. They are implemented |
|
865 * as a CCommandBase (actually a CServerBase) sub-class that runs in its own |
|
866 * process. However, the stdin and stdout handles of this command are not attached |
|
867 * directly to a console (or set of pipes) as is normally the case. Instead they are |
|
868 * attached to a persistent console (RIoPersistentConsole). This type of console |
|
869 * allows a real console (or set of pipes) to be transiently connected and then |
|
870 * disconnected without the server command being aware that this has happend. This |
|
871 * allows a client command to temporarily connect to the server command's stdio, |
|
872 * issue a command, and receive a response. This can happen numerous times to a |
|
873 * single server command instance, which allows the server command to maintain |
|
874 * state. |
|
875 * |
|
876 * Generally, server commands implement a set of internal commands that are |
|
877 * themselves CCommandBase (actually CServerCommandBase or CBranchCommandBase) |
|
878 * sub-classes. These are created as required inside the command server process |
|
879 * in response to client command requests. |
|
880 * |
|
881 * There is generally a single sub-class of this class (that is built into an |
|
882 * executable) to interact with a given server command. Its job is to: |
|
883 * |
|
884 * a) Create the server command process if its not already running. |
|
885 * b) Create a pair of pipes that are connected to the server command's |
|
886 * persistent console. |
|
887 * c) Issue a command to the server (normally read from the command-line of |
|
888 * this command). |
|
889 * d) Retrieve a response from the server. |
|
890 * e) Possibly parse the server response. |
|
891 * f) Print a result to this command's stdout (which, note, is completely |
|
892 * independent of the server command's stdout). |
|
893 * g) Exit with an integer value indicating the success or failure of the |
|
894 * command. |
|
895 * |
|
896 * This base class takes care of (a) - (d). The concrete sub-class is responsible |
|
897 * for (e) - (g). |
|
898 */ |
|
899 class CClientBase : public CCommandBase |
|
900 { |
|
901 protected: |
|
902 IMPORT_C CClientBase(TUint aFlags, const TDesC& aServerExeName, const TDesC& aPersistentConsoleName, const TDesC& aServerPrompt); |
|
903 IMPORT_C ~CClientBase(); |
|
904 private: |
|
905 virtual void HandleServerResponseL(RPointerArray<HBufC> aLines) = 0; |
|
906 private: // From CCommandBase. |
|
907 IMPORT_C virtual void DoRunL(); |
|
908 IMPORT_C virtual void ArgumentsL(RCommandArgumentList& aArguments); |
|
909 IMPORT_C virtual void HandleLeave(TInt aError); |
|
910 private: |
|
911 friend class CServerWatcher; |
|
912 friend class CServerReader; |
|
913 friend class CServerWriter; |
|
914 void HandleServerReadComplete(TInt aError, TDes& aLine); |
|
915 void HandleServerWriteComplete(TInt aError); |
|
916 void HandleServerDeath(TExitType aExitType, TInt aExitReason, const TDesC& aExitCategory); |
|
917 void SendCommand(); |
|
918 protected: |
|
919 TBool iVerbose; |
|
920 private: |
|
921 const TPtrC iServerExeName; |
|
922 const TPtrC iPersistentConsoleName; |
|
923 const TPtrC iServerPrompt; |
|
924 HBufC* iCommand; |
|
925 RChildProcess iServerProcess; |
|
926 RIoPersistentConsole iPcons; |
|
927 RIoPipe iServerWritePipe; |
|
928 RIoWriteHandle iServerWriteHandle; |
|
929 RIoPipe iServerReadPipe; |
|
930 RIoReadHandle iServerReadHandle; |
|
931 CServerWatcher* iServerWatcher; |
|
932 CServerReader* iServerReader; |
|
933 CServerWriter* iServerWriter; |
|
934 RPointerArray<HBufC> iLines; |
|
935 TBool iWaitingForServerPrompt; |
|
936 }; |
|
937 |
|
938 |
|
939 /** |
|
940 * @brief A class used to identify instances of individual commands running inside |
|
941 * a command server (which is a CServerBase sub-class). |
|
942 * |
|
943 * Note, it is up to a suitable sub-class (of usually CBranchCommandBase) to assign |
|
944 * these identifiers via CServerCommandBase::SetId. |
|
945 */ |
|
946 class TServerCommandId |
|
947 { |
|
948 public: |
|
949 IMPORT_C TServerCommandId(); |
|
950 IMPORT_C TServerCommandId(TUint aValue); |
|
951 IMPORT_C TUint Value() const; |
|
952 IMPORT_C void Set(const TServerCommandId& aId); |
|
953 IMPORT_C TBool operator==(const TServerCommandId& aId) const; |
|
954 private: |
|
955 TUint iId; |
|
956 }; |
|
957 |
|
958 |
|
959 /** |
|
960 * @brief An interface used by CServerCommandBase to report information to the server's |
|
961 * user. |
|
962 * |
|
963 * Note, this class is not intended for external derivation. Rather, sub-classes of |
|
964 * CServerBase must provide an implementation of its simplified pure virtual interface |
|
965 * (Report, ReportWarning and ReportError). |
|
966 */ |
|
967 class MServerCommandReporter |
|
968 { |
|
969 public: |
|
970 virtual void Report(const TServerCommandId& aId, TRefByValue<const TDesC> aFmt, ...) = 0; |
|
971 virtual void ReportList(const TServerCommandId& aId, TRefByValue<const TDesC> aFmt, VA_LIST& aList) = 0; |
|
972 virtual void Report(const TServerCommandId& aId, TRefByValue<const TDesC8> aFmt, ...) = 0; |
|
973 virtual void ReportList(const TServerCommandId& aId, TRefByValue<const TDesC8> aFmt, VA_LIST& aList) = 0; |
|
974 virtual void ReportWarning(const TServerCommandId& aId, TRefByValue<const TDesC> aFmt, ...) = 0; |
|
975 virtual void ReportWarningList(const TServerCommandId& aId, TRefByValue<const TDesC> aFmt, VA_LIST& aList) = 0; |
|
976 virtual void ReportError(const TServerCommandId& aId, TInt aError, TRefByValue<const TDesC> aFmt, ...) = 0; |
|
977 virtual void ReportErrorList(const TServerCommandId& aId, TInt aError, TRefByValue<const TDesC> aFmt, VA_LIST& aList) = 0; |
|
978 }; |
|
979 |
|
980 |
|
981 class CServerCommandFactory; |
|
982 |
|
983 /** |
|
984 * @brief The base class for command servers. |
|
985 * |
|
986 * Each command server is expected to create one (and only one) sub-class of this class. It is |
|
987 * effectively the root object of the server and is responsible for parsing input received on stdin |
|
988 * and creates corresponding command objects accordingly. Note, all textual responses from the |
|
989 * server's commands are routed through the sub-class of this class via its pure virtual interface. |
|
990 * Note also, only one call to ReportError will be received for a given line read from stdin. |
|
991 */ |
|
992 class CServerBase : public CCommandBase, public MServerCommandReporter, public MLineEditorObserver |
|
993 { |
|
994 public: |
|
995 IMPORT_C ~CServerBase(); |
|
996 IMPORT_C void Exit(TInt aError); |
|
997 protected: |
|
998 IMPORT_C CServerBase(TUint aFlags, const TDesC& aPrompt, const TDesC& aCommandHistoryFileName); |
|
999 IMPORT_C CServerCommandFactory& Factory(); |
|
1000 IMPORT_C void CheckNewConsoleLine(); |
|
1001 protected: |
|
1002 virtual void InitializeL() = 0; |
|
1003 virtual void Report(const TServerCommandId& aId, const TDesC& aDes) = 0; |
|
1004 virtual void Report(const TServerCommandId& aId, const TDesC8& aDes) = 0; |
|
1005 virtual void ReportWarning(const TServerCommandId& aId, const TDesC& aDes) = 0; |
|
1006 virtual void ReportError(const TServerCommandId& aId, TInt aError, const TDesC& aDes) = 0; |
|
1007 protected: // From CCommandBase. |
|
1008 IMPORT_C virtual void BaseConstructL(); |
|
1009 IMPORT_C virtual void DoRunL(); |
|
1010 IMPORT_C virtual void PrintList(TRefByValue<const TDesC> aFmt, VA_LIST& aList); |
|
1011 IMPORT_C virtual void PrintList(TRefByValue<const TDesC8> aFmt, VA_LIST& aList); |
|
1012 IMPORT_C virtual void PrintErrorList(TInt aError, TRefByValue<const TDesC> aFmt, VA_LIST& aList); |
|
1013 IMPORT_C virtual void PrintWarningList(TRefByValue<const TDesC> aFmt, VA_LIST& aList); |
|
1014 private: // From MServerCommandReporter. |
|
1015 IMPORT_C virtual void Report(const TServerCommandId& aId, TRefByValue<const TDesC> aFmt, ...); |
|
1016 IMPORT_C virtual void ReportList(const TServerCommandId& aId, TRefByValue<const TDesC> aFmt, VA_LIST& aList); |
|
1017 IMPORT_C virtual void Report(const TServerCommandId& aId, TRefByValue<const TDesC8> aFmt, ...); |
|
1018 IMPORT_C virtual void ReportList(const TServerCommandId& aId, TRefByValue<const TDesC8> aFmt, VA_LIST& aList); |
|
1019 IMPORT_C virtual void ReportWarning(const TServerCommandId& aId, TRefByValue<const TDesC> aFmt, ...); |
|
1020 IMPORT_C virtual void ReportWarningList(const TServerCommandId& aId, TRefByValue<const TDesC> aFmt, VA_LIST& aList); |
|
1021 IMPORT_C virtual void ReportError(const TServerCommandId& aId, TInt aError, TRefByValue<const TDesC> aFmt, ...); |
|
1022 IMPORT_C virtual void ReportErrorList(const TServerCommandId& aId, TInt aError, TRefByValue<const TDesC> aFmt, VA_LIST& aList); |
|
1023 private: // From MLineEditorObserver. |
|
1024 IMPORT_C virtual void LeoHandleLine(const TDesC& aLine); |
|
1025 private: |
|
1026 void ParseLineL(const TDesC& aLine); |
|
1027 const TDesC& NextLineL(); |
|
1028 private: |
|
1029 const TDesC& iPrompt; |
|
1030 const TDesC& iCommandHistoryFileName; |
|
1031 TBuf<512> iLine; |
|
1032 CLineEditor* iLineEditor; |
|
1033 CServerCommandFactory* iFactory; |
|
1034 TIoConsWriterAdaptor iWriterAdaptor; |
|
1035 TBool iLineRead; |
|
1036 TBool iExit; |
|
1037 TInt iExitReason; |
|
1038 TBool iErrorReported; |
|
1039 }; |
|
1040 |
|
1041 |
|
1042 class CServerCommandConstructor; |
|
1043 |
|
1044 /** |
|
1045 * @brief The base class for commands that run within a command server. |
|
1046 * |
|
1047 * A class should be derived from this class for each "leaf" command of |
|
1048 * the server. A leaf command is one that doesn't support any sub-commands |
|
1049 * (see CBranchCommand for details of commands that do support sub-commands). |
|
1050 * Each sub-class must be registered with a CServerCommandFactory object |
|
1051 * via the template method AddLeafCommandL. |
|
1052 */ |
|
1053 class CServerCommandBase : public CCommandBase |
|
1054 { |
|
1055 public: |
|
1056 IMPORT_C virtual ~CServerCommandBase(); |
|
1057 IMPORT_C const TServerCommandId& Id() const; |
|
1058 IMPORT_C void SetId(const TServerCommandId& aId); |
|
1059 IMPORT_C void SetFactory(CServerCommandFactory& aFactory); |
|
1060 protected: |
|
1061 IMPORT_C CServerCommandBase(); |
|
1062 IMPORT_C CServerCommandBase(TUint aFlags); |
|
1063 IMPORT_C CServerCommandFactory& Factory(); |
|
1064 private: // From CCommandBase. |
|
1065 IMPORT_C virtual void PrintList(TRefByValue<const TDesC> aFmt, VA_LIST& aList); |
|
1066 IMPORT_C virtual void PrintList(TRefByValue<const TDesC8> aFmt, VA_LIST& aList); |
|
1067 IMPORT_C virtual void PrintErrorList(TInt aError, TRefByValue<const TDesC> aFmt, VA_LIST& aList); |
|
1068 IMPORT_C virtual void PrintWarningList(TRefByValue<const TDesC> aFmt, VA_LIST& aList); |
|
1069 private: |
|
1070 friend class CServerBase; |
|
1071 friend class CServerCommandConstructor; |
|
1072 void SetReporter(MServerCommandReporter* aReporter); |
|
1073 private: |
|
1074 TServerCommandId iId; |
|
1075 MServerCommandReporter* iReporter; |
|
1076 CServerCommandFactory* iFactory; |
|
1077 }; |
|
1078 |
|
1079 |
|
1080 typedef CServerCommandBase* (*TServerCommandConstructor)(); |
|
1081 |
|
1082 /** |
|
1083 * @brief A helper class for CServerCommandFactory used to store a means of |
|
1084 * constructing leaf commands. |
|
1085 */ |
|
1086 class CServerCommandConstructor : public CBase |
|
1087 { |
|
1088 public: |
|
1089 IMPORT_C static CServerCommandConstructor* NewLC(const TDesC& aName, TServerCommandConstructor aConstructor, CServerCommandFactory& aFactory, MServerCommandReporter* aReporter, const CCommandInfoFile* aCif); |
|
1090 IMPORT_C ~CServerCommandConstructor(); |
|
1091 IMPORT_C const TPtrC& Name() const; |
|
1092 IMPORT_C CServerCommandBase* CreateImplementationLC() const; |
|
1093 IMPORT_C virtual TBool IsFactory() const; |
|
1094 protected: |
|
1095 CServerCommandConstructor(const TDesC& aName, TServerCommandConstructor aConstructor, CServerCommandFactory& aFactory, MServerCommandReporter* aReporter, const CCommandInfoFile* aCif); |
|
1096 protected: |
|
1097 TPtrC iName; |
|
1098 TServerCommandConstructor iConstructorLC; |
|
1099 CServerCommandFactory& iFactory; |
|
1100 MServerCommandReporter* iReporter; |
|
1101 const CCommandInfoFile* iCif; |
|
1102 }; |
|
1103 |
|
1104 |
|
1105 /** |
|
1106 * @brief A class that can be used to manage a hierarchy of commands. |
|
1107 */ |
|
1108 class CServerCommandFactory : public CServerCommandConstructor, public MLineCompleter |
|
1109 { |
|
1110 public: |
|
1111 IMPORT_C static CServerCommandFactory* NewL(MServerCommandReporter* aReporter, const CCommandInfoFile* aCif); |
|
1112 IMPORT_C static CServerCommandFactory* NewLC(const TDesC& aName, TServerCommandConstructor aConstructor, MServerCommandReporter* aReporter, const CCommandInfoFile* aCif); |
|
1113 IMPORT_C ~CServerCommandFactory(); |
|
1114 IMPORT_C const CServerCommandConstructor& GetSubCommandL(const TDesC& aName) const; |
|
1115 IMPORT_C virtual TBool IsFactory() const; |
|
1116 template <class SubCmnd> inline CServerCommandConstructor& AddLeafCommandL(); |
|
1117 template <class SubCmnd> inline CServerCommandFactory& AddFactoryCommandL(); |
|
1118 IMPORT_C void ListCommandsL(RArray<TPtrC>& aList) const; |
|
1119 private: // From MLineCompleter. |
|
1120 virtual void LcCompleteLineL(TConsoleLine& aLine, const TChar& aEscapeChar); |
|
1121 private: |
|
1122 enum TFactoryType |
|
1123 { |
|
1124 ERoot, |
|
1125 EBranch |
|
1126 }; |
|
1127 private: |
|
1128 CServerCommandFactory(MServerCommandReporter* aReporter, const CCommandInfoFile* aCif); |
|
1129 CServerCommandFactory(const TDesC& aName, TServerCommandConstructor aConstructor, MServerCommandReporter* aReporter, const CCommandInfoFile* aCif); |
|
1130 void ConstructL(TFactoryType aType); |
|
1131 void CompleteLineL(TConsoleLine& aLine, TInt aPos, const RArray<TPtrC> aPossibilities) const; |
|
1132 const CServerCommandConstructor* GetSubCommand(const TDesC& aName) const; |
|
1133 IMPORT_C void AddSubCommandL(const CServerCommandConstructor* aCommand); |
|
1134 private: |
|
1135 RHashMap<const TPtrC, const CServerCommandConstructor*> iSubCommands; |
|
1136 }; |
|
1137 |
|
1138 |
|
1139 /** |
|
1140 * @brief The base class for commands that support multiple sub-commands. |
|
1141 */ |
|
1142 class CBranchCommandBase : public CServerCommandBase |
|
1143 { |
|
1144 public: |
|
1145 IMPORT_C virtual ~CBranchCommandBase(); |
|
1146 protected: |
|
1147 IMPORT_C CBranchCommandBase(); |
|
1148 IMPORT_C virtual const TDesC& TypeDescription(); |
|
1149 IMPORT_C virtual void ConfigureSubCommand(CServerCommandBase& aNewlyConstructedCommand); |
|
1150 IMPORT_C virtual void HandleSubCommandComplete(CServerCommandBase& aCommand); |
|
1151 IMPORT_C virtual void HandleBackgroundSubCommand(CServerCommandBase& aCommand); |
|
1152 private: |
|
1153 void BuildEnumL(); |
|
1154 private: // From CCommandBase. |
|
1155 IMPORT_C virtual void DoRunL(); |
|
1156 IMPORT_C virtual void ArgumentsL(RCommandArgumentList& aArguments); |
|
1157 private: |
|
1158 IoUtils::CTextBuffer* iSubCommandEnum; |
|
1159 HBufC* iSubCommandArgs; |
|
1160 TInt iType; |
|
1161 }; |
|
1162 |
|
1163 #include <fshell/ioutils.inl> |
|
1164 |
|
1165 } // Closing namespace brace. |
|
1166 |
|
1167 |
|
1168 #define EXE_BOILER_PLATE(__CLASS_NAME) \ |
|
1169 void MainL()\ |
|
1170 {\ |
|
1171 CActiveScheduler* scheduler = new(ELeave) CActiveScheduler;\ |
|
1172 CleanupStack::PushL(scheduler);\ |
|
1173 CActiveScheduler::Install(scheduler);\ |
|
1174 IoUtils::CCommandBase* command = __CLASS_NAME::NewLC();\ |
|
1175 command->RunCommandL();\ |
|
1176 CleanupStack::PopAndDestroy(2, scheduler);\ |
|
1177 }\ |
|
1178 \ |
|
1179 GLDEF_C TInt E32Main()\ |
|
1180 {\ |
|
1181 __UHEAP_MARK;\ |
|
1182 TInt err = KErrNoMemory;\ |
|
1183 CTrapCleanup* cleanup = CTrapCleanup::New();\ |
|
1184 if (cleanup)\ |
|
1185 {\ |
|
1186 TRAP(err, MainL());\ |
|
1187 delete cleanup;\ |
|
1188 }\ |
|
1189 __UHEAP_MARKEND;\ |
|
1190 return err;\ |
|
1191 }\ |
|
1192 |
|
1193 // Note, this used to be a member function of CCommandBase (called "LeaveIfError"). It was changed to a macro to work around |
|
1194 // a problem with GCCE (version "arm-none-symbianelf-gcc.exe (GCC) 3.4.3 (release) (CodeSourcery ARM Q1C 2005)") whereby |
|
1195 // USER-EXEC 3 panics would occur if a leave from a function with variadic parameters took place. |
|
1196 #define LeaveIfErr(_error, _errorFmtString...) \ |
|
1197 do \ |
|
1198 { \ |
|
1199 TInt __err = (_error); \ |
|
1200 if (__err < 0) \ |
|
1201 { \ |
|
1202 this->PrintError(__err, _errorFmtString); \ |
|
1203 User::Leave(__err); \ |
|
1204 } \ |
|
1205 } \ |
|
1206 while (0) |
|
1207 |
|
1208 #define StaticLeaveIfErr(_error, _errorFmtString...) \ |
|
1209 do \ |
|
1210 { \ |
|
1211 TInt __err = (_error); \ |
|
1212 if (__err < 0) \ |
|
1213 { \ |
|
1214 if (IoUtils::CCommandBase::HaveStatic()) IoUtils::PrintError(__err, _errorFmtString); \ |
|
1215 User::Leave(__err); \ |
|
1216 } \ |
|
1217 } \ |
|
1218 while (0) |
|
1219 |
|
1220 #define CommandLeaveIfErr(_command, _error, _errorFmtString...) \ |
|
1221 do \ |
|
1222 { \ |
|
1223 TInt __err = (_error); \ |
|
1224 if (__err < 0) \ |
|
1225 { \ |
|
1226 (_command).PrintError(__err, _errorFmtString); \ |
|
1227 User::Leave(__err); \ |
|
1228 } \ |
|
1229 } \ |
|
1230 while (0) |
|
1231 |
|
1232 #define TRAPL(leavingFunction, errorFmtString...) { TRAPD(_err, leavingFunction); LeaveIfErr(_err, errorFmtString); } |
|
1233 #define STRAPL(leavingFunction, errorFmtString...) { TRAPD(_err, leavingFunction); StaticLeaveIfErr(_err, errorFmtString); } |
|
1234 #define CTRAPL(command, leavingFunction, errorFmtString...) { TRAPD(_err, leavingFunction); CommandLeaveIfErr(command, _err, errorFmtString); } |
|
1235 #define TRAP_QUIETLY(err, leavingFunction) \ |
|
1236 if (IoUtils::CCommandBase::HaveStatic()) \ |
|
1237 { \ |
|
1238 IoUtils::CCommandBase::Static().StartSupressingErrors(); \ |
|
1239 TRAP(err, leavingFunction); \ |
|
1240 IoUtils::CCommandBase::Static().StopSupressingErrors(); \ |
|
1241 } \ |
|
1242 else \ |
|
1243 { \ |
|
1244 TRAP(err, leavingFunction); \ |
|
1245 } |
|
1246 |
|
1247 #define TRAPD_QUIETLY(_err, leavingFunction) TInt _err = KErrNone; TRAP_QUIETLY(_err, leavingFunction); |
|
1248 #define TRAP_IGNORE_QUIETLY(leavingFunction) { TRAPD_QUIETLY(_err, leavingFunction); (void)_err; } |
|
1249 |
|
1250 #endif // __IOUTILS_H__ |