1 /* |
|
2 * Copyright (c) 2010 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 |
|
19 #include <eikenv.h> |
|
20 #include <coeaui.h> |
|
21 #include <pathinfo.h> |
|
22 #include "creator_cmdscriptrun.h" |
|
23 #include "engine.h" |
|
24 #include "enginewrapper.h" |
|
25 #include "creator.pan" |
|
26 |
|
27 |
|
28 // delay before script running and application exiting in seconds |
|
29 // when script is run from command line |
|
30 const TInt KCommandLineDelay = 3; |
|
31 |
|
32 //---------------------------------------------------------------------------- |
|
33 |
|
34 CCreatorCmdScriptRun* CCreatorCmdScriptRun::NewL(CCreatorEngine* aEngine) |
|
35 { |
|
36 CCreatorCmdScriptRun* self = CCreatorCmdScriptRun::NewLC(aEngine); |
|
37 CleanupStack::Pop(self); |
|
38 return self; |
|
39 } |
|
40 |
|
41 CCreatorCmdScriptRun* CCreatorCmdScriptRun::NewLC(CCreatorEngine* aEngine) |
|
42 { |
|
43 CCreatorCmdScriptRun* self = new (ELeave) CCreatorCmdScriptRun; |
|
44 CleanupStack::PushL(self); |
|
45 self->ConstructL(aEngine); |
|
46 return self; |
|
47 } |
|
48 |
|
49 |
|
50 // ConstructL |
|
51 void CCreatorCmdScriptRun::ConstructL(CCreatorEngine* aEngine) |
|
52 { |
|
53 iEngine = aEngine; |
|
54 |
|
55 iMode = ETimerModeNone; |
|
56 iTickCount = 0; |
|
57 iTimer = CHeartbeat::NewL(0); |
|
58 |
|
59 // parse script name and random data file name from command line |
|
60 iCommandLineScriptName = HBufC::NewL(User::CommandLineLength()); |
|
61 iCommandLineRandomDataFileName = HBufC::NewL(User::CommandLineLength()); |
|
62 HBufC* commandLine = HBufC::NewLC(User::CommandLineLength()); |
|
63 TPtr16 ptr = commandLine->Des(); |
|
64 User::CommandLine(ptr); |
|
65 commandLine->Des().Trim(); |
|
66 |
|
67 TInt pos = commandLine->Des().Find(_L(" ")); |
|
68 if (pos != KErrNotFound) |
|
69 { |
|
70 iCommandLineScriptName->Des().Copy(commandLine->Des().Left(pos)); |
|
71 iCommandLineRandomDataFileName->Des().Copy(commandLine->Des().Mid(pos)); |
|
72 iCommandLineRandomDataFileName->Des().Trim(); |
|
73 } |
|
74 else |
|
75 { |
|
76 iCommandLineScriptName->Des().Copy(commandLine->Des()); |
|
77 iCommandLineRandomDataFileName->Des().Copy(KNullDesC); |
|
78 } |
|
79 |
|
80 CleanupStack::PopAndDestroy(commandLine); |
|
81 |
|
82 if (iCommandLineScriptName->Des().Length() > 0) |
|
83 { |
|
84 iMode = ETimerModeStartScript; |
|
85 iTimer->Start(ETwelveOClock, this); |
|
86 } |
|
87 } |
|
88 |
|
89 |
|
90 CCreatorCmdScriptRun::CCreatorCmdScriptRun() |
|
91 { |
|
92 // add any construction that cannot leave here |
|
93 } |
|
94 |
|
95 |
|
96 CCreatorCmdScriptRun::~CCreatorCmdScriptRun() |
|
97 { |
|
98 delete iCommandLineRandomDataFileName; |
|
99 delete iCommandLineScriptName; |
|
100 |
|
101 if (iTimer) |
|
102 { |
|
103 iTimer->Cancel(); |
|
104 delete iTimer; |
|
105 iTimer = NULL; |
|
106 } |
|
107 } |
|
108 |
|
109 void CCreatorCmdScriptRun::RunScriptDone() |
|
110 { |
|
111 if (iMode == ETimerModeStartScript) |
|
112 { |
|
113 iMode = ETimerModeExitAppUi; |
|
114 iTimer->Start(ETwelveOClock, this); |
|
115 } |
|
116 } |
|
117 |
|
118 void CCreatorCmdScriptRun::Beat() |
|
119 { |
|
120 TRAP_IGNORE( TickL() ); |
|
121 } |
|
122 |
|
123 void CCreatorCmdScriptRun::Synchronize() |
|
124 { |
|
125 TRAP_IGNORE( TickL() ); |
|
126 } |
|
127 |
|
128 void CCreatorCmdScriptRun::TickL() |
|
129 { |
|
130 iTickCount++; |
|
131 if (iTickCount > KCommandLineDelay) |
|
132 { |
|
133 iTimer->Cancel(); |
|
134 iTickCount = 0; |
|
135 if (iMode == ETimerModeStartScript) |
|
136 { |
|
137 iEngine->GetRandomDataFromFileL(*iCommandLineRandomDataFileName); |
|
138 TInt status = iEngine->RunScriptL(*iCommandLineScriptName); |
|
139 if (status != KErrNone) |
|
140 { |
|
141 TBuf<128> noteMsg; |
|
142 if (status == KErrNotFound) |
|
143 { |
|
144 _LIT(KMessage1, "Error in opening script file."); |
|
145 noteMsg.Copy(KMessage1); |
|
146 } |
|
147 else if (status == KErrCorrupt) |
|
148 { |
|
149 _LIT(KMessage2, "Error in parsing script file."); |
|
150 noteMsg.Copy(KMessage2); |
|
151 } |
|
152 else if (status == KErrCompletion) |
|
153 { |
|
154 _LIT(KMessage3, "Script file does not contain any elements."); |
|
155 noteMsg.Copy(KMessage3); |
|
156 } |
|
157 else |
|
158 { |
|
159 _LIT(KMessage4, "Unknown error in opening script file."); |
|
160 noteMsg.Copy(KMessage4); |
|
161 } |
|
162 iEngine->GetEngineWrapper()->ShowNote(noteMsg); |
|
163 RunScriptDone(); |
|
164 } |
|
165 } |
|
166 else if (iMode == ETimerModeExitAppUi) |
|
167 { |
|
168 iMode = ETimerModeNone; |
|
169 iEngine->GetEngineWrapper()->CloseCreatorApp(); |
|
170 } |
|
171 } |
|
172 } |
|