20 |
20 |
21 #include "locationcoreimp.h" |
21 #include "locationcoreimp.h" |
22 #include "locationservice.h" |
22 #include "locationservice.h" |
23 |
23 |
24 |
24 |
25 |
25 CGetLoc::CGetLoc() : |
26 |
26 CActive(CActive::EPriorityStandard) |
27 |
27 { |
28 //Constructor |
28 |
29 |
29 } |
30 CGetLoc :: CGetLoc():CActive( CActive::EPriorityStandard ) |
30 |
31 { |
31 CGetLoc::~CGetLoc() |
32 |
32 |
|
33 { |
|
34 iPositioner.Close() ; |
|
35 delete iGenericPosInfo; |
|
36 iLocationService = NULL; |
|
37 |
33 } |
38 } |
34 |
39 |
35 /** |
40 /** |
36 * Funtion name: ConstructL |
41 * Funtion name: ConstructL |
37 * Constructs an active object and initalises this object |
42 * Constructs an active object and initalises this object |
38 * with subsessions for communicating with location server |
43 * with subsessions for communicating with location server |
39 */ |
44 */ |
40 |
45 |
41 void CGetLoc::ConstructL() |
46 void CGetLoc::ConstructL(RPositionServer& aPositionServer , |
|
47 TPositionFieldIdList aList , |
|
48 TInt aRequestType, |
|
49 TPositionModuleId aModuleId) |
42 { |
50 { |
43 // Initialise the position request sequence |
51 // Initialise the position request sequence |
44 |
52 |
45 DoInitialiseL(); |
53 DoInitialiseL(); |
46 |
54 |
47 } |
55 |
48 |
56 if( aModuleId.iUid ) |
49 |
57 { |
|
58 //Open a new subsession with position server |
|
59 User :: LeaveIfError((this->iPositioner).Open(aPositionServer,aModuleId)); |
|
60 } |
|
61 |
|
62 else |
|
63 { |
|
64 //Open a new subsession with position server using default module |
|
65 User :: LeaveIfError((this->iPositioner).Open(aPositionServer)) ; |
|
66 } |
|
67 |
|
68 CleanupClosePushL(iPositioner); |
|
69 //Set the identity of this particular requestor |
|
70 User::LeaveIfError( (this->iPositioner).SetRequestor( |
|
71 CRequestor::ERequestorService, |
|
72 CRequestor::EFormatApplication, |
|
73 KIdentity ) ); |
|
74 |
|
75 this->iPosInfoBase = &(this->iPositionInfo); |
|
76 this->iRequestType = aRequestType; |
|
77 this->iGenericPosInfo = HPositionGenericInfo :: NewL(); |
|
78 CleanupStack :: PushL(this->iGenericPosInfo); |
|
79 |
|
80 if(aList) |
|
81 { |
|
82 User :: LeaveIfError((this->iGenericPosInfo)->SetRequestedFields(aList)); |
|
83 } |
|
84 |
|
85 CleanupStack ::Pop(this->iGenericPosInfo ); |
|
86 CleanupStack::Pop(&iPositioner); |
|
87 } |
50 /** |
88 /** |
51 * Function name: NewL , |
89 * Function name: NewL , |
52 * Constructs a new core implementation object which will later |
90 * Constructs a new core implementation object which will later |
53 * Be added to active schedular |
91 * Be added to active schedular |
54 * on success returns pointer to constructed object, else leaves |
92 * on success returns pointer to constructed object, else leaves |
56 */ |
94 */ |
57 |
95 |
58 |
96 |
59 |
97 |
60 |
98 |
61 EXPORT_C CGetLoc* CGetLoc::NewL( RPositionServer &aPositionServer , |
99 EXPORT_C CGetLoc* CGetLoc::NewL( RPositionServer& aPositionServer , |
62 TPositionFieldIdList aList , |
100 TPositionFieldIdList aList , |
63 TInt aRequestType, |
101 TInt aRequestType, |
64 TInt /*aLocationInfoCategory*/ ) |
102 TInt /*aLocationInfoCategory*/, |
65 { |
103 TPositionModuleId aModuleId) |
66 //Check for the presence of ActiveScheduler |
104 { |
|
105 //Check for the presence of ActiveScheduler |
67 //Create the object |
106 //Create the object |
68 CActiveScheduler *current = CActiveScheduler::Current() ; |
107 |
|
108 CActiveScheduler* current = CActiveScheduler::Current(); |
69 |
109 |
70 if(!current) |
110 if(!current) |
71 { |
111 { |
72 User::Leave(KErrNotFound); //Leave if consumer is not event driven |
112 User::Leave(KErrNotFound); //Leave if consumer is not event driven |
73 } |
113 } |
74 |
|
75 |
114 |
76 CGetLoc* self = new( ELeave ) CGetLoc(); |
115 CGetLoc* self = new( ELeave ) CGetLoc(); |
77 CleanupStack::PushL(self); |
116 CleanupStack::PushL(self); |
78 |
117 |
79 TInt error = (self->iPositioner).Open(aPositionServer) ; //Open a new subsession with position server |
118 self->ConstructL(aPositionServer , |
80 |
119 aList , |
81 if(error) |
120 aRequestType, |
82 { |
121 aModuleId); |
83 User :: Leave( error) ; |
122 |
84 } |
123 CleanupStack::Pop(self); |
85 |
|
86 //Set the identity of this particular requestor |
|
87 User::LeaveIfError( (self->iPositioner).SetRequestor( CRequestor::ERequestorService, |
|
88 CRequestor::EFormatApplication, |
|
89 KIdentity ) ); |
|
90 |
|
91 |
|
92 |
|
93 self->iPosInfoBase = &(self->iPositionInfo) ; |
|
94 self->iRequestType = aRequestType ; |
|
95 self->iGenericPosInfo = HPositionGenericInfo :: NewL() ; |
|
96 |
|
97 if(aList) |
|
98 { |
|
99 error = (self->iGenericPosInfo)->SetRequestedFields(aList) ; |
|
100 } |
|
101 |
|
102 User :: LeaveIfError(error) ; |
|
103 CleanupStack :: PushL(self->iGenericPosInfo) ; |
|
104 |
|
105 self->ConstructL(); |
|
106 CleanupStack ::Pop(self->iGenericPosInfo ); |
|
107 CleanupStack::Pop( self ); |
|
108 |
124 |
109 //Return pointer to the created object |
125 //Return pointer to the created object |
110 return self; |
126 return self; |
111 } |
127 } |
112 |
128 |
113 CGetLoc ::~CGetLoc() |
|
114 |
|
115 { |
|
116 iPositioner.Close() ; |
|
117 delete iGenericPosInfo ; |
|
118 |
|
119 } |
|
120 |
129 |
121 TInt CGetLoc::DoInitialiseL() |
130 TInt CGetLoc::DoInitialiseL() |
122 { |
131 { |
123 iCallBack = NULL ; |
132 iCallBack = NULL ; |
124 iRequestStatus =0; |
133 iRequestStatus =0; |
128 |
137 |
129 |
138 |
130 |
139 |
131 |
140 |
132 /** |
141 /** |
133 * CGetLoc :: GetLocation accepts update options from the consumers |
142 * CGetLoc :: GetLocationUpdates accepts update options from the consumers and |
134 * returns the status of job submitted |
143 * submits an aynchronous request to the location server |
|
144 * Returns the status of job submitted |
135 */ |
145 */ |
136 |
146 |
137 TInt CGetLoc :: GetLocation( MLocationCallBack* aCallBackObj , |
147 TInt CGetLoc::GetLocationUpdates(CLocationService* aLocationService,MLocationCallBack* aCallBackObj, |
138 const TPositionUpdateOptions* aUpdateOptions ) |
148 const TPositionUpdateOptions* aUpdateOptions) |
139 { |
149 { |
|
150 //Pointer to CLocationService used in RunL |
|
151 iLocationService = aLocationService; |
140 |
152 |
141 //Register the call back address |
153 //Register the call back address |
142 iCallBack = aCallBackObj ; |
154 iCallBack = aCallBackObj ; |
143 TInt error = KErrNone ; |
155 TInt error = KErrNone ; |
144 //First set the update options before Issuing Notification request to server |
156 //First set the update options before Issuing Notification request to server |
191 |
203 |
192 |
204 |
193 |
205 |
194 |
206 |
195 |
207 |
196 /** |
|
197 * Function Name :GetLocationUpdates |
|
198 * Notifies the user whenever his position changes |
|
199 * Returns status of the submitted job |
|
200 */ |
|
201 |
|
202 TInt CGetLoc:: GetLocationUpdates( MLocationCallBack* aCallBackObj , |
|
203 const TPositionUpdateOptions* aUpdateOptions ) |
|
204 { |
|
205 |
|
206 //Register the call back address |
|
207 iCallBack = aCallBackObj ; |
|
208 |
|
209 if(aUpdateOptions) |
|
210 { |
|
211 TInt error = iPositioner.SetUpdateOptions(*aUpdateOptions) ; |
|
212 |
|
213 if(error) //If update options failed then no return error to caller |
|
214 { |
|
215 return error ; |
|
216 } |
|
217 } |
|
218 else //set the default values |
|
219 { |
|
220 TPositionUpdateOptions updateopts ; |
|
221 |
|
222 // Set update interval to one second to receive one position data per second |
|
223 updateopts.SetUpdateInterval(TTimeIntervalMicroSeconds(KSUpdateInterval)); |
|
224 |
|
225 // If position server could not get position |
|
226 // In two minutes it will terminate the position request |
|
227 updateopts.SetUpdateTimeOut(TTimeIntervalMicroSeconds(KSUpdateTimeOut)); |
|
228 |
|
229 // Positions which have time stamp below KMaxAge can be reused |
|
230 updateopts.SetMaxUpdateAge(TTimeIntervalMicroSeconds(KSMaxAge)); |
|
231 |
|
232 // Enables location framework to send partial position data |
|
233 updateopts.SetAcceptPartialUpdates(FALSE); |
|
234 |
|
235 |
|
236 iPositioner.SetUpdateOptions(updateopts) ; |
|
237 } |
|
238 |
|
239 |
|
240 if(!(this->IsAdded())) //Add to the active list if not added |
|
241 { |
|
242 CActiveScheduler :: Add(this) ; |
|
243 } |
|
244 |
|
245 |
|
246 iPositioner.NotifyPositionUpdate( *iGenericPosInfo, iStatus ); |
|
247 SetActive() ; |
|
248 return KErrNone ; |
|
249 } |
|
250 |
208 |
251 |
209 |
252 /** |
210 /** |
253 * RunL Method called by Active Scheduler after reciving an event |
211 * RunL Method called by Active Scheduler after reciving an event |
254 * This method actually calls the registered callbacks |
212 * This method actually calls the registered callbacks |
282 } |
240 } |
283 } |
241 } |
284 |
242 |
285 break ; |
243 break ; |
286 } |
244 } |
287 |
245 case KErrTimedOut: |
|
246 { |
|
247 iCallBack->HandleNotifyL(NULL , iStatus.Int()) ; |
|
248 //Re-issue the request even though there's an error |
|
249 if (iRequestType == KTraceRequest) |
|
250 { |
|
251 if (this->IsAdded() && !this->IsActive()) |
|
252 { |
|
253 if (!this->IsStatusComplete()) |
|
254 { |
|
255 iPositioner.NotifyPositionUpdate( *iGenericPosInfo, |
|
256 iStatus); |
|
257 SetActive(); |
|
258 } |
|
259 |
|
260 } |
|
261 } |
|
262 break; |
|
263 } |
288 case KErrArgument: |
264 case KErrArgument: |
289 case KPositionQualityLoss: //Need to check this returnig s60 error code from here |
265 case KPositionQualityLoss: //Need to check this returnig s60 error code from here |
290 case KErrTimedOut : |
|
291 case KErrNotFound : //Service provider not available, or gone down in between |
266 case KErrNotFound : //Service provider not available, or gone down in between |
292 { |
267 { |
293 |
268 |
294 iCallBack->HandleNotifyL(NULL , iStatus.Int()) ; |
269 iCallBack->HandleNotifyL(NULL , iStatus.Int()) ; |
295 break ; |
270 break ; |