|
1 /* |
|
2 * Copyright (c) 2008-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 the License "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 |
|
19 #include <usif/scr/scr.h> |
|
20 #include <e32cons.h> |
|
21 #include "command.h" |
|
22 |
|
23 using namespace Usif; |
|
24 |
|
25 _LIT(KTxtAppTitle, "Reference Application Manager\n"); |
|
26 _LIT(KTxtAppVersion, "Version 1.00(0)\n"); |
|
27 _LIT(KTxtCopyright, "Copyright (c) Symbian Software Ltd 2008. All rights reserved.\n"); |
|
28 |
|
29 _LIT(KTxtEPOC32EX,"EXAMPLES"); |
|
30 _LIT(KTxtFormatFailed,"\nFailed with leave code = %d\n"); |
|
31 _LIT(KTxtPressToExit, "Press any key to exit..."); |
|
32 _LIT(KTxtPressToContinue, "\nPress any key to continue...\n\n"); |
|
33 |
|
34 _LIT(KTxtHelp01, "\nThe syntax of the command is incorrect. Use the following options:\n\n"); |
|
35 _LIT(KTxtHelp02, "--list [--name name] [--vendor vendor] [--type type] [--removable|nonremovable]\n"); |
|
36 _LIT(KTxtHelp03, "[--activated|deactivated] [--drives drivelist] [--property name value [language]]\n"); |
|
37 _LIT(KTxtHelp04, "[--intproperty name value] [--file path] [--locale language]\n\n"); |
|
38 |
|
39 _LIT(KTxtHelp05, "OPTIONS\n\n"); |
|
40 _LIT(KTxtHelp06, " --name NAME\n"); |
|
41 _LIT(KTxtHelp07, " lists components with name NAME\n\n"); |
|
42 _LIT(KTxtHelp08, " --vendor VENDOR\n"); |
|
43 _LIT(KTxtHelp09, " lists components with vendor VENDOR\n\n"); |
|
44 _LIT(KTxtHelp10, " --type TYPE\n"); |
|
45 _LIT(KTxtHelp11, " lists components with software type TYPE\n\n"); |
|
46 _LIT(KTxtHelp12, " --removable\n"); |
|
47 _LIT(KTxtHelp13, " lists removable components only\n\n"); |
|
48 _LIT(KTxtHelp16, " --activated\n"); |
|
49 _LIT(KTxtHelp17, " lists components with SCOMO state Activated\n\n"); |
|
50 _LIT(KTxtHelp18, " --deactivated\n"); |
|
51 _LIT(KTxtHelp19, " lists components with SCOMO state Deactivated\n\n"); |
|
52 _LIT(KTxtHelp20, " --drives DRIVES\n"); |
|
53 _LIT(KTxtHelp21, " lists components whose files were installed to DRIVES\n\n"); |
|
54 _LIT(KTxtHelp22, " --property N V L\n"); |
|
55 _LIT(KTxtHelp23, " lists components with string property name N and value V and optional language code L, for example English=1, French=2, German=3\n\n"); |
|
56 _LIT(KTxtHelp26, " --locale LANGUAGE\n"); |
|
57 _LIT(KTxtHelp27, " defines language LANGUAGE to be used to find the component info, for example English=1, French=2, German=3\n\n"); |
|
58 |
|
59 _LIT(KTxtHelp30, "--delete ComponentID\n"); |
|
60 _LIT(KTxtHelp31, " deletes component with ComponentID. The ID of a component to be removed can be obtained using the 'list' command.\n\n"); |
|
61 |
|
62 _LIT(KTxtHelp40, "EXAMPLES\n\n"); |
|
63 _LIT(KTxtHelp41, " refappmanager --list\n\n"); |
|
64 _LIT(KTxtHelp42, " refappmanager --list --type native\n\n"); |
|
65 _LIT(KTxtHelp43, " refappmanager --list --vendor Symbian\n\n"); |
|
66 _LIT(KTxtHelp44, " refappmanager --list --type java --drives cef --activated --locale 2\n\n"); |
|
67 _LIT(KTxtHelp45, " refappmanager --delete 6\n\n"); |
|
68 |
|
69 // ================================================================================== |
|
70 |
|
71 // Start-up functions and helpers |
|
72 LOCAL_C void InitL(); |
|
73 LOCAL_C void ExecCommandL(CConsoleBase& aConsole); |
|
74 LOCAL_C void DisplayHelp(CConsoleBase& aConsole); |
|
75 |
|
76 // Main function called by E32 |
|
77 GLDEF_C TInt E32Main() |
|
78 { |
|
79 // Get clean-up stack |
|
80 CTrapCleanup* cleanup=CTrapCleanup::New(); |
|
81 |
|
82 __UHEAP_MARK; |
|
83 |
|
84 // Call InitL() and catch all leaves |
|
85 TRAPD(error,InitL()); |
|
86 __ASSERT_ALWAYS(!error,User::Panic(KTxtEPOC32EX,error)); |
|
87 |
|
88 __UHEAP_MARKEND; |
|
89 |
|
90 // Destroy clean-up stack |
|
91 delete cleanup; |
|
92 |
|
93 return 0; |
|
94 } |
|
95 |
|
96 // ================================================================================== |
|
97 |
|
98 LOCAL_C void InitL() |
|
99 { |
|
100 // Create console |
|
101 CConsoleBase* console = Console::NewL(KTxtAppTitle,TSize(KConsFullScreen,KConsFullScreen)); |
|
102 CleanupStack::PushL(console); |
|
103 |
|
104 // Call ExecCommandL() and catch all leaves |
|
105 TRAPD(err, ExecCommandL(*console)); |
|
106 if (err == KErrArgument) |
|
107 { |
|
108 DisplayHelp(*console); |
|
109 } |
|
110 else if (err != KErrNone) |
|
111 { |
|
112 console->Printf(KTxtFormatFailed, err); |
|
113 } |
|
114 |
|
115 // Wait for any key |
|
116 console->Printf(KTxtPressToExit); |
|
117 console->Getch(); |
|
118 |
|
119 CleanupStack::PopAndDestroy(console); |
|
120 } |
|
121 |
|
122 // ================================================================================== |
|
123 |
|
124 LOCAL_C void ExecCommandL(CConsoleBase& aConsole) |
|
125 { |
|
126 // Display info |
|
127 aConsole.Printf(KTxtAppTitle); |
|
128 aConsole.Printf(KTxtAppVersion); |
|
129 aConsole.Printf(KTxtCopyright); |
|
130 |
|
131 // Create parser |
|
132 CCommandLineParser* parser = CCommandLineParser::NewLC(); |
|
133 |
|
134 // Instantiate and register the 'list' and 'delete' commands. If we had |
|
135 // more commands it could be more efficient to implement a command factory |
|
136 // in order to instantiate only a single command on demand. This example |
|
137 // application provides only two commands and therefore the above mentioned |
|
138 // optimisation isn't needed here. |
|
139 parser->RegisterCommandL(*CListCommand::NewLC()); |
|
140 parser->RegisterCommandL(*CDeleteCommand::NewLC()); |
|
141 |
|
142 // Parse input and find the matching command |
|
143 CConsoleCommand& cmd = parser->ParseL(); |
|
144 |
|
145 // Execute the command |
|
146 cmd.ExecuteL(aConsole); |
|
147 |
|
148 // Cleanup the parser and commands |
|
149 CleanupStack::PopAndDestroy(3, parser); |
|
150 } |
|
151 |
|
152 // ================================================================================== |
|
153 |
|
154 LOCAL_C void DisplayHelp(CConsoleBase& aConsole) |
|
155 { |
|
156 aConsole.Printf(KTxtHelp01); |
|
157 aConsole.Printf(KTxtHelp02); |
|
158 aConsole.Printf(KTxtHelp03); |
|
159 aConsole.Printf(KTxtHelp04); |
|
160 aConsole.Printf(KTxtHelp05); |
|
161 aConsole.Printf(KTxtHelp06); |
|
162 aConsole.Printf(KTxtHelp07); |
|
163 aConsole.Printf(KTxtHelp08); |
|
164 aConsole.Printf(KTxtHelp09); |
|
165 |
|
166 aConsole.Printf(KTxtPressToContinue); |
|
167 aConsole.Getch(); |
|
168 |
|
169 aConsole.Printf(KTxtHelp10); |
|
170 aConsole.Printf(KTxtHelp11); |
|
171 aConsole.Printf(KTxtHelp12); |
|
172 aConsole.Printf(KTxtHelp13); |
|
173 aConsole.Printf(KTxtHelp16); |
|
174 aConsole.Printf(KTxtHelp17); |
|
175 aConsole.Printf(KTxtHelp18); |
|
176 aConsole.Printf(KTxtHelp19); |
|
177 aConsole.Printf(KTxtHelp20); |
|
178 aConsole.Printf(KTxtHelp21); |
|
179 |
|
180 aConsole.Printf(KTxtPressToContinue); |
|
181 aConsole.Getch(); |
|
182 |
|
183 aConsole.Printf(KTxtHelp22); |
|
184 aConsole.Printf(KTxtHelp23); |
|
185 aConsole.Printf(KTxtHelp26); |
|
186 aConsole.Printf(KTxtHelp27); |
|
187 aConsole.Printf(KTxtHelp30); |
|
188 aConsole.Printf(KTxtHelp31); |
|
189 |
|
190 aConsole.Printf(KTxtPressToContinue); |
|
191 aConsole.Getch(); |
|
192 |
|
193 aConsole.Printf(KTxtHelp40); |
|
194 aConsole.Printf(KTxtHelp41); |
|
195 aConsole.Printf(KTxtHelp42); |
|
196 aConsole.Printf(KTxtHelp43); |
|
197 aConsole.Printf(KTxtHelp44); |
|
198 aConsole.Printf(KTxtHelp45); |
|
199 } |