|
1 // Copyright (c) 2005-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 // |
|
15 |
|
16 |
|
17 |
|
18 // INCLUDE FILES |
|
19 #include "EPos_CPosDataSimulationController.h" |
|
20 #include "EPos_CPosFileHandler.h" |
|
21 |
|
22 // ================= MEMBER FUNCTIONS ======================= |
|
23 |
|
24 // C++ default constructor can NOT contain any code, that |
|
25 // might leave. |
|
26 // |
|
27 CPosDataSimController::CPosDataSimController( |
|
28 TBool aTimeRelativePlayback) : |
|
29 CPosControllerBase(aTimeRelativePlayback), iSimulationState(EPosCheckIfFailRequest), iSimulationInProcess(EFalse) |
|
30 { |
|
31 CActiveScheduler::Add(this); |
|
32 } |
|
33 |
|
34 // EPOC default constructor can leave. |
|
35 void CPosDataSimController::ConstructL(const TDesC& aSimulationFile) |
|
36 { |
|
37 User::LeaveIfError(iTimer.CreateLocal()); |
|
38 |
|
39 iSimDataArray = new (ELeave) CDesC8ArrayFlat(KNoOfSimulatedDataItems); |
|
40 |
|
41 CPosFileHandler* fileHandler = CPosFileHandler::NewL(aSimulationFile); |
|
42 CleanupStack::PushL(fileHandler); |
|
43 fileHandler->ReadL(*iSimDataArray); |
|
44 CleanupStack::PopAndDestroy(fileHandler); |
|
45 |
|
46 iDataSimulator.ParseAndCreatePosObjectL(iBasePosition, iSimDataArray); |
|
47 iSimulatedPosition = iBasePosition; |
|
48 } |
|
49 |
|
50 // Two-phased constructor. |
|
51 CPosDataSimController* CPosDataSimController::NewL( |
|
52 const TDesC& aSimulationFile, |
|
53 TBool aTimeRelativePlayback) |
|
54 { |
|
55 CPosDataSimController* self = new (ELeave) CPosDataSimController(aTimeRelativePlayback); |
|
56 CleanupStack::PushL(self); |
|
57 self->ConstructL(aSimulationFile); |
|
58 CleanupStack::Pop(self); |
|
59 return self; |
|
60 } |
|
61 |
|
62 // Destructor |
|
63 CPosDataSimController::~CPosDataSimController() |
|
64 { |
|
65 Cancel(); |
|
66 iTimer.Cancel(); |
|
67 iTimer.Close(); |
|
68 iRequestStatus = NULL; |
|
69 delete iSimDataArray; |
|
70 } |
|
71 |
|
72 // ---------------------------------------------------------------------------- |
|
73 // CPosSimulationPositioner::NotifyPositionUpdate |
|
74 // |
|
75 // (other items were commented in a header). |
|
76 // ---------------------------------------------------------------------------- |
|
77 // |
|
78 void CPosDataSimController::NotifyPositionUpdate( |
|
79 TPositionInfoBase& aPosInfo, |
|
80 TRequestStatus& aStatus, |
|
81 CPosSimulationPositioner& aSimPos) |
|
82 { |
|
83 NotifyPositionUpdateBase(aPosInfo, aStatus, aSimPos); |
|
84 |
|
85 iNumRequests++; |
|
86 iRequestStartTime.UniversalTime(); |
|
87 |
|
88 if (iSimulationInProcess) |
|
89 { |
|
90 SetCompletionCodeAndWait(); |
|
91 } |
|
92 else if (!IsActive()) |
|
93 { |
|
94 //this section is done only once at powerup time |
|
95 if(iTimeRelativePlayback) |
|
96 { |
|
97 //in TRP mode we are using this variable to |
|
98 //determinate begin of the simulation |
|
99 //in TRP mode this variable one setuped is never changed |
|
100 iLastRequestTime.UniversalTime(); |
|
101 } |
|
102 iTimer.Cancel(); |
|
103 iTimer.After(iStatus, |
|
104 I64INT(iDataSimulator.PowerupTime().Int64())); |
|
105 SetActive(); |
|
106 } |
|
107 } |
|
108 |
|
109 // ---------------------------------------------------------------------------- |
|
110 // CPosDataSimController::CancelNotifyPositionUpdate |
|
111 // |
|
112 // (other items were combmented in a header). |
|
113 // ---------------------------------------------------------------------------- |
|
114 // |
|
115 void CPosDataSimController::CancelNotifyPositionUpdate(const CPosSimulationPositioner& aSimPos) |
|
116 { |
|
117 CPosControllerBase::CancelNotifyPositionUpdate(aSimPos); |
|
118 if(!iTimeRelativePlayback) |
|
119 { |
|
120 Cancel(); |
|
121 } |
|
122 } |
|
123 |
|
124 // ---------------------------------------------------------------------------- |
|
125 // CPosDataSimController::CompleteRequest |
|
126 // |
|
127 // (other items were commented in a header). |
|
128 // ---------------------------------------------------------------------------- |
|
129 // |
|
130 void CPosDataSimController::CompleteRequest(TInt aErrorCode) |
|
131 { |
|
132 CompleteRequestBase(aErrorCode); |
|
133 iSimulationState = EPosCheckIfFailRequest; |
|
134 } |
|
135 |
|
136 // ---------------------------------------------------------------------------- |
|
137 // CPosDataSimController::SetCompletionCodeAndWait |
|
138 // |
|
139 // (other items were commented in a header). |
|
140 // ---------------------------------------------------------------------------- |
|
141 // |
|
142 void CPosDataSimController::SetCompletionCodeAndWait() |
|
143 { |
|
144 if(!IsActive()) |
|
145 { |
|
146 iCompleteCode = iDataSimulator.FailThisRequest(iNumRequests); |
|
147 |
|
148 iSimulationState = EPosTransferAndComplete; |
|
149 iTimer.Cancel(); |
|
150 iTimer.After(iStatus, |
|
151 I64INT(iDataSimulator.TimeToWait(iRequestStartTime).Int64())); |
|
152 SetActive(); |
|
153 } |
|
154 } |
|
155 |
|
156 // ---------------------------------------------------------------------------- |
|
157 // CPosDataSimController::RunL |
|
158 // |
|
159 // (other items were commented in a header). |
|
160 // ---------------------------------------------------------------------------- |
|
161 // |
|
162 void CPosDataSimController::RunL() |
|
163 { |
|
164 if (iSimulationState == EPosCheckIfFailRequest) |
|
165 { |
|
166 SetCompletionCodeAndWait(); |
|
167 } |
|
168 else |
|
169 { |
|
170 // Powerup has been done |
|
171 if (!iSimulationInProcess) |
|
172 { |
|
173 iSimulationInProcess = ETrue; |
|
174 } |
|
175 else if (iCompleteCode == KErrNone) |
|
176 { |
|
177 if (iTimeRelativePlayback) |
|
178 { |
|
179 iSimulatedPosition = iBasePosition; |
|
180 } |
|
181 iDataSimulator.ComputeNewPositionL(iSimulatedPosition, |
|
182 iRequestStartTime, iLastRequestTime); |
|
183 } |
|
184 if(!iTimeRelativePlayback) |
|
185 { |
|
186 iLastRequestTime = iRequestStartTime; |
|
187 } |
|
188 iSimulatedPosition.SetCurrentTime(); |
|
189 iPosition.SetPosition(iSimulatedPosition); |
|
190 CompleteRequest(iCompleteCode); |
|
191 } |
|
192 } |
|
193 |
|
194 // ---------------------------------------------------------------------------- |
|
195 // CPosDataSimController::DoCancel |
|
196 // |
|
197 // (other items were commented in a header). |
|
198 // ---------------------------------------------------------------------------- |
|
199 // |
|
200 void CPosDataSimController::DoCancel() |
|
201 { |
|
202 // If request cancelled, then we have consumed Powerup Time |
|
203 // and are in simulation mode |
|
204 // |
|
205 iSimulationInProcess = ETrue; |
|
206 iTimer.Cancel(); |
|
207 } |
|
208 |
|
209 // ---------------------------------------------------------------------------- |
|
210 // CPosDataSimController::RunError |
|
211 // |
|
212 // (other items were commented in a header). |
|
213 // ---------------------------------------------------------------------------- |
|
214 // |
|
215 TInt CPosDataSimController::RunError(TInt aError) |
|
216 { |
|
217 CompleteRequest(aError); |
|
218 return KErrNone; |
|
219 } |
|
220 |
|
221 // End of File |