1. Change tag style for error log
[platform/core/location/lbs-location.git] / location / manager / location-accuracy.c
1 /*
2  * libslp-location
3  *
4  * Copyright (c) 2010-2013 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Youngae Kang <youngae.kang@samsung.com>, Minjune Kim <sena06.kim@samsung.com>
7  *                      Genie Kim <daejins.kim@samsung.com>
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  */
21
22 #ifdef HAVE_CONFIG_H
23 #include "config.h"
24 #endif
25
26 #include "location-accuracy.h"
27 #include "location-log.h"
28
29 GType
30 location_accuracy_get_type(void)
31 {
32         static volatile gsize type_volatile = 0;
33         if (g_once_init_enter(&type_volatile)) {
34                 GType type = g_boxed_type_register_static(g_intern_static_string("LocationAccuracy"),
35                                         (GBoxedCopyFunc) location_accuracy_copy, (GBoxedFreeFunc) location_accuracy_free);
36
37                 g_once_init_leave(&type_volatile, type);
38         }
39         return type_volatile;
40 }
41
42 EXPORT_API LocationAccuracy *
43 location_accuracy_new(LocationAccuracyLevel level, gdouble horizontal_accuracy, gdouble vertical_accuracy)
44 {
45         LocationAccuracy *accuracy = g_slice_new0(LocationAccuracy);
46         g_return_val_if_fail(accuracy, NULL);
47
48         accuracy->level = level;
49         accuracy->horizontal_accuracy = horizontal_accuracy;
50         accuracy->vertical_accuracy = vertical_accuracy;
51
52         return accuracy;
53 }
54
55 EXPORT_API void
56 location_accuracy_free(LocationAccuracy *accuracy)
57 {
58         g_return_if_fail(accuracy);
59         g_slice_free(LocationAccuracy, accuracy);
60 }
61
62 static int
63 comp_int(int a, int b)
64 {
65         if (a < b) return -1;
66         if (a == b) return 0;
67         return 1;
68 }
69
70 static int
71 comp_double_reverse(double a, double b)
72 {
73         if (a > b) return -1;
74         else if (a == b) return 0;
75         return 1;
76 }
77
78 EXPORT_API int
79 location_accuracy_level_compare(const LocationAccuracy *accuracy1, const LocationAccuracy *accuracy2)
80 {
81         g_return_val_if_fail(accuracy1, -1);
82         g_return_val_if_fail(accuracy2, 1);
83
84         return comp_int(accuracy1->level, accuracy2->level);
85 }
86
87 EXPORT_API int
88 location_accuracy_compare(const LocationAccuracy *accuracy1, const LocationAccuracy *accuracy2)
89 {
90         int ret = 0;
91         ret = location_accuracy_level_compare(accuracy1, accuracy2);
92         if (!ret) {
93                 ret = comp_double_reverse(accuracy1->horizontal_accuracy, accuracy2->horizontal_accuracy);
94                 if (!ret) return comp_double_reverse(accuracy1->vertical_accuracy, accuracy2->vertical_accuracy);
95         }
96         return ret;
97 }
98
99 EXPORT_API LocationAccuracy *
100 location_accuracy_copy(const LocationAccuracy *accuracy)
101 {
102         g_return_val_if_fail(accuracy, NULL);
103         return location_accuracy_new(accuracy->level, accuracy->horizontal_accuracy, accuracy->vertical_accuracy);
104 }