|
1 /* |
|
2 * Copyright (c) 2009 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: Class used to set & get the trigger attributes |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "lbttriggernode.h" |
|
19 #include "lbtcontextsourceplugindebug.h" |
|
20 |
|
21 |
|
22 // --------------------------------------------------------------------------- |
|
23 // TTriggerNode::SetTriggerNameL |
|
24 // --------------------------------------------------------------------------- |
|
25 // |
|
26 void TTriggerNode::SetTriggerNameL( const TPtrC& aTriggerName ) |
|
27 { |
|
28 // Check that the name is not NULL,if Yes then |
|
29 // leave with KErrArgument |
|
30 if( aTriggerName == KNullDesC ) |
|
31 { |
|
32 User::Leave( KErrArgument ); |
|
33 } |
|
34 |
|
35 // Check that the length of the name is <= 256,if not then |
|
36 // extract only upto 256 characters before setting |
|
37 if( aTriggerName.Length() > KMaxNameLength ) |
|
38 { |
|
39 iTriggerName.Set( aTriggerName.Mid( 0,KMaxNameLength ) ); |
|
40 } |
|
41 else |
|
42 { |
|
43 iTriggerName.Set( aTriggerName ); |
|
44 } |
|
45 } |
|
46 |
|
47 // --------------------------------------------------------------------------- |
|
48 // TTriggerNode::SetLatitudeL |
|
49 // --------------------------------------------------------------------------- |
|
50 // |
|
51 void TTriggerNode::SetLatitudeL( const TPtrC& aLatitude ) |
|
52 { |
|
53 LBTCONTEXTSOURCEPLUGINDEBUG ( "TTriggerNode::SetLatitudeL - IN" ); |
|
54 // Check that the value is not NULL |
|
55 if( aLatitude == KNullDesC ) |
|
56 { |
|
57 // set value to NaN & leave with KErrArgument |
|
58 TRealX nan; |
|
59 nan.SetNaN(); |
|
60 iLatitude = nan; |
|
61 User::Leave( KErrArgument ); |
|
62 } |
|
63 |
|
64 // Convert the string to TReal64 |
|
65 // holds the parsed number in text form |
|
66 TBuf<KRealWidth> parsedLatitude; |
|
67 TLex lexer( aLatitude ); |
|
68 User::LeaveIfError( lexer.Val( iLatitude,KRealPoint ) ); |
|
69 // Format the real number to round off to 6 decimal digits |
|
70 // initialize the TRealFormat variable |
|
71 TRealFormat realFormat; |
|
72 realFormat.iPoint = KRealPoint; |
|
73 realFormat.iType = KRealFormatFixed | KDoNotUseTriads; |
|
74 realFormat.iPlaces = KCoordinateDecimalPlaces; |
|
75 realFormat.iWidth = KRealWidth; |
|
76 User::LeaveIfError( parsedLatitude.Num( iLatitude,realFormat ) ); |
|
77 // convert the formattted string back to TReal64 |
|
78 TLex lex( parsedLatitude ); |
|
79 User::LeaveIfError( lex.Val( iLatitude,KRealPoint ) ); |
|
80 |
|
81 // Check the range of the latitude value,if not within range |
|
82 // leave with KErrArgument |
|
83 if ( !( iLatitude >= KMinLatitude && iLatitude <= KMaxLatitude ) ) |
|
84 { |
|
85 User::Leave( KErrArgument ); |
|
86 } |
|
87 LBTCONTEXTSOURCEPLUGINDEBUG ( "TTriggerNode::SetLatitudeL - OUT" ); |
|
88 } |
|
89 |
|
90 // --------------------------------------------------------------------------- |
|
91 // TTriggerNode::SetLongitudeL |
|
92 // --------------------------------------------------------------------------- |
|
93 // |
|
94 void TTriggerNode::SetLongitudeL( const TPtrC& aLongitude ) |
|
95 { |
|
96 // Check that the value is not NULL |
|
97 if( aLongitude == KNullDesC ) |
|
98 { |
|
99 // set value to NaN & leave with KErrArgument |
|
100 TRealX nan; |
|
101 nan.SetNaN(); |
|
102 iLatitude = nan; |
|
103 User::Leave( KErrArgument ); |
|
104 } |
|
105 |
|
106 // Convert the string to TReal64 |
|
107 // holds the parsed number in text form |
|
108 TBuf<KRealWidth> parsedLongitude; |
|
109 TLex lexer( aLongitude ); |
|
110 User::LeaveIfError( lexer.Val( iLongitude,KRealPoint ) ); |
|
111 // Format the real number to round off to 6 decimal digits |
|
112 // initialize the TRealFormat variable |
|
113 TRealFormat realFormat; |
|
114 realFormat.iPoint = KRealPoint; |
|
115 realFormat.iType = KRealFormatFixed | KDoNotUseTriads; |
|
116 realFormat.iPlaces = KCoordinateDecimalPlaces; |
|
117 realFormat.iWidth = KRealWidth; |
|
118 User::LeaveIfError( parsedLongitude.Num( iLongitude,realFormat ) ); |
|
119 // convert the formattted string back to TReal64 |
|
120 TLex lex( parsedLongitude ); |
|
121 User::LeaveIfError( lex.Val( iLongitude,KRealPoint ) ); |
|
122 |
|
123 // Check the range of the latitude value,if not within range |
|
124 // leave with KErrArgument |
|
125 if ( !( iLongitude >= KMinLongitude && iLongitude <= KMaxLongitude ) ) |
|
126 { |
|
127 User::Leave( KErrArgument ); |
|
128 } |
|
129 } |
|
130 |
|
131 // --------------------------------------------------------------------------- |
|
132 // TTriggerNode::SetRegionL |
|
133 // --------------------------------------------------------------------------- |
|
134 // |
|
135 void TTriggerNode::SetRegionL( const TPtrC& aRegion ) |
|
136 { |
|
137 // Check that the value is not NULL |
|
138 if( aRegion == KNullDesC ) |
|
139 { |
|
140 User::Leave( KErrArgument ); |
|
141 } |
|
142 // check that the region specified is a circle,since it is the |
|
143 // only permissible value else leave with KErrArgument |
|
144 // Convert the value read from file to lower case inorder to compare |
|
145 // the values |
|
146 TInt length = aRegion.Length(); |
|
147 HBufC * buffer = HBufC::NewL( length ); |
|
148 CleanupStack::PushL( buffer ); |
|
149 TPtr ptr = buffer->Des(); |
|
150 ptr.Copy( aRegion ); |
|
151 ptr.LowerCase(); |
|
152 |
|
153 if ( ! ( ptr.CompareC( KRegionValue ) ) ) |
|
154 { |
|
155 iRegion.Set( aRegion ); |
|
156 } |
|
157 else |
|
158 { |
|
159 User::Leave( KErrArgument ); |
|
160 } |
|
161 CleanupStack::PopAndDestroy( buffer ); |
|
162 } |
|
163 |
|
164 // --------------------------------------------------------------------------- |
|
165 // TTriggerNode::SetRadiusL |
|
166 // --------------------------------------------------------------------------- |
|
167 // |
|
168 void TTriggerNode::SetRadiusL( const TPtrC& aRadius ) |
|
169 { |
|
170 // Check that the value is not NULL |
|
171 if( aRadius == KNullDesC ) |
|
172 { |
|
173 // set value to NaN & leave with KErrArgument |
|
174 TRealX nan; |
|
175 nan.SetNaN(); |
|
176 iRadius = nan; |
|
177 User::Leave( KErrArgument ); |
|
178 } |
|
179 |
|
180 // Check the radius value, |
|
181 // Minimum radius must be 100 meters |
|
182 TLex lex( aRadius ); |
|
183 TReal radiusValue = 0; |
|
184 User::LeaveIfError( lex.Val( radiusValue ) ); |
|
185 |
|
186 // Check that the radius value is positive else leave with KErrArgument |
|
187 if( radiusValue < 0 ) |
|
188 { |
|
189 User::Leave( KErrArgument ); |
|
190 } |
|
191 |
|
192 if ( radiusValue < KMinRadius ) |
|
193 { |
|
194 iRadius = KMinRadius; |
|
195 } |
|
196 else |
|
197 { |
|
198 iRadius = radiusValue; |
|
199 } |
|
200 } |
|
201 |
|
202 // --------------------------------------------------------------------------- |
|
203 // TTriggerNode::SetDirection |
|
204 // --------------------------------------------------------------------------- |
|
205 // |
|
206 void TTriggerNode::SetDirectionL( const TPtrC& aDirection ) |
|
207 { |
|
208 // If the value is null,then set default value to |
|
209 // CLbtTriggerConditionArea::EFireOnEnter |
|
210 if( aDirection == KNullDesC ) |
|
211 { |
|
212 iDirection = CLbtTriggerConditionArea::EFireOnEnter; |
|
213 } |
|
214 |
|
215 // Compare the value set in the file with the permissible values |
|
216 // If it doesnt match ,then set the default value |
|
217 // Convert the value read to lower case to compare the strings |
|
218 TInt length = aDirection.Length(); |
|
219 HBufC * buffer = HBufC::NewL( length ); |
|
220 TPtr ptr = buffer->Des(); |
|
221 ptr.Copy( aDirection ); |
|
222 ptr.LowerCase(); |
|
223 |
|
224 if( !( ptr.CompareC( KDirectionValueOnEntry ) ) ) |
|
225 { |
|
226 iDirection = CLbtTriggerConditionArea::EFireOnEnter; |
|
227 } |
|
228 else if( !( ptr.CompareC( KDirectionValueOnExit ) ) ) |
|
229 { |
|
230 iDirection = CLbtTriggerConditionArea::EFireOnExit; |
|
231 } |
|
232 else |
|
233 { |
|
234 iDirection = CLbtTriggerConditionArea::EFireOnEnter; |
|
235 } |
|
236 |
|
237 delete buffer; |
|
238 } |
|
239 |
|
240 // --------------------------------------------------------------------------- |
|
241 // TTriggerNode::SetContextSource |
|
242 // --------------------------------------------------------------------------- |
|
243 // |
|
244 void TTriggerNode::SetContextSource( const TPtrC& aSetName ) |
|
245 { |
|
246 // If the value is null,then set default context source value to "Location" |
|
247 if( aSetName == KNullDesC ) |
|
248 { |
|
249 iSetName.Set( KDefaultContextSourceName ); |
|
250 } |
|
251 |
|
252 // Check that the length of the name is <= 256,if not then |
|
253 // extract only upto 256 characters before setting |
|
254 if( aSetName.Length() > KMaxNameLength ) |
|
255 { |
|
256 iSetName.Set( aSetName.Mid( 0,KMaxNameLength ) ); |
|
257 } |
|
258 else |
|
259 { |
|
260 iSetName.Set(aSetName); |
|
261 } |
|
262 } |
|
263 |
|
264 // --------------------------------------------------------------------------- |
|
265 // TTriggerNode::SetCurrentState |
|
266 // --------------------------------------------------------------------------- |
|
267 // |
|
268 void TTriggerNode::SetCurrentStateL( const TPtrC& aCurrentState ) |
|
269 { |
|
270 // If the value is null,then set default value to |
|
271 // CLbtTriggerEntry::EStateEnabled |
|
272 if( aCurrentState == KNullDesC ) |
|
273 { |
|
274 iCurrentState = CLbtTriggerEntry::EStateEnabled; |
|
275 } |
|
276 |
|
277 // Compare the value set in the file with the permissible values |
|
278 // If it doesnt match ,then set the default value |
|
279 // Convert the value read to lower case to compare the strings |
|
280 TInt length = aCurrentState.Length(); |
|
281 HBufC * buffer = HBufC::NewL( length ); |
|
282 TPtr ptr = buffer->Des(); |
|
283 ptr.Copy( aCurrentState ); |
|
284 ptr.LowerCase(); |
|
285 |
|
286 if( !( ptr.CompareC( KCurrentStateOn ) ) ) |
|
287 { |
|
288 iCurrentState = CLbtTriggerEntry::EStateEnabled; |
|
289 } |
|
290 else if( !( ptr.CompareC( KCurrentStateOff ) ) ) |
|
291 { |
|
292 iCurrentState = CLbtTriggerEntry::EStateDisabled; |
|
293 } |
|
294 else |
|
295 { |
|
296 iCurrentState = CLbtTriggerEntry::EStateEnabled; |
|
297 } |
|
298 |
|
299 delete buffer; |
|
300 } |
|
301 |
|
302 // --------------------------------------------------------------------------- |
|
303 // TTriggerNode::GetTriggerName |
|
304 // --------------------------------------------------------------------------- |
|
305 // |
|
306 TInt TTriggerNode::GetTriggerName( TPtrC& aTriggerName ) |
|
307 { |
|
308 if ( iTriggerName == KNullDesC ) |
|
309 { |
|
310 return KErrNotFound; |
|
311 } |
|
312 |
|
313 aTriggerName.Set( iTriggerName ); |
|
314 return KErrNone; |
|
315 } |
|
316 |
|
317 // --------------------------------------------------------------------------- |
|
318 // TTriggerNode::GetLatitude |
|
319 // --------------------------------------------------------------------------- |
|
320 // |
|
321 TInt TTriggerNode::GetLatitude( TReal& aLatitude ) |
|
322 { |
|
323 if ( Math::IsNaN( iLatitude ) ) |
|
324 { |
|
325 return KErrNotFound; |
|
326 } |
|
327 |
|
328 aLatitude = iLatitude; |
|
329 return KErrNone; |
|
330 } |
|
331 |
|
332 // --------------------------------------------------------------------------- |
|
333 // TTriggerNode::GetLongitude |
|
334 // --------------------------------------------------------------------------- |
|
335 // |
|
336 TInt TTriggerNode::GetLongitude( TReal& aLongitude ) |
|
337 { |
|
338 if ( Math::IsNaN( iLongitude ) ) |
|
339 { |
|
340 return KErrNotFound; |
|
341 } |
|
342 |
|
343 aLongitude = iLongitude; |
|
344 return KErrNone; |
|
345 } |
|
346 |
|
347 // --------------------------------------------------------------------------- |
|
348 // TTriggerNode::GetDirection |
|
349 // --------------------------------------------------------------------------- |
|
350 // |
|
351 CLbtTriggerConditionArea::TDirection TTriggerNode::GetDirection() |
|
352 { |
|
353 return iDirection; |
|
354 } |
|
355 |
|
356 |
|
357 |
|
358 // --------------------------------------------------------------------------- |
|
359 // TTriggerNode::GetRegion |
|
360 // --------------------------------------------------------------------------- |
|
361 // |
|
362 TInt TTriggerNode::GetRegion( TPtrC& aRegion ) |
|
363 { |
|
364 if ( iRegion == KNullDesC ) |
|
365 { |
|
366 return KErrNotFound; |
|
367 } |
|
368 |
|
369 aRegion.Set( iRegion ); |
|
370 return KErrNone; |
|
371 } |
|
372 |
|
373 // --------------------------------------------------------------------------- |
|
374 // TTriggerNode::GetRadius |
|
375 // --------------------------------------------------------------------------- |
|
376 // |
|
377 TInt TTriggerNode::GetRadius( TReal& aRadius ) |
|
378 { |
|
379 if ( Math::IsNaN( iRadius ) ) |
|
380 { |
|
381 return KErrNotFound; |
|
382 } |
|
383 |
|
384 aRadius = iRadius; |
|
385 return KErrNone; |
|
386 } |
|
387 |
|
388 // --------------------------------------------------------------------------- |
|
389 // TTriggerNode::GetContextSource |
|
390 // --------------------------------------------------------------------------- |
|
391 // |
|
392 TPtrC& TTriggerNode::GetContextSource() |
|
393 { |
|
394 return iSetName; |
|
395 } |
|
396 |
|
397 // --------------------------------------------------------------------------- |
|
398 // TTriggerNode::GetCurrentState |
|
399 // --------------------------------------------------------------------------- |
|
400 // |
|
401 CLbtTriggerEntry::TLbtTriggerState TTriggerNode::GetCurrentState() |
|
402 { |
|
403 return iCurrentState; |
|
404 } |
|
405 |