fd7b523324c81c903e66cd48b3528990b901b4f2
[framework/location/libslp-location.git] / location / location-velocity.c
1 /*
2  * libslp-location
3  *
4  * Copyright (c) 2010-2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Youngae Kang <youngae.kang@samsung.com>, Yunhan Kim <yhan.kim@samsung.com>,
7  *          Genie Kim <daejins.kim@samsung.com>, Minjune Kim <sena06.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/location-velocity.h"
27 #include "location/location-log.h"
28
29 GType
30 location_velocity_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 (
35                         g_intern_static_string ("LocationVelocity"),
36                         (GBoxedCopyFunc) location_velocity_copy,
37                         (GBoxedFreeFunc) location_velocity_free);
38                 g_once_init_leave(&type_volatile, type);
39         }
40         return type_volatile;
41 }
42
43 EXPORT_API LocationVelocity*
44 location_velocity_new (guint timestamp,
45         gdouble speed,
46         gdouble direction,
47         gdouble climb)
48 {
49         LocationVelocity* velocity = g_slice_new0(LocationVelocity);
50         velocity->timestamp = timestamp;
51         velocity->speed = speed;
52         velocity->direction = direction;
53         velocity->climb = climb;
54         return velocity;
55 }
56
57 EXPORT_API void
58 location_velocity_free (LocationVelocity* velocity)
59 {
60         g_return_if_fail(velocity);
61         g_slice_free(LocationVelocity, velocity);
62 }
63
64 EXPORT_API gboolean
65 location_velocity_equal (const LocationVelocity *velocity1, const LocationVelocity *velocity2)
66 {
67         g_return_val_if_fail(velocity1, FALSE);
68         g_return_val_if_fail(velocity2, FALSE);
69
70         if (velocity1->timestamp == velocity2->timestamp &&
71                 velocity1->speed == velocity2->speed &&
72                 velocity1->direction == velocity2->direction &&
73                 velocity1->climb == velocity2->climb)
74                 return TRUE;
75         return FALSE;
76 }
77
78 EXPORT_API LocationVelocity*
79 location_velocity_copy (const LocationVelocity *velocity)
80 {
81         g_return_val_if_fail(velocity, NULL);
82
83         LocationVelocity *new_velocity = NULL;
84
85         new_velocity = location_velocity_new(velocity->timestamp,
86                                                                 velocity->speed,
87                                                                 velocity->direction,
88                                                                 velocity->climb);
89         if(new_velocity) new_velocity->updated_timestamp = velocity->updated_timestamp;
90
91         return new_velocity;
92 }