summaryrefslogtreecommitdiff
path: root/src/locations.c
blob: c369c825a74a5ec05e9acde9eb2b523657e42500 (plain)
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
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
/*
 * Copyright (c) 2011-2013 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>
#ifdef TIZEN_WEARABLE
#include <unistd.h>
#include <package_manager.h>
#include <app_manager.h>
#include <app_control.h>
#endif
#include "location_internal.h"
#include "location_bounds.h"
#include "location_batch.h"


#define LOCATIONS_NULL_ARG_CHECK(arg)	\
	LOCATIONS_CHECK_CONDITION((arg != NULL),LOCATIONS_ERROR_INVALID_PARAMETER,"LOCATIONS_ERROR_INVALID_PARAMETER") \

/*
* Internal Implementation
*/

static location_setting_changed_s g_location_setting[LOCATIONS_METHOD_WPS+1];

static int __convert_error_code(int code)
{
	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_ACCESSIBILITY_NOT_ALLOWED;
		msg = "LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED";
		break;
	case LOCATION_ERROR_SETTING_OFF:
		ret = LOCATIONS_ERROR_GPS_SETTING_OFF;
		msg = "LOCATIONS_ERROR_GPS_SETTING_OFF";
		break;
	case LOCATION_ERROR_SECURITY_DENIED:
		ret = LOCATIONS_ERROR_SECURITY_RESTRICTED;
		msg = "LOCATIONS_ERROR_SECURITY_RESTRICTED";
		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;
	}
	if (ret != LOCATIONS_ERROR_NONE)
		LOCATIONS_LOGE("%s(0x%08x) : core fw error(0x%x)", msg, ret, code);
	return ret;
}

static location_method_e __convert_location_method_e(LocationMethod method)
{
	location_method_e _method = LOCATIONS_METHOD_NONE;
	switch(method) {
		case LOCATION_METHOD_HYBRID:
			_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_NONE:
		default:
			break;
	}
	return _method;
}

static LocationMethod __convert_LocationMethod(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_NONE:
		default:
			_method = LOCATION_METHOD_NONE;
			break;
	}
	return _method;
}

static void __cb_service_updated(GObject * self, guint type, gpointer data, gpointer accuracy, gpointer userdata)
{
	LOCATIONS_LOGD("Callback function has been invoked. ");
	location_manager_s *handle = (location_manager_s *) userdata;
	if (type == VELOCITY_UPDATED && handle->user_cb[_LOCATIONS_EVENT_TYPE_VELOCITY]) {
		LocationVelocity *vel = (LocationVelocity *) data;
		LOCATIONS_LOGD("Current velocity: timestamp : %d", vel->timestamp);
		((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]);
	}
	else if (type == POSITION_UPDATED && handle->user_cb[_LOCATIONS_EVENT_TYPE_POSITION]) {
		LocationPosition *pos = (LocationPosition *) data;
		LOCATIONS_LOGD("Current position: timestamp : %d", pos->timestamp);
		((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]);
	}
	else if (type == SATELLITE_UPDATED && handle->user_cb[_LOCATIONS_EVENT_TYPE_SATELLITE]) {
		LocationSatellite *sat = (LocationSatellite *)data;
		LOCATIONS_LOGD("Current satellite information: timestamp : %d, number of active : %d, number of inview : %d",
			 sat->timestamp, sat->num_of_sat_used, sat->num_of_sat_inview);
		((gps_status_satellite_updated_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_SATELLITE]) (sat->num_of_sat_used, sat->num_of_sat_inview,
												 sat->timestamp, handle->user_data[_LOCATIONS_EVENT_TYPE_SATELLITE]);
	}
}

static void __cb_location_updated(GObject * self, int error, gpointer position, gpointer velocity, gpointer accuracy, gpointer userdata)
{
	LOCATIONS_LOGD("Callback function has been invoked. ");
	int converted_err = __convert_error_code(error);
	location_manager_s *handle = (location_manager_s *) userdata;
	LocationPosition *pos = (LocationPosition*) position;
	LocationVelocity *vel = (LocationVelocity*) velocity;

	LOCATIONS_LOGD("Current position: timestamp : %d", pos->timestamp);
	if (handle->user_cb[_LOCATIONS_EVENT_TYPE_LOCATION]) {
		((location_updated_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_LOCATION]) (converted_err, pos->latitude, pos->longitude, pos->altitude,
			pos->timestamp, vel->speed, vel->climb, vel->direction, handle->user_data[_LOCATIONS_EVENT_TYPE_LOCATION]);
	}
}

#if 0
static gboolean __cb_single_service_stop(gpointer user_data)
{
	location_manager_s *handle = (location_manager_s *) user_data;

	if (handle->timeout) {
		g_source_remove(handle->timeout);
		handle->timeout = 0;
	}

	location_stop(handle->object);

	return FALSE;
}
#endif

static void __cb_service_enabled(GObject * self, guint status, gpointer userdata)
{
	LOCATIONS_LOGD("Callback function has been invoked. ");
	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]);
	}
}

static void __cb_service_disabled(GObject * self, guint status, gpointer userdata)
{
	LOCATIONS_LOGD("Callback function has been invoked. ");
	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]);
}

#ifdef TIZEN_WEARABLE
static void __show_popup_host_setting_off()
{
	app_control_h app_control_handle = NULL;
	int ret;
	do {
		ret = app_control_create(&app_control_handle);
		if (ret != APP_CONTROL_ERROR_NONE) {
			LOCATIONS_LOGD("app_control_create failed. Error %d", ret);
			break;
		}

		ret = app_control_set_operation(app_control_handle, "http://tizen.org/appcontrol/operation/configure/location");
		if (ret != APP_CONTROL_ERROR_NONE) {
			LOCATIONS_LOGD("app_control_set_operation failed. Error %d", ret);
			break;
		}

		ret = app_control_set_app_id(app_control_handle, "com.samsung.setting-location");
		if (ret != APP_CONTROL_ERROR_NONE) {
			LOCATIONS_LOGD("app_control_set_app_id failed. Error %d", ret);
			break;
		}

		ret = app_control_add_extra_data(app_control_handle, "popup", "provider_setting_off");
		if (ret != APP_CONTROL_ERROR_NONE) {
			LOCATIONS_LOGD("app_control_add_extra_data failed. Error %d", ret);
			break;
		}

		ret = app_control_send_launch_request(app_control_handle, NULL, NULL);
		if (ret != APP_CONTROL_ERROR_NONE) {
			LOCATIONS_LOGD("app_control_send_launch_request failed. Error %d", ret);
			break;
		}
	} while(0);

	if (app_control_handle != NULL) {
		ret = app_control_destroy(app_control_handle);
		if (ret != APP_CONTROL_ERROR_NONE) {
			LOCATIONS_LOGD("app_control_destroy failed. Error %d", ret);
		}
	}
}

