|
1 // Copyright (c) 2002-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 // $Header$ |
|
15 // The CTEngine is the class that manages the test infrastructure |
|
16 // It knows how to process scripts and where to find command knowledge |
|
17 // The plan is: |
|
18 // Process console command line or command line supplied script |
|
19 // read in each line (or command) and process that (if appropriate) |
|
20 // |
|
21 // |
|
22 |
|
23 #ifndef __CCMDBASE_H__ |
|
24 #define __CCMDBASE_H__ |
|
25 |
|
26 //----------------------------------------------------------------------------- |
|
27 // Include Files |
|
28 |
|
29 #include <e32base.h> |
|
30 #include <uri8.h> |
|
31 |
|
32 //----------------------------------------------------------------------------- |
|
33 |
|
34 #include "CCmdFamily.h" |
|
35 #include "TEngine.h" |
|
36 #include "TfrLex.h" |
|
37 |
|
38 //----------------------------------------------------------------------------- |
|
39 |
|
40 class CCmdBase : public CBase |
|
41 { |
|
42 public: // Data Types |
|
43 |
|
44 // Boolean flags 1-8 from the 1-32 are reserved for the framework's |
|
45 // use, present or future. |
|
46 enum |
|
47 { |
|
48 EDoLog = 1, // print to log |
|
49 EFlag2 = 2, |
|
50 EFlag3 = 3, |
|
51 EFlag4 = 4, |
|
52 EFlag5 = 5, |
|
53 EFlag6 = 6, |
|
54 EFlag7 = 7, |
|
55 EFlag8 = 8, |
|
56 EMaxFlags |
|
57 }; |
|
58 |
|
59 public: // Constructors and destructors |
|
60 |
|
61 // Constructors. Have your own ones in the derived classes. |
|
62 static CCmdBase* NewL (TInt, const TDesC &); |
|
63 static CCmdBase* NewLC(TInt, const TDesC &); |
|
64 static CCmdBase* NewL (TInt, const TDesC &, const TDesC &); |
|
65 static CCmdBase* NewLC(TInt, const TDesC &, const TDesC &); |
|
66 |
|
67 // Destructor. |
|
68 ~CCmdBase(); |
|
69 |
|
70 protected: |
|
71 |
|
72 // Local constructor (is protected for the derived classes). |
|
73 virtual void ConstructL(TInt, const TDesC &); |
|
74 virtual void ConstructL(TInt, const TDesC &, const TDesC &); |
|
75 |
|
76 // have a wait event method (which may or may not be inherited) |
|
77 virtual void WaitEvents() {}; |
|
78 |
|
79 // have a wait event method (which may or may not be inherited) |
|
80 virtual void DoneWaitEvents() {}; |
|
81 |
|
82 // this provides a generic means of updating the completion code |
|
83 virtual void SetCompletionCode(TInt); |
|
84 virtual TInt GetCompletionCode() { return iCompletionCode; } |
|
85 |
|
86 protected: |
|
87 |
|
88 // No default constructor. |
|
89 CCmdBase(); |
|
90 |
|
91 public: // New functions |
|
92 |
|
93 // Get the Command Id. |
|
94 TInt CommandId(); |
|
95 |
|
96 // Get the Keyword Phrase. |
|
97 const TDesC &Keyphrase(); |
|
98 |
|
99 // Set and Get the Command Family context. |
|
100 void SetFamily(CCmdFamily *); |
|
101 CCmdFamily *Family(); |
|
102 |
|
103 // Set and Get the Help Text. |
|
104 void SetHelpText(const TDesC &); |
|
105 const TDesC& HelpText(); |
|
106 |
|
107 // Set and Get a boolean flag, flags 1-32 supported. |
|
108 void SetFlag(TInt, TBool = ETrue); |
|
109 TBool Flag(TInt); |
|
110 |
|
111 // Set and Get the StepOver flag. |
|
112 void SetStepOver(TBool = ETrue); |
|
113 TBool StepOver(); |
|
114 |
|
115 // Recognize command i.e. check that the command string begins with |
|
116 // the Keyword Phrase AND that the next after the keyword phrase is |
|
117 // not alphabetic nor digit (end-of-string is accepted). NOTE: this |
|
118 // sets the command's StepOver flag from the command family. |
|
119 virtual TBool Recognize(const TDesC & ); |
|
120 virtual TBool Recognize(TLex); |
|
121 |
|
122 // Get command parameters = the remainder after the Keyword Phrase |
|
123 // in the command string. Leaves (KErrArgument) if cannot recogize |
|
124 // the command. |
|
125 virtual TPtrC ParamsL(const TDesC &); |
|
126 virtual TPtrC ParamsL(TLex aCommand); |
|
127 |
|
128 // Process command string. |
|
129 // Override... |
|
130 virtual TInt ProcessL(const TDesC &); |
|
131 |
|
132 // Process command string. |
|
133 // Override... |
|
134 TInt ProcessStepOverL(); |
|
135 |
|
136 // simplify logging facility |
|
137 void Log(TRefByValue<const TDesC> aFmt, ... ); |
|
138 |
|
139 // WriteDateStamp |
|
140 void WriteDateStamp(); |
|
141 void WriteDateStamp(const TDateTime &); |
|
142 |
|
143 protected: // New functions |
|
144 |
|
145 // Print out formatted/unformatted message. |
|
146 void Printf(TRefByValue<const TDesC> aFmt, ...); |
|
147 void Print (const TDesC& aText, const TBool & = ETrue); |
|
148 |
|
149 // Raise error: returns back the given error code. |
|
150 TInt Error( TInt aError, TRefByValue<const TDesC> aFmt, ... ); |
|
151 |
|
152 // Get Test Machine. |
|
153 CTEngine *Machine(); |
|
154 |
|
155 // Get Test Console. |
|
156 CConsoleBase* Console(); |
|
157 |
|
158 protected: // Data |
|
159 |
|
160 // Command Flags, a bit for each flag numbered from 1 to 32. |
|
161 TUint32 iFlags; |
|
162 |
|
163 private: // Data |
|
164 |
|
165 // Command Family. |
|
166 CCmdFamily* iFamily; |
|
167 |
|
168 // Command id. |
|
169 TInt iCommandId; |
|
170 |
|
171 // Keyword phrase. |
|
172 TPtrC iKeyphrase; |
|
173 |
|
174 // Help text. |
|
175 TPtrC iHelpText; |
|
176 |
|
177 // Step over me. |
|
178 TBool iStepOver; |
|
179 |
|
180 // operation completion code |
|
181 TInt iCompletionCode; |
|
182 |
|
183 }; |
|
184 |
|
185 /* |
|
186 // |
|
187 // The constuction of CCmdBase derived classes goes as outlined below: |
|
188 // |
|
189 |
|
190 class CCmdSample : public CCmdBase |
|
191 { |
|
192 public: |
|
193 static CCmdSample* NewL ( TInt aCommandId, const TDesC& aKeyphrase ); |
|
194 static CCmdSample* NewLC( TInt aCommandId, const TDesC& aKeyphrase ); |
|
195 ~CCmdSample( ); |
|
196 protected: |
|
197 void ConstructL( TInt aCommandId, const TDesC& aKeyphrase ); |
|
198 public: |
|
199 TInt ProcessL( const TDesC& aCommand, TBool doExecute = ETrue ); |
|
200 ... |
|
201 }; |
|
202 |
|
203 CCmdSample* CCmdSample::NewL( TInt aCommandId, const TDesC& aKeyphrase ) |
|
204 { |
|
205 CCmdSample* self = NewLC( aCommandId, aKeyphrase ); |
|
206 CleanupStack::Pop(); |
|
207 return self; |
|
208 } |
|
209 CCmdSample* CCmdSample::NewLC( TInt aCommandId, const TDesC& aKeyphrase ) |
|
210 { |
|
211 CCmdsample* self = new (ELeave) CCmdSample(); |
|
212 CleanupStack::PushL( self ); |
|
213 self->ConstructL( aCommandId, aKeyphrase ); |
|
214 return self; |
|
215 } |
|
216 CCmdSample::~CCmdSample( ) |
|
217 { |
|
218 ...destroy additional member data in here. |
|
219 }; |
|
220 void CCmdSample::ConstructL( TInt aCommandId, const TDesC& aKeyphrase ) |
|
221 { |
|
222 CCmdBase::ConstructL ( aCommandId, aKeyphrase ); |
|
223 ...initialize additional member data in here. |
|
224 } |
|
225 |
|
226 */ |
|
227 |
|
228 |
|
229 #endif // __CCMDBASE_H__ |
|
230 |
|
231 //----------------------------------------------------------------------------- |
|
232 // End of File |
|
233 //----------------------------------------------------------------------------- |