summaryrefslogtreecommitdiff
path: root/location/manager/location-accuracy.c
blob: d51983736d53a636ecf823fd66b6edaf5dc27c9a (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
/*
 * libslp-location
 *
 * Copyright (c) 2010-2013 Samsung Electronics Co., Ltd. All rights reserved.
 *
 * Contact: Youngae Kang <youngae.kang@samsung.com>, Minjune Kim <sena06.kim@samsung.com>
 *          Genie Kim <daejins.kim@samsung.com>
 *
 * 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.
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include "location-accuracy.h"
#include "location-log.h"

GType
location_accuracy_get_type (void)
{
	static volatile gsize type_volatile = 0;
	if(g_once_init_enter(&type_volatile)) {
		GType type = g_boxed_type_register_static (
			g_intern_static_string ("LocationAccuracy"),
			(GBoxedCopyFunc) location_accuracy_copy,
			(GBoxedFreeFunc) location_accuracy_free);
		g_once_init_leave(&type_volatile, type);
	}
	return type_volatile;
}

EXPORT_API LocationAccuracy*
location_accuracy_new (LocationAccuracyLevel level,
	gdouble horizontal_accuracy,
	gdouble vertical_accuracy)
{
	LocationAccuracy* accuracy = g_slice_new0 (LocationAccuracy);
	accuracy->level = level;
	accuracy->horizontal_accuracy = horizontal_accuracy;
	accuracy->vertical_accuracy = vertical_accuracy;

	return accuracy;
}

EXPORT_API void
location_accuracy_free (LocationAccuracy* accuracy)
{
	g_return_if_fail (accuracy);
	g_slice_free (LocationAccuracy, accuracy);
}

static int
comp_int(int a, int b)
{
	if (a < b) return -1;
	if (a == b) return 0;
	return 1;
}

static int
comp_double_reverse(double a, double b)
{
	if (a > b) return -1;
	else if (a == b) return 0;
	return 1;
}

EXPORT_API int
location_accuracy_level_compare(const LocationAccuracy *accuracy1, const LocationAccuracy *accuracy2)
{
	g_return_val_if_fail(accuracy1, -1);
	g_return_val_if_fail(accuracy2, 1);

	return comp_int(accuracy1->level, accuracy2->level);
}

EXPORT_API int
location_accuracy_compare (const LocationAccuracy *accuracy1, const LocationAccuracy *accuracy2)
{
	int ret = 0;
	ret = location_accuracy_level_compare(accuracy1, accuracy2);
	if(!ret){
		ret = comp_double_reverse(accuracy1->horizontal_accuracy, accuracy2->horizontal_accuracy);
		if(!ret) return comp_double_reverse(accuracy1->vertical_accuracy, accuracy2->vertical_accuracy);
	}
	return ret;
}

EXPORT_API LocationAccuracy*
location_accuracy_copy (const LocationAccuracy *accuracy)
{
	g_return_val_if_fail(accuracy, NULL);
	return location_accuracy_new(accuracy->level,
				accuracy->horizontal_accuracy,
				accuracy->vertical_accuracy);
}