static void __cb_service_error_emitted(GObject * self, guint error_code, gpointer userdata)
{
	LOCATIONS_LOGD("Error[%d] Callback function has been invoked. ", error_code);
	location_manager_s *handle = (location_manager_s *) userdata;
	const char *svoice = "com.samsung.svoice";

	if (handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]) {
		switch (error_code) {
			case LOCATION_ERROR_SETTING_OFF: {
				pid_t pid = 0;
				char *app_id = NULL;
				int ret = 0;

				pid = getpid();
				ret = app_manager_get_app_id (pid, &app_id);
				if (ret == APP_MANAGER_ERROR_NONE && app_id && strncmp(app_id, svoice, strlen(svoice)) != 0) {
					__show_popup_host_setting_off();
				} else {
					LOCATIONS_LOGD("########## SVoice ################");
				}
				((location_service_state_changed_cb)handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE])
						(LOCATIONS_SERVICE_HOST_SETTING_OFF,
						handle->user_data[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]);
				break;
			}

			default: {
				break;
			}
		}
	}

}
#endif

static int __compare_position (gconstpointer a, gconstpointer b)
{
	if(location_position_equal((LocationPosition*) a, (LocationPosition *)b) == TRUE) {
		return 0;
	}

	return -1;
}

static int __boundary_compare(LocationBoundary * bound1, LocationBoundary * bound2)
{
	int ret = -1;

	if (bound1->type == bound2->type) {
		switch (bound1->type) {
		case LOCATION_BOUNDARY_CIRCLE:
			if (location_position_equal(bound1->circle.center, bound2->circle.center) && bound1->circle.radius == bound2->circle.radius) {
				ret = 0;
			}
			break;
		case LOCATION_BOUNDARY_RECT:
			if (location_position_equal(bound1->rect.left_top, bound2->rect.left_top) && location_position_equal(bound1->rect.right_bottom, bound2->rect.right_bottom)) {
				ret = 0;
			}
			break;
		case LOCATION_BOUNDARY_POLYGON: {
			GList *boundary1_next = NULL;
			GList *boundary2_start = NULL, *boundary2_prev = NULL, *boundary2_next = NULL;
			if (g_list_length(bound1->polygon.position_list) != g_list_length(bound2->polygon.position_list)) {
				return -1;
			}

			boundary2_start = g_list_find_custom(bound2->polygon.position_list, g_list_nth_data(bound1->polygon.position_list, 0), (GCompareFunc) __compare_position);
			if (boundary2_start == NULL) return -1;

			boundary2_prev = g_list_previous(boundary2_start);
			boundary2_next = g_list_next(boundary2_start);

			if (boundary2_prev == NULL) boundary2_prev = g_list_last(bound2->polygon.position_list);
			if (boundary2_next == NULL) boundary2_next = g_list_first(bound2->polygon.position_list);

			boundary1_next = g_list_next(bound1->polygon.position_list);
			if (boundary1_next != NULL && boundary2_prev != NULL &&
					location_position_equal((LocationPosition*)boundary1_next->data, (LocationPosition*)boundary2_prev->data) == TRUE) {
				boundary1_next = g_list_next(boundary1_next);
				while (boundary1_next) {
					boundary2_prev = g_list_previous(boundary2_prev);
					if (boundary2_prev == NULL) boundary2_prev = g_list_last(bound2->polygon.position_list);
					if (location_position_equal((LocationPosition*)boundary1_next->data, (LocationPosition*) boundary2_prev->data) == FALSE) {
						return -1;
					}
					boundary1_next = g_list_next(boundary1_next);
				}
				ret = 0;
			} else if (boundary1_next != NULL && boundary2_next != NULL &&
					location_position_equal((LocationPosition*)boundary1_next->data, (LocationPosition*)boundary2_next->data) == TRUE) {
				boundary1_next = g_list_next(boundary1_next);
				while(boundary1_next) {
					boundary2_next = g_list_next(boundary2_next);
					if (boundary2_next == NULL) boundary2_next = g_list_first(bound2->polygon.position_list);
					if (location_position_equal((LocationPosition*)boundary1_next->data, (LocationPosition*) boundary2_next->data) == FALSE) {
						return -1;
					}
					boundary1_next = g_list_next(boundary1_next);
				}
				ret = 0;
			} else {
				return -1;
			}
			break;
		}
		default:
			break;
		}
	}
	return ret;
}

static void __cb_zone_in(GObject * self, gpointer boundary, gpointer position, gpointer accuracy, gpointer userdata)
{
	LOCATIONS_LOGD("Callback function has been invoked.");
	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]);
	}

	location_bounds_s *bounds;
	GList *bounds_list = g_list_first(handle->bounds_list);
	while (bounds_list) {
		bounds = (location_bounds_s *)bounds_list->data;
		if (__boundary_compare(boundary, bounds->boundary) == 0) {
			LOCATIONS_LOGD("Find zone in boundary");
			((location_bounds_state_changed_cb) bounds->user_cb) (LOCATIONS_BOUNDARY_IN, bounds->user_data);
			break;
		}
		bounds_list = g_list_next(bounds_list);
	}
}

static void __cb_zone_out(GObject * self, gpointer boundary, gpointer position, gpointer accuracy, gpointer userdata)
{
	LOCATIONS_LOGD("Callback function has been invoked.");
	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]);
	}

	location_bounds_s *bounds;
	GList *bounds_list = g_list_first(handle->bounds_list);
	while (bounds_list) {
		bounds = (location_bounds_s *)bounds_list->data;
		if (__boundary_compare(boundary, bounds->boundary) == 0) {
			LOCATIONS_LOGD("Find zone out boundary");
			((location_bounds_state_changed_cb) bounds->user_cb) (LOCATIONS_BOUNDARY_OUT, bounds->user_data);
			break;
		}
		bounds_list = g_list_next(bounds_list);
	}
}

static 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;
	LOCATIONS_LOGD("event type : %d. ", type);
	return LOCATIONS_ERROR_NONE;
}

static 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;
	LOCATIONS_LOGD("event type : %d. ", type);
	return LOCATIONS_ERROR_NONE;
}

static void __foreach_boundary(LocationBoundary * boundary, void *user_data)
{
	location_manager_s *handle = (location_manager_s *) user_data;

	if (handle != NULL && boundary != NULL) {
		int ret = -1;
		location_bounds_h bounds;
		if (boundary->type == LOCATION_BOUNDARY_CIRCLE) {
			location_coords_s center;
			center.latitude = boundary->circle.center->latitude;
			center.longitude = boundary->circle.center->longitude;
			ret = location_bounds_create_circle(center, boundary->circle.radius, &bounds);
		} else if (boundary->type == LOCATION_BOUNDARY_RECT) {
			location_coords_s left_top;
			location_coords_s right_bottom;
			left_top.latitude = boundary->rect.left_top->latitude;
			left_top.longitude = boundary->rect.left_top->longitude;
			right_bottom.latitude = boundary->rect.right_bottom->latitude;
			right_bottom.longitude = boundary->rect.right_bottom->longitude;
			ret = location_bounds_create_rect(left_top, right_bottom, &bounds);
		} else if (boundary->type == LOCATION_BOUNDARY_POLYGON) {
			GList *list = boundary->polygon.position_list;
			int size = g_list_length(list);
			if (size > 0) {
				location_coords_s coords[size];
				int cnt = 0;
				while (list) {
					LocationPosition *pos = list->data;
					coords[cnt].latitude = pos->latitude;
					coords[cnt].longitude = pos->longitude;
					list = g_list_next(list);
					cnt++;
				}
				ret = location_bounds_create_polygon(coords, size, &bounds);
			}
		} else {
			LOCATIONS_LOGI("Invalid boundary type : %d", boundary->type);
		}

		if (ret != LOCATIONS_ERROR_NONE) {
			LOCATIONS_LOGI("Failed to create location_bounds : (0x%08x) ", ret);
		} else {
			if (handle->is_continue_foreach_bounds) {
				handle->is_continue_foreach_bounds =
					((location_bounds_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_FOREACH_BOUNDS]) (bounds,
															handle->
															user_data
															[_LOCATIONS_EVENT_TYPE_FOREACH_BOUNDS]);
			}
			location_bounds_destroy(bounds);
		}
	} else {
		LOCATIONS_LOGD("__foreach_boundary() has been failed");
	}
}

