|
1 // Copyright (c) 2007-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_defaultproxycommon.h" |
|
20 #include "epos_cposrequestor.h" |
|
21 #include "epos_cpossingletonmanager.h" |
|
22 #include "epos_mposrequestorlistener.h" |
|
23 #include "epos_cpospsyfixstatemanager.h" |
|
24 |
|
25 #include <lbs/epos_cpositioner.h> |
|
26 #include "epos_mposmodulestatusmanager.h" |
|
27 |
|
28 // ================= MEMBER FUNCTIONS ======================= |
|
29 |
|
30 // C++ default constructor can NOT contain any code, that |
|
31 // might leave. |
|
32 // |
|
33 CPosRequestor::CPosRequestor( |
|
34 MPosRequestorListener& aListener, |
|
35 CPosPsyFixStateManager& aFixStateManager, |
|
36 MPosModuleStatusManager& aModuleStatusManager ) |
|
37 : CActive( CActive::EPriorityStandard ), |
|
38 iListener( aListener ), |
|
39 iFixStateManager( aFixStateManager ), |
|
40 iModuleStatusManager( aModuleStatusManager ) |
|
41 { |
|
42 CActiveScheduler::Add( this ); |
|
43 } |
|
44 |
|
45 // EPOC default constructor can leave. |
|
46 void CPosRequestor::ConstructL( |
|
47 CPositioner& aDefaultPositioner, |
|
48 TPositionModuleId aModuleId ) |
|
49 { |
|
50 iPositioner = CPositioner::NewL( aModuleId, aDefaultPositioner ); |
|
51 } |
|
52 |
|
53 // Two phase constructor |
|
54 CPosRequestor* CPosRequestor::NewL( |
|
55 CPositioner& aDefaultPositioner, |
|
56 TPositionModuleId aModuleId, |
|
57 MPosRequestorListener& aListener, |
|
58 CPosPsyFixStateManager& aFixStateManager, |
|
59 MPosModuleStatusManager& aModuleStatusManager ) |
|
60 { |
|
61 CPosRequestor* self = new ( ELeave ) CPosRequestor( |
|
62 aListener, |
|
63 aFixStateManager, |
|
64 aModuleStatusManager ); |
|
65 CleanupStack::PushL(self); |
|
66 self->ConstructL( aDefaultPositioner, aModuleId ); |
|
67 CleanupStack::Pop(self); |
|
68 return self; |
|
69 } |
|
70 |
|
71 // Destructor |
|
72 CPosRequestor::~CPosRequestor() |
|
73 { |
|
74 Cancel(); |
|
75 delete iPosInfo; |
|
76 delete iPositioner; |
|
77 } |
|
78 |
|
79 // --------------------------------------------------------- |
|
80 // CPosRequestor::ModuleId |
|
81 // --------------------------------------------------------- |
|
82 // |
|
83 TPositionModuleId CPosRequestor::ModuleId() const |
|
84 { |
|
85 return iPositioner->ImplementationUid(); |
|
86 } |
|
87 |
|
88 // --------------------------------------------------------- |
|
89 // CPosRequestor::MakeLocationRequestL |
|
90 // --------------------------------------------------------- |
|
91 // |
|
92 void CPosRequestor::MakeLocationRequestL( const TPositionInfoBase& aPosInfo ) |
|
93 { |
|
94 if ( IsActive() ) |
|
95 { |
|
96 //The previous location request will not be canceled. |
|
97 //We mark the iPosInfo is not uptodate. |
|
98 iIsPosInfoUpTodate= EFalse; |
|
99 return; |
|
100 } |
|
101 |
|
102 if ( iPosInfo != NULL ) |
|
103 { |
|
104 delete iPosInfo; |
|
105 iPosInfo = NULL; |
|
106 } |
|
107 |
|
108 //Copy position info data structure |
|
109 TInt posInfoSize = aPosInfo.PositionClassSize(); |
|
110 |
|
111 iPosInfo = reinterpret_cast< TPositionInfoBase* > ( |
|
112 User::AllocL( posInfoSize ) ); |
|
113 |
|
114 Mem::Copy( iPosInfo , &aPosInfo, posInfoSize ); |
|
115 |
|
116 //Make location request |
|
117 iStatus = KRequestPending; |
|
118 iPositioner->NotifyPositionUpdate( *iPosInfo, iStatus ); |
|
119 SetActive(); |
|
120 iIsPosInfoUpTodate = ETrue; |
|
121 |
|
122 //Get previous device state |
|
123 TPositionModuleStatus moduleStatus; |
|
124 iModuleStatusManager.GetModuleStatus( |
|
125 ModuleId(), |
|
126 moduleStatus ); |
|
127 |
|
128 //Notify fix state manager that a PSY is used |
|
129 iFixStateManager.PsyUsed( |
|
130 ModuleId(), |
|
131 moduleStatus.DeviceStatus() ); |
|
132 } |
|
133 |
|
134 // --------------------------------------------------------- |
|
135 // CPosRequestor::Cancel(TInt) |
|
136 // --------------------------------------------------------- |
|
137 // |
|
138 void CPosRequestor::CancelWithReason(TInt aCancelReason) |
|
139 { |
|
140 iCancelReason = aCancelReason; |
|
141 Cancel(); |
|
142 iCancelReason = KErrCancel; //reset for next time |
|
143 } |
|
144 |
|
145 // --------------------------------------------------------- |
|
146 // CPosRequestor::StartTrackingL |
|
147 // --------------------------------------------------------- |
|
148 // |
|
149 void CPosRequestor::StartTrackingL( TTimeIntervalMicroSeconds& aInterval ) |
|
150 { |
|
151 if ( iPositioner->TrackingOverridden() && !iTrackingStarted ) |
|
152 { |
|
153 iPositioner->StartTrackingL( aInterval ); |
|
154 iTrackingStarted = ETrue; |
|
155 } |
|
156 } |
|
157 |
|
158 // --------------------------------------------------------- |
|
159 // CPosRequestor::StopTracking |
|
160 // --------------------------------------------------------- |
|
161 // |
|
162 void CPosRequestor::StopTracking() |
|
163 { |
|
164 if ( iPositioner->TrackingOverridden() && iTrackingStarted ) |
|
165 { |
|
166 iPositioner->StopTracking(); |
|
167 iTrackingStarted = EFalse; |
|
168 } |
|
169 } |
|
170 |
|
171 // --------------------------------------------------------- |
|
172 // CPosRequestor::RunL |
|
173 // --------------------------------------------------------- |
|
174 // |
|
175 void CPosRequestor::RunL() |
|
176 { |
|
177 iListener.LocationRequestCompleted( |
|
178 ModuleId(), |
|
179 iStatus.Int(), |
|
180 *iPosInfo, |
|
181 iIsPosInfoUpTodate ); |
|
182 } |
|
183 |
|
184 // --------------------------------------------------------- |
|
185 // CPosRequestor::DoCancel |
|
186 // --------------------------------------------------------- |
|
187 // |
|
188 void CPosRequestor::DoCancel() |
|
189 { |
|
190 //We don't need to check if requestor is active or not. |
|
191 //CActive::Cancel() function will not call DoCancel() |
|
192 //if the active object is not active |
|
193 TRACESTRING2( "Location Request Canceled: %x", ModuleId() ) |
|
194 iPositioner->CancelNotifyPositionUpdate(iCancelReason); |
|
195 |
|
196 //Notify fix state manager that location request is canceled |
|
197 iFixStateManager.SetPsyFixState( |
|
198 ModuleId(), |
|
199 iStatus.Int() ); |
|
200 } |
|
201 |
|
202 |
|
203 // End of File |