|
1 /* |
|
2 * Copyright (c) 2008 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: Handles getLocation requests |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "cpositioner.h" |
|
21 #include "logger.h" |
|
22 #include "locationfunctionserver.h" |
|
23 |
|
24 using namespace java::location; |
|
25 |
|
26 // UNNAMED LOCAL NAMESPACE |
|
27 namespace |
|
28 { |
|
29 // Delay subsequent getLocation() calls. This way the failing |
|
30 // requests do not steal all processing time |
|
31 const TInt KLocCallDelay = 500000; |
|
32 } |
|
33 |
|
34 // ============================ MEMBER FUNCTIONS =============================== |
|
35 |
|
36 // ----------------------------------------------------------------------------- |
|
37 // CPositioner::CPositioner |
|
38 // C++ default constructor can NOT contain any code, that |
|
39 // might leave. |
|
40 // ----------------------------------------------------------------------------- |
|
41 // |
|
42 CPositioner::CPositioner(LocationFunctionServer* aFunctionSource) : |
|
43 CPositionerBase(aFunctionSource) |
|
44 { |
|
45 } |
|
46 |
|
47 // ----------------------------------------------------------------------------- |
|
48 // CPositioner::ConstructL |
|
49 // Symbian 2nd phase constructor can leave. |
|
50 // ----------------------------------------------------------------------------- |
|
51 // |
|
52 void CPositioner::ConstructL(RPositionServer& aServer, |
|
53 TPositionModuleId aModuleId, |
|
54 TPositionModuleInfo::TCapabilities aCapabilities) |
|
55 { |
|
56 BaseConstructL(aServer, aModuleId, aCapabilities); |
|
57 User::LeaveIfError(iTimer.CreateLocal()); |
|
58 } |
|
59 |
|
60 // ----------------------------------------------------------------------------- |
|
61 // CPositioner::NewL |
|
62 // Two-phased constructor. |
|
63 // ----------------------------------------------------------------------------- |
|
64 // |
|
65 CPositioner* CPositioner::NewL(LocationFunctionServer* aFunctionSource, |
|
66 RPositionServer& aServer, TPositionModuleId aModuleId, |
|
67 TPositionModuleInfo::TCapabilities aCapabilities) |
|
68 { |
|
69 CPositioner* self = new(ELeave) CPositioner(aFunctionSource); |
|
70 CleanupStack::PushL(self); |
|
71 self->ConstructL(aServer, aModuleId, aCapabilities); |
|
72 CleanupStack::Pop(self); |
|
73 return self; |
|
74 } |
|
75 |
|
76 // Destructor |
|
77 CPositioner::~CPositioner() |
|
78 { |
|
79 iTimer.Close(); |
|
80 Cancel(); |
|
81 } |
|
82 |
|
83 // ----------------------------------------------------------------------------- |
|
84 // CPositioner::StaticCancel |
|
85 // (other items were commented in a header). |
|
86 // ----------------------------------------------------------------------------- |
|
87 // |
|
88 void CPositioner::StaticCancel(CPositioner* aSelf) |
|
89 { |
|
90 aSelf->Cancel(); |
|
91 } |
|
92 |
|
93 // ----------------------------------------------------------------------------- |
|
94 // CPositioner::SetCallBackData |
|
95 // ----------------------------------------------------------------------------- |
|
96 // |
|
97 void CPositioner::SetCallBackData(jobject aJavaPositioner, JNIEnv* aJni) |
|
98 { |
|
99 mJni = aJni; |
|
100 mPeer = aJavaPositioner; |
|
101 |
|
102 jclass positionerClass = (*mJni).GetObjectClass(mPeer); |
|
103 |
|
104 //Get Method ID of Get Location Data Callback |
|
105 mGetLocationCallBack = mJni->GetMethodID(positionerClass, "syncComplete", |
|
106 "(I)V"); |
|
107 } |
|
108 |
|
109 // ----------------------------------------------------------------------------- |
|
110 // CPositioner::RunL |
|
111 // (other items were commented in a header). |
|
112 // ----------------------------------------------------------------------------- |
|
113 // |
|
114 void CPositioner::RunL() |
|
115 { |
|
116 TInt returnCode = iStatus.Int(); |
|
117 |
|
118 switch (returnCode) |
|
119 { |
|
120 case KErrNone: |
|
121 { |
|
122 // If previously returned code was buffer overflow just inform |
|
123 // that the request was successful. |
|
124 TInt ret = (iDelayedCode == KErrPositionBufferOverflow) |
|
125 || (iDelayedCode == KErrOverflow) ? KErrNone : iDelayedCode; |
|
126 // Obtained location information successfully, location fix is partial, |
|
127 // or the quality of the fix is poor. In the last two cases the |
|
128 // Java implementation tries to obtain location fix again. see API |
|
129 // specification about location fixes when temporary unavailable. |
|
130 // This is because the current implementation does not support partial |
|
131 // location fixes |
|
132 mJni = mFunctionServer->getValidJniEnv(); |
|
133 (*mJni).CallVoidMethod(mPeer, mGetLocationCallBack, ret); |
|
134 break; |
|
135 } |
|
136 case KErrOverflow: // Fallthrough |
|
137 case KErrPositionBufferOverflow: |
|
138 { |
|
139 // CPositionerBase handles buffer size errors |
|
140 HandleBufferSizeErrorL(returnCode); |
|
141 // Buffer increased successfully. Make a new request |
|
142 UpdatePosition(); |
|
143 break; |
|
144 } |
|
145 // Handle other return codes of RPositioner::NotifyPositionUpdate() |
|
146 // Partial update feature is not supported by this implementation |
|
147 case KPositionPartialUpdate: // Fallthrough |
|
148 case KPositionQualityLoss: // Fallthrough |
|
149 // KErrTimedOut is handled on Java-side |
|
150 case KErrTimedOut: // Fallthrough |
|
151 // KErrNotFound is returned if current module is invalid |
|
152 case KErrNotFound: // Fallthrough |
|
153 // HPositionGenericInfo should be supported by all PSYs |
|
154 case KErrArgument: // Fallthrough |
|
155 // KErrAccessDenied if no requestor specified |
|
156 case KErrAccessDenied: // Fallthrough |
|
157 case KErrUnknown: // Used in MLFW |
|
158 // Position request was canceled |
|
159 case KErrCancel: // Fallthrough |
|
160 // Bad implementation but due to partial fixes this cannot be fixed |
|
161 // at the moment. Correct when partial fixes are supported. Java tries |
|
162 // to obtain location fixes until time specified in Java-side expires |
|
163 // Delay response so that repeated calls to getLocation do not steal |
|
164 // all CPU time |
|
165 default: |
|
166 { |
|
167 iTimer.After(iStatus, KLocCallDelay); |
|
168 SetActive(); |
|
169 break; |
|
170 } |
|
171 } |
|
172 iDelayedCode = returnCode; |
|
173 } |
|
174 |
|
175 // ----------------------------------------------------------------------------- |
|
176 // CPositioner::DoCancel |
|
177 // (other items were commented in a header). |
|
178 // ----------------------------------------------------------------------------- |
|
179 // |
|
180 void CPositioner::DoCancel() |
|
181 { |
|
182 iTimer.Cancel(); |
|
183 iPositioner.CancelRequest(EPositionerNotifyPositionUpdate); |
|
184 mJni = mFunctionServer->getValidJniEnv(); |
|
185 (*mJni).CallVoidMethod(mPeer, mGetLocationCallBack, KErrCancel); |
|
186 } |
|
187 |
|
188 // ----------------------------------------------------------------------------- |
|
189 // CPositioner::RunError |
|
190 // (other items were commented in a header). |
|
191 // ----------------------------------------------------------------------------- |
|
192 // |
|
193 TInt CPositioner::RunError(TInt aError) |
|
194 { |
|
195 mJni = mFunctionServer->getValidJniEnv(); |
|
196 (*mJni).CallVoidMethod(mPeer, mGetLocationCallBack, aError); |
|
197 return KErrNone; |
|
198 } |
|
199 |
|
200 // ----------------------------------------------------------------------------- |
|
201 // CPositioner::GetLocation |
|
202 // (other items were commented in a header). |
|
203 // ----------------------------------------------------------------------------- |
|
204 // |
|
205 TInt CPositioner::GetLocation(TInt aTimeout) |
|
206 { |
|
207 TTimeIntervalMicroSeconds timeout = MAKE_TINT64(0, aTimeout) * 1000000; |
|
208 TPositionUpdateOptions updateOptions; |
|
209 updateOptions.SetUpdateTimeOut(timeout); |
|
210 |
|
211 TInt err = iPositioner.SetUpdateOptions(updateOptions); |
|
212 |
|
213 if (err == KErrNone) |
|
214 { |
|
215 UpdatePosition(); |
|
216 } |
|
217 return err; |
|
218 } |
|
219 |
|
220 // End of File |