static void __setting_changed_cb(LocationMethod method, gboolean enable, void *user_data)
{
	LOCATIONS_LOGD("__setting_changed_cb method [%d]", method);
	location_method_e _method = __convert_location_method_e(method);
	location_setting_changed_s *_setting_changed = (location_setting_changed_s *)user_data;
	if (_setting_changed == NULL) {
		LOCATIONS_LOGE("Invaild userdata\n");
		return;
	}

	if (_setting_changed[_method].callback != NULL) {
		_setting_changed[_method].callback(_method, enable, _setting_changed[_method].user_data);
	}
}

/////////////////////////////////////////
// Location Manager
////////////////////////////////////////

static void __cb_batch_updated(GObject * self, guint num_of_location, gpointer userdata)
{
	LOCATIONS_LOGD("Batch callback function has been invoked.");
	location_manager_s *handle = (location_manager_s *) userdata;

	if (handle->user_cb[_LOCATIONS_EVENT_TYPE_BATCH]) {
		((location_batch_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_BATCH]) (num_of_location, handle->user_data[_LOCATIONS_EVENT_TYPE_BATCH]);
	}
}

EXPORT_API int location_manager_set_location_batch_cb(location_manager_h manager, location_batch_cb callback, int batch_interval, int batch_period, void *user_data)
{
	LOCATIONS_LOGD("location_manager_set_location_batch_cb");
	LOCATIONS_CHECK_CONDITION(batch_interval >= 1 && batch_interval <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
	LOCATIONS_CHECK_CONDITION(batch_period >= 120 && batch_period <= 600, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
	LOCATIONS_NULL_ARG_CHECK(manager);
	LOCATIONS_NULL_ARG_CHECK(callback);
	location_manager_s *handle = (location_manager_s *) manager;
	g_object_set(handle->object, "batch-period", batch_period, NULL);
	g_object_set(handle->object, "batch-interval", batch_interval, NULL);
	return __set_callback(_LOCATIONS_EVENT_TYPE_BATCH, manager, callback, user_data);
}

EXPORT_API int location_manager_unset_location_batch_cb (location_manager_h manager)
{
	LOCATIONS_LOGD("location_manager_unset_location_batch_cb");
	return __unset_callback(_LOCATIONS_EVENT_TYPE_BATCH, manager);
}

EXPORT_API int location_manager_start_batch(location_manager_h manager)
{
	LOCATIONS_LOGD("location_manager_start_batch");
	LOCATIONS_NULL_ARG_CHECK(manager);
	location_manager_s *handle = (location_manager_s *) manager;

	if (LOCATIONS_METHOD_GPS == handle->method)
	{
		if (!handle->sig_id[_LOCATION_SIGNAL_BATCH_UPDATED]) {
			handle->sig_id[_LOCATION_SIGNAL_BATCH_UPDATED] = g_signal_connect(handle->object, "batch-updated", G_CALLBACK(__cb_batch_updated), handle);
		}
	} else {
		LOCATIONS_LOGE("method is not GPS");
	}

	if (handle->user_cb[_LOCATIONS_EVENT_TYPE_BATCH] != NULL) {
		LOCATIONS_LOGI("batch status set : Start");
	}

	int ret = location_start_batch(handle->object);
	if (ret != LOCATION_ERROR_NONE) {
		return __convert_error_code(ret);
	}

	return LOCATIONS_ERROR_NONE;
}

EXPORT_API int location_manager_stop_batch(location_manager_h manager)
{
	LOCATIONS_LOGD("location_manager_stop_batch");
	LOCATIONS_NULL_ARG_CHECK(manager);
	location_manager_s *handle = (location_manager_s *) manager;

	if (LOCATIONS_METHOD_GPS == handle->method)
	{
		if (handle->sig_id[_LOCATION_SIGNAL_BATCH_UPDATED]) {
			g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_BATCH_UPDATED]);
			handle->sig_id[_LOCATION_SIGNAL_BATCH_UPDATED] = 0;
		}
	} else {
		LOCATIONS_LOGE("method is not GPS");
	}

	int ret = location_stop_batch(handle->object);
	if (ret != LOCATION_ERROR_NONE) {
		return __convert_error_code(ret);
	}

	return LOCATIONS_ERROR_NONE;
}

EXPORT_API int location_manager_foreach_location_batch(location_manager_h manager, location_batch_get_location_cb callback, void *user_data)
{
	LOCATIONS_LOGD("location_manager_foreach_location_batch");
	LOCATIONS_NULL_ARG_CHECK(manager);
	LOCATIONS_NULL_ARG_CHECK(callback);
	location_manager_s *handle = (location_manager_s *) manager;
	LocationBatch *batch = NULL;

	int ret = location_get_batch (handle->object, &batch);
	if (ret != LOCATION_ERROR_NONE || batch == NULL) {
		if (ret == LOCATION_ERROR_NOT_SUPPORTED) {
			LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d", LOCATIONS_ERROR_INCORRECT_METHOD, handle->method);
			return LOCATIONS_ERROR_INCORRECT_METHOD;
		} else if (ret == LOCATION_ERROR_NOT_ALLOWED) {
			LOCATIONS_LOGE("LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED");
			return LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED;
		}

		LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : batch is NULL ",
			 LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
		return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
	}

	int i;
	for (i = 0; i < batch->num_of_location; i++) {
		gdouble latitude;
		gdouble longitude;
		gdouble altitude;
		gdouble speed;
		gdouble direction;
		gdouble h_accuracy;
		gdouble v_accuracy;
		guint timestamp;

		location_get_batch_details(batch, i, &latitude, &longitude, &altitude, &speed, &direction, &h_accuracy, &v_accuracy, &timestamp);
		if (callback(latitude, longitude, altitude, speed, direction, h_accuracy, v_accuracy, timestamp, user_data) != TRUE) {
			break;
		}
	}
	location_batch_free(batch);
	batch = NULL;
	return LOCATIONS_ERROR_NONE;
}

/*
* Public Implementation
*/

