|
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_CPosControllerBase.h" |
|
20 #include "EPos_CPosSimulationPositioner.h" |
|
21 #include <e32debug.h> |
|
22 |
|
23 //consts |
|
24 |
|
25 const TInt KDefaultReadInterval(1000000); //1 second |
|
26 |
|
27 // ================= MEMBER FUNCTIONS ======================= |
|
28 |
|
29 // C++ default constructor can NOT contain any code, that |
|
30 // might leave. |
|
31 // |
|
32 CPosControllerBase::CPosControllerBase(TBool aTimeRelativePlayback) |
|
33 : CActive(EPriorityStandard), iTimeRelativePlayback(aTimeRelativePlayback), |
|
34 iTimeBetweenReads(KDefaultReadInterval) |
|
35 { |
|
36 } |
|
37 |
|
38 // Destructor |
|
39 CPosControllerBase::~CPosControllerBase() |
|
40 { |
|
41 CancelAllNotifyPositionUpdate(); |
|
42 iSimulationPositioners.Close(); |
|
43 } |
|
44 |
|
45 void CPosControllerBase::CompleteRequest(const TInt aIndex, TInt aErrorCode) |
|
46 { |
|
47 if (aIndex > KErrNotFound && aIndex < iSimulationPositioners.Count()) |
|
48 { |
|
49 TRequestStatus& status = iSimulationPositioners[aIndex].iReqStatus; |
|
50 iSimulationPositioners[aIndex].iSimPos.CompleteRequest(status, aErrorCode); |
|
51 iSimulationPositioners.Remove(aIndex); |
|
52 } |
|
53 else |
|
54 { |
|
55 User::Panic(_L("iSimulationPositioners corrupted"), KErrCorrupt); |
|
56 } |
|
57 } |
|
58 |
|
59 // ---------------------------------------------------------------------------- |
|
60 // CPosNmeaController::CancelNotifyPositionUpdate |
|
61 // |
|
62 // (other items were commented in a header). |
|
63 // ---------------------------------------------------------------------------- |
|
64 // |
|
65 void CPosControllerBase::CancelNotifyPositionUpdate(const CPosSimulationPositioner& aSimPos) |
|
66 { |
|
67 TInt index = FindPositioner(aSimPos); |
|
68 if (index > KErrNotFound) |
|
69 { |
|
70 TRequestStatus& rs = iSimulationPositioners[index].iReqStatus; |
|
71 CompleteRequest(index, KErrCancel); |
|
72 } |
|
73 } |
|
74 |
|
75 void CPosControllerBase::CancelAllNotifyPositionUpdate() |
|
76 { |
|
77 while ( iSimulationPositioners.Count() > 0 ) |
|
78 { |
|
79 //complete always first of iSimulationPositioner |
|
80 //because CompleteRequest deletes completed positioner |
|
81 CompleteRequest(0, KErrCancel); |
|
82 } |
|
83 // for(TInt index=0; index < iSimulationPositioners.Count(); index++) |
|
84 // { |
|
85 // CompleteRequest(index, KErrCancel); |
|
86 // index--; |
|
87 // } |
|
88 } |
|
89 |
|
90 void CPosControllerBase::NotifyPositionUpdateBase(TPositionInfoBase& aPosInfo, TRequestStatus& aStatus, CPosSimulationPositioner& aSimPos) |
|
91 { |
|
92 aStatus = KRequestPending; |
|
93 CPosSimulationPositioner::ClearAndSetDefaultPositionData(aPosInfo); |
|
94 TPositionerReference ref(aSimPos,aStatus, static_cast<TPositionInfo&>(aPosInfo)); |
|
95 TInt err = iSimulationPositioners.Append(ref); |
|
96 if (err != KErrNone) |
|
97 { |
|
98 //not using CopleteRequest(const CPosSimulationPositioner&, TRequestStatus&, TInt) |
|
99 //because adding positioner to array was unsuccessful then we can't remove it |
|
100 //from it. It could cause PANIC |
|
101 aSimPos.CompleteRequest(aStatus, err); |
|
102 } |
|
103 } |
|
104 |
|
105 void CPosControllerBase::CompleteRequestBase(TInt aErrorCode) |
|
106 { |
|
107 TPosition pos; |
|
108 iPosition.GetPosition(pos); |
|
109 TInt i = 0; |
|
110 while (i < iSimulationPositioners.Count()) |
|
111 { |
|
112 if (aErrorCode != KPositionPartialUpdate |
|
113 || iSimulationPositioners[i].iSimPos.PartialUpdateAllowed()) |
|
114 { |
|
115 iSimulationPositioners[i].iPosition.SetPosition(pos); |
|
116 CompleteRequest(i, aErrorCode); |
|
117 //complete request removes current position from iSimulationPositioners |
|
118 //then wee need to not modify iterator |
|
119 } |
|
120 else |
|
121 { |
|
122 i++; |
|
123 } |
|
124 } |
|
125 // for(TInt i=0; i < iSimulationPositioners.Count(); i++) |
|
126 // { |
|
127 // if(aErrorCode!=KPositionPartialUpdate || |
|
128 // iSimulationPositioners[i].iSimPos.PartialUpdateAllowed() ) |
|
129 // { |
|
130 // iSimulationPositioners[i].iPosition.SetPosition(pos); |
|
131 // CompleteRequest(i, aErrorCode); |
|
132 // //complete request removes current position from iSimulationPositioners |
|
133 // //then wee need to modify iterator |
|
134 // i--; |
|
135 // } |
|
136 // } |
|
137 |
|
138 CPosSimulationPositioner::ClearAndSetDefaultPositionData(iPosition); |
|
139 } |
|
140 |
|
141 TInt CPosControllerBase::FindPositioner(const CPosSimulationPositioner& aSimPos) |
|
142 { |
|
143 TInt ret = KErrNotFound; |
|
144 for(TInt i = 0; i < iSimulationPositioners.Count(); i++) |
|
145 { |
|
146 if( &iSimulationPositioners[i].iSimPos == &aSimPos) |
|
147 { |
|
148 ret = i; |
|
149 break; |
|
150 } |
|
151 } |
|
152 return ret; |
|
153 } |
|
154 |
|
155 // End of File |