|
1 /* |
|
2 * Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "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 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 /** @file |
|
19 @internalComponent |
|
20 @test |
|
21 */ |
|
22 |
|
23 |
|
24 #ifndef COMMANDENGINE_H |
|
25 #define COMMANDENGINE_H |
|
26 |
|
27 #include "ncmtestdefines.hrh" |
|
28 |
|
29 #include <e32base.h> |
|
30 #include <e32hashtab.h> |
|
31 |
|
32 #define COMMAND_MAX_COUNT_PER_PAGE NUM_EVENT_ON_SCREEN |
|
33 #define COMMAND_MAX_PAGE 9 |
|
34 |
|
35 class CUsbNcmConsole; |
|
36 |
|
37 NONSHARABLE_CLASS(CNcmCommandBase) : public CActive |
|
38 /** |
|
39 The CNcmCommandBase class is the base class of command classes |
|
40 */ |
|
41 { |
|
42 friend class CNcmCommandEngine; |
|
43 public: |
|
44 virtual ~CNcmCommandBase(); |
|
45 |
|
46 //Set the command key |
|
47 void SetKey(TUint aKey); |
|
48 //Get the command key |
|
49 TUint Key() const; |
|
50 |
|
51 //The command action when user choose a command. It must be implemneted by command classes. |
|
52 virtual void DoCommandL() = 0; |
|
53 |
|
54 //Set the command description. which will be displayed in command help. |
|
55 void SetDescription(const TDesC& aDescription); |
|
56 const virtual TDesC& Description(); |
|
57 |
|
58 protected: |
|
59 CNcmCommandBase(TInt aPriority, CUsbNcmConsole& aConsole, TUint aKey); |
|
60 |
|
61 protected: |
|
62 //From CActive |
|
63 virtual void DoCancel(); |
|
64 virtual void RunL(); |
|
65 |
|
66 protected: |
|
67 //Main console |
|
68 CUsbNcmConsole& iTestConsole; |
|
69 |
|
70 //The character which indicates the command |
|
71 TUint iKey; |
|
72 //The command's description |
|
73 TBuf<NUM_CHARACTERS_ON_LINE> iDescription; |
|
74 |
|
75 }; |
|
76 |
|
77 NONSHARABLE_CLASS(CNcmCommandEngine) : public CActive |
|
78 /** |
|
79 CNcmCommandEngine manages all command classes. |
|
80 */ |
|
81 { |
|
82 public: |
|
83 static CNcmCommandEngine* NewL(CUsbNcmConsole& aUsb); |
|
84 ~CNcmCommandEngine(); |
|
85 |
|
86 //Add command to command engine. |
|
87 void RegisterCommand(CNcmCommandBase* aCommand); |
|
88 //Destroy all commands in command engine. |
|
89 void RemoveAllCommand(); |
|
90 |
|
91 //Get command help info. |
|
92 void PrintHelp(TInt aPage); |
|
93 |
|
94 private: |
|
95 CNcmCommandEngine(CUsbNcmConsole& aUsb); |
|
96 void ConstructL(); |
|
97 |
|
98 //From CActive |
|
99 void DoCancel(); |
|
100 void RunL(); |
|
101 TInt RunError(TInt aError); |
|
102 |
|
103 private: |
|
104 //Main console |
|
105 CUsbNcmConsole& iTestConsole; |
|
106 |
|
107 //The mapping of key and commands. |
|
108 RHashMap<TUint, CNcmCommandBase*> iCommandMap; |
|
109 //keep the key infomation, the command will be displayed in which page and which line. |
|
110 TUint iCommandKeys[COMMAND_MAX_PAGE][COMMAND_MAX_COUNT_PER_PAGE]; |
|
111 //Indicate the page of the last command . |
|
112 TInt iLastPage; |
|
113 //Indicate the place of the last command in the last page. |
|
114 TInt iLastItem; |
|
115 //Indicate the rest lines in the last used page. |
|
116 TInt iRemainLine; |
|
117 }; |
|
118 |
|
119 #endif // COMMANDENGINE_H |