EXPORT_API bool location_manager_is_supported_method(location_method_e method)
{
	LOCATIONS_LOGD("location_manager_is_supported_method %d", method);
	LocationMethod _method = __convert_LocationMethod(method);
	if (_method == LOCATION_METHOD_NONE) {
		LOCATIONS_LOGE("Not supported method [%d]", method);
		set_last_result(LOCATIONS_ERROR_INCORRECT_METHOD);
		return false;
	}

	set_last_result(LOCATIONS_ERROR_NONE);
	return location_is_supported_method(_method);
}

EXPORT_API int location_manager_is_enabled_method(location_method_e method, bool *enable)
{
	if (LOCATIONS_METHOD_HYBRID > method || LOCATIONS_METHOD_WPS < method) {
		LOCATIONS_LOGE("Not supported method [%d]", method);
		return LOCATIONS_ERROR_INCORRECT_METHOD;
	}

	LOCATIONS_LOGD("location_manager_is_enabled_method %d", method);
	LOCATIONS_NULL_ARG_CHECK(enable);
	int is_enabled_val = -1;
	LocationMethod _method = __convert_LocationMethod(method);
	int ret = location_is_enabled_method(_method, &is_enabled_val);
	if (ret != LOCATION_ERROR_NONE) {
		if (ret == LOCATION_ERROR_NOT_SUPPORTED)
			return LOCATIONS_ERROR_INCORRECT_METHOD;
		return __convert_error_code(ret);
	}
	if (is_enabled_val == -1)
		return TIZEN_ERROR_PERMISSION_DENIED;

	*enable = (is_enabled_val == 0)?FALSE:TRUE;
	return LOCATIONS_ERROR_NONE;
}

EXPORT_API int location_manager_create(location_method_e method, location_manager_h * manager)
{
	LOCATIONS_LOGD("location_manager_create (method : %d)", method);

	LocationMethod _method = __convert_LocationMethod(method);
	if (_method == LOCATION_METHOD_NONE) {
		LOCATIONS_LOGE("LOCATIONS_ERROR_NOT_SUPPORTED(0x%08x) : fail to location_init", LOCATIONS_ERROR_NOT_SUPPORTED);
		return LOCATIONS_ERROR_NOT_SUPPORTED;
	}
	if (!location_is_supported_method(_method)) {
		LOCATIONS_LOGE("LOCATIONS_ERROR_NOT_SUPPORTED(0x%08x) : fail to location_is_supported_method", LOCATIONS_ERROR_NOT_SUPPORTED);
		return LOCATIONS_ERROR_NOT_SUPPORTED;
	}

	//It is moved here becasue of TCS.
	LOCATIONS_NULL_ARG_CHECK(manager);

	if (location_init() != LOCATION_ERROR_NONE) {
		LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : fail to location_init", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
		return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
	}

	location_manager_s *handle = (location_manager_s *) malloc(sizeof(location_manager_s));
	if (handle == NULL) {
		LOCATIONS_LOGE("OUT_OF_MEMORY(0x%08x)", 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) {
		LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : fail to location_new", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
		free(handle);
		return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
	}
	handle->method = method;
	handle->is_continue_foreach_bounds = TRUE;
	handle->bounds_list = NULL;

	if (!handle->sig_id[_LOCATION_SIGNAL_SERVICE_ENABLED])
		handle->sig_id[_LOCATION_SIGNAL_SERVICE_ENABLED] = g_signal_connect(handle->object, "service-enabled", G_CALLBACK(__cb_service_enabled), handle);

	if (!handle->sig_id[_LOCATION_SIGNAL_SERVICE_DISABLED])
		handle->sig_id[_LOCATION_SIGNAL_SERVICE_DISABLED] = g_signal_connect(handle->object, "service-disabled", G_CALLBACK(__cb_service_disabled), handle);

	#ifdef TIZEN_WEARABLE
	if (!handle->sig_id[_LOCATION_SIGNAL_ERROR_EMITTED])
		handle->sig_id[_LOCATION_SIGNAL_ERROR_EMITTED] = g_signal_connect(handle->object, "error-emitted", G_CALLBACK(__cb_service_error_emitted), handle);
	#endif

	*manager = (location_manager_h) handle;
	return LOCATIONS_ERROR_NONE;
}

EXPORT_API int location_manager_destroy(location_manager_h manager)
{
	LOCATIONS_LOGD("location_manager_destroy");
	LOCATIONS_NULL_ARG_CHECK(manager);
	location_manager_s *handle = (location_manager_s *) manager;

	if (handle->sig_id[_LOCATION_SIGNAL_SERVICE_ENABLED]) {
		g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_SERVICE_ENABLED]);
		handle->sig_id[_LOCATION_SIGNAL_SERVICE_ENABLED] = 0;
	}

	if (handle->sig_id[_LOCATION_SIGNAL_SERVICE_DISABLED]) {
		g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_SERVICE_DISABLED]);
		handle->sig_id[_LOCATION_SIGNAL_SERVICE_DISABLED] = 0;
	}

	#ifdef TIZEN_WEARABLE
	if (handle->sig_id[_LOCATION_SIGNAL_ERROR_EMITTED]) {
		g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_ERROR_EMITTED]);
		handle->sig_id[_LOCATION_SIGNAL_ERROR_EMITTED] = 0;
	}
	#endif

	int ret = location_free(handle->object);
	if (ret != LOCATIONS_ERROR_NONE) {
		return __convert_error_code(ret);
	}
	free(handle);
	return LOCATIONS_ERROR_NONE;
}

EXPORT_API int location_manager_start(location_manager_h manager)
{
	LOCATIONS_LOGD("location_manager_start");
	LOCATIONS_NULL_ARG_CHECK(manager);
	location_manager_s *handle = (location_manager_s *) manager;

	if (!handle->sig_id[_LOCATION_SIGNAL_SERVICE_UPDATED])
		handle->sig_id[_LOCATION_SIGNAL_SERVICE_UPDATED] = g_signal_connect(handle->object, "service-updated", G_CALLBACK(__cb_service_updated), handle);

	if (LOCATIONS_METHOD_HYBRID <= handle->method && LOCATIONS_METHOD_WPS >= handle->method)
	{
		if (!handle->sig_id[_LOCATION_SIGNAL_ZONE_IN])
			handle->sig_id[_LOCATION_SIGNAL_ZONE_IN] = g_signal_connect(handle->object, "zone-in", G_CALLBACK(__cb_zone_in), handle);

		if (!handle->sig_id[_LOCATION_SIGNAL_ZONE_OUT])
			handle->sig_id[_LOCATION_SIGNAL_ZONE_OUT] = g_signal_connect(handle->object, "zone-out", G_CALLBACK(__cb_zone_out), handle);
	} else {
		LOCATIONS_LOGI("This method [%d] is not supported zone-in, zone-out signal.", handle->method);
	}

	if (handle->user_cb[_LOCATIONS_EVENT_TYPE_SATELLITE] != NULL) {
		LOCATIONS_LOGI("Satellite update_cb is set");
		location_set_option(handle->object, "USE_SV");
	}

	int ret = location_start(handle->object);
	if (ret != LOCATION_ERROR_NONE) {
		return __convert_error_code(ret);
	}
	return LOCATIONS_ERROR_NONE;
}

EXPORT_API int location_manager_request_single_location(location_manager_h manager, int timeout, location_updated_cb callback, void *user_data)
{
	LOCATIONS_LOGD("location_manager_request_single_location");
	LOCATIONS_NULL_ARG_CHECK(manager);
	LOCATIONS_NULL_ARG_CHECK(callback);
	if (timeout <= 0 || timeout > 120) {
		LOCATIONS_LOGE("timeout scope is incorrect(1~120) [%d]", timeout);
		return LOCATIONS_ERROR_INVALID_PARAMETER;
	}

	location_manager_s *handle = (location_manager_s *) manager;
	int ret = LOCATIONS_ERROR_NONE;

	if (!handle->sig_id[_LOCATION_SIGNAL_LOCATION_UPDATED])
		handle->sig_id[_LOCATION_SIGNAL_LOCATION_UPDATED] = g_signal_connect(handle->object, "location-updated", G_CALLBACK(__cb_location_updated), handle);

	ret = __set_callback(_LOCATIONS_EVENT_TYPE_LOCATION, manager, callback, user_data);
	if (ret != LOCATIONS_ERROR_NONE) {
		return ret;
	}

	ret = location_request_single_location(handle->object, timeout);
	if (ret != LOCATION_ERROR_NONE) {
		return __convert_error_code(ret);
	}
	return LOCATIONS_ERROR_NONE;
}

EXPORT_API int location_manager_stop(location_manager_h manager)
{
	LOCATIONS_LOGD("location_manager_stop");
	LOCATIONS_NULL_ARG_CHECK(manager);
	location_manager_s *handle = (location_manager_s *) manager;

	if (handle->sig_id[_LOCATION_SIGNAL_SERVICE_UPDATED]) {
		g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_SERVICE_UPDATED]);
		handle->sig_id[_LOCATION_SIGNAL_SERVICE_UPDATED] = 0;
	}

	if (LOCATIONS_METHOD_HYBRID <= handle->method && LOCATIONS_METHOD_WPS >= handle->method)
	{
		if (handle->sig_id[_LOCATION_SIGNAL_ZONE_IN]) {
			g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_ZONE_IN]);
			handle->sig_id[_LOCATION_SIGNAL_ZONE_IN] = 0;
		}

		if (handle->sig_id[_LOCATION_SIGNAL_ZONE_OUT]) {
			g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_ZONE_OUT]);
			handle->sig_id[_LOCATION_SIGNAL_ZONE_OUT] = 0;
		}
	}

	int ret = location_stop(handle->object);
	if (ret != LOCATION_ERROR_NONE) {
		return __convert_error_code(ret);
	}
	return LOCATIONS_ERROR_NONE;
}

EXPORT_API int location_manager_add_boundary(location_manager_h manager, location_bounds_h bounds)
{
	LOCATIONS_LOGD("location_manager_add_boundary");
	LOCATIONS_NULL_ARG_CHECK(manager);
	LOCATIONS_NULL_ARG_CHECK(bounds);

	location_manager_s *handle = (location_manager_s *) manager;
	location_bounds_s *bound_handle = (location_bounds_s *) bounds;
	int ret = location_boundary_add(handle->object, bound_handle->boundary);
	if (ret != LOCATION_ERROR_NONE) {
		return __convert_error_code(ret);
	}
	bound_handle->is_added = TRUE;
	handle->bounds_list = g_list_append(handle->bounds_list, bound_handle);
	return LOCATIONS_ERROR_NONE;
}

EXPORT_API int location_manager_remove_boundary(location_manager_h manager, location_bounds_h bounds)
{
	LOCATIONS_LOGD("location_manager_remove_boundary");
	LOCATIONS_NULL_ARG_CHECK(manager);
	LOCATIONS_NULL_ARG_CHECK(bounds);

	location_manager_s *handle = (location_manager_s *) manager;
	location_bounds_s *bound_handle = (location_bounds_s *) bounds;
	int ret = location_boundary_remove(handle->object, bound_handle->boundary);
	if (ret != LOCATION_ERROR_NONE) {
		return __convert_error_code(ret);
	}
	handle->bounds_list = g_list_remove(handle->bounds_list, bound_handle);
	bound_handle->is_added = FALSE;
	return LOCATIONS_ERROR_NONE;
}

EXPORT_API int location_manager_foreach_boundary(location_manager_h manager, location_bounds_cb callback, void *user_data)
{
	LOCATIONS_LOGD("location_manager_foreach_boundary");
	LOCATIONS_NULL_ARG_CHECK(manager);
	LOCATIONS_NULL_ARG_CHECK(callback);

	location_manager_s *handle = (location_manager_s *) manager;
	handle->user_cb[_LOCATIONS_EVENT_TYPE_FOREACH_BOUNDS] = callback;
	handle->user_data[_LOCATIONS_EVENT_TYPE_FOREACH_BOUNDS] = user_data;
	handle->is_continue_foreach_bounds = TRUE;
	int ret = location_boundary_foreach(handle->object, __foreach_boundary, handle);
	if (ret != LOCATION_ERROR_NONE) {
		return __convert_error_code(ret);
	}
	return LOCATIONS_ERROR_NONE;
}

EXPORT_API int location_manager_get_method(location_manager_h manager, location_method_e * method)
{
	LOCATIONS_LOGD("location_manager_get_method %d", 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:
		*method = LOCATIONS_METHOD_HYBRID;
		break;
	case LOCATION_METHOD_GPS:
		*method = LOCATIONS_METHOD_GPS;
		break;
	case LOCATION_METHOD_WPS:
		*method = LOCATIONS_METHOD_WPS;
		break;
	default:
		{
			LOCATIONS_LOGE("LOCATIONS_ERROR_INVALID_PARAMETER(0x%08x) : Out of range (location_method_e) - method : %d ",
				 LOCATIONS_ERROR_INVALID_PARAMETER, method);
			return LOCATIONS_ERROR_INVALID_PARAMETER;
		}
	}
	//*method = handle->method;
	return LOCATIONS_ERROR_NONE;
}

EXPORT_API int location_manager_get_position(location_manager_h manager, double *altitude, double *latitude, double *longitude,
					time_t * timestamp)
{
	LOCATIONS_LOGD("location_manager_get_position");
	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);
	}

	if (pos->status == LOCATION_STATUS_NO_FIX) {
		return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
	} else {
		*latitude = pos->latitude;
		*longitude = pos->longitude;
		*altitude = pos->altitude;
	}
	*timestamp = pos->timestamp;
	location_position_free(pos);
	location_accuracy_free(acc);
	return LOCATIONS_ERROR_NONE;
}

EXPORT_API int location_manager_get_location(location_manager_h manager, double *altitude, double *latitude, double *longitude, double *climb, double *direction, double *speed, location_accuracy_level_e *level, double *horizontal, double *vertical, time_t *timestamp)
{
	LOCATIONS_LOGD("location_manager_get_location");
	LOCATIONS_NULL_ARG_CHECK(manager);
	LOCATIONS_NULL_ARG_CHECK(altitude);
	LOCATIONS_NULL_ARG_CHECK(latitude);
	LOCATIONS_NULL_ARG_CHECK(longitude);
	LOCATIONS_NULL_ARG_CHECK(climb);
	LOCATIONS_NULL_ARG_CHECK(direction);
	LOCATIONS_NULL_ARG_CHECK(speed);
	LOCATIONS_NULL_ARG_CHECK(level);
	LOCATIONS_NULL_ARG_CHECK(horizontal);
	LOCATIONS_NULL_ARG_CHECK(vertical);
	LOCATIONS_NULL_ARG_CHECK(timestamp);

	location_manager_s *handle = (location_manager_s *) manager;
	int ret;
	LocationPosition *pos = NULL;
	LocationVelocity *vel = NULL;
	LocationAccuracy *acc = NULL;
	ret = location_get_position_ext(handle->object, &pos, &vel, &acc);
	if (ret != LOCATION_ERROR_NONE) {
		return __convert_error_code(ret);
	}

	if (pos->status == LOCATION_STATUS_NO_FIX) {
		return __convert_error_code(LOCATION_ERROR_NOT_AVAILABLE);
	} else {
		*latitude = pos->latitude;
		*longitude = pos->longitude;
		*altitude = pos->altitude;
	}
	*timestamp = pos->timestamp;
	*climb = vel->climb;
	*direction = vel->direction;
	*speed = vel->speed;
	*level = acc->level;
	*horizontal = acc->horizontal_accuracy;
	*vertical = acc->vertical_accuracy;

	location_position_free(pos);
	location_velocity_free(vel);
	location_accuracy_free(acc);
	return LOCATIONS_ERROR_NONE;
}

EXPORT_API int location_manager_get_velocity(location_manager_h manager, double *climb, double *direction, double *speed, time_t * timestamp)
{
	LOCATIONS_LOGD("location_manager_get_velocity");
	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);
	}

	*climb = vel->climb;
	*direction = vel->direction;
	*speed = vel->speed;
	*timestamp = vel->timestamp;
	location_velocity_free(vel);
	location_accuracy_free(acc);
	return LOCATIONS_ERROR_NONE;
}

EXPORT_API int location_manager_get_accuracy(location_manager_h manager, location_accuracy_level_e * level, double *horizontal,
					double *vertical)
{
	LOCATIONS_LOGD("location_manager_get_accuracy");
	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);
	}

	if (acc == NULL) {
		return __convert_error_code(LOCATION_ERROR_NOT_AVAILABLE);
	}

	*level = acc->level;
	*horizontal = acc->horizontal_accuracy;
	*vertical = acc->vertical_accuracy;
	location_position_free(pos);
	location_accuracy_free(acc);
	return LOCATIONS_ERROR_NONE;
}

EXPORT_API int location_manager_get_last_position(location_manager_h manager, double *altitude, double *latitude, double *longitude,
						time_t * timestamp)
{
	LOCATIONS_LOGD("location_manager_get_last_position");
	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 *last_pos = NULL;
	LocationAccuracy *last_acc = NULL;
	ret = location_get_last_position(handle->object, &last_pos, &last_acc);
	if (ret != LOCATION_ERROR_NONE) {
		return __convert_error_code(ret);
	}

	if (last_pos->status == LOCATION_STATUS_NO_FIX) {
		return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
	} else {
		*latitude = last_pos->latitude;
		*longitude = last_pos->longitude;
		*altitude = last_pos->altitude;
	}
	*timestamp = last_pos->timestamp;
	location_position_free(last_pos);
	location_accuracy_free(last_acc);
	return LOCATIONS_ERROR_NONE;
}

EXPORT_API int location_manager_get_last_location(location_manager_h manager, double *altitude, double *latitude, double *longitude, double *climb, double *direction, double *speed, location_accuracy_level_e * level, double *horizontal, double *vertical, time_t * timestamp)
{
	LOCATIONS_LOGD("location_manager_get_last_location");
	LOCATIONS_NULL_ARG_CHECK(manager);
	LOCATIONS_NULL_ARG_CHECK(altitude);
	LOCATIONS_NULL_ARG_CHECK(latitude);
	LOCATIONS_NULL_ARG_CHECK(longitude);
	LOCATIONS_NULL_ARG_CHECK(climb);
	LOCATIONS_NULL_ARG_CHECK(direction);
	LOCATIONS_NULL_ARG_CHECK(speed);
	LOCATIONS_NULL_ARG_CHECK(level);
	LOCATIONS_NULL_ARG_CHECK(horizontal);
	LOCATIONS_NULL_ARG_CHECK(vertical);
	LOCATIONS_NULL_ARG_CHECK(timestamp);

	location_manager_s *handle = (location_manager_s *) manager;

	int ret;
	LocationPosition *last_pos = NULL;
	LocationVelocity *last_vel = NULL;
	LocationAccuracy *last_acc = NULL;
	ret = location_get_last_position_ext(handle->object, &last_pos, &last_vel, &last_acc);
	if (ret != LOCATION_ERROR_NONE) {
		return __convert_error_code(ret);
	}

	if (last_pos->status == LOCATION_STATUS_NO_FIX) {
		return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
	} else {
		*latitude = last_pos->latitude;
		*longitude = last_pos->longitude;
		*altitude = last_pos->altitude;
	}
	*timestamp = last_pos->timestamp;
	*climb = last_vel->climb;
	*direction = last_vel->direction;
	*speed = last_vel->speed;
	*level = last_acc->level;
	*horizontal = last_acc->horizontal_accuracy;
	*vertical = last_acc->vertical_accuracy;
	location_position_free(last_pos);
	location_velocity_free(last_vel);
	location_accuracy_free(last_acc);
	return LOCATIONS_ERROR_NONE;
}

EXPORT_API int location_manager_get_last_velocity(location_manager_h manager, double *climb, double *direction, double *speed, time_t * timestamp)
{
	LOCATIONS_LOGD("location_manager_get_last_velocity");
	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 *last_vel = NULL;
	LocationAccuracy *last_acc = NULL;
	ret = location_get_last_velocity(handle->object, &last_vel, &last_acc);
	if (ret != LOCATION_ERROR_NONE) {
		return __convert_error_code(ret);
	}

	*climb = last_vel->climb;
	*direction = last_vel->direction;
	*speed = last_vel->speed;
	*timestamp = last_vel->timestamp;
	location_velocity_free(last_vel);
	location_accuracy_free(last_acc);
	return LOCATIONS_ERROR_NONE;
}

EXPORT_API int location_manager_get_last_accuracy(location_manager_h manager, location_accuracy_level_e * level, double *horizontal,
						double *vertical)
{
	LOCATIONS_LOGD("location_manager_get_last_accuracy");
	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 *last_pos = NULL;
	LocationAccuracy *last_acc = NULL;
	ret = location_get_last_position(handle->object, &last_pos, &last_acc);
	if (ret != LOCATION_ERROR_NONE) {
		return __convert_error_code(ret);
	}

	*level = last_acc->level;
	*horizontal = last_acc->horizontal_accuracy;
	*vertical = last_acc->vertical_accuracy;
	location_position_free(last_pos);
	location_accuracy_free(last_acc);
	return LOCATIONS_ERROR_NONE;
}

EXPORT_API int location_manager_get_accessibility_state(location_accessibility_state_e* state)
{
	LOCATIONS_LOGD("location_manager_get_accessibility_state");
	LOCATIONS_NULL_ARG_CHECK(state);

	int ret = LOCATION_ERROR_NONE;
	LocationAccessState auth = LOCATION_ACCESS_NONE;
	ret = location_get_accessibility_state (&auth);
	if (ret != LOCATION_ERROR_NONE) {
		*state = LOCATIONS_ACCESS_STATE_NONE;
		return __convert_error_code(ret);
	}

	switch (auth) {
		case LOCATION_ACCESS_DENIED:
			*state = LOCATIONS_ACCESS_STATE_DENIED;
			break;
		case LOCATION_ACCESS_ALLOWED:
			*state = LOCATIONS_ACCESS_STATE_ALLOWED;
			break;
		case LOCATION_ACCESS_NONE:
		default:
			*state = LOCATIONS_ACCESS_STATE_NONE;
			break;
	}

	return LOCATIONS_ERROR_NONE;
}

EXPORT_API int location_manager_set_position_updated_cb(location_manager_h manager, location_position_updated_cb callback, int interval, void *user_data)
{
	LOCATIONS_LOGD("location_manager_set_position_updated_cb");
	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, "pos-interval", interval, NULL);
	return __set_callback(_LOCATIONS_EVENT_TYPE_POSITION, manager, callback, user_data);
}

EXPORT_API int location_manager_unset_position_updated_cb(location_manager_h manager)
{
	LOCATIONS_LOGD("location_manager_unset_position_updated_cb");
	return __unset_callback(_LOCATIONS_EVENT_TYPE_POSITION, manager);
}

EXPORT_API int location_manager_set_velocity_updated_cb(location_manager_h manager, location_velocity_updated_cb callback, int interval, void *user_data)
{
	LOCATIONS_LOGD("location_manager_set_velocity_updated_cb");
	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, "vel-interval", interval, NULL);
	return __set_callback(_LOCATIONS_EVENT_TYPE_VELOCITY, manager, callback, user_data);
}

EXPORT_API int location_manager_unset_velocity_updated_cb(location_manager_h manager)
{
	LOCATIONS_LOGD("location_manager_unset_velocity_updated_cb");
	return __unset_callback(_LOCATIONS_EVENT_TYPE_VELOCITY, manager);
}

EXPORT_API int location_manager_set_service_state_changed_cb(location_manager_h manager, location_service_state_changed_cb callback,
							void *user_data)
{
	LOCATIONS_LOGD("location_manager_set_service_state_changed_cb");
	return __set_callback(_LOCATIONS_EVENT_TYPE_SERVICE_STATE, manager, callback, user_data);
}

EXPORT_API int location_manager_unset_service_state_changed_cb(location_manager_h manager)
{
	LOCATIONS_LOGD("location_manager_unset_service_state_changed_cb");
	return __unset_callback(_LOCATIONS_EVENT_TYPE_SERVICE_STATE, manager);
}

EXPORT_API int location_manager_set_zone_changed_cb(location_manager_h manager, location_zone_changed_cb callback, void *user_data)
{
	LOCATIONS_LOGD("location_manager_set_zone_changed_cb");
	return __set_callback(_LOCATIONS_EVENT_TYPE_BOUNDARY, manager, callback, user_data);
}

EXPORT_API int location_manager_unset_zone_changed_cb(location_manager_h manager)
{
	LOCATIONS_LOGD("location_manager_unset_zone_changed_cb");
	return __unset_callback(_LOCATIONS_EVENT_TYPE_BOUNDARY, manager);
}

EXPORT_API int location_manager_set_setting_changed_cb(location_method_e method, location_setting_changed_cb callback, void *user_data)
{
	LOCATIONS_LOGD("location_manager_set_setting_changed_cb");
	LOCATIONS_NULL_ARG_CHECK(callback);

	LocationMethod _method = __convert_LocationMethod(method);
	int ret = LOCATION_ERROR_NONE;

	if (_method == LOCATION_METHOD_NONE) {
		return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
	}

	g_location_setting[_method].callback = callback;
	g_location_setting[_method].user_data = user_data;

	ret = location_add_setting_notify(_method, __setting_changed_cb, &g_location_setting);
	return __convert_error_code(ret);
}

EXPORT_API int location_manager_unset_setting_changed_cb(location_method_e method /*, location_setting_changed_cb callback */)
{
	LOCATIONS_LOGD("location_manager_unset_setting_changed_cb");
//	LOCATIONS_NULL_ARG_CHECK(callback);
	LocationMethod _method = __convert_LocationMethod(method);
	int ret = LOCATION_ERROR_NONE;
/*
	if (g_location_setting[method].callback != callback) {
		LOCATIONS_LOGE("Invalid parameter");
		return LOCATIONS_ERROR_INVALID_PARAMETER;
	}
*/
	ret = location_ignore_setting_notify(_method, __setting_changed_cb);
	if (ret != LOCATION_ERROR_NONE) {
		LOCATIONS_LOGE("Fail to ignore notify. Error[%d]", ret);
		ret = __convert_error_code(ret);
	}

	g_location_setting[method].callback = NULL;
	g_location_setting[method].user_data = NULL;

	return LOCATIONS_ERROR_NONE;
}

EXPORT_API int location_manager_get_distance(double start_latitude, double start_longitude, double end_latitude, double end_longitude, double *distance)
{
	LOCATIONS_LOGD("location_manager_get_distance");
	LOCATIONS_NULL_ARG_CHECK(distance);
	LOCATIONS_CHECK_CONDITION(start_latitude>=-90 && start_latitude<=90,LOCATIONS_ERROR_INVALID_PARAMETER,"LOCATIONS_ERROR_INVALID_PARAMETER");
	LOCATIONS_CHECK_CONDITION(start_longitude>=-180 && start_longitude<=180,LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
	LOCATIONS_CHECK_CONDITION(end_latitude>=-90 && end_latitude<=90,LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
	LOCATIONS_CHECK_CONDITION(end_longitude>=-180 && end_longitude<=180,LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");

	int ret = LOCATION_ERROR_NONE;
	ulong u_distance;

	LocationPosition *start = location_position_new (0, start_latitude, start_longitude, 0, LOCATION_STATUS_2D_FIX);
	LocationPosition *end = location_position_new (0, end_latitude, end_longitude, 0, LOCATION_STATUS_2D_FIX);

	ret = location_get_distance (start, end, &u_distance);
	if (ret != LOCATION_ERROR_NONE) {
		return __convert_error_code(ret);
	}

	*distance = (double)u_distance;

	return LOCATIONS_ERROR_NONE;
}

/////////////////////////////////////////
// GPS Status & Satellites
////////////////////////////////////////

EXPORT_API int gps_status_get_nmea(location_manager_h manager, char **nmea)
{
	LOCATIONS_LOGD("gps_status_get_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) {
			LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d",
				 LOCATIONS_ERROR_INCORRECT_METHOD, handle->method);
			return LOCATIONS_ERROR_INCORRECT_METHOD;
		}
	} else if (handle->method != LOCATIONS_METHOD_GPS) {
		LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d",
			 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) {
		LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : nmea data is NULL ",
			 LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
		return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
	}
	*nmea = NULL;
	*nmea = strdup(nmea_data);
	if (*nmea == NULL) {
		LOCATIONS_LOGE("LOCATIONS_ERROR_OUT_OF_MEMORY(0x%08x) : fail to strdup ",
			 LOCATIONS_ERROR_OUT_OF_MEMORY);
		return LOCATIONS_ERROR_OUT_OF_MEMORY;
	}
	g_free(nmea_data);
	return LOCATIONS_ERROR_NONE;
}

EXPORT_API int gps_status_get_satellite(location_manager_h manager, int *num_of_active, int *num_of_inview, time_t *timestamp)
{
	LOCATIONS_LOGD("gps_status_get_satellite");
	LOCATIONS_NULL_ARG_CHECK(manager);
	LOCATIONS_NULL_ARG_CHECK(num_of_active);
	LOCATIONS_NULL_ARG_CHECK(num_of_inview);
	LOCATIONS_NULL_ARG_CHECK(timestamp);
	location_manager_s *handle = (location_manager_s *) manager;
	LocationSatellite *sat = NULL;
	int ret = location_get_satellite (handle->object, &sat);
	if (ret != LOCATION_ERROR_NONE || sat == NULL) {
		if (ret == LOCATION_ERROR_NOT_SUPPORTED) {
			LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d",
				LOCATIONS_ERROR_INCORRECT_METHOD, handle->method);
			return LOCATIONS_ERROR_INCORRECT_METHOD;
		} else if (ret == LOCATION_ERROR_NOT_ALLOWED) {
			LOCATIONS_LOGE("LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED");
			return LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED;
		}

		LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : satellite is NULL ",
			LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
		return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
	}

	*num_of_active = sat->num_of_sat_used;
	*num_of_inview = sat->num_of_sat_inview;
	*timestamp = sat->timestamp;
	location_satellite_free(sat);
	sat = NULL;
	return LOCATIONS_ERROR_NONE;
}

EXPORT_API int gps_status_set_satellite_updated_cb(location_manager_h manager, gps_status_satellite_updated_cb callback, int interval, void *user_data)
{
	LOCATIONS_LOGD("gps_status_set_satellite_updated_cb");
	LOCATIONS_CHECK_CONDITION(interval >= 1
					&& interval <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
	LOCATIONS_NULL_ARG_CHECK(manager);
	LOCATIONS_NULL_ARG_CHECK(callback);
	location_manager_s *handle = (location_manager_s *) manager;
	location_set_option(handle->object, "USE_SV");
	g_object_set(handle->object, "sat-interval", interval, NULL);
	return __set_callback(_LOCATIONS_EVENT_TYPE_SATELLITE, manager, callback, user_data);
}

EXPORT_API int gps_status_unset_satellite_updated_cb(location_manager_h manager)
{
	LOCATIONS_LOGD("gps_status_unset_satellite_updated_cb");
	return __unset_callback(_LOCATIONS_EVENT_TYPE_SATELLITE, manager);
}

EXPORT_API int gps_status_foreach_satellites_in_view(location_manager_h manager, gps_status_get_satellites_cb callback, void *user_data)
{
	LOCATIONS_LOGD("gps_status_foreach_satellites_in_view");
	LOCATIONS_NULL_ARG_CHECK(manager);
	LOCATIONS_NULL_ARG_CHECK(callback);
	location_manager_s *handle = (location_manager_s *) manager;
	LocationSatellite *sat = NULL;
	int ret = location_get_satellite (handle->object, &sat);
	if (ret != LOCATION_ERROR_NONE || sat == NULL) {
		if (ret == LOCATION_ERROR_NOT_SUPPORTED) {
			LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d",
				 LOCATIONS_ERROR_INCORRECT_METHOD, handle->method);
			return LOCATIONS_ERROR_INCORRECT_METHOD;
		} else if (ret == LOCATION_ERROR_NOT_ALLOWED) {
			LOCATIONS_LOGE("LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED");
			return LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED;
		}

		LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : satellite is NULL ",
			 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;
}

EXPORT_API int gps_status_get_last_satellite(location_manager_h manager, int *num_of_active, int *num_of_inview, time_t *timestamp)
{
	LOCATIONS_LOGD("gps_status_get_last_satellite");
	LOCATIONS_NULL_ARG_CHECK(manager);
	LOCATIONS_NULL_ARG_CHECK(num_of_active);
	LOCATIONS_NULL_ARG_CHECK(num_of_inview);
	LOCATIONS_NULL_ARG_CHECK(timestamp);
	location_manager_s *handle = (location_manager_s *) manager;
	int ret = LOCATION_ERROR_NONE;
	LocationSatellite *last_sat = NULL;
	ret = location_get_last_satellite(handle->object, &last_sat);
	if (ret != LOCATION_ERROR_NONE || last_sat == NULL) {
		if (ret == LOCATION_ERROR_NOT_SUPPORTED) {
			LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d",
				 LOCATIONS_ERROR_INCORRECT_METHOD, handle->method);
			return LOCATIONS_ERROR_INCORRECT_METHOD;
		} else if (ret == LOCATION_ERROR_NOT_ALLOWED) {
			LOCATIONS_LOGE("LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED");
			return LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED;
		}

		LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : satellite is NULL ",
			 LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
		return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
	}

	*num_of_active = last_sat->num_of_sat_used;
	*num_of_inview = last_sat->num_of_sat_inview;
	*timestamp = last_sat->timestamp;
	location_satellite_free(last_sat);
	return LOCATIONS_ERROR_NONE;
}

EXPORT_API int gps_status_foreach_last_satellites_in_view(location_manager_h manager, gps_status_get_satellites_cb callback,
							void *user_data)
{
	LOCATIONS_LOGD("gps_status_foreach_last_satellites_in_view");
	LOCATIONS_NULL_ARG_CHECK(manager);
	LOCATIONS_NULL_ARG_CHECK(callback);
	location_manager_s *handle = (location_manager_s *) manager;
	int ret;
	LocationSatellite *last_sat = NULL;
	ret = location_get_last_satellite(handle->object, &last_sat);
	if (ret != LOCATION_ERROR_NONE || last_sat == NULL) {
		if (ret == LOCATION_ERROR_NOT_SUPPORTED) {
			LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d",
				 LOCATIONS_ERROR_INCORRECT_METHOD, handle->method);
			return LOCATIONS_ERROR_INCORRECT_METHOD;
		}

		LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : satellite is NULL ",
			 LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
		return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
	}

	int i;
	for (i = 0; i < last_sat->num_of_sat_inview; i++) {
		guint prn;
		gboolean used;
		guint elevation;
		guint azimuth;
		gint snr;
		location_satellite_get_satellite_details(last_sat, i, &prn, &used, &elevation, &azimuth, &snr);
		if (callback(azimuth, elevation, prn, snr, used, user_data) != TRUE) {
			break;
		}
	}
	location_satellite_free(last_sat);
	return LOCATIONS_ERROR_NONE;
}