1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
|
/*
* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <locations_private.h>
#include <dlog.h>
#ifdef LOG_TAG
#undef LOG_TAG
#endif
#define LOG_TAG "TIZEN_N_LOCATION_MANAGER"
/*
* Internal Macros
*/
#define LOCATIONS_CHECK_CONDITION(condition,error,msg) \
if(condition) {} else \
{ LOGE("[%s] %s(0x%08x)",__FUNCTION__, msg,error); return error;}; \
#define LOCATIONS_NULL_ARG_CHECK(arg) \
LOCATIONS_CHECK_CONDITION(arg != NULL,LOCATIONS_ERROR_INVALID_PARAMETER,"LOCATIONS_ERROR_INVALID_PARAMETER")
/*
* Internal Implementation
*/
int _convert_error_code(int code,char *func_name)
{
int ret;
char* msg = "LOCATIONS_ERROR_NONE";
switch(code)
{
case LOCATION_ERROR_NONE:
ret = LOCATIONS_ERROR_NONE;
msg = "LOCATIONS_ERROR_NONE";
break;
case LOCATION_ERROR_NETWORK_FAILED:
case LOCATION_ERROR_NETWORK_NOT_CONNECTED:
ret = LOCATIONS_ERROR_NETWORK_FAILED;
msg = "LOCATIONS_ERROR_NETWORK_FAILED";
break;
case LOCATION_ERROR_NOT_ALLOWED:
ret = LOCATIONS_ERROR_GPS_SETTING_OFF;
msg = "LOCATIONS_ERROR_GPS_SETTING_OFF";
break;
case LOCATION_ERROR_NOT_AVAILABLE:
case LOCATION_ERROR_CONFIGURATION:
case LOCATION_ERROR_PARAMETER:
case LOCATION_ERROR_UNKNOWN:
default:
msg = "LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE";
ret = LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
}
LOGE("[%s] %s(0x%08x) : core fw error(0x%x)",func_name,msg, ret, code);
return ret;
}
void cb_service_updated (GObject *self, guint type, gpointer data, gpointer accuracy, gpointer userdata)
{
LOGI("[%s] Callback function has been invoked. ",__FUNCTION__);
location_manager_s * handle = (location_manager_s*)userdata;
if( type == VELOCITY_UPDATED && handle->user_cb[_LOCATIONS_EVENT_TYPE_VELOCITY])
{
LocationVelocity *vel = (LocationVelocity*) data;
LOGI("[%s] Current velocity: timestamp : %d, speed: %f, direction : %f, climb : %f", __FUNCTION__ , vel->timestamp, vel->speed, vel->direction, vel->climb);
((location_velocity_updated_cb)handle->user_cb[_LOCATIONS_EVENT_TYPE_VELOCITY])(vel->speed, vel->direction,vel->climb, vel->timestamp ,handle->user_data[_LOCATIONS_EVENT_TYPE_VELOCITY]);
}
if( type == POSITION_UPDATED && handle->user_cb[_LOCATIONS_EVENT_TYPE_POSITION])
{
LocationPosition *pos = (LocationPosition*) data;
LOGI("[%s] Current position: timestamp : %d, latitude : %f, altitude: %f, longitude: %f", __FUNCTION__ , pos->timestamp, pos->latitude, pos->altitude, pos->longitude);
((location_position_updated_cb)handle->user_cb[_LOCATIONS_EVENT_TYPE_POSITION])(pos->latitude, pos->longitude,pos->altitude, pos->timestamp ,handle->user_data[_LOCATIONS_EVENT_TYPE_POSITION]);
}
}
void cb_service_enabled (GObject *self, guint status, gpointer userdata)
{
LOGI("[%s] Callback function has been invoked. ",__FUNCTION__);
location_manager_s * handle = (location_manager_s*)userdata;
if(handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE])
{
((location_service_state_changed_cb)handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE])(LOCATIONS_SERVICE_ENABLED,handle->user_data[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]);
}
}
void cb_service_disabled (GObject *self, guint status, gpointer userdata)
{
LOGI("[%s] Callback function has been invoked. ",__FUNCTION__);
location_manager_s * handle = (location_manager_s*)userdata;
if( handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE] )
((location_service_state_changed_cb)handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE])(LOCATIONS_SERVICE_DISABLED,handle->user_data[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]);
}
void cb_zone_in (GObject *self, guint type, gpointer position, gpointer accuracy, gpointer userdata)
{
location_manager_s * handle = (location_manager_s*)userdata;
if( handle->user_cb[_LOCATIONS_EVENT_TYPE_BOUNDARY] )
{
LocationPosition *pos = (LocationPosition*) position;
((location_zone_changed_cb)handle->user_cb[_LOCATIONS_EVENT_TYPE_BOUNDARY])(LOCATIONS_BOUNDARY_IN, pos->latitude,pos->longitude,pos->altitude, pos->timestamp ,handle->user_data[_LOCATIONS_EVENT_TYPE_BOUNDARY]);
}
}
void cb_zone_out (GObject *self, guint type, gpointer position, gpointer accuracy, gpointer userdata)
{
location_manager_s * handle = (location_manager_s*)userdata;
if( handle->user_cb[_LOCATIONS_EVENT_TYPE_BOUNDARY] )
{
LocationPosition *pos = (LocationPosition*) position;
((location_zone_changed_cb)handle->user_cb[_LOCATIONS_EVENT_TYPE_BOUNDARY])(LOCATIONS_BOUNDARY_OUT, pos->latitude,pos->longitude,pos->altitude, pos->timestamp ,handle->user_data[_LOCATIONS_EVENT_TYPE_BOUNDARY]);
}
}
int _set_callback(_location_event_e type, location_manager_h manager, void* callback, void *user_data)
{
LOCATIONS_NULL_ARG_CHECK(manager);
LOCATIONS_NULL_ARG_CHECK(callback);
location_manager_s * handle = (location_manager_s *) manager;
handle->user_cb[type] = callback;
handle->user_data[type] = user_data;
LOGI("[%s] event type : %d. ",__FUNCTION__, type);
return LOCATIONS_ERROR_NONE;
}
int _unset_callback(_location_event_e type, location_manager_h manager)
{
LOCATIONS_NULL_ARG_CHECK(manager);
location_manager_s * handle = (location_manager_s *) manager;
handle->user_cb[type] = NULL;
handle->user_data[type] = NULL;
LOGI("[%s] event type : %d. ",__FUNCTION__, type);
return LOCATIONS_ERROR_NONE;
}
void _remove_boundary(LocationBoundary *boundary, void *user_data)
{
LocationObject* loc = (LocationObject*) user_data;
if (loc != NULL && boundary != NULL)
{
int ret = location_boundary_remove(loc, boundary);
if(ret != LOCATION_ERROR_NONE)
{
LOGI("[%s] Failed to remove boundary : 0x%x. ",__FUNCTION__, ret);
}
else
{
LOGI("[%s] Delete previous boundary - type : %d ",__FUNCTION__, boundary->type);
}
}
}
/////////////////////////////////////////
// Location Manager
////////////////////////////////////////
/*
* Public Implementation
*/
bool location_manager_is_supported_method(location_method_e method)
{
LocationMethod _method = LOCATION_METHOD_NONE;
switch(method)
{
case LOCATIONS_METHOD_HYBRID :
_method = LOCATION_METHOD_HYBRID;
break;
case LOCATIONS_METHOD_GPS:
_method = LOCATION_METHOD_GPS;
break;
case LOCATIONS_METHOD_WPS :
_method = LOCATION_METHOD_WPS;
break;
case LOCATIONS_METHOD_SPS :
_method = LOCATION_METHOD_SPS;
break;
default :
_method = LOCATION_METHOD_NONE;
break;
}
return location_is_supported_method(_method);
}
int location_manager_create(location_method_e method, location_manager_h* manager)
{
LOCATIONS_NULL_ARG_CHECK(manager);
if(location_init()!=LOCATION_ERROR_NONE)
return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
LocationMethod _method = LOCATION_METHOD_NONE;
switch(method)
{
case LOCATIONS_METHOD_NONE :
_method = LOCATION_METHOD_NONE;
break;
case LOCATIONS_METHOD_HYBRID :
_method = LOCATION_METHOD_HYBRID;
break;
case LOCATIONS_METHOD_GPS:
_method = LOCATION_METHOD_GPS;
break;
case LOCATIONS_METHOD_WPS :
_method = LOCATION_METHOD_WPS;
break;
case LOCATIONS_METHOD_SPS :
_method = LOCATION_METHOD_SPS;
break;
default :
{
LOGE("[%s] LOCATIONS_ERROR_INVALID_PARAMETER(0x%08x) : Out of range (location_method_e) - method : %d ",__FUNCTION__,LOCATIONS_ERROR_INVALID_PARAMETER, method);
return LOCATIONS_ERROR_INVALID_PARAMETER;
}
}
location_manager_s *handle = (location_manager_s*)malloc(sizeof(location_manager_s));
if(handle==NULL)
{
LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __FUNCTION__, LOCATIONS_ERROR_OUT_OF_MEMORY);
return LOCATIONS_ERROR_OUT_OF_MEMORY;
}
memset(handle, 0 , sizeof(location_manager_s));
handle->object = location_new(_method);
if(handle->object == NULL)
{
LOGE("[%s] LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : fail to location_new", __FUNCTION__, LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
free(handle);
return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
}
handle->method = method;
handle->boundary= NULL;
*manager = (location_manager_h)handle;
return LOCATIONS_ERROR_NONE;
}
int location_manager_destroy(location_manager_h manager)
{
LOCATIONS_NULL_ARG_CHECK(manager);
location_manager_s *handle = (location_manager_s*)manager;
if(handle->boundary)
{
location_boundary_free(handle->boundary);
}
int ret = location_free(handle->object);
if(ret!=LOCATIONS_ERROR_NONE)
{
return _convert_error_code(ret,(char*)__FUNCTION__);
}
free(handle);
return LOCATIONS_ERROR_NONE;
}
int location_manager_start(location_manager_h manager)
{
LOCATIONS_NULL_ARG_CHECK(manager);
location_manager_s *handle = (location_manager_s*)manager;
g_signal_connect (handle->object, "service-enabled", G_CALLBACK(cb_service_enabled), handle);
g_signal_connect (handle->object, "service-disabled", G_CALLBACK(cb_service_disabled), handle);
g_signal_connect (handle->object, "service-updated", G_CALLBACK(cb_service_updated), handle);
g_signal_connect (handle->object, "zone-in", G_CALLBACK(cb_zone_in), handle);
g_signal_connect (handle->object, "zone-out", G_CALLBACK(cb_zone_out), handle);
int ret = location_start (handle->object);
if( ret != LOCATION_ERROR_NONE)
{
return _convert_error_code(ret,(char*)__FUNCTION__);
}
return LOCATIONS_ERROR_NONE;
}
int location_manager_stop(location_manager_h manager)
{
LOCATIONS_NULL_ARG_CHECK(manager);
location_manager_s *handle = (location_manager_s*)manager;
int ret = location_stop (handle->object);
if( ret != LOCATION_ERROR_NONE)
{
return _convert_error_code(ret,(char*)__FUNCTION__);
}
return LOCATIONS_ERROR_NONE;
}
int location_manager_set_boundary_rect(location_manager_h manager, double top_left_latitude,double top_left_longitude,double bottom_right_latitude,double bottom_right_longitude)
{
LOCATIONS_NULL_ARG_CHECK(manager);
LOCATIONS_CHECK_CONDITION(top_left_latitude>=-90 && top_left_latitude<=90,LOCATIONS_ERROR_INVALID_PARAMETER,"LOCATIONS_ERROR_INVALID_PARAMETER");
LOCATIONS_CHECK_CONDITION(top_left_longitude>=-180 && bottom_right_longitude<=180,LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
LOCATIONS_CHECK_CONDITION(bottom_right_latitude>=-90 && bottom_right_latitude<=90,LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
LOCATIONS_CHECK_CONDITION(bottom_right_longitude>=-180 && bottom_right_longitude<=180,LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
location_manager_s *handle = (location_manager_s*)manager;
int ret;
ret = location_boundary_foreach(handle->object, _remove_boundary,handle->object );
if(ret != LOCATION_ERROR_NONE)
{
LOGI("[%s] Failed to foreach boundary : 0x%x. ",__FUNCTION__, ret);
}
LocationPosition *rb = location_position_new(0, bottom_right_latitude, bottom_right_longitude, 0, LOCATION_STATUS_2D_FIX);
if (rb ==NULL)
{
LOGE("[%s] LOCATIONS_ERROR_OUT_OF_MEMORY(0x%08x) : fail to location_position_new", __FUNCTION__, LOCATIONS_ERROR_OUT_OF_MEMORY);
return LOCATIONS_ERROR_OUT_OF_MEMORY;
}
LocationPosition *lt = location_position_new(0, top_left_latitude, top_left_longitude, 0, LOCATION_STATUS_2D_FIX);
if (lt ==NULL)
{
LOGE("[%s] LOCATIONS_ERROR_OUT_OF_MEMORY(0x%08x) : fail to location_position_new", __FUNCTION__, LOCATIONS_ERROR_OUT_OF_MEMORY);
location_position_free (rb);
return LOCATIONS_ERROR_OUT_OF_MEMORY;
}
LocationBoundary* bound = NULL;
bound = location_boundary_new_for_rect(lt, rb);
location_position_free (rb);
location_position_free (lt);
if(bound)
{
ret = location_boundary_add(handle->object, bound);
if(handle->boundary)
{
location_boundary_free(handle->boundary);
handle->boundary = NULL;
}
handle->boundary = location_boundary_copy(bound);
location_boundary_free(bound);
if( ret != LOCATION_ERROR_NONE)
{
return _convert_error_code(ret,(char*)__FUNCTION__);
}
}
else
{
LOGE("[%s] LOCATIONS_ERROR_OUT_OF_MEMORY(0x%08x) : fail to location_boundary_new_for_rect", __FUNCTION__, LOCATIONS_ERROR_OUT_OF_MEMORY);
return LOCATIONS_ERROR_OUT_OF_MEMORY;
}
return LOCATIONS_ERROR_NONE;
}
int location_manager_set_boundary_circle(location_manager_h manager, double center_latitude,double center_longitude, double radius)
{
LOCATIONS_NULL_ARG_CHECK(manager);
LOCATIONS_CHECK_CONDITION(center_latitude>=-90 && center_latitude<=90,LOCATIONS_ERROR_INVALID_PARAMETER,"LOCATIONS_ERROR_INVALID_PARAMETER");
LOCATIONS_CHECK_CONDITION(center_longitude>=-180 && center_longitude<=180,LOCATIONS_ERROR_INVALID_PARAMETER,"LOCATIONS_ERROR_INVALID_PARAMETER");
LOCATIONS_CHECK_CONDITION(radius>=0,LOCATIONS_ERROR_INVALID_PARAMETER,"LOCATIONS_ERROR_INVALID_PARAMETER");
location_manager_s *handle = (location_manager_s*)manager;
int ret;
ret = location_boundary_foreach(handle->object, _remove_boundary, handle->object);
if(ret != LOCATION_ERROR_NONE)
{
LOGI("[%s] Failed to foreach boundary : 0x%x. ",__FUNCTION__, ret);
}
LocationPosition *center = location_position_new(0, center_latitude, center_longitude, 0, LOCATION_STATUS_2D_FIX);
if (center ==NULL)
{
LOGE("[%s] LOCATIONS_ERROR_OUT_OF_MEMORY(0x%08x) : fail to location_position_new", __FUNCTION__, LOCATIONS_ERROR_OUT_OF_MEMORY);
return LOCATIONS_ERROR_OUT_OF_MEMORY;
}
LocationBoundary* bound = NULL;
bound = location_boundary_new_for_circle(center,radius);
location_position_free (center);
if(bound)
{
ret = location_boundary_add(handle->object, bound);
if(handle->boundary)
{
location_boundary_free(handle->boundary);
handle->boundary = NULL;
}
handle->boundary = location_boundary_copy(bound);
location_boundary_free(bound);
if( ret != LOCATION_ERROR_NONE)
{
return _convert_error_code(ret,(char*)__FUNCTION__);
}
}
else
{
LOGE("[%s] LOCATIONS_ERROR_OUT_OF_MEMORY(0x%08x) : fail to location_boundary_new_for_circle", __FUNCTION__, LOCATIONS_ERROR_OUT_OF_MEMORY);
return LOCATIONS_ERROR_OUT_OF_MEMORY;
}
return LOCATIONS_ERROR_NONE;
}
int location_manager_is_boundary_contains_coordinate(location_manager_h manager, double latitude, double longitude, bool *contained)
{
LOCATIONS_NULL_ARG_CHECK(manager);
LOCATIONS_NULL_ARG_CHECK(contained);
LOCATIONS_CHECK_CONDITION(latitude>=-90 && latitude<=90,LOCATIONS_ERROR_INVALID_PARAMETER,"LOCATIONS_ERROR_INVALID_PARAMETER");
LOCATIONS_CHECK_CONDITION(longitude>=-180 && longitude<=180,LOCATIONS_ERROR_INVALID_PARAMETER,"LOCATIONS_ERROR_INVALID_PARAMETER");
location_manager_s *handle = (location_manager_s*)manager;
if(handle->boundary==NULL)
{
LOGI("[%s] There is no boundary ",__FUNCTION__);
*contained = FALSE;
return LOCATIONS_ERROR_NONE;
}
LocationPosition *pos = location_position_new(0, latitude, longitude, 0, LOCATION_STATUS_2D_FIX);
if (pos ==NULL)
{
LOGE("[%s] LOCATIONS_ERROR_OUT_OF_MEMORY(0x%08x) : fail to location_position_new", __FUNCTION__, LOCATIONS_ERROR_OUT_OF_MEMORY);
*contained = FALSE;
return LOCATIONS_ERROR_OUT_OF_MEMORY;
}
gboolean is_inside = location_boundary_if_inside(handle->boundary, pos);
if(is_inside)
{
*contained = TRUE;
}
else
{
*contained = FALSE;
}
location_position_free (pos);
return LOCATIONS_ERROR_NONE;
}
int location_manager_get_method(location_manager_h manager, location_method_e* method)
{
LOCATIONS_NULL_ARG_CHECK(manager);
LOCATIONS_NULL_ARG_CHECK(method);
location_manager_s *handle = (location_manager_s*)manager;
LocationMethod _method = LOCATION_METHOD_NONE;
g_object_get(handle->object, "method", &_method, NULL);
switch(_method)
{
case LOCATION_METHOD_NONE :
*method = LOCATIONS_METHOD_NONE;
break;
case LOCATION_METHOD_HYBRID :
case LOCATION_METHOD_CPS:
case LOCATION_METHOD_IPS :
*method = LOCATIONS_METHOD_HYBRID;
break;
case LOCATION_METHOD_GPS:
*method = LOCATIONS_METHOD_GPS;
break;
case LOCATION_METHOD_WPS :
*method = LOCATIONS_METHOD_WPS;
break;
case LOCATION_METHOD_SPS :
*method = LOCATIONS_METHOD_SPS;
break;
default :
{
LOGE("[%s] LOCATIONS_ERROR_INVALID_PARAMETER(0x%08x) : Out of range (location_method_e) - method : %d ",__FUNCTION__,LOCATIONS_ERROR_INVALID_PARAMETER, method);
return LOCATIONS_ERROR_INVALID_PARAMETER;
}
}
//*method = handle->method;
return LOCATIONS_ERROR_NONE;
}
int location_manager_get_position(location_manager_h manager, double *altitude, double *latitude, double *longitude, time_t *timestamp)
{
LOCATIONS_NULL_ARG_CHECK(manager);
LOCATIONS_NULL_ARG_CHECK(altitude);
LOCATIONS_NULL_ARG_CHECK(latitude);
LOCATIONS_NULL_ARG_CHECK(longitude);
LOCATIONS_NULL_ARG_CHECK(timestamp);
location_manager_s *handle = (location_manager_s*)manager;
int ret;
LocationPosition *pos = NULL;
LocationAccuracy *acc = NULL;
ret = location_get_position(handle->object, &pos, &acc);
if( ret != LOCATION_ERROR_NONE)
{
return _convert_error_code(ret,(char*)__FUNCTION__);
}
if(pos->status == LOCATION_STATUS_NO_FIX)
{
*altitude = -1;
*latitude = -1;
*longitude =-1;
}
else
{
if(pos->status == LOCATION_STATUS_3D_FIX)
{
*altitude = pos->altitude;
}
else
{
*altitude = -1;
}
*latitude = pos->latitude;
*longitude = pos->longitude;
}
*timestamp = pos->timestamp;
location_position_free (pos);
location_accuracy_free (acc);
return LOCATIONS_ERROR_NONE;
}
int location_manager_get_velocity(location_manager_h manager, int *climb, int *direction, int *speed, time_t *timestamp)
{
LOCATIONS_NULL_ARG_CHECK(manager);
LOCATIONS_NULL_ARG_CHECK(climb);
LOCATIONS_NULL_ARG_CHECK(direction);
LOCATIONS_NULL_ARG_CHECK(speed);
LOCATIONS_NULL_ARG_CHECK(timestamp);
location_manager_s *handle = (location_manager_s*)manager;
int ret;
LocationVelocity *vel = NULL;
LocationAccuracy *acc = NULL;
ret = location_get_velocity(handle->object, &vel, &acc);
if( ret != LOCATION_ERROR_NONE)
{
return _convert_error_code(ret,(char*)__FUNCTION__);
}
*climb = vel->climb;
*direction = vel->direction;
*speed = vel->speed;
*timestamp = vel->timestamp;
location_velocity_free(vel);
location_accuracy_free(acc);
return LOCATIONS_ERROR_NONE;
}
int location_manager_get_accuracy(location_manager_h manager, location_accuracy_level_e *level, double *horizontal, double *vertical)
{
LOCATIONS_NULL_ARG_CHECK(manager);
LOCATIONS_NULL_ARG_CHECK(level);
LOCATIONS_NULL_ARG_CHECK(horizontal);
LOCATIONS_NULL_ARG_CHECK(vertical);
location_manager_s *handle = (location_manager_s*)manager;
int ret;
LocationPosition *pos = NULL;
LocationAccuracy *acc = NULL;
ret = location_get_position(handle->object, &pos, &acc);
if( ret != LOCATION_ERROR_NONE)
{
return _convert_error_code(ret,(char*)__FUNCTION__);
}
*level = acc->level;
*horizontal = acc->horizontal_accuracy;
*vertical = acc->vertical_accuracy;
location_position_free(pos);
location_accuracy_free(acc);
return LOCATIONS_ERROR_NONE;
}
int location_manager_get_last_known_position(location_manager_h manager, double *altitude, double *latitude, double *longitude, time_t *timestamp)
{
LOCATIONS_NULL_ARG_CHECK(manager);
LOCATIONS_NULL_ARG_CHECK(altitude);
LOCATIONS_NULL_ARG_CHECK(latitude);
LOCATIONS_NULL_ARG_CHECK(longitude);
LOCATIONS_NULL_ARG_CHECK(timestamp);
location_manager_s *handle = (location_manager_s*)manager;
LocationMethod _method = LOCATION_METHOD_NONE;
g_object_get(handle->object, "method", &_method, NULL);
int ret;
LocationLastPosition pos;
ret = location_get_last_known_position(handle->object, _method, &pos);
if (ret == LOCATION_ERROR_UNKNOWN)
{
*altitude = 0;
*latitude = 0;
*longitude =0;
*timestamp = 0;
LOGI("[%s] There is no record of any previous position information. ",__FUNCTION__);
return LOCATIONS_ERROR_NONE;
}
else if( ret != LOCATION_ERROR_NONE)
{
return _convert_error_code(ret,(char*)__FUNCTION__);
}
*altitude = pos.altitude;
*latitude = pos.latitude;
*longitude = pos.longitude;
*timestamp = pos.timestamp;
return LOCATIONS_ERROR_NONE;
}
int location_manager_set_position_updated_cb(location_manager_h manager, location_position_updated_cb callback, int interval, void *user_data)
{
LOCATIONS_CHECK_CONDITION(interval>=1 && interval<=120, LOCATIONS_ERROR_INVALID_PARAMETER,"LOCATIONS_ERROR_INVALID_PARAMETER");
LOCATIONS_NULL_ARG_CHECK(manager);
location_manager_s *handle = (location_manager_s*)manager;
g_object_set(handle->object, "update-interval", interval, NULL);
return _set_callback(_LOCATIONS_EVENT_TYPE_POSITION,manager,callback,user_data);
}
int location_manager_unset_position_updated_cb(location_manager_h manager)
{
return _unset_callback(_LOCATIONS_EVENT_TYPE_POSITION,manager);
}
int location_manager_set_velocity_updated_cb(location_manager_h manager, location_velocity_updated_cb callback, void *user_data)
{
return _set_callback(_LOCATIONS_EVENT_TYPE_VELOCITY,manager,callback,user_data);
}
int location_manager_unset_velocity_updated_cb(location_manager_h manager)
{
return _unset_callback(_LOCATIONS_EVENT_TYPE_VELOCITY,manager);
}
int location_manager_set_service_state_changed_cb(location_manager_h manager, location_service_state_changed_cb callback, void *user_data)
{
return _set_callback(_LOCATIONS_EVENT_TYPE_SERVICE_STATE,manager,callback,user_data);
}
int location_manager_unset_service_state_changed_cb(location_manager_h manager)
{
return _unset_callback(_LOCATIONS_EVENT_TYPE_SERVICE_STATE,manager);
}
int location_manager_set_zone_changed_cb(location_manager_h manager, location_zone_changed_cb callback, void *user_data)
{
return _set_callback(_LOCATIONS_EVENT_TYPE_BOUNDARY,manager,callback,user_data);
}
int location_manager_unset_zone_changed_cb(location_manager_h manager)
{
return _unset_callback(_LOCATIONS_EVENT_TYPE_BOUNDARY,manager);
}
/////////////////////////////////////////
// GPS Status & Satellites
////////////////////////////////////////
int gps_status_get_nmea(location_manager_h manager, char** nmea)
{
LOCATIONS_NULL_ARG_CHECK(manager);
LOCATIONS_NULL_ARG_CHECK(nmea);
location_manager_s *handle = (location_manager_s*)manager;
if(handle->method == LOCATIONS_METHOD_HYBRID)
{
LocationMethod _method = LOCATION_METHOD_NONE;
g_object_get(handle->object, "method", &_method, NULL);
if(_method!=LOCATION_METHOD_GPS)
{
LOGE("[%s] LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d", __FUNCTION__, LOCATIONS_ERROR_INCORRECT_METHOD, handle->method);
return LOCATIONS_ERROR_INCORRECT_METHOD;
}
}
else if(handle->method != LOCATIONS_METHOD_GPS)
{
LOGE("[%s] LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d", __FUNCTION__, LOCATIONS_ERROR_INCORRECT_METHOD, handle->method);
return LOCATIONS_ERROR_INCORRECT_METHOD;
}
gchar* nmea_data = NULL;
g_object_get(handle->object, "nmea", &nmea_data, NULL);
if(nmea_data == NULL)
{
LOGE("[%s] LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : nmea data is NULL ",__FUNCTION__,LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
}
*nmea = NULL;
*nmea = strdup(nmea_data);
if(*nmea == NULL)
{
LOGE("[%s] LOCATIONS_ERROR_OUT_OF_MEMORY(0x%08x) : fail to strdup ",__FUNCTION__,LOCATIONS_ERROR_OUT_OF_MEMORY);
return LOCATIONS_ERROR_OUT_OF_MEMORY;
}
g_free(nmea_data);
return LOCATIONS_ERROR_NONE;
}
int gps_status_get_satellite_count_in_view(location_manager_h manager, int *count)
{
LOCATIONS_NULL_ARG_CHECK(manager);
LOCATIONS_NULL_ARG_CHECK(count);
location_manager_s *handle = (location_manager_s*)manager;
if(handle->method == LOCATIONS_METHOD_HYBRID)
{
LocationMethod _method = LOCATION_METHOD_NONE;
g_object_get(handle->object, "method", &_method, NULL);
if(_method!=LOCATION_METHOD_GPS)
{
LOGE("[%s] LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d", __FUNCTION__, LOCATIONS_ERROR_INCORRECT_METHOD, handle->method);
return LOCATIONS_ERROR_INCORRECT_METHOD;
}
}
else if(handle->method != LOCATIONS_METHOD_GPS)
{
LOGE("[%s] LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d", __FUNCTION__, LOCATIONS_ERROR_INCORRECT_METHOD, handle->method);
return LOCATIONS_ERROR_INCORRECT_METHOD;
}
LocationSatellite *sat = NULL;
g_object_get (handle->object, "satellite", &sat, NULL);
if (sat == NULL)
{
LOGE("[%s] LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : satellite is NULL ",__FUNCTION__,LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
}
*count = sat->num_of_sat_inview;
location_satellite_free (sat);
sat = NULL;
return LOCATIONS_ERROR_NONE;
}
int gps_status_foreach_satellites_in_view (location_manager_h manager, gps_status_get_satellites_cb callback, void *user_data)
{
LOCATIONS_NULL_ARG_CHECK(manager);
LOCATIONS_NULL_ARG_CHECK(callback);
location_manager_s *handle = (location_manager_s*)manager;
if(handle->method == LOCATIONS_METHOD_HYBRID)
{
LocationMethod _method = LOCATION_METHOD_NONE;
g_object_get(handle->object, "method", &_method, NULL);
if(_method!=LOCATION_METHOD_GPS)
{
LOGE("[%s] LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d", __FUNCTION__, LOCATIONS_ERROR_INCORRECT_METHOD, handle->method);
return LOCATIONS_ERROR_INCORRECT_METHOD;
}
}
else if(handle->method != LOCATIONS_METHOD_GPS)
{
LOGE("[%s] LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d", __FUNCTION__, LOCATIONS_ERROR_INCORRECT_METHOD, handle->method);
return LOCATIONS_ERROR_INCORRECT_METHOD;
}
LocationSatellite *sat = NULL;
g_object_get (handle->object, "satellite", &sat, NULL);
if (sat == NULL)
{
LOGE("[%s] LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : satellite is NULL ",__FUNCTION__,LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
}
int i;
for (i=0; i<sat->num_of_sat_inview; i++)
{
guint prn;
gboolean used;
guint elevation;
guint azimuth;
gint snr;
location_satellite_get_satellite_details(sat, i, &prn, &used, &elevation, &azimuth, &snr);
if ( callback(azimuth, elevation, prn, snr, used, user_data) != TRUE )
break;
}
location_satellite_free (sat);
sat = NULL;
return LOCATIONS_ERROR_NONE;
}
int gps_status_get_active_satellite_count(location_manager_h manager, int *count)
{
LOCATIONS_NULL_ARG_CHECK(manager);
LOCATIONS_NULL_ARG_CHECK(count);
location_manager_s *handle = (location_manager_s*)manager;
if(handle->method == LOCATIONS_METHOD_HYBRID)
{
LocationMethod _method = LOCATION_METHOD_NONE;
g_object_get(handle->object, "method", &_method, NULL);
if(_method!=LOCATION_METHOD_GPS)
{
LOGE("[%s] LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d", __FUNCTION__, LOCATIONS_ERROR_INCORRECT_METHOD, handle->method);
return LOCATIONS_ERROR_INCORRECT_METHOD;
}
}
else if(handle->method != LOCATIONS_METHOD_GPS)
{
LOGE("[%s] LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d", __FUNCTION__, LOCATIONS_ERROR_INCORRECT_METHOD, handle->method);
return LOCATIONS_ERROR_INCORRECT_METHOD;
}
LocationSatellite *sat = NULL;
g_object_get (handle->object, "satellite", &sat, NULL);
if (sat == NULL)
{
LOGE("[%s] LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : satellite is NULL ",__FUNCTION__,LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
}
*count = sat->num_of_sat_used;
location_satellite_free (sat);
sat = NULL;
return LOCATIONS_ERROR_NONE;
